Пример #1
0
    def get_gamemap_path(self, user, **kwargs):
        """Return a path between last and current user position

        Args:
            **kwargs:
                latitude - the point latitude
                longitude  - the point longitude
                user - <User>, who did it request

        Return:
            last_box - a last box, where the user did something,
            current_box - a current user box,
            path - [(x, y), (x, y)] - path from last_box to curr_box
        """
        def _get_path(prev, curr):
            end = prev.get_gamemap_position()
            start = curr.get_gamemap_position()

            def _compare(a, b):
                if a > b:
                    return -1
                if a < b:
                    return 1
                return 0

            def _get(_path=None):
                if _path is None:
                    _path = [start]
                last = _path[-1]
                next_x = _compare(last[0], end[0]) + last[0]
                next_y = start[1]
                if next_x == end[0]:
                    next_y = _compare(last[1], end[1]) + last[1]
                _path.append([next_x, next_y])
                if next_x == end[0] and next_y == end[1]:
                    return _path
                return _get(_path)

            return _get()

        params = parameters.PlaceSearchParametersFactory.create(
            kwargs, self.city_service)
        params_dict = params.get_db_params()
        places_list = filter(
            lambda p: p.gamemap_position,
            queries.search_places(**params_dict))
        curr = places_list and places_list[0] or None
        prev = places_list and random.choice(places_list) or None
        path = _get_path(prev, curr)
        # create/update path for user in db
        self.update_user_gamemap(modelUser.objects.get(email=user), path,
                                 params_dict[params_names.CITY_ID])
        return dict(
            path=path,
            prev_box=self._make_place_distance_item(prev, params),
            current_box=self._make_place_distance_item(curr, params),
        )
Пример #2
0
 def search_in_venue(self, **kwargs):
     params = parameters.PlaceSearchParametersFactory.create(
         kwargs, self.city_service)
     places_in_radius = []
     places_in_params = []
     if params.get_db_params().get('radius'):
         places_in_radius = queries.search_places(**params.get_db_params())
     newparams = params.get_db_params()
     newparams['radius'] = None
     places_out_radius = \
         list(set(queries.search_places(**newparams))-set(places_in_radius))
     places = {
         'out_radius':[self._make_place_distance_item(p,params) \
             for p in places_out_radius],
         'in_radius':[self._make_place_distance_item(p,params) \
             for p in places_in_radius]
     }
     return places
Пример #3
0
 def search_in_venue(self, **kwargs):
     params = parameters.PlaceSearchParametersFactory.create(
         kwargs, self.city_service)
     places_in_radius = []
     places_in_params = []
     if params.get_db_params().get('radius'):
         places_in_radius = queries.search_places(**params.get_db_params())
     newparams = params.get_db_params()
     newparams['radius'] = None
     places_out_radius = \
         list(set(queries.search_places(**newparams))-set(places_in_radius))
     places = {
         'out_radius':[self._make_place_distance_item(p,params) \
             for p in places_out_radius],
         'in_radius':[self._make_place_distance_item(p,params) \
             for p in places_in_radius]
     }
     return places
Пример #4
0
    def search_in_venue(self, **kwargs):
        """Gets places around point from sz db

        Gets places around point. Filter by radius, query and
        return list of places.

        Args:
            **kwargs:
                latitude - the point latitude
                longitude  - the point longitude
                query - string key for filter
                radius - radius for filter
        Returns:
            [<Place>,..]
        """
        params = parameters.PlaceSearchParametersFactory.create(
            kwargs, self.city_service)
        places_list = queries.search_places(**params.get_db_params())
        return self._make_distance_items_list(params, places_list)
Пример #5
0
 def search(self, **kwargs):
     params = parameters.PlaceSearchParametersFactory.create(kwargs, self.city_service)
     places = queries.search_places(**params.get_db_params())
     return [self._make_place_distance_item(place, params) for place in places]