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

cleanup code (remove old code)

parent 955df77d
No related branches found
No related tags found
1 merge request!341SDC-1188 - final merge
Pipeline #72628 passed
......@@ -202,8 +202,7 @@ class Task(models.Model):
tasks_for_this_sasid = Task.objects.filter(sas_id=self.sas_id)
self.calculated_qualities = qualities.calculate_qualities(self, tasks_for_this_sasid, quality_thresholds)
# make sure that every task has an activity (backward compatibility)
# TODO: uncomment to enable SDC-1188 functionality for deploy STEP 2
# make sure that every task has an activity (also for backward compatibility)
associate_task_with_activity(self)
# remark:
......@@ -340,25 +339,6 @@ class Task(models.Model):
except:
return None
# keep the old mechanism in comments to test/evaluate
# TODO: remove when it is no longer used by the GUI
# --- <CUT> ---
@property
def sas_id_has_archived(self):
"""
check if any task belonging to this sas_id already has an output SAS_ID at the LTA
"""
try:
for task in Task.objects.filter(sas_id=self.sas_id):
try:
if task.archive['sas_id_archived']:
return task.archive['sas_id_archived']
except:
pass
except:
return None
# --- </CUT> ---
@property
def path_to_lta(self):
"""
......@@ -369,98 +349,6 @@ class Task(models.Model):
except:
return None
# keep the old mechanism in comments to test/evaluate, remove later when it works
# TODO: remove when it is no longer used by the GUI
# ---- <CUT> ----
@property
def sasid_path_to_lta(self):
"""
check if any task belonging to this sas_id already has a 'path_to_lta' setting
"""
try:
for task in Task.objects.filter(sas_id=self.sas_id):
try:
if task.archive['path_to_lta']:
return task.archive['path_to_lta']
except:
# if 'path_to_lta' is not found, or 'archive' is empty, continue to the next task
pass
except:
return None
@property
def sasid_is_verified(self):
for task in Task.objects.filter(sas_id=self.sas_id):
if task.status not in verified_statusses:
return False
return True
@property
def sasid_finished_fraction(self):
size_archived = 0
size_remaining = 0
total_size = 0
tasks = Task.objects.filter(sas_id=self.sas_id)
for task in tasks:
if task.status == State.FINISHED.value:
size_archived = size_archived + task.size_to_process
else:
size_remaining = size_remaining + task.size_to_process
total_size = total_size + task.size_to_process
finished = {}
try:
finished['fraction'] = round((size_archived / (size_remaining + size_archived)) * 100)
except:
finished['fraction'] = -1
finished['total_size'] = total_size
finished['remaining'] = size_remaining
return finished
@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, 'finishing': 0, 'finished': 0,
'suspended': 0,'discarded': 0, 'archived_failed': 0, 'finished_failed': 0}
tasks = Task.objects.filter(sas_id=self.sas_id)
for task in tasks:
try:
statusses[task.status] += 1
except:
pass
incomplete = int(statusses['scrubbed']) + int(statusses['archiving']) + int(statusses['finishing']) +\
int(statusses['suspended']) + int(statusses['archived_failed']) + int(statusses['finished_failed'])
complete = int(statusses['archived']) + int(statusses['finished'])
completion = round(complete / (incomplete + complete) * 100)
non_zero_statusses = {key: value for key, value in statusses.items() if value != 0}
result['status'] = non_zero_statusses
result['completion'] = completion
return result
# ---- </CUT> ----
@property
def task_type_join(self):
try:
......
......@@ -65,7 +65,6 @@ def handle_post_save(sender, **kwargs):
"""
task = kwargs.get('instance')
# TODO: uncomment to enable SDC-1188 functionality
update_activity(task)
......
......@@ -52,19 +52,6 @@
{{ task.sas_id }}
</td>
<td>
<!-- keep the old mechanism in comments to test/evaluate, remove later when it works
{% if task.sas_id_archived != None %}
<a href={{ task.path_to_lta }} target="_blank">
<img src="{% static 'taskdatabase/ldvlogo_small.png' %}" height="20" alt="link to LTA">
{{ task.sas_id_archived }}
</a>&nbsp;
{% else %}
-
{% endif %}
-->
<!-- new activity mechanism, to enable SDC-1188 -->
{% if task.activity.archive.sas_id_archived != None %}
<a href={{ task.path_to_lta }} target="_blank">
<img src="{% static 'taskdatabase/ldvlogo_small.png' %}" height="20" alt="link to LTA">
......@@ -73,7 +60,6 @@
{% else %}
-
{% endif %}
</td>
<td>
......
......@@ -34,18 +34,10 @@
<td>{{ task.project }}</td>
<td>{{ task.sas_id }}</td>
<td>{{ task.filter }} </td>
<!-- keep the old mechanism in comments to test/evaluate, remove later when it works
<td>{{ task.sasid_finished_fraction.fraction }}% of {{ task.sasid_finished_fraction.total_size|filesizeformat }}</td>
<td>{{ task.size_to_process|filesizeformat }} / {{ task.sasid_finished_fraction.remaining|filesizeformat }}</td>
-->
<!-- new activity mechanism, to enable SDC-1188 -->
<td>{{ task.activity.finished_fraction }}% of {{ task.activity.total_size|filesizeformat }}</td>
<td>{{ task.size_to_process|filesizeformat }} / {{ task.activity.remaining|filesizeformat }}</td>
<td>
{% include "taskdatabase/failures/retry_buttons.html" %}
{% if task.stageit_url != None %}
......
......@@ -31,7 +31,7 @@
{% include 'taskdatabase/pagination.html' %}
</div>
</div>
<p class="footer"> Version 17 Feb 2024
<p class="footer"> Version 19 Feb 2024
</div>
{% include 'taskdatabase/refresh.html' %}
......
......@@ -23,24 +23,6 @@
<a href="{% url 'task-change-priority-sasid' task.pk '10' my_tasks.number %}" class="btn btn-warning btn-sm" role="button">+10</a>
{% endif %}
</td>
<!-- keep the old mechanism in comments to test/evaluate, remove later when it works
<td>{{ task.sasid_ingested_fraction.status }}</td>
<td>{{ task.sasid_ingested_fraction.completion }}%</td>
<td>
{% if task.sas_id_has_archived != None %}
<a href={{ task.sasid_path_to_lta }} target="_blank">
<img src="{% static 'taskdatabase/ldvlogo_small.png' %}" height="20" alt="link to LTA">
{{ task.sas_id_has_archived }}
</a>&nbsp;
{% else %}
-
{% endif %}
</td>
-->
<!-- new activity mechanism, to enable SDC-1188 -->
<td>{{ task.activity.ingestq_status }}</td>
<td>{{ task.activity.ingested_fraction }}%</td>
<td>
......
......@@ -69,13 +69,7 @@
{% endif %}
</td>
<!-- keep the old mechanism in comments to test/evaluate, remove later when it works
<td class="{{ task.calculated_qualities.per_sasid }}">{{ task.calculated_qualities.per_sasid|default_if_none:"-" }}</td>
-->
<!-- new activity mechanism, to enable SDC-1188 -->
<td class="{{ task.activity.calculated_quality }}">{{ task.activity.calculated_quality|default_if_none:"-" }}</td>
<td class="{{ task.quality }}">{{ task.quality|default_if_none:"-" }}</td>
<td>{% include "taskdatabase/validation/validation_buttons.html" %}</td>
<td><a href="{% url 'task-discard-view-sasid' task.pk 'discard' my_tasks.number %}" class="btn btn-danger btn-sm" role="button"><i class="fas fa-trash-alt"></i></a></td>
......
<!-- keep the old mechanism in comments to test/evaluate, remove later when it works
{% if task.sasid_is_verified %}
<a href="{% url 'task-validate-sasid' task.pk 'poor' 'validated' my_tasks.number %}" class="btn btn-danger btn-sm" role="button"><i class="fas fa-check"></i> P</a>
{% endif %}
{% if task.sasid_is_verified %}
<a href="{% url 'task-validate-sasid' task.pk 'moderate' 'validated' my_tasks.number %}" class="btn btn-warning btn-sm" role="button"><i class="fas fa-check"></i> M</a>
{% endif %}
{% if task.sasid_is_verified %}
<a href="{% url 'task-validate-sasid' task.pk 'good' 'validated' my_tasks.number %}" class="btn btn-success btn-sm" role="button"><i class="fas fa-check"></i> G</a>
{% endif %}
{% if task.sasid_is_verified %}
<a href="{% url 'task-validate-sasid' task.pk 'calculated' 'validated' my_tasks.number %}" class="btn btn-success btn-sm" role="button"><i class="fas fa-check"></i> Validate</a>
{% endif %}
-->
<!-- new activity mechanism, to enable SDC-1188 -->
{% if task.activity.is_verified %}
<a href="{% url 'task-validate-sasid' task.pk 'poor' 'validated' my_tasks.number %}" class="btn btn-danger btn-sm" role="button"><i class="fas fa-check"></i> P</a>
{% endif %}
......
......@@ -20,15 +20,15 @@ class TestIngestFraction(TestCase):
Task.objects.get_or_create(filter='a',sas_id=54321, status='scrubbed', workflow=workflow_requantisation)
Task.objects.get_or_create(filter='b',sas_id=54321, status='scrubbed', workflow=workflow_requantisation)
# def test_ingest_fraction(self):
#
# # collapse all tasks into a single task for this sas_id
# task = Task.objects.filter(sas_id=54321).distinct('sas_id')[0]
# task.save()
#
# # get the list of statusses and level of completion
# statusses = task.activity.ingestq_status
# completion = task.activity.ingested_fraction
#
# self.assertEqual(statusses, {'scrubbed': 2, 'archiving': 1, 'archived': 1, 'finishing': 1, 'finished': 2, 'discarded': 1, 'archived_failed': 1})
# self.assertEqual(completion,38)
def test_ingest_fraction(self):
# collapse all tasks into a single task for this sas_id
task = Task.objects.filter(sas_id=54321).distinct('sas_id')[0]
task.save()
# get the list of statusses and level of completion
statusses = task.activity.ingestq_status
completion = task.activity.ingested_fraction
self.assertEqual(statusses, {'scrubbed': 2, 'archiving': 1, 'archived': 1, 'finishing': 1, 'finished': 2, 'discarded': 1, 'archived_failed': 1})
self.assertEqual(completion,38)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment