-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestplot.py
89 lines (78 loc) · 2.32 KB
/
testplot.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
import time
import datetime as dt
import matplotlib.pyplot as plt
import matplotlib.dates as dat
import sqlite3
from dateutil import tz
def getHistData (numSamples,location):
print(location)
curs.execute("SELECT * FROM sensorsData WHERE zonename = (?) ORDER BY ttime DESC, tdata DESC LIMIT (?) ",(location, str(numSamples)))
data = curs.fetchall()
#dates = []
timeStamps = []
temps = []
hums = []
#from_zone = tz.gettz('Europe/Rome')
#to_zone = tz.gettz('UTC')
for row in reversed(data):
#dates.append(row[0])
timeStamp=dt.datetime.strptime(row[0]+row[1], '%Y-%m-%d%H:%M:%S')
#timeStamps.append(dt.datetime.strptime(row[0]+row[1], '%Y-%m-%d%H:%M:%S'))
timeStamp=datetime_from_utc_to_local(timeStamp)
#timeStamp = timeStamp.astimezone(to_zone)
timeStamps.append(timeStamp)
temps.append(row[4])
hums.append(row[5])
return timeStamps, temps, hums
#def plot_temp():
# timeStamps, temps, hums = getHistData(numSamples,location)
# ys = temps
# fig = Figure()
# axis = fig.add_subplot(1, 1, 1)
# axis.set_title("Temperature [°C]")
# axis.set_xlabel("Samples")
# axis.grid(True)
# xs = range(numSamples)
# axis.plot(xs, ys)
# canvas = FigureCanvas(fig)
# output = io.BytesIO()
# canvas.print_png(output)
# response = make_response(output.getvalue())
# response.mimetype = 'image/png'
# return response
def plot_hum():
timeStamps, temps, hums = getHistData(numSamples,location)
#ys = hums
ys= temps
xs = timeStamps
formatter = dat.DateFormatter('%d-%m %H:%M')
#fig = Figure()
#axis = fig.add_subplot(1, 1, 1)
#canvas = FigureCanvas(fig)
#output = io.BytesIO()
#canvas.print_png(output)
#response = make_response(output.getvalue())
#response.mimetype = 'image/png'
#return response
fig, ax = plt.subplots()
ax.set_title("Humidity [%]")
ax.grid(True)
plt.plot_date(xs, ys,'o-')
#ax.xaxis.set_major_locator(loc)
ax.xaxis.set_major_formatter(formatter)
ax.xaxis.set_tick_params(rotation=30, labelsize=10)
plt.show()
def datetime_from_utc_to_local(utc_datetime):
now_timestamp = time.time()
offset = dt.datetime.fromtimestamp(now_timestamp) - dt.datetime.utcfromtimestamp(now_timestamp)
return utc_datetime + offset
conn=sqlite3.connect('tempDB.db')
curs=conn.cursor()
numSamples = 1500
location="SOGGIORNO"
plot_hum()
# Create figure for plotting
#fig = plt.figure()
#ax = fig.add_subplot(1, 1, 1)
#xs = []
#ys = []