コード例 #1
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()))
コード例 #2
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()