From 6b35a200da1180b69d25f95cb4850c3f9024ba02 Mon Sep 17 00:00:00 2001
From: Vermaas <vermaas@astron.nl>
Date: Tue, 9 Jan 2024 15:32:32 +0100
Subject: [PATCH] handling review comments

---
 atdb/taskdatabase/config.py                        |  1 -
 atdb/taskdatabase/models.py                        | 14 +++++++++++++-
 .../taskdatabase/ingest/filter_buttons.html        |  2 +-
 .../templates/taskdatabase/ingest/page.html        |  2 +-
 atdb/taskdatabase/tests/test_ingest_fraction.py    |  7 ++++---
 atdb/taskdatabase/urls.py                          |  2 +-
 atdb/taskdatabase/views.py                         |  6 +++---
 7 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/atdb/taskdatabase/config.py b/atdb/taskdatabase/config.py
index acfde381..f50b238a 100644
--- a/atdb/taskdatabase/config.py
+++ b/atdb/taskdatabase/config.py
@@ -1,4 +1,3 @@
-VERSION = "Version 1.0.0 (14 jan 2020)"
 TASKS_PER_PAGE = 50
 TASKS_PER_PAGE_SMALL = 10
 
diff --git a/atdb/taskdatabase/models.py b/atdb/taskdatabase/models.py
index a87d4146..b9eafb69 100644
--- a/atdb/taskdatabase/models.py
+++ b/atdb/taskdatabase/models.py
@@ -329,6 +329,18 @@ class Task(models.Model):
 
     @property
     def sasid_ingested_fraction(self):
+        """
+        This 'property' of a task returns the fraction of queued/ingested tasks per SAS_ID
+        and a list of statusses of other tasks belonging to the same SAS_ID.
+        It is implemented as 'property', because then it can be used in html pages like this:
+           <td>{{ task.sasid_ingested_fraction.status }}</td>
+           <td>{{ task.sasid_ingested_fraction.completion }}%</td>
+
+        A selection of statusses are considered 'queued', and another selection is considered 'ingested'.
+        The division of those 2 are returned as a 'completed %'.
+        A limited list of statusses for the other tasks that belong to this SAS_ID is also returned.
+
+        """
         result = {}
         statusses = {'scrubbed': 0, 'archiving': 0, 'archived': 0, 'finished': 0, 
                      'suspended': 0,'discarded': 0, 'archived_failed': 0, 'finished_failed': 0}
@@ -337,7 +349,7 @@ class Task(models.Model):
 
         for task in tasks:
             try:
-                statusses[task.status] = statusses[task.status] + 1
+                statusses[task.status] += 1
             except:
                 pass
 
diff --git a/atdb/taskdatabase/templates/taskdatabase/ingest/filter_buttons.html b/atdb/taskdatabase/templates/taskdatabase/ingest/filter_buttons.html
index 917aaa80..782d2ec1 100644
--- a/atdb/taskdatabase/templates/taskdatabase/ingest/filter_buttons.html
+++ b/atdb/taskdatabase/templates/taskdatabase/ingest/filter_buttons.html
@@ -16,7 +16,7 @@
              <tr>
                <td>
                    {% include "taskdatabase/ingest/clear_filter_button.html" %}
-                    <a href="{% url 'task-set-filter' 'scrubbed' 'ingest' %}" class="btn btn-secondary btn-sm" role="button">Queued</a>
+                    <a href="{% url 'task-set-filter' 'scrubbed' 'ingest' %}" class="btn btn-secondary btn-sm" role="button">Queued (scrubbed)</a>
                     <a href="{% url 'task-set-filter' 'archiving' 'ingest' %}" class="btn btn-secondary btn-sm" role="button"><i>Archiving</i></a>
 
                </td>
diff --git a/atdb/taskdatabase/templates/taskdatabase/ingest/page.html b/atdb/taskdatabase/templates/taskdatabase/ingest/page.html
index aeef24b3..cfcbcbd8 100644
--- a/atdb/taskdatabase/templates/taskdatabase/ingest/page.html
+++ b/atdb/taskdatabase/templates/taskdatabase/ingest/page.html
@@ -11,7 +11,7 @@
             <div class="col-12">
                 <h3>Ingest Queue</h3>
 
-                SAS_ID's with tasks <i>archiving</i> or queued (<i>scrubbed</i>) for ingest into LTA.
+                The ingest queue shows SASids with archiving and queued (scrubbed) tasks which are ingesting into the LTA
 
                 {% include 'taskdatabase/ingest/filter_buttons.html' %}&nbsp;
 
diff --git a/atdb/taskdatabase/tests/test_ingest_fraction.py b/atdb/taskdatabase/tests/test_ingest_fraction.py
index fbfd4eb1..9a48ae93 100644
--- a/atdb/taskdatabase/tests/test_ingest_fraction.py
+++ b/atdb/taskdatabase/tests/test_ingest_fraction.py
@@ -16,7 +16,8 @@ class TestIngestFraction(TestCase):
         Task.objects.get_or_create(filter='a',sas_id=54321, status='archived', workflow=workflow_requantisation)
         Task.objects.get_or_create(filter='a',sas_id=54321, status='finished', workflow=workflow_requantisation)
         Task.objects.get_or_create(filter='b',sas_id=54321, status='finished', workflow=workflow_requantisation)
-        Task.objects.get_or_create(filter='b', sas_id=54321, status='discarded', workflow=workflow_requantisation)
+        Task.objects.get_or_create(filter='a', sas_id=54321, status='discarded', workflow=workflow_requantisation)
+        Task.objects.get_or_create(filter='a', sas_id=54321, status='archived_failed', workflow=workflow_requantisation)
     def test_ingest_fraction(self):
 
         # collapse all tasks into a single task for this sas_id
@@ -26,5 +27,5 @@ class TestIngestFraction(TestCase):
         statusses = task.sasid_ingested_fraction['status']
         completion = task.sasid_ingested_fraction['completion']
 
-        self.assertEqual(statusses, {'scrubbed': 2, 'archiving': 1, 'archived': 1, 'finished': 2, 'discarded': 1})
-        self.assertEqual(completion,50)
+        self.assertEqual(statusses, {'scrubbed': 2, 'archiving': 1, 'archived': 1, 'finished': 2, 'discarded': 1, 'archived_failed': 1})
+        self.assertEqual(completion,43)
diff --git a/atdb/taskdatabase/urls.py b/atdb/taskdatabase/urls.py
index b2212002..f2926390 100644
--- a/atdb/taskdatabase/urls.py
+++ b/atdb/taskdatabase/urls.py
@@ -19,7 +19,7 @@ urlpatterns = [
     path('validation', views.ShowValidationPage.as_view(), name='validation'),
     path('failures', views.ShowFailuresPage.as_view(), name='failures'),
     path('discarded', views.ShowDiscardedPage.as_view(), name='discarded'),
-    path('ingest', views.ShowIngestPage.as_view(), name='ingest'),
+    path('ingest', views.ShowIngestQPage.as_view(), name='ingest'),
     path('finished', views.ShowFinishedPage.as_view(), name='finished'),
 
     path('task_details/<int:id>/<page>', views.TaskDetails, name='task-details'),
diff --git a/atdb/taskdatabase/views.py b/atdb/taskdatabase/views.py
index c6cb9235..c3d36016 100644
--- a/atdb/taskdatabase/views.py
+++ b/atdb/taskdatabase/views.py
@@ -442,7 +442,7 @@ class ShowDiscardedPage(ListView):
         return tasks
 
 
-class ShowIngestPage(ListView):
+class ShowIngestQPage(ListView):
     """
      This shows aggregated tasks per sas_id that are queued for ingest or archiving
      Note that the global filter is also applied
@@ -488,7 +488,7 @@ class ShowIngestPage(ListView):
 
 class ShowFinishedPage(ListView):
     """
-    This shows the tasks that are archived
+    This shows the tasks that are finished
     Note that the global filter is also applied
     """
     template_name = 'taskdatabase/archived/page.html'
@@ -1391,7 +1391,7 @@ def ChangePrioritySasID(request, pk, priority_change, page=0):
             task.priority = priority
             task.save()
 
-    return redirect('ingest')
+    return redirect_with_params('ingest', '?page=' + page)
 
 
 
-- 
GitLab