-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
116 lines (68 loc) · 2.54 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
import numpy as np
import sqlalchemy
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from sqlalchemy import create_engine, func
from flask import Flask, jsonify, render_template
from flask_cors import CORS
engine = create_engine("postgres://zaduqyjf:EWKQdSG0Y6c1oin0T_bc6HaULsB8ODus@salt.db.elephantsql.com:5432/zaduqyjf")
print(engine)
Base = automap_base()
Base.prepare(engine, reflect=True)
print(list(Base.classes))
canada_location = Base.classes.canada_location
canada_date = Base.classes.canada_date
canada_renewable=Base.classes.canada_Renewable
app = Flask(__name__)
CORS(app)
#@app.route("/")
#def welcome():
# return ("/api/v1.0/location, /api/v1.0/date ,/api/v1.0/renewable")
@app.route("/api/v1.0/location")
def locations():
session = Session(engine)
results = session.query(canada_location.Name, canada_location.Capacity, canada_location.Type, canada_location.lat, canada_location.lon, canada_location.Date).all()
output = [{'name': name,
'capacity': capacity,
'type': elec_type,
'coordinates': f'{lat}, {lon}',
'date': date} for (name, capacity, elec_type, lat, lon, date) in results]
#print(results)
session.close()
return jsonify(output)
@app.route("/api/v1.0/date")
def dates():
session = Session(engine)
results = session.query(canada_date.GEO, canada_date.Date, canada_date.Type, canada_date.VALUE).all()
session.close()
return jsonify(results)
@app.route("/api/v1.0/renewable")
def renewable():
session = Session(engine)
results = session.query(canada_renewable.GEO, canada_renewable.Date, canada_renewable.GreenType, canada_renewable.RtoNR_Ratio,canada_renewable.lat ,canada_renewable.lon ).all()
output =[{'province': name,
'date': date,
'type': elec_type,
'coordinates': f'{lat}, {lon}',
'lat':lat,
'lon':lon,
'RenewabletoNonReneableRatio': rtonr} for (name, date, elec_type, rtonr, lat, lon) in results]
session.close()
return jsonify(output)
@app.route("/")
def main():
return render_template('index.html')
@app.route("/plots")
def plots():
return render_template('plots.html')
@app.route("/map")
def map():
return render_template('map.html')
@app.route("/plots2")
def plots2():
return render_template('plots2.html')
@app.route("/plots3")
def plots3():
return render_template('plots3.html')
if __name__ == '__main__':
app.run(debug=True)