Beispiel #1
0
def testLoc(wlanfake=0, gpsfake=False, verbose=False):
    # Get WLAN scanning results.
    len_visAPs, wifis = getWLAN(wlanfake)

    # Fix current position.
    fixloc = fixPos(len_visAPs, wifis, verbose)
    #fixloc = [ 39.922848,116.472895 ]
    print 'fixed location: \n%s' % fixloc

    # Get GPS referenced Position.
    if not gpsfake: refloc = getGPS()
    else: refloc = [39.922648, 116.472895]
    print 'referenced location: \n%s' % refloc

    # Log the fixed and referenced positioning record.
    # Logging format: [ timestamp, MAC1|MAC2..., fLat, fLon, rLat, rLon ].
    timestamp = time.strftime('%Y-%m%d-%H%M')
    visMACs = '|'.join(wifis[0])
    #error = dist_unit(fixloc[0], fixloc[1], refloc[0], refloc[1])*RADIUS
    locline = [timestamp, visMACs, fixloc[0], fixloc[1], refloc[0], refloc[1]]
    print 'locline:\n%s' % locline

    date = time.strftime('%Y-%m%d')
    locfilename = LOCPATH + date + LOCSUFFIX
    dumpCSV(locfilename, locline)
Beispiel #2
0
def testLoc(wlanfake=0, gpsfake=False, verbose=False):
    # Get WLAN scanning results.
    len_visAPs, wifis = getWLAN(wlanfake)

    # Fix current position.
    fixloc = fixPos(len_visAPs, wifis, verbose)
    #fixloc = [ 39.922848,116.472895 ]
    print 'fixed location: \n%s' % fixloc

    # Get GPS referenced Position.
    if not gpsfake: refloc = getGPS()
    else: refloc = [ 39.922648,116.472895 ]
    print 'referenced location: \n%s' % refloc

    # Log the fixed and referenced positioning record.
    # Logging format: [ timestamp, MAC1|MAC2..., fLat, fLon, rLat, rLon ].
    timestamp = time.strftime('%Y-%m%d-%H%M')
    visMACs = '|'.join(wifis[0])
    #error = dist_unit(fixloc[0], fixloc[1], refloc[0], refloc[1])*RADIUS
    locline = [ timestamp, visMACs, fixloc[0], fixloc[1], refloc[0], refloc[1] ]
    print 'locline:\n%s' % locline

    date = time.strftime('%Y-%m%d')
    locfilename = LOCPATH + date + LOCSUFFIX
    dumpCSV(locfilename, locline)
Beispiel #3
0
def collectData(req=None, reqfmt=None, ret=None, retfmt=None, algos=None):
    """
    req: 16/14 col raw data.
    ret: macs, rsss, cpp(lat,lon,err).
    algos: tuple of used algos, e.g. ('cpp', 'py', 'google').
    """
    sys.stdout.write('Slicing & Merging test data ... ')
    macrss = np.char.array(
        req[:, [reqfmt['idx_macs'], reqfmt['idx_rsss']]]).split('|')
    reqcols = [reqfmt['idx_lat'], reqfmt['idx_lon']]

    # complete *addcols* column definition:
    # err_cpp, ee_cpp, py(lat,lon,err,ep,ee), ep_cpp_py, ee_cpp_py, google(lat,lon,err,ep,ee).
    addcols = []
    idiffs = []
    atoken = None
    istats = []
    ipylocoks = []
    isErrinRange = {
        'cpp': {
            'all': 0,
            'errless200': 0
        },
        'py': {
            'all': 0,
            'errless200': 0
        },
        'google': {
            'all': 0,
            'errless200': 0
        }
    }

    usecpp = False
    usepy = False
    usegoogle = False
    idx_cur = 0
    if 'cpp' in algos:
        usecpp = True
        istats_cpp = offsets_stats['cpp']
        istats.extend(
            istats_cpp)  # offset of istats item in cpp section of addcols.
        idx_cur += idxscnt_addcols['cpp'][1]
        retcols = [retfmt['ilat_cpp'], retfmt['ilon_cpp'], retfmt['ierr_cpp']]
    if 'py' in algos:
        usepy = True
        istats_py = (idx_cur + np.array(offsets_stats['py'])).tolist()
        istats.extend(
            istats_py)  # offset of istats item in cpp section of addcols.
        if usecpp:
            idx_cur = idx_cur + idxscnt_addcols['py'][1] + idxscnt_addcols[
                'cpp_py'][1]
            # reqret format: ref(lat,lon), cpp(lat,lon,err)
            reqret = np.append(req[:, reqcols], ret[:, retcols],
                               axis=1).astype(float)
        else:
            idx_cur += idxscnt_addcols['py'][1]
            reqret = req[:, reqcols].astype(float)
    if 'google' in algos:
        usegoogle = True
        istats_google = (idx_cur + np.array(offsets_stats['google'])).tolist()
        istats.extend(
            istats_google)  # offset of istats item in cpp section of addcols.
    print 'Done'
    print 'istats: %s' % istats

    for icase in xrange(len(reqret)):
        macs = np.array(macrss[icase, 0])
        rsss = np.array(macrss[icase, 1])
        latref = reqret[icase, 0]
        lonref = reqret[icase, 1]
        addcol = []
        if usecpp:
            latcpp = reqret[icase, 2]
            loncpp = reqret[icase, 3]
            cpperr = reqret[icase, 4]

            # cpploc error to refloc.
            err_cpp = geo.dist_km(loncpp, latcpp, lonref, latref) * 1000
            addcol.append(err_cpp)
            # cpp error estimation error.
            ee = cpperr - err_cpp
            if ee >= 0:
                isErrinRange['cpp']['all'] += 1
                if err_cpp <= 200:
                    isErrinRange['cpp']['errless200'] += 1
            ee_cpp = abs(ee) / cpperr
            addcol.append(ee_cpp)
        if usepy:
            # pyloc result.
            num_visAPs = len(macs)
            INTERSET = min(cfg.CLUSTERKEYSIZE, num_visAPs)
            idxs_max = np.argsort(rsss)[:INTERSET]
            mr = np.vstack((macs, rsss))[:, idxs_max]
            pyloc = wlanpos.fixPos(INTERSET, mr, verb=False)
            if not pyloc: continue
            ipylocoks.append(icase)
            addcol.extend(pyloc)
            # pyloc error to refloc.
            err_py = geo.dist_km(pyloc[1], pyloc[0], lonref, latref) * 1000
            addcol.append(err_py)
            # py error estimation error.
            ee = pyloc[2] - err_py
            if ee >= 0:
                isErrinRange['py']['all'] += 1
                if err_py <= 200:
                    isErrinRange['py']['errless200'] += 1
            ee_py = abs(ee) / pyloc[2]
            addcol.append(ee_py)
            if usecpp:
                # pyloc error to cpploc.
                err_cpp_py = geo.dist_km(pyloc[1], pyloc[0], loncpp,
                                         latcpp) * 1000
                addcol.append(err_cpp_py)
                # error between cpploc error & pyloc error.
                ee_cpp_py = abs(err_cpp - err_py)
                addcol.append(ee_cpp_py)
                if err_cpp_py or ee_cpp_py: idiffs.append(icase)
        if usegoogle:
            # google location api results.
            mr = mr.tolist()
            # Old interface of makeReq.
            #gloc_req = gl.makeReq(wlans=mr, atoken=atoken)
            wlans = []
            for iwlan, mac in enumerate(mr[0]):
                wlan = {}
                wlan['mac_address'] = mac
                wlan['signal_strength'] = mr[1][iwlan]
                wlans.append(wlan)
            gloc_req = gl.makeReq(wlans=wlans, atoken=atoken)
            gloc_ret = gl.getGL(gloc_req)
            gloc_pos = gloc_ret['location']
            if (not atoken) and ('access_token' in gloc_ret):
                atoken = gloc_ret['access_token']
            addcol.extend(gloc_pos.values())
            # google loc error to refloc.
            err_google = geo.dist_km(gloc_pos['longitude'],
                                     gloc_pos['latitude'], lonref,
                                     latref) * 1000
            addcol.append(err_google)
            # google loc error estimation error.
            ee = gloc_pos['accuracy'] - err_google
            if ee >= 0:
                isErrinRange['google']['all'] += 1
                if err_google <= 200:
                    isErrinRange['google']['errless200'] += 1
            ee_google = abs(ee) / gloc_pos['accuracy']
            addcol.append(ee_google)
        print '%d: %s' % (icase + 1, addcol)
        addcols.append(addcol)
        print

    return (addcols, isErrinRange, reqret, ipylocoks, istats, idiffs)
Beispiel #4
0
def collectData(req=None, reqfmt=None, ret=None, retfmt=None, algos=None):
    """
    req: 16/14 col raw data.
    ret: macs, rsss, cpp(lat,lon,err).
    algos: tuple of used algos, e.g. ('cpp', 'py', 'google').
    """
    sys.stdout.write('Slicing & Merging test data ... ')
    macrss = np.char.array(req[ :, [reqfmt['idx_macs'],reqfmt['idx_rsss']] ]).split('|')
    reqcols = [ reqfmt['idx_lat'], reqfmt['idx_lon'] ]

    # complete *addcols* column definition: 
    # err_cpp, ee_cpp, py(lat,lon,err,ep,ee), ep_cpp_py, ee_cpp_py, google(lat,lon,err,ep,ee).
    addcols = []; idiffs = []; atoken = None; istats = []; ipylocoks = []
    isErrinRange={'cpp': {'all':0, 'errless200':0}, 
                   'py': {'all':0, 'errless200':0}, 
               'google': {'all':0, 'errless200':0} }

    usecpp = False; usepy = False; usegoogle = False
    idx_cur = 0
    if 'cpp' in algos: 
        usecpp = True
        istats_cpp = offsets_stats['cpp']
        istats.extend(istats_cpp) # offset of istats item in cpp section of addcols.
        idx_cur += idxscnt_addcols['cpp'][1]
        retcols = [ retfmt['ilat_cpp'], retfmt['ilon_cpp'], retfmt['ierr_cpp'] ]
    if 'py' in algos: 
        usepy = True
        istats_py = (idx_cur + np.array(offsets_stats['py'])).tolist()
        istats.extend(istats_py) # offset of istats item in cpp section of addcols.
        if usecpp:
            idx_cur = idx_cur + idxscnt_addcols['py'][1] + idxscnt_addcols['cpp_py'][1]
            # reqret format: ref(lat,lon), cpp(lat,lon,err)
            reqret = np.append(req[:,reqcols], ret[:,retcols], axis=1).astype(float)
        else:
            idx_cur += idxscnt_addcols['py'][1]
            reqret = req[:,reqcols].astype(float)
    if 'google' in algos: 
        usegoogle = True
        istats_google = (idx_cur + np.array(offsets_stats['google'])).tolist()
        istats.extend(istats_google) # offset of istats item in cpp section of addcols.
    print 'Done'
    print 'istats: %s' % istats

    for icase in xrange(len(reqret)):
        macs = np.array(macrss[icase,0]) 
        rsss = np.array(macrss[icase,1])
        latref = reqret[icase,0]; lonref = reqret[icase,1] 
        addcol = []
        if usecpp:
            latcpp = reqret[icase,2]; loncpp = reqret[icase,3]; cpperr = reqret[icase,4] 

            # cpploc error to refloc.
            err_cpp = geo.dist_km(loncpp, latcpp, lonref, latref)*1000
            addcol.append(err_cpp)
            # cpp error estimation error.
            ee = cpperr - err_cpp 
            if ee >= 0: 
                isErrinRange['cpp']['all'] += 1
                if err_cpp <= 200:
                    isErrinRange['cpp']['errless200'] += 1
            ee_cpp = abs(ee)/cpperr
            addcol.append(ee_cpp)
        if usepy:
            # pyloc result.
            num_visAPs = len(macs)
            INTERSET = min(cfg.CLUSTERKEYSIZE, num_visAPs)
            idxs_max = np.argsort(rsss)[:INTERSET]
            mr = np.vstack((macs, rsss))[:,idxs_max]
            pyloc = wlanpos.fixPos(INTERSET, mr, verb=False)
            if not pyloc: continue
            ipylocoks.append(icase)
            addcol.extend(pyloc)
            # pyloc error to refloc.
            err_py = geo.dist_km(pyloc[1], pyloc[0], lonref, latref)*1000
            addcol.append(err_py)
            # py error estimation error.
            ee = pyloc[2] - err_py 
            if ee >= 0: 
                isErrinRange['py']['all'] += 1
                if err_py <= 200:
                    isErrinRange['py']['errless200'] += 1
            ee_py = abs(ee)/pyloc[2]
            addcol.append(ee_py)
            if usecpp:
                # pyloc error to cpploc.
                err_cpp_py = geo.dist_km(pyloc[1], pyloc[0], loncpp, latcpp)*1000
                addcol.append(err_cpp_py)
                # error between cpploc error & pyloc error.
                ee_cpp_py = abs(err_cpp - err_py)
                addcol.append(ee_cpp_py)
                if err_cpp_py or ee_cpp_py: idiffs.append(icase)
        if usegoogle:
            # google location api results.
            mr = mr.tolist()
            # Old interface of makeReq.
            #gloc_req = gl.makeReq(wlans=mr, atoken=atoken)
            wlans = []
            for iwlan,mac in enumerate(mr[0]):
                wlan = {}
                wlan['mac_address'] = mac
                wlan['signal_strength'] = mr[1][iwlan]
                wlans.append(wlan)
            gloc_req = gl.makeReq(wlans=wlans, atoken=atoken)
            gloc_ret = gl.getGL(gloc_req)
            gloc_pos = gloc_ret['location']
            if (not atoken) and ('access_token' in gloc_ret):
                atoken = gloc_ret['access_token']
            addcol.extend( gloc_pos.values() )
            # google loc error to refloc.
            err_google = geo.dist_km(gloc_pos['longitude'], gloc_pos['latitude'], lonref, latref)*1000
            addcol.append(err_google)
            # google loc error estimation error.
            ee = gloc_pos['accuracy'] - err_google 
            if ee >= 0: 
                isErrinRange['google']['all'] += 1
                if err_google <= 200:
                    isErrinRange['google']['errless200'] += 1
            ee_google = abs(ee)/gloc_pos['accuracy']
            addcol.append(ee_google)
        print '%d: %s' % (icase+1, addcol)
        addcols.append(addcol)
        print 

    return (addcols, isErrinRange, reqret, ipylocoks, istats, idiffs)