Beispiel #1
0
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()
Beispiel #2
0
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()
Beispiel #3
0
def analyse_flight(flight_id, full=2048, triangle=6144, sprint=512):
    logger.info("Analysing flight %d" % flight_id)

    if analysis.analyse_flight(Flight.get(flight_id), full, triangle, sprint):
        db.session.commit()
    else:
        logger.warn("Analysis of flight %d failed." % flight_id)
Beispiel #4
0
def analyse_flight(flight_id, full=2048, triangle=6144, sprint=512):
    logger.info("Analysing flight %d" % flight_id)

    if analysis.analyse_flight(Flight.get(flight_id), full, triangle, sprint):
        db.session.commit()
    else:
        logger.warn("Analysis of flight %d failed." % flight_id)
Beispiel #5
0
def update():
    flight_id_list = request.values.getlist('flight_id')
    model_list = request.values.getlist('model')
    registration_list = request.values.getlist('registration')
    competition_id_list = request.values.getlist('competition_id')

    if (flight_id_list is None
            or len(flight_id_list) != len(model_list)
            or len(flight_id_list) != len(registration_list)):
        flash(_('Sorry, some error happened when updating your flight(s). Please contact a administrator for help.'), 'warning')
        return redirect('/flights/latest')

    for index, id in enumerate(flight_id_list):
        # Parse flight id

        try:
            id = int(id)
        except ValueError:
            continue

        # Get flight from database and check if it is writable

        flight = Flight.get(id)

        if not flight or not flight.is_writable(g.current_user):
            continue

        # Parse model, registration and competition ID

        try:
            model_id = int(model_list[index])
        except ValueError:
            model_id = None

        if model_id == 0:
            model_id = None

        registration = registration_list[index]
        if registration is not None:
            registration = registration.strip()
            if not 0 < len(registration) < 32:
                registration = None

        competition_id = competition_id_list[index]
        if competition_id is not None:
            competition_id = competition_id.strip()
            if not 0 < len(competition_id) < 5:
                competition_id = None

        # Set new values

        flight.model_id = model_id
        flight.registration = registration
        flight.competition_id = competition_id
        flight.time_modified = datetime.utcnow()

    db.session.commit()

    flash(_('Your flight(s) have been successfully updated.'))
    return redirect('/flights/latest')
Beispiel #6
0
def _update_flight(flight_id, model_id, registration, competition_id):
    # Get flight from database and check if it is writable
    flight = Flight.get(flight_id)

    if not flight or not flight.is_writable(g.current_user):
        return False

    # Parse model, registration and competition ID
    if model_id == 0:
        model_id = None

    if registration is not None:
        registration = registration.strip()
        if not 0 < len(registration) <= 32:
            registration = None

    if competition_id is not None:
        competition_id = competition_id.strip()
        if not 0 < len(competition_id) <= 5:
            competition_id = None

    # Set new values
    flight.model_id = model_id
    flight.registration = registration
    flight.competition_id = competition_id
    flight.time_modified = datetime.utcnow()

    db.session.commit()

    return True
Beispiel #7
0
def _update_flight(flight_id, model_id, registration, competition_id,
                   takeoff_time, scoring_start_time,
                   scoring_end_time, landing_time):
    # Get flight from database and check if it is writable
    flight = Flight.get(flight_id)

    if not flight or not flight.is_writable(g.current_user):
        return False

    # Parse model, registration and competition ID
    if model_id == 0:
        model_id = None

    if registration is not None:
        registration = registration.strip()
        if not 0 < len(registration) <= 32:
            registration = None

    if competition_id is not None:
        competition_id = competition_id.strip()
        if not 0 < len(competition_id) <= 5:
            competition_id = None

    # Set new values
    flight.model_id = model_id
    flight.registration = registration
    flight.competition_id = competition_id
    flight.time_modified = datetime.utcnow()

    # Update times only if they are reasonable and have been changed...
    trigger_analysis = False

    if takeoff_time and scoring_start_time and scoring_end_time and landing_time \
       and takeoff_time <= scoring_start_time <= scoring_end_time <= landing_time \
       and (flight.takeoff_time != takeoff_time
            or flight.scoring_start_time != scoring_start_time
            or flight.scoring_end_time != scoring_end_time
            or flight.landing_time != landing_time):

        flight.takeoff_time = takeoff_time
        flight.scoring_start_time = scoring_start_time
        flight.scoring_end_time = scoring_end_time
        flight.landing_time = landing_time

        trigger_analysis = True

    flight.privacy_level = Flight.PrivacyLevel.PUBLIC

    db.session.commit()

    if trigger_analysis:
        analyse_flight(flight)

    try:
        tasks.analyse_flight.delay(flight.id)
        tasks.find_meetings.delay(flight.id)
    except ConnectionError:
        current_app.logger.info('Cannot connect to Redis server')

    return True
Beispiel #8
0
def check_update_form(prefix, flight_id, name, status):
    if not flight_id:
        return None, None, None

    # Get flight from database and check if it is writable
    flight = Flight.get(flight_id)

    if not flight:
        abort(404)

    if status == UploadStatus.DUPLICATE:
        return flight, None, None

    else:
        if not flight.is_writable(g.current_user):
            abort(403)

        form = UploadUpdateForm(prefix=str(prefix), obj=flight)
        trace = _get_flight_path(flight)

        # Force takeoff_time and landing_time to be within the igc file limits
        if form.takeoff_time.data < trace['igc_start_time']:
            form.takeoff_time.data = trace['igc_start_time']

        if form.landing_time.data > trace['igc_end_time']:
            form.landing_time.data = trace['igc_end_time']

        return flight, trace, form
Beispiel #9
0
def analyse_flight(flight_id, full=2048, triangle=6144, sprint=512):
    logger.info("Analysing flight %d" % flight_id)

    flight = Flight.get(flight_id)
    success = analysis.analyse_flight(flight, full, triangle, sprint)

    if not success:
        logger.warn("Analysis of flight %d failed." % flight_id)
        return

    unlock_flight_achievements(flight)

    db.session.commit()
Beispiel #10
0
def check_update_form(prefix, flight_id, name, status):
    if not flight_id:
        return None, None

    # Get flight from database and check if it is writable
    flight = Flight.get(flight_id)

    if not flight:
        abort(404)

    if status == UploadStatus.DUPLICATE:
        return flight, None

    else:
        if not flight.is_writable(g.current_user):
            abort(403)

        form = ChangeAircraftForm(prefix=str(prefix), obj=flight)

        return flight, form
Beispiel #11
0
def check_update_form(prefix, status):
    form = UploadUpdateForm(prefix=str(prefix))

    if not form.id or not form.id.data:
        return None, None, None

    flight_id = form.id.data

    # Get flight from database and check if it is writable
    flight = Flight.get(flight_id)

    if not flight:
        abort(404)

    if status == UploadStatus.DUPLICATE:
        return flight, None, None

    else:
        if not flight.is_writable(g.current_user):
            abort(403)

        fp = flight_path(flight.igc_file, add_elevation=True, max_points=None)

        form.populate_obj(flight)

        # replace None in form.pilot_id and form.co_pilot_id with 0
        if not form.pilot_id.data: form.pilot_id.data = 0
        if not form.co_pilot_id.data: form.co_pilot_id.data = 0

        # Force takeoff_time and landing_time to be within the igc file limits
        if form.takeoff_time.data < fp[0].datetime:
            form.takeoff_time.data = fp[0].datetime

        if form.landing_time.data > fp[-1].datetime:
            form.landing_time.data = fp[-1].datetime

        return flight, fp, form
Beispiel #12
0
def check_update_form(prefix, status):
    form = UploadUpdateForm(prefix=str(prefix))

    if not form.id or not form.id.data:
        return None, None, None

    flight_id = form.id.data

    # Get flight from database and check if it is writable
    flight = Flight.get(flight_id)

    if not flight:
        abort(404)

    if status == UploadStatus.DUPLICATE:
        return flight, None, None

    else:
        if not flight.is_writable(g.current_user):
            abort(403)

        fp = flight_path(flight.igc_file, add_elevation=True, max_points=None)

        form.populate_obj(flight)

        # replace None in form.pilot_id and form.co_pilot_id with 0
        if not form.pilot_id.data: form.pilot_id.data = 0
        if not form.co_pilot_id.data: form.co_pilot_id.data = 0

        # Force takeoff_time and landing_time to be within the igc file limits
        if form.takeoff_time.data < fp[0].datetime:
            form.takeoff_time.data = fp[0].datetime

        if form.landing_time.data > fp[-1].datetime:
            form.landing_time.data = fp[-1].datetime

        return flight, fp, form
Beispiel #13
0
def update():
    flight_id_list = request.values.getlist('flight_id')
    model_list = request.values.getlist('model')
    registration_list = request.values.getlist('registration')
    competition_id_list = request.values.getlist('competition_id')

    if (flight_id_list is None or len(flight_id_list) != len(model_list)
            or len(flight_id_list) != len(registration_list)):
        flash(
            _('Sorry, some error happened when updating your flight(s). Please contact a administrator for help.'
              ), 'warning')
        return redirect('/flights/latest')

    for index, id in enumerate(flight_id_list):
        # Parse flight id

        try:
            id = int(id)
        except ValueError:
            continue

        # Get flight from database and check if it is writable

        flight = Flight.get(id)

        if not flight or not flight.is_writable(g.current_user):
            continue

        # Parse model, registration and competition ID

        try:
            model_id = int(model_list[index])
        except ValueError:
            model_id = None

        if model_id == 0:
            model_id = None

        registration = registration_list[index]
        if registration is not None:
            registration = registration.strip()
            if not 0 < len(registration) < 32:
                registration = None

        competition_id = competition_id_list[index]
        if competition_id is not None:
            competition_id = competition_id.strip()
            if not 0 < len(competition_id) < 5:
                competition_id = None

        # Set new values

        flight.model_id = model_id
        flight.registration = registration
        flight.competition_id = competition_id
        flight.time_modified = datetime.utcnow()

    db.session.commit()

    flash(_('Your flight(s) have been successfully updated.'))
    return redirect('/flights/latest')
Beispiel #14
0
def _update_flight(flight_id, fp, model_id, registration, competition_id,
                   takeoff_time, scoring_start_time,
                   scoring_end_time, landing_time,
                   pilot_id, pilot_name,
                   co_pilot_id, co_pilot_name):
    # Get flight from database and check if it is writable
    flight = Flight.get(flight_id)

    if not flight or not flight.is_writable(g.current_user):
        return False

    # Parse model, registration and competition ID
    if model_id == 0:
        model_id = None

    if registration is not None:
        registration = registration.strip()
        if not 0 < len(registration) <= 32:
            registration = None

    if competition_id is not None:
        competition_id = competition_id.strip()
        if not 0 < len(competition_id) <= 5:
            competition_id = None

    if pilot_id == 0:
        pilot_id = None

    # Set new values
    if flight.pilot_id != pilot_id:
        flight.pilot_id = pilot_id

        # update club if pilot changed
        if pilot_id:
            flight.club_id = User.get(pilot_id).club_id

    flight.pilot_name = pilot_name if pilot_name else None

    flight.co_pilot_id = co_pilot_id if co_pilot_id != 0 else None
    flight.co_pilot_name = co_pilot_name if co_pilot_name else None

    flight.model_id = model_id
    flight.registration = registration
    flight.competition_id = competition_id
    flight.time_modified = datetime.utcnow()

    # Update times only if they are reasonable and have been changed...
    trigger_analysis = False

    if takeoff_time and scoring_start_time and scoring_end_time and landing_time \
       and takeoff_time <= scoring_start_time <= scoring_end_time <= landing_time \
       and (flight.takeoff_time != takeoff_time
            or flight.scoring_start_time != scoring_start_time
            or flight.scoring_end_time != scoring_end_time
            or flight.landing_time != landing_time):

        flight.takeoff_time = takeoff_time
        flight.scoring_start_time = scoring_start_time
        flight.scoring_end_time = scoring_end_time
        flight.landing_time = landing_time

        trigger_analysis = True

    flight.privacy_level = Flight.PrivacyLevel.PUBLIC

    db.session.commit()

    if trigger_analysis:
        analyse_flight(flight, fp=fp)

    try:
        tasks.analyse_flight.delay(flight.id)
        tasks.find_meetings.delay(flight.id)
    except ConnectionError:
        current_app.logger.info('Cannot connect to Redis server')

    return True