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_glider_type(line) if line.startswith('HFGID'): igc_headers['reg'] = parse_glider_reg(line) # don't read more than 100 lines, that should be enough i += 1 if i > 100: break return igc_headers
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((int(line[0]), float(line[1]), float(line[2]), int(line[3]), int(line[4]))) return path
def analyse_flight(flight): path = files.filename_to_path(flight.igc_file.filename) log.info('Analyzing ' + path) root = None with os.popen(helper_path('AnalyseFlight') + ' "' + path + '"') as f: try: root = simplejson.load(f) except simplejson.JSONDecodeError: log.error('Parsing the output of AnalyseFlight failed.') if log.isEnabledFor(logging.DEBUG): with os.popen(helper_path('AnalyseFlight') + ' "' + path + '"') as f_debug: log.debug(helper_path('AnalyseFlight') + ' "' + path + '" = ' + str(f_debug.readlines())) return False if not root: return False if 'events' in root: save_events(root['events'], flight) 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 = int(trace['score']) else: flight.olc_plus_score = None save_contests(root, flight) save_phases(root, flight) flight.needs_analysis = False return True