Skip to content

Commit

Permalink
feat(api): add pagination to timeline API, close #118
Browse files Browse the repository at this point in the history
  • Loading branch information
ivelin committed Nov 11, 2019
1 parent 8e20202 commit 40993d6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build/prepare-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ docker tag "ambianic/ambianic-edge:latest" "ambianic/ambianic-edge:$MAJOR"
docker push "ambianic/ambianic-edge:$MAJOR"
docker tag "ambianic/ambianic-edge:latest" "ambianic/ambianic-edge:$MAJOR.$MINOR"
docker push "ambianic/ambianic-edge:$MAJOR.$MINOR"
docker tag "ambianic/ambianic-edge:latest" "ambianic/ambianic-edge $RELEASE_VERSION"
docker tag "ambianic/ambianic-edge:latest" "ambianic/ambianic-edge:$RELEASE_VERSION"
docker push "ambianic/ambianic-edge:$RELEASE_VERSION"
1 change: 1 addition & 0 deletions src/ambianic/webapp/flaskr.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def view_pipelines():
def get_timeline():
response_object = {'status': 'success'}
req_page = request.args.get('page', default=1, type=int)
log.debug('Requested timeline events page" %d', req_page)
nonlocal data_dir
resp = samples.get_timeline(page=req_page, data_dir=data_dir)
response_object['timeline'] = resp
Expand Down
12 changes: 8 additions & 4 deletions src/ambianic/webapp/server/samples.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Restful services related to pipeline samples."""
"""REST API for timeline events from pipeline samples."""
import logging
import uuid
import datetime
Expand Down Expand Up @@ -157,8 +157,12 @@ def get_timeline(before_datetime=None, page=1, data_dir=None):
log.debug('Fetched timeline file into struct of type %r with %d events: ',
type(timeline_events),
len(timeline_events))
# bring latest events to front
timeline_events.reverse()
# events are appended to the file as they arrive
# we need to read in reverse order to get the latest one first
timeline_slice = \
timeline_events[-1*page_start_position - 1:
-1*page_end_position - 1:
-1]
# files = sorted(files, key=os.path.getmtime, reverse=True)
# for json_file in files[page_start_position:page_end_position]:
# if
Expand All @@ -169,7 +173,7 @@ def get_timeline(before_datetime=None, page=1, data_dir=None):
# samples.append(sample)
# lines = map(str, files)
# log.debug('File names follow:\n %s', "\n".join(lines))
return timeline_events
return timeline_slice


def add_sample(new_sample=None):
Expand Down

0 comments on commit 40993d6

Please sign in to comment.