-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_strings.py
More file actions
76 lines (64 loc) · 2.62 KB
/
Copy pathplot_strings.py
File metadata and controls
76 lines (64 loc) · 2.62 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import matplotlib
matplotlib.use('Agg')
import sqlite3
import datetime
import matplotlib.pyplot as plt
import matplotlib.dates as mdate
from matplotlib import style
import sys
import os
import froniusconfig
def plot_week():
conn = sqlite3.connect(froniusconfig.dbname)
c = conn.cursor()
c.execute(''' SELECT * FROM stringdata WHERE DATETIME(timestamp,'unixepoch') > DATETIME('now','-7 days');''')
data = c.fetchall()
timestamp = []
current_dc_string_1_a = []
current_dc_string_2_a = []
voltage_dc_string_1_v = []
voltage_dc_string_2_v = []
power_w = []
local_tz = datetime.datetime.now(datetime.timezone(datetime.timedelta(0))).astimezone().tzinfo
for row in data:
timestamp.append(row[0])
current_dc_string_1_a.append(row[1])
current_dc_string_2_a.append(row[2])
voltage_dc_string_1_v.append(row[3])
voltage_dc_string_2_v.append(row[4])
power_w.append(row[5])
timestamp_converted = [mdate.epoch2num(row) for row in timestamp]
matplotlib.rcParams.update({'font.size': 8})
fig, ax1 = plt.subplots()
fig.set_figheight(4)
fig.set_figwidth(16)
fig.set_dpi(100)
fig.autofmt_xdate(rotation=90)
color1 = 'tab:blue'
color2 = 'tab:cyan'
ax1.set_xlabel('time')
ax1.set_ylabel('Current [A]', color=color1)
ax1.xaxis.set_major_locator(mdate.HourLocator(interval=4))
ax1.xaxis.set_major_formatter(mdate.DateFormatter('%d.%m.%Y %H:%M',tz=local_tz))
ax1.xaxis.set_minor_locator(mdate.HourLocator(interval=1))
ax1.xaxis.grid(which='minor', linewidth=0.5)
ax1.plot_date(timestamp_converted,current_dc_string_1_a, xdate=True, color=color1, linestyle='solid', marker='None')
ax1.plot_date(timestamp_converted,current_dc_string_2_a, xdate=True, color=color2, linestyle='solid', marker='None')
ax2 = ax1.twinx()
color3 = 'tab:red'
color4 = 'tab:orange'
ax2.set_ylabel('Voltage [V]', color=color3)
ax2.xaxis.set_major_locator(mdate.HourLocator(interval=4))
ax2.xaxis.set_major_formatter(mdate.DateFormatter('%d.%m.%Y %H:%M', tz=local_tz))
ax2.xaxis.set_minor_locator(mdate.HourLocator(interval=1))
ax2.xaxis.grid(which='minor', linewidth=0.5)
ax2.plot_date(timestamp_converted, voltage_dc_string_1_v, xdate=True,linestyle='solid', marker='None', color=color3)
ax2.plot_date(timestamp_converted, voltage_dc_string_2_v, xdate=True,linestyle='solid', marker='None', color=color4)
plt.grid(True)
plt.tight_layout()
plt.savefig(froniusconfig.figurepath + 'fronius_strings_week.png')
plt.close()
def main(argv):
plot_week()
if __name__ == "__main__":
main(sys.argv)