Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added tracking model run time #2

Merged
merged 8 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ersilia/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions ersilia/core/tracking.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
import json
import pandas as pd

Expand All @@ -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)
Expand All @@ -27,6 +35,9 @@ def track(self, input, result, meta):

print("Model metadata:", meta)

time = datetime.now() - self.time_start
print("Time taken:", time)

def log_to_console(self, data):
print(f"\n{json.dumps(data)}\n")

Expand Down