Skip to content

Commit

Permalink
Merge pull request #15 from hcs-t4sg/holden/current_session
Browse files Browse the repository at this point in the history
Holden/track model runs using a file
  • Loading branch information
AC-Dap authored Oct 28, 2023
2 parents 11fd537 + 77a626d commit 229a816
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ secrets.json
development.ipynb
development.py
tmp/
.idea/

# Sphinx related
/doctrees
Expand Down
10 changes: 10 additions & 0 deletions ersilia/cli/commands/close.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime
import os
from . import ersilia_cli
from .. import echo
from ... import ErsiliaModel
Expand All @@ -17,3 +19,11 @@ def close():
mdl = ErsiliaModel(model_id, service_class=service_class)
mdl.close()
echo(":no_entry: Model {0} closed".format(mdl.model_id), fg="green")

# renames current_session to timestamp
old_file_path = "current_session.txt"
new_file_path = os.path.join(
os.path.dirname(old_file_path),
datetime.datetime.now().strftime("%Y%m%d%H%M%S"),
)
os.rename(old_file_path, new_file_path)
13 changes: 12 additions & 1 deletion ersilia/cli/commands/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ def serve_cmd():
type=click.INT,
help="Preferred port to use (integer)",
)
def serve(model, lake, docker, port):
# Add the new flag for tracking the serve session
@click.option(
"-t/",
"--track_serve/--no_track_serve",
"track_serve",
required=False,
default=True,
)
def serve(model, lake, docker, port, track_serve):
if docker:
service_class = "docker"
else:
Expand Down Expand Up @@ -54,3 +62,6 @@ def serve(model, lake, docker, port):
echo("")
echo(":person_tipping_hand: Information:", fg="blue")
echo(" - info", fg="blue")
if track_serve:
with open("current_session.txt", "w") as f:
f.write("Session started for model: {0}".format(mdl.model_id))
12 changes: 11 additions & 1 deletion ersilia/core/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,19 @@ def track(self, input, result, meta):

self.get_file_sizes(input_dataframe, result_dataframe)

json_object = json.dumps(json_dict, indent = 4)
json_object = json.dumps(json_dict, indent=4)
print("\nJSON Dictionary:\n", json_object)

# log results to console
with open("../cli/commands/current_session.txt", "a") as f:
# write the print statements to a file
f.write(f"\n{json.dumps(input_dataframe)}\n")
f.write(f"\n{json.dumps(result_dataframe)}\n")
f.write(f"\n{json.dumps(meta)}\n")
f.write(f"\nModel ID: {model_id}\n")
f.write(f"\nTime taken: {time}\n")
f.write(f"\nNAN Count:\n {nan_count}\n")

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

Expand Down

0 comments on commit 229a816

Please sign in to comment.