diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/views.py b/SAS/TMSS/backend/src/tmss/tmssapp/views.py index ebba5b28dce0a4747d95f316af127322d41c19fd..70cf03e6dd61739fe88f317e9d55112313c02698 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/views.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/views.py @@ -756,23 +756,46 @@ def failure_report(request): operation_description="Get a json list of the current public schedule.") def public_schedule(request): '''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 - 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) \ - .filter(obsolete_since__isnull=True) \ - .filter(on_sky_stop_time__gte=datetime.utcnow()) \ - .filter(on_sky_start_time__lte=datetime.utcnow()+timedelta(days=14)) \ - .order_by('on_sky_start_time').all() + return __create_html_schedule(request, past=False) + + +@permission_classes([AllowAny]) +@authentication_classes([AllowAny]) +@swagger_auto_schema(responses={200: 'A json list of the current public schedule.'}, + operation_description="Get a json list of the current public schedule.") +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(): 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 + 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''' 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: 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')) @@ -813,15 +836,20 @@ def public_schedule(request): } </style> <title>LOFAR observing schedule %sUTC</title> - <meta http-equiv="refresh" content="60"> + <meta http-equiv="refresh" content="300"> </head> <body> + <h1>%s</h1> + <p>%s</p> <table> %s </table> </body> </html> - ''' % (datetime.utcnow().strftime("%Y-%m-%d %H:%M"), table_rows,) + ''' % (title, + title, + description, + table_rows,) return HttpResponse(html_doc, content_type='text/html') diff --git a/SAS/TMSS/backend/src/tmss/urls.py b/SAS/TMSS/backend/src/tmss/urls.py index 51c1d6601214f0350191dd483b73a441b4107f7f..e691fdc120ff7a55afc0dc512ea3e165065e6d6e 100644 --- a/SAS/TMSS/backend/src/tmss/urls.py +++ b/SAS/TMSS/backend/src/tmss/urls.py @@ -270,6 +270,7 @@ urlpatterns = [url(r'^api$', RedirectView.as_view(url='/api/')), RedirectView.as_view(url='/oidc/')), url(r'^oidc/', include('mozilla_django_oidc.urls')), url(r'^schedule', views.public_schedule), + url(r'^past_schedule', views.public_past_schedule), url(r'', include(frontend_urls)), url(r'^.*', include(frontend_urlpatterns)), ]