-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
128 lines (104 loc) · 4.04 KB
/
main.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
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
#initializing
import os
import tkinter
from flask import Flask, render_template, url_for, redirect, request
from flask_sqlalchemy import SQLAlchemy
#import jyserver.Flask as jsf
# THE BUILDING OBJECT
class Building:
BLDG_NAME = ""
NUMFLOORS = 0
busynessList = [[0]]
# Initializes the building's name and floors
def __init__(self, name="N/A", floors = 0):
self.BLDG_NAME = name
self.NUMFLOORS = floors
self.makeBusynessList()
# Adds the user's busyness value to a list for a given building floor
def addBusyNum(self, floor= 2, busyNum = 0):
rFloor = floor - 1
for i in range(len(self.busynessList[rFloor])):
if self.busynessList[rFloor][i] == 0:
self.busynessList[rFloor][i] = busyNum
break
elif i == len(self.busynessList[rFloor]) - 1:
self.busynessList[rFloor].append(busyNum)
break
# Constructs the base lists we'll be using to store density values
def makeBusynessList(self):
arr = [[0]]
for i in range(self.NUMFLOORS - 1):
arr.append([0])
self.busynessList = arr
# Removes the first index of the list of a given floor
def removeValue(self, floor = 2):
self.busynessList[floor - 1].pop(0)
# Gets the average of all values on a floor
def getAverage(self, floor = 2):
rFloor = floor - 1
floorValues = len(self.busynessList[rFloor])
average = 0
if floorValues > 0:
total = 0
for busyNum in self.busynessList[rFloor]:
total += float(busyNum)
average = total / floorValues
return average
return self.busynessList[rFloor][0]
# Return all values of a given floor as a string
def floorValues(self, floor = 1):
rFloor = floor - 1
valString = "[" + str(self.busynessList[rFloor][0])
if (len(self.busynessList[rFloor]) > 0):
for index in range(len(self.busynessList[rFloor]) - 1):
valString = valString + ", " + str(self.busynessList[rFloor][index + 1])
return self.BLDG_NAME + str(floor) + ": " + valString + "]"
#print("PCL INFO_____________")
PCL = Building("PCL", 6)
GDC = Building("GDC", 8)
SAC = Building("SAC", 5)
BLDG_SET = [PCL, GDC, SAC]
def getBuilding(bldg_name):
for bldg in BLDG_SET:
if bldg_name == bldg.BLDG_NAME:
return bldg
# FLASK NONSENSE
app = Flask(__name__, template_folder='templates')
app.config['SQLALCHEMY_DATABASE_URL'] = 'sqlite:///.db'
db = SQLAlchemy(app)
# Upon bootup this is the main page, redirects to building page
@app.route('/')
def index():
return redirect(url_for("buildingPage"))
# Page where user chooses their building
@app.route('/building', methods=["POST", "GET"])
def buildingPage():
if request.method == "POST":
bldg = request.form['buttonBldg']
return redirect(url_for("floorPage", bldgName= bldg))
else:
return render_template('building.html')
# Page where user chooses the floor they want to see of a Building
@app.route('/floors.html/<bldgName>', methods=["POST", "GET"])
def floorPage(bldgName):
if request.method == "POST":
level = request.form['levelBtn']
return redirect(url_for("busyPage", bldgName = bldgName, floor = level))
else:
currentBldg = getBuilding(bldgName)
floors = currentBldg.NUMFLOORS
return render_template('floors.html', content=bldgName, floorNums=floors)
# Page where user views or enters their own "busyness" stats
@app.route('/status.html/<bldgName><floor>', methods=["POST", "GET"])
def busyPage(bldgName, floor):
currentBldg = getBuilding(bldgName)
average = round(currentBldg.getAverage(int(floor)), 2)
if request.method == "POST":
myNum= request.form['busyness']
currentBldg.addBusyNum(int(floor), myNum)
average = round(currentBldg.getAverage(int(floor)), 2)
return render_template('status.html', thisBuilding=bldgName, thisFloor=floor, currentAverage=average)
else:
return render_template('status.html', thisBuilding=bldgName, thisFloor=floor, currentAverage=average)
if __name__ == '__main__':
app.run(debug=True)