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

OSB-32: changed query parameter name, and configured the controller to reply correctly to request

parent 9bfb531e
No related branches found
No related tags found
2 merge requests!89Monitoring maintenance Epic branch merge,!1Resolve OSB-13 "Monitoringmaintenance "
......@@ -124,7 +124,7 @@ class ControllerStationOverview(ValidableReadOnlyView):
errors_only = 'true'
n_station_tests = 4
n_rtsm = 4
errors_type = []
error_types = []
fields = [
coreapi.Field(
......@@ -160,7 +160,7 @@ class ControllerStationOverview(ValidableReadOnlyView):
description='displays or not only the station with more than one error')
),
coreapi.Field(
"errors_type",
"error_types",
required=False,
location='query',
type=parse_array,
......@@ -193,8 +193,8 @@ class ControllerStationOverview(ValidableReadOnlyView):
station_test_payload = OrderedDict()
component_errors = station_test.component_errors
selected_component_errors = component_errors
if(self.errors_type):
selected_component_errors = component_errors.filter(type__in=self.errors_type)
if(self.error_types):
selected_component_errors = component_errors.filter(type__in=self.error_types)
station_test_payload[
'total_component_errors'] = selected_component_errors.count()
station_test_payload['start_datetime'] = station_test.start_datetime
......@@ -229,13 +229,14 @@ class ControllerStationOverview(ValidableReadOnlyView):
unique_modes = [item['mode'] for item in
rtsm.errors_summary.values('mode').distinct()]
rtsm_payload['mode'] = unique_modes
rtsm_payload['total_component_errors'] = rtsm.errors_summary.count()
errors_summary = OrderedDict()
selected_rtsm_errors = rtsm.errors_summary
if(self.errors_type):
selected_rtsm_errors = rtsm.errors_summary.filter(error_type__in=self.errors_type)
if(self.error_types):
selected_rtsm_errors = rtsm.errors_summary.filter(error_type__in=self.error_types)
rtsm_payload['total_component_errors'] = selected_rtsm_errors.count()
errors_summary = OrderedDict()
errors_summary_query = selected_rtsm_errors.values('error_type').annotate(
total=Count('error_type'))
......@@ -262,7 +263,7 @@ class ControllerStationTestsSummary(ValidableReadOnlyView):
station_group = 'A'
errors_only = 'true'
lookback_time = 7
errors_type = []
error_types = []
fields = [
coreapi.Field(
......@@ -289,7 +290,7 @@ class ControllerStationTestsSummary(ValidableReadOnlyView):
minimum=1)
),
coreapi.Field(
"errors_type",
"error_types",
required=False,
location='query',
type=parse_array,
......@@ -315,19 +316,19 @@ class ControllerStationTestsSummary(ValidableReadOnlyView):
for station_test in station_test_list:
station_test_payload = OrderedDict()
component_errors = station_test.component_errors
station_test_payload['station_name'] = station_test.station.name
selected_component_errors = station_test.component_errors
if(self.errors_type):
selected_component_errors.filter(type__in=self.errors_type)
if(self.error_types):
selected_component_errors = selected_component_errors.filter(type__in=self.error_types)
station_test_payload[
'total_component_errors'] = station_test.component_errors.count()
'total_component_errors'] = selected_component_errors.count()
station_test_payload['date'] = station_test.start_datetime.strftime('%Y-%m-%d')
station_test_payload['start_datetime'] = station_test.start_datetime
station_test_payload['end_datetime'] = station_test.end_datetime
station_test_payload['checks'] = station_test.checks
component_errors_summary = component_errors. \
component_errors_summary = selected_component_errors. \
values('component__type', 'type').annotate(
total=Count('type')).order_by('-total')
component_errors_summary_dict = OrderedDict()
......@@ -359,7 +360,7 @@ class ControllerLatestObservations(ValidableReadOnlyView):
station_group = 'A'
errors_only = 'true'
errors_type = []
error_types = []
fields = [
coreapi.Field(
......@@ -386,7 +387,7 @@ class ControllerLatestObservations(ValidableReadOnlyView):
description='select rtsm from date (ex. YYYY-MM-DD)')
),
coreapi.Field(
"errors_type",
"error_types",
required=False,
location='query',
type=parse_array,
......@@ -417,8 +418,8 @@ class ControllerLatestObservations(ValidableReadOnlyView):
.annotate(total=Count('errors_summary__error_type')) \
.order_by('observation_id', 'station__name')
if self.errors_type:
errors_summary = errors_summary.filter(errors_summary__error_type__in=self.errors_type)
if self.error_types:
errors_summary = errors_summary.filter(errors_summary__error_type__in=self.error_types)
response = dict()
for error_summary in errors_summary:
......@@ -467,7 +468,7 @@ class ControllerStationTestStatistics(ValidableReadOnlyView):
description = "Statistical summary of both or either the station test and RTSM"
station_group = 'A'
test_type = 'B'
errors_type = []
error_types = []
fields = [
coreapi.Field(
......@@ -510,7 +511,7 @@ class ControllerStationTestStatistics(ValidableReadOnlyView):
description='averaging interval in days')
),
coreapi.Field(
"errors_type",
"error_types",
required=False,
location='query',
type=parse_array,
......@@ -530,9 +531,9 @@ class ControllerStationTestStatistics(ValidableReadOnlyView):
component_errors = component_errors.filter(station_test__station__type=station_group)
rtsm_summary_errors = rtsm_summary_errors.filter(
observation__station__type=station_group)
if self.errors_type:
component_errors = component_errors.filter(type__in=self.errors_type)
rtsm_summary_errors = rtsm_summary_errors.filter(error_type__in=self.errors_type)
if self.error_types:
component_errors = component_errors.filter(type__in=self.error_types)
rtsm_summary_errors = rtsm_summary_errors.filter(error_type__in=self.error_types)
station_test_results = []
rtsm_results = []
......@@ -584,9 +585,9 @@ class ControllerStationTestStatistics(ValidableReadOnlyView):
rtsm_summary_errors = rtsm_summary_errors.filter(
observation__station__type=station_group)
if self.errors_type:
component_errors = component_errors.filter(type__in=self.errors_type)
rtsm_summary_errors = rtsm_summary_errors.filter(error_type__in=self.errors_type)
if self.error_types:
component_errors = component_errors.filter(type__in=self.error_types)
rtsm_summary_errors = rtsm_summary_errors.filter(error_type__in=self.error_types)
if test_type in ['S', 'B']:
station_test_results = component_errors. \
......@@ -667,6 +668,7 @@ class ControllerAllComponentErrorTypes(ValidableReadOnlyView):
data = [item['type'] for item in ComponentError.objects.values('type').distinct()]
return Response(status=status.HTTP_200_OK, data=data)
class ControllerStationComponentErrors(ValidableReadOnlyView):
description = "Provides a summary per station of the component errors"
# required parameters
......@@ -675,7 +677,7 @@ class ControllerStationComponentErrors(ValidableReadOnlyView):
to_date = None
# optional parameters
test_type = 'B'
errors_type = []
error_types = []
fields = [
coreapi.Field(
......@@ -707,7 +709,7 @@ class ControllerStationComponentErrors(ValidableReadOnlyView):
)
),
coreapi.Field(
"errors_type",
"error_types",
required=False,
location='query',
type=parse_array,
......@@ -726,7 +728,7 @@ class ControllerStationComponentErrors(ValidableReadOnlyView):
.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')
failing_component_types = station_tests.distinct('component_errors__component__type').exclude(component_errors__component__type__isnull=True).values_list('component_errors__component__type')
for failing_component_type in failing_component_types:
failing_component_type = failing_component_type[0]
......@@ -743,8 +745,8 @@ class ControllerStationComponentErrors(ValidableReadOnlyView):
test_summary['component_errors'] = component_errors_dict
component_errors = station_test.component_errors\
.filter(component__type=failing_component_type)
if self.errors_type:
component_errors = component_errors.filter(type__in=self.errors_type)
if self.error_types:
component_errors = component_errors.filter(type__in=self.error_types)
for component_error in component_errors:
component_id = component_error.component.component_id
......@@ -855,8 +857,8 @@ class ControllerStationComponentErrors(ValidableReadOnlyView):
'stop_frequency', 'percentage',
'error_type', 'count', 'rcu')
if self.errors_type:
component_errors = component_errors.filter(error_type__in=self.errors_type)
if self.error_types:
component_errors = component_errors.filter(error_type__in=self.error_types)
for component_error in component_errors:
component_id = component_error['rcu']
details = dict(percentage = component_error['percentage'],
......
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