Mercurial > ~darius > hgwebdir.cgi > agl
comparison agl.py @ 17:227a2a524675
Annotate how much was saved if the data is plotted.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 11 Sep 2017 22:46:37 +0930 |
parents | 201ad77bac40 |
children | 156ab071a9de |
comparison
equal
deleted
inserted
replaced
16:201ad77bac40 | 17:227a2a524675 |
---|---|
212 return | 212 return |
213 # Convert TZ naive UTC to TZ aware UTC then adjust to local time | 213 # Convert TZ naive UTC to TZ aware UTC then adjust to local time |
214 xdata = map(lambda f: f.replace(tzinfo = utc).astimezone(lt), ary[:,0]) | 214 xdata = map(lambda f: f.replace(tzinfo = utc).astimezone(lt), ary[:,0]) |
215 xhours = matplotlib.dates.date2num(xdata) * 24 | 215 xhours = matplotlib.dates.date2num(xdata) * 24 |
216 xdeltas = xhours[1:] - xhours[0:-1] | 216 xdeltas = xhours[1:] - xhours[0:-1] |
217 calcd = {} | |
217 for idx in range(len(cols)): | 218 for idx in range(len(cols)): |
218 col = cols[idx] | 219 col = cols[idx] |
219 ydata = ary[:,idx + 1] | 220 ydata = ary[:,idx + 1] |
220 if col in convs: | 221 if col in convs: |
221 ydata = convs[col](ydata) | 222 ydata = convs[col](ydata) |
225 else: | 226 else: |
226 scale_min = None | 227 scale_min = None |
227 scale_max = None | 228 scale_max = None |
228 | 229 |
229 if col in tarrifs: | 230 if col in tarrifs: |
230 annotation = '%s: $%.2f' % (names[col], (ydata[1:] * xdeltas).sum() / 1000.0 * tarrifs[col]) | 231 calc = (ydata[1:] * xdeltas).sum() / 1000.0 * tarrifs[col] |
232 annotation = '%s: $%.2f' % (names[col], calc) | |
233 calcd[col] = calc | |
231 else: | 234 else: |
232 annotation = None | 235 annotation = None |
233 | 236 |
234 if units[col] == yaxisunits1: | 237 if units[col] == yaxisunits1: |
235 ax = ax1lines | 238 ax = ax1lines |
267 ax2.set_ylim(bottom = line[4], top = line[5]) | 270 ax2.set_ylim(bottom = line[4], top = line[5]) |
268 if line[6] != None: | 271 if line[6] != None: |
269 annotations.append(line[6]) | 272 annotations.append(line[6]) |
270 | 273 |
271 ax2.legend(loc = 'upper right') | 274 ax2.legend(loc = 'upper right') |
275 if all(map(lambda x: x in calcd, ('power_imported', 'power_exported', 'power_consumed', 'power_generated'))): | |
276 annotations.append('Saved: $%0.2f' % ((calcd['power_consumed'] - calcd['power_generated']) - | |
277 (calcd['power_imported'] - calcd['power_exported']))) | |
272 ax1.text(0.02, 0.9, reduce(lambda a, b: a + '\n' + b, annotations), | 278 ax1.text(0.02, 0.9, reduce(lambda a, b: a + '\n' + b, annotations), |
273 transform = ax1.transAxes, bbox = dict(facecolor = 'red', alpha = 0.5), | 279 transform = ax1.transAxes, bbox = dict(facecolor = 'red', alpha = 0.5), |
274 ha = 'left', va = 'top') | 280 ha = 'left', va = 'top') |
275 ndays = int(max(1, round(((end - start).total_seconds()) / 86400))) | 281 ndays = int(max(1, round(((end - start).total_seconds()) / 86400))) |
276 for ax in fig.get_axes(): | 282 for ax in fig.get_axes(): |