def test_list_to_fix(): values = [ datetime(2016, 5, 4, 8, 10, 50), 29450, dict(latitude=50.82191666668235, longitude=6.181650000001908), 230, 48, None, None, 0, None, None, 8, None, 0, ] fix = FlightPathFix(*values) assert fix.datetime.isoformat() == "2016-05-04T08:10:50" assert fix.seconds_of_day == 29450 assert fix.location["latitude"] == approx(50.82191666668235) assert fix.location["longitude"] == approx(6.181650000001908) assert fix.gps_altitude == 230 assert fix.pressure_altitude == 48 assert fix.enl == None assert fix.track == None assert fix.groundspeed == 0 assert fix.tas == None assert fix.ias == None assert fix.siu == 8 assert fix.elevation == None
def _get_flight_path2(pilot, last_update=None): query = TrackingFix.query().filter( and_( TrackingFix.pilot == pilot, TrackingFix.location != None, TrackingFix.altitude != None, TrackingFix.max_age_filter(12), TrackingFix.time_visible <= datetime.utcnow(), )) query = query.order_by(TrackingFix.time) start_fix = query.first() if not start_fix: return None start_time = (start_fix.time.hour * 3600 + start_fix.time.minute * 60 + start_fix.time.second) if last_update: query = query.filter(TrackingFix.time >= start_fix.time + timedelta(seconds=(last_update - start_time))) result = [] for fix in query: location = fix.location if location is None: continue time_delta = fix.time - start_fix.time time = start_time + time_delta.days * 86400 + time_delta.seconds result.append( FlightPathFix( datetime=fix.time, seconds_of_day=time, location={ "latitude": location.latitude, "longitude": location.longitude, }, gps_altitude=fix.altitude, enl=fix.engine_noise_level, track=fix.track, groundspeed=fix.ground_speed, tas=fix.airspeed, elevation=fix.elevation, )) return result
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, )
def _get_flight_path2(pilot, last_update=None): query = TrackingFix.query() \ .filter(and_(TrackingFix.pilot == pilot, TrackingFix.location != None, TrackingFix.altitude != None, TrackingFix.max_age_filter(12))) if pilot.tracking_delay > 0 and not pilot.is_readable(g.current_user): query = query.filter(TrackingFix.delay_filter(pilot.tracking_delay)) query = query.order_by(TrackingFix.time) start_fix = query.first() if not start_fix: return None start_time = start_fix.time.hour * 3600 + start_fix.time.minute * 60 + start_fix.time.second if last_update: query = query.filter(TrackingFix.time >= start_fix.time + timedelta(seconds=(last_update - start_time))) result = [] for fix in query: location = fix.location if location is None: continue time_delta = fix.time - start_fix.time time = start_time + time_delta.days * 86400 + time_delta.seconds result.append( FlightPathFix(datetime=fix.time, seconds_of_day=time, location={ 'latitude': location.latitude, 'longitude': location.longitude }, gps_altitude=fix.altitude, enl=fix.engine_noise_level, track=fix.track, groundspeed=fix.ground_speed, tas=fix.airspeed, elevation=fix.elevation)) return result
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)
def test_kwargs(): fix = FlightPathFix(datetime=datetime(2016, 5, 4, 8, 10, 50), seconds_of_day=29450, location=dict(latitude=50.82191666668235, longitude=6.181650000001908), gps_altitude=230, pressure_altitude=48, groundspeed=0, siu=8) assert fix.datetime.isoformat() == '2016-05-04T08:10:50' assert fix.seconds_of_day == 29450 assert fix.location['latitude'] == approx(50.82191666668235) assert fix.location['longitude'] == approx(6.181650000001908) assert fix.gps_altitude == 230 assert fix.pressure_altitude == 48 assert fix.enl == None assert fix.track == None assert fix.groundspeed == 0 assert fix.tas == None assert fix.ias == None assert fix.siu == 8 assert fix.elevation == None