Skip to content
Snippets Groups Projects
Commit 080cdff6 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

TMSS-2893: a past and a present page, plus annotation

parent 663ded07
No related branches found
No related tags found
1 merge request!1289Resolve TMSS-2893
...@@ -756,23 +756,46 @@ def failure_report(request): ...@@ -756,23 +756,46 @@ def failure_report(request):
operation_description="Get a json list of the current public schedule.") operation_description="Get a json list of the current public schedule.")
def public_schedule(request): def public_schedule(request):
'''return the current and future(2 weeks) running and scheduled units in a simple html table''' '''return the current and future(2 weeks) running and scheduled units in a simple html table'''
# get all current and future running and scheduled units return __create_html_schedule(request, past=False)
scheduled_or_running_units = models.SchedulingUnitBlueprint.objects.prefetch_related('task_blueprints__specifications_template__type') \
.select_related(models.SchedulingUnitBlueprint.path_to_project, 'status', 'specifications_template', 'specifications_template') \
.filter(status__value__in=models.SchedulingUnitStatus.ACTIVE_STATUS_VALUES) \ @permission_classes([AllowAny])
.filter(obsolete_since__isnull=True) \ @authentication_classes([AllowAny])
.filter(on_sky_stop_time__gte=datetime.utcnow()) \ @swagger_auto_schema(responses={200: 'A json list of the current public schedule.'},
.filter(on_sky_start_time__lte=datetime.utcnow()+timedelta(days=14)) \ operation_description="Get a json list of the current public schedule.")
.order_by('on_sky_start_time').all() def public_past_schedule(request):
'''return the past schedule of observed units in the cycle in a simple html table'''
return __create_html_schedule(request, past=True)
def __create_html_schedule(request, past: bool=False):
# get all current and future running and scheduled units
if 'json' in request.headers.get('Accept','').lower(): if 'json' in request.headers.get('Accept','').lower():
return JsonResponse("Sorry, Json is not supported", status=status.HTTP_501_NOT_IMPLEMENTED, safe=False) return JsonResponse("Sorry, Json is not supported", status=status.HTTP_501_NOT_IMPLEMENTED, safe=False)
# else, return html table
base_url = request._current_scheme_host base_url = request._current_scheme_host
title = 'LOFAR observing schedule %sUTC' %(datetime.utcnow().strftime("%Y-%m-%d %H:%M"), )
scheduling_units = models.SchedulingUnitBlueprint.objects.prefetch_related('task_blueprints__specifications_template__type') \
.select_related(models.SchedulingUnitBlueprint.path_to_project, 'status', 'specifications_template', 'specifications_template') \
.filter(status__value__in=models.SchedulingUnitStatus.ACTIVE_OR_FINISHED_STATUS_VALUES) \
.filter(obsolete_since__isnull=True)
if past:
current_cycle = models.Cycle.objects.filter(start__lte=datetime.utcnow()).order_by('-start').first()
scheduling_units = scheduling_units.filter(on_sky_stop_time__gte=current_cycle.start) \
.filter(on_sky_start_time__lte=datetime.utcnow())
description = '''This page shows all %s's past observations. Please find the current observations <a href="%s">here</a>''' % (current_cycle.name, base_url.rstrip('/')+'/schedule')
else:
scheduling_units = scheduling_units.filter(on_sky_stop_time__gte=datetime.utcnow()) \
.filter(on_sky_start_time__lte=datetime.utcnow()+timedelta(days=14))
description = '''This page shows all observations for the upcoming 2 weeks. Please find all past observations <a href="%s">here</a>''' % (base_url.rstrip('/')+'/past_schedule', )
description += '''<br>This schedule is subject to change based on changing telescope operational circumstances'''
scheduling_units = scheduling_units.order_by('on_sky_start_time').all()
table_rows = '''<tr><th>Project</th><th>ID</th><th>Name</th><th>Status</th><th>Start [UTC]</th><th>End [UTC]</th><th>Antenna</th><th>Target(s)</th></tr>\n''' table_rows = '''<tr><th>Project</th><th>ID</th><th>Name</th><th>Status</th><th>Start [UTC]</th><th>End [UTC]</th><th>Antenna</th><th>Target(s)</th></tr>\n'''
row_date = date.min row_date = date.min
for su in scheduled_or_running_units: for su in scheduling_units:
if su.on_sky_start_time.date() > row_date: if su.on_sky_start_time.date() > row_date:
row_date = su.on_sky_start_time.date() row_date = su.on_sky_start_time.date()
table_rows += '''<tr><td style="font-weight: bold; background-color: #999999;" colspan=9>%s</td></tr>\n''' % (row_date.strftime('%Y-%m-%d')) table_rows += '''<tr><td style="font-weight: bold; background-color: #999999;" colspan=9>%s</td></tr>\n''' % (row_date.strftime('%Y-%m-%d'))
...@@ -813,15 +836,20 @@ def public_schedule(request): ...@@ -813,15 +836,20 @@ def public_schedule(request):
} }
</style> </style>
<title>LOFAR observing schedule %sUTC</title> <title>LOFAR observing schedule %sUTC</title>
<meta http-equiv="refresh" content="60"> <meta http-equiv="refresh" content="300">
</head> </head>
<body> <body>
<h1>%s</h1>
<p>%s</p>
<table> <table>
%s %s
</table> </table>
</body> </body>
</html> </html>
''' % (datetime.utcnow().strftime("%Y-%m-%d %H:%M"), table_rows,) ''' % (title,
title,
description,
table_rows,)
return HttpResponse(html_doc, content_type='text/html') return HttpResponse(html_doc, content_type='text/html')
...@@ -270,6 +270,7 @@ urlpatterns = [url(r'^api$', RedirectView.as_view(url='/api/')), ...@@ -270,6 +270,7 @@ urlpatterns = [url(r'^api$', RedirectView.as_view(url='/api/')),
RedirectView.as_view(url='/oidc/')), RedirectView.as_view(url='/oidc/')),
url(r'^oidc/', include('mozilla_django_oidc.urls')), url(r'^oidc/', include('mozilla_django_oidc.urls')),
url(r'^schedule', views.public_schedule), url(r'^schedule', views.public_schedule),
url(r'^past_schedule', views.public_past_schedule),
url(r'', include(frontend_urls)), url(r'', include(frontend_urls)),
url(r'^.*', include(frontend_urlpatterns)), url(r'^.*', include(frontend_urlpatterns)),
] ]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment