-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplotRoofBatteries.py
More file actions
47 lines (42 loc) · 1.52 KB
/
plotRoofBatteries.py
File metadata and controls
47 lines (42 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/local/python/bin/python
import pymysql
import matplotlib.pyplot as plt
def get_battery_data(start, finish):
"""
"""
qry = """
SELECT
last_update, north_v2, north_v4,
south_v1, south_v4
FROM roof_battery_voltage
WHERE last_update > %s AND last_update < %s
"""
qry_args = (start, finish)
with pymysql.connect(host='10.2.5.32', db='ngts_ops',
cursorclass=pymysql.cursors.DictCursor) as cur:
cur.execute(qry, qry_args)
results = cur.fetchall()
return results
if __name__ == "__main__":
start = "2019-09-01 00:00:00"
finish = "2019-12-31 23:59:59"
datas = get_battery_data(start, finish)
time, north_1, north_2, south_1, south_2 = [], [], [], [], []
for data in datas:
time.append(data['last_update'])
north_1.append(data['north_v2'])
north_2.append(data['north_v4'])
south_1.append(data['south_v1'])
south_2.append(data['south_v4'])
fig, ax = plt.subplots(2, figsize=(10, 10), sharex=True, sharey=True)
ax[0].plot(time[::500], north_1[::500], 'r-')
ax[0].plot(time[::500], north_2[::500], 'k-')
ax[0].set_ylabel('Volts (north)')
ax[0].legend(('battery 1', 'battery 2',), )
ax[1].plot(time[::500], south_1[::500], 'r-')
ax[1].plot(time[::500], south_2[::500], 'k-')
ax[1].legend(('battery 1', 'battery 2',), )
ax[1].set_ylabel('Volts (south)')
ax[1].set_xlabel('Date')
fig.tight_layout()
fig.savefig('battery_voltage.png', dpi=300)