Mercurial > ~darius > hgwebdir.cgi > vanlogger
comparison graph.py @ 8:30e7adf283ca
Add depth of discharge annotation when plotting state_of_charge
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Fri, 22 Dec 2017 13:10:23 +0100 |
parents | a7e9775b33f6 |
children | 899bc9c22787 |
comparison
equal
deleted
inserted
replaced
7:40a3b403a096 | 8:30e7adf283ca |
---|---|
11 import requests | 11 import requests |
12 import sqlite3 | 12 import sqlite3 |
13 import tzlocal | 13 import tzlocal |
14 | 14 |
15 class Column(object): | 15 class Column(object): |
16 def __init__(self, rowname, title, table, units, limits = (None, None), conv = None): | 16 def __init__(self, rowname, title, table, units, limits = (None, None), conv = None, annofn = None): |
17 self.rowname = rowname | 17 self.rowname = rowname |
18 self.title = title | 18 self.title = title |
19 self.table = table | 19 self.table = table |
20 self.units = units | 20 self.units = units |
21 self.limits = limits | 21 self.limits = limits |
22 self.conv = None | 22 self.conv = conv |
23 self.annofn = annofn | |
23 | 24 |
24 columns = [ | 25 columns = [ |
25 Column('main_voltage', 'Battery Voltage', 'eprolog', 'Vdc'), | 26 Column('main_voltage', 'Battery Voltage', 'eprolog', 'Vdc'), |
26 Column('aux_voltage', 'Aux Voltage', 'eprolog', 'Vdc'), | 27 Column('aux_voltage', 'Aux Voltage', 'eprolog', 'Vdc'), |
27 Column('battery_curr', 'Battery Current', 'eprolog', 'A'), | 28 Column('battery_curr', 'Battery Current', 'eprolog', 'A'), |
28 Column('amp_hours', 'Battery Amp Hours', 'eprolog', 'Ah'), | 29 Column('amp_hours', 'Battery Amp Hours', 'eprolog', 'Ah'), |
29 Column('state_of_charge', 'State of Charge', 'eprolog', '%', (0, 100)), | 30 Column('state_of_charge', 'State of Charge', 'eprolog', '%', (0, 100), annofn = lambda xdata, ydata: 'DoD: %.1f' % (100 - ydata.min())), |
30 Column('time_remaining', 'Time Remaining', 'eprolog', 'min'), | 31 Column('time_remaining', 'Time Remaining', 'eprolog', 'min'), |
31 Column('battery_temp', 'Battery Temperature', 'eprolog', 'C'), | 32 Column('battery_temp', 'Battery Temperature', 'eprolog', 'C'), |
32 | 33 |
33 Column('ac_act_power', 'Active Power', 'giantlog', 'W'), | 34 Column('ac_act_power', 'Active Power', 'giantlog', 'W'), |
34 Column('ac_app_power', 'Apparent Power', 'giantlog', 'W'), | 35 Column('ac_app_power', 'Apparent Power', 'giantlog', 'W'), |
163 c.ydata = map(c.conv, c.ydata) | 164 c.ydata = map(c.conv, c.ydata) |
164 | 165 |
165 scale_min, scale_max = c.limits | 166 scale_min, scale_max = c.limits |
166 | 167 |
167 # DoD? | 168 # DoD? |
168 c.annotation = None | 169 if c.annofn != None: |
170 c.annotation = c.annofn(c.xdata, c.ydata) | |
171 else: | |
172 c.annotation = None | |
169 | 173 |
170 # Work out which axis to plot on | 174 # Work out which axis to plot on |
171 if c.units == yaxisunits1: | 175 if c.units == yaxisunits1: |
172 ax = ax1lines | 176 ax = ax1lines |
173 else: | 177 else: |