-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbathroomBarCharts.py
58 lines (51 loc) · 1.49 KB
/
bathroomBarCharts.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
import datetime
import plotly.plotly as py
import sqlite3 as lite
from plotly.graph_objs import *
#Plotly signin info
py.sign_in(user, key)
#Arrays for holding data
bath1Hour=[]
bath2Hour=[]
#Database connection
con = lite.connect('bathroom.db')
with con:
cur = con.cursor()
inputString = "select * from bath WHERE date(datetime(Time, 'unixepoch', 'localtime')) = date('now', 'localtime') AND Bathroom=1"
cur.execute(inputString)
results = cur.fetchall()
time1 = [x[1] for x in results]
for x in time1:
value = datetime.datetime.fromtimestamp(x)
hour = value.strftime('%H:%M:%S')
bath1Hour.append(value)
cur2 = con.cursor()
inputString = "select * from bath WHERE date(datetime(Time, 'unixepoch', 'localtime')) = date('now', 'localtime' ) AND Bathroom=2"
cur2.execute(inputString)
results = cur2.fetchall()
time2 = [x[1] for x in results]
for x in time2:
value = datetime.datetime.fromtimestamp(x)
hour = value.strftime('%H:%M:%S')
bath2Hour.append(value)
#Set histogram view to automatically group plot points
trace1 = Histogram(
x=bath1Hour,
name="Bathroom1",
nbinsx=40, #this sets the amount of bins of grouped data
)
trace2 = Histogram(
x=bath2Hour,
name='Bathroom2',
nbinsx=40,
)
data = Data([trace1, trace2])
layout = Layout(
barmode='group',
bargroupgap=0,
title="Bathroom Use",
xaxis=XAxis(title='Time'),
yaxis=YAxis(title='Number of Uses')
)
fig = Figure(data=data, layout=layout)
plot_url = py.plot(fig, filename='grouped-bar')