diff --git a/atdb/taskdatabase/services/algorithms.py b/atdb/taskdatabase/services/algorithms.py index ec93aaf8d45897e556c6c3d9aa62e42ebed9ffe5..c692e2003c5065419cc2e1b5d71361cbacb542dc 100644 --- a/atdb/taskdatabase/services/algorithms.py +++ b/atdb/taskdatabase/services/algorithms.py @@ -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())) -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</h4>" - results += "<p>Clicking a link will redirect to SURF SARA in a new browser window. </p>" - # translate the path to a url try: @@ -696,13 +693,45 @@ def construct_inspectionplots(task): translation = srm_to_url.split("::") # find the plots in the quality json structure - plots = task.quality_json["plots"] - for plot in plots: - basename = plot['basename'] - surl = plot['surl'] + "?action=show&authz=" + str(token) + 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) - url = surl.replace(translation[0],translation[1]) - results += '<tr><td><a href="' + url + '" target="_blank">'+ basename + '</a></td></tr>' + 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"] + + for plot in plots: + 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) + + 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><td>'+str(plot['size'])+'</td></tr>' + plot_files.append(plot_file) return results @@ -713,90 +742,71 @@ def construct_summary(task): totals = "" results = "" - # find the plots in the quality json structure - try: - summary = task.quality_json["summary"] - title = "<h4>Summary File (for SAS_ID " + task.sas_id+ ")</h4> " - - total_size_input = 0 - total_size_output = 0 - - for key in summary: - record = summary[key] - - total_size_input += record['input_size'] - total_size_output+= record['output_size'] - - line = '' - line += '<tr style="background-color:#7EB1C4"><td colspan="3"><b>' + key + '</b></td></tr>' - - line += '<th></th><th>Name</th><th>Size</th>' - line += '<tr><td><b>Input</b></td>' - line += '<td>' + record['input_name'] + '</td>' - line += '<td>' + str(record['input_size']) + ' (' + record['input_size_str'] + ')</td>' - line += '</tr>' - line += '<tr><td><b>Output</b></td>' - line += '<td>' + record['output_name'] + '</td>' - line += '<td>' + str(record['output_size']) + ' (' + record['output_size_str'] + ')</td>' - line += '</tr>' - line += '<tr><td><b>Ratio</b></td>' - line += '<td colspan="2">' + str(round(record['size_ratio'],2)) + '</td>' - line += '</tr>' + sas_id = task.sas_id + title = "<h4>Summary File for SAS_ID " + task.sas_id + "</h4> " - try: - input_content = record['input_content'] - if input_content: - line += '<th>Input Content</th>' - line += '<tr><td colspan="3">' - for filename in input_content: - line += filename + '\n' - line += '</td></tr>' - except: - pass + 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>' - 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 + # find the plots in the quality json structure + try: + summary = task.quality_json["summary"] - try: - to_add = record['added'] - if to_add: - line += '<th>Added</th>' - line += '<tr><td colspan="3">' - for filename in to_add: - line += '<tr><td colspan="3">' + filename + '<td</tr>' - except: - pass + total_size_input = 0 + total_size_output = 0 - try: - to_delete = record['deleted'] - if to_delete: - line += '<th>Deleted</th>' - for filename in to_delete: - line += '<tr><td colspan="3">' +filename + '<td</tr>' + for key in summary: + record = summary[key] - except: - pass + total_size_input += record['input_size'] + total_size_output+= record['output_size'] - results += line + line = '' + line += '<tr style="background-color:#7EB100"><td colspan="3"><b>' + key + '</b></td></tr>' - try: - 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>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>' + line += '<th></th><th>Name</th><th>Size</th>' + line += '<tr><td><b>Input</b></td>' + line += '<td>' + record['input_name'] + '</td>' + line += '<td>' + str(record['input_size']) + ' (' + record['input_size_str'] + ')</td>' + line += '</tr>' + line += '<tr><td><b>Output</b></td>' + line += '<td>' + record['output_name'] + '</td>' + line += '<td>' + str(record['output_size']) + ' (' + record['output_size_str'] + ')</td>' + line += '</tr>' + line += '<tr><td><b>Ratio</b></td>' + line += '<td colspan="2">' + str(round(record['size_ratio'],3)) + '</td>' + line += '</tr>' + + try: + added = record['added'] + if added: + line += '<th>Added</th>' + line += '<tr><td colspan="3">' + for filename in added: + line += '<tr><td colspan="3">' + filename + '<td</tr>' + except: + pass + + try: + deleted = record['deleted'] + if deleted: + line += '<th>Deleted</th>' + for filename in deleted: + line += '<tr><td colspan="3">' +filename + '<td</tr>' + + except: + pass + + results += line except: pass - except: - pass + + 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>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, 3)) + '</td></tr>' results = title + totals + results return results diff --git a/atdb/taskdatabase/templates/taskdatabase/index.html b/atdb/taskdatabase/templates/taskdatabase/index.html index 74d76183b1af79fc7d51d55ad5390c1ea4d12a7c..ef3d25afc562727c6aef6c39d0e09d5128237c8e 100644 --- a/atdb/taskdatabase/templates/taskdatabase/index.html +++ b/atdb/taskdatabase/templates/taskdatabase/index.html @@ -34,7 +34,7 @@ {% include 'taskdatabase/pagination.html' %} </div> </div> - <p class="footer"> Version 8 December 2022 - 16:00 + <p class="footer"> Version 13 December 2022 - 13:00 </div> diff --git a/atdb/taskdatabase/templates/taskdatabase/validation/inspection_plots.html b/atdb/taskdatabase/templates/taskdatabase/validation/inspection_plots.html index 066c080b268b7478bfd70e5f940e1da49bbf9e7c..fa948a08e1be5ee01881a68c91a405a64d79ab76 100644 --- a/atdb/taskdatabase/templates/taskdatabase/validation/inspection_plots.html +++ b/atdb/taskdatabase/templates/taskdatabase/validation/inspection_plots.html @@ -5,7 +5,6 @@ <div class="card"> <div class="card-body"> - <p>Clicking a link will redirect to SURF SARA in a new browser window. </p> <table class="table table-striped"> {{ my_plots | safe }} </table> diff --git a/atdb/taskdatabase/templates/taskdatabase/validation/tasks_validation.html b/atdb/taskdatabase/templates/taskdatabase/validation/tasks_validation.html index 196bbd6f54ac5a3e068466757f375c4f380083cc..4dde5827bcc4b0c8684c0fcad31dce92047ee3ac 100644 --- a/atdb/taskdatabase/templates/taskdatabase/validation/tasks_validation.html +++ b/atdb/taskdatabase/templates/taskdatabase/validation/tasks_validation.html @@ -19,7 +19,7 @@ <td> <a class="open-modal btn btn-primary btn-sm" 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"> </a> </td> diff --git a/atdb/taskdatabase/urls.py b/atdb/taskdatabase/urls.py index 09dba0c2ee01e58fd829fd24912c674ab72cd49e..b5b585a5ab6439a49b68cc5a7288018f0a0b99ba 100644 --- a/atdb/taskdatabase/urls.py +++ b/atdb/taskdatabase/urls.py @@ -29,7 +29,9 @@ urlpatterns = [ 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('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-outputs/<int:id>/', views.ShowOutputs, name='show-outputs'), diff --git a/atdb/taskdatabase/views.py b/atdb/taskdatabase/views.py index a030b977cb6f5566580f638d434ac37da4c71642..b15cce1dc1e3741941be271a21736c33bd964b4e 100644 --- a/atdb/taskdatabase/views.py +++ b/atdb/taskdatabase/views.py @@ -561,6 +561,7 @@ def AnnotateQualityTaskId(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 + if request.method == "POST": form = QualityAnnotationForm(request.POST) @@ -603,11 +604,21 @@ def ShowInspectionPlots(request, id=0, page=0): task = Task.objects.get(id=id) # 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}) -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 task = Task.objects.get(id=id)