Skip to content

Commit

Permalink
Add unknown status count
Browse files Browse the repository at this point in the history
  • Loading branch information
rosswhitfield committed Sep 29, 2024
1 parent e10f498 commit c766206
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/webmon_app/reporting/metrics/view_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


def postprocessing_diagnostics():
"""collect and return Cataloging & Reduction diagnostics"""
common_services = Instrument.objects.get(name="common")
agents = []

Expand Down Expand Up @@ -42,7 +43,7 @@ def postprocessing_diagnostics():


def instrument_status():
# return map of instrument name to run status
"""return map of instrument name to run status"""

instruments = Instrument.objects.all().order_by("name")
status = {}
Expand All @@ -57,18 +58,19 @@ def instrument_status():
def run_statuses(minutes=60):
"""Of all the runs created in the last n minutes,
return the number that are acquiring, complete, incomplete,
error along with the total number"""
error or unknown along with the total number"""

runs = DataRun.objects.filter(created_on__gte=timezone.now() - timezone.timedelta(minutes=minutes)).order_by(
"created_on"
)

statuses = {"count": len(runs), "acquiring": 0, "incomplete": 0, "complete": 0, "error": 0}
statuses = {"total": len(runs), "acquiring": 0, "incomplete": 0, "complete": 0, "error": 0, "unknown": 0}

for run_id in runs:
try:
s = WorkflowSummary.objects.get(run_id=run_id)
except WorkflowSummary.DoesNotExist:
statuses["unknown"] += 1
continue

if not is_acquisition_complete(run_id):
Expand Down
27 changes: 22 additions & 5 deletions src/webmon_app/reporting/tests/test_metrics/test_view_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,25 @@ def test_run_statuses(self):
WorkflowSummary.objects.create(run_id=dataRun0, complete=True)

statuses = run_statuses()
assert statuses["count"] == 0
assert statuses["total"] == 0
assert statuses["acquiring"] == 0
assert statuses["incomplete"] == 0
assert statuses["complete"] == 0
assert statuses["error"] == 0
assert statuses["unknown"] == 0

# run should be acquiring
dataRun1 = DataRun(run_number=1, ipts_id=ipts, instrument_id=inst, file="/filename")
dataRun1.save()
WorkflowSummary.objects.create(run_id=dataRun1)

statuses = run_statuses()
assert statuses["count"] == 1
assert statuses["total"] == 1
assert statuses["acquiring"] == 1
assert statuses["incomplete"] == 0
assert statuses["complete"] == 0
assert statuses["error"] == 0
assert statuses["unknown"] == 0

# run should be incomplete
dataRun2 = DataRun(run_number=2, ipts_id=ipts, instrument_id=inst, file="/filename")
Expand All @@ -152,11 +154,12 @@ def test_run_statuses(self):
WorkflowSummary.objects.create(run_id=dataRun2)

statuses = run_statuses()
assert statuses["count"] == 2
assert statuses["total"] == 2
assert statuses["acquiring"] == 1
assert statuses["incomplete"] == 1
assert statuses["complete"] == 0
assert statuses["error"] == 0
assert statuses["unknown"] == 0

# run should be complete
dataRun3 = DataRun(run_number=3, ipts_id=ipts, instrument_id=inst, file="/filename")
Expand All @@ -165,11 +168,12 @@ def test_run_statuses(self):
WorkflowSummary.objects.create(run_id=dataRun3, complete=True)

statuses = run_statuses()
assert statuses["count"] == 3
assert statuses["total"] == 3
assert statuses["acquiring"] == 1
assert statuses["incomplete"] == 1
assert statuses["complete"] == 1
assert statuses["error"] == 0
assert statuses["unknown"] == 0

# run should be error
dataRun4 = DataRun(run_number=4, ipts_id=ipts, instrument_id=inst, file="/filename")
Expand All @@ -180,8 +184,21 @@ def test_run_statuses(self):
WorkflowSummary.objects.create(run_id=dataRun4)

statuses = run_statuses()
assert statuses["count"] == 4
assert statuses["total"] == 4
assert statuses["acquiring"] == 1
assert statuses["incomplete"] == 1
assert statuses["complete"] == 1
assert statuses["error"] == 1
assert statuses["unknown"] == 0

# create run but now WorkflowSummary. status should be unknown
dataRun5 = DataRun(run_number=5, ipts_id=ipts, instrument_id=inst, file="/filename")
dataRun5.save()

statuses = run_statuses()
assert statuses["total"] == 5
assert statuses["acquiring"] == 1
assert statuses["incomplete"] == 1
assert statuses["complete"] == 1
assert statuses["error"] == 1
assert statuses["unknown"] == 1

0 comments on commit c766206

Please sign in to comment.