def find_meetings(flight_id): logger.info("Searching for near flights of flight %d" % flight_id) flight = Flight.get(flight_id) # Update FlightPathChunks of current flight FlightPathChunks.update_flight_path(flight) other_flights = FlightPathChunks.get_near_flights(flight) # delete all previous detected points between src and dst for key in other_flights: FlightMeetings.query().filter( or_( and_( FlightMeetings.source == flight, FlightMeetings.destination_id == key, ), and_( FlightMeetings.destination == flight, FlightMeetings.source_id == key, ), )).delete() # Insert new meetings into table for flight_id, meetings in other_flights.items(): other_flight = Flight.get(flight_id) for meeting in meetings: FlightMeetings.add_meeting(flight, other_flight, meeting["times"][0], meeting["times"][-1]) db.session.commit()
def find_meetings(flight_id): logger.info("Searching for near flights of flight %d" % flight_id) flight = Flight.get(flight_id) # Update FlightPathChunks of current flight FlightPathChunks.update_flight_path(flight) other_flights = FlightPathChunks.get_near_flights(flight) # delete all previous detected points between src and dst for key in other_flights: FlightMeetings.query() \ .filter(or_(and_(FlightMeetings.source == flight, FlightMeetings.destination_id == key), and_(FlightMeetings.destination == flight, FlightMeetings.source_id == key))) \ .delete() # Insert new meetings into table for flight_id, meetings in other_flights.iteritems(): other_flight = Flight.get(flight_id) for meeting in meetings: FlightMeetings.add_meeting(flight, other_flight, meeting['times'][0], meeting['times'][-1]) db.session.commit()
def index(): near_flights = FlightMeetings.get_meetings(g.flight) mark_flight_notifications_read(g.flight) return render_template('flights/map.jinja', flight=g.flight, near_flights=near_flights, other_flights=g.other_flights, comments=comments_partial(), phase_formatter=format_phase, leg_formatter=format_legs)
def index(): near_flights = FlightMeetings.get_meetings(g.flight) mark_flight_notifications_read(g.flight) return render_template( 'flights/map.jinja', flight=g.flight, near_flights=near_flights, other_flights=g.other_flights, comments=comments_partial(), phase_formatter=format_phase, leg_formatter=format_legs)
def index(): def add_flight_path(flight): trace = _get_flight_path(flight) return (flight, trace) near_flights = FlightMeetings.get_meetings(g.flight) other_flights = map(add_flight_path, g.other_flights) mark_flight_notifications_read(g.flight) return render_template('flights/view.jinja', flight=g.flight, trace=_get_flight_path(g.flight), near_flights=near_flights, other_flights=other_flights, phase_formatter=format_phase)
def index(): def add_flight_path(flight): trace = _get_flight_path(flight) return (flight, trace) near_flights = FlightMeetings.get_meetings(g.flight) other_flights = map(add_flight_path, g.other_flights) mark_flight_notifications_read(g.flight) return render_template( 'flights/view.jinja', flight=g.flight, trace=_get_flight_path(g.flight), near_flights=near_flights, other_flights=other_flights, phase_formatter=format_phase)
def test_meetings(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) flight2 = flights.one( igc_file=igcs.simple(owner=users.jane(), md5="foobar")) meeting1 = FlightMeetings( source=flight, destination=flight2, start_time=datetime(2016, 4, 3, 12, 34, 56), end_time=datetime(2016, 4, 3, 12, 38, 1), ) meeting2 = FlightMeetings( source=flight2, destination=flight, start_time=datetime(2016, 4, 3, 12, 56, 36), end_time=datetime(2016, 4, 3, 13, 1, 31), ) add_fixtures(db_session, flight, flight2, meeting1, meeting2) res = client.get("/flights/{id}?extended".format(id=flight.id)) assert res.status_code == 200 assert res.json == { u"flight": expected_basic_flight_json(flight), u"near_flights": [{ u"flight": { u"id": flight2.id, u"pilot": { u"id": flight2.pilot.id, u"name": u"Jane Doe" }, u"pilotName": None, u"copilot": None, u"copilotName": None, u"model": None, u"registration": None, u"competitionId": None, u"igcFile": { u"filename": u"simple.igc", u"date": u"2011-06-18", u"registration": None, u"owner": { u"id": flight2.igc_file.owner.id, u"name": u"Jane Doe", }, u"model": None, u"competitionId": None, }, }, u"times": [ { u"start": u"2016-04-03T12:34:56+00:00", u"end": u"2016-04-03T12:38:01+00:00", }, { u"start": u"2016-04-03T12:56:36+00:00", u"end": u"2016-04-03T13:01:31+00:00", }, ], }], u"comments": [], u"contest_legs": { u"classic": [], u"triangle": [] }, u"phases": [], u"performance": { u"circling": [], u"cruise": {} }, }
def index(): if 'application/json' in request.headers.get('Accept', ''): return jsonify(flight=FlightSchema().dump(g.flight).data) near_flights = FlightMeetings.get_meetings(g.flight).values() near_flights = NearFlightSchema().dump(near_flights, many=True).data comments = FlightCommentSchema().dump(g.flight.comments, many=True).data phases_schema = FlightPhaseSchema(only=( 'circlingDirection', 'type', 'secondsOfDay', 'startTime', 'duration', 'altDiff', 'distance', 'vario', 'speed', 'glideRate', )) phases = phases_schema.dump(g.flight.phases, many=True).data cruise_performance_schema = FlightPhaseSchema(only=( 'duration', 'fraction', 'altDiff', 'distance', 'vario', 'speed', 'glideRate', 'count', )) cruise_performance = cruise_performance_schema.dump(g.flight.cruise_performance).data circling_performance_schema = FlightPhaseSchema(only=( 'circlingDirection', 'count', 'vario', 'fraction', 'duration', 'altDiff', )) circling_performance = circling_performance_schema.dump(g.flight.circling_performance, many=True).data contest_leg_schema = ContestLegSchema() contest_legs = {} for type in ['classic', 'triangle']: legs = g.flight.get_contest_legs('olc_plus', type) contest_legs[type] = contest_leg_schema.dump(legs, many=True).data mark_flight_notifications_read(g.flight) return render_template( 'flights/map.jinja', flight=g.flight, flight_json=FlightSchema().dump(g.flight).data, near_flights=near_flights, other_flights=g.other_flights, comments=comments, contest_legs=contest_legs, phases=phases, performance=dict(circling=circling_performance, cruise=cruise_performance))
def read(flight_id): flight = get_requested_record(Flight, flight_id, joinedload=[Flight.igc_file]) current_user = User.get(request.user_id) if request.user_id else None if not flight.is_viewable(current_user): return jsonify(), 404 _reanalyse_if_needed(flight) mark_flight_notifications_read(flight) flight_json = FlightSchema().dump(flight).data if 'extended' not in request.args: return jsonify(flight=flight_json) near_flights = FlightMeetings.get_meetings(flight).values() near_flights = NearFlightSchema().dump(near_flights, many=True).data comments = FlightCommentSchema().dump(flight.comments, many=True).data phases_schema = FlightPhaseSchema(only=( 'circlingDirection', 'type', 'secondsOfDay', 'startTime', 'duration', 'altDiff', 'distance', 'vario', 'speed', 'glideRate', )) phases = phases_schema.dump(flight.phases, many=True).data cruise_performance_schema = FlightPhaseSchema(only=( 'duration', 'fraction', 'altDiff', 'distance', 'vario', 'speed', 'glideRate', 'count', )) cruise_performance = cruise_performance_schema.dump( flight.cruise_performance).data circling_performance_schema = FlightPhaseSchema(only=( 'circlingDirection', 'count', 'vario', 'fraction', 'duration', 'altDiff', )) circling_performance = circling_performance_schema.dump( flight.circling_performance, many=True).data performance = dict(circling=circling_performance, cruise=cruise_performance) contest_leg_schema = ContestLegSchema() contest_legs = {} for type in ['classic', 'triangle']: legs = flight.get_contest_legs('olc_plus', type) contest_legs[type] = contest_leg_schema.dump(legs, many=True).data return jsonify(flight=flight_json, near_flights=near_flights, comments=comments, contest_legs=contest_legs, phases=phases, performance=performance)
def test_meetings(db_session, client): flight = flights.one(igc_file=igcs.simple(owner=users.john())) flight2 = flights.one( igc_file=igcs.simple(owner=users.jane(), md5='foobar')) meeting1 = FlightMeetings( source=flight, destination=flight2, start_time=datetime(2016, 4, 3, 12, 34, 56), end_time=datetime(2016, 4, 3, 12, 38, 1), ) meeting2 = FlightMeetings( source=flight2, destination=flight, start_time=datetime(2016, 4, 3, 12, 56, 36), end_time=datetime(2016, 4, 3, 13, 1, 31), ) add_fixtures(db_session, flight, flight2, meeting1, meeting2) res = client.get('/flights/{id}?extended'.format(id=flight.id)) assert res.status_code == 200 assert res.json == { u'flight': expected_basic_flight_json(flight), u'near_flights': [{ u'flight': { u'id': flight2.id, u'pilot': { u'id': flight2.pilot.id, u'name': u'Jane Doe', }, u'pilotName': None, u'copilot': None, u'copilotName': None, u'model': None, u'registration': None, u'competitionId': None, u'igcFile': { u'filename': u'simple.igc', u'date': u'2011-06-18', u'registration': None, u'owner': { u'id': flight2.igc_file.owner.id, u'name': u'Jane Doe', }, u'model': None, u'competitionId': None, }, }, u'times': [{ u'start': u'2016-04-03T12:34:56+00:00', u'end': u'2016-04-03T12:38:01+00:00', }, { u'start': u'2016-04-03T12:56:36+00:00', u'end': u'2016-04-03T13:01:31+00:00', }], }], u'comments': [], u'contest_legs': { u'classic': [], u'triangle': [], }, u'phases': [], u'performance': { u'circling': [], u'cruise': {}, }, }
def read(flight_id): flight = get_requested_record(Flight, flight_id, joinedload=[Flight.igc_file]) current_user = User.get(request.user_id) if request.user_id else None if not flight.is_viewable(current_user): return jsonify(), 404 _reanalyse_if_needed(flight) mark_flight_notifications_read(flight) flight_json = FlightSchema().dump(flight).data if "extended" not in request.args: return jsonify(flight=flight_json) near_flights = FlightMeetings.get_meetings(flight).values() near_flights = NearFlightSchema().dump(near_flights, many=True).data comments = FlightCommentSchema().dump(flight.comments, many=True).data phases_schema = FlightPhaseSchema( only=( "circlingDirection", "type", "secondsOfDay", "startTime", "duration", "altDiff", "distance", "vario", "speed", "glideRate", ) ) phases = phases_schema.dump(flight.phases, many=True).data cruise_performance_schema = FlightPhaseSchema( only=("duration", "fraction", "altDiff", "distance", "vario", "speed", "glideRate", "count") ) cruise_performance = cruise_performance_schema.dump(flight.cruise_performance).data circling_performance_schema = FlightPhaseSchema( only=("circlingDirection", "count", "vario", "fraction", "duration", "altDiff") ) circling_performance = circling_performance_schema.dump(flight.circling_performance, many=True).data performance = dict(circling=circling_performance, cruise=cruise_performance) contest_leg_schema = ContestLegSchema() contest_legs = {} for type in ["classic", "triangle"]: legs = flight.get_contest_legs("olc_plus", type) contest_legs[type] = contest_leg_schema.dump(legs, many=True).data return jsonify( flight=flight_json, near_flights=near_flights, comments=comments, contest_legs=contest_legs, phases=phases, performance=performance, )