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

Merge branch 'sdch-3725-show-combined-list-of-plots' into 'master'

upgrade inspection plots and summary pages

See merge request !270
parents a699a1f0 5f8359a0
Branches
No related tags found
1 merge request!270upgrade inspection plots and summary pages
Pipeline #41199 canceled
...@@ -678,11 +678,8 @@ def unique_values_for_aggregation_key(queryset, aggregation_key): ...@@ -678,11 +678,8 @@ def unique_values_for_aggregation_key(queryset, aggregation_key):
return list(map(lambda x: x[aggregation_key], queryset.values(aggregation_key).distinct())) return list(map(lambda x: x[aggregation_key], queryset.values(aggregation_key).distinct()))
def construct_inspectionplots(task): def construct_inspectionplots(task,source='taskid'):
#results = "<h4>Inspection Plots (for SAS_ID " + task.sas_id + ")</h4>" #results = "<h4>Inspection Plots (for SAS_ID " + task.sas_id + ")</h4>"
results = "<h4>Inspection Plots</h4>"
results += "<p>Clicking a link will redirect to SURF SARA in a new browser window. </p>"
# translate the path to a url # translate the path to a url
try: try:
...@@ -696,13 +693,45 @@ def construct_inspectionplots(task): ...@@ -696,13 +693,45 @@ def construct_inspectionplots(task):
translation = srm_to_url.split("::") translation = srm_to_url.split("::")
# find the plots in the quality json structure # find the plots in the quality json structure
if source == 'task_id':
results = "<h4>Inspection Plots and Summary Logs</h4>"
results += "<p>Clicking a link will redirect to SURF SARA in a new browser window. </p>"
plots = task.quality_json["plots"]
for plot in plots:
basename = plot['basename']
surl = plot['surl'] + "?action=show&authz=" + str(token)
url = surl.replace(translation[0],translation[1])
results += '<tr><td><a href="' + url + '" target="_blank">'+ basename + '</a></td></tr>'
elif source == 'sas_id':
sas_id = task.sas_id
results = "<h4>(Unique) Inspection Plots and Summary Logs for SAS_ID" + str(sas_id) + "</h4>"
results += "<p>Clicking a link will redirect to SURF SARA in a new browser window. </p>"
# keep a temporary list of filenames to check uniqueness
plot_files = []
tasks = Task.objects.filter(sas_id=sas_id)
for task in tasks:
results += 'Task <tr style="background-color:#7EB1C4"><td colspan="3"><b>' + str(task.id) + '</b></td></tr>'
plots = task.quality_json["plots"] plots = task.quality_json["plots"]
for plot in plots: for plot in plots:
basename = plot['basename'] basename = plot['basename']
plot_file = basename + str(plot['size'])
# only add unique files
if not plot_file in plot_files:
surl = plot['surl'] + "?action=show&authz=" + str(token) surl = plot['surl'] + "?action=show&authz=" + str(token)
url = surl.replace(translation[0], translation[1]) url = surl.replace(translation[0], translation[1])
results += '<tr><td><a href="' + url + '" target="_blank">' + basename + '</a></td></tr>' results += '<tr><td><a href="' + url + '" target="_blank">' + basename + '</a></td></tr>'
#results += '<tr><td><a href="' + url + '" target="_blank">' + basename + '</a></td><td>'+str(plot['size'])+'</td></tr>'
plot_files.append(plot_file)
return results return results
...@@ -713,10 +742,16 @@ def construct_summary(task): ...@@ -713,10 +742,16 @@ def construct_summary(task):
totals = "" totals = ""
results = "" results = ""
sas_id = task.sas_id
title = "<h4>Summary File for SAS_ID " + task.sas_id + "</h4> "
tasks = Task.objects.filter(sas_id=sas_id)
for task in tasks:
results += '<tr style="background-color:#7EB1C4"><td colspan="3"><b>Task ' + str(task.id) + '</b></td></tr>'
# find the plots in the quality json structure # find the plots in the quality json structure
try: try:
summary = task.quality_json["summary"] summary = task.quality_json["summary"]
title = "<h4>Summary File (for SAS_ID " + task.sas_id+ ")</h4> "
total_size_input = 0 total_size_input = 0
total_size_output = 0 total_size_output = 0
...@@ -728,7 +763,7 @@ def construct_summary(task): ...@@ -728,7 +763,7 @@ def construct_summary(task):
total_size_output+= record['output_size'] total_size_output+= record['output_size']
line = '' line = ''
line += '<tr style="background-color:#7EB1C4"><td colspan="3"><b>' + key + '</b></td></tr>' line += '<tr style="background-color:#7EB100"><td colspan="3"><b>' + key + '</b></td></tr>'
line += '<th></th><th>Name</th><th>Size</th>' line += '<th></th><th>Name</th><th>Size</th>'
line += '<tr><td><b>Input</b></td>' line += '<tr><td><b>Input</b></td>'
...@@ -740,46 +775,24 @@ def construct_summary(task): ...@@ -740,46 +775,24 @@ def construct_summary(task):
line += '<td>' + str(record['output_size']) + ' (' + record['output_size_str'] + ')</td>' line += '<td>' + str(record['output_size']) + ' (' + record['output_size_str'] + ')</td>'
line += '</tr>' line += '</tr>'
line += '<tr><td><b>Ratio</b></td>' line += '<tr><td><b>Ratio</b></td>'
line += '<td colspan="2">' + str(round(record['size_ratio'],2)) + '</td>' line += '<td colspan="2">' + str(round(record['size_ratio'],3)) + '</td>'
line += '</tr>' line += '</tr>'
try: try:
input_content = record['input_content'] added = record['added']
if input_content: if added:
line += '<th>Input Content</th>'
line += '<tr><td colspan="3">'
for filename in input_content:
line += filename + '\n'
line += '</td></tr>'
except:
pass
try:
output_content = record['output_content']
if output_content:
line += '<th>Output Content</th>'
line += '<tr><td colspan="3">'
for filename in output_content:
line += filename + '\n'
line += '</td></tr>'
except:
pass
try:
to_add = record['added']
if to_add:
line += '<th>Added</th>' line += '<th>Added</th>'
line += '<tr><td colspan="3">' line += '<tr><td colspan="3">'
for filename in to_add: for filename in added:
line += '<tr><td colspan="3">' + filename + '<td</tr>' line += '<tr><td colspan="3">' + filename + '<td</tr>'
except: except:
pass pass
try: try:
to_delete = record['deleted'] deleted = record['deleted']
if to_delete: if deleted:
line += '<th>Deleted</th>' line += '<th>Deleted</th>'
for filename in to_delete: for filename in deleted:
line += '<tr><td colspan="3">' +filename + '<td</tr>' line += '<tr><td colspan="3">' +filename + '<td</tr>'
except: except:
...@@ -787,16 +800,13 @@ def construct_summary(task): ...@@ -787,16 +800,13 @@ def construct_summary(task):
results += line results += line
try: except:
pass
totals += '<th>Totals</th><th></th><th></th>' totals += '<th>Totals</th><th></th><th></th>'
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>'
totals += '<tr><td colspan="2"><b>Ratio</b></td><td>' + str(round(total_size_output/total_size_input,2)) + '</td></tr>' totals += '<tr><td colspan="2"><b>Ratio</b></td><td>' + str(round(total_size_output / total_size_input, 3)) + '</td></tr>'
except:
pass
except:
pass
results = title + totals + results results = title + totals + results
return results return results
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
{% include 'taskdatabase/pagination.html' %} {% include 'taskdatabase/pagination.html' %}
</div> </div>
</div> </div>
<p class="footer"> Version 8 December 2022 - 16:00 <p class="footer"> Version 13 December 2022 - 13:00
</div> </div>
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
<p>Clicking a link will redirect to SURF SARA in a new browser window. </p>
<table class="table table-striped"> <table class="table table-striped">
{{ my_plots | safe }} {{ my_plots | safe }}
</table> </table>
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<td> <td>
<a class="open-modal btn btn-primary btn-sm" <a class="open-modal btn btn-primary btn-sm"
href="{% url 'inspection-plots' task.id my_tasks.number %}" href="{% url 'inspection-plots' task.id my_tasks.number %}"
data-popup-url="{% url 'inspection-plots' task.id my_tasks.number %}"> data-popup-url="{% url 'inspection-plots-sasid' task.id my_tasks.number %}">
<img src="{% static 'taskdatabase/surfsara.jpg' %}" height="20" alt="inspection plots"> <img src="{% static 'taskdatabase/surfsara.jpg' %}" height="20" alt="inspection plots">
</a>&nbsp; </a>&nbsp;
</td> </td>
......
...@@ -29,7 +29,9 @@ urlpatterns = [ ...@@ -29,7 +29,9 @@ urlpatterns = [
path('annotate_quality_sasid/<int:id>', views.AnnotateQualitySasId, name='annotate-quality-sasid'), path('annotate_quality_sasid/<int:id>', views.AnnotateQualitySasId, name='annotate-quality-sasid'),
path('annotate_quality_sasid/<int:id>/<page>', views.AnnotateQualitySasId, name='annotate-quality-sasid'), path('annotate_quality_sasid/<int:id>/<page>', views.AnnotateQualitySasId, name='annotate-quality-sasid'),
path('show_inspectionplots/<int:id>/<page>', views.ShowInspectionPlots, name='inspection-plots'), path('show_inspectionplots/<int:id>/<page>', views.ShowInspectionPlots, name='inspection-plots'),
path('show_summary/<int:id>/<page>', views.ShowSummary, name='summary'), path('show_inspectionplots_sasid/<int:id>/<page>', views.ShowInspectionPlotsSasId, name='inspection-plots-sasid'),
path('show_summary/<int:id>/<page>', views.ShowSummarySasId, name='summary'),
path('show-inputs/<int:id>/', views.ShowInputs, name='show-inputs'), path('show-inputs/<int:id>/', views.ShowInputs, name='show-inputs'),
path('show-outputs/<int:id>/', views.ShowOutputs, name='show-outputs'), path('show-outputs/<int:id>/', views.ShowOutputs, name='show-outputs'),
......
...@@ -561,6 +561,7 @@ def AnnotateQualityTaskId(request, id=0, page=0): ...@@ -561,6 +561,7 @@ def AnnotateQualityTaskId(request, id=0, page=0):
def AnnotateQualitySasId(request, id=0, page=0): def AnnotateQualitySasId(request, id=0, page=0):
# a POST means that the form is filled in and should be stored in the database # a POST means that the form is filled in and should be stored in the database
if request.method == "POST": if request.method == "POST":
form = QualityAnnotationForm(request.POST) form = QualityAnnotationForm(request.POST)
...@@ -603,11 +604,21 @@ def ShowInspectionPlots(request, id=0, page=0): ...@@ -603,11 +604,21 @@ def ShowInspectionPlots(request, id=0, page=0):
task = Task.objects.get(id=id) task = Task.objects.get(id=id)
# convert the path to a url # convert the path to a url
plots_html = algorithms.construct_inspectionplots(task) plots_html = algorithms.construct_inspectionplots(task, source='task_id')
return render(request, "taskdatabase/validation/inspection_plots.html", {'task': task, 'my_plots': plots_html})
def ShowInspectionPlotsSasId(request, id=0, page=0):
# a GET means that the form should be presented to be filled in
task = Task.objects.get(id=id)
# convert the path to a url
plots_html = algorithms.construct_inspectionplots(task, source='sas_id')
return render(request, "taskdatabase/validation/inspection_plots.html", {'task': task, 'my_plots': plots_html}) return render(request, "taskdatabase/validation/inspection_plots.html", {'task': task, 'my_plots': plots_html})
def ShowSummary(request, id=0, page=0): def ShowSummarySasId(request, id=0, page=0):
# a GET means that the form should be presented to be filled in # a GET means that the form should be presented to be filled in
task = Task.objects.get(id=id) task = Task.objects.get(id=id)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment