def test_upstream_meter(self): meter1 = ElecMeter(metadata={'site_meter': True}, meter_id=METER_ID) self.assertIsNone(meter1.upstream_meter()) meter2 = ElecMeter(metadata={'submeter_of': 1}, meter_id=METER_ID2) self.assertEquals(meter2.upstream_meter(), meter1) meter3 = ElecMeter(metadata={'submeter_of': 2}, meter_id=METER_ID3) self.assertEquals(meter3.upstream_meter(), meter2)
def correlation(self): meter_1 = ElecMeter(store=self.datastore, metadata=self.meter_meta, meter_id=METER_ID) meter_2 = ElecMeter(store=self.datastore, metadata=self.meter_meta, meter_id=METER_ID2) # Let us get raw DataFrames df1 = self.datastore.store.get('/building1/elec/meter1') df2 = self.datastore.store.get('/building1/elec/meter2') # Let us compute the value using nilmtk corr12_nilmtk = meter_1.correlation(meter_2) print("Correlation using nilmtk:", corr12_nilmtk) # Let us now compute the value using Pandas functions corr12_pandas = df1.corr(df2) print("Correlation using pandas:", corr12_pandas) from pandas.util.testing import assert_frame_equal assert_frame_equal(corr12_nilmtk, corr12_pandas)
def test_total_energy(self): meter = ElecMeter(meter_id=METER_ID) with self.assertRaises(RuntimeError): meter.total_energy() meter = ElecMeter(store=self.datastore, metadata=self.meter_meta, meter_id=METER_ID) energy = meter.total_energy() check_energy_numbers(self, energy) # Check a second time to check cache energy = meter.total_energy() check_energy_numbers(self, energy) meter.clear_cache() # Check period_range period_index = pd.period_range(start=meter.get_timeframe().start, periods=5, freq='D') meter.total_energy(sections=period_index, full_results=True)
def test_select_best_ac_type(self): self.assertEqual(measure.select_best_ac_type(['reactive']), 'reactive') self.assertEqual( measure.select_best_ac_type(['active', 'reactive', 'apparent']), 'active') ElecMeter.meter_devices.update({ 'test model': { 'measurements': [{ 'physical_quantity': 'power', 'type': 'apparent' }] } }) meter_id = ElecMeterID(1, 1, 'REDD') meter = ElecMeter(metadata={'device_model': 'test model'}, meter_id=meter_id) self.assertEqual( measure.select_best_ac_type(['reactive'], meter.available_power_ac_types()), 'reactive')
def test_proportion_of_energy(self): meter = ElecMeter(store=self.datastore, metadata=self.meter_meta, meter_id=METER_ID) self.assertEquals(meter.proportion_of_energy(meter), 1.0)
def test_load(self): meter = ElecMeter(store=self.datastore, metadata=self.meter_meta, meter_id=METER_ID) self.assertEqual(meter.metadata['device_model'], 'Energy Meter') self.assertEqual(meter.device['sample_period'], 10)