def test_create_monthly_energy_measurement_with_defaults(self):
        size = len(MonthlyMeasurement.objects.all())

        monthly_en_measurement = MonthlyMeasurement()
        monthly_en_measurement.collection_date = \
            timezone.datetime(2019, 2, 5, 14, 0, 0)
        monthly_en_measurement.transductor = self.transductor
        monthly_en_measurement.active_max_power_list_peak_time = []
        monthly_en_measurement.active_max_power_list_off_peak_time = []
        monthly_en_measurement.reactive_max_power_list_peak_time = []
        monthly_en_measurement.reactive_max_power_list_off_peak_time = []

        self.assertIsNone(monthly_en_measurement.save())
        self.assertEqual(size + 1, len(MonthlyMeasurement.objects.all()))
    def test_update_monthly_energy_measurement(self):
        monthly_energy_measurement = MonthlyMeasurement()
        monthly_energy_measurement.transductor = \
            EnergyTransductor.objects.get(
                serial_number=87654321
            )
        monthly_energy_measurement.active_max_power_list_peak_time = []
        monthly_energy_measurement.active_max_power_list_peak = []
        monthly_energy_measurement.active_max_power_list_off_peak_time = []
        monthly_energy_measurement.active_max_power_list_off_peak = []
        monthly_energy_measurement.reactive_max_power_list_peak_time = []
        monthly_energy_measurement.reactive_max_power_list_peak = []
        monthly_energy_measurement.reactive_max_power_list_off_peak_time = []
        monthly_energy_measurement.reactive_max_power_list_off_peak = []
        monthly_energy_measurement.save()

        monthly_energy_measurement.generated_energy_peak_time = 9

        self.assertEqual(
            None,
            monthly_energy_measurement.save(
                update_fields=['generated_energy_peak_time']))

        self.assertTrue(9,
                        monthly_energy_measurement.generated_energy_peak_time)
    def test_not_create_monthly_energy_measurement_empty_transductor(self):
        en_measurement = MonthlyMeasurement()

        with self.assertRaises(IntegrityError):
            en_measurement.save()
    def test_create_monthly_energy_measurement(self):
        size = len(MonthlyMeasurement.objects.all())

        monthly_en_measurement = MonthlyMeasurement()
        monthly_en_measurement.slave_collection_date = \
            timezone.datetime(2019, 2, 5, 14, 0, 0)
        monthly_en_measurement.trasnductor_collection_date = \
            timezone.datetime(2019, 2, 5, 14, 0, 0)
        monthly_en_measurement.transductor = self.transductor
        monthly_en_measurement.generated_energy_peak_time = 9
        monthly_en_measurement.generated_energy_off_peak_time = 9
        monthly_en_measurement.consumption_peak_time = 9
        monthly_en_measurement.consumption_off_peak_time = 9
        monthly_en_measurement.inductive_power_peak_time = 9
        monthly_en_measurement.inductive_power_off_peak_time = 9
        monthly_en_measurement.capacitive_power_peak_time = 9
        monthly_en_measurement.capacitive_power_off_peak_time = 9
        monthly_en_measurement.active_max_power_peak_time = 9
        monthly_en_measurement.active_max_power_off_peak_time = 9
        monthly_en_measurement.reactive_max_power_peak_time = 9
        monthly_en_measurement.reactive_max_power_off_peak_time = 9
        monthly_en_measurement.active_max_power_list_peak_time = []
        monthly_en_measurement.active_max_power_list_peak = []
        monthly_en_measurement.active_max_power_list_off_peak_time = []
        monthly_en_measurement.active_max_power_list_off_peak = []
        monthly_en_measurement.reactive_max_power_list_peak_time = []
        monthly_en_measurement.reactive_max_power_list_peak = []
        monthly_en_measurement.reactive_max_power_list_off_peak_time = []
        monthly_en_measurement.reactive_max_power_list_off_peak = []

        self.assertIsNone(monthly_en_measurement.save())
        self.assertEqual(size + 1, len(MonthlyMeasurement.objects.all()))
예제 #5
0
    def save_monthly_measurement(self, response, transductor):
        measurement = MonthlyMeasurement()
        measurement.transductor = transductor

        measurement.collection_date = timezone.datetime(
            response[0],
            response[1],
            response[2],
            response[3],
            response[4],
            response[5]
        )

        measurement.generated_energy_peak_time = response[6]
        measurement.generated_energy_off_peak_time = response[7]

        measurement.consumption_peak_time = response[8]
        measurement.consumption_off_peak_time = response[9]

        # FIXME - This 2 measurements comming as NaN from the transductor
        measurement.inductive_power_peak_time = 0
        measurement.inductive_power_off_peak_time = 0

        measurement.capacitive_power_peak_time = 0
        measurement.capacitive_power_off_peak_time = 0

        measurement.active_max_power_peak_time = response[14]
        measurement.active_max_power_off_peak_time = response[15]

        measurement.reactive_max_power_peak_time = response[16]
        measurement.reactive_max_power_off_peak_time = response[17]

        # Arguments refer to initial positions of response information
        # Further information on transductor's Memory Map
        measurement.active_max_power_list_peak_time = []
        year = timezone.datetime.today().year

        date = timezone.datetime(year, response[19] // 256, 
                                 response[19] % 256, response[20] // 256,
                                 response[20] % 256)  
        measurement.active_max_power_list_peak_time.append([response[18],
                                                            date])

        date = timezone.datetime(year, response[22] // 256, 
                                 response[22] % 256, response[23] // 256,
                                 response[23] % 256)

        measurement.active_max_power_list_peak_time.append([response[21],
                                                            date])
        date = timezone.datetime(year, response[25] // 256, 
                                 response[25] % 256, response[26] // 256,
                                 response[26] % 256)  
        measurement.active_max_power_list_peak_time.append([response[24],
                                                            date])

        date = timezone.datetime(year, response[28] // 256, 
                                 response[28] % 256, response[29] // 256,
                                 response[29] % 256)  
        measurement.active_max_power_list_peak_time.append([response[27],
                                                            date])

        measurement.active_max_power_list_off_peak_time = []

        date = timezone.datetime(year, response[31] // 256, 
                                 response[31] % 256, response[32] // 256,
                                 response[32] % 256)  
        measurement.active_max_power_list_off_peak_time.append([
            response[30], 
            date])
        date = timezone.datetime(year, response[34] // 256, 
                                 response[34] % 256, response[35] // 256,
                                 response[35] % 256)  
        measurement.active_max_power_list_off_peak_time.append(
            [response[33], 
             date])

        date = timezone.datetime(year, response[37] // 256, 
                                 response[37] % 256, response[38] // 256,
                                 response[38] % 256)  
        measurement.active_max_power_list_off_peak_time.append(
            [response[36], 
             date])
        date = timezone.datetime(year, response[40] // 256, 
                                 response[40] % 256, response[41] // 256,
                                 response[41] % 256)  
        measurement.active_max_power_list_off_peak_time.append(
            [response[39], 
             date])

        measurement.reactive_max_power_list_peak_time = []
        date = timezone.datetime(year, response[43] // 256, response[43] % 256,
                                 response[44] // 256, response[44] % 256)  
        measurement.reactive_max_power_list_peak_time.append([response[42], 
                                                              date])
        date = timezone.datetime(year, response[46] // 256, response[46] % 256,
                                 response[47] // 256, response[47] % 256)  
        measurement.reactive_max_power_list_peak_time.append([response[45], 
                                                              date])
        date = timezone.datetime(year, response[49] // 256, response[49] % 256,
                                 response[50] // 256, response[50] % 256)  
        measurement.reactive_max_power_list_peak_time.append([response[48], 
                                                              date])
        date = timezone.datetime(year, response[52] // 256, response[52] % 256,
                                 response[53] // 256, response[53] % 256)  
        measurement.reactive_max_power_list_peak_time.append([response[51], 
                                                              date])

        measurement.reactive_max_power_list_off_peak_time = [] 

        date = timezone.datetime(year, response[55] // 256, response[55] % 256,
                                 response[56] // 256, response[56] % 256)  
        measurement.reactive_max_power_list_off_peak_time.append([response[54],
                                                                  date])
        date = timezone.datetime(year, response[58] // 256, response[58] % 256,
                                 response[59] // 256, response[59] % 256)  
        measurement.reactive_max_power_list_off_peak_time.append([response[57],
                                                                  date])
        date = timezone.datetime(year, response[61] // 256, response[61] % 256,
                                 response[62] // 256, response[62] % 256)  
        measurement.reactive_max_power_list_off_peak_time.append([response[60],
                                                                  date])
        date = timezone.datetime(year, response[64] // 256, response[64] % 256,
                                 response[65] // 256, response[65] % 256)  
        measurement.reactive_max_power_list_off_peak_time.append([response[63],
                                                                  date])

        measurement.save()