From 9cc1a721fea5615e7eea6c1ce1db5b80aa667219 Mon Sep 17 00:00:00 2001
From: Nico Vermaas <vermaas@astron.nl>
Date: Fri, 19 Mar 2021 15:00:57 +0100
Subject: [PATCH] highlight max value

---
 atdb/atdb/static/taskdatabase/style.css       | 10 +++++++
 atdb/taskdatabase/services/algorithms.py      | 28 ++++++++++++++++++-
 .../static/taskdatabase/style.css             |  6 +++-
 3 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/atdb/atdb/static/taskdatabase/style.css b/atdb/atdb/static/taskdatabase/style.css
index 3eb74069..d466ffd8 100644
--- a/atdb/atdb/static/taskdatabase/style.css
+++ b/atdb/atdb/static/taskdatabase/style.css
@@ -59,6 +59,16 @@ p.title {
    font-size: 13pt;
 }
 
+.info {
+   background-color: #E0F8F8;
+}
+
+.max {
+   font-weight: bold;
+   color: darkgray;
+   background-color: lightgreen;
+}
+
 .form-signin {
   width: 100%;
   max-width: 330px;
diff --git a/atdb/taskdatabase/services/algorithms.py b/atdb/taskdatabase/services/algorithms.py
index f3f5d53b..1a9dcec7 100644
--- a/atdb/taskdatabase/services/algorithms.py
+++ b/atdb/taskdatabase/services/algorithms.py
@@ -335,6 +335,25 @@ def human_readable(size_in_bytes):
         return "0"
 
 
+def highlight_value(values, value_to_highlight):
+
+    # find 'class' left of the value
+    pos_value = values.find(str(value_to_highlight))
+
+    # split up the values, left and right of the search area
+    part1 = values[:pos_value - 15]
+    part2 = values[pos_value:]
+
+    substring = values[pos_value - 15:pos_value]
+    if 'inactive' in substring:
+        new_substring = substring.replace('inactive', 'max')
+    else:
+        new_substring = substring.replace('active', 'max')
+
+    values = part1 + new_substring + part2
+
+    return values
+
 def construct_tasks_per_workflow_html(request, workflow_results):
 
     # --- Progress of tasks per active workflow ---
@@ -369,15 +388,19 @@ def construct_tasks_per_workflow_html(request, workflow_results):
         values += "<td colspan='8'></td></tr><tr>"
 
         d = workflow_result['nr_of_tasks_per_status']
+        max = 0
 
         for key in d:
+
             try:
                 percentage = round(int(d[key]) / int(workflow_result['nr_of_tasks']) * 100)
+                if (percentage > max) and (key in settings.ALL_STATUSSES):
+                    max = percentage
             except:
                 percentage = 0
 
             # distinguish active statusses
-            style = ""
+            style = "inactive"
             if key in settings.ACTIVE_STATUSSES or key=='active':
                 style = "active"
 
@@ -394,6 +417,9 @@ def construct_tasks_per_workflow_html(request, workflow_results):
 #        values += "<td>" + str(human_readable(workflow_result['size_processed'])) + " ("+ str(percentage) + "%) </td>"
 #        values += "<td>" + str(workflow_result['total_processing_time']) + "</td>"
 
+        if max>0:
+            values = highlight_value(values, max)
+
         results_tasks += "</tr><tr>" + values + "</tr>"
 
     results_tasks = "<tbody>" + results_tasks + "</tbody>"
diff --git a/atdb/taskdatabase/static/taskdatabase/style.css b/atdb/taskdatabase/static/taskdatabase/style.css
index cd37610d..6ad92e4f 100644
--- a/atdb/taskdatabase/static/taskdatabase/style.css
+++ b/atdb/taskdatabase/static/taskdatabase/style.css
@@ -60,9 +60,13 @@ p.title {
 }
 
 .info {
-   font-size: 13pt;
    background-color: #E0F8F8;
 }
+.max {
+   font-weight: bold;
+   color: green;
+   background-color: lightgreen;
+}
 
 .form-signin {
   width: 100%;
-- 
GitLab