-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathWH_Interactive_Map.py
More file actions
128 lines (109 loc) · 5.08 KB
/
WH_Interactive_Map.py
File metadata and controls
128 lines (109 loc) · 5.08 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
from bokeh.models import BoxSelectTool, BoxZoomTool, LassoSelectTool, HoverTool, Quad
from bokeh.plotting import figure, output_file, show, gridplot, ColumnDataSource
from bokeh.models.widgets import Dropdown, Panel, Tabs, CheckboxButtonGroup, RadioGroup
from bokeh.io import output_file, show, vform, save
import csv
#PROJECT OVERVIEW:
#Create an interactive map of West Hall showing hallway culture via gender distribution, sleeping habits, time spent in hallways, etc.
#(If we hear back from STAR, we'll also have data on how people move from year to year, which will be awesome to implement)
#PROGRESS:
#currently outputs to an html file which has 3 tabs - WH1, WH2, and WH3
#rooms are currently blue squares, have hover functionality with correct labels but no data
#Also have buttons that are currently nonfunctional but are planned to be able to display different color coordinations for each room.
#Initializes and draws all rooms from a .csv file with data from survey sent to first years.
#NEXT STEPS:
#Get more room data from people (keep collecting survey responses)
#Draw rooms in correct places
#Make import for roommate names work correctly
#Make hover display room number and inhabitant names instead of '???'
#Make buttons functional
#figure out how to make buttons active
#make metric for color changing and coordination
# output to static HTML file
output_file("WH_Firstyears.html")
class Room(object):
def __init__(self, roomNum='000', roommates='[Roommate Names Here]', gender='[Some Gender Here]', bedtime=0, lightsleep=0, halltime=0, top=1, bottom=0, left=0, right=1):
self.roomNum = roomNum
self.roommates = roommates
self.gender = gender
self.bedtime = bedtime
self.lightsleep = lightsleep
self.halltime = halltime
self.top = top
self.bottom = bottom
self.left = left
self.right = right
def __str__(self):
return 'Room Number: %s / Current Inhabitants: %s / Gender: %s / Average Bedtime: %s' %(self.roomNum, self.roommates, self.gender, self.bedtime)
def drawRoom(self):
if int(self.roomNum)<200:
#draw on first floor
rooms1 = p1.quad(top=self.top,bottom=self.bottom, left=self.left, right=self.right,
nonselection_fill_alpha=0.01,
nonselection_fill_color=None,
nonselection_line_color="firebrick",
nonselection_line_alpha=1.0,
selection_color="blue",
selection_fill_alpha=.5)
elif int(self.roomNum)<300:
#draw on second floor
rooms2 = p2.quad(top=self.top,bottom=self.bottom, left=self.left, right=self.right,
nonselection_fill_alpha=0.01,
nonselection_fill_color=None,
nonselection_line_color="firebrick",
nonselection_line_alpha=1.0,
selection_color="blue",
selection_fill_alpha=.5)
else:
#draw on third floor
rooms3 = p3.quad(top=self.top,bottom=self.bottom, left=self.left, right=self.right,
nonselection_fill_alpha=0.01,
nonselection_fill_color=None,
nonselection_line_color="firebrick",
nonselection_line_alpha=1.0,
selection_color="blue",
selection_fill_alpha=.5)
TOOLS = "box_zoom,box_select,resize,reset,hover,tap"
#draws first floor of WH
p1 = figure(plot_width=400, plot_height=400, tools=TOOLS,title="West Hall First Floor")
tab1 = Panel(child=p1, title="WH1")
p1.segment(x0=[1, 1, 1, 6], y0=[1, 6, 1, 1], x1=[6, 6, 1, 6],
y1=[1, 6, 6, 6], color="#F4A582", line_width=3)
p1.select_one(HoverTool).tooltips = [('Room Number','@roomNum'),('Inhabitants','@roommates')]
#draws second floor of WH
p2 = figure(plot_width=400, plot_height=400, tools=TOOLS,title="West Hall Second Floor")
tab2 = Panel(child=p2, title="WH2")
p2.segment(x0=[1, 1, 1, 6], y0=[1, 6, 1, 1], x1=[6, 6, 1, 6],
y1=[1, 6, 6, 6], color="#F4A582", line_width=3)
p2.select_one(HoverTool).tooltips = [('Room Number','@roomNum'),('Inhabitants','@roommates')]
#draws third floor of WH
p3 = figure(plot_width=400, plot_height=400, tools=TOOLS,title="West Hall Third Floor")
tab3 = Panel(child=p3, title="WH3")
p3.segment(x0=[1, 1, 1, 6], y0=[1, 6, 1, 1], x1=[6, 6, 1, 6],
y1=[1, 6, 6, 6], color="#F4A582", line_width=3)
p3.select_one(HoverTool).tooltips = [('Room Number','@roomNum'),('Inhabitants','@roommates')]
#Pull data from csv file and create Room objects from it!
with open('WH_Freshmen.csv') as csvfile:
freshmen_data = csv.reader(csvfile, delimiter=',', quotechar='\"')
#roomList = []
for row in freshmen_data:
roomA = Room() #initializes a new Room for each row in the csv data file
roomA.roomNum = row[0]
roomA.roomates = row[1] #not working for some reason?
roomA.gender = row[2]
roomA.bedtime = row[3]
roomA.lightsleep = row[4]
roomA.halltime = row[5]
roomA.top = 2
roomA.bottom = 1
roomA.left = 1
roomA.right = 2
roomA.drawRoom()
#roomList.append(roomA) #creates list of all Room objects
dropdown_choices = [("Gender", "gender"), ("Bedtime", "bedtime"), ("Light Sleeper", "lightsleep"), ("Time in Hallway", "halltime")]
dropdown = Dropdown(label="Hallway Metrics", type="warning", menu=dropdown_choices)
tabs = Tabs(tabs=[tab1, tab2, tab3])
layout = vform(dropdown, tabs)
# show the results
save(tabs)
show(layout)