Esempio n. 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
Esempio n. 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
Esempio n. 3
0
 def _make_place_distance_item(self, place, params):
     latitude, longitude = parameters.get_position_from_dict(
         params.get_api_params())
     distance = gis_core.distance(longitude, latitude, place.longitude(),
                                  place.latitude())
     azimuth = gis_core.azimuth(longitude, latitude, place.longitude(),
                                place.latitude())
     item = dict(place=place, distance=distance, azimuth=azimuth)
     return item
Esempio n. 4
0
 def _make_place_distance_item(self, place, params):
     latitude, longitude = parameters.get_position_from_dict(
         params.get_api_params())
     distance = gis_core.distance(
         longitude, latitude, place.longitude(), place.latitude())
     azimuth = gis_core.azimuth(
         longitude, latitude, place.longitude(), place.latitude())
     item = dict(place=place, distance=distance, azimuth=azimuth)
     return item
Esempio n. 5
0
 def _make_place_distance_item(self, place, params):
     if place.position:
         latitude, longitude = parameters.get_position_from_dict(
             params.get_api_params())
         args = [longitude, latitude, place.longitude(), place.latitude()]
         distance = gis_core.distance(*args)
         azimuth = gis_core.azimuth(*args)
     else:
         distance = None
         azimuth = None
     return dict(place=place, distance=distance, azimuth=azimuth)
Esempio n. 6
0
 def _filter_place(self, p, creator, radius):
     distance = gis_core.distance(
         creator['longitude'], creator['latitude'],
         p[u'location'].get('lng'), p[u'location'].get('lat'))
     #filter only in radius
     if distance > radius:
         return False
     position = gis_core.ll_to_point(
         p[u'location'].get(u'lng'), p[u'location'].get(u'lat'))
     place = modelPlace.objects.filter(name=p['name'], position=position)
     #take only not created or not active in db places
     is_create = place[0].is_active if place else False
     return not is_create
Esempio n. 7
0
 def create_place(self, params, city_id, creator, radius):
     distance = gis_core.distance(
         creator['longitude'], creator['latitude'],
         params[u'location'].get('lng'), params[u'location'].get('lat'))
     #filter only in radius
     if distance > radius:
         return False
     location = params.get(u'location', {})
     position = gis_core.ll_to_point(
         location.get(u'lng'), params[u'location'].get(u'lat'))
     place_params = dict(
         address=location.get('address'),
         crossStreet=location.get('crossStreet'),
         contact=location.get('contact'),
         fsq_id=params.get('id'),
         city_id=city_id,
         position=position,
         name=params.get('name')
     )
     foursquare_cat = params.get(u'categories')[0] \
         if len(params.get(u'categories', [])) else {}
     if foursquare_cat:
         foursquare_icon = foursquare_cat.get('icon', {})
         place_params['foursquare_icon_suffix'] = foursquare_icon.get(
             u'suffix')
         place_params['foursquare_icon_prefix'] = foursquare_icon.get(
             u'prefix')
     '''
     Зачем здесь экспешн ?
     Да потому что из-за уникальной географической позиции в
     городе тестирования city_id определяется поразному в разных
     точках города и с таким ид, name, position  место не находится,
     но и создавать не даст
     '''
     try:
         p, is_create = modelPlace.objects.get_or_create(**place_params)
     except IntegrityError:
         p = modelPlace.objects.filter(
             position=position, name=params.get('name'))
         p = p[0] if p else None
     return p if (p and not p.is_active) else False