Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
PyBusMap
Manage
Activity
Members
Labels
Plan
Issues
10
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anton Sarukhanov
PyBusMap
Commits
7d4274e6
Commit
7d4274e6
authored
8 years ago
by
Anton Sarukhanov
Browse files
Options
Downloads
Patches
Plain Diff
Caching tweaks
parent
db38cea0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app.py
+13
-10
13 additions, 10 deletions
app.py
with
13 additions
and
10 deletions
app.py
+
13
−
10
View file @
7d4274e6
...
@@ -46,8 +46,8 @@ def map_embed(mode):
...
@@ -46,8 +46,8 @@ def map_embed(mode):
elif
mode
==
"
p
"
:
elif
mode
==
"
p
"
:
return
render_template
(
'
predictions.html
'
,
agency
=
agency
,
config
=
app
.
config
,
embed
=
True
)
return
render_template
(
'
predictions.html
'
,
agency
=
agency
,
config
=
app
.
config
,
embed
=
True
)
@app.route
(
'
/ajax
'
)
@app.route
(
'
/ajax
'
)
@cache_for
(
seconds
=
5
)
def
ajax
():
def
ajax
():
"""
Handle all async requests (from JS).
"""
"""
Handle all async requests (from JS).
"""
query
=
request
.
args
.
get
(
'
query
'
)
query
=
request
.
args
.
get
(
'
query
'
)
...
@@ -62,6 +62,7 @@ def ajax():
...
@@ -62,6 +62,7 @@ def ajax():
return
render_template
(
template_name
,
agency
=
agency
,
config
=
app
.
config
)
return
render_template
(
template_name
,
agency
=
agency
,
config
=
app
.
config
)
except
TemplateNotFound
:
except
TemplateNotFound
:
return
abort
(
404
)
return
abort
(
404
)
@cache_for
(
hours
=
1
)
def
routes
():
def
routes
():
"""
Serve the route configuration (routes, stops)
"""
"""
Serve the route configuration (routes, stops)
"""
from
models
import
Route
,
RouteStop
,
Stop
from
models
import
Route
,
RouteStop
,
Stop
...
@@ -69,11 +70,12 @@ def ajax():
...
@@ -69,11 +70,12 @@ def ajax():
.
filter
(
Agency
.
tag
==
agency_tag
).
all
()
.
filter
(
Agency
.
tag
==
agency_tag
).
all
()
stops
=
db
.
session
.
query
(
Stop
).
options
(
joinedload
(
Stop
.
routes
))
\
stops
=
db
.
session
.
query
(
Stop
).
options
(
joinedload
(
Stop
.
routes
))
\
.
filter
(
Stop
.
routes
.
any
(
Route
.
id
.
in_
([
r
.
id
for
r
in
routes
]))).
all
()
.
filter
(
Stop
.
routes
.
any
(
Route
.
id
.
in_
([
r
.
id
for
r
in
routes
]))).
all
()
return
{
return
jsonify
(
{
"
routes
"
:
{
r
.
tag
:
r
.
serialize
()
for
r
in
routes
},
"
routes
"
:
{
r
.
tag
:
r
.
serialize
()
for
r
in
routes
},
"
stops
"
:
{
s
.
id
:
s
.
serialize
()
for
s
in
stops
}
"
stops
"
:
{
s
.
id
:
s
.
serialize
()
for
s
in
stops
}
}
}
)
@cache_for
(
seconds
=
5
)
def
vehicles
():
def
vehicles
():
"""
Serve the current vehicle locations and arrival predictions.
"""
"""
Serve the current vehicle locations and arrival predictions.
"""
from
models
import
Route
,
VehicleLocation
,
Prediction
from
models
import
Route
,
VehicleLocation
,
Prediction
...
@@ -105,11 +107,12 @@ def ajax():
...
@@ -105,11 +107,12 @@ def ajax():
Prediction
.
prediction
>=
now
)
\
Prediction
.
prediction
>=
now
)
\
.
group_by
(
Prediction
.
id
,
Prediction
.
vehicle
,
Prediction
.
stop_id
)
\
.
group_by
(
Prediction
.
id
,
Prediction
.
vehicle
,
Prediction
.
stop_id
)
\
.
all
()
.
all
()
return
{
return
jsonify
(
{
"
locations
"
:
{
v
.
vehicle
:
v
.
serialize
()
for
v
in
vehicle_locations
},
"
locations
"
:
{
v
.
vehicle
:
v
.
serialize
()
for
v
in
vehicle_locations
},
"
predictions
"
:
{
p
.
id
:
p
.
serialize
()
for
p
in
predictions
}
"
predictions
"
:
{
p
.
id
:
p
.
serialize
()
for
p
in
predictions
}
}
}
)
@cache_for
(
seconds
=
15
)
def
predictions
():
def
predictions
():
"""
Serve arrival predictions only.
"""
"""
Serve arrival predictions only.
"""
from
models
import
Prediction
from
models
import
Prediction
...
@@ -132,16 +135,16 @@ def ajax():
...
@@ -132,16 +135,16 @@ def ajax():
predictions
=
predictions
\
predictions
=
predictions
\
.
group_by
(
Prediction
.
id
,
Prediction
.
vehicle
,
Prediction
.
stop_id
)
\
.
group_by
(
Prediction
.
id
,
Prediction
.
vehicle
,
Prediction
.
stop_id
)
\
.
all
()
.
all
()
return
{
return
jsonify
(
{
"
predictions
"
:
{
p
.
vehicle
:
p
.
serialize
()
for
p
in
predictions
},
"
predictions
"
:
{
p
.
vehicle
:
p
.
serialize
()
for
p
in
predictions
},
}
}
)
if
query
==
"
routes
"
:
if
query
==
"
routes
"
:
return
jsonify
(
routes
()
)
return
routes
()
elif
query
==
"
vehicles
"
:
elif
query
==
"
vehicles
"
:
return
jsonify
(
vehicles
()
)
return
vehicles
()
elif
query
==
"
predictions
"
:
elif
query
==
"
predictions
"
:
return
jsonify
(
predictions
()
)
return
predictions
()
elif
query
==
"
modal
"
:
elif
query
==
"
modal
"
:
modal_name
=
request
.
args
.
get
(
'
modal_name
'
)
modal_name
=
request
.
args
.
get
(
'
modal_name
'
)
return
modal
(
modal_name
)
return
modal
(
modal_name
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment