-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharts_read.py
131 lines (110 loc) · 3.78 KB
/
charts_read.py
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import csv
import matplotlib.pyplot as plt
def chart_today_img():
time = []
value = []
with open('data/energy.csv') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
energy = float(row[0])
with open('data/charts_today.csv') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
split = row[0].split(';')
time.append(split[0])
value.append(float(split[1]))
plt.figure(figsize=(10, 5))
plt.plot(time, value, color="dodgerblue")
plt.xlabel('Hour')
plt.ylabel('Value')
plt.title('Daily production')
plt.xticks(['6:00', '9:00', '12:00', '15:00', '18:00', '21:00'])
plt.yticks([1, 2, 3, 4, 5, 6, 7], ['1kW', '2kW', '3kW', '4kW', '5kW', '6kW', '7kW'])
plt.grid(axis='y')
plt.savefig('img/charts_today.jpg', format='jpg')
plt.close()
return energy
def get_static_data():
data = []
with open('data/basic.csv') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
value = row[0].split(';')
data.append(value[1])
return data
def charts_month_img(month):
time = []
value = []
with open('data/charts_month_' + month + '.csv') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
split = row[0].split(';')
time.append(split[0])
value.append(float(split[1]))
plt.figure(figsize=(10, 5))
plt.bar(time, value, color="dodgerblue", edgecolor="white", width=1, linewidth=5)
plt.xlabel('Day')
plt.ylabel('Value')
plt.title('Monthly production')
plt.yticks([10, 20, 30, 40], ['10kWh', '20kWh', '30kWh', '40kWh'])
plt.grid(axis='y')
plt.savefig('img/charts_month_' + month + '.jpg', format='jpg')
plt.close()
def charts_prediction_img():
time = []
value = []
with open('data/energy_prediction.csv') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
split = row[0].split(';')
time.append(split[0])
value.append(float(split[1]))
plt.figure(figsize=(10, 5))
plt.bar(time, value, color="dodgerblue", edgecolor="white", width=1, linewidth=5)
plt.xlabel('Day')
plt.ylabel('Value')
plt.title('Predictions')
plt.yticks([10, 20, 30, 40], ['10kWh', '20kWh', '30kWh', '40kWh'])
plt.grid(axis='y')
plt.savefig('img/energy_prediction.jpg', format='jpg')
plt.close()
def get_sum_energy_today():
with open('data/energy.csv') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
sum_today = float(row[0])
return round(sum_today, 2)
def get_sum_energy_prediction():
sum_prediction = 0
with open('data/energy_prediction.csv') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
split = row[0].split(';')
sum_prediction += float(split[1])
return round(sum_prediction, 2)
def get_sum_energy_today_month():
sum_today_month = 0
with open('data/charts_month_today.csv') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
split = row[0].split(';')
sum_today_month += float(split[1])
return round(sum_today_month, 2)
def get_sum_energy_last_month():
sum_last_month = 0
with open('data/charts_month_last.csv') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
split = row[0].split(';')
sum_last_month += float(split[1])
return round(sum_last_month, 2)
def all_img():
chart_today_img()
charts_month_img('today')
charts_month_img('last')
charts_prediction_img()
#print(get_sum_energy_today())
#print(get_sum_energy_prediction())
#print(get_sum_energy_today_month())
#print(get_sum_energy_last_month())
all_img()