-
Notifications
You must be signed in to change notification settings - Fork 2
/
charts.py
executable file
·54 lines (37 loc) · 1.15 KB
/
charts.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
#!/usr/bin/env python
from pyfroniussolarapi import solarapi
import pickle
import csv
def save_obj(obj, name ):
with open('obj/'+ name + '.pkl', 'wb') as f:
pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL)
def load_obj(name ):
with open('obj/' + name + '.pkl', 'rb') as f:
return pickle.load(f)
#api = solarapi.solarapi("192.168.3.110",True)
#data = api.GetAllArchiveData()
#save_obj(data,"archivedata")
data = load_obj("archivedata")
f = open("archivedata.csv", 'wt')
try:
writer = csv.writer(f)
mainkeys = data.keys()
writer.writerow( ['']+mainkeys )
timekeys = []
for columnno in range(0,len( data.keys() )):
column_timekeys = data[ data.keys()[columnno] ][0].keys()
timekeys+=column_timekeys
# remove duplicates and sort ascending
timekeys = list(set(timekeys))
timekeys.sort(key=int)
for timekey in timekeys:
row = [timekey]
for columnname in mainkeys:
if timekey in data[columnname][0]:
row+=[data[columnname][0][timekey]]
else:
row+=[0]
writer.writerow( row )
finally:
f.close()
#print data.keys()