I am trying to build an API to Octopus Engergy and I can make an API call and retrieve energy consumption data by an hourly unit over a few days like so:
download_manager = DownloadManager(meter_mpan=meter_mpan,
meter_serial=meter_serial,
api_key=octopus_api_key)
s_elec_consumption = download_manager.create_elec_consumption_s()
print(s_elec_consumption)
r = download_manager.retrieve_electricity_consumption(meter_mpan=meter_mpan, meter_serial=meter_serial,period_from='2021-02-18T00:00:00Z',
period_to='2021-02-19T00:00:00Z')
print(r.json().keys())
r.json().keys()
dict2 = r.json()['results']
# I slice the data from the APi into lists to make it easier to read in a chart (see below)
c = 0
consumption = []
utc = []
time_period = []
for i in dict2:
consumption.append(dict2[c]['consumption'])
utc = (dict2[c]['interval_end'])
date = utc[5:10] # slicing from the elemnet in utc
time = utc[11:16] # slicing from the elemnet in utc
t = f"{date} {time}"
print(t)
time_period.append(t)
c += 1
# I plot my data
fig, ax = plt.subplots()
ax.plot(time_period, consumption, linewidth=3)
# set chart titkle and axis title
ax.set_title("Octopus Energy Usage", fontsize = 14)
ax.set_ylabel("KwH", fontsize = 14)
ax.set_xlabel("Date/Time", fontsize = 14)
plt.show()
Anyway the above code works fine but I end up with a chart that is basically unreadable (See x-axis in the graph below).
So my question is: Is there a way to tell the api to only send a whole or half days data (rather than hourly data) or is there a way I can sum the data that I get back from the API and use the chart to show the summed data. As an FYI the data teh API sends back is like the following. Thanks
2021-02-18 23:00:00+00:00 0.102
2021-02-18 22:30:00+00:00 0.118
2021-02-18 22:00:00+00:00 0.153
2021-02-18 21:30:00+00:00 0.133
2021-02-18 21:00:00+00:00 0.185
