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

TMSS-770: Add fraction percentages in remaining functions

parent 679adc5b
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.
...@@ -134,7 +134,7 @@ def _get_observation_hours_per_category(cycle: models.Cycle, start: datetime, st ...@@ -134,7 +134,7 @@ def _get_observation_hours_per_category(cycle: models.Cycle, start: datetime, st
""" """
from lofar.sas.tmss.tmss.workflowapp.models.schedulingunitflow import SchedulingUnitProcess from lofar.sas.tmss.tmss.workflowapp.models.schedulingunitflow import SchedulingUnitProcess
result = {'total_duration_failed': 0, 'total_duration_idle': 0, 'DDT Com Rep': 0} result = {'total_duration': 0, 'total_duration_successful': 0, 'total_duration_failed': 0, 'total_duration_idle': 0, 'DDT Com Rep': 0}
# Filter System Unavailability # Filter System Unavailability
# TODO: Maybe add some other case scenarios where the system is not up and running? # TODO: Maybe add some other case scenarios where the system is not up and running?
...@@ -153,16 +153,29 @@ def _get_observation_hours_per_category(cycle: models.Cycle, start: datetime, st ...@@ -153,16 +153,29 @@ def _get_observation_hours_per_category(cycle: models.Cycle, start: datetime, st
project_categoy = sub.project.project_category project_categoy = sub.project.project_category
if project_categoy == 'ddt' or project_categoy == 'commissioning': # TODO: Rep as repetition. if project_categoy == 'ddt' or project_categoy == 'commissioning': # TODO: Rep as repetition.
result['DDT Com Rep'] += sub.observed_duration.total_seconds() result['DDT Com Rep'] += sub.observed_duration.total_seconds()
# Distinguish successful and failed # Aggregate total and idle
result['total_duration'] += sub.observed_duration.total_seconds()
result['total_duration_idle'] += sub.observed_duration.total_seconds() result['total_duration_idle'] += sub.observed_duration.total_seconds()
# Distinguish successful and failed
sup = SchedulingUnitProcess.objects.filter(su=sub).first() sup = SchedulingUnitProcess.objects.filter(su=sub).first()
result[f'total_duration_successful_{prio.name}'] += sub.observed_duration.total_seconds() if sup and sup.results_accepted else 0 result[f'total_duration_successful_{prio.name}'] += sub.observed_duration.total_seconds() if sup and sup.results_accepted else 0
result['total_duration_failed'] += sub.observed_duration.total_seconds() if sup and sup.results_accepted is False else 0 result['total_duration_failed'] += sub.observed_duration.total_seconds() if sup and sup.results_accepted is False else 0
# Calculate prio percentages
result[f'successful_{prio.name}_perc'] = result[f'total_duration_successful_{prio.name}'] * 100.0 / result['total_duration'] if result['total_duration'] > 0 else None
# Aggregate prio durations to general successful
result['total_duration_successful'] += result[f'total_duration_successful_{prio.name}']
# Subtract prio states from total to get partial idle # Subtract prio states from total to get partial idle
result['total_duration_idle'] -= result[f'total_duration_successful_{prio.name}'] result['total_duration_idle'] -= result[f'total_duration_successful_{prio.name}']
# Subtract total failed to get total idle eventually # Subtract total failed to get total idle eventually
result['total_duration_idle'] -= result['total_duration_failed'] result['total_duration_idle'] -= result['total_duration_failed']
# Calculate percentages
result['successful_perc'] = result['total_duration_successful'] * 100.0 / result['total_duration'] if result['total_duration'] > 0 else None
result['idle_perc'] = result['total_duration_idle'] * 100.0 / result['total_duration'] if result['total_duration'] > 0 else None
result['failed_perc'] = result['total_duration_failed'] * 100.0 / result['total_duration'] if result['total_duration'] > 0 else None
result['ddt_com_rep_perc'] = result['DDT Com Rep'] * 100.0 / result['total_duration'] if result['total_duration'] > 0 else None
result['system_unavailability_perc'] = result['System Unavailability'] * 100.0 / result['total_duration'] if result['System Unavailability'] and result['total_duration'] > 0 else None
return result return result
...@@ -397,6 +410,14 @@ def _get_subs_and_durations_from_project(project_pk: int, start: datetime, stop: ...@@ -397,6 +410,14 @@ def _get_subs_and_durations_from_project(project_pk: int, start: datetime, stop:
subs = {'successful': subs_succeeded, 'failed': subs_failed} subs = {'successful': subs_succeeded, 'failed': subs_failed}
# Calculate percentages
durations['not_cancelled_perc'] = durations['total_not_cancelled'] * 100.0 / durations['total'] if durations['total'] > 0 else None
durations['succeeded_perc'] = durations['total_succeeded'] * 100.0 / durations['total'] if durations['total'] > 0 else None
durations['failed_perc'] = durations['total_failed'] * 100.0 / durations['total'] if durations['total'] > 0 else None
durations['observed_perc'] = durations['total_observed'] * 100.0 / durations['total'] if durations['total'] > 0 else None
durations['observed_succeeded_perc'] = durations['total_observed_succeeded'] * 100.0 / durations['total'] if durations['total'] > 0 else None
durations['observed_failed_perc'] = durations['total_observed_failed'] * 100.0 / durations['total'] if durations['total'] > 0 else None
return subs, durations return subs, durations
......
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