コード例 #1
0
    def test_create_minutely_energy_measurement_with_defaults(self):
        size = len(MinutelyMeasurement.objects.all())

        minutely_en_measurement = MinutelyMeasurement()
        minutely_en_measurement.transductor = self.transductor

        self.assertIsNone(minutely_en_measurement.save())
        self.assertEqual(size + 1, len(MinutelyMeasurement.objects.all()))
コード例 #2
0
    def test_create_phase_drop_event(self):
        before = len(PhaseDropEvent.objects.all())

        a = MinutelyMeasurement()
        a.voltage_a = 220
        a.voltage_b = 220
        a.voltage_c = 50
        a.transductor = self.transductor
        a.check_measurements()

        self.assertEqual(before + 1, len(PhaseDropEvent.objects.all()))
コード例 #3
0
    def test_update_minutely_energy_measurement(self):
        minutely_energy_measurement = MinutelyMeasurement()
        minutely_energy_measurement.transductor = \
            EnergyTransductor.objects.get(
                serial_number=87654321
            )
        minutely_energy_measurement.save()

        minutely_energy_measurement.total_power_factor = 100

        self.assertEqual(
            None,
            minutely_energy_measurement.save(
                update_fields=['total_power_factor']))

        self.assertTrue(100, minutely_energy_measurement.total_power_factor)
コード例 #4
0
    def test_not_create_minutely_energy_measurement_empty_transductor(self):
        en_measurement = MinutelyMeasurement()

        with self.assertRaises(IntegrityError):
            en_measurement.save()
コード例 #5
0
    def test_create_minutely_energy_measurement(self):
        size = len(MinutelyMeasurement.objects.all())

        minutely_en_measurement = MinutelyMeasurement()
        minutely_en_measurement.slave_collection_date = \
            timezone.datetime(2019, 2, 5, 14, 0, 0)
        minutely_en_measurement.transductor_collection_date = \
            timezone.datetime(2019, 2, 5, 14, 0, 0)
        minutely_en_measurement.transductor = self.transductor
        minutely_en_measurement.frequency_a = 666
        minutely_en_measurement.voltage_a = 666
        minutely_en_measurement.voltage_b = 666
        minutely_en_measurement.voltage_c = 666
        minutely_en_measurement.current_a = 666
        minutely_en_measurement.current_b = 666
        minutely_en_measurement.current_c = 666
        minutely_en_measurement.active_power_a = 666
        minutely_en_measurement.active_power_b = 666
        minutely_en_measurement.active_power_c = 666
        minutely_en_measurement.total_active_power = 666
        minutely_en_measurement.reactive_power_a = 666
        minutely_en_measurement.reactive_power_b = 666
        minutely_en_measurement.reactive_power_c = 666
        minutely_en_measurement.total_reactive_power = 666
        minutely_en_measurement.apparent_power_a = 666
        minutely_en_measurement.apparent_power_b = 666
        minutely_en_measurement.apparent_power_c = 666
        minutely_en_measurement.total_apparent_power = 666
        minutely_en_measurement.power_factor_a = 666
        minutely_en_measurement.power_factor_b = 666
        minutely_en_measurement.power_factor_c = 666
        minutely_en_measurement.total_power_factor = 666
        minutely_en_measurement.dht_voltage_a = 666
        minutely_en_measurement.dht_voltage_b = 666
        minutely_en_measurement.dht_voltage_c = 666
        minutely_en_measurement.dht_current_a = 666
        minutely_en_measurement.dht_current_b = 666
        minutely_en_measurement.dht_current_c = 666

        self.assertIsNone(minutely_en_measurement.save())
        self.assertEqual(size + 1, len(MinutelyMeasurement.objects.all()))
コード例 #6
0
    def test_create_precarious_voltage_event(self):
        before = len(PrecariousVoltageEvent.objects.all())

        a = MinutelyMeasurement()
        a.voltage_a = 220
        a.voltage_b = 220
        a.voltage_c = 199
        a.transductor = self.transductor
        a.check_measurements()

        b = MinutelyMeasurement()
        b.voltage_a = 220
        b.voltage_b = 230
        b.voltage_c = 220
        b.transductor = self.transductor
        b.check_measurements()

        self.assertEqual(before + 2, len(PrecariousVoltageEvent.objects.all()))
コード例 #7
0
    def test_create_critical_voltage_event(self):
        before = len(CriticalVoltageEvent.objects.all())

        a = MinutelyMeasurement()
        a.voltage_a = 220
        a.voltage_b = 400
        a.voltage_c = 200
        a.transductor = self.transductor
        a.check_measurements()

        b = MinutelyMeasurement()
        b.voltage_a = 220
        b.voltage_b = 180
        b.voltage_c = 200
        b.transductor = self.transductor
        b.check_measurements()

        self.assertEqual(before + 2, len(CriticalVoltageEvent.objects.all()))
コード例 #8
0
ファイル: models.py プロジェクト: pablodiegoss/SMI-Slave
 def save_rescued_data(self, response, transductor):
     measurement = MinutelyMeasurement()
     if(MinutelyMeasurement.objects.filter(
             collection_date=response[0][0]).__len__() != 0):
         return response[0][0]
     measurement.collection_date = response[0][0]       
     measurement.voltage_a = response[0][1]
     measurement.voltage_b = response[0][2]
     measurement.voltage_c = response[0][3]
     measurement.current_a = response[0][4]
     measurement.current_b = response[0][5]
     measurement.current_c = response[0][6]
     measurement.total_active_power = response[0][7]
     measurement.total_reactive_power = response[0][8]
     measurement.transductor = transductor
     measurement.save()
     return measurement.collection_date
コード例 #9
0
ファイル: models.py プロジェクト: pablodiegoss/SMI-Slave
    def save_minutely_measurement(self, response, transductor):
        from data_reader.utils import perform_data_rescue

        self.verify_collection_date(response, transductor)

        minutely_measurement = MinutelyMeasurement()
        minutely_measurement.transductor = transductor

        # saving the datetime from transductor
        date = timezone.datetime(
            response[0],
            response[1],
            response[2],
            response[3],
            response[4],
            response[5]
        )
        minutely_measurement.collection_date = date

        minutely_measurement.frequency_a = response[6]
        minutely_measurement.voltage_a = response[7]
        minutely_measurement.voltage_b = response[8]
        minutely_measurement.voltage_c = response[9]
        minutely_measurement.current_a = response[10]
        minutely_measurement.current_b = response[11]
        minutely_measurement.current_c = response[12]
        minutely_measurement.active_power_a = response[13]
        minutely_measurement.active_power_b = response[14]
        minutely_measurement.active_power_c = response[15]
        minutely_measurement.total_active_power = response[16]
        minutely_measurement.reactive_power_a = response[17]
        minutely_measurement.reactive_power_b = response[18]
        minutely_measurement.reactive_power_c = response[19]
        minutely_measurement.total_reactive_power = response[20]
        minutely_measurement.apparent_power_a = response[21]
        minutely_measurement.apparent_power_b = response[22]
        minutely_measurement.apparent_power_c = response[23]
        minutely_measurement.total_apparent_power = response[24]
        minutely_measurement.power_factor_a = response[25]
        minutely_measurement.power_factor_b = response[26]
        minutely_measurement.power_factor_c = response[27]
        minutely_measurement.total_power_factor = response[28]
        minutely_measurement.dht_voltage_a = response[29]
        minutely_measurement.dht_voltage_b = response[30]
        minutely_measurement.dht_voltage_c = response[31]
        minutely_measurement.dht_current_a = response[32]
        minutely_measurement.dht_current_b = response[33]
        minutely_measurement.dht_current_c = response[34]
        minutely_measurement.consumption_a = response[35]
        minutely_measurement.consumption_b = response[36]
        minutely_measurement.consumption_c = response[37]
        minutely_measurement.total_consumption = response[38]

        minutely_measurement.save()
        if transductor.broken:
            collect_old_data_thread = Thread(
                target=perform_data_rescue,
                args=(transductor, transductor.last_collection,
                      date)
            )
            collect_old_data_thread.start()
            transductor.broken = False

        transductor.last_collection = minutely_measurement.collection_date 
        transductor.save()