Merge branch 'master' of https://dev.danilafe.com/CS-46X/server
This commit is contained in:
commit
910bb5d5bf
BIN
fgs/.model.py.swp
Normal file
BIN
fgs/.model.py.swp
Normal file
Binary file not shown.
BIN
fgs/.views.py.swo
Normal file
BIN
fgs/.views.py.swo
Normal file
Binary file not shown.
BIN
fgs/.views.py.swp
Normal file
BIN
fgs/.views.py.swp
Normal file
Binary file not shown.
BIN
fgs/__init__.pyc
Normal file
BIN
fgs/__init__.pyc
Normal file
Binary file not shown.
BIN
fgs/__pycache__/__init__.cpython-37.pyc
Normal file
BIN
fgs/__pycache__/__init__.cpython-37.pyc
Normal file
Binary file not shown.
BIN
fgs/__pycache__/jwt.cpython-37.pyc
Normal file
BIN
fgs/__pycache__/jwt.cpython-37.pyc
Normal file
Binary file not shown.
BIN
fgs/__pycache__/model.cpython-37.pyc
Normal file
BIN
fgs/__pycache__/model.cpython-37.pyc
Normal file
Binary file not shown.
BIN
fgs/__pycache__/views.cpython-37.pyc
Normal file
BIN
fgs/__pycache__/views.cpython-37.pyc
Normal file
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 .model import *
|
||||||
from flask import g, jsonify, request, abort
|
from flask import g, jsonify, request, abort
|
||||||
from sqlalchemy import func
|
from sqlalchemy import func
|
||||||
|
import geopy.distance
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
|
@ -37,6 +38,29 @@ def collars():
|
||||||
|
|
||||||
return jsonify(active_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')
|
@app.route('/collars/<int:id>/history')
|
||||||
@jwt_required
|
@jwt_required
|
||||||
def collar_history(id):
|
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
|
FLASK_APP=fgs flask run
|
||||||
|
|
Loading…
Reference in New Issue
Block a user