示例#1
0
def test_speed_format():
    """ Check speed formatting """

    eq_(units.format_speed(0, 0), '0 km/h')
    eq_(units.format_speed(0), '0.0 km/h')
    eq_(units.format_speed(12), '43.2 km/h')
    eq_(units.format_speed(10, 3), '36.000 km/h')
示例#2
0
def test_speed_format():
    """ Check speed formatting """

    assert units.format_speed(0, 0) == '0 km/h'
    assert units.format_speed(0) == '0.0 km/h'
    assert units.format_speed(12) == '43.2 km/h'
    assert units.format_speed(10, 3) == '36.000 km/h'
def test_speed_format():
    """ Check speed formatting """

    eq_(units.format_speed(0, 0), "0 km/h")
    eq_(units.format_speed(0), "0.0 km/h")
    eq_(units.format_speed(12), "43.2 km/h")
    eq_(units.format_speed(10, 3), "36.000 km/h")
示例#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 "",
             vario=units.format_lift(phase.vario),
             alt_diff=units.format_altitude(phase.alt_diff),
             count=phase.count,
             duration=phase.duration,
             is_circling=is_circling,
             type=PHASETYPE_NAMES[phase.phase_type],
             circling_direction="",
             distance="",
             glide_rate="")

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

        # 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_number(phase.glide_rate)
        else:
            r['glide_rate'] = u'\u221e'  # infinity
    else:
        r['circling_direction'] = CIRCDIR_NAMES[phase.circling_direction]
    return r
示例#5
0
文件: flight.py 项目: fb/skylines
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 "",
             vario=units.format_lift(phase.vario),
             alt_diff=units.format_altitude(phase.alt_diff),
             count=phase.count,
             duration=phase.duration,
             is_circling=is_circling,
             type=PHASETYPE_NAMES[phase.phase_type],
             circling_direction="",
             distance="",
             glide_rate="")

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

        # 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_number(phase.glide_rate)
        else:
            r['glide_rate'] = u'\u221e'  # infinity
    else:
        r['circling_direction'] = CIRCDIR_NAMES[phase.circling_direction]
    return r
示例#6
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
示例#7
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