Merge branch 'master' of https://dev.danilafe.com/CS-46X/server
This commit is contained in:
commit
ec08fca5b7
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
*.swp
|
||||
*.sqlite
|
||||
__pycache__
|
|
@ -26,10 +26,12 @@ class DataPoint(db.Model):
|
|||
|
||||
class StimulusActivation(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
collar_id = db.Column(db.Integer, db.ForeignKey('collar.id'))
|
||||
longitude = db.Column(db.Float(precision=10))
|
||||
latitude = db.Column(db.Float(precision=10))
|
||||
volume_level = db.Column(db.Integer)
|
||||
voltage_level = db.Column(db.Integer)
|
||||
datetime = db.Column(db.DateTime)
|
||||
|
||||
class User(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
|
11
fgs/views.py
11
fgs/views.py
|
@ -4,6 +4,7 @@ from .model import *
|
|||
from flask import g, jsonify, request, abort
|
||||
from sqlalchemy import func
|
||||
import geopy.distance
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
|
@ -80,4 +81,12 @@ def collar_detail(id):
|
|||
collar = Collar.query.filter_by(id=id).first()
|
||||
if collar is None: abort(404)
|
||||
|
||||
return jsonify({'id': collar.id, 'name': collar.name })
|
||||
# get stimulus activation reports from within last 24 hours
|
||||
since = datetime.now() - timedelta(hours=24)
|
||||
stimulus_points = StimulusActivation.query.\
|
||||
filter_by(collar_id=id).\
|
||||
filter(StimulusActivation.datetime < since).\
|
||||
order_by(StimulusActivation.datetime.desc())
|
||||
n_stimulus = stimulus_points.count()
|
||||
|
||||
return jsonify({'id': collar.id, 'name': collar.name, 'stimilus': n_stimulus })
|
||||
|
|
Loading…
Reference in New Issue
Block a user