fixed SQL between

pull/1/head
Konstantin Gründger 2015-11-14 21:15:22 +01:00
rodzic 89b6201c85
commit 45195706a4
1 zmienionych plików z 45 dodań i 9 usunięć

Wyświetl plik

@ -16,13 +16,13 @@ app = Flask(__name__)
@app.route("/rec.php")
def index():
def rec():
sq = session.query(ReceiverBeacon.name, func.max(ReceiverBeacon.timestamp).label('lastseen')) \
.group_by(ReceiverBeacon.name) \
.subquery()
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)) \
.order_by(ReceiverBeacon.name)
@ -39,21 +39,21 @@ def index():
@app.route('/lxml.php', methods=['GET', 'POST'])
def live():
show_offline = request.args.get('a', False)
def lxml():
show_offline = request.args.get('a', 0) == 1
lat_max = request.args.get('b', 90)
lat_min = request.args.get('c', -90)
lon_max = request.args.get('d', 180)
lon_min = request.args.get('e', -180)
if show_offline:
start_observation = date.today()
observation_start = date.today()
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')) \
.filter(and_(between(AircraftBeacon.latitude, lat_max, lat_min), between(AircraftBeacon.longitude, lon_max, lon_min))) \
.filter(AircraftBeacon.timestamp > start_observation) \
.filter(and_(between(AircraftBeacon.latitude, lat_min, lat_max), between(AircraftBeacon.longitude, lon_min, lon_max))) \
.filter(AircraftBeacon.timestamp > observation_start) \
.group_by(AircraftBeacon.address) \
.subquery()
@ -65,7 +65,7 @@ def live():
lines.append('<?xml version="1.0" encoding="UTF-8"?>')
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_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
@ -77,5 +77,41 @@ def live():
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__":
app.run(debug=True)