Beispiel #1
0
    def update_igc_headers(self):
        path = files.filename_to_path(self.filename)
        igc_headers = read_igc_headers(path)
        if igc_headers is None:
            return

        if "manufacturer_id" in igc_headers:
            self.logger_manufacturer_id = igc_headers["manufacturer_id"]

        if "logger_id" in igc_headers:
            self.logger_id = igc_headers["logger_id"]

        if "date_utc" in igc_headers:
            self.date_utc = igc_headers["date_utc"]

        if "model" in igc_headers and (igc_headers["model"] is None
                                       or 0 < len(igc_headers["model"]) < 64):
            self.model = igc_headers["model"]

        if "reg" in igc_headers and (igc_headers["reg"] is None
                                     or 0 < len(igc_headers["reg"]) < 32):
            self.registration = igc_headers["reg"]

        if "cid" in igc_headers and (igc_headers["cid"] is None
                                     or 0 < len(igc_headers["cid"]) < 5):
            self.competition_id = igc_headers["cid"]
Beispiel #2
0
    def update_igc_headers(self):
        path = files.filename_to_path(self.filename)
        igc_headers = read_igc_headers(path)
        condor_fpl, landscape = read_condor_fpl(path)
        if igc_headers is None:
            return

        if len(condor_fpl) > 0:
            self.is_condor_file = True
            self.landscape = landscape
            self.flight_plan_md5 = file_md5(
                StringIO.StringIO('\n'.join(condor_fpl)))

        if "manufacturer_id" in igc_headers:
            self.logger_manufacturer_id = igc_headers["manufacturer_id"]

        if "logger_id" in igc_headers:
            self.logger_id = igc_headers["logger_id"]

        if "date_utc" in igc_headers:
            self.date_utc = igc_headers["date_utc"]

        if "model" in igc_headers and (igc_headers["model"] is None
                                       or 0 < len(igc_headers["model"]) < 64):
            self.model = igc_headers["model"]

        if "reg" in igc_headers and (igc_headers["reg"] is None
                                     or 0 < len(igc_headers["reg"]) < 32):
            self.registration = igc_headers["reg"]

        if "cid" in igc_headers and (igc_headers["cid"] is None
                                     or 0 < len(igc_headers["cid"]) < 5):
            self.competition_id = igc_headers["cid"]
Beispiel #3
0
def read_igc_headers(filename):
    path = files.filename_to_path(filename)

    try:
        f = file(path, 'r')
    except IOError:
        return dict()

    igc_headers = dict()

    i = 0
    for line in f:
        if line[0] == 'A' and len(line) >= 4:
            igc_headers['manufacturer_id'] = line[1:4]

            if len(line) >= 7:
                igc_headers['logger_id'] = parse_logger_id(line)

        if line.startswith('HFGTY'):
            igc_headers['model'] = parse_pattern(hfgty_re, line)

        if line.startswith('HFGID'):
            igc_headers['reg'] = parse_pattern(hfgid_re, line)

        if line.startswith('HFCID'):
            igc_headers['cid'] = parse_pattern(hfcid_re, line)

        # don't read more than 100 lines, that should be enough
        i += 1
        if i > 100:
            break

    return igc_headers
Beispiel #4
0
    def update_igc_headers(self):
        path = files.filename_to_path(self.filename)
        igc_headers = read_igc_headers(path)
        if igc_headers is None:
            return

        if "manufacturer_id" in igc_headers:
            self.logger_manufacturer_id = igc_headers["manufacturer_id"]

        if "logger_id" in igc_headers:
            self.logger_id = igc_headers["logger_id"]

        if "date_utc" in igc_headers:
            self.date_utc = igc_headers["date_utc"]

        if "model" in igc_headers and (
            igc_headers["model"] is None or 0 < len(igc_headers["model"]) < 64
        ):
            self.model = igc_headers["model"]

        if "reg" in igc_headers and (
            igc_headers["reg"] is None or 0 < len(igc_headers["reg"]) < 32
        ):
            self.registration = igc_headers["reg"]

        if "cid" in igc_headers and (
            igc_headers["cid"] is None or 0 < len(igc_headers["cid"]) < 5
        ):
            self.competition_id = igc_headers["cid"]
Beispiel #5
0
    def update_igc_headers(self):
        path = files.filename_to_path(self.filename)
        igc_headers = read_igc_headers(path)
        if igc_headers is None:
            return

        if 'manufacturer_id' in igc_headers:
            self.logger_manufacturer_id = igc_headers['manufacturer_id']

        if 'logger_id' in igc_headers:
            self.logger_id = igc_headers['logger_id']

        if 'date_utc' in igc_headers:
            self.date_utc = igc_headers['date_utc']

        if 'model' in igc_headers and (igc_headers['model'] is None
                                       or 0 < len(igc_headers['model']) < 64):
            self.model = igc_headers['model']

        if 'reg' in igc_headers and (igc_headers['reg'] is None
                                     or 0 < len(igc_headers['reg']) < 32):
            self.registration = igc_headers['reg']

        if 'cid' in igc_headers and (igc_headers['cid'] is None
                                     or 0 < len(igc_headers['cid']) < 5):
            self.competition_id = igc_headers['cid']
Beispiel #6
0
def flight_path(igc_file, max_points=1000):
    args = [
        helper_path('FlightPath'),
        '--max-points=' + str(max_points),
        files.filename_to_path(igc_file.filename),
    ]

    return map(line_to_fix, Popen(args, stdout=PIPE).stdout)
Beispiel #7
0
def flight_path(igc_file, max_points = 1000):
    path = files.filename_to_path(igc_file.filename)
    f = os.popen(helper_path('FlightPath') + ' --max-points=' + str(max_points) + ' "' + path + '"')

    path = []
    for line in f:
        line = line.split()
        path.append(FlightPathFix(int(line[0]), float(line[1]), float(line[2]), int(line[3]), int(line[4])))
    return path
Beispiel #8
0
def _get_flight_path(flight, threshold=0.001, max_points=3000):
    num_levels = 4
    zoom_factor = 4
    zoom_levels = [0]
    zoom_levels.extend([
        round(-math.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(
        files.filename_to_path(flight.igc_file.filename))

    if flight.qnh:
        xcsoar_flight.setQNH(flight.qnh)

    begin = flight.takeoff_time - timedelta(seconds=2 * 60)
    end = flight.landing_time + timedelta(seconds=2 * 60)

    if begin > end:
        begin = datetime.min
        end = datetime.max

    xcsoar_flight.reduce(
        begin=begin,
        end=end,
        num_levels=num_levels,
        zoom_factor=zoom_factor,
        threshold=threshold,
        max_points=max_points,
    )

    encoded_flight = xcsoar_flight.encode()

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

    elevations_t, elevations_h = _get_elevations(flight)
    contest_traces = _get_contest_traces(flight)

    geoid_height = (egm96_height(flight.takeoff_location)
                    if flight.takeoff_location else 0)

    return dict(
        points=points,
        barogram_t=barogram_t,
        barogram_h=barogram_h,
        enl=enl,
        contests=contest_traces,
        elevations_t=elevations_t,
        elevations_h=elevations_h,
        sfid=flight.id,
        geoid=geoid_height,
    )
Beispiel #9
0
def test_user_delete_deletes_owned_igc_files(db_session):
    with open(igcs.simple_path, 'r') as f:
        filename = files.add_file('simple.igc', f)

    assert filename is not None
    assert os.path.isfile(files.filename_to_path(filename))

    john = users.john()
    igc = igcs.simple(owner=john, filename=filename)
    db_session.add(igc)
    db_session.commit()

    assert db_session.query(IGCFile).count() == 1
    assert db_session.query(IGCFile).get(igc.id).owner_id == john.id

    john.delete()
    db_session.commit()

    assert db_session.query(IGCFile).count() == 0
    assert not os.path.isfile(files.filename_to_path(filename))
Beispiel #10
0
def test_user_delete_deletes_owned_igc_files(db_session):
    with open(igcs.simple_path, "r") as f:
        filename = files.add_file("simple.igc", f)

    assert filename is not None
    assert os.path.isfile(files.filename_to_path(filename))

    john = users.john()
    igc = igcs.simple(owner=john, filename=filename)
    db_session.add(igc)
    db_session.commit()

    assert db_session.query(IGCFile).count() == 1
    assert db_session.query(IGCFile).get(igc.id).owner_id == john.id

    john.delete()
    db_session.commit()

    assert db_session.query(IGCFile).count() == 0
    assert not os.path.isfile(files.filename_to_path(filename))
Beispiel #11
0
def analyse_flight(flight, full=512, triangle=1024, sprint=64):
    path = files.filename_to_path(flight.igc_file.filename)
    log.info('Analyzing ' + path)

    try:
        root = xcsoar.analyse_flight(
            path, full_points=full, triangle_points=triangle,
            sprint_points=sprint, popen_kwargs=dict(preexec_fn=setlimits))
    except Exception, e:
        log.warning('Parsing the output of AnalyseFlight failed. (' + str(e) + ')')
        return False
Beispiel #12
0
def _get_flight_path(flight, threshold=0.001, max_points=3000):
    num_levels = 4
    zoom_factor = 4
    zoom_levels = [0]
    zoom_levels.extend([
        round(-math.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(
        files.filename_to_path(flight.igc_file.filename))

    begin = flight.takeoff_time - timedelta(seconds=2 * 60)
    end = flight.landing_time + timedelta(seconds=2 * 60)

    if begin > end:
        begin = datetime.min
        end = datetime.max

    xcsoar_flight.reduce(begin=begin,
                         end=end,
                         num_levels=num_levels,
                         zoom_factor=zoom_factor,
                         threshold=threshold,
                         max_points=max_points)

    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_t, elevations_h = _get_elevations(flight)
    contest_traces = _get_contest_traces(flight)

    return dict(encoded=encoded,
                zoom_levels=zoom_levels,
                num_levels=num_levels,
                barogram_t=barogram_t,
                barogram_h=barogram_h,
                enl=enl,
                contests=contest_traces,
                elevations_t=elevations_t,
                elevations_h=elevations_h,
                sfid=flight.id)
Beispiel #13
0
def analyse_flight(flight, full=512, triangle=1024, sprint=64, fp=None):
    path = files.filename_to_path(flight.igc_file.filename)
    current_app.logger.info('Analyzing ' + path)

    root, fp = run_analyse_flight(flight,
                                  full=full,
                                  triangle=triangle,
                                  sprint=sprint,
                                  fp=fp)

    if root is None:
        current_app.logger.warning('Analyze flight failed.')
        return False

    if 'qnh' in root and root['qnh'] is not None:
        flight.qnh = root['qnh']

    if 'events' in root:
        save_events(root['events'], flight)

    if flight.takeoff_time is None \
       or flight.landing_time is None:
        return False

    contest = find_contest(root, 'olc_plus')
    if contest is not None:
        trace = find_trace(contest, 'classic')
        if trace is not None and 'distance' in trace:
            flight.olc_classic_distance = int(trace['distance'])
        else:
            flight.olc_classic_distance = None

        trace = find_trace(contest, 'triangle')
        if trace is not None and 'distance' in trace:
            flight.olc_triangle_distance = int(trace['distance'])
        else:
            flight.olc_triangle_distance = None

        trace = find_trace(contest, 'plus')
        if trace is not None and 'score' in trace:
            flight.olc_plus_score = trace['score']
        else:
            flight.olc_plus_score = None

    save_contests(root, flight)
    save_phases(root, flight)

    calculate_leg_statistics(flight, fp)

    flight.needs_analysis = False
    return True
Beispiel #14
0
def _get_flight_path(flight, threshold=0.001, max_points=3000):
    num_levels = 4
    zoom_factor = 4
    zoom_levels = [0]
    zoom_levels.extend(
        [
            round(-math.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(files.filename_to_path(flight.igc_file.filename))

    if flight.qnh:
        xcsoar_flight.setQNH(flight.qnh)

    begin = flight.takeoff_time - timedelta(seconds=2 * 60)
    end = flight.landing_time + timedelta(seconds=2 * 60)

    if begin > end:
        begin = datetime.min
        end = datetime.max

    xcsoar_flight.reduce(
        begin=begin, end=end, num_levels=num_levels, zoom_factor=zoom_factor, threshold=threshold, max_points=max_points
    )

    encoded_flight = xcsoar_flight.encode()

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

    elevations_t, elevations_h = _get_elevations(flight)
    contest_traces = _get_contest_traces(flight)

    geoid_height = egm96_height(flight.takeoff_location) if flight.takeoff_location else 0

    return dict(
        points=points,
        barogram_t=barogram_t,
        barogram_h=barogram_h,
        enl=enl,
        contests=contest_traces,
        elevations_t=elevations_t,
        elevations_h=elevations_h,
        sfid=flight.id,
        geoid=geoid_height,
    )
Beispiel #15
0
def analyse_flight(flight, full=512, triangle=1024, sprint=64, fp=None):
    path = files.filename_to_path(flight.igc_file.filename)
    current_app.logger.info("Analyzing " + path)

    root, fp = run_analyse_flight(flight,
                                  full=full,
                                  triangle=triangle,
                                  sprint=sprint,
                                  fp=fp)

    if root is None:
        current_app.logger.warning("Analyze flight failed.")
        return False

    if "qnh" in root and root["qnh"] is not None:
        flight.qnh = root["qnh"]

    if "events" in root:
        save_events(root["events"], flight)

    if flight.takeoff_time is None or flight.landing_time is None:
        return False

    contest = find_contest(root, "olc_plus")
    if contest is not None:
        trace = find_trace(contest, "classic")
        if trace is not None and "distance" in trace:
            flight.olc_classic_distance = int(trace["distance"])
        else:
            flight.olc_classic_distance = None

        trace = find_trace(contest, "triangle")
        if trace is not None and "distance" in trace:
            flight.olc_triangle_distance = int(trace["distance"])
        else:
            flight.olc_triangle_distance = None

        trace = find_trace(contest, "plus")
        if trace is not None and "score" in trace:
            flight.olc_plus_score = trace["score"]
        else:
            flight.olc_plus_score = None

    save_contests(root, flight)
    save_phases(root, flight)

    calculate_leg_statistics(flight, fp)

    flight.needs_analysis = False
    return True
Beispiel #16
0
def flight_path(igc_file, max_points=1000, add_elevation=False, qnh=None):
    if isinstance(igc_file, IGCFile):
        path = files.filename_to_path(igc_file.filename)
    elif is_string(igc_file):
        path = igc_file
    else:
        return None

    output = run_flight_path(path, max_points=max_points, qnh=qnh)

    if add_elevation and len(output):
        output = get_elevation(output)

    return list(FlightPathFix(*line) for line in output)
Beispiel #17
0
def flight_path(igc_file, max_points=1000, add_elevation=False, qnh=None):
    if isinstance(igc_file, IGCFile):
        path = files.filename_to_path(igc_file.filename)
    elif isinstance(igc_file, (str, unicode)):
        path = igc_file
    else:
        return None

    output = run_flight_path(path, max_points=max_points, qnh=qnh)

    if add_elevation and len(output):
        output = get_elevation(output)

    return map(lambda line: FlightPathFix(*line), output)
Beispiel #18
0
def flight_path(igc_file, max_points=1000, add_elevation=False, qnh=None):
    if isinstance(igc_file, IGCFile):
        path = files.filename_to_path(igc_file.filename)
    elif is_string(igc_file):
        path = igc_file
    else:
        return None

    output = run_flight_path(path, max_points=max_points, qnh=qnh)

    if add_elevation and len(output):
        output = get_elevation(output)

    return list(FlightPathFix(*line) for line in output)
Beispiel #19
0
def flight_path(igc_file, max_points=1000, add_elevation=False, qnh=None):
    if isinstance(igc_file, IGCFile):
        path = files.filename_to_path(igc_file.filename)
    elif isinstance(igc_file, (str, unicode)):
        path = igc_file
    else:
        return None

    output = run_flight_path(path, max_points=max_points, qnh=qnh)

    if add_elevation and len(output):
        output = get_elevation(output)

    return map(lambda line: FlightPathFix(*line), output)
Beispiel #20
0
def analyse_flight(flight, full=512, triangle=1024, sprint=64, fp=None):
    path = files.filename_to_path(flight.igc_file.filename)
    current_app.logger.info('Analyzing ' + path)

    root, fp = run_analyse_flight(
        flight, full=full, triangle=triangle, sprint=sprint,
        fp=fp)

    if root is None:
        current_app.logger.warning('Analyze flight failed.')
        return False

    if 'qnh' in root and root['qnh'] is not None:
        flight.qnh = root['qnh']

    if 'events' in root:
        save_events(root['events'], flight)

    if flight.takeoff_time is None \
       or flight.landing_time is None:
        return False

    contest = find_contest(root, 'olc_plus')
    if contest is not None:
        trace = find_trace(contest, 'classic')
        if trace is not None and 'distance' in trace:
            flight.olc_classic_distance = int(trace['distance'])
        else:
            flight.olc_classic_distance = None

        trace = find_trace(contest, 'triangle')
        if trace is not None and 'distance' in trace:
            flight.olc_triangle_distance = int(trace['distance'])
        else:
            flight.olc_triangle_distance = None

        trace = find_trace(contest, 'plus')
        if trace is not None and 'score' in trace:
            flight.olc_plus_score = trace['score']
        else:
            flight.olc_plus_score = None

    save_contests(root, flight)
    save_phases(root, flight)

    calculate_leg_statistics(flight, fp)

    flight.needs_analysis = False
    return True
Beispiel #21
0
def run_analyse_flight(flight, full=None, triangle=None, sprint=None):
    limits = get_limits()

    filename = files.filename_to_path(flight.igc_file.filename)
    xcsoar_flight = xcsoar.Flight(
        flight_path(filename, add_elevation=True, max_points=None))

    analysis_times = get_analysis_times(xcsoar_flight.times())

    if flight.takeoff_time:
        analysis_times['takeoff']['time'] = flight.takeoff_time
        analysis_times['takeoff']['location'][
            'latitude'] = flight.takeoff_location.latitude
        analysis_times['takeoff']['location'][
            'longitude'] = flight.takeoff_location.longitude

    if flight.scoring_start_time:
        analysis_times['scoring_start']['time'] = flight.scoring_start_time

    if flight.scoring_end_time:
        analysis_times['scoring_end']['time'] = flight.scoring_end_time

    if flight.landing_time:
        analysis_times['landing']['time'] = flight.landing_time
        analysis_times['landing']['location'][
            'latitude'] = flight.landing_location.latitude
        analysis_times['landing']['location'][
            'longitude'] = flight.landing_location.longitude

    if analysis_times:
        analysis = xcsoar_flight.analyse(
            analysis_times['takeoff']['time'],
            analysis_times['scoring_start']['time']
            if analysis_times['scoring_start'] else None,
            analysis_times['scoring_end']['time']
            if analysis_times['scoring_end'] else None,
            analysis_times['landing']['time'],
            full=full,
            triangle=triangle,
            sprint=sprint,
            max_iterations=limits['iter_limit'],
            max_tree_size=limits['tree_size_limit'])
        analysis['events'] = analysis_times

        return analysis

    else:
        return None
Beispiel #22
0
def analyse_flight(flight, full=512, triangle=1024, sprint=64, fp=None):
    path = files.filename_to_path(flight.igc_file.filename)
    current_app.logger.info("Analyzing " + path)

    root, fp = run_analyse_flight(
        flight, full=full, triangle=triangle, sprint=sprint, fp=fp
    )

    if root is None:
        current_app.logger.warning("Analyze flight failed.")
        return False

    if "qnh" in root and root["qnh"] is not None:
        flight.qnh = root["qnh"]

    if "events" in root:
        save_events(root["events"], flight)

    if flight.takeoff_time is None or flight.landing_time is None:
        return False

    contest = find_contest(root, "olc_plus")
    if contest is not None:
        trace = find_trace(contest, "classic")
        if trace is not None and "distance" in trace:
            flight.olc_classic_distance = int(trace["distance"])
        else:
            flight.olc_classic_distance = None

        trace = find_trace(contest, "triangle")
        if trace is not None and "distance" in trace:
            flight.olc_triangle_distance = int(trace["distance"])
        else:
            flight.olc_triangle_distance = None

        trace = find_trace(contest, "plus")
        if trace is not None and "score" in trace:
            flight.olc_plus_score = trace["score"]
        else:
            flight.olc_plus_score = None

    save_contests(root, flight)
    save_phases(root, flight)

    calculate_leg_statistics(flight, fp)

    flight.needs_analysis = False
    return True
Beispiel #23
0
def test_data(db_session):
    # create test user
    john = users.john()
    db_session.add(john)

    # create IGC file
    igc_file = igcs.simple(john)
    igc_file.weglide_status = 1
    db_session.add(igc_file)

    path = files.filename_to_path(igc_file.filename)
    copyfile(igcs.simple_path, path)

    db_session.flush()

    return (john, igc_file)
Beispiel #24
0
def run_analyse_flight(flight, full=None, triangle=None, sprint=None):
    limits = get_limits()

    filename = files.filename_to_path(flight.igc_file.filename)
    xcsoar_flight = xcsoar.Flight(flight_path(filename, add_elevation=True, max_points=None))

    analysis_times = get_analysis_times(xcsoar_flight.times())

    if flight.takeoff_time:
        analysis_times['takeoff']['time'] = flight.takeoff_time
        analysis_times['takeoff']['location']['latitude'] = flight.takeoff_location.latitude
        analysis_times['takeoff']['location']['longitude'] = flight.takeoff_location.longitude

    if flight.scoring_start_time:
        analysis_times['scoring_start']['time'] = flight.scoring_start_time

    if flight.scoring_end_time:
        analysis_times['scoring_end']['time'] = flight.scoring_end_time

    if flight.landing_time:
        analysis_times['landing']['time'] = flight.landing_time
        analysis_times['landing']['location']['latitude'] = flight.landing_location.latitude
        analysis_times['landing']['location']['longitude'] = flight.landing_location.longitude

    if analysis_times:
        analysis = xcsoar_flight.analyse(analysis_times['takeoff']['time'],
                                         analysis_times['scoring_start']['time']
                                         if analysis_times['scoring_start'] else None,
                                         analysis_times['scoring_end']['time']
                                         if analysis_times['scoring_end'] else None,
                                         analysis_times['landing']['time'],
                                         full=full,
                                         triangle=triangle,
                                         sprint=sprint,
                                         max_iterations=limits['iter_limit'],
                                         max_tree_size=limits['tree_size_limit'])
        analysis['events'] = analysis_times

        return analysis

    else:
        return None
Beispiel #25
0
def _get_flight_path(flight, threshold=0.001, max_points=3000):
    num_levels = 4
    zoom_factor = 4
    zoom_levels = [0]
    zoom_levels.extend([round(-math.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(files.filename_to_path(flight.igc_file.filename))

    begin = flight.takeoff_time - timedelta(seconds=2 * 60)
    end = flight.landing_time + timedelta(seconds=2 * 60)

    if begin > end:
        begin = datetime.min
        end = datetime.max

    xcsoar_flight.reduce(begin=begin,
                         end=end,
                         num_levels=num_levels,
                         zoom_factor=zoom_factor,
                         threshold=threshold,
                         max_points=max_points)

    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_t, elevations_h = _get_elevations(flight)
    contest_traces = _get_contest_traces(flight)

    return dict(encoded=encoded, zoom_levels=zoom_levels, num_levels=num_levels,
                barogram_t=barogram_t, barogram_h=barogram_h,
                enl=enl, contests=contest_traces,
                elevations_t=elevations_t, elevations_h=elevations_h,
                sfid=flight.id)
Beispiel #26
0
    def update_igc_headers(self):
        path = files.filename_to_path(self.filename)
        igc_headers = read_igc_headers(path)
        if igc_headers is None:
            return

        if 'manufacturer_id' in igc_headers:
            self.logger_manufacturer_id = igc_headers['manufacturer_id']

        if 'logger_id' in igc_headers:
            self.logger_id = igc_headers['logger_id']

        if 'date_utc' in igc_headers:
            self.date_utc = igc_headers['date_utc']

        if 'model' in igc_headers and 0 < len(igc_headers['model']) < 64:
            self.model = igc_headers['model']

        if 'reg' in igc_headers and 0 < len(igc_headers['reg']) < 32:
            self.registration = igc_headers['reg']

        if 'cid' in igc_headers and 0 < len(igc_headers['cid']) < 5:
            self.competition_id = igc_headers['cid']
Beispiel #27
0
def run_analyse_flight(flight,
                       full=None, triangle=None, sprint=None,
                       fp=None):
    limits = get_limits()

    if not fp:
        filename = files.filename_to_path(flight.igc_file.filename)
        fp = flight_path(filename, add_elevation=True, max_points=None)

    if len(fp) < 2:
        return None, None

    xcsoar_flight = xcsoar.Flight(fp)

    analysis_times = get_analysis_times(xcsoar_flight.times())

    # Fallback if automated flight detection has failed - check if first and last
    # fix could be ok and use both of them for takeoff and landing
    if not analysis_times and fp[0].datetime < fp[-1].datetime:
        analysis_times = dict(takeoff=dict(time=fp[0].datetime,
                                           location=fp[0].location),
                              scoring_start=None,
                              scoring_end=None,
                              landing=dict(time=fp[-1].datetime,
                                           location=fp[-1].location))

    # Give priority to already stored takeoff and landing times
    if flight.takeoff_time and flight.takeoff_location:
        analysis_times['takeoff']['time'] = flight.takeoff_time
        analysis_times['takeoff']['location'] = dict(latitude=flight.takeoff_location.latitude,
                                                     longitude=flight.takeoff_location.longitude)

    if flight.landing_time and flight.landing_location:
        analysis_times['landing']['time'] = flight.landing_time
        analysis_times['landing']['location'] = dict(latitude=flight.landing_location.latitude,
                                                     longitude=flight.landing_location.longitude)

    # If no scoring window was found fallback to takeoff - landing
    if not analysis_times['scoring_start']:
        analysis_times['scoring_start'] = analysis_times['takeoff'].copy()

    if not analysis_times['scoring_end']:
        analysis_times['scoring_end'] = analysis_times['landing'].copy()

    # And give priority to already stored scoring times
    if flight.scoring_start_time:
        analysis_times['scoring_start']['time'] = flight.scoring_start_time

    if flight.scoring_end_time:
        analysis_times['scoring_end']['time'] = flight.scoring_end_time

    if analysis_times:
        analysis = xcsoar_flight.analyse(analysis_times['takeoff']['time'] - datetime.timedelta(seconds=300),
                                         analysis_times['scoring_start']['time'],
                                         analysis_times['scoring_end']['time'],
                                         analysis_times['landing']['time'] + datetime.timedelta(seconds=300),
                                         full=full,
                                         triangle=triangle,
                                         sprint=sprint,
                                         max_iterations=limits['iter_limit'],
                                         max_tree_size=limits['tree_size_limit'])
        analysis['events'] = analysis_times

        return analysis, fp

    else:
        return None, None
Beispiel #28
0
def run_analyse_flight(flight, full=None, triangle=None, sprint=None, fp=None):
    limits = get_limits()

    if not fp:
        filename = files.filename_to_path(flight.igc_file.filename)
        fp = flight_path(filename, add_elevation=True, max_points=None)

    if len(fp) < 2:
        return None, None

    xcsoar_flight = xcsoar.Flight(fp)

    analysis_times = get_analysis_times(xcsoar_flight.times())

    # Fallback if automated flight detection has failed - check if first and last
    # fix could be ok and use both of them for takeoff and landing
    if not analysis_times and fp[0].datetime < fp[-1].datetime:
        analysis_times = dict(
            takeoff=dict(time=fp[0].datetime, location=fp[0].location),
            scoring_start=None,
            scoring_end=None,
            landing=dict(time=fp[-1].datetime, location=fp[-1].location),
        )

    # Give priority to already stored takeoff and landing times
    if flight.takeoff_time and flight.takeoff_location:
        analysis_times["takeoff"]["time"] = flight.takeoff_time
        analysis_times["takeoff"]["location"] = dict(
            latitude=flight.takeoff_location.latitude, longitude=flight.takeoff_location.longitude
        )

    if flight.landing_time and flight.landing_location:
        analysis_times["landing"]["time"] = flight.landing_time
        analysis_times["landing"]["location"] = dict(
            latitude=flight.landing_location.latitude, longitude=flight.landing_location.longitude
        )

    # If no scoring window was found fallback to takeoff - landing
    if not analysis_times["scoring_start"]:
        analysis_times["scoring_start"] = analysis_times["takeoff"].copy()

    if not analysis_times["scoring_end"]:
        analysis_times["scoring_end"] = analysis_times["landing"].copy()

    # And give priority to already stored scoring times
    if flight.scoring_start_time:
        analysis_times["scoring_start"]["time"] = flight.scoring_start_time

    if flight.scoring_end_time:
        analysis_times["scoring_end"]["time"] = flight.scoring_end_time

    if analysis_times:
        analysis = xcsoar_flight.analyse(
            analysis_times["takeoff"]["time"] - datetime.timedelta(seconds=300),
            analysis_times["scoring_start"]["time"],
            analysis_times["scoring_end"]["time"],
            analysis_times["landing"]["time"] + datetime.timedelta(seconds=300),
            full=full,
            triangle=triangle,
            sprint=sprint,
            max_iterations=limits["iter_limit"],
            max_tree_size=limits["tree_size_limit"],
        )
        analysis["events"] = analysis_times

        return analysis, fp

    else:
        return None, None
def flight_path(igc_file, max_points=1000):
    path = files.filename_to_path(igc_file.filename)
    return list(xcsoar.flight_path(path, max_points=max_points))