kopia lustrzana https://github.com/glidernet/ogn-python
fixed SQL between
rodzic
89b6201c85
commit
45195706a4
|
@ -16,13 +16,13 @@ app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/rec.php")
|
@app.route("/rec.php")
|
||||||
def index():
|
def rec():
|
||||||
sq = session.query(ReceiverBeacon.name, func.max(ReceiverBeacon.timestamp).label('lastseen')) \
|
sq = session.query(ReceiverBeacon.name, func.max(ReceiverBeacon.timestamp).label('lastseen')) \
|
||||||
.group_by(ReceiverBeacon.name) \
|
.group_by(ReceiverBeacon.name) \
|
||||||
.subquery()
|
.subquery()
|
||||||
|
|
||||||
last_10_minutes = datetime.utcnow() - timedelta(minutes=10)
|
last_10_minutes = datetime.utcnow() - timedelta(minutes=10)
|
||||||
receiver_query = session.query(ReceiverBeacon.name, ReceiverBeacon.latitude, ReceiverBeacon.longitude, case([(sq.c.lastseen>last_10_minutes, True)], else_=False).label('is_online')) \
|
receiver_query = session.query(ReceiverBeacon.name, ReceiverBeacon.latitude, ReceiverBeacon.longitude, case([(sq.c.lastseen > last_10_minutes, True)], else_=False).label('is_online')) \
|
||||||
.filter(and_(ReceiverBeacon.name == sq.c.name, ReceiverBeacon.timestamp == sq.c.lastseen)) \
|
.filter(and_(ReceiverBeacon.name == sq.c.name, ReceiverBeacon.timestamp == sq.c.lastseen)) \
|
||||||
.order_by(ReceiverBeacon.name)
|
.order_by(ReceiverBeacon.name)
|
||||||
|
|
||||||
|
@ -39,21 +39,21 @@ def index():
|
||||||
|
|
||||||
|
|
||||||
@app.route('/lxml.php', methods=['GET', 'POST'])
|
@app.route('/lxml.php', methods=['GET', 'POST'])
|
||||||
def live():
|
def lxml():
|
||||||
show_offline = request.args.get('a', False)
|
show_offline = request.args.get('a', 0) == 1
|
||||||
lat_max = request.args.get('b', 90)
|
lat_max = request.args.get('b', 90)
|
||||||
lat_min = request.args.get('c', -90)
|
lat_min = request.args.get('c', -90)
|
||||||
lon_max = request.args.get('d', 180)
|
lon_max = request.args.get('d', 180)
|
||||||
lon_min = request.args.get('e', -180)
|
lon_min = request.args.get('e', -180)
|
||||||
|
|
||||||
if show_offline:
|
if show_offline:
|
||||||
start_observation = date.today()
|
observation_start = date.today()
|
||||||
else:
|
else:
|
||||||
start_observation = datetime.utcnow - timedelta(minutes=5)
|
observation_start = datetime.utcnow() - timedelta(minutes=5)
|
||||||
|
|
||||||
sq = session.query(AircraftBeacon.address, func.max(AircraftBeacon.timestamp).label('lastseen')) \
|
sq = session.query(AircraftBeacon.address, func.max(AircraftBeacon.timestamp).label('lastseen')) \
|
||||||
.filter(and_(between(AircraftBeacon.latitude, lat_max, lat_min), between(AircraftBeacon.longitude, lon_max, lon_min))) \
|
.filter(and_(between(AircraftBeacon.latitude, lat_min, lat_max), between(AircraftBeacon.longitude, lon_min, lon_max))) \
|
||||||
.filter(AircraftBeacon.timestamp > start_observation) \
|
.filter(AircraftBeacon.timestamp > observation_start) \
|
||||||
.group_by(AircraftBeacon.address) \
|
.group_by(AircraftBeacon.address) \
|
||||||
.subquery()
|
.subquery()
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ def live():
|
||||||
lines.append('<?xml version="1.0" encoding="UTF-8"?>')
|
lines.append('<?xml version="1.0" encoding="UTF-8"?>')
|
||||||
lines.append('<markers>')
|
lines.append('<markers>')
|
||||||
|
|
||||||
hashcode = '4711abcd'
|
hashcode = '4711abcd' #Todo
|
||||||
flarm_competition = lambda flarm_object: '_' + hashcode[6:7] if flarm_object is None else flarm_object.competition
|
flarm_competition = lambda flarm_object: '_' + hashcode[6:7] if flarm_object is None else flarm_object.competition
|
||||||
flarm_registration = lambda flarm_object: hashcode if flarm_object is None else flarm_object.registration
|
flarm_registration = lambda flarm_object: hashcode if flarm_object is None else flarm_object.registration
|
||||||
flarm_address = lambda flarm_object: 0 if flarm_object is None else flarm_object.address
|
flarm_address = lambda flarm_object: 0 if flarm_object is None else flarm_object.address
|
||||||
|
@ -77,5 +77,41 @@ def live():
|
||||||
return Response(xml, mimetype='text/xml')
|
return Response(xml, mimetype='text/xml')
|
||||||
|
|
||||||
|
|
||||||
|
#Todo
|
||||||
|
@app.route('/livexml1.php', methods=['GET', 'POST'])
|
||||||
|
def livexml1():
|
||||||
|
id = request.args.get('id')
|
||||||
|
l = request.args.get('l')
|
||||||
|
|
||||||
|
lines = list()
|
||||||
|
lines.append('<?xml version="1.0" encoding="UTF-8"?>')
|
||||||
|
lines.append('<markers>')
|
||||||
|
lines.append('<m e="0"/>')
|
||||||
|
|
||||||
|
lines.append('<m e="{0}" i="{1}" r="{2}"/>'.format(1, 'asdf', ''))
|
||||||
|
|
||||||
|
lines.append('</markers>')
|
||||||
|
xml = '\n'.join(lines)
|
||||||
|
return Response(xml, mimetype='text/xml')
|
||||||
|
|
||||||
|
|
||||||
|
#Todo
|
||||||
|
@app.route('/dataxml.php', methods=['GET', 'POST'])
|
||||||
|
def dataxml():
|
||||||
|
i = request.args.get('id')
|
||||||
|
address = request.args.get('l')
|
||||||
|
|
||||||
|
lines = list()
|
||||||
|
lines.append('<?xml version="1.0" encoding="UTF-8"?>')
|
||||||
|
lines.append('<markers>')
|
||||||
|
lines.append('<m e="0"/>')
|
||||||
|
|
||||||
|
lines.append('<m g="{0}" i="{1}" a="{2}" b="{3}" c="{4}" d="{5}" e="{6}"/>'.format(0, 1, 2, 3, 4, 5, 6, 7))
|
||||||
|
|
||||||
|
lines.append('</markers>')
|
||||||
|
xml = '\n'.join(lines)
|
||||||
|
return Response(xml, mimetype='text/xml')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
|
Ładowanie…
Reference in New Issue