Example #1
0
 def explore_in_venues(self, **kwargs):
     params = parameters.PlaceSearchParametersFactory.create(
         kwargs, self.city_service).get_db_params()
     latitude = params.get(params_names.LATITUDE)
     longitude = params.get(params_names.LONGITUDE)
     city_id = params.get(params_names.CITY_ID)
     query = params.get(params_names.QUERY)
     radius = params.get(params_names.RADIUS)
     creator = {
         'email':kwargs[u'creator'],
         'latitude':latitude,
         'longitude':longitude
     }
     #get place_list from 4qk        
     result = venue.search(
         {'latitude': latitude, 'longitude': longitude},
         query,
         radius
     )['venues']
     #filter only in radius
     result_filter_by_radius = filter(
         lambda p: gis_core.distance(
                 creator['longitude'], creator['latitude'],
                 p[u'location'].get('lng'), p[u'location'].get('lat')
             )<=radius,
         result
     )
     #take only not created in db places
     result_filter_by_created = filter(
         lambda p: 
             #place not created in db
             not models.Place.objects.filter(
                 name=p.get(u'name'),
                 position=gis_core.ll_to_point(
                     p[u'location'].get(u'lng'), p[u'location'].get(u'lat')
                 )
             ) 
             #or place created in db but not active
             or models.Place.objects.get(
                 name=p.get(u'name'),
                 position=gis_core.ll_to_point(
                     p[u'location'].get(u'lng'), p[u'location'].get(u'lat')
                 )
             ).is_active is False,                    
         result_filter_by_radius
     )
     place_and_distance_list = []
     for p in result_filter_by_created:
         new_place = dict(
             distance=gis_core.distance(
                 creator['longitude'], creator['latitude'],
                 p[u'location'].get('lng'), p[u'location'].get('lat')
             ),
             azimuth=gis_core.azimuth(longitude, latitude,
                 p[u'location'].get(u'lng'), p[u'location'].get(u'lat')),
             creator=creator,
             place=self.create_place(p,city_id),
         )
         place_and_distance_list.append(new_place)
     return place_and_distance_list
Example #2
0
 def explore_in_venues(self, **kwargs):
     params = parameters.PlaceSearchParametersFactory.create(
         kwargs, self.city_service).get_db_params()
     latitude = params.get(params_names.LATITUDE)
     longitude = params.get(params_names.LONGITUDE)
     city_id = params.get(params_names.CITY_ID)
     query = params.get(params_names.QUERY)
     radius = params.get(params_names.RADIUS)
     creator = {
         'email': kwargs[u'creator'],
         'latitude': latitude,
         'longitude': longitude
     }
     #get place_list from 4qk
     result = venue.search({
         'latitude': latitude,
         'longitude': longitude
     }, query, radius)['venues']
     #filter only in radius
     result_filter_by_radius = filter(
         lambda p: gis_core.distance(creator['longitude'], creator[
             'latitude'], p[u'location'].get('lng'), p[u'location'].get(
                 'lat')) <= radius, result)
     #take only not created in db places
     result_filter_by_created = filter(
         lambda p:
         #place not created in db
         not models.Place.objects.filter(name=p.get(u'name'),
                                         position=gis_core.ll_to_point(
                                             p[u'location'].get(u'lng'), p[
                                                 u'location'].get(u'lat')))
         #or place created in db but not active
         or models.Place.objects.get(
             name=p.get(u'name'),
             position=gis_core.ll_to_point(p[u'location'].get(u'lng'), p[
                 u'location'].get(u'lat'))).is_active is False,
         result_filter_by_radius)
     place_and_distance_list = []
     for p in result_filter_by_created:
         new_place = dict(
             distance=gis_core.distance(creator['longitude'],
                                        creator['latitude'],
                                        p[u'location'].get('lng'),
                                        p[u'location'].get('lat')),
             azimuth=gis_core.azimuth(longitude, latitude,
                                      p[u'location'].get(u'lng'),
                                      p[u'location'].get(u'lat')),
             creator=creator,
             place=self.create_place(p, city_id),
         )
         place_and_distance_list.append(new_place)
     return place_and_distance_list
Example #3
0
 def search_in_venues(self, **kwargs):
     params = parameters.PlaceSearchParametersFactory.create(kwargs, self.city_service).get_db_params()
     latitude = params.get(params_names.LATITUDE)
     longitude = params.get(params_names.LONGITUDE)
     city_id = params.get(params_names.CITY_ID)
     query = params.get(params_names.QUERY)
     radius = params.get(params_names.RADIUS)
     result = venue.search({"latitude": latitude, "longitude": longitude}, query, radius)
     place_and_distance_list = map(
         lambda l: {
             "place": models.Place(
                 id=l[u"id"],
                 name=l[u"name"],
                 contact=l.get(u"contact"),
                 address=l[u"location"].get(u"address") and (u"%s" % l[u"location"].get(u"address")) or None,
                 crossStreet=l[u"location"].get(u"crossStreet")
                 and (u"%s" % l[u"location"].get(u"crossStreet"))
                 or None,
                 position=gis_core.ll_to_point(l[u"location"].get(u"lng"), l[u"location"].get(u"lat")),
                 city_id=None,
                 foursquare_icon_suffix=utils.safe_get(l, lambda el: el[u"categories"][0][u"icon"][u"suffix"]),
                 foursquare_icon_prefix=utils.safe_get(l, lambda el: el[u"categories"][0][u"icon"][u"prefix"]),
             ),
             "distance": l[u"location"].get(u"distance"),
             "azimuth": gis_core.azimuth(
                 longitude, latitude, l[u"location"].get(u"lng"), l[u"location"].get(u"lat")
             ),
         },
         result["venues"],
     )
     if len(place_and_distance_list) > 0:
         caching_manager = ModelCachingManager(
             [item["place"] for item in place_and_distance_list],
             lambda e: e.date,
             datetime.timedelta(seconds=60 * 60 * 24 * 3),
         )
         if len(caching_manager.for_insert) > 0:
             for e in caching_manager.for_insert:
                 e.city_id = city_id
         if len(caching_manager.cached) > 0:
             for e in caching_manager.cached:
                 stored_city = lists.first_match(lambda x: x.id == e.id, caching_manager.stored)
                 e.city_id = stored_city.city_id
         caching_manager.save()
     return place_and_distance_list
Example #4
0
    def explore_in_venues(self, **kwargs):
        """Gets places around point from external db

        Gets places around point. Filter by radius, query and
        return list of places, which NOT created in szdb OR created
        but NOT active (anyway a place should be dont created in BL).

        Args:
            **kwargs:
                latitude - the point latitude
                longitude  - the point longitude
                query - string key for filter
                radius - radius for filter
                user - <User>

        Returns:
            [<Place>,..]
        """
        params = parameters.PlaceSearchParametersFactory.create(
            kwargs, self.city_service).get_db_params()
        latitude = params.get(params_names.LATITUDE)
        longitude = params.get(params_names.LONGITUDE)
        city_id = params.get(params_names.CITY_ID)
        query = params.get(params_names.QUERY)
        radius = params.get(params_names.RADIUS)
        creator = {
            'email': kwargs[u'user'].email,
            'latitude': latitude, 'longitude': longitude
        }
        #get place_list from 4qk
        result = venue.search(
            {'latitude': latitude, 'longitude': longitude},
            query, radius
        )
        places_list = []
        for p in result['venues']:
            new_place = self.create_place(p, city_id, creator, radius)
            if new_place:
                places_list.append(new_place)
        return places_list