Exemplo n.º 1
0
    def post(self, args):
        """
        Add a new park.
        """
        park = Park()
        park.name = args['name']
        park.address = args['address']
        park.admission_price = args['admission_price']
        park.operator_id = db.session.query(
            Operator.id).filter(Operator.name == args['operator']).first()

        business_hours = BusinessHours(opening_time=args['opening_time'],
                                       closing_time=args['closing_time'])
        location = Location(latitude=args['latitude'],
                            longitude=args['longitude'])
        park.location = location.to_wkt_element()
        park.operating_hours = business_hours
        sponsors = Sponsor.find_if_none_create(args['sponsors'])
        park.sponsors = sponsors
        with parks_ns.commit_or_abort(
                db.session,
                default_error_message="Failed to create the park."):
            db.session.add(park)

        return park
Exemplo n.º 2
0
    def post(self, args):
        """
        Get parks by geolocation.
        """

        try:
            if args['filters']:
                filters = args['filters']
        except KeyError:
            filters = {}
        search_type = args['search']

        # Decide which query to use based on search param
        # refactor to use strategy pattern in future
        if 'point' in search_type:
            radius = int(args['radius'])
            point = Location(latitude=args['latitude'],
                             longitude=args['longitude'])
            return Park.get_parks_by_point(point,
                                           radius=radius,
                                           filters=filters)
        elif 'path' in search_type:
            points = [
                Location(latitude=coordinate[0], longitude=coordinate[1])
                for coordinate in args['coordinates']
            ]
            return Park.get_poi_along_path(points,
                                           args['radius'],
                                           filters=filters)
Exemplo n.º 3
0
def parks():
    """
    Generate random parks.
    """
    data = []
    num_of_rides = 99

    click.echo('Working on parks...')
    with app.app_context():
        operators = db.session.query(Operator).all()

        while num_of_rides >= 0:
            operator = random.choice(operators)
            park_name = operator.name + " - " + fake.city()
            address = fake.address()
            location = Location(fake.latitude(),
                                fake.longitude()).to_wkt_element()
            price = round(random.uniform(50, 150), 2)

            params = {
                'name': park_name,
                'address': address,
                'location': location,
                'admission_price': price,
                'operator_id': operator.id
            }

            data.append(params)
            num_of_rides -= 1

        return _bulk_insert(Park, data, 'parks')
Exemplo n.º 4
0
 def _deserialize(self, value, attr, data):
     if value is None:
         return value
     else:
         if attr == 'location':
             return Location(value.get('longitude'), value.get('latitude'))
         else:
             return None
Exemplo n.º 5
0
def test_poly():
    """
    Generate random ridetypes.
    """
    lines = []
    lines.append(Location(37.31917, -122.04511))
    lines.append(Location(37.35247, -122.06396))
    lines.append(Location(37.38412, -122.02139))
    lines.append(Location(37.36994, -121.9953))
    lines.append(Location(37.34374, -121.97607))
    """
    Generate random parks.
    """
    data = []
    num_of_rides = len(lines) - 1

    click.echo('Working on test parks...')
    with app.app_context():
        while num_of_rides >= 0:
            location = lines.pop()
            park_name = "test - " + fake.city()
            address = fake.address()
            location = location.to_wkt_element()
            price = round(random.uniform(50, 150), 2)

            params = {
                'name': park_name,
                'address': address,
                'location': location,
                'admission_price': price,
                'operator_id': 1,
                'business_hours': 1
            }

            data.append(params)
            num_of_rides -= 1

        return _bulk_insert(Park, data, 'parks')
Exemplo n.º 6
0
 def __init__(self, **kwargs):
     location = Location(latitude=kwargs.get('lat', 0),
                         longitude=kwargs.get('lng', 0))
     self.location = location.to_wkt_element()
     super(Park, self).__init__()