Skip to content
Snippets Groups Projects
Commit 170480e2 authored by Nico Vermaas's avatar Nico Vermaas
Browse files

add quality statistics to summary page

parent 5a28569f
No related branches found
No related tags found
2 merge requests!304update branch with master,!302automatic quality validation
Pipeline #51993 passed
...@@ -127,7 +127,7 @@ def calculate_qualities(task): ...@@ -127,7 +127,7 @@ def calculate_qualities(task):
""" """
try: try:
# gather the results of all the calculated_quality values for this sas_id # gather the results of all the calculated_quality values for this sas_id
d = {'poor': 0, 'moderate': 0, 'good': 0} qualities = {'poor': 0, 'moderate': 0, 'good': 0}
for task in Task.objects.filter(sas_id=unsaved_task.sas_id): for task in Task.objects.filter(sas_id=unsaved_task.sas_id):
...@@ -140,16 +140,16 @@ def calculate_qualities(task): ...@@ -140,16 +140,16 @@ def calculate_qualities(task):
try: try:
key = t.calculated_qualities['per_task'] key = t.calculated_qualities['per_task']
d[key] = d[key] + 1 qualities[key] = qualities[key] + 1
except: except:
# ignore the tasks that have no calculated quality (they are probably not 'stored'). # ignore the tasks that have no calculated quality (they are probably not 'stored').
pass pass
total = d['poor'] + d['moderate'] + d['good'] total = qualities['poor'] + qualities['moderate'] + qualities['good']
if total > 0: if total > 0:
percentage_poor = (d['poor'] / total) * 100 percentage_poor = (qualities['poor'] / total) * 100
percentage_good = (d['good'] / total) * 100 percentage_good = (qualities['good'] / total) * 100
quality_sasid = "moderate" quality_sasid = "moderate"
if percentage_poor >= quality_thresholds['overall_poor']: if percentage_poor >= quality_thresholds['overall_poor']:
......
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
Author: Nico Vermaas - Astron Author: Nico Vermaas - Astron
Description: Business logic for ATDB. These functions are called from the views (views.py). Description: Business logic for ATDB. These functions are called from the views (views.py).
""" """
import os import json
import requests import requests
import base64 import base64
from datetime import datetime, timedelta from datetime import datetime
from django.db.models import Q, Sum from django.db.models import Q, Sum
import logging import logging
from .common import timeit from .common import timeit
...@@ -801,11 +801,13 @@ def construct_summary(task): ...@@ -801,11 +801,13 @@ def construct_summary(task):
results = "" results = ""
total_size_input = 0 total_size_input = 0
total_size_output = 0 total_size_output = 0
qualities = {'poor': 0, 'moderate': 0, 'good': 0}
sas_id = task.sas_id sas_id = task.sas_id
title = "<h4>Summary File for SAS_ID " + task.sas_id + "</h4> " title = "<h4>Summary File for SAS_ID " + task.sas_id + "</h4> "
tasks = Task.objects.filter(sas_id=sas_id) tasks = Task.objects.filter(sas_id=sas_id)
for task in tasks: for task in tasks:
# skip 'suspended' and 'discarded' tasks # skip 'suspended' and 'discarded' tasks
...@@ -853,8 +855,9 @@ def construct_summary(task): ...@@ -853,8 +855,9 @@ def construct_summary(task):
# add calculated quality (if present) # add calculated quality (if present)
calculated_qualities = task.calculated_qualities calculated_qualities = task.calculated_qualities
if calculated_qualities: if calculated_qualities:
line += '<tr><td><b>Calculated Quality</b></td>'
task_quality = calculated_qualities['per_task'] task_quality = calculated_qualities['per_task']
line += '<tr><td><b>Calculated Quality</b></td>'
line += '<td class="' + task_quality + '">' + str(task_quality) + '</td>' line += '<td class="' + task_quality + '">' + str(task_quality) + '</td>'
line += '</tr>' line += '</tr>'
...@@ -881,12 +884,19 @@ def construct_summary(task): ...@@ -881,12 +884,19 @@ def construct_summary(task):
except: except:
pass pass
try:
key = task.calculated_qualities['per_task']
qualities[key] = qualities[key] + 1
except:
# ignore the tasks that have no calculated quality (they are probably not 'stored').
pass
results += line results += line
except: except:
pass pass
totals += '<th>Totals</th><th></th><th></th>' totals += '<th>Totals</th><th></th><th width="35%"></th>'
try: try:
totals += '<tr><td colspan="2"><b>Input size</b></td><td>' + str(total_size_input) + '</td></tr>' totals += '<tr><td colspan="2"><b>Input size</b></td><td>' + str(total_size_input) + '</td></tr>'
totals += '<tr><td colspan="2"><b>Output size</b><td>' + str(total_size_output) + '</td></tr>' totals += '<tr><td colspan="2"><b>Output size</b><td>' + str(total_size_output) + '</td></tr>'
...@@ -898,6 +908,24 @@ def construct_summary(task): ...@@ -898,6 +908,24 @@ def construct_summary(task):
sasid_quality = calculated_qualities['per_sasid'] sasid_quality = calculated_qualities['per_sasid']
totals += '<tr><td colspan="2"><b>Calculated Quality</b></td>' totals += '<tr><td colspan="2"><b>Calculated Quality</b></td>'
totals += '<td class="' + sasid_quality + '">' + str(sasid_quality) + '</td></tr>' totals += '<td class="' + sasid_quality + '">' + str(sasid_quality) + '</td></tr>'
totals += '<tr><td colspan="2"><b>Quality Statistics</b></td><td>' + str(qualities) + '</td></tr>'
try:
quality_thresholds = json.loads(Configuration.objects.get(key='quality_thresholds').value)
totals += '<tr>'
totals += '<td><b>RFI thresholds</b></td>'
totals += '<td>Per Task</td><td>M, rfi >'+ str(quality_thresholds['poor']) + '% = P, rfi <=' + str(quality_thresholds['moderate']) + '% = G</td>'
totals += '</tr>'
totals += '<tr>'
totals += '<td></td>'
totals += '<td>Per SAS_ID</td><td>M, >'+ str(quality_thresholds['overall_poor']) + '% P = P, >' + str(quality_thresholds['overall_good']) + '% G = G</td>'
totals += '</tr>'
except:
pass
except: except:
pass pass
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
{% include 'taskdatabase/pagination.html' %} {% include 'taskdatabase/pagination.html' %}
</div> </div>
</div> </div>
<p class="footer"> Version 21 June 2023 <p class="footer"> Version 23 June 2023
</div> </div>
{% include 'taskdatabase/refresh.html' %} {% include 'taskdatabase/refresh.html' %}
......
...@@ -1082,7 +1082,8 @@ def TaskValidateSasId(request, pk, quality, new_status, page=0): ...@@ -1082,7 +1082,8 @@ def TaskValidateSasId(request, pk, quality, new_status, page=0):
sas_id = task.sas_id sas_id = task.sas_id
tasks = Task.objects.filter(sas_id=sas_id) tasks = Task.objects.filter(sas_id=sas_id)
for task in tasks: for task in tasks:
if task.status == 'stored':
if task.status == 'stored' or task.status == 'validated ':
if quality == 'calculated': if quality == 'calculated':
try: try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment