diff --git a/fgs/.model.py.swp b/fgs/.model.py.swp new file mode 100644 index 0000000..5cec15f Binary files /dev/null and b/fgs/.model.py.swp differ diff --git a/fgs/.views.py.swo b/fgs/.views.py.swo new file mode 100644 index 0000000..bd90646 Binary files /dev/null and b/fgs/.views.py.swo differ diff --git a/fgs/.views.py.swp b/fgs/.views.py.swp new file mode 100644 index 0000000..fdd4d70 Binary files /dev/null and b/fgs/.views.py.swp differ diff --git a/fgs/__init__.pyc b/fgs/__init__.pyc new file mode 100644 index 0000000..5f41580 Binary files /dev/null and b/fgs/__init__.pyc differ diff --git a/fgs/__pycache__/__init__.cpython-37.pyc b/fgs/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..56e6bcb Binary files /dev/null and b/fgs/__pycache__/__init__.cpython-37.pyc differ diff --git a/fgs/__pycache__/jwt.cpython-37.pyc b/fgs/__pycache__/jwt.cpython-37.pyc new file mode 100644 index 0000000..6a28e75 Binary files /dev/null and b/fgs/__pycache__/jwt.cpython-37.pyc differ diff --git a/fgs/__pycache__/model.cpython-37.pyc b/fgs/__pycache__/model.cpython-37.pyc new file mode 100644 index 0000000..9c4ae71 Binary files /dev/null and b/fgs/__pycache__/model.cpython-37.pyc differ diff --git a/fgs/__pycache__/views.cpython-37.pyc b/fgs/__pycache__/views.cpython-37.pyc new file mode 100644 index 0000000..92ac2d2 Binary files /dev/null and b/fgs/__pycache__/views.cpython-37.pyc differ diff --git a/fgs/views.py b/fgs/views.py index 220d752..162ad26 100644 --- a/fgs/views.py +++ b/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//history') @jwt_required def collar_history(id): diff --git a/run.sh b/run.sh index 2b51965..5738f53 100755 --- a/run.sh +++ b/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 " " + 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