changeset 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
files agl.py
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/agl.py	Mon Sep 11 22:14:47 2017 +0930
+++ b/agl.py	Mon Sep 11 22:46:37 2017 +0930
@@ -214,6 +214,7 @@
     xdata = map(lambda f: f.replace(tzinfo = utc).astimezone(lt), ary[:,0])
     xhours = matplotlib.dates.date2num(xdata) * 24
     xdeltas = xhours[1:] - xhours[0:-1]
+    calcd = {}
     for idx in range(len(cols)):
         col = cols[idx]
         ydata = ary[:,idx + 1]
@@ -227,7 +228,9 @@
             scale_max = None
 
         if col in tarrifs:
-            annotation = '%s: $%.2f' % (names[col], (ydata[1:] * xdeltas).sum() / 1000.0 * tarrifs[col])
+            calc = (ydata[1:] * xdeltas).sum() / 1000.0 * tarrifs[col]
+            annotation = '%s: $%.2f' % (names[col], calc)
+            calcd[col] = calc
         else:
             annotation = None
 
@@ -269,6 +272,9 @@
                 annotations.append(line[6])
 
         ax2.legend(loc = 'upper right')
+    if all(map(lambda x: x in calcd, ('power_imported', 'power_exported', 'power_consumed', 'power_generated'))):
+        annotations.append('Saved: $%0.2f' % ((calcd['power_consumed'] - calcd['power_generated']) -
+                                                  (calcd['power_imported'] - calcd['power_exported'])))
     ax1.text(0.02, 0.9, reduce(lambda a, b: a + '\n' + b, annotations),
                  transform = ax1.transAxes, bbox = dict(facecolor = 'red', alpha = 0.5),
                  ha = 'left', va = 'top')