Skip to content

Commit

Permalink
fix time wasted
Browse files Browse the repository at this point in the history
  • Loading branch information
brisvag committed Oct 8, 2024
1 parent b577790 commit f60b79c
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/stemia/cryosparc/time_wasted.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@ def cli(project_dirs, useful_jobs):
)

import json
from datetime import timedelta
import logging
from datetime import datetime, timedelta
from pathlib import Path

from rich import print
from rich.logging import RichHandler
from rich.progress import Progress

logging.basicConfig(
format="%(message)s",
datefmt="[%X]",
handlers=[RichHandler()],
)

with Progress() as prog:
for proj in prog.track(project_dirs, description="Reading projects..."):
proj = Path(proj)
Expand Down Expand Up @@ -63,15 +71,15 @@ def get_parents(job, proj, parents):
for job in prog.track(jobs, description="Reading jobs..."):
job_meta = job / "job.json"
if not job_meta.exists():
# print(f'Missing job metadata for {job.name}, skipping.')
logging.log(f"Missing job metadata for {job.name}, skipping.")
skipped += 1
continue
with open(job_meta) as f:
meta = json.load(f)

start = meta["started_at"]
if start is None:
# print(f'job {job.name} was not started, skipping')
logging.info(f"job {job.name} was not started, skipping")
skipped += 1
continue

Expand All @@ -81,12 +89,20 @@ def get_parents(job, proj, parents):
if end is None:
end = meta["failed_at"]
if end is None:
# print(f'job {job.name} was not finished, skipping')
logging.info(f"job {job.name} was not finished, skipping")
skipped += 1
continue

running = timedelta(milliseconds=end["$date"] - start["$date"])
queued = timedelta(milliseconds=start["$date"] - launch["$date"])
if isinstance(end["$date"], int):
running = timedelta(milliseconds=end["$date"] - start["$date"])
queued = timedelta(milliseconds=start["$date"] - launch["$date"])
elif isinstance(end["$date"], str):
running = datetime.fromisoformat(
end["$date"]
) - datetime.fromisoformat(start["$date"])
queued = datetime.fromisoformat(
start["$date"]
) - datetime.fromisoformat(launch["$date"])

total_queued += queued

Expand Down

0 comments on commit f60b79c

Please sign in to comment.