public IQueryable <Building> RemoveNonCollectiveMeasurements(int building_id)
        {
            //IQueryable containing at most one entry
            IQueryable <Building> foundBuildings = CurrentDataSource.Buildings.Where(b => b.ID == building_id);

            if (foundBuildings != null)
            {
                foreach (Building building in foundBuildings)
                {
                    foreach (Vertex v in building.Vertices)
                    {
                        //Build a collective measurement or an empty measurement
                        WifiMeasurement collectiveWifi = BuildCollectiveWifiMeasurement(v);
                        WifiMeasurement lightWifi;
                        if (collectiveWifi == null)
                        {
                            lightWifi = new WifiMeasurement();
                        }
                        else
                        {
                            lightWifi = createLightWeightMeasurement(collectiveWifi);
                        }

                        v.WifiMeasurements.Clear();
                        v.WifiMeasurements.Add(lightWifi);
                    }
                }
            }
            return(foundBuildings);
        }
Exemplo n.º 2
0
 public bool removeFingerprint(WifiMeasurement value)
 {
     if (!fingerprints.Contains(value))
     {
         return(false);
     }
     return(fingerprints.Remove(value));
 }
Exemplo n.º 3
0
        public bool addFingerprint(WifiMeasurement value)
        {
            if (fingerprints == null)
            {
                return(false);
            }
            if (value == null)
            {
                return(false);
            }

            fingerprints.Add(value);
            return(true);
        }
        private void updateCollectiveWifiMeasurement(Vertex source)
        {
            if (source == null)
            {
                return;
            }
            if (source.WifiMeasurements.Count < 1)
            {
                return;
            }

            WifiMeasurement collectiveWifi = new WifiMeasurement();

            collectiveWifi.Is_Collective = true;

            //1. Build collective measurement based on existing measurements for the source vertex.
            foreach (WifiMeasurement wifi in source.WifiMeasurements)
            {
                //ignore collective measurements (and cancel previous - but don't delete yet)
                if (wifi.Is_Collective == true) //HACK, until we get a better approach (requires schema change and cascading delete, wifi-meas id must be part of prim key of hist)
                {
                    wifi.Is_Collective  = false;
                    wifi.Was_Collective = true;
                    continue;
                }
                if (wifi.Was_Collective == true)
                {
                    continue;
                }
                Histogram curHist;
                foreach (Histogram hist in wifi.Histograms)
                {
                    curHist = collectiveWifi.Histograms.FirstOrDefault(h => h.Mac == hist.Mac && h.value == hist.value);
                    if (curHist == null) //insert new histogram (ap, val)
                    {
                        curHist       = new Histogram();
                        curHist.Mac   = hist.Mac;
                        curHist.value = hist.value;
                        curHist.count = 0;
                        collectiveWifi.Histograms.Add(curHist);
                    }
                    curHist.count += hist.count; //update count for (ap, val)
                }
            }
            source.WifiMeasurements.Add(collectiveWifi);

            this.CurrentDataSource.SaveChanges();
        }
        //Here we build a lightweight histogram by taking the (mac, (value,count)) to find the avg value
        //Result: Histogram with (mac, (avg-value, count=1))
        private WifiMeasurement createLightWeightMeasurement(WifiMeasurement orgMeas)
        {
            if (orgMeas == null)
            {
                return(null);
            }

            WifiMeasurement newMeas = new WifiMeasurement();

            newMeas.ID              = orgMeas.ID;
            newMeas.Vertex_ID       = orgMeas.Vertex_ID;
            newMeas.meas_time_start = orgMeas.meas_time_start;
            newMeas.meas_time_end   = orgMeas.meas_time_end;

            Dictionary <String, int> macTotalValue = new Dictionary <string, int>();
            Dictionary <String, int> macTotalCount = new Dictionary <string, int>();

            foreach (Histogram h in orgMeas.Histograms)
            {
                if (!macTotalValue.ContainsKey(h.Mac))
                {
                    macTotalValue.Add(h.Mac, 0);
                    macTotalCount.Add(h.Mac, 0);
                }
                macTotalValue[h.Mac] += Math.Abs(h.value) * h.count;
                macTotalCount[h.Mac] += Math.Abs(h.count);
            }
            foreach (String mac in macTotalValue.Keys)
            {
                Histogram newHist = new Histogram();
                newHist.Mac   = mac;
                newHist.value = -(macTotalValue[mac] / macTotalCount[mac]);
                newHist.count = 1;
                newMeas.Histograms.Add(newHist);
            }
            return(newMeas);
        }
Exemplo n.º 6
0
 public void AddToWifiMeasurements(WifiMeasurement wifiMeasurement)
 {
     base.AddObject("WifiMeasurements", wifiMeasurement);
 }
Exemplo n.º 7
0
 public static WifiMeasurement CreateWifiMeasurement(int ID, int vertex_ID)
 {
     WifiMeasurement wifiMeasurement = new WifiMeasurement();
     wifiMeasurement.ID = ID;
     wifiMeasurement.Vertex_ID = vertex_ID;
     return wifiMeasurement;
 }