-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_311.py
93 lines (73 loc) · 3.05 KB
/
data_311.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
# import json
# import pprint
# from pymongo import MongoClient
from flask import Flask, render_template, request, url_for, jsonify
from bson.json_util import dumps
# client = MongoClient('localhost', 27017)
# db = client['visualization311']
app = Flask(__name__)
# data_path = './static/data/'
# old one
# @app.route("/data")
# def data():
# df = pd.read_csv(data_path + '311DataMini.csv')
# return df.to_json(orient='records')
#Prototype before merging
#make sure you edit index.html for url_for to /data
# @app.route('/population_data', methods=['GET', 'POST'])
# def population_data():
# start_year = request.args.get('start_year')
# end_year = request.args.get('end_year')
# print('PYTHON YEARS')
# print(start_year)
# print(end_year)
# population = db.population.find()
# # querydata = db.complaints.find({"CreatedDate": {"$gte":"2010-01-00 00:00:00", "$lt":"2010-12-00 00:00:00"}})
# querydata = db.complaints.aggregate([
# {'$match':
# {
# 'CreatedDate':
# {
# "$gte": start_year, "$lt":end_year
# }
# }
# },
# { '$group':
# { '_id': {'ZipCode': '$ZipCode'},
# 'Density': {'$sum': 1}
# }
# }
# ])
# list = []
# list.append(population)
# list.append(querydata)
# # querydata = db.complaints.find({"CreatedDate": {"$gte":"2011-09-00 00:00:00", "$lt":"2011-10-00 00:00:00"} , "$or" : [{"ComplaintType":"Blocked Driveway", "ComplaintType":"Rodent"}] })
# return dumps(list)
# @app.route('/zipcode_data', methods=['GET', 'POST'])
# def zipcode_data():
# zipcode_data = request.args.get('zipcode')
# start_month = request.args.get('start_month')
# end_month = request.args.get('end_month')
# # zip = request.json['zipcode']
# querydata = db.complaints.find({"CreatedDate": {"$gte":start_month, "$lt":end_month}, "$and" : [{"ZipCode": int(zipcode_data)}]})
# # querydata = db.complaints.find({"CreatedDate": {"$gte":"2011-09-00 00:00:00", "$lt":"2011-10-00 00:00:00"} , "$or" : [{"ComplaintType":"Blocked Driveway", "ComplaintType":"Rodent"}] })
# return dumps(querydata)
# @app.route('/data', methods=['POST'])
# def data():
# if (request.method == 'POST'):
# complaintType = request.form.getlist('options')
# fromTime = request.form['from']
# toTime = request.form['to']
# mongoListparam = []
# for item in complaintType:
# mongoListparam.append({"ComplaintType":item})
# querydata = db.complaints.find({"CreatedDate": {"$gte":fromTime, "$lt":toTime} , "$or" : mongoListparam })
# return dumps(querydata)
# else:
# querydata = db.complaints.find({"CreatedDate": {"$gte":"2011-09-00 00:00:00", "$lt":"2011-10-00 00:00:00"} , "$or" : [{"ComplaintType":"Blocked Driveway", "ComplaintType":"Rodent"}] })
# return dumps(querydata)
@app.route('/')
def hello():
return render_template('index.html')
if __name__ == "__main__":
app.run(port=8000, debug=True)