Exemple #1
0
    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()
Exemple #2
0
    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()
Exemple #3
0
def get_airport(id):
    airport = Airport.get(id)
    if not airport:
        raise KeyError("The requested airport was not found.")

    data, errors = airport_schema.dump(airport)
    return data
Exemple #4
0
def airport(id):
    airport = Airport.get(id)
    if not airport:
        abort(404)

    airport = airport_to_json(airport, short=False)
    return jsonify(airport)
Exemple #5
0
    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))
Exemple #6
0
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
        )
Exemple #7
0
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)
Exemple #8
0
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)
Exemple #9
0
            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
Exemple #10
0
def get_airport(id):
    airport = Airport.get(id)
    if not airport:
        raise KeyError('The requested airport was not found.')

    data, errors = airport_schema.dump(airport)
    return data
Exemple #11
0
    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))
Exemple #12
0
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_airports_by_bbox(bbox):
    if not isinstance(bbox, Bounds):
        raise TypeError('Invalid `bbox` parameter.')

    bbox.normalize()
    if bbox.get_size() > 20 * 20:
        raise ValueError('Requested `bbox` is too large.')

    return map(airport_to_dict, Airport.by_bbox(bbox))
Exemple #14
0
def get_airports_by_bbox(bbox):
    if not isinstance(bbox, Bounds):
        raise TypeError('Invalid `bbox` parameter.')

    bbox.normalize()
    if bbox.get_size() > 20 * 20:
        raise ValueError('Requested `bbox` is too large.')

    return map(airport_to_dict, Airport.by_bbox(bbox))
Exemple #15
0
def get_airports_by_bbox(bbox):
    if not isinstance(bbox, Bounds):
        raise TypeError("Invalid `bbox` parameter.")

    bbox.normalize()
    if bbox.get_size() > 20 * 20:
        raise ValueError("Requested `bbox` is too large.")

    data, errors = airport_list_schema.dump(Airport.by_bbox(bbox), many=True)
    return data
Exemple #16
0
def get_airports_by_bbox(bbox):
    if not isinstance(bbox, Bounds):
        raise TypeError('Invalid `bbox` parameter.')

    bbox.normalize()
    if bbox.get_size() > 20 * 20:
        raise ValueError('Requested `bbox` is too large.')

    data, errors = airport_list_schema.dump(Airport.by_bbox(bbox), many=True)
    return data
Exemple #17
0
def airports():
    bbox = request.args.get('bbox', type=Bounds.from_bbox_string)
    if not bbox:
        raise BadRequest('Invalid `bbox` parameter.')

    bbox.normalize()
    if bbox.get_size() > 20 * 20:
        raise BadRequest('Requested `bbox` is too large.')

    airports = map(airport_to_json, Airport.by_bbox(bbox))
    return jsonify(airports=airports)
Exemple #18
0
    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,
        }
Exemple #19
0
    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,
        }
Exemple #20
0
def merzbrueck(**kwargs):
    return Airport(
        name="Aachen Merzbruck",
        icao="EDKA",
        country_code="DE",
        altitude=189,
        location_wkt=from_shape(Point(6.186389, 50.823056), srid=4326),
        frequency=122.875,
        runway_len=520,
        runway_dir=80,
        surface="asphalt",
        type="airport",
    ).apply_kwargs(kwargs)
Exemple #21
0
def test_airport():
    return Airport(
        name='Aachen Merzbruck',
        icao='EDKA',
        country_code='DE',
        altitude=189,
        location_wkt=from_shape(Point(6.186389, 50.823056), srid=4326),
        frequency=122.875,
        runway_len=520,
        runway_dir=80,
        surface='asphalt',
        type='airport',
    )
Exemple #22
0
def fixtures(db_session):
    data = {
        'john':
        User(first_name=u'John', last_name=u'Doe', password='******'),
        'jane':
        User(first_name=u'Jane', last_name=u'Doe', password='******'),
        'lva':
        Club(name=u'LV Aachen', website='https://www.lv-aachen.de'),
        'sfn':
        Club(name=u'Sportflug Niederberg'),
        'edka':
        Airport(name=u'Aachen-Merzbrück',
                country_code='DE',
                icao='EDKA',
                frequency='122.875'),
        'mbg':
        Airport(name=u'Meiersberg', country_code='DE'),
    }

    for v in data.itervalues():
        db_session.add(v)

    db_session.commit()
    return data
Exemple #23
0
    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)
Exemple #24
0
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)
Exemple #25
0
welt2000 = get_database(path=args.welt2000_path)

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

    airport = Airport()
    airport.location = airport_w2k
    airport.altitude = airport_w2k.altitude

    airport.name = airport_w2k.name
    airport.short_name = airport_w2k.short_name
    airport.icao = airport_w2k.icao
    airport.country_code = airport_w2k.country_code
    airport.surface = airport_w2k.surface
    airport.runway_len = airport_w2k.runway_len
    airport.runway_dir = airport_w2k.runway_dir
    airport.frequency = airport_w2k.freq
    airport.type = airport_w2k.type

    db.session.add(airport)
Exemple #26
0
 def add_airport(self, airport_w2k):
     airport = Airport()
     self.update_airport(airport, airport_w2k)
     db.session.add(airport)
Exemple #27
0
def meiersberg(**kwargs):
    return Airport(name=u'Meiersberg', country_code='DE').apply_kwargs(kwargs)
Exemple #28
0
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)
Exemple #29
0
def get_airport(id):
    airport = Airport.get(id)
    if not airport:
        raise KeyError('The requested airport was not found.')

    return airport_to_dict(airport, short=False)
Exemple #30
0
def meiersberg(**kwargs):
    return Airport(name=u"Meiersberg", country_code="DE").apply_kwargs(kwargs)
Exemple #31
0
welt2000 = get_database()

i = 0

for airport_w2k in welt2000:
    if airport_w2k.type != 'airport' \
        and airport_w2k.type != 'glider_site' \
        and airport_w2k.type != 'uml':
      continue

    i += 1
    if i%100 == 0:
        DBSession.flush()
        print str(i) + ": " + airport_w2k.country_code + " " + airport_w2k.name

    airport = Airport()
    airport.location = airport_w2k
    airport.altitude = airport_w2k.altitude

    airport.name = airport_w2k.name
    airport.short_name = airport_w2k.short_name
    airport.icao = airport_w2k.icao
    airport.country_code = airport_w2k.country_code
    airport.surface = airport_w2k.surface
    airport.runway_len = airport_w2k.runway_len
    airport.runway_dir = airport_w2k.runway_dir
    airport.frequency = airport_w2k.freq
    airport.type = airport_w2k.type

    DBSession.add(airport)
def get_airport(id):
    airport = Airport.get(id)
    if not airport:
        raise KeyError('The requested airport was not found.')

    return airport_to_dict(airport, short=False)
Exemple #33
0
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(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)