Skip to content

Commit

Permalink
Added summary endpoint #9
Browse files Browse the repository at this point in the history
  • Loading branch information
abkfenris committed Dec 11, 2016
1 parent 6fb05a9 commit f18c8ff
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ test:

up:
\rm -f celerybeat.pid
alias dc=docker-compose
docker-compose up -d --build
docker-compose logs -f
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ services:
- ./docker-data/postgis:/var/lib/postgresql/data
environment:
PGDATA: /var/lib/postgresql/data/PGDATA
ports:
- "5432:5432"
taskqueue:
image: redis:alpine

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ beautifulsoup4==4.5.1
dateparser==0.5.0
lxml==3.6.4
html2text==2016.9.19
celery==4.0.0
celery==4.0.1
redis==2.10.5

# Testing
Expand Down
34 changes: 33 additions & 1 deletion sugarloaf/controllers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

@api.route('/current')
def current():
"""Return a json with most recent trail and lift conditions and daily report"""
latest = db.session.scalar(func.MAX(TrailStatus.dt))

trails = db.session.query(Trail.name,
Expand All @@ -27,4 +28,35 @@ def current():
'groomed': trail.groomed,
'snowmaking': trail.snowmaking,
'open': trail.open} for trail in trails]})



@api.route('/summary')
def summary():
""" Return json with a summary of the trail status by update """
conditions = db.session.query(TrailStatus.dt,
TrailStatus.open,
TrailStatus.groomed,
TrailStatus.snowmaking,
Trail.difficulty,
Area.name,
func.count())\
.filter(TrailStatus.trail_id == Trail.id, Trail.area_id == Area.id)\
.group_by(TrailStatus.dt,
TrailStatus.open,
TrailStatus.groomed,
TrailStatus.snowmaking,
Trail.difficulty,
Area.name)

output = {'conditions': [{
'datetime': condition.dt,
'open': condition.open,
'groomed': condition.groomed,
'snowmaking': condition.snowmaking,
'difficulty': condition.difficulty,
'trail_count': condition[5],
'area': condition.name
} for condition in conditions]}

print(output)
return jsonify(output)

0 comments on commit f18c8ff

Please sign in to comment.