Beispiel #1
0
def format_legs(flight, legs):
    r = []

    for leg in legs:
        duration = leg.end_time - leg.start_time

        if duration.total_seconds() > 0:
            speed = leg.distance / duration.total_seconds()
            climb_percentage = leg.climb_duration.total_seconds(
            ) / duration.total_seconds() * 100
        else:
            speed = 0
            climb_percentage = 0

        if abs(leg.cruise_height) > 0 and leg.cruise_distance \
           and abs(leg.cruise_distance / leg.cruise_height) < 1000:
            glide_rate = format_decimal(float(leg.cruise_distance) /
                                        -leg.cruise_height,
                                        format='#.#')
        else:
            glide_rate = u'\u221e'  # infinity

        if leg.climb_duration.total_seconds() > 0:
            if leg.climb_height:
                climbrate = leg.climb_height / leg.climb_duration.total_seconds(
                )
            else:
                climbrate = 0

            climbrate_text = units.format_lift(climbrate)
        else:
            climbrate_text = u'-'

        r.append(
            dict(distance=units.format_distance(leg.distance, 1),
                 duration=duration,
                 speed=units.format_speed(speed),
                 climb_percentage=format_decimal(climb_percentage,
                                                 format='#.#'),
                 climbrate=climbrate_text,
                 glide_rate=glide_rate,
                 start_time_of_day=to_seconds_of_day(flight.takeoff_time,
                                                     leg.start_time)))

    return r
Beispiel #2
0
def format_legs(flight, legs):
    r = []

    for leg in legs:
        duration = leg.end_time - leg.start_time

        if duration.total_seconds() > 0:
            speed = leg.distance / duration.total_seconds()
            climb_percentage = leg.climb_duration.total_seconds() / duration.total_seconds() * 100
        else:
            speed = 0
            climb_percentage = 0

        if abs(leg.cruise_height) > 0 and leg.cruise_distance \
           and abs(leg.cruise_distance / leg.cruise_height) < 1000:
            glide_rate = format_decimal(float(leg.cruise_distance) / -leg.cruise_height, format='#.#')
        else:
            glide_rate = u'\u221e'  # infinity

        if leg.climb_duration.total_seconds() > 0:
            if leg.climb_height:
                climbrate = leg.climb_height / leg.climb_duration.total_seconds()
            else:
                climbrate = 0

            climbrate_text = units.format_lift(climbrate)
        else:
            climbrate_text = u'-'

        r.append(dict(distance=units.format_distance(leg.distance, 1),
                      duration=duration,
                      speed=units.format_speed(speed),
                      climb_percentage=format_decimal(climb_percentage, format='#.#'),
                      climbrate=climbrate_text,
                      glide_rate=glide_rate,
                      start_time_of_day=to_seconds_of_day(flight.takeoff_time, leg.start_time)))

    return r
Beispiel #3
0
def format_phase(phase):
    """Format phase properties to human readable format
    """
    is_circling = phase.phase_type == FlightPhase.PT_CIRCLING

    r = dict(start="%s" % format_time(phase.start_time),
             fraction="%d%%" %
             phase.fraction if phase.fraction is not None else "",
             speed=units.format_speed(phase.speed)
             if phase.speed is not None else "",
             speed_number=units.format_speed(phase.speed, name=False)
             if phase.speed is not None else "",
             vario=units.format_lift(phase.vario),
             vario_number=units.format_lift(phase.vario, name=False),
             alt_diff=units.format_altitude(phase.alt_diff),
             alt_diff_number=units.format_altitude(phase.alt_diff, name=False),
             count=phase.count,
             duration=phase.duration,
             is_circling=is_circling,
             type=PHASETYPE_NAMES[phase.phase_type],
             circling_direction="",
             distance="",
             distance_number="",
             glide_rate="",
             circling_direction_left=phase.circling_direction ==
             FlightPhase.CD_LEFT,
             circling_direction_right=phase.circling_direction ==
             FlightPhase.CD_RIGHT,
             is_powered=phase.phase_type == FlightPhase.PT_POWERED)

    if not is_circling:
        r['distance'] = units.format_distance(phase.distance, 1)
        r['distance_number'] = units.format_distance(phase.distance,
                                                     1,
                                                     name=False)

        # Sensible glide rate values are formatted as numbers. Others are shown
        # as infinity symbol.
        if abs(phase.alt_diff) > 0 and abs(phase.glide_rate) < 1000:
            r['glide_rate'] = format_decimal(phase.glide_rate)
        else:
            r['glide_rate'] = u'\u221e'  # infinity
    else:
        r['circling_direction'] = CIRCDIR_NAMES[phase.circling_direction]
    return r
Beispiel #4
0
def format_phase(phase):
    """Format phase properties to human readable format
    """
    is_circling = phase.phase_type == FlightPhase.PT_CIRCLING

    r = dict(start="%s" % format_time(phase.start_time),
             fraction="%d%%" % phase.fraction if phase.fraction is not None else "",
             speed=units.format_speed(phase.speed) if phase.speed is not None else "",
             speed_number=units.format_speed(phase.speed, name=False) if phase.speed is not None else "",
             vario=units.format_lift(phase.vario),
             vario_number=units.format_lift(phase.vario, name=False),
             alt_diff=units.format_altitude(phase.alt_diff),
             alt_diff_number=units.format_altitude(phase.alt_diff, name=False),
             count=phase.count,
             duration=phase.duration,
             is_circling=is_circling,
             type=PHASETYPE_NAMES[phase.phase_type],
             circling_direction="",
             distance="",
             distance_number="",
             glide_rate="",
             circling_direction_left=phase.circling_direction == FlightPhase.CD_LEFT,
             circling_direction_right=phase.circling_direction == FlightPhase.CD_RIGHT,
             is_powered=phase.phase_type == FlightPhase.PT_POWERED)

    if not is_circling:
        r['distance'] = units.format_distance(phase.distance, 1)
        r['distance_number'] = units.format_distance(phase.distance, 1, name=False)

        # Sensible glide rate values are formatted as numbers. Others are shown
        # as infinity symbol.
        if abs(phase.alt_diff) > 0 and abs(phase.glide_rate) < 1000:
            r['glide_rate'] = format_decimal(phase.glide_rate)
        else:
            r['glide_rate'] = u'\u221e'  # infinity
    else:
        r['circling_direction'] = CIRCDIR_NAMES[phase.circling_direction]
    return r
def _create_list(tab,
                 kw,
                 date=None,
                 pilot=None,
                 club=None,
                 airport=None,
                 pinned=None,
                 filter=None,
                 columns=None):
    pilot_alias = aliased(User, name='pilot')
    owner_alias = aliased(User, name='owner')

    subq = db.session \
        .query(FlightComment.flight_id, func.count('*').label('count')) \
        .group_by(FlightComment.flight_id).subquery()

    flights = db.session.query(Flight, subq.c.count) \
        .join(Flight.igc_file) \
        .options(contains_eager(Flight.igc_file)) \
        .join(owner_alias, IGCFile.owner) \
        .options(contains_eager(Flight.igc_file, IGCFile.owner, alias=owner_alias)) \
        .outerjoin(pilot_alias, Flight.pilot) \
        .options(contains_eager(Flight.pilot, alias=pilot_alias)) \
        .options(joinedload(Flight.co_pilot)) \
        .outerjoin(Flight.club) \
        .options(contains_eager(Flight.club)) \
        .outerjoin(Flight.takeoff_airport) \
        .options(contains_eager(Flight.takeoff_airport)) \
        .outerjoin(Flight.model) \
        .options(contains_eager(Flight.model)) \
        .outerjoin((subq, Flight.comments))

    if date:
        flights = flights.filter(Flight.date_local == date)

    if pilot:
        flights = flights.filter(
            or_(Flight.pilot == pilot, Flight.co_pilot == pilot))
    if club:
        flights = flights.filter(Flight.club == club)

    if airport:
        flights = flights.filter(Flight.takeoff_airport == airport)

    if pinned:
        flights = flights.filter(Flight.id.in_(pinned))

    if filter is not None:
        flights = flights.filter(filter)

    if request.is_xhr:
        if not columns:
            columns = {
                0: (Flight, 'date_local'),
                1: (Flight, 'index_score'),
                2: (pilot_alias, 'name'),
                3: (Flight, 'olc_classic_distance'),
                4: (Airport, 'name'),
                5: (Club, 'name'),
                6: (AircraftModel, 'name'),
                7: (Flight, 'takeoff_time'),
                8: (Flight, 'id'),
                9: (Flight, 'num_comments'),
            }

        flights, response_dict = GetDatatableRecords(kw, flights, columns)

        aaData = []
        for flight, num_comments in flights:
            aaData.append(
                dict(takeoff_time=flight.takeoff_time.strftime('%H:%M'),
                     landing_time=flight.landing_time.strftime('%H:%M'),
                     date=flight.date_local.strftime('%d.%m.%Y'),
                     date_formatted=format_date(flight.date_local),
                     index_score=format_decimal(flight.index_score,
                                                format='0'),
                     olc_classic_distance=flight.olc_classic_distance,
                     pilot_id=flight.pilot_id,
                     pilot=flight.pilot and flight.pilot.name,
                     pilot_name=flight.pilot_name,
                     co_pilot_id=flight.co_pilot_id,
                     co_pilot=flight.co_pilot and flight.co_pilot.name,
                     co_pilot_name=flight.co_pilot_name,
                     club_id=flight.club_id,
                     club=flight.club and truncate(flight.club.name, 25),
                     owner=flight.igc_file.owner.name,
                     takeoff_airport=flight.takeoff_airport
                     and flight.takeoff_airport.name,
                     takeoff_airport_id=flight.takeoff_airport
                     and flight.takeoff_airport.id,
                     takeoff_airport_country_code=flight.takeoff_airport
                     and flight.takeoff_airport.country_code.lower(),
                     takeoff_airport_country_name=flight.takeoff_airport
                     and country_name(flight.takeoff_airport.country_code),
                     aircraft=(flight.model and flight.model.name)
                     or (flight.igc_file.model
                         and '[' + flight.igc_file.model + ']'),
                     aircraft_reg=flight.registration
                     or flight.igc_file.registration or "Unknown",
                     flight_id=flight.id,
                     num_comments=num_comments))

        return jsonify(aaData=aaData, **response_dict)

    else:
        if not date:
            flights = flights.order_by(Flight.date_local.desc())

        flights_count = flights.count()
        if flights_count > int(
                current_app.config.get('SKYLINES_LISTS_SERVER_SIDE', 250)):
            limit = int(
                current_app.config.get('SKYLINES_LISTS_DISPLAY_LENGTH', 50))
        else:
            limit = int(
                current_app.config.get('SKYLINES_LISTS_SERVER_SIDE', 250))

        flights = flights.order_by(Flight.index_score.desc())
        flights = flights.limit(limit)

        return render_template('flights/list.jinja',
                               tab=tab,
                               date=date,
                               pilot=pilot,
                               club=club,
                               airport=airport,
                               flights=flights,
                               flights_count=flights_count)
Beispiel #6
0
def _create_list(tab, kw, date=None, pilot=None, club=None, airport=None,
                 pinned=None, filter=None, columns=None):
    pilot_alias = aliased(User, name='pilot')
    owner_alias = aliased(User, name='owner')

    subq = db.session \
        .query(FlightComment.flight_id, func.count('*').label('count')) \
        .group_by(FlightComment.flight_id).subquery()

    flights = db.session.query(Flight, subq.c.count) \
        .join(Flight.igc_file) \
        .options(contains_eager(Flight.igc_file)) \
        .join(owner_alias, IGCFile.owner) \
        .options(contains_eager(Flight.igc_file, IGCFile.owner, alias=owner_alias)) \
        .outerjoin(pilot_alias, Flight.pilot) \
        .options(contains_eager(Flight.pilot, alias=pilot_alias)) \
        .options(joinedload(Flight.co_pilot)) \
        .outerjoin(Flight.club) \
        .options(contains_eager(Flight.club)) \
        .outerjoin(Flight.takeoff_airport) \
        .options(contains_eager(Flight.takeoff_airport)) \
        .outerjoin(Flight.model) \
        .options(contains_eager(Flight.model)) \
        .outerjoin((subq, Flight.comments))

    if date:
        flights = flights.filter(Flight.date_local == date)

    if pilot:
        flights = flights.filter(or_(Flight.pilot == pilot,
                                     Flight.co_pilot == pilot))
    if club:
        flights = flights.filter(Flight.club == club)

    if airport:
        flights = flights.filter(Flight.takeoff_airport == airport)

    if pinned:
        flights = flights.filter(Flight.id.in_(pinned))

    if filter is not None:
        flights = flights.filter(filter)

    if request.is_xhr:
        if not columns:
            columns = {
                0: (Flight, 'date_local'),
                1: (Flight, 'index_score'),
                2: (pilot_alias, 'name'),
                3: (Flight, 'olc_classic_distance'),
                4: (Airport, 'name'),
                5: (Club, 'name'),
                6: (AircraftModel, 'name'),
                7: (Flight, 'takeoff_time'),
                8: (Flight, 'id'),
                9: (Flight, 'num_comments'),
            }

        flights, response_dict = GetDatatableRecords(kw, flights, columns)

        aaData = []
        for flight, num_comments in flights:
            aaData.append(dict(takeoff_time=flight.takeoff_time.strftime('%H:%M'),
                               landing_time=flight.landing_time.strftime('%H:%M'),
                               date=flight.date_local.strftime('%d.%m.%Y'),
                               date_formatted=format_date(flight.date_local),
                               index_score=format_decimal(flight.index_score, format='0'),
                               olc_classic_distance=flight.olc_classic_distance,
                               pilot_id=flight.pilot_id,
                               pilot=flight.pilot and flight.pilot.name,
                               pilot_name=flight.pilot_name,
                               co_pilot_id=flight.co_pilot_id,
                               co_pilot=flight.co_pilot and flight.co_pilot.name,
                               co_pilot_name=flight.co_pilot_name,
                               club_id=flight.club_id,
                               club=flight.club and truncate(flight.club.name, 25),
                               owner=flight.igc_file.owner.name,
                               takeoff_airport=flight.takeoff_airport and flight.takeoff_airport.name,
                               takeoff_airport_id=flight.takeoff_airport and flight.takeoff_airport.id,
                               takeoff_airport_country_code=flight.takeoff_airport and flight.takeoff_airport.country_code.lower(),
                               takeoff_airport_country_name=flight.takeoff_airport and country_name(flight.takeoff_airport.country_code),
                               aircraft=(flight.model and flight.model.name) or (flight.igc_file.model and '[' + flight.igc_file.model + ']'),
                               aircraft_reg=flight.registration or flight.igc_file.registration or "Unknown",
                               flight_id=flight.id,
                               num_comments=num_comments))

        return jsonify(aaData=aaData, **response_dict)

    else:
        if not date:
            flights = flights.order_by(Flight.date_local.desc())

        flights_count = flights.count()
        if flights_count > int(current_app.config.get('SKYLINES_LISTS_SERVER_SIDE', 250)):
            limit = int(current_app.config.get('SKYLINES_LISTS_DISPLAY_LENGTH', 50))
        else:
            limit = int(current_app.config.get('SKYLINES_LISTS_SERVER_SIDE', 250))

        flights = flights.order_by(Flight.index_score.desc())
        flights = flights.limit(limit)

        return render_template('flights/list.jinja',
                               tab=tab, date=date, pilot=pilot, club=club,
                               airport=airport, flights=flights,
                               flights_count=flights_count)