-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·76 lines (61 loc) · 2.71 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
70
71
72
73
74
75
76
# ---------------------------------------------------------------------------------
# Imports
# -------------------------------------------------------------------------------*/
from flask import Flask, render_template
from flask_adminlte import AdminLTE
import map_data
# from wordcloud import WordCloud
# from PIL import Image
from bigquery import BigQuery
# ---------------------------------------------------------------------------------
# Configuration
# -------------------------------------------------------------------------------*/
# Application
app = Flask(__name__)
AdminLTE(app)
# ---------------------------------------------------------------------------------
# Global Functions
# -------------------------------------------------------------------------------*/
# wordmap colour function
def white_color_func(word, font_size, position, orientation, random_state=None, **kwargs):
return "hsl(360, 100%, 100%)"
# ---------------------------------------------------------------------------------
# Page Routes
# -------------------------------------------------------------------------------*/
@app.route('/')
def index():
# ----------------------
# BigQuery
# --------------------*/
query = BigQuery()
most_pop_overall = query.most_popular_overall()
most_pop_day = query.most_popular_day()
most_pop_month = query.most_popular_month()
most_pop_time = query.most_popular_time()
# -----------------------------------------------------------
# Fetch Data for Google Map using Melbourne City Data API
# ---------------------------------------------------------*/
avg_daily_traffic = map_data.MapData().get_average_daily_traffic()
# avg = query.get_average_daily_traffic()
# ----------------------
# Word Cloud
# --------------------*/
# pedestrian counts for each location
frequencies = {}
for location in avg_daily_traffic:
frequencies[location[0]] = int(location[1])
# # create word cloud
# wordcloud = WordCloud(width=1856,
# height=600,
# font_path='./static/fonts/Oxygen/Oxygen-Bold.ttf',
# min_font_size=5,
# background_color=None,
# color_func=white_color_func,
# ).generate_from_frequencies(frequencies, 100)
#
# # save to image file
# wordcloud.to_file('static/img/wordcloud.png')
return render_template('index.html', most_pop_overall=most_pop_overall, most_pop_day=most_pop_day,
most_pop_month=most_pop_month, most_pop_time=most_pop_time, avg_daily_traffic=avg_daily_traffic)
if __name__ == '__main__':
app.run(debug=True)