hectorespert / python-oligo

Cliente Python (NO OFICIAL) para i-DE (Iberdrola distribución)
https://hectorespert.github.io/python-oligo/
MIT License
70 stars 27 forks source link

Add possibility to retrieve consumption for a time period #14

Closed pbalm closed 3 years ago

pbalm commented 3 years ago

Adding function consumption that will retrieve the hourly consumption in Wh, always for the hour preceding to the corresponding instant.

sonarcloud[bot] commented 3 years ago

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

pbalm commented 3 years ago

I also have some code to convert the output to a pandas DataFrame but I didn't want to include it because that would introduce a dependency on pandas. But perhaps I should have included it in the example in the README. It goes like this:

import pandas as pd

start = date.today() - timedelta(days=7)
end = date.today() - timedelta(days=1)

values = connection.consumption(start, end)

times = pd.date_range(start=start, end=datetime.combine(end, datetime.min.time()) + timedelta(hours=23), freq='h')
times_local = times.tz_localize('CET', ambiguous='NaT', nonexistent='shift_forward')

df = pd.DataFrame(index=times_local, data={'values': values})
hectorespert commented 3 years ago

I also have some code to convert the output to a pandas DataFrame but I didn't want to include it because that would introduce a dependency on pandas. But perhaps I should have included it in the example in the README. It goes like this:

import pandas as pd

start = date.today() - timedelta(days=7)
end = date.today() - timedelta(days=1)

values = connection.consumption(start, end)

times = pd.date_range(start=start, end=datetime.combine(end, datetime.min.time()) + timedelta(hours=23), freq='h')
times_local = times.tz_localize('CET', ambiguous='NaT', nonexistent='shift_forward')

df = pd.DataFrame(index=times_local, data={'values': values})

@pbalm, You could add it in the demo folder: https://github.com/hectorespert/python-oligo/tree/master/demo