opengridcc / opengrid-dev

Open source building monitoring, analysis and control
Apache License 2.0
26 stars 21 forks source link

Unit conversion and resampling not playing along nicely #124

Open JrtPec opened 8 years ago

JrtPec commented 8 years ago

I tried putting myself in the shoes of someone who's not so experienced with OpenGrid while trying to design an analysis. I want to do an analysis on monthly gas consumption, preferably in kWh.

gas_sensor.get_data(resample='M', unit='kWh') gives me UndefinedUnitError: 'M' is not defined in the unit registry, other combinations give me a range of ValueError, DimensionalityError, ...

Little did I know that I had to flag diff=False, only so I can do df.diff() afterwards to get a monthly gas consumption in kWh.

Anyhow... something we could work on this evening?

JrtPec commented 8 years ago

I think the problem lies in sensor._unit_conversion_factor(), on lines like source = self.unit + '/' + resample, which works great when resample is something like 'min' or 'hour'. I just tried 'MS', which is start of month, but was interpreted as MegaSiemens... :-/

JrtPec commented 8 years ago

get_data() should have 4 arguments:

If the source is cumulative: power & energy imply a diff(), energy cumulative implies no diff.

If the source is not cumulative: power & energy are ok, energy cumulative implies a sum().

We have to rewrite the conversion from power to energy.