Mercurial > ~darius > hgwebdir.cgi > agl
comparison agl.py @ 5:b42baa411817
Display battery_power (which seems to be in milliwatts..?)
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 11 Sep 2017 12:39:08 +0930 |
parents | deb3adc4e086 |
children | 2e50426c946f |
comparison
equal
deleted
inserted
replaced
4:deb3adc4e086 | 5:b42baa411817 |
---|---|
89 updatedb(cur, data) | 89 updatedb(cur, data) |
90 dbh.commit() | 90 dbh.commit() |
91 date += datetime.timedelta(days = 1) | 91 date += datetime.timedelta(days = 1) |
92 | 92 |
93 if args.graph: | 93 if args.graph: |
94 graph(args.filename, cur, ['battery_charge', 'power_imported', 'power_exported', 'power_consumed', 'power_generated'], start, end) | 94 graph(args.filename, cur, ['battery_charge', 'battery_power', 'power_imported', 'power_exported', 'power_consumed', 'power_generated'], start, end) |
95 | 95 |
96 def mkdb(cur): | 96 def mkdb(cur): |
97 cur.execute(''' | 97 cur.execute(''' |
98 CREATE TABLE IF NOT EXISTS agl ( | 98 CREATE TABLE IF NOT EXISTS agl ( |
99 t_stamp TIMESTAMP PRIMARY KEY, | 99 t_stamp TIMESTAMP PRIMARY KEY, |
130 'site_cons_battery' : 'Watt', | 130 'site_cons_battery' : 'Watt', |
131 'site_cons_grid' : 'Watt', | 131 'site_cons_grid' : 'Watt', |
132 'site_cons_pv' : 'Watt' | 132 'site_cons_pv' : 'Watt' |
133 } | 133 } |
134 | 134 |
135 convs = { | |
136 'battery_power' : lambda a: a / 1000.0 | |
137 } | |
138 | |
135 names = { | 139 names = { |
136 'battery_charge' : 'Battery Charge', | 140 'battery_charge' : 'Battery Charge', |
137 'battery_power' : 'Battery Power', | 141 'battery_power' : 'Battery Power', |
138 'power_consumed' : 'Power Consumed', | 142 'power_consumed' : 'Power Consumed', |
139 'power_expected' : 'Power Expected', | 143 'power_expected' : 'Power Expected', |
197 print('No data') | 201 print('No data') |
198 return | 202 return |
199 # Convert naive UTC to proper UTC then adjust to local time | 203 # Convert naive UTC to proper UTC then adjust to local time |
200 xdata = map(lambda f: f.replace(tzinfo = utc).astimezone(lt), ary[:,0]) | 204 xdata = map(lambda f: f.replace(tzinfo = utc).astimezone(lt), ary[:,0]) |
201 for idx in range(len(cols)): | 205 for idx in range(len(cols)): |
206 ydata = ary[:,idx + 1] | |
207 if cols[idx] in convs: | |
208 ydata = convs[cols[idx]](ydata) | |
202 if units[cols[idx]] == yaxisunits1: | 209 if units[cols[idx]] == yaxisunits1: |
203 ax1lines.append([xdata, ary[:,idx + 1], names[cols[idx]], colourlist[colouridx]]) | 210 ax1lines.append([xdata, ydata, names[cols[idx]], colourlist[colouridx]]) |
204 else: | 211 else: |
205 ax2lines.append([xdata, ary[:,idx + 1], names[cols[idx]], colourlist[colouridx]]) | 212 ax2lines.append([xdata, ydata, names[cols[idx]], colourlist[colouridx]]) |
206 colouridx += 1 | 213 colouridx += 1 |
207 | 214 |
208 if fname == None: | 215 if fname == None: |
209 import matplotlib.pylab | 216 import matplotlib.pylab |
210 fig = matplotlib.pylab.figure() | 217 fig = matplotlib.pylab.figure() |