Esempio n. 1
0
    def get_track_name(self, location):
        """Get name of a location which comes from a track.

        @param: location, {'name':'',
                           'clatitude':'',
                           'clongitude':'',
                           }
        """
        if not location:
            return ''
        if not location['name']:
            if location['clatitude'] and location['clongitude']:
                pass
            else:
                track = get_locations_with_clatlon([location,], self.db)
                location = track[0] 
            name = get_location_name(location['clatitude'], location['clongitude'], self.redis)
            if name:
                location['name'] = name 
                self.db.execute("UPDATE T_LOCATION SET name = %s WHERE id = %s",
                                name, location['id'])

        return location['name'] if location['name'] else ''
Esempio n. 2
0
    def request_realtime(self, query, callback=None):
        """
        All realtime requests in REALTIME_VALID_INTERVAL will be considered as
        only one. If not, invoke gf and use handle_location of lbmphelper. 
        """
        location = QueryHelper.get_location_info(self.current_user.tid, self.db, self.redis)
        if location and location['name'] is None:
            location['name'] = '' 
                
        ret = DotDict(status=ErrorCode.SUCCESS,
                      message='',
                      location=None)

        locations = [location,] 
        locations = get_locations_with_clatlon(locations, self.db) 
        location = locations[0]

        if (location and location.clatitude and location.clongitude):
            if location.has_key('id'):
                del location['id']
            
            location['degree'] = float(location.degree)
            location['tid'] = self.current_user.tid
            ret.location = location
            if callback:
                callback(ret)
                return

        lat, lon = get_latlon_from_cellid(0,0,0,0, self.current_user.sim)
        clat, clon = get_clocation_from_ge([lat,],[lon,]) 
        clat = int(clat[0]) if len(clat)>0 else 0 
        clon = int(clon[0]) if len(clon)>0 else 0 
        name = get_location_name(clat, clon, self.redis)
        
        location = DotDict(category = 1, # cellid
                           dev_id = self.current_user.tid, 
                           lat = lat, 
                           lon = lon, 
                           cLat = clat, 
                           cLon = clon, 
                           alt = 0,
                           gps_time = int(time.time()), 
                           type = 1, 
                           speed = 0.0, 
                           degree = 0.0, 
                           name = name, 
                           cellid = None,
                           locate_error = 20)
        if clat and clon:
            ret.location = DotDict()
            ret.location.latitude = lat
            ret.location.longitude = lon
            ret.location.clongitude = clon
            ret.location.clatitude = clat
            ret.location.timestamp = int(time.time()) 
            ret.location.name = name
            ret.location.speed = 0
            ret.location.type = 1
            ret.location.tid = self.current_user.tid
            ret.location.degree = 0.0 
            ret.location.locte_error = 20 
            insert_location(location, self.db, self.redis)
            logging.info("[UWEB] tid %s cellid query success", self.current_user.tid)
        else:
            ret.status = ErrorCode.LOCATION_CELLID_FAILED 
            ret.message = ErrorCode.ERROR_MESSAGE[ret.status]
            logging.info("[UWEB] Do not find any location, and cellid query failed. tid: %s", 
                         self.current_user.tid)

        if callback:
            callback(ret)