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

adding get_size endpoint

parent 472e8078
No related branches found
No related tags found
No related merge requests found
Pipeline #8741 passed
atdb/docs/ATDB-LDV Workflow Diagram.png

102 KiB | W: | H:

atdb/docs/ATDB-LDV Workflow Diagram.png

107 KiB | W: | H:

atdb/docs/ATDB-LDV Workflow Diagram.png
atdb/docs/ATDB-LDV Workflow Diagram.png
atdb/docs/ATDB-LDV Workflow Diagram.png
atdb/docs/ATDB-LDV Workflow Diagram.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -52,6 +52,7 @@ class TaskWriteSerializer(serializers.ModelSerializer): ...@@ -52,6 +52,7 @@ class TaskWriteSerializer(serializers.ModelSerializer):
'stage_request_id', 'stage_request_id',
'status','new_status', 'status','new_status',
'inputs','outputs','metrics','status_history', 'inputs','outputs','metrics','status_history',
'size_to_process','size_processed','total_processing_time',
'log_entries' 'log_entries'
) )
...@@ -104,6 +105,7 @@ class TaskReadSerializer(serializers.ModelSerializer): ...@@ -104,6 +105,7 @@ class TaskReadSerializer(serializers.ModelSerializer):
'stage_request_id', 'stage_request_id',
'status','new_status', 'status','new_status',
'inputs','outputs','metrics','status_history', 'inputs','outputs','metrics','status_history',
'size_to_process', 'size_processed', 'total_processing_time',
'log_entries' 'log_entries'
) )
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
Description: Business logic for ATDB. These functions are called from the views (views.py). Description: Business logic for ATDB. These functions are called from the views (views.py).
""" """
from django.db.models import Sum from django.db.models import Q,Sum
import logging import logging
from .common import timeit from .common import timeit
from ..models import Task from ..models import Task
...@@ -24,11 +24,13 @@ def get_size(status_list): ...@@ -24,11 +24,13 @@ def get_size(status_list):
:return: summed sizes :return: summed sizes
""" """
logger.info("get_size("+status_list+")") logger.info("get_size("+str(status_list)+")")
#todo: implement
field = 'size_to_process'
query = field + '__sum' query = field + '__sum'
sum_value = Task.objects.filter(status__in=status_list).aggregate(Sum(field))[query] tasks = Task.objects.filter(status__in=status_list)
sum_value = tasks.aggregate(Sum(field))[query]
if sum_value == None: if sum_value == None:
sum_value = 0.0 sum_value = 0.0
return sum_value return sum_value
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<th width="15%">Workflow</th> <th width="15%">Workflow</th>
<th>Created</th> <th>Created</th>
<th>Size</th> <th>size-to-process</th>
<th>Set Status</th> <th>Set Status</th>
</tr> </tr>
</thead> </thead>
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
</div> </div>
{% include 'taskdatabase/pagination.html' %} {% include 'taskdatabase/pagination.html' %}
</div> </div>
<p class="footer"> Version 1.0.0 (2 feb 2021 - 10:00) <p class="footer"> Version 1.0.0 (2 feb 2021 - 12:00)
<script type="text/javascript"> <script type="text/javascript">
(function(seconds) { (function(seconds) {
var refresh, var refresh,
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<td>{{ task.workflow }} <td>{{ task.workflow }}
<td>{{ task.creationTime|date:"Y-m-d H:i:s" }} </td> <td>{{ task.creationTime|date:"Y-m-d H:i:s" }} </td>
<td>{{ task.size|filesizeformat }} </td> <td>{{ task.size_to_process|filesizeformat }} </td>
</td> </td>
<td> <td>
......
...@@ -28,7 +28,7 @@ class TaskFilter(filters.FilterSet): ...@@ -28,7 +28,7 @@ class TaskFilter(filters.FilterSet):
model = Task model = Task
fields = { fields = {
'task_type': ['exact', 'icontains'], 'task_type': ['exact', 'icontains','in'],
'filter': ['exact', 'icontains'], 'filter': ['exact', 'icontains'],
'project': ['exact', 'icontains'], 'project': ['exact', 'icontains'],
'sas_id': ['exact', 'icontains'], 'sas_id': ['exact', 'icontains'],
...@@ -239,13 +239,20 @@ class GetSizeView(generics.ListAPIView): ...@@ -239,13 +239,20 @@ class GetSizeView(generics.ListAPIView):
# override list and generate a custom response # override list and generate a custom response
def list(self, request, *args, **kwargs): def list(self, request, *args, **kwargs):
# call the business logic query_params = dict(self.request.query_params)
status_list = ['defined','staged'] try:
status_in = query_params['status__in']
status_list=status_in[0].split(',')
print(status_list)
except:
# if no 'status__in=' is given, then use the default list
status_list = ['staged','processing','processed','validating','validate', 'ingesting', 'removing', 'removed']
size = algorithms.get_size(status_list) size = algorithms.get_size(status_list)
# return a response # return a response
return Response({ return Response({
'size': size, 'total_size': size,
}) })
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment