-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapi.py
More file actions
47 lines (40 loc) · 1.4 KB
/
api.py
File metadata and controls
47 lines (40 loc) · 1.4 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
from flask import Flask, request, render_template
from flask_restful import Resource, Api
from createDictionary import *
import copy
# from normalizer import normalize
from functools import reduce
import evaluate
data = createDictionary()
print(data)
app = Flask(__name__)
api = Api(app)
def applyParams(data_,params):
table = copy.deepcopy(data_)
if reduce((lambda x,y:int(x)*int(y)),list(params.values()))==1:
return table
for key in table:
for issue in table[key]:
table[key][issue] *= float(params[issue])
return table
class regions(Resource):
def get(self):
return data
class regionsApplied(Resource):
def get(self,paramSafety,paramHealth,paramEconomy):
params = {'Safety':paramSafety,'Health':paramHealth,'Economy':paramEconomy}
table = applyParams(data,params)
return table
class best(Resource):
def get(self,paramSafety,paramHealth,paramEconomy):
params = {'Safety':paramSafety,'Health':paramHealth,'Economy':paramEconomy}
table = applyParams(data,params)
return evaluate.best(table)
api.add_resource(regions, '/data')
api.add_resource(best,'/best/<paramSafety>/<paramHealth>/<paramEconomy>')
api.add_resource(regionsApplied,'/table/<paramSafety>/<paramHealth>/<paramEconomy>')
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run(port='5002')