Skip to content

Commit

Permalink
Removing schema primary key and improving examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dmvieira committed Jul 27, 2020
1 parent 770f03c commit cf93b4c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
10 changes: 4 additions & 6 deletions driftage/db/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
DRIFTAGE_TABLENAME = environ.get("DRIFTAGE_TABLENAME", "driftage_kb")

table = Table(DRIFTAGE_TABLENAME, MetaData(),
Column('driftage_jid', String, primary_key=True),
Column(
'driftage_datetime_monitored', DateTime, primary_key=True),
Column(
'driftage_datetime_analysed', DateTime, primary_key=True),
Column('driftage_identifier', String, primary_key=True),
Column('driftage_jid', String),
Column('driftage_datetime_monitored', DateTime),
Column('driftage_datetime_analysed', DateTime),
Column('driftage_identifier', String),
Column('driftage_data', PickleType),
Column('driftage_predicted', Boolean)
)
2 changes: 0 additions & 2 deletions examples/health_monitor/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ services:
- POSTGRES_DB=driftage_kb
- POSTGRES_USER=agents
- POSTGRES_PASSWORD=passw0rd
volumes:
- ./build/timescaledb:/var/lib/postgresql/data
ports:
- 5432:5432
ejabberd:
Expand Down
4 changes: 3 additions & 1 deletion examples/health_monitor/executor/csv_executor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import time
import logging
from datetime import datetime
from driftage.executor import Executor
from driftage.executor.sink import Sink

Expand Down Expand Up @@ -29,10 +30,11 @@ def is_available(self) -> bool:

async def drain(self, data: dict):
logger.debug(f"Writing data: {data} to {self.path}")
now = datetime.utcnow()
with open(self.path, "a") as f:
f.write(
f"{data['timestamp']}, {data['identifier']}, "
f"{data['predicted']}\n"
f"{data['predicted']}, {now}\n"
)


Expand Down
12 changes: 7 additions & 5 deletions examples/health_monitor/planner/voting_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class VotingPredictor(PlannerPredictor):

start_time = datetime.utcnow()
last_time = datetime.utcnow()
voting_low_threashold = 2
voting_low_threashold = 3
voting_high_threashold = 8

@property
def predict_period(self):
return 1.5
return 5

async def predict(self) -> List[PredictResult]:
now = datetime.utcnow()
Expand All @@ -40,9 +40,11 @@ async def predict(self) -> List[PredictResult]:

columns = [
table.c.driftage_identifier.name, table.c.driftage_predicted.name]
drifts = df[
table.c.driftage_datetime_monitored > self.start_time
][columns].groupby(

from_now_df = df[
df[table.c.driftage_datetime_monitored.name] > self.start_time
]
drifts = from_now_df[columns].groupby(
table.c.driftage_identifier.name).sum().to_dict()
drift_prediction = drifts[table.c.driftage_predicted.name]

Expand Down

0 comments on commit cf93b4c

Please sign in to comment.