def save_takeoff(event, flight): flight.takeoff_time = import_datetime_attribute(event, "time") flight.takeoff_location = read_location(event["location"]) if flight.takeoff_location is not None: flight.takeoff_airport = Airport.by_location(flight.takeoff_location, date=flight.takeoff_time) flight.date_local = get_takeoff_date(flight)
def get_nearest_airport(track): airport = Airport.by_location(track.location, None) if not airport: return None return dict(airport=airport_schema.dump(airport).data, distance=airport.distance(track.location))
def get_nearest_airport(): airport = Airport.by_location(track.location, None) if airport is None: return None, None distance = airport.distance(track.location) return airport, distance
def save_takeoff(event, flight): flight.takeoff_time = import_datetime_attribute(event, 'time') flight.takeoff_location = read_location(event) if flight.takeoff_location is not None: flight.takeoff_airport = Airport.by_location(flight.takeoff_location) flight.date_local = get_takeoff_date(flight)
def save_landing(event, flight): flight.landing_time = import_datetime_attribute(event, "time") flight.landing_location = read_location(event["location"]) if flight.landing_location is not None: flight.landing_airport = Airport.by_location( flight.landing_location, date=flight.landing_time )
def run(self, commit, welt2000_path): welt2000 = get_database(path=welt2000_path) self.current_date = datetime.utcnow() i = 0 for airport_w2k in welt2000: if (airport_w2k.type != 'airport' and airport_w2k.type != 'glider_site' and airport_w2k.type != 'ulm'): continue i += 1 if i % 100 == 0: db.session.flush() print str( i ) + ": " + airport_w2k.country_code + " " + airport_w2k.name # try to find this airport in the database near_airport = Airport.query() \ .filter(and_(Airport.short_name == airport_w2k.short_name, Airport.country_code == airport_w2k.country_code)) \ .filter(or_(Airport.valid_until == None, Airport.valid_until > self.current_date)) \ .first() # fall back to location-search if airport is not found # and only reuse this airport if it's within 250 meters of the old one... if near_airport is None or near_airport.distance( airport_w2k) > 250: near_airport = Airport.by_location(airport_w2k, distance_threshold=0.0025) if near_airport is None: # this airport is not in our database yet. add it... self.add_airport(airport_w2k) else: # seems to be the same airport. update with current values self.show_differences(near_airport, airport_w2k) self.update_airport(near_airport, airport_w2k) db.session.flush() # now invalidate all remaining airports invalid_airports = Airport.query() \ .filter(Airport.time_modified < self.current_date) \ .filter(or_(Airport.valid_until == None, Airport.valid_until > self.current_date)) for airport in invalid_airports: print "{} {} {}" \ .format(airport.country_code, airport.name, airport.icao) print " invalidated" airport.valid_until = self.current_date if commit: db.session.commit()
def save_takeoff(event, flight): flight.takeoff_time = import_datetime_attribute(event, "time") flight.takeoff_location = read_location(event["location"]) if flight.takeoff_location is not None: flight.takeoff_airport = Airport.by_location( flight.takeoff_location, date=flight.takeoff_time ) flight.date_local = get_takeoff_date(flight)
def run(self, commit, welt2000_path): welt2000 = get_database(path=welt2000_path) self.current_date = datetime.utcnow() i = 0 for airport_w2k in welt2000: if (airport_w2k.type != 'airport' and airport_w2k.type != 'glider_site' and airport_w2k.type != 'ulm'): continue i += 1 if i % 100 == 0: db.session.flush() print str(i) + ": " + airport_w2k.country_code + " " + airport_w2k.name # try to find this airport in the database near_airport = Airport.query() \ .filter(and_(Airport.short_name == airport_w2k.short_name, Airport.country_code == airport_w2k.country_code)) \ .filter(or_(Airport.valid_until == None, Airport.valid_until > self.current_date)) \ .first() # fall back to location-search if airport is not found # and only reuse this airport if it's within 250 meters of the old one... if near_airport is None or near_airport.distance(airport_w2k) > 250: near_airport = Airport.by_location(airport_w2k, distance_threshold=0.0025) if near_airport is None: # this airport is not in our database yet. add it... self.add_airport(airport_w2k) else: # seems to be the same airport. update with current values self.show_differences(near_airport, airport_w2k) self.update_airport(near_airport, airport_w2k) db.session.flush() # now invalidate all remaining airports invalid_airports = Airport.query() \ .filter(Airport.time_modified < self.current_date) \ .filter(or_(Airport.valid_until == None, Airport.valid_until > self.current_date)) for airport in invalid_airports: print "{} {} {}" \ .format(airport.country_code, airport.name, airport.icao) print " invalidated" airport.valid_until = self.current_date if commit: db.session.commit()
def get_nearest_airport(track): airport = Airport.by_location(track.location, None) if not airport: return None distance = airport.distance(track.location) return { 'name': airport.name, 'country_code': airport.country_code, 'distance': distance, }
def index(self, **kw): subq = DBSession.query(TrackingFix, over(func.rank(), partition_by=TrackingFix.pilot_id, order_by=desc(TrackingFix.time)).label('rank')) \ .outerjoin(TrackingFix.pilot) \ .filter(TrackingFix.time >= datetime.utcnow() - timedelta(hours=6)) \ .filter(TrackingFix.location_wkt != None) \ .subquery() query = DBSession.query(TrackingFix) \ .filter(TrackingFix.id == subq.c.id) \ .filter(subq.c.rank == 1) \ .order_by(desc(TrackingFix.time)) tracks = [] for track in query.all(): airport = Airport.by_location(track.location, None) distance = airport.distance(track.location) tracks.append([track, airport, distance]) return dict(tracks=tracks)
def save_landing(event, flight): flight.landing_time = import_datetime_attribute(event, 'time') flight.landing_location = read_location(event) if flight.landing_location is not None: flight.landing_airport = Airport.by_location(flight.landing_location)
i += 1 if i % 100 == 0: db.session.flush() print str(i) + ": " + airport_w2k.country_code + " " + airport_w2k.name # try to find this airport in the database near_airport = Airport.query() \ .filter(Airport.short_name == airport_w2k.short_name) \ .filter(or_(Airport.valid_until == None, Airport.valid_until > current_date)) \ .first() # fall back to location-search if airport is not found # and only reuse this airport if it's within 250 meters of the old one... if near_airport is None or near_airport.distance(airport_w2k) > 250: near_airport = Airport.by_location(airport_w2k, distance_threshold=0.0025) if near_airport is None: # this airport is not in our database yet. add it... add_airport(airport_w2k) else: # seems to be the same airport. update with current values show_differences(near_airport, airport_w2k) update_airport(near_airport, airport_w2k) db.session.flush() # now invalidate all remaining airports invalid_airports = Airport.query() \