Skip to content
Snippets Groups Projects
Commit 304e2e9b authored by Mattia Mancini's avatar Mattia Mancini
Browse files

OSB-34: cleaned up the code and added automatic generation of the plot on request

parent 8aa98b2d
No related branches found
No related tags found
2 merge requests!89Monitoring maintenance Epic branch merge,!1Resolve OSB-13 "Monitoringmaintenance "
......@@ -5,7 +5,8 @@ import matplotlib.pyplot as plt
import numpy
from celery import shared_task
from django.conf import settings
from celery.signals import task_prerun
from lofar.maintenance.django_postgresql import backend_tasks
from .models.rtsm import RTSMObservation, MODE_TO_COMPONENT, RTSMErrorSummary, RTSMSummaryPlot
logger = logging.getLogger(__name__)
......@@ -208,15 +209,15 @@ def generate_summary_plot_for_error(error_summary_id):
full_path)
summary_plot.uri = file_name
summary_plot.save()
return full_path
return summary_plot.pk
except Exception as e:
logger.exception('exception %s occurred skipping...', e)
summary_plot.delete()
raise e
@shared_task(bind=True, track_started=True)
def check_error_summary_plot(self, error_summary_id):
@shared_task()
def check_error_summary_plot(error_summary_id):
"""
Checks if the error summary plot is presents otherwise it generates one
:param self: shared_task
......@@ -224,8 +225,11 @@ def check_error_summary_plot(self, error_summary_id):
:param error_summary_id: database id of the RTSMErrorSummary to check
:return:
"""
logger.debug('looking for rtsm error summary %s', error_summary_id)
error_summary = RTSMErrorSummary.objects.get(pk=error_summary_id)
summary_plot = error_summary.summary_plot.first()
logger.debug('summary error found %s', summary_plot)
if summary_plot is None:
return generate_summary_plot_for_error(error_summary_id)
else:
......@@ -238,26 +242,5 @@ def check_error_summary_plot(self, error_summary_id):
elif os.path.isdir(full_path):
raise Exception('%s is a directory' % full_path)
else:
return error_summary.summary_plot.uri
@shared_task(bind=True, track_started=True)
def check_observation_plots(self, database_id):
"""
Generate the summary plots from a given RTSM observation
:param self: shared_task
:type self: celery.shared_task()
:param database_id: database id of the RTSM observation
:return:
"""
observation = RTSMObservation.objects.get(id=database_id)
observation_metadata = ObservationMetadata()
observation_metadata.observation_id = observation.observation_id
observation_metadata.station_name = observation.station.name
observation_metadata.samples = observation.samples
list_of_generated_files = []
for error in observation.errors_summary.all():
list_of_generated_files += [check_error_summary_plot.delay(error.pk)]
return 'checking in progress'
logger.debug('summary error %s is complete no need to generate additional plot', summary_plot.pk)
return summary_plot.pk
......@@ -44,7 +44,5 @@ urlpatterns = [
url(r'^api/view/ctrl_stationtest_statistics', ControllerStationTestStatistics.as_view()),
url(r'^api/view/ctrl_list_component_error_types', ControllerAllComponentErrorTypes.as_view()),
url(r'^api/view/ctrl_station_component_errors', ControllerStationComponentErrors.as_view()),
url(r'^api/view/ctrl_test_queue', ControllerTestCeleryQueue.as_view()),
url(r'^api/docs', include_docs_urls(title='Monitoring DB API'))
]
from .common import *
from ..models.rtsm import RTSMObservation, RTSMError, RTSMSpectrum
from ..serializers.rtsm import RTSMObservationSerializer, RTSMErrorSerializer, \
RTSMSpectrumSerializer, RTSMSummaryPlotSerializer, RTSMSummaryPlot
RTSMSpectrumSerializer, RTSMSummaryPlotSerializer, RTSMErrorSummary
from ..rtsm_test_raw_parser import parse_rtsm_test
import os
from ..tasks import check_error_summary_plot
logger = logging.getLogger('views')
......@@ -24,14 +26,19 @@ class RTSMObservationViewSet(viewsets.ReadOnlyModelViewSet):
serializer_class = RTSMObservationSerializer
filter_fields = '__all__'
import os
@api_view(['GET'])
def get_summary_plot(request, pk):
try:
entity = RTSMSummaryPlot.objects.get(pk=pk)
uri = RTSMSummaryPlotSerializer(entity).data['uri']
entity = RTSMErrorSummary.objects.get(pk=pk)
summary_plot = entity.summary_plot.first()
if summary_plot is None:
raise ObjectDoesNotExist()
uri = RTSMSummaryPlotSerializer(summary_plot).data['uri']
except ObjectDoesNotExist as e:
check_error_summary_plot.delay(pk)
return HttpResponse('<h1>NOT FOUND</h1>', status=status.HTTP_404_NOT_FOUND)
try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment