From cf93b4cf47406e40fc53ecbfe4fe88d78a5e42d8 Mon Sep 17 00:00:00 2001 From: Diogo Munaro Vieira Date: Sun, 26 Jul 2020 21:48:43 -0300 Subject: [PATCH] Removing schema primary key and improving examples --- driftage/db/schema.py | 10 ++++------ examples/health_monitor/docker-compose.yml | 2 -- examples/health_monitor/executor/csv_executor.py | 4 +++- examples/health_monitor/planner/voting_planner.py | 12 +++++++----- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/driftage/db/schema.py b/driftage/db/schema.py index d10f7f7..0332ef1 100644 --- a/driftage/db/schema.py +++ b/driftage/db/schema.py @@ -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) ) diff --git a/examples/health_monitor/docker-compose.yml b/examples/health_monitor/docker-compose.yml index ab94404..623b085 100644 --- a/examples/health_monitor/docker-compose.yml +++ b/examples/health_monitor/docker-compose.yml @@ -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: diff --git a/examples/health_monitor/executor/csv_executor.py b/examples/health_monitor/executor/csv_executor.py index 5a6e894..23e7129 100644 --- a/examples/health_monitor/executor/csv_executor.py +++ b/examples/health_monitor/executor/csv_executor.py @@ -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 @@ -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" ) diff --git a/examples/health_monitor/planner/voting_planner.py b/examples/health_monitor/planner/voting_planner.py index 4252042..358c7be 100644 --- a/examples/health_monitor/planner/voting_planner.py +++ b/examples/health_monitor/planner/voting_planner.py @@ -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() @@ -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]