コード例 #1
0
        private static Building getNearestAPMatchBuilding(SnifferWifiMeasurement meas)
        {
            if (LoadedBuildings == null)
            {
                return(null);
            }
            if (meas == null)
            {
                return(null);
            }

            Building bestMatch = null;
            //find best match by matching number of common APs
            int maxCommonAPs = 0;

            foreach (Building curBuilding in LoadedBuildings)
            {
                int commonAPs = getNumberOfIdenticalMacs(meas.getMACs(), curBuilding);
                if (commonAPs > maxCommonAPs)
                {
                    maxCommonAPs = commonAPs;
                    bestMatch    = curBuilding;
                }
            }
            return(bestMatch);
        }
コード例 #2
0
        //Public visibility so we can test it (directly) via unit tests
        public static SnifferWifiMeasurement getNStrongestAPMeasurement(SnifferWifiMeasurement measurement, int n)
        {
            if (measurement.getMACs().Count < n)
            {
                return(measurement);
            }

            SortedDictionary <double, String> strongestAPs = new SortedDictionary <double, String>();

            //Find the n strongest macs
            //
            foreach (String mac in measurement.getMACs())     //all APs in sample
            {
                double curMacVal = measurement.getAvgDbM(mac);
                while (strongestAPs.ContainsKey(curMacVal))
                {
                    curMacVal += 0.0001;
                }

                strongestAPs.Add(curMacVal, mac);

                //NB: TreeMap sorts members in ascending order!
                //Thus, we remove from the head to keep the strongest values
                if (strongestAPs.Count > n)
                {
                    strongestAPs.Remove(strongestAPs.First().Key);
                }
            }

            //Create new measurement containing n strongest macs
            SnifferWifiMeasurement result = new SnifferWifiMeasurement();

            foreach (double d in strongestAPs.Keys)
            {
                SnifferHistogram h = new SnifferHistogram();
                h.Mac   = strongestAPs[d];
                h.value = (int)d;
                h.count = 1;
                result.SnifferHistograms.Add(h);
                //result.addValue(strongestAPs.get(d), (int)d);
            }
            return(result);
        }
コード例 #3
0
        public EstimateResult compare(IEnumerable <Vertex> vertices, SnifferWifiMeasurement measurement)
        {
            measurement = getNStrongestAPMeasurement(measurement, 7);

            if (vertices == null || measurement == null)
            {
                return(null);
            }

            bcs = WifiPosEngine.BestCandidateSet; //new BCS(5); //bcs.clear();

            double         curDist;               //distance of current vertice in search space
            EstimateResult result = new EstimateResult(null, double.MaxValue);

            foreach (Vertex curVertex in vertices)                                          //sammenlign med hver Vertex
            {
                foreach (SnifferWifiMeasurement curFP in curVertex.SnifferWifiMeasurements) //sammenlign med hvert fingerprint (usually only one - otherwise use more intelligent approach)
                {
                    curDist = 0;
                    foreach (String mac in measurement.getMACs())             //all APs in sample
                    {
                        if (curFP.containsMac(mac))
                        {
                            curDist += Math.Pow((measurement.getAvgDbM(mac) - curFP.getAvgDbM(mac)), 2);
                        }
                        else
                        {
                            curDist += Math.Pow((measurement.getAvgDbM(mac) - MISSING_MAC_PENALTY), 2);
                        }
                    }

                    curDist = Math.Sqrt(curDist);
                    if (curDist < result.getDistance())
                    {
                        result.setDistance(curDist);
                        result.setVertex(curVertex);
                    }
                    bcs.add(curVertex, curDist);             //add to best candidate set - which will take care of only using the best estimates.
                }
            }
            //The following only yields a local error estimate within the primary- or secondary
            //vertices and may thus not be appropriate
            result.setErrorEstimate(Math.Ceiling(bcs.getMaxDistance()));
            return(result);
        }