This commit is contained in:
Danila Fedorin 2020-05-12 17:33:11 -07:00
commit 910bb5d5bf
10 changed files with 33 additions and 1 deletions

BIN
fgs/.model.py.swp Normal file

Binary file not shown.

BIN
fgs/.views.py.swo Normal file

Binary file not shown.

BIN
fgs/.views.py.swp Normal file

Binary file not shown.

BIN
fgs/__init__.pyc Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -3,6 +3,7 @@ from .jwt import jwt_required
from .model import *
from flask import g, jsonify, request, abort
from sqlalchemy import func
import geopy.distance
@app.route('/')
def index():
@ -37,6 +38,29 @@ def collars():
return jsonify(active_collars)
@app.route('/collars/stats/distance')
@jwt_required
def collars_distance():
active_collars = []
for collar in Collar.query.filter_by(active=True).all():
coords = DataPoint.query.filter_by(collar_id=collar.id).\
order_by(DataPoint.datetime.desc())
distance_kilometers = 0
coords_pairs = list(map(lambda e : (e.longitude, e.latitude), coords))
coord_last = coords_pairs.pop()
for coord in coords_pairs:
distance_kilometers += geopy.distance.VincentyDistance(coord_last,coord).km
coord_last = coord
active_collars.append(
{'id': collar.id, 'name': collar.name,
'distance': distance_kilometers }
)
return jsonify(active_collars)
@app.route('/collars/<int:id>/history')
@jwt_required
def collar_history(id):

10
run.sh
View File

@ -1,2 +1,10 @@
inlets client --remote=104.236.9.120:8090 --upstream=http://127.0.0.1:5000 --token=$1 &
#!/bin/bash
if [ "$#" -ne 3 ]; then
echo usage: $0 "<inlets_ip_address:port> <inlets_token> <sqlite_database_path>"
exit
fi
# Run the Flask and Python server through inlets
export DB_LOC=$3
inlets client --remote=$1 --upstream=http://127.0.0.1:5000 --token=$2 &
FLASK_APP=fgs flask run