Beispiel #1
0
def _get_contest_traces(flight):
    contests = [
        dict(contest_type="olc_plus", trace_type="triangle"),
        dict(contest_type="olc_plus", trace_type="classic"),
    ]

    contest_traces = []

    for contest in contests:
        contest_trace = flight.get_optimised_contest_trace(
            contest["contest_type"], contest["trace_type"])
        if not contest_trace:
            continue

        fixes = [(x.latitude, x.longitude) for x in contest_trace.locations]
        times = []
        for time in contest_trace.times:
            times.append(flight.takeoff_time.hour * 3600 +
                         flight.takeoff_time.minute * 60 +
                         flight.takeoff_time.second +
                         (time - flight.takeoff_time).days * 86400 +
                         (time - flight.takeoff_time).seconds)

        contest_traces.append(
            dict(
                name=contest["contest_type"] + " " + contest["trace_type"],
                turnpoints=xcsoar.encode(fixes, floor=1e5, method="double"),
                times=xcsoar.encode(times, method="signed"),
            ))

    return contest_traces
Beispiel #2
0
def _get_contest_traces(flight):
    contests = [
        dict(contest_type='olc_plus', trace_type='triangle'),
        dict(contest_type='olc_plus', trace_type='classic')
    ]

    contest_traces = []

    for contest in contests:
        contest_trace = flight.get_optimised_contest_trace(
            contest['contest_type'], contest['trace_type'])
        if not contest_trace:
            continue

        fixes = map(lambda x: (x.latitude, x.longitude),
                    contest_trace.locations)
        times = []
        for time in contest_trace.times:
            times.append(flight.takeoff_time.hour * 3600 +
                         flight.takeoff_time.minute * 60 +
                         flight.takeoff_time.second +
                         (time - flight.takeoff_time).days * 86400 +
                         (time - flight.takeoff_time).seconds)

        contest_traces.append(
            dict(name=contest['contest_type'] + " " + contest['trace_type'],
                 turnpoints=xcsoar.encode(fixes, floor=1e5, method="double"),
                 times=xcsoar.encode(times, method="signed")))

    return contest_traces
Beispiel #3
0
def _encode_flight_path(fp, qnh):
    # Reduce to 1000 points maximum with equal spacing
    shortener = int(max(1, len(fp) / 1000))

    barogram_h = xcsoar.encode([
        pressure_alt_to_qnh_alt(fix.pressure_altitude, qnh)
        for fix in fp[::shortener]
    ],
                               method="signed")
    barogram_t = xcsoar.encode([fix.seconds_of_day for fix in fp[::shortener]],
                               method="signed")
    enl = xcsoar.encode(
        [fix.enl if fix.enl is not None else 0 for fix in fp[::shortener]],
        method="signed")
    elevations_h = xcsoar.encode([
        fix.elevation if fix.elevation is not None else -1000
        for fix in fp[::shortener]
    ],
                                 method="signed")

    return dict(barogram_h=barogram_h,
                barogram_t=barogram_t,
                enl=enl,
                elevations_h=elevations_h,
                igc_start_time=fp[0].datetime,
                igc_end_time=fp[-1].datetime)
Beispiel #4
0
def _get_contest_traces(flight):
    contests = [
        dict(contest_type="olc_plus", trace_type="triangle"),
        dict(contest_type="olc_plus", trace_type="classic"),
    ]

    contest_traces = []

    for contest in contests:
        contest_trace = flight.get_optimised_contest_trace(contest["contest_type"], contest["trace_type"])
        if not contest_trace:
            continue

        fixes = map(lambda x: (x.latitude, x.longitude), contest_trace.locations)
        times = []
        for time in contest_trace.times:
            times.append(
                flight.takeoff_time.hour * 3600
                + flight.takeoff_time.minute * 60
                + flight.takeoff_time.second
                + (time - flight.takeoff_time).days * 86400
                + (time - flight.takeoff_time).seconds
            )

        contest_traces.append(
            dict(
                name=contest["contest_type"] + " " + contest["trace_type"],
                turnpoints=xcsoar.encode(fixes, floor=1e5, method="double"),
                times=xcsoar.encode(times, method="signed"),
            )
        )

    return contest_traces
Beispiel #5
0
def _encode_flight_path(fp, qnh):
    # Reduce to 1000 points maximum with equal spacing
    shortener = int(max(1, len(fp) / 1000))

    barogram_h = xcsoar.encode(
        [
            pressure_alt_to_qnh_alt(fix.pressure_altitude, qnh)
            for fix in fp[::shortener]
        ],
        method="signed",
    )
    barogram_t = xcsoar.encode(
        [fix.seconds_of_day for fix in fp[::shortener]], method="signed"
    )
    enl = xcsoar.encode(
        [fix.enl if fix.enl is not None else 0 for fix in fp[::shortener]],
        method="signed",
    )
    elevations_h = xcsoar.encode(
        [
            fix.elevation if fix.elevation is not None else -1000
            for fix in fp[::shortener]
        ],
        method="signed",
    )

    return dict(
        barogram_h=barogram_h,
        barogram_t=barogram_t,
        enl=enl,
        elevations_h=elevations_h,
        igc_start_time=fp[0].datetime,
        igc_end_time=fp[-1].datetime,
    )
Beispiel #6
0
def _get_elevations(flight):
    elevations = get_elevations_for_flight(flight)

    # Encode lists
    elevations_t = xcsoar.encode([t for t, h in elevations], method="signed")
    elevations_h = xcsoar.encode([h for t, h in elevations], method="signed")

    return elevations_t, elevations_h
Beispiel #7
0
def _get_elevations(flight):
    elevations = get_elevations_for_flight(flight)

    # Encode lists
    elevations_t = xcsoar.encode([t for t, h in elevations], method="signed")
    elevations_h = xcsoar.encode([h for t, h in elevations], method="signed")

    return elevations_t, elevations_h
Beispiel #8
0
def _get_flight_path(flight):
    fp = flight_path(flight.igc_file, add_elevation=True)

    barogram_h = xcsoar.encode([fix.altitude for fix in fp], method="signed")
    barogram_t = xcsoar.encode([fix.seconds_of_day for fix in fp], method="signed")
    enl = xcsoar.encode([fix.enl if fix.enl is not None else 0 for fix in fp], method="signed")
    elevations_h = xcsoar.encode([fix.elevation if fix.elevation is not None else -1000 for fix in fp], method="signed")

    return dict(barogram_h=barogram_h, barogram_t=barogram_t,
                enl=enl, elevations_h=elevations_h,
                igc_start_time=fp[0].datetime, igc_end_time=fp[-1].datetime)
Beispiel #9
0
def _get_flight_path(pilot, threshold=0.001, last_update=None):
    fp = _get_flight_path2(pilot, last_update=last_update)
    if not fp:
        return None

    num_levels = 4
    zoom_factor = 4
    zoom_levels = [0]
    zoom_levels.extend([round(-log(32.0 / 45.0 * (threshold * pow(zoom_factor, num_levels - i - 1)), 2)) for i in range(1, num_levels)])

    xcsoar_flight = xcsoar.Flight(fp)

    xcsoar_flight.reduce(num_levels=num_levels,
                         zoom_factor=zoom_factor,
                         threshold=threshold)

    encoded_flight = xcsoar_flight.encode()

    points = encoded_flight['locations']
    barogram_t = encoded_flight['times']
    barogram_h = encoded_flight['altitude']
    enl = encoded_flight['enl']

    fp_reduced = map(lambda line: FlightPathFix(*line), xcsoar_flight.path())
    elevations = xcsoar.encode([fix.elevation if fix.elevation is not None else UNKNOWN_ELEVATION for fix in fp_reduced], method="signed")

    geoid_height = egm96_height(Location(latitude=fp[0].location['latitude'],
                                         longitude=fp[0].location['longitude']))

    return dict(points=points,
                barogram_t=barogram_t, barogram_h=barogram_h, enl=enl,
                elevations=elevations, geoid=geoid_height)
Beispiel #10
0
def _get_flight_path(pilot, threshold=0.001, last_update=None):
    fp = _get_flight_path2(pilot, last_update=last_update)
    if not fp:
        return None

    num_levels = 4
    zoom_factor = 4
    zoom_levels = [0]
    zoom_levels.extend([round(-log(32.0 / 45.0 * (threshold * pow(zoom_factor, num_levels - i - 1)), 2)) for i in range(1, num_levels)])

    xcsoar_flight = xcsoar.Flight(fp)

    xcsoar_flight.reduce(num_levels=num_levels,
                         zoom_factor=zoom_factor,
                         threshold=threshold)

    encoded_flight = xcsoar_flight.encode()

    encoded = dict(points=encoded_flight['locations'],
                   levels=encoded_flight['levels'],
                   zoom_levels=zoom_levels)

    barogram_t = encoded_flight['times']
    barogram_h = encoded_flight['altitude']
    enl = encoded_flight['enl']
    elevations = xcsoar.encode([fix.elevation if fix.elevation is not None else UNKNOWN_ELEVATION for fix in fp], method="signed")

    return dict(encoded=encoded, zoom_levels=zoom_levels, num_levels=num_levels,
                barogram_t=barogram_t, barogram_h=barogram_h, enl=enl,
                elevations=elevations)
Beispiel #11
0
def _get_flight_path(pilot, threshold=0.001, last_update=None):
    fp = _get_flight_path2(pilot, last_update=last_update)
    if not fp:
        return None

    num_levels = 4
    zoom_factor = 4
    zoom_levels = [0]
    zoom_levels.extend([
        round(-log(
            32.0 / 45.0 *
            (threshold * pow(zoom_factor, num_levels - i - 1)), 2))
        for i in range(1, num_levels)
    ])

    xcsoar_flight = xcsoar.Flight(fp)

    xcsoar_flight.reduce(num_levels=num_levels,
                         zoom_factor=zoom_factor,
                         threshold=threshold)

    encoded_flight = xcsoar_flight.encode()

    points = encoded_flight["locations"]
    barogram_t = encoded_flight["times"]
    barogram_h = encoded_flight["altitude"]
    enl = encoded_flight["enl"]

    fp_reduced = map(lambda line: FlightPathFix(*line), xcsoar_flight.path())
    elevations = xcsoar.encode(
        [
            fix.elevation if fix.elevation is not None else UNKNOWN_ELEVATION
            for fix in fp_reduced
        ],
        method="signed",
    )

    geoid_height = egm96_height(
        Location(latitude=fp[0].location["latitude"],
                 longitude=fp[0].location["longitude"]))

    return dict(
        points=points,
        barogram_t=barogram_t,
        barogram_h=barogram_h,
        enl=enl,
        elevations=elevations,
        geoid=geoid_height,
    )
Beispiel #12
0
def _get_flight_path(pilot, threshold=0.001, last_update=None):
    fp = _get_flight_path2(pilot, last_update=last_update)
    if not fp:
        return None

    num_levels = 4
    zoom_factor = 4
    zoom_levels = [0]
    zoom_levels.extend([
        round(-log(
            32.0 / 45.0 *
            (threshold * pow(zoom_factor, num_levels - i - 1)), 2))
        for i in range(1, num_levels)
    ])

    xcsoar_flight = xcsoar.Flight(fp)

    xcsoar_flight.reduce(num_levels=num_levels,
                         zoom_factor=zoom_factor,
                         threshold=threshold)

    encoded_flight = xcsoar_flight.encode()

    encoded = dict(points=encoded_flight['locations'],
                   levels=encoded_flight['levels'],
                   zoom_levels=zoom_levels)

    barogram_t = encoded_flight['times']
    barogram_h = encoded_flight['altitude']
    enl = encoded_flight['enl']

    fp_reduced = map(lambda line: FlightPathFix(*line), xcsoar_flight.path())
    elevations = xcsoar.encode([
        fix.elevation if fix.elevation is not None else UNKNOWN_ELEVATION
        for fix in fp_reduced
    ],
                               method="signed")

    return dict(encoded=encoded,
                zoom_levels=zoom_levels,
                num_levels=num_levels,
                barogram_t=barogram_t,
                barogram_h=barogram_h,
                enl=enl,
                elevations=elevations)
Beispiel #13
0
    print fix

  flight.reduce(takeoff['time'], landing['time'], max_points=10)

  print "Flight path from takeoff to landing, reduced:"
  fixes = flight.path(takeoff['time'], landing['time'])
  for fix in fixes:
    print fix

  flight_sequence = fixes

  analysis = flight.analyse(takeoff['time'], release['time'], landing['time'])
  pprint(analysis)

  fixes = flight.path(takeoff['time'], landing['time'])
  print xcsoar.encode([(row[2]['longitude'], row[2]['latitude']) for row in fixes], floor=10e5, method="double")

  pprint(flight.encode())

del flight


print
print "Init xcsoar.Flight with a python sequence"

flight = xcsoar.Flight([fix[0:5] for fix in flight_sequence])

for fix in flight.path():
  print fix

del flight
Beispiel #14
0
    fixes = flight.path(takeoff['time'], landing['time'])
    for fix in fixes:
        print(fix)

    flight_sequence = fixes

    analysis = flight.analyse(takeoff=takeoff['time'],
                              scoring_start=release['time'],
                              scoring_end=landing['time'],
                              landing=landing['time'])
    pprint(analysis)

    fixes = flight.path(takeoff['time'], landing['time'])
    print(
        xcsoar.encode([(row[2]['latitude'], row[2]['longitude'])
                       for row in fixes],
                      floor=10e5,
                      method="double"))

    pprint(flight.encode())

del flight

print()
print("Init xcsoar.Flight with a python sequence")

flight = xcsoar.Flight([fix[0:5] for fix in flight_sequence])


def assert_fixes_equal(fix1, fix2):
    assert fix1[1] == fix2[1]