Skip to content
Snippets Groups Projects
Commit 0ecd38aa authored by Mattia Mancini's avatar Mattia Mancini
Browse files

Add static rendering of input output objects

parent 0f803d03
No related branches found
No related tags found
4 merge requests!143Query Page:,!125Master,!123Master,!122Add static rendering of input output objects
...@@ -16,6 +16,7 @@ DJANGO_TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" ...@@ -16,6 +16,7 @@ DJANGO_TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@timeit @timeit
def get_size(status_list, type): def get_size(status_list, type):
""" """
...@@ -100,6 +101,48 @@ def convert_list_of_dicts_to_html(my_blob): ...@@ -100,6 +101,48 @@ def convert_list_of_dicts_to_html(my_blob):
return results return results
import xml.etree.ElementTree as ElementTree
from typing import Union, List, Dict
def _generate_html_from_json_tree(json_blob: Union[List, Dict], element: ElementTree.Element):
if isinstance(json_blob, list) or isinstance(json_blob, tuple):
if element.tag != 'tbody':
sub_table = ElementTree.SubElement(element, 'table')
else:
sub_table = element
for item in json_blob:
row = ElementTree.SubElement(sub_table, 'tr')
element = ElementTree.SubElement(row, 'td')
_generate_html_from_json_tree(item, element)
elif isinstance(json_blob, dict):
if element.tag != 'tbody':
sub_table = ElementTree.SubElement(element, 'table')
else:
sub_table = element
for key, value in json_blob.items():
row = ElementTree.SubElement(sub_table, 'tr')
key_element = ElementTree.SubElement(row, 'td')
bold_key = ElementTree.SubElement(key_element, 'b')
bold_key.text = key
value_element = ElementTree.SubElement(row, 'td')
_generate_html_from_json_tree(value, value_element)
else:
value = ElementTree.SubElement(element, 'td', attrib={"style": "max-width:25rem"})
value.text = str(json_blob)
def convert_json_to_nested_table(json_blob):
root_element = ElementTree.Element('tbody')
_generate_html_from_json_tree(json_blob, root_element)
return ElementTree.tostring(root_element, method='xml').decode()
def convert_config_to_html(querylist): def convert_config_to_html(querylist):
results = "" results = ""
try: try:
...@@ -116,7 +159,8 @@ def convert_config_to_html(querylist): ...@@ -116,7 +159,8 @@ def convert_config_to_html(querylist):
except: except:
pass pass
line = "<tr><td><b>" + str(filter) + "</b></td> <td><b>" + str(key) + "</b></td><td>" + str(value) + "</td></tr>" line = "<tr><td><b>" + str(filter) + "</b></td> <td><b>" + str(key) + "</b></td><td>" + str(
value) + "</td></tr>"
results = results + line results = results + line
except: except:
results = "<tr><td>no data</td></tr>" results = "<tr><td>no data</td></tr>"
...@@ -126,7 +170,6 @@ def convert_config_to_html(querylist): ...@@ -126,7 +170,6 @@ def convert_config_to_html(querylist):
# aggregate information from the tasks table per workflow per status # aggregate information from the tasks table per workflow per status
def aggregate_resources_tasks(selection): def aggregate_resources_tasks(selection):
workflow_results = [] workflow_results = []
my_workflows = [] my_workflows = []
...@@ -248,7 +291,6 @@ def aggregate_resources_logs(selection): ...@@ -248,7 +291,6 @@ def aggregate_resources_logs(selection):
# aggregate information from the logentries table per workflow per status # aggregate information from the logentries table per workflow per status
def aggregate_resources_logs_version1(): def aggregate_resources_logs_version1():
records = [] records = []
# get all active tasks # get all active tasks
...@@ -344,7 +386,6 @@ def human_readable(size_in_bytes): ...@@ -344,7 +386,6 @@ def human_readable(size_in_bytes):
def highlight_value(values, value_to_highlight): def highlight_value(values, value_to_highlight):
# find 'class' left of the value # find 'class' left of the value
pos_value = values.find(str(value_to_highlight)) pos_value = values.find(str(value_to_highlight))
...@@ -362,8 +403,8 @@ def highlight_value(values, value_to_highlight): ...@@ -362,8 +403,8 @@ def highlight_value(values, value_to_highlight):
return values return values
def construct_tasks_per_workflow_html(request, workflow_results):
def construct_tasks_per_workflow_html(request, workflow_results):
# --- Progress of tasks per active workflow --- # --- Progress of tasks per active workflow ---
results_tasks = "<p>Progress of tasks per workflow</p>" results_tasks = "<p>Progress of tasks per workflow</p>"
...@@ -390,7 +431,8 @@ def construct_tasks_per_workflow_html(request, workflow_results): ...@@ -390,7 +431,8 @@ def construct_tasks_per_workflow_html(request, workflow_results):
percentage = round(int(workflow_result['size_processed']) / int(workflow_result['size_to_process']) * 100) percentage = round(int(workflow_result['size_processed']) / int(workflow_result['size_to_process']) * 100)
except: except:
percentage = 0 percentage = 0
values += "<td><b>size processed:</b> " + str(human_readable(workflow_result['size_processed'])) + " (<b>"+ str(percentage) + "%</b>) </td>" values += "<td><b>size processed:</b> " + str(
human_readable(workflow_result['size_processed'])) + " (<b>" + str(percentage) + "%</b>) </td>"
values += "<td><b>processing time:</b> " + str(workflow_result['total_processing_time']) + "</td>" values += "<td><b>processing time:</b> " + str(workflow_result['total_processing_time']) + "</td>"
values += "<td colspan='8'></td></tr><tr>" values += "<td colspan='8'></td></tr><tr>"
...@@ -502,7 +544,6 @@ def construct_logs_per_workflow_html(request, workflow_results): ...@@ -502,7 +544,6 @@ def construct_logs_per_workflow_html(request, workflow_results):
def construct_dashboard_html(request, selection): def construct_dashboard_html(request, selection):
# gather and construct the dashboard based on the requested selection # gather and construct the dashboard based on the requested selection
# --- Progress of tasks per active workflow --- # --- Progress of tasks per active workflow ---
...@@ -516,4 +557,3 @@ def construct_dashboard_html(request, selection): ...@@ -516,4 +557,3 @@ def construct_dashboard_html(request, selection):
results_logs = construct_logs_per_workflow_html(request, log_records) results_logs = construct_logs_per_workflow_html(request, log_records)
return results_tasks, results_logs return results_tasks, results_logs
...@@ -7,37 +7,10 @@ ...@@ -7,37 +7,10 @@
<div class="card-body"> <div class="card-body">
<h3>Inputs </h3> <h3>Inputs </h3>
<table class="table table-striped"> <table class="table table-striped">
<tbody id="inputs_table"> <tbody>
{{ results | safe }}
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
<script>
var inputs_values = {{ resultsjson | safe }}
function generate_tree(tree, div) {
if (Array.isArray(tree)) {
var array = $("<tbody></tbody>")
div.append(array)
for (let row_index in tree) {
var row = $('<tr></tr>')
generate_tree(tree[row_index], row)
array.append(row)
}
} else if (typeof (tree) === 'object' && tree !== null) {
for (var att_name in tree) {
var row = $(`<tr><td><b>${att_name}</b></td></tr>`)
generate_tree(tree[att_name], row);
div.append(
row
)
}
} else {
div.append(`<td>${tree}</td>`)
}
}
generate_tree(inputs_values, $('#inputs_table'))
</script>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -6,39 +6,9 @@ ...@@ -6,39 +6,9 @@
<div class="card-body"> <div class="card-body">
<h3>Outputs </h3> <h3>Outputs </h3>
<table class="table table-striped"> <table class="table table-striped">
<tbody id="output_values"> {{ results | safe }}
</tbody>
</table> </table>
</div> </div>
</div> </div>
<script>
var output_values = {{ resultsjson | safe }}
function generate_tree(tree, div) {
if (Array.isArray(tree)) {
var array = $("<tbody></tbody>")
div.append(array)
for (let row_index in tree) {
var row = $('<tr></tr>')
generate_tree(tree[row_index], row)
array.append(row)
}
} else if (typeof (tree) === 'object' && tree !== null) {
for (var att_name in tree) {
var row = $(`<tr><td><b>${att_name}</b></td></tr>`)
generate_tree(tree[att_name], row);
div.append(
row
)
}
} else {
div.append(`<td>${tree}</td>`)
}
}
generate_tree(output_values, $('#output_values'))
</script>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -266,16 +266,16 @@ def ShowInputs(request, id): ...@@ -266,16 +266,16 @@ def ShowInputs(request, id):
task = Task.objects.get(id=id) task = Task.objects.get(id=id)
# convert the json to a presentable piece of html for the output template # convert the json to a presentable piece of html for the output template
results = algorithms.convert_list_of_dicts_to_html(task.inputs) results = algorithms.convert_json_to_nested_table(task.inputs)
return render(request, "taskdatabase/details/inputs.html", {'results': results, 'resultsjson': task.inputs}) return render(request, "taskdatabase/details/inputs.html", {'results': results})
def ShowOutputs(request, id): def ShowOutputs(request, id):
task = Task.objects.get(id=id) task = Task.objects.get(id=id)
# convert the json to a presentable piece of html for the output template # convert the json to a presentable piece of html for the output template
results = algorithms.convert_list_of_dicts_to_html(task.outputs) results = algorithms.convert_json_to_nested_table(task.outputs)
return render(request, "taskdatabase/details/outputs.html", {'results': results, 'resultsjson': task.outputs})
return render(request, "taskdatabase/details/outputs.html", {'results': results})
def ShowMetrics(request, id): def ShowMetrics(request, id):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment