private void queryNearestDistance(int rssi[]) { Log.i(TAG, "queryNearestDistance BEGIN"); WifiReferencePointProxy proxy = new WifiReferencePointProxy(act); proxy.initDB(); ArrayList<HashMap> list = new ArrayList<HashMap>(); // list = proxy.queryReferencePointDis(mApScanRssi); list = proxy.queryReferencePointDis(scanDataList); // list = proxy.getRegularCoodinate(); Collections.sort( list, new Comparator<HashMap>() { @Override public int compare(HashMap lhs, HashMap rhs) { // TODO Auto-generated method stub return (Integer) rhs.get(WifiReferencePointVO.DISTANCE) == (Integer) lhs.get(WifiReferencePointVO.DISTANCE) ? 0 : ((Integer) rhs.get(WifiReferencePointVO.DISTANCE) < (Integer) lhs.get(WifiReferencePointVO.DISTANCE) ? 1 : -1); // return (Integer) rhs.get(WifiReferencePointVO.DISTANCE) < (Integer) lhs // .get(WifiReferencePointVO.DISTANCE) ? 1 : -1; } }); /* int knnSample = 3; double mPosibility = -1; int knnNo = 0; for(int i = 0; i < knnSample; i++) { BayesClassifier bayes = new BayesClassifier(list.get(i), scanDataList); double res = bayes.getLocationPosibility(); if(res > mPosibility) { mPosibility = res; knnNo = i; } } Log.i(TAG, "The most suitable knn is no" +knnNo + ", Pos = "+mPosibility); */ // using Bayes algorithm to get positionX, Y /* float newPositionX = Float.parseFloat((String) list.get(knnNo).get(WifiReferencePointVO.POSITION_X)); float newPositionY = Float.parseFloat((String) list.get(knnNo).get(WifiReferencePointVO.POSITION_Y)); */ // using knn algorithm to get positionX, Y float newPositionX = (Float.parseFloat((String) list.get(0).get(WifiReferencePointVO.POSITION_X)) + Float.parseFloat((String) list.get(1).get(WifiReferencePointVO.POSITION_X)) + Float.parseFloat((String) list.get(2).get(WifiReferencePointVO.POSITION_X))) / 3; float newPositionY = (Float.parseFloat((String) list.get(0).get(WifiReferencePointVO.POSITION_Y)) + Float.parseFloat((String) list.get(1).get(WifiReferencePointVO.POSITION_Y)) + Float.parseFloat((String) list.get(2).get(WifiReferencePointVO.POSITION_Y))) / 3; WifiReferencePointVO.lastPosX = newPositionX; WifiReferencePointVO.lastPosY = newPositionY; double x0_x1 = Math.pow( Float.parseFloat((String) list.get(0).get(WifiReferencePointVO.POSITION_X)) - Float.parseFloat((String) list.get(1).get(WifiReferencePointVO.POSITION_X)), 2); double y0_y1 = Math.pow( Float.parseFloat((String) list.get(0).get(WifiReferencePointVO.POSITION_Y)) - Float.parseFloat((String) list.get(1).get(WifiReferencePointVO.POSITION_Y)), 2); double x1_x2 = Math.pow( Float.parseFloat((String) list.get(1).get(WifiReferencePointVO.POSITION_X)) - Float.parseFloat((String) list.get(2).get(WifiReferencePointVO.POSITION_X)), 2); double y1_y2 = Math.pow( Float.parseFloat((String) list.get(1).get(WifiReferencePointVO.POSITION_Y)) - Float.parseFloat((String) list.get(2).get(WifiReferencePointVO.POSITION_Y)), 2); double x2_x0 = Math.pow( Float.parseFloat((String) list.get(2).get(WifiReferencePointVO.POSITION_X)) - Float.parseFloat((String) list.get(0).get(WifiReferencePointVO.POSITION_X)), 2); double y2_y0 = Math.pow( Float.parseFloat((String) list.get(2).get(WifiReferencePointVO.POSITION_Y)) - Float.parseFloat((String) list.get(0).get(WifiReferencePointVO.POSITION_Y)), 2); Log.i( TAG, "x0_x1 = " + x0_x1 + " y0_y1 = " + y0_y1 + " x1_x2 = " + x1_x2 + " y1_y2 = " + y1_y2 + " x2_x0 = " + x2_x0 + " y2_y0 =" + y2_y0); double e1 = Math.sqrt(x0_x1 + y0_y1); double e2 = Math.sqrt(x1_x2 + y1_y2); double e3 = Math.sqrt(x2_x0 + y2_y0); String edges = "The Edge E1 = " + e1 + " E2 = " + e2 + " E3 = " + e3; String res = "The 1st Nearest posX = " + newPositionX + " posY = " + newPositionY; String mOnLine = (String) list.get(0).get(WifiReferencePointVO.PATH_NUMBER); Log.i(TAG, "" + res); Log.i(TAG, "on Line: " + mOnLine); act.setCurrentLocation(newPositionX, newPositionY, rssi); }
private void setTestingData(int rssi[]) { // TODO Auto-generated method stub Log.i(TAG, "setTestingData BEGIN"); testingModeScanCount++; currentScanCount = 0; TestingModeProxy tmProxy = new TestingModeProxy(act); tmProxy.initDB(); WifiReferencePointProxy proxy = new WifiReferencePointProxy(act); proxy.initDB(); ArrayList<HashMap> list = new ArrayList<HashMap>(); list = proxy.queryReferencePointDis(scanDataList); Collections.sort( list, new Comparator<HashMap>() { @Override public int compare(HashMap lhs, HashMap rhs) { // TODO Auto-generated method stub return (Integer) rhs.get(WifiReferencePointVO.DISTANCE) == (Integer) lhs.get(WifiReferencePointVO.DISTANCE) ? 0 : ((Integer) rhs.get(WifiReferencePointVO.DISTANCE) < (Integer) lhs.get(WifiReferencePointVO.DISTANCE) ? 1 : -1); } }); float newPositionX = (Float.parseFloat((String) list.get(0).get(WifiReferencePointVO.POSITION_X)) + Float.parseFloat((String) list.get(1).get(WifiReferencePointVO.POSITION_X)) + Float.parseFloat((String) list.get(2).get(WifiReferencePointVO.POSITION_X))) / 3; float newPositionY = (Float.parseFloat((String) list.get(0).get(WifiReferencePointVO.POSITION_Y)) + Float.parseFloat((String) list.get(1).get(WifiReferencePointVO.POSITION_Y)) + Float.parseFloat((String) list.get(2).get(WifiReferencePointVO.POSITION_Y))) / 3; float dis = (float) Math.sqrt( (Math.pow((newPositionX - WifiReferencePointVO.lastPosX), 2) + (Math.pow((newPositionY - WifiReferencePointVO.lastPosY), 2)))); Log.i(TAG, "Distance between last and current point = " + dis); TestingModeVO tmVO = new TestingModeVO(); tmVO.mPosX = Float.toString(newPositionX); tmVO.mPosY = Float.toString(newPositionY); tmVO.mDis = Float.toString(dis); if (dis > maxDistance2M) { tmVO.mPosJump2M = "Y"; } else tmVO.mPosJump2M = "N"; if (dis > maxDistance3M) { tmVO.mPosJump3M = "Y"; } else tmVO.mPosJump3M = "N"; tmProxy.setTestingData(tmVO); if (testingModeScanCount >= maxTestCount) { tmProxy.closeDbAndCursor(); getTestingModeRes(); act.finishTestingMode(outOfDistanceCount2M, outOfDistanceCount3M); } else { act.wiFiManager.startScan(); } }