Beispiel #1
0
def get_clocation_from_localge(positions):
    """Local ge.
    @params: position, [{"lon":*,"lat":*}, {}, ...] 
    @return: position, [{"lon":*,"lat":*}, {}, ...] 
    """
    result = [] 
    MAX_COUNT = 100 
    if len(positions) > MAX_COUNT: 
        logging.info("[LBMPHELPER] Get clocations: The number of positions is more than MAX_COUNT!") 
        return result 
        
    try: 
        args = dict(position=positions) 
        response = LbmpSenderHelper.forward(LbmpSenderHelper.URLS.LOCALGE, args) 
        response = json_decode(response) 
        if response["status"] == 0: 
            result.extend(response["position"]) 
        else: # NOTE: provide a dummy list 
            result.extend([dict(lon=0,lat=0) for i in xrange(len(positions))]) 
            logging.info("[LBMPHELPER] Get clocation failed, response: %s, args: %s", 
                         response['info'], args) 
    except Exception as e: 
        logging.exception("[LBMPHELPER] Get clocations from GE failed.  Exception: %s", e.args) 
    finally:
        return result
Beispiel #2
0
def get_location_name(clat, clon, redis):
    """Get location's name.
   
    @params: clat, degree*3600000
             clon, degree*3600000
             redis
    @return: name
    """
    name = ''
    try: 
        key = get_location_cache_key(int(clon), int(clat))
        name = redis.getvalue(key)
        if not name:
            args = dict(lon=(float(clon)/3600000),
                        lat=(float(clat)/3600000))
            response = LbmpSenderHelper.forward(LbmpSenderHelper.URLS.GV, args)
            response = json_decode(response)
            if response['success'] == 0:
                name = response.get('address')
                if name: # keep it in location for 7 days.
                    redis.setvalue(key, name, EVENTER.LOCATION_NAME_EXPIRY)
            else:
                logging.error("[LBMPHELPER] Get location name failed, response: %s, args: %s",
                              response.get('info'), args)
    except Exception as e:
        logging.exception("[LBMPHELPER] Get location name from GV failed. Exception: %s", e.args)
    return name 
Beispiel #3
0
def subscription_lbmp(mobile):
    """ Subscription LE for new sim.

    NOTE: deprecated. 
    In fact, subscription_lbmp can not work now.
    """
    data = DotDict(sim=mobile,
                   action="A")
    response = LbmpSenderHelper.forward(
        LbmpSenderHelper.URLS.SUBSCRIPTION, data)
    response = json_decode(response)
    if response['success'] == '000':
        logging.info("[GW] mobile: %s subscription LE success! ",
                     mobile)
    else:
        logging.info("[GW] mobile: %s subscription LE failed! response:%s",
                     mobile, response)
Beispiel #4
0
def get_clocation_from_ge(lats, lons):
    """@params: lats, [degree*3600000, ...]
                lons, [degree*3600000, ...]
       @return: clats,[degree*3600000, ...]
                clons, [degree*3600000, ...]
    """
    # send 20 items for getting offset latlon every time.
    #MAX_COUNT = 20 
    MAX_COUNT = 100 
    clats = [] 
    clons = [] 
    try: 
        # NOTE: if lats and lons has different number of items, or either
        # is a empty list, return clats and clons directly 
        if (len(lats) != len(lons)) or (not (lats and lons)):
            logging.error("[LBMPHELPER] Invalid data. len(lats)=%s, len(lons)=%s, lats: %s, lons: %s", 
                          len(lats), len(lons), lats, lons)
            return clats, clons

        #NOTE: when there are too many lats and lons, send 20 pairs one time till all is sent.
        d, m = divmod(len(lats), MAX_COUNT)
        rounds = (d + 1) if m else d
        for i in xrange(rounds):
            lats_item = lats[(i * MAX_COUNT) : ((i+1) * MAX_COUNT)]
            lons_item = lons[(i * MAX_COUNT) : ((i+1) * MAX_COUNT)]

            args = DotDict(lats=lats_item,
                           lons=lons_item)
            response = LbmpSenderHelper.forward(LbmpSenderHelper.URLS.GE, args)
            response = json_decode(response)
            if response['success'] == 0:
                clats_item = response['position']['clats']
                clons_item = response['position']['clons']
            else:
                # NOTE: porvide a dummy list
                clats_item = [0,] * len(lats_item)
                clons_item = [0,] * len(lons_item)
                logging.info("[LBMPHELPER] Get clocation from GE failed, response: %s, args: %s",
                             response['info'], args)
            clats.extend(clats_item)
            clons.extend(clons_item)
    except Exception as e:
        logging.exception("[LBMPHELPER] Get latlon from GE failed. Exception: %s", e.args)
    return clats, clons
Beispiel #5
0
def get_latlon_from_cellid(mcc, mnc, lac, cid, sim):
    """@params: mcc, mobile country code 
                mnc, mobile network code 
                lac, location area code 
                cid, cellid
       @return: lat, degree
                lon, degree
    """
    lat = 0
    lon = 0
    try:
        args = dict(mcc=mcc, mnc=mnc,
                    lac=lac, cid=cid, sim=sim)
        response = LbmpSenderHelper.forward(LbmpSenderHelper.URLS.LE, args)
        response = json_decode(response) 
        if response['success'] == 0:
            lat = response['position']['lat']
            lon = response['position']['lon']
        else:
            logging.info("[LBMPHELPER] Get latlon from LE failed, response: %s, args: %s",
                         response['info'], args)
    except Exception as e:
        logging.exception("[LBMPHELPER] Get latlon from LE failed. Exception: %s", e.args)
    return lat, lon