Skip to content
Snippets Groups Projects
Commit d42a8848 authored by Mario Raciti's avatar Mario Raciti
Browse files

TMSS-770: Add fraction percentages; minor fixes

parent 5fca25b8
No related branches found
No related tags found
3 merge requests!634WIP: COBALT commissioning delta,!522Resolve TMSS-770,!481Draft: SW-971 SW-973 SW-975: Various fixes to build LOFAR correctly.
......@@ -54,9 +54,13 @@ def _get_telescope_time_distribution(cycle: models.Cycle, start: datetime, stop:
total += sub.observed_duration.total_seconds()
succeeded += sub.observed_duration.total_seconds() if sup and sup.results_accepted else 0
failed += sub.observed_duration.total_seconds() if sup and sup.results_accepted is False else 0
# Calculate derived and store durations
idle = total - succeeded - failed
result[c if c == 'UNASSIGNED' or c == 'FILLER' else c.name] = {'durations': {'total': total, 'succeeded': succeeded,
'failed': failed, 'idle': idle}}
succeeded_perc = succeeded * 100.0 / total if total > 0 else None
failed_perc = failed * 100.0 / total if total > 0 else None
idle_perc = idle * 100.0 / total if total > 0 else None
durations = {'total': total, 'succeeded': succeeded, 'succeeded_perc': succeeded_perc, 'failed': failed, 'failed_perc': failed_perc, 'idle': idle, 'idle_perc': idle_perc}
result[c if c == 'UNASSIGNED' or c == 'FILLER' else c.name] = {'durations': durations}
return result
......@@ -84,7 +88,7 @@ def _get_average_efficiency(cycle: models.Cycle, start: datetime, stop: datetime
sup = SchedulingUnitProcess.objects.filter(su=sub).first()
total_per_day += sub.observed_duration.total_seconds()
total_succeeded_per_day += sub.observed_duration.total_seconds() if sup and sup.results_accepted else 0
efficiency_per_day += total_succeeded_per_day / total_per_day if total_per_day > 0 else 0
efficiency_per_day += total_succeeded_per_day * 100.0 / total_per_day if total_per_day > 0 else 0
i += 1
d += step
......@@ -112,12 +116,14 @@ def _get_completion_level(cycle: models.Cycle, start: datetime, stop: datetime)
sup = SchedulingUnitProcess.objects.filter(su=sub).first()
total += sub.observed_duration.total_seconds()
total_succeeded += sub.observed_duration.total_seconds() if sup and sup.results_accepted else 0
result['total'], result['succeeded'] = total, total_succeeded
# Store durations
succeeded_perc = total_succeeded * 100.0 / total if total > 0 else None
result['total'], result['succeeded'], result['succeeded_perc'] = total, total_succeeded, succeeded_perc
# Calculate prognosis
unschedulable_subtasks = models.Subtask.objects.filter(task_blueprints__scheduling_unit_blueprint__in=subs).filter(state='unschedulable')
unschedulable_duration = sum([uns.specified_duration.total_seconds() for uns in unschedulable_subtasks])
result['prognosis'] = (total - unschedulable_duration) * 100.0 / total if total > 0 and total >= unschedulable_duration else None
result['prognosis'] = unschedulable_duration * 100.0 / total if total > 0 else None
return result
......@@ -182,8 +188,8 @@ def _get_weekly_efficiency(cycle: models.Cycle, start: datetime, stop: datetime)
sup = SchedulingUnitProcess.objects.filter(su=sub).first()
total_per_week += sub.observed_duration.total_seconds()
total_succeeded_per_week += sub.observed_duration.total_seconds() if sup and sup.results_accepted else 0
result['weeks'].append(
{'week': d.date().isoformat(), 'efficiency': total_succeeded_per_week / total_per_week if total_per_week > 0 else None})
efficiency = total_succeeded_per_week * 100.0 / total_per_week if total_per_week > 0 else None
result['weeks'].append({'week': d.date().isoformat(), 'efficiency': efficiency})
d += step
return result
......@@ -297,7 +303,8 @@ def _get_failures(cycle: models.Cycle, start: datetime, stop: datetime) -> {}:
sup = SchedulingUnitProcess.objects.filter(su=sub).first()
total_per_month += sub.observed_duration.total_seconds()
total_failed_per_month += sub.observed_duration.total_seconds() if sup and sup.results_accepted is False else 0
result['months'].append({'month': d.date().isoformat(), 'total': total_per_month, 'total_failed': total_failed_per_month})
failed_perc = total_failed_per_month * 100.0 / total_per_month if total_per_month > 0 else None
result['months'].append({'month': d.date().isoformat(), 'total': total_per_month, 'total_failed': total_failed_per_month, 'failed_perc': failed_perc})
d += step
return result
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment