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

OSB-32: started working on ControllerStationComponentErrors

parent b0333510
No related branches found
No related tags found
2 merge requests!89Monitoring maintenance Epic branch merge,!1Resolve OSB-13 "Monitoringmaintenance "
...@@ -7,6 +7,16 @@ from .station import Station ...@@ -7,6 +7,16 @@ from .station import Station
from .fixed_types import STATION_TYPES from .fixed_types import STATION_TYPES
MODE_TO_COMPONENT = {
1: 'LBL',
2: 'LBL',
3: 'LBH',
4: 'LBH',
5: 'HBA',
6: 'HBA',
7: 'HBA'
}
class RTSMObservation(models.Model): class RTSMObservation(models.Model):
observation_id = models.PositiveIntegerField(default=0) observation_id = models.PositiveIntegerField(default=0)
......
...@@ -42,6 +42,7 @@ urlpatterns = [ ...@@ -42,6 +42,7 @@ urlpatterns = [
url(r'^api/view/ctrl_latest_observation', ControllerLatestObservations.as_view()), url(r'^api/view/ctrl_latest_observation', ControllerLatestObservations.as_view()),
url(r'^api/view/ctrl_stationtest_statistics', ControllerStationTestStatistics.as_view()), 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_list_component_error_types', ControllerAllComponentErrorTypes.as_view()),
url(r'^api/view/ctrl_station_component_errors', ControllerStationComponentErrors.as_view()),
url(r'^api/docs', include_docs_urls(title='Monitoring DB API')) url(r'^api/docs', include_docs_urls(title='Monitoring DB API'))
] ]
...@@ -6,16 +6,16 @@ from math import ceil ...@@ -6,16 +6,16 @@ from math import ceil
import coreapi import coreapi
import coreschema import coreschema
from django.db.models import Count from django.db.models import Count
from lofar.maintenance.monitoringdb.models.component_error import ComponentError
from lofar.maintenance.monitoringdb.models.rtsm import RTSMErrorSummary, MODE_TO_COMPONENT
from lofar.maintenance.monitoringdb.models.rtsm import RTSMObservation
from lofar.maintenance.monitoringdb.models.station import Station
from lofar.maintenance.monitoringdb.models.station_test import StationTest
from rest_framework import status from rest_framework import status
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.schemas import ManualSchema from rest_framework.schemas import ManualSchema
from rest_framework.views import APIView from rest_framework.views import APIView
from lofar.maintenance.monitoringdb.models.component_error import ComponentError
from lofar.maintenance.monitoringdb.models.rtsm import RTSMErrorSummary
from lofar.maintenance.monitoringdb.models.rtsm import RTSMObservation
from lofar.maintenance.monitoringdb.models.station import Station
from lofar.maintenance.monitoringdb.models.station_test import StationTest
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -46,13 +46,13 @@ class ValidableReadOnlyView(APIView): ...@@ -46,13 +46,13 @@ class ValidableReadOnlyView(APIView):
# Override this to make the schema validation work # Override this to make the schema validation work
fields = [] fields = []
description = ''
def compute_response(self): def compute_response(self):
raise NotImplementedError() raise NotImplementedError()
@property @property
def schema(self): def schema(self):
return ManualSchema(fields=self.fields) return ManualSchema(fields=self.fields, description=self.description)
def validate_query_parameters(self, request): def validate_query_parameters(self, request):
""" """
...@@ -89,6 +89,10 @@ class ValidableReadOnlyView(APIView): ...@@ -89,6 +89,10 @@ class ValidableReadOnlyView(APIView):
try: try:
response = self.compute_response() response = self.compute_response()
except ValueError as e:
return Response(status=status.HTTP_406_NOT_ACCEPTABLE,
data='Please specify the correct parameters: %s' % (e,))
except Exception as e: except Exception as e:
logger.exception(e) logger.exception(e)
return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR, return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR,
...@@ -97,9 +101,7 @@ class ValidableReadOnlyView(APIView): ...@@ -97,9 +101,7 @@ class ValidableReadOnlyView(APIView):
class ControllerStationOverview(ValidableReadOnlyView): class ControllerStationOverview(ValidableReadOnlyView):
""" description = "Overview of the latest tests performed on the stations"
Overview of the latest tests performed on the stations
"""
station_group = 'A' station_group = 'A'
errors_only = 'true' errors_only = 'true'
...@@ -222,9 +224,8 @@ class ControllerStationOverview(ValidableReadOnlyView): ...@@ -222,9 +224,8 @@ class ControllerStationOverview(ValidableReadOnlyView):
class ControllerStationTestsSummary(ValidableReadOnlyView): class ControllerStationTestsSummary(ValidableReadOnlyView):
""" description = "Overview of the latest station tests performed on" \
Overview of the latest station tests performed on the stations # lookback days before now " the stations a [loopback_time] days ago from now"
"""
station_group = 'A' station_group = 'A'
errors_only = 'true' errors_only = 'true'
lookback_time = 7 lookback_time = 7
...@@ -308,9 +309,7 @@ class ControllerStationTestsSummary(ValidableReadOnlyView): ...@@ -308,9 +309,7 @@ class ControllerStationTestsSummary(ValidableReadOnlyView):
class ControllerLatestObservations(ValidableReadOnlyView): class ControllerLatestObservations(ValidableReadOnlyView):
""" description = "Overview of the latest observations performed on the stations"
Overview of the latest observations performed on the stations
"""
station_group = 'A' station_group = 'A'
errors_only = 'true' errors_only = 'true'
...@@ -406,35 +405,7 @@ class ControllerLatestObservations(ValidableReadOnlyView): ...@@ -406,35 +405,7 @@ class ControllerLatestObservations(ValidableReadOnlyView):
class ControllerStationTestStatistics(ValidableReadOnlyView): class ControllerStationTestStatistics(ValidableReadOnlyView):
""" description = "Statistical summary of both or either the station test and RTSM"
/views/ctrl_stationtest_statistics:
parameters:
station_group [C|R|I|ALL] (optional, default ALL)
test_type [RTSM|STATIONTEST|BOTH] (optional, default BOTH)
from_date #DATE
to_date #DATE
averaging_interval: #TIMESPAN
result:
{
start_date : #DATE,
end_date: #DATE,
averaging_interval: #INTERVAL,
error_per_station: [{
time: #DATE,
station_name: <station_name>
n_errors: #nr_errors int
}, ...],
error_per_error_type: [{
time: #DATE,
error_type: <error_type>
n_errors: #nr_errors int
}, ...],
},
....
]
"""
station_group = 'A' station_group = 'A'
test_type = 'B' test_type = 'B'
...@@ -614,8 +585,133 @@ result: ...@@ -614,8 +585,133 @@ result:
class ControllerAllComponentErrorTypes(ValidableReadOnlyView): class ControllerAllComponentErrorTypes(ValidableReadOnlyView):
schema = ManualSchema(description="Returns all distinct component errors", fields=[]) description = "Lists all the presents component error types"
def compute_response(self): def compute_response(self):
data = [item['type'] for item in ComponentError.objects.values('type').distinct()] data = [item['type'] for item in ComponentError.objects.values('type').distinct()]
return Response(status=status.HTTP_200_OK, data=data) return Response(status=status.HTTP_200_OK, data=data)
class ControllerStationComponentErrors(ValidableReadOnlyView):
description = "Provides a summary per station of the component errors"
# required parameters
station_name = None
from_date = None
to_date = None
# optional parameters
test_type = 'B'
fields = [
coreapi.Field(
'station_name',
required=True,
location='query',
schema=coreschema.String(description='name of the station to select')
),
coreapi.Field(
'from_date',
required=True,
location='query',
schema=coreschema.String(description='select tests from date (ex. YYYY-MM-DD)')
),
coreapi.Field(
'to_date',
required=True,
location='query',
schema=coreschema.String(description='select tests from date (ex. YYYY-MM-DD)')
),
coreapi.Field(
'test_type',
required=False,
location='query',
schema=coreschema.Enum(
['R', 'S', 'B'],
description='select the type of test possible values are (R, RTSM),'
' (S, Station test), (B, both)[DEFAULT=B]',
)
)
]
def collect_station_test_errors(self):
station_entry = Station.objects.filter(name=self.station_name).first()
response_payload = OrderedDict()
station_tests = station_entry.stationtest_set \
.filter(start_datetime__gte=self.from_date,
end_datetime__lte=self.to_date)
failing_component_types = station_tests.distinct('component_errors__component__type').values_list('component_errors__component__type')
print(failing_component_types)
for failing_component_type in failing_component_types:
failing_component_type = failing_component_type[0]
component_type_errors_list = list()
response_payload[failing_component_type] = component_type_errors_list
for station_test in station_tests.order_by('-start_datetime'):
test_summary = OrderedDict()
test_summary['test_type'] = 'S'
test_summary['start_date'] = station_test.start_datetime
test_summary['end_date'] = station_test.end_datetime
component_errors_dict = OrderedDict()
test_summary['component_errors'] = component_errors_dict
component_errors = station_test.component_errors\
.filter(component__type=failing_component_type)
for component_error in component_errors:
component_id = component_error.component.component_id
error_type = component_error.type
details = component_error.details
if component_id not in component_errors:
component_errors_dict[str(component_id)] = list()
component_errors_dict[str(component_id)] += [dict(error_type=error_type,
details=details)]
component_type_errors_list.append(test_summary)
return response_payload
def collect_rtsm_errors(self):
station_entry = Station.objects.filter(name=self.station_name).first()
response_payload = OrderedDict()
print(dir(station_entry))
rtsm_observations = station_entry.rtsmobservation_set \
.filter(start_datetime__gte=self.from_date,
end_datetime__lte=self.to_date)
print(rtsm_observations)
failing_component_modes = rtsm_observations.distinct(
'errors_summary__mode').values_list('errors_summary__mode')
for observing_mode in failing_component_modes:
observing_mode = observing_mode[0]
for rtsm_observation in rtsm_observations.order_by('-start_datetime'):
rtsm_summary = OrderedDict()
rtsm_summary['test_type'] = 'R'
rtsm_summary['start_date'] = rtsm_observation.start_datetime
rtsm_summary['end_date'] = rtsm_observation.end_datetime
component_errors_dict = OrderedDict()
rtsm_summary['component_errors'] = component_errors_dict
component_errors = rtsm_observation.errors_summary\
.filter(mode=observing_mode)\
.values('error_type', 'start_frequency',
'stop_frequency', 'percentage',
'error_type', 'samples', 'count', 'rcu')
for component_error in component_errors:
component_id = component_error['rcu']
percentage = component_error['percentage']
start_frequency = component_error['start_frequency']
stop_frequency = component_error['stop_frequency']
error_type = component_error['error_type']
#TODO I AM HERE
print(dir(component_error))
def compute_response(self):
self.from_date = parse_date(self.from_date)
self.to_date = parse_date(self.to_date)
station_test_errors = self.collect_station_test_errors()
rtsm_errors = self.collect_rtsm_errors()
return Response(status=status.HTTP_200_OK, data=station_test_errors)
\ No newline at end of file
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