Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Istrati committed Nov 1, 2024
1 parent b1f59fe commit d249bf3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
5 changes: 2 additions & 3 deletions app/anomaly-detector/anomaly_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,8 @@ async def connect_to_database(dbname, dbuser, dbpass, dbhost, dbport):
"""
conn = f"host={dbhost} port={dbport} dbname={dbname} user={dbuser} password={dbpass}"
try:
pool = AsyncConnectionPool(conn, min_size=1, max_size=20)
await pool.open()
return pool
async with AsyncConnectionPool(conn, min_size=1, max_size=20) as pool:
return pool
except Exception as e:
print(f"Failed to connect to database: {e}")
return None
Expand Down
10 changes: 5 additions & 5 deletions app/anomaly-detector/anomaly_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ def create_embeddings(df):
for unit in ['year', 'month', 'day', 'hour', 'minute', 'second']:
df[f"{col}_{unit}"] = getattr(df[col].dt, unit)

# new_timestamp_features = [
# float(col) for col in df.columns
# if col.startswith("EVENT_TIMESTAMP_") or col.startswith("LABEL_TIMESTAMP_")
# ]
new_timestamp_features = [
col for col in df.columns
if col.startswith("EVENT_TIMESTAMP_") or col.startswith("LABEL_TIMESTAMP_")
]

# Combine numerical, categorical and timestamp features
combined_features = concat([
df[numerical_features], encoded_categorical_features #, df[new_timestamp_features]
df[numerical_features], encoded_categorical_features, df[new_timestamp_features]
], axis=1)
print(combined_features.head())

Expand Down

0 comments on commit d249bf3

Please sign in to comment.