Merge branch 'master' of https://dev.danilafe.com/CS-46X/server
This commit is contained in:
commit
910bb5d5bf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
24
fgs/views.py
24
fgs/views.py
|
@ -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
10
run.sh
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue