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

Merge branch 'SDC-470' into 'master'

SDC-470: Create api-function to retrieve the minimum start time and maximum...

See merge request !154
parents 6ae71ba4 89d778bd
No related branches found
No related tags found
4 merge requests!163SDC-470: Create api-function to retrieve the minimum start time and maximum...,!158SDC-470: Create api-function to retrieve the minimum start time and maximum...,!155SDC-470: Create api-function to retrieve the minimum start time and maximum...,!154SDC-470: Create api-function to retrieve the minimum start time and maximum...
Pipeline #24000 passed
...@@ -41,6 +41,34 @@ def get_size(status_list, type): ...@@ -41,6 +41,34 @@ def get_size(status_list, type):
return sum_value return sum_value
@timeit
def get_min_start_and_max_end_time(sas_id):
"""
Retrieve the minimum start time en maximum end time of a set of taskids (sas_id) which has the
status 'archived' or 'finished'
The start time is the moment when the task start 'processing'
The end time is the moment when the task was 'processed'
"""
min_start_time = None
max_end_time = None
logger.info("get_min_start_and_max_end_time(" + str(status_list) + ")")
tasks = Task.objects.filter(sas_id=sas_id).filter(status='archived') + Task.objects.filter(sas_id=sas_id).filter(status='finished')
for task in tasks:
# If more entrees are found for 'processing' task, get the latest
start_time = LogEntry.objects.filter(task=task.pk).filter(step_name='running').filter(status='processing').lastest('timestamp').timestamp
# If more entrees are found for 'processed' task, get the latest
end_time = LogEntry.objects.filter(task=task.pk).filter(step_name='running').filter(status='processed').lastest('timestamp').timestamp
if min_start_time is None:
min_start_time = start_time
elif start_time < min_start_time:
min_start_time = start_time
if max_end_time is None:
max_end_time = end_time
elif end_time > max_end_time:
max_end_time = end_time
return min_start_time, max_end_time
def convert_logentries_to_html(log_entries): def convert_logentries_to_html(log_entries):
results = "" results = ""
......
...@@ -54,6 +54,8 @@ urlpatterns = [ ...@@ -54,6 +54,8 @@ urlpatterns = [
# --- custom requests --- # --- custom requests ---
# /atdb/get_size?status__in=defined,staged # /atdb/get_size?status__in=defined,staged
path('tasks/get_size/', views.GetSizeView.as_view(), name='get-size-view'), path('tasks/get_size/', views.GetSizeView.as_view(), name='get-size-view'),
# /atdb/get_min_start_and_max_end_time?sas_id=65005
path('get_min_start_and_max_end_time/', views.GetMinMaxTimeView.as_view(), name='get-min-start-and-max-end-time-view'),
# --- controller resources --- # --- controller resources ---
path('tasks/<int:pk>/setstatus/<new_status>/<page>', views.TaskSetStatus, name='task-setstatus-view'), path('tasks/<int:pk>/setstatus/<new_status>/<page>', views.TaskSetStatus, name='task-setstatus-view'),
......
...@@ -737,3 +737,22 @@ class GetSizeView(generics.ListAPIView): ...@@ -737,3 +737,22 @@ class GetSizeView(generics.ListAPIView):
}) })
# /atdb/get_min_start_and_max_end_time?sas_id=650065
class GetMinMaxTimeView(generics.ListAPIView):
queryset = Task.objects.all()
# override list and generate a custom response
def list(self, request, *args, **kwargs):
# read the arguments from the query
try:
sas_id = self.request.query_params['sas_id']
start_time, end_time = algorithms.get_min_start_and_max_end_time(sas_id)
return Response({
'start_time': start_time,
'end_time': end_time,
})
except Exception as error:
return Response({
'error': str(error)
})
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment