diff --git a/ersilia/core/model.py b/ersilia/core/model.py index 30500bee..2ef49f26 100644 --- a/ersilia/core/model.py +++ b/ersilia/core/model.py @@ -416,6 +416,10 @@ def get_apis(self): def run( self, input=None, output=None, batch_size=DEFAULT_BATCH_SIZE, track_run=False ): + # Init some tracking before the run starts + if self._run_tracker is not None and track_run: + self._run_tracker.start_tracking() + api_name = self.get_apis()[0] result = self.api( api_name=api_name, input=input, output=output, batch_size=batch_size diff --git a/ersilia/core/tracking.py b/ersilia/core/tracking.py index f123b505..d445eb68 100644 --- a/ersilia/core/tracking.py +++ b/ersilia/core/tracking.py @@ -1,3 +1,4 @@ +from datetime import datetime import json import pandas as pd @@ -10,6 +11,13 @@ class RunTracker: NOTE: Currently, the Splunk connection is not set up. For now, we will print tracking results to the console. """ + def __init__(self): + self.time_start = None + + # function to be called before model is run + def start_tracking(self): + self.time_start = datetime.now() + def read_csv(self, file): # reads csv file and returns Pandas dataframe return pd.read_csv(file) @@ -27,9 +35,12 @@ def track(self, input, result, meta): print("Model metadata:", meta) - model_id = meta['metadata'].get ('Identifier', 'Unknown') + model_id = meta['metadata'].get('Identifier', 'Unknown') print ("Model ID:", model_id) - + + time = datetime.now() - self.time_start + print("Time taken:", time) + def log_to_console(self, data): print(f"\n{json.dumps(data)}\n")