-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
108 lines (76 loc) · 3.38 KB
/
app.py
File metadata and controls
108 lines (76 loc) · 3.38 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
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
# Import Dependencies
import datetime as dt
import numpy as np
import pandas as pdimport
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from sqlalchemy import create_engine, func, MetaData, Table, Column
from flask import Flask, jsonify, render_template
from flask_cors import CORS
import os
# import config
# Create engine, automap and session
# db Setup
# engine = create_engine(f'postgres://{config.user}:{config.password}@ec2-52-22-216-69.compute-1.amazonaws.com:5432/d5qr295as59lsj')
engine = create_engine(os.environ.get('DATABASE_URL', None))
base = automap_base()
base.prepare(engine, reflect=True)
session = Session(engine)
fire_table = base.classes.fires_2013_2017
# flask setup
app = Flask(__name__)
#############################################
# /api/v1.0/interactive_pie
#############################################
@app.route("/homepage")
def welcome():
return("Available Routes:<br/> /api/v1.0/interactive_pie/<fire_cause>/<st>/<year>")
@app.route("/api/v1.0/interactive_pie/<st>/<year>")
def interactive_pie(st, year):
session = Session(engine)
pie_results = session.query(fire_table.st, fire_table.year,fire_table.month, fire_table.latitude1, fire_table.longitude1, fire_table.cause1, fire_table.cause2,fire_table.cause3, fire_table.cause4).filter(fire_table.st == st).filter(fire_table.year == year).all()
#.filter(fire_table.cause1 == cause1)\
#.filter(fire_table.cause2 == cause2)\
session.close()
pie_string = []
for st, year, month, latitude1, longitude1, cause1, cause2, cause3, cause4 in pie_results:
pie_data_dict = {}
pie_data_dict["st"] = st
pie_data_dict["year"] = year
pie_data_dict["month"] = month
pie_data_dict["latitude"] = latitude1
pie_data_dict["longitude"] = longitude1
pie_data_dict["cause1"] = cause1
pie_data_dict["cause2"] = cause2
pie_data_dict["cause3"] = cause3
pie_data_dict["cause4"] = cause4
pie_string.append(pie_data_dict)
response = jsonify(pie_string)
response.headers.add('Access-Control-Allow-Origin', '*')
return (response)
# @app.route("/api/v1.0/everything/")
# def everything():
# session = Session(engine)
# everything_results = session.query(fire_table.st, fire_table.year,fire_table.month, fire_table.latitude1, fire_table.longitude1, fire_table.cause1, fire_table.cause2,fire_table.cause3, fire_table.cause4).filter(fire_table.st == st).filter(fire_table.year == year).all()
# #.filter(fire_table.cause1 == cause1)\
# #.filter(fire_table.cause2 == cause2)\
# session.close()
# everything_string = []
# for st, year, month, latitude1, longitude1, cause1, cause2, cause3, cause4 in pie_results:
# pie_data_dict = {}
# pie_data_dict["st"] = st
# pie_data_dict["year"] = year
# pie_data_dict["month"] = month
# pie_data_dict["latitude"] = latitude1
# pie_data_dict["longitude"] = longitude1
# pie_data_dict["cause1"] = cause1
# pie_data_dict["cause2"] = cause2
# pie_data_dict["cause3"] = cause3
# pie_data_dict["cause4"] = cause4
# pie_string.append(pie_data_dict)
# return jsonify(pie_string)
@app.route("/")
def homepage():
return render_template("index.html")
if __name__ == '__main__':
app.run(threaded=True, port=5000)