diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/adapters/plots.py b/SAS/TMSS/backend/src/tmss/tmssapp/adapters/plots.py index bb5b6fb7d09961b8b20ea2c85b21267e59d579b3..6b4b95fa10e9d072e3ba7f7079bd23a008ed144a 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/adapters/plots.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/adapters/plots.py @@ -454,7 +454,7 @@ def scheduling_constraints_plot_for_date(proposed_date: date, station: str=None) proposed_start_time=None, include_min_max_elevations=False) -def lst_pressure_plot(lower_bound: datetime=None, upper_bound: datetime=None, include_calibrators: bool=True) -> bytes: +def lst_pressure_plot(lower_bound: datetime=None, upper_bound: datetime=None, include_calibrators: bool=True, projects: list=None) -> bytes: # create "bins" per minute for a full sidereal 23h56m day # start with 0 pressure for each minute-bin if lower_bound is None: @@ -489,6 +489,9 @@ def lst_pressure_plot(lower_bound: datetime=None, upper_bound: datetime=None, in for status, q_filter in filters.items(): observation_tasks = models.TaskBlueprint.objects.filter(q_filter).filter(obsolete_since__isnull=True).filter(specifications_template__type__value=models.TaskType.Choices.OBSERVATION.value) + if projects: + observation_tasks = observation_tasks.filter(scheduling_unit_blueprint__draft__scheduling_set__project__name__in=projects) + if status not in ('schedulable', 'unschedulable'): if lower_bound: observation_tasks = observation_tasks.filter(on_sky_stop_time__gte=lower_bound) @@ -558,7 +561,7 @@ def lst_pressure_plot(lower_bound: datetime=None, upper_bound: datetime=None, in from django.db.models import Max scheduling_units = models.SchedulingUnitBlueprint.objects.filter(status__value=models.SchedulingUnitStatus.Choices.SCHEDULED.value) scheduling_units = scheduling_units.filter(obsolete_since__isnull=True) - upper_bound = scheduling_units.aggregate(Max('on_sky_stop_time'))['on_sky_stop_time__max'] + upper_bound = scheduling_units.aggregate(Max('on_sky_stop_time'))['on_sky_stop_time__max'] or lower_bound+timedelta(days=365) # used for reporting in title upper_bound_day_start = upper_bound.replace(hour=0, minute=0, second=0, microsecond=0) @@ -567,9 +570,10 @@ def lst_pressure_plot(lower_bound: datetime=None, upper_bound: datetime=None, in # create the figure fig, axes = plt.subplots(figsize=(16, 10)) - fig.suptitle("LST pressure %s - %s %s" % (lower_bound.strftime('%Y-%m-%d'), - upper_bound_day_start.strftime('%Y-%m-%d'), - 'targets and calibrators' if include_calibrators else 'targets only')) + fig.suptitle("LST pressure %s - %s %s%s" % (lower_bound.strftime('%Y-%m-%d'), + upper_bound_day_start.strftime('%Y-%m-%d'), + ','.join(projects)+' ' if projects else '', + 'targets and calibrators' if include_calibrators else 'targets only')) axes.set_xlim(lower_bound_day_start, lower_bound_day_start+timedelta(hours=23, minutes=56, seconds=4)) # axes.set_ylim(0, max(pressures)) diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py b/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py index 26b39ae2c502c8502fcdf1621d6bdcf80d30f961..b5fadea88dfb6e274725ba06fc985bea9ff1f047 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py @@ -508,6 +508,19 @@ class ProjectViewSet(LOFARViewSet): return Response(result, status=status.HTTP_200_OK) + @method_decorator(never_cache) + @action(methods=['get'], detail=True, renderer_classes=(ImagePNGRenderer,)) + def pressure_plot(self, request, pk=None): + project = get_object_or_404(models.Project, pk=pk) + + from lofar.sas.tmss.tmss.tmssapp.adapters.plots import lst_pressure_plot + plot = lst_pressure_plot(lower_bound=project.earliest_possible_cycle_start_time, + upper_bound=project.latest_possible_cycle_stop_time, + include_calibrators=False, + projects=[project.name]) + return Response(plot, content_type='image/png', status=status.HTTP_201_CREATED) + + class ProjectNestedViewSet(LOFARNestedViewSet): queryset = models.Project.objects.all() serializer_class = serializers.ProjectSerializer diff --git a/SAS/TMSS/backend/src/tmss/urls.py b/SAS/TMSS/backend/src/tmss/urls.py index 8c2941393324ffbc339eb92bc57c7b134930b899..1917123caf8f4d8ffa4e25126a44d09481695ae5 100644 --- a/SAS/TMSS/backend/src/tmss/urls.py +++ b/SAS/TMSS/backend/src/tmss/urls.py @@ -87,10 +87,10 @@ urlpatterns = [ re_path('submit_trigger', views.submit_trigger, name='submit_trigger'), re_path('friends_of_projects/', views.friends_of_projects, name='get_friends_of_projects'), re_path('my_roles_overview/', views.my_roles, name='get_my_roles'), - re_path('daily_schedule_plot/?(?P<datestamp>(\d{4}-[01]\d-[0-3]\d))?/?', views.daily_schedule_plot, name='daily_schedule_plot'), - re_path('daily_scheduling_constraints_overview/?(?P<datestamp>(\d{4}-[01]\d-[0-3]\d))?/?', views.daily_scheduling_constraints_overview, name='daily_scheduling_constraints_overview'), - re_path('lst_pressure_plot/?(?P<from_date>(\d{4}-[01]\d-[0-3]\d))?/?(?P<until_date>(\d{4}-[01]\d-[0-3]\d))?/?', views.lst_pressure_plot, name='lst_pressure_plot'), - re_path('lst_target_pressure_plot/?(?P<from_date>(\d{4}-[01]\d-[0-3]\d))?/?(?P<until_date>(\d{4}-[01]\d-[0-3]\d))?/?', views.lst_target_pressure_plot, name='lst_target_pressure_plot'), + re_path('plots/daily_schedule_plot/?(?P<datestamp>(\d{4}-[01]\d-[0-3]\d))?/?', views.daily_schedule_plot, name='daily_schedule_plot'), + re_path('plots/daily_scheduling_constraints_overview/?(?P<datestamp>(\d{4}-[01]\d-[0-3]\d))?/?', views.daily_scheduling_constraints_overview, name='daily_scheduling_constraints_overview'), + re_path('plots/lst_pressure_plot/?(?P<from_date>(\d{4}-[01]\d-[0-3]\d))?/?(?P<until_date>(\d{4}-[01]\d-[0-3]\d))?/?', views.lst_pressure_plot, name='lst_pressure_plot'), + re_path('plots/lst_target_pressure_plot/?(?P<from_date>(\d{4}-[01]\d-[0-3]\d))?/?(?P<until_date>(\d{4}-[01]\d-[0-3]\d))?/?', views.lst_target_pressure_plot, name='lst_target_pressure_plot'), re_path('failure_report/', views.failure_report, name='failure_report'), ] diff --git a/SAS/TMSS/frontend/tmss_webapp/src/services/schedule.service.js b/SAS/TMSS/frontend/tmss_webapp/src/services/schedule.service.js index f761625b5304791830eae90a4851ac1105e94c36..495917f8c22fdb382105972fdc54bb537778b2cc 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/services/schedule.service.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/services/schedule.service.js @@ -106,7 +106,7 @@ const ScheduleService = { getConstraintImgOnDate : async function(onDate) { if (onDate===undefined) return; try { - let imageurl = "/api/daily_schedule_plot/" + onDate + let imageurl = "/api/plots/daily_schedule_plot/" + onDate const response = await axios.get( imageurl, { responseType: "blob", } ); const dataUrl = URL.createObjectURL(response.data); return dataUrl;