File size: 1,032 Bytes
f614769 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import json
import time
from datetime import datetime
class InProgressExperimentTracker:
def __init__(self, track_file="runs_in_progress.json"):
self.track_file = track_file
def _load_runs(self):
try:
with open(self.track_file, "r") as file:
return json.load(file)
except FileNotFoundError:
return {}
def _save_runs(self, runs):
with open(self.track_file, "w") as file:
json.dump(runs, file, indent=4)
def start_run(self, index):
runs = self._load_runs()
timestamp = datetime.now().isoformat()
runs[index] = timestamp
self._save_runs(runs)
print(f"Run {index} started at {timestamp}")
def complete_run(self, index):
runs = self._load_runs()
if index in runs:
del runs[str(index)]
self._save_runs(runs)
print(f"Run {index} completed and removed from tracking")
else:
print(f"Run {index} not found in tracking")
|