diff --git a/LCU/Maintenance/DBInterface/monitoringdb/views/controllers.py b/LCU/Maintenance/DBInterface/monitoringdb/views/controllers.py index 257d517b01a549934ecba39540b7264ea9c65204..65f5eb839e7419e1c5a753221adf3ef6ac9cf937 100644 --- a/LCU/Maintenance/DBInterface/monitoringdb/views/controllers.py +++ b/LCU/Maintenance/DBInterface/monitoringdb/views/controllers.py @@ -929,7 +929,7 @@ class ControllerStationComponentElementErrors(ValidableReadOnlyView): rcu_id = (antenna_id - 48) * 2 rcu_id += 1 if polarization == 'X' else 0 elif type == 'HBA': - rcu_id = antenna_id + rcu_id = antenna_id * 2 rcu_id += 0 if polarization == 'X' else 1 else: rcu_id = -1 @@ -942,6 +942,49 @@ class ControllerStationComponentElementErrors(ValidableReadOnlyView): rcus={rcu_x:'X', rcu_y:'Y'} return rcus + def compute_ok_rtsm_list(self): + mode=COMPONENT_TO_MODE[self.component_type] + + rcus_per_polarization = self.rcus_from_antenna_and_type(self.antenna_id, + self.component_type) + + good_observation_list = RTSMObservation.objects.filter(errors_summary__mode__in=mode, + start_datetime__gt=self.from_date, + end_datetime__lt=self.to_date, + station__name=self.station_name).\ + exclude(errors_summary__rcu__in=list(rcus_per_polarization.keys())).\ + order_by('-start_datetime').values('pk', + 'observation_id', + 'start_datetime', + 'end_datetime') + result = [] + for observation in good_observation_list: + entry = dict(test_id=observation['observation_id'], + db_id=observation['pk'], + start_date=observation['start_datetime'], + end_date=observation['end_datetime'], + test_type='R', + component_errors=dict()) + result.append(entry) + return result + + def compute_ok_station_test(self): + good_station_test = StationTest.objects.filter(start_datetime__gt=self.from_date, + end_datetime__lt=self.to_date, + station__name=self.station_name).\ + exclude(component_errors__component__component_id=self.antenna_id).\ + values('pk', 'start_datetime', 'end_datetime').order_by('-start_datetime') + result = [] + for station_test in good_station_test: + entry = dict(test_id=station_test['pk'], + db_id=station_test['pk'], + start_date=station_test['start_datetime'], + end_date=station_test['end_datetime'], + test_type='S', + component_errors=dict()) + result.append(entry) + return result + def compute_rtsm_errors_list(self): errors = dict() rcus_per_polarization = self.rcus_from_antenna_and_type(self.antenna_id, @@ -980,8 +1023,7 @@ class ControllerStationComponentElementErrors(ValidableReadOnlyView): if polarization not in errors[observation_pk]: errors[observation_pk]['component_errors'][polarization] = dict( rcu=rcu, - errors = dict(), - element_errors = dict() + errors = dict() ) error_type = item['error_type'] percentage = item['percentage'] @@ -1006,7 +1048,7 @@ class ControllerStationComponentElementErrors(ValidableReadOnlyView): station_test__end_datetime__lt=self.to_date, station_test__station__name=self.station_name, component__type=self.component_type, - component__component_id__in=list(rcus_per_polarization.keys())).order_by('-station_test__start_datetime') + component__component_id=self.antenna_id).order_by('-station_test__start_datetime') for component_error in component_errors: station_test_pk = component_error.station_test.pk if station_test_pk not in errors.keys(): @@ -1016,21 +1058,20 @@ class ControllerStationComponentElementErrors(ValidableReadOnlyView): end_date=component_error.station_test.end_datetime, test_type='S', component_errors=dict()) - component_id = component_error.component.component_id - polarization = rcus_per_polarization[component_id] - if polarization not in errors[station_test_pk]: - errors[station_test_pk]['component_errors'][polarization] = dict( - rcu=component_id, - errors=dict()) - error_type = component_error.type - details = component_error.details - errors_per_error_polarization = errors[station_test_pk]['component_errors'][polarization]['errors'] - errors_per_error_polarization[error_type] = dict(details=details, element_errors=dict()) - - - for element in component_error.failing_elements.values('element__element_id', 'details'): - element_id = element['element__element_id'] - errors_per_error_polarization[error_type]['element_errors'][element_id] = element['details'] + for rcu_id, polarization in rcus_per_polarization.items(): + if polarization not in errors[station_test_pk]: + errors[station_test_pk]['component_errors'][polarization] = dict( + rcu=rcu_id, + errors=dict()) + error_type = component_error.type + details = component_error.details + errors_per_error_polarization = errors[station_test_pk]['component_errors'][polarization]['errors'] + errors_per_error_polarization[error_type] = dict(details=details, element_errors=dict()) + + + for element in component_error.failing_elements.values('element__element_id', 'details'): + element_id = element['element__element_id'] + errors_per_error_polarization[error_type]['element_errors'][element_id] = element['details'] return list(errors.values()) @@ -1041,9 +1082,10 @@ class ControllerStationComponentElementErrors(ValidableReadOnlyView): station_test_list = [] if self.test_type == 'R' or self.test_type == 'A': - rtsm_errors_list = self.compute_rtsm_errors_list() + rtsm_errors_list = self.compute_rtsm_errors_list() + self.compute_ok_rtsm_list() + if self.test_type == 'S' or self.test_type == 'A': - station_test_list = self.compute_station_tests_error_list() + station_test_list = self.compute_station_tests_error_list() + self.compute_ok_station_test() combined = rtsm_errors_list + station_test_list combined_and_sorted = sorted(combined, key=lambda test: test['start_date'], reverse=True)