-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·69 lines (53 loc) · 2.05 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
#!/usr/bin/env python3
import sys
import util
import json
import ec_model
import googlemaps
import numpy as np
from flask import Flask, render_template, request
APP = Flask(__name__)
GM_KEY = util.get_google_api_key()
@app.route("/")
def index():
return render_template('index.html', app_name="- PHARMACY -", gm_key=GM_KEY, lat=-23.543196, lng=-46.632432)
@app.route('/get_pharmacies', methods = ['POST'])
def get_pharmacies():
if request.method == 'POST':
lat = float(request.form['latitude'])
lng = float(request.form['longitude'])
radius = int(request.form['radius'])
population = int(request.form['population'])
generation = int(request.form['generation'])
cxprob = float(request.form['cxprob'])
mtprob = float(request.form['mtprob'])
location = (lat, lng)
try:
(init_pop, log, pareto, pharmacies, hospitals) = ec_model.run(location, radius, population=population, n_gen=generation, cxpb=cxprob, mtpb=mtprob, test=False)
response = {
'status': "ok",
'mb_key': util.get_mapbox_api_key(),
'center_spot': location,
'best_spot_lats': list(map(lambda x: x[0], pareto[0:5])),
'best_spot_longs': list(map(lambda x: x[1], pareto[0:5])),
'pharm_lats': list(map(lambda x: x.latitude, pharmacies)),
'pharm_longs': list(map(lambda x: x.longitude, pharmacies)),
'pharm_names': list(map(lambda x: x.name, pharmacies)),
'hosp_lats': list(map(lambda x: x.latitude, hospitals)),
'hosp_longs': list(map(lambda x: x.longitude, hospitals)),
'hosp_names': list(map(lambda x: x.name, hospitals)),
'init_pop_lats': list(map(lambda x: x[0], init_pop)),
'init_pop_longs': list(map(lambda x: x[1], init_pop)),
'gens': list(map(lambda x: x['gen'],log)),
'std_pharm': list(map(lambda x: x['std'][0],log)),
'std_hosp': list(map(lambda x: x['std'][1],log)),
'avg_pharm': list(map(lambda x: x['avg'][0],log)),
'avg_hosp': list(map(lambda x: x['avg'][1],log))
}
except Exception as e:
response = {
'status': str(e)
}
return json.dumps(response), 200
if __name__ == "__main__":
APP.run(debug=True)