-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenChart.py
More file actions
87 lines (67 loc) · 2.06 KB
/
genChart.py
File metadata and controls
87 lines (67 loc) · 2.06 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
76
77
78
79
80
81
82
83
84
85
86
87
from typing import TextIO
import numpy as np
from numpy.core.records import array
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
import matplotlib.dates as mdates
import os
import datetime as dt
def GenerateMoistureChart():
f=open('/home/pi/AutoWater/moistureDate',"r")
moisture=[]
raw=[]
time=[]
while True:
nstr=f.readline()
#print(nstr)
if len(nstr) == 0:
break
strarray=nstr.split(",")
#print(strarray)
moisture.append(strarray[1])
raw.append(strarray[3])
time.append(strarray[5])
# print(len(moisture)) #only shows data for five days
lens=len(moisture)-1440
if (len(moisture)>1440):
del moisture[:lens]
del raw[:lens]
del time[:lens]
print(len(moisture))
print(len(raw))
print(time)
#print(moisture)
moisture=list(map(int, moisture))
raw=list(map(int, raw))
time=[dt.datetime.strptime(d,'%Y-%m-%d %H:%M\n') for d in time]
#print(time)
dic={
"moisture":moisture,
"raw":raw,
"time":time
}
testpour={
"time":["2021-12-12 01:34\n","2021-12-12 01:34\n"],
"point":[20,30]
}
df=pd.DataFrame(dic)
df_test=pd.DataFrame(testpour)
#plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M\n'))
#plt.gca().xaxis.set_major_locator(mdates.DayLocator())
plt.plot(df.time, df.moisture, color="#62879e")
plt.xlabel('DateTime')
#plt.xticks(df.time, rotation='vertical')
plt.ylabel("Moisture (%)")
# plt.gca().invert_yaxis() 反轉Y軸
#plt.plot(df_test.time,df_test.point)
plt2=plt.twinx()
plt.title('Moisture')
plt.legend(loc = 'lower left')
plt2.set_ylabel("Raw Data")
plt2.plot(df.time,df.raw,color="#fcba03")
#plt2.invert_yaxis()
plt2.legend(loc= 0)
plt.gcf().autofmt_xdate()
#plt.show()
plt.savefig(f'{os.path.dirname(os.path.abspath(__file__))}/Captured/moisture.jpg', bbox_inches='tight')