-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbathroomCircles.py
84 lines (76 loc) · 1.95 KB
/
bathroomCircles.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
import datetime
import plotly.plotly as py
from plotly.graph_objs import *
import sqlite3 as lite
#sign in for plot.ly
py.sign_in(user, key)
#Arrays to hold sql results
bath1Hour=[]
bath2Hour=[]
bathNumber=[]
bathNumber2=[]
size1=[]
size2=[]
#Sqlite Connection
con = lite.connect('bathroom.db')
with con:
#Bathroom1 Cursor
cur = con.cursor()
inputString = "select * from bath WHERE Bathroom=1"
cur.execute(inputString)
results = cur.fetchall()
time1 = [x[1] for x in results]
for x in time1:
#Get date/time stored in database
value = datetime.datetime.fromtimestamp(x)
bath1Hour.append(value)
#Set the bathroom number in array every time there's a new entry. Makes plotting easier.
bathNumber.append("1")
#Get the number of seconds bathroom was occupied
count1 = [x[2] for x in results]
for x in count1:
#Divide by 10 to make the circles more manageable
size1.append((float(x))/10)
#Bathroom2 Cursor
cur2 = con.cursor()
inputString = "select * from bath WHERE Bathroom=2"
cur2.execute(inputString)
results = cur2.fetchall()
time2 = [x[1] for x in results]
for x in time2:
value = datetime.datetime.fromtimestamp(x)
bath2Hour.append(value)
bathNumber2.append("2")
count2 = [x[2] for x in results]
for x in count2:
size2.append((float(x))/10)
#Setting Data for plotly
Bathroom1 = Scatter(
x=bath1Hour,
y=bathNumber,
mode='markers',
name='Bathroom1',
marker=Marker(
color='rgb(102, 153, 255)',
size=size1,
opacity=0.6
)
)
Bathroom2 = Scatter(
x=bath2Hour,
y=bathNumber2,
mode='markers',
name='Bathroom2',
marker=Marker(
color='rgb(255, 102, 0)',
size=size2,
)
)
data = Data([Bathroom1, Bathroom2])
layout = Layout(
showlegend=True,
title='Bubble Chart of Usage',
xaxis=XAxis(title='Time'),
)
fig = Figure(data=data, layout=layout)
plot_url = py.plot(fig, filename='bubblechart')