Updated SQL command
This commit is contained in:
parent
8839eedd40
commit
5a20130c37
|
@ -3,7 +3,7 @@ from flask_sqlalchemy import SQLAlchemy
|
|||
import os
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///./data.sqlite'
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.getenv('DB_LOC')
|
||||
app.secret_key = os.environ.get('FGS_SECRET_KEY') or 'default secret key'
|
||||
|
||||
db = SQLAlchemy(app)
|
||||
|
|
22
fgs/views.py
22
fgs/views.py
|
@ -1,4 +1,4 @@
|
|||
from . import app
|
||||
from . import app, db
|
||||
from .jwt import jwt_required
|
||||
from .model import *
|
||||
from flask import g, jsonify, request, abort
|
||||
|
@ -25,18 +25,16 @@ def me():
|
|||
@app.route('/collars')
|
||||
@jwt_required
|
||||
def collars():
|
||||
active_collars = Collar.query.\
|
||||
filter_by(active=True).\
|
||||
join(DataPoint, isouter=True).\
|
||||
active_collars = []
|
||||
for collar in Collar.query.filter_by(active=True).all():
|
||||
max_point = DataPoint.query.filter_by(collar_id=collar.id).\
|
||||
order_by(DataPoint.datetime.desc()).\
|
||||
group_by(Collar.id).\
|
||||
with_entities(
|
||||
Collar.id, Collar.name,
|
||||
DataPoint.longitude, DataPoint.latitude).\
|
||||
all()
|
||||
active_collars = [
|
||||
{'id': id, 'name': name, 'pos': {'longitude': lo, 'latitude': la}}
|
||||
for (id, name, lo, la) in active_collars]
|
||||
first()
|
||||
active_collars.append(
|
||||
{'id': collar.id, 'name': collar.name, 'pos':
|
||||
{'longitude': max_point.longitude, 'latitude': max_point.latitude}}
|
||||
)
|
||||
|
||||
return jsonify(active_collars)
|
||||
|
||||
@app.route('/collars/<int:id>/history')
|
||||
|
|
Loading…
Reference in New Issue
Block a user