-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_function.py
90 lines (63 loc) · 2.77 KB
/
server_function.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
from jinja2 import StrictUndefined
from flask import (Flask, render_template, redirect, request, flash,
session, jsonify)
from flask_debugtoolbar import DebugToolbarExtension
from model import connect_to_db, db, Category, Weather, Lift, Skirun, User, Rating, SkillLevel, CatUser
from random import sample
import json
import os
##############################################################################
def blackcomb_flare_json():
"""creates json data for d3 map"""
lifts = Lift.query.all()
skiruns = Skirun.query.all()
lifts_list = []
for lift in lifts:
if lift.mountain == 'Blackcomb':
lift_dict = {}
lift_dict['name'] = lift.name
# query for the inner most mtn lift & skirun information
mtn_query = '''SELECT json_agg(t)
FROM (
SELECT
s.name AS name
FROM lifts AS l
JOIN skiruns_lifts AS sl ON l.lift_id = sl.lift_id
JOIN skiruns As s ON sl.skirun_id = s.skirun_id
WHERE l.lift_id= :lift_id) t; '''
lift_list = db.session.execute(mtn_query, {'lift_id': lift.lift_id})
lift_list = lift_list.fetchall()
# Inner most child
lift_list = lift_list[0][0]
lift_dict['children'] = lift_list
# import pdb; pdb.set_trace()
lifts_list.append(lift_dict)
b_master_dict = {'name': 'Blackcomb', 'children': lifts_list}
return b_master_dict
def whistler_flare_json():
"""creates json data for d3 map"""
lifts = Lift.query.all()
skiruns = Skirun.query.all()
lifts_list = []
for lift in lifts:
if lift.mountain == 'Whistler':
lift_dict = {}
lift_dict['name'] = lift.name
# query for the inner most mtn lift & skirun information
mtn_query = '''SELECT json_agg(t)
FROM (
SELECT
s.name AS name
FROM lifts AS l
JOIN skiruns_lifts AS sl ON l.lift_id = sl.lift_id
JOIN skiruns As s ON sl.skirun_id = s.skirun_id
WHERE l.lift_id= :lift_id) t; '''
lift_list = db.session.execute(mtn_query, {'lift_id': lift.lift_id})
lift_list = lift_list.fetchall()
# Inner most child
lift_list = lift_list[0][0]
lift_dict['children'] = lift_list
# import pdb; pdb.set_trace()
lifts_list.append(lift_dict)
w_master_dict = {'name': 'Whistler', 'children': lifts_list}
return w_master_dict