-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
119 lines (89 loc) · 3.65 KB
/
app.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
from flask import Flask, render_template, jsonify, Response
import pandas as pd
import numpy as np
import json
app = Flask(__name__, static_url_path='')
JSON = "application/json"
data = None
def loadCSV():
data = pd.read_csv('../waltti.csv', quotechar='"', low_memory=False)
data.loc[:, 'lat'] = 0
data.loc[:, 'lng'] = 0
data = data.reindex(columns=['lineid','stopid', 'lat', 'lng', 'variation', 'zone', 'age_group' ])
data.assign(price = lambda x: 0)
return data
data = loadCSV()
# Loading the Stops
stdata = pd.read_csv('stops.txt', quotechar='"', delimiter=',', low_memory=False)
stdata = stdata.reindex(columns=['stop_id','stop_lat', 'stop_lon'])
# Appending latitude and longitudes to the Main DataFrame
for i, row in stdata.iterrows():
stop_id = int(row['stop_id'])
data.loc[(data.stopid == stop_id), 'lat'] = row['stop_lat']
data.loc[(data.stopid == stop_id), 'lng'] = row['stop_lon']
# Loading Passenger CSV
pdata = pd.read_csv('data/passengersbusstops.csv', delimiter=';', low_memory=False)
pdata = pdata.reindex(columns=['stopid','Freq'])
pdata.loc[:, 'lat'] = 0
pdata.loc[:, 'lng'] = 0
@app.route("/")
def home():
lines = data.loc[~data['lineid'].duplicated()]
ageGroups = data.loc[~data['age_group'].duplicated()]
outd = lines.to_dict(orient="index")
outAgeGroups = ageGroups.to_dict(orient="index")
return render_template('index.html', ageGroups=outAgeGroups, outd=outd )
@app.route("/markers")
def marker():
outd = ""
return render_template('markers.html', outd=outd )
@app.route("/passengersbusstops")
def passengersBusStops():
for i, row in stdata.iterrows():
stop_id = int(row['stop_id'])
pdata.loc[(pdata.stopid == stop_id), 'lat'] = row['stop_lat']
pdata.loc[(pdata.stopid == stop_id), 'lng'] = row['stop_lon']
out = pdata.to_dict(orient="index")
output = []
for a in out:
output.append(out[a])
return Response(json.dumps(output), 200, mimetype=JSON)
@app.route("/api/v1/get-stopid")
def getStopid():
stops = data.loc[~data['stopid'].duplicated()]
out = stops.to_json(orient='records')[1:-1].replace('},{', '} {')
return out
@app.route("/api/v1/get-card")
def getCard():
stops = data.loc[~data['stopid'].duplicated()]
out = stops.to_json(orient='records')[1:-1].replace('},{', '} {')
return out
@app.route("/api/v1/get/<variation>/<zone>")
def getData(variation, zone):
filter = data[(data["zone"] == int(zone)) & (data["variation"] == str(variation))]
out = filter.to_json(orient='records')[1:-1].replace('},{', '} {')
return out
# Get all the lines
@app.route("/api/v1/get/lines")
def getLines():
lines = data.loc[~data['lineid'].duplicated()]
out = lines.to_json(orient='records')
return Response(json.dumps(out), 200, mimetype=JSON)
@app.route("/api/v1/get/line-routes/<lineid>")
def getLineRoutes(lineid):
filter = data[(data["lineid"] == int(lineid))]
filterout = filter.loc[~filter['stopid'].duplicated()]
filterout = filterout.reindex(columns=['lat', 'lng'])
filterout.loc[:, 'users'] = 0
for i, row in stdata.iterrows():
stop_id = int(row['stop_id'])
data.loc[(data.stopid == stop_id), 'lat'] = row['stop_lat']
data.loc[(data.stopid == stop_id), 'lng'] = row['stop_lon']
out = filterout.to_dict(orient="index")
output = []
for a in out:
output.append(out[a])
return Response(json.dumps(output), 200, mimetype=JSON)
#return render_template('data.html', out=output )
if __name__ == "__main__":
app.run(port=5000, debug=True)