-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
410 lines (311 loc) · 11.7 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# BUS SCHEDULE
import pymongo
from pymongo import MongoClient
from pymongo.errors import CollectionInvalid
import folium
import json
import csv
import os
import routes
import database
import gpsapi
from flask import json
#MongoDB
client = pymongo.MongoClient("mongodb+srv://admin:admin@cluster0.jv3iz.mongodb.net/CitizenInformation?retryWrites=true&w=majority")
db=client['CitizenInformation']
filename = 'data//route_stops.csv'
filename1 = 'data//stops.csv'
filename2 = 'data//cancel.csv'
filename3 = 'data//x.csv'
filename4 = 'data//cancelFeb.csv'
filename5 = 'data//xFeb.csv'
r3 = []
c3 = []
r2 = []
c2 = []
r1 = []
c1 = []
r =[]
c = []
rt_stop123 = db["Route_Stops"]
x = rt_stop123.find_one()
print("Data of Route_stop table :" + str(x))
stop123 = db["Stops"]
y = stop123.find_one()
print("Data of Stop table :" + str(y))
#list of all the data
# for x in col.find():
# r1.append(x)
# BUS CANCELLATION
cancel123 = db["Cancel"]
x = cancel123.find_one()
print("Data of Cancel table :" + str(x))
x123 = db["X"]
y = x123.find_one()
print("Data of X table :" + str(y))
with open(filename, 'r') as csvfile:
csvreader = csv.reader(csvfile)
c=next(csvreader)
for i in csvreader:
r.append(i)
with open(filename1, 'r') as csvfile:
csvreader1 = csv.reader(csvfile)
c1=next(csvreader1)
for j in csvreader1:
r1.append(j)
with open(filename2, 'r') as csvfile:
csvreader2 = csv.reader(csvfile)
c2=next(csvreader2)
for m in csvreader2:
r2.append(m)
with open(filename3, 'r') as csvfile:
csvreader3 = csv.reader(csvfile)
c3=next(csvreader3)
for n in csvreader3:
r3.append(n)
#January Bus Cancels
with open(filename, 'r') as csvfile:
csvreader = csv.reader(csvfile)
c=next(csvreader)
for i in csvreader:
r.append(i)
with open(filename1, 'r') as csvfile:
csvreader1 = csv.reader(csvfile)
c1=next(csvreader1)
for j in csvreader1:
r1.append(j)
with open(filename4, 'r') as csvfile:
csvreader2 = csv.reader(csvfile)
c2=next(csvreader2)
for m in csvreader2:
r2.append(m)
with open(filename5, 'r') as csvfile:
csvreader3 = csv.reader(csvfile)
c3=next(csvreader3)
for n in csvreader3:
r3.append(n)
#MAIN
database.onStart()
from flask import Flask, render_template
app = Flask(__name__)
# Global Vars
# I'll do the work here and we can later move it out to its on .py
class STATUSLEVELS():
DANGER = 2,
WARNING = 1,
OK = 0
class transitElement():
def __init__(self, imp_id, status, canCount, warnCount):
self.eId = imp_id
self.eStatus = status
self.eCanCount = canCount
self.eWarnCount = warnCount
class fakeRouteElement(transitElement):
def __init__(self, imp_id, status, canCount, warnCount):
self.eId = imp_id
self.eStatus = status
self.eCanCount = canCount
self.eWarnCount = warnCount
class fakeStopElement():
def __init__(self, imp_id, status, canCount, warnCount):
self.eId = imp_id
self.eStatus = status
self.eCanCount = canCount
self.eWarnCount = warnCount
def populateRoutesForStopDatabase(stopID, date):
#database call
database.findRoutesForStop(stopID, "17:00:00")
fakeRouteList=[
fakeRouteElement(95,1,0,0),
fakeRouteElement(75,1,0,0),
fakeRouteElement(85,1,0,0),
fakeRouteElement(88,1,0,0),
fakeRouteElement(4,1,1,2)
]
return fakeRouteList
fakeRouteList=[
fakeRouteElement(95,1,0,0),
fakeRouteElement(75,1,0,0),
fakeRouteElement(85,1,0,0),
fakeRouteElement(88,1,0,0),
fakeRouteElement(4,1,1,2)
]
fakeRouteList2=[
{ "eId": 5, "eStatus": 1,"eCanCount": 1, "eWarnCount": 2}
]
# Routes
@app.route('/<routeID>/<stopID>')
def routesAndStops(routeID, stopID):
#Route and stop valid parsing needs to be done here
#add "isValid" to the first if
if routeID is not None or stopID is not None:
if routeID.lower() == "all":
#Here we will need to do a quick call to get the cached health of all the routes
#Filter out the routes we don't need and update a list of
# RouteID's, statusLevel, HasCancellations, HasWarnings
# WE can update the JS on the page to hardcode the images used for "bus route types"
# So we don't need to pass extra data per cycle
#API check also needed here as well as cancellation check
#Switch over to class return type
return render_template("stops.html",
title="Occasional Transport: Ottawa Bus Edition",
mastHead="Stops Page",
selectedRouteID="all",
selectedstopID=stopID,
statusLevel=STATUSLEVELS.OK,
locationText="Located between at the intersection of Two and Fern",
locationDescrip="Lovely Stop. Great Atmosphere",
mastDescrip="Display all Stops For " + stopID + " stop ID",
fakeRouteListSend=fakeRouteList)
else:
return render_template("stops.html",
title="Occasional Transport: Ottawa Bus Edition",
mastHead="Stops Page",
selectedRouteID=routeID,
selectedstopID=stopID,
statusLevel=STATUSLEVELS.OK,
locationText="Located between at the intersection of Two and Fern",
locationDescrip="Lovely Stop. Great Atmosphere",
mastDescrip="Display "+ routeID +" route information for " + stopID + " stop ID",
fakeRouteListSend=fakeRouteList)
else:
index()
@app.route('/<routeID>/<stopID>/json')
def routesAndStopsJson(routeID, stopID):
def make_summary():
return fakeRouteList2
if routeID is not None or stopID is not None:
if routeID.lower() == "all":
if routeID is not None:
data = make_summary()
response = app.response_class(
response=json.dumps(data),
status=200,
mimetype='application/json'
)
return response
else:
if routeID is not None:
data = make_summary()
response = app.response_class(
response=json.dumps(data),
status=200,
mimetype='application/json'
)
return response
else:
index()
@app.route('/<routeID>')
def busRoutes(routeID):
#Route valid parsing needs to be done here
#add "isValid" to the first if
if routeID is not None:
return render_template("routes.html",
title="Occasional Transport: Ottawa Bus Edition",
mastHead="Routes Page",
selectedRouteID=routeID,
statusLevel=STATUSLEVELS.OK,
mastDescrip="Display "+ routeID +" route information ")
else:
index()
@app.route('/<routeID>/json')
def busRoutesJson(routeID):
#Route valid parsing needs to be done here
#add "isValid" to the first if
def make_summary():
return fakeRouteList2
if routeID is not None:
data = make_summary()
response = app.response_class(
response=json.dumps(data),
status=200,
mimetype='application/json'
)
return response
else:
index()
@app.route('/')
def index():
return render_template("index.html",
title="Occasional Transport: Ottawa Bus Edition",
mastHead="Where's my @#$@ Bus?",
statusLevel=STATUSLEVELS.OK,
mastDescrip="Who knows. We don't. Move along.")
# Historical Routes
@app.route('/cancel/jan')
def jan():
m = folium.Map(location=[45.4215, -75.6972], zoom_start=13)
for k in r1:
folium.Marker(location=[k[4], k[5]], tooltip=[k[2], k[1]],
icon=folium.Icon(color='blue', icon='bus', prefix='fa')).add_to(m)
for a in r2:
for b in r3:
if (a[0] == b[0]):
if (b[1] < "2"):
folium.Marker(location=[a[3], a[4]], tooltip=[a[1], 'Cancellation:', b[1]],
icon=folium.Icon(color='purple', icon='bus', prefix='fa')).add_to(m)
elif (b[1] >= "2" and b[1] < "4"):
folium.Marker(location=[a[3], a[4]], tooltip=[a[1], b[1], 'Cancellations'],
icon=folium.Icon(color='orange', icon='bus', prefix='fa')).add_to(m)
elif (b[1] >= "4"):
folium.Marker(location=[a[3], a[4]], tooltip=[a[1], b[1]],
icon=folium.Icon(color='red', icon='bus', prefix='fa')).add_to(m)
m.save('templates//jan_stops.html')
return render_template("jan_stops.html")
@app.route('/cancel/feb')
def feb():
m = folium.Map(location=[45.4215, -75.6972], zoom_start=13)
for k in r1:
folium.Marker(location=[k[4], k[5]], tooltip=[k[2], k[1]],
icon=folium.Icon(color='blue', icon='bus', prefix='fa')).add_to(m)
for a in r2:
for b in r3:
if (a[0] == b[0]):
if (b[1] < "2"):
folium.Marker(location=[a[3], a[4]], tooltip=[a[1], 'Cancellation:', b[1]],
icon=folium.Icon(color='purple', icon='bus', prefix='fa')).add_to(m)
elif (b[1] >= "2" and b[1] < "4"):
folium.Marker(location=[a[3], a[4]], tooltip=[a[1], b[1], 'Cancellations'],
icon=folium.Icon(color='orange', icon='bus', prefix='fa')).add_to(m)
elif (b[1] >= "4"):
folium.Marker(location=[a[3], a[4]], tooltip=[a[1], b[1]],
icon=folium.Icon(color='red', icon='bus', prefix='fa')).add_to(m)
m.save('templates//feb_stops.html')
return render_template("feb_stops.html")
@app.route('/schedule/<route_id>')
def scheduleroute(route_id):
m = folium.Map(location=[45.4215, -75.6972], zoom_start=13)
for k in r:
if (k[1] == route_id and k[2] == "1"):
for l in r1:
if (k[3] == l[0]):
folium.Marker(location=[l[4], l[5]], tooltip=[l[2], l[1]],
icon=folium.Icon(color='red', icon='bus', prefix='fa')).add_to(m)
m.save('templates//schedule.html')
return render_template("schedule.html")
@app.route('/cancel/<cancel_id>')
def cancel(cancel_id):
m = folium.Map(location=[45.4215, -75.6972], zoom_start=13)
for k in r:
if (k[1] == cancel_id):
for l in r1:
if (k[3] == l[0]):
folium.Marker(location=[l[4], l[5]], tooltip=[l[2], l[1]],
icon=folium.Icon(color='blue', icon='bus', prefix='fa')).add_to(m)
for a in r2:
if (a[2] == cancel_id):
for b in r3:
if (a[0] == b[0]):
if (b[1] < "2"):
folium.Marker(location=[a[3], a[4]], tooltip=[a[1], 'Cancellation:', b[1]],
icon=folium.Icon(color='purple', icon='bus', prefix='fa')).add_to(m)
elif (b[1] >= "2" and b[1] < "4"):
folium.Marker(location=[a[3], a[4]], tooltip=[a[1], b[1], 'Cancellations'],
icon=folium.Icon(color='orange', icon='bus', prefix='fa')).add_to(m)
elif (b[1] >= "4"):
folium.Marker(location=[a[3], a[4]], tooltip=[a[1], b[1]],
icon=folium.Icon(color='red', icon='bus', prefix='fa')).add_to(m)
m.save('templates//cancel.html')
return render_template("cancel.html")
if __name__=="__main__":
app.run(port=8000,debug=True)