Exemplo n.º 1
0
        public Return.LocationDate[] GetHistory(string id)
        {
            LocationDateDb[]      locs = new LocationDateDb[] { };
            Return.LocationDate[] ret;

            using (UserContext context = new UserContext())
            {
                User user = context.Users.FirstOrDefault(u => u.Name.Equals(id));

                if (user != null)
                {
                    user.Locations.Sort(new LocationDateComparer());

                    int floor = user.Locations[user.Locations.Count - 1].F;

                    int i = 1;
                    for (; i < user.Locations.Count; i++)
                    {
                        if (user.Locations[user.Locations.Count - i].F != floor)
                        {
                            i++;
                            break;
                        }
                    }


                    locs = user.Locations.Skip(user.Locations.Count - i).ToArray();
                }

                ret = locs.Select(x => new Return.LocationDate()
                {
                    Dat = new Date()
                    {
                        Year   = x.Year,
                        Month  = x.Month,
                        Day    = x.Day,
                        Hour   = x.Hour,
                        Minute = x.Minute,
                        Second = x.Second
                    },
                    Loc = new Location()
                    {
                        X = x.X,
                        Y = x.Y,
                        Z = x.Z,
                        F = x.F
                    },
                }).ToArray();
            }

            return(ret);
        }
Exemplo n.º 2
0
        public LocationDate GetLocation(string id, WirelessSignal[] signals)
        {
            ILocationPredictable pred = new RandomForest(CzyPrzemek ? RdataPrzemek : RdataPawel);

            foreach (var sig in signals)
            {
                sig.Id = sig.Id.Replace(":", ".");
                sig.Id = String.Concat("BSSID_", sig.Id);
            }

            int[] signal = new int[pred.Inputs.Length];

            for (int i = 0; i < pred.Inputs.Length; i++)
            {
                bool isSet = false;
                int  index = -1;
                for (int j = 0; j < signals.Length; j++)
                {
                    if (pred.Inputs[i].Equals(signals[j].Id))
                    {
                        isSet = true;
                        index = j;
                    }
                }
                if (isSet)
                {
                    signal[i] = signals[index].Value;
                }
                else
                {
                    signal[i] = pred.NAValue;
                }
            }

            Interfaces.Location loca = pred.PredictLocation(signal);
            loca.Y *= -1;
            LocationDateDb loc;
            DateTime       now;

            using (UserContext context = new UserContext())
            {
                User user = context.Users.FirstOrDefault(u => u.Name.Equals(id));
                if (user == null)
                {
                    user           = new User();
                    user.Name      = id;
                    user.Locations = new List <LocationDateDb>();
                    context.Users.Add(user);
                    context.SaveChanges();
                }
                user = context.Users.First(u => u.Name.Equals(id));

                now = DateTime.Now;
                loc = new LocationDateDb()
                {
                    X      = loca.X,
                    Y      = loca.Y,
                    Z      = loca.Z,
                    F      = loca.F,
                    Year   = now.Year,
                    Month  = now.Month,
                    Day    = now.Day,
                    Hour   = now.Hour,
                    Minute = now.Minute,
                    Second = now.Second,
                    UserId = user.Id,
                };

                user.Locations.Add(loc);



                context.SaveChanges();
            }

            //return loca;
            return(new LocationDate()
            {
                Loc = new Location()
                {
                    X = loc.X, Y = loc.Y, Z = loc.Z, F = loc.F
                },
                Dat = new Date()
                {
                    Year = now.Year, Month = now.Month, Hour = now.Hour, Minute = now.Minute, Second = now.Second
                }
            });

            #region not used

            //int smallest = -1, biggest = -1;
            //smallest = signals.Min(a => a.Value);
            //biggest = signals.Max(a => a.Value);

            //LocationDateDb l = new LocationDateDb()
            //{

            //        Year = 1991,
            //        Month = 5,
            //        Day = 29,
            //        Hour = 21,
            //        Minute = 40,
            //        Second = 0,

            //            X = 1.0,
            //            Y = 2.0,
            //            Z = biggest,
            //            F = smallest

            //};

            //using (var context = new UserContext())
            //{
            //    User user = context.Users.FirstOrDefault(u => u.Name.Equals(id));
            //    if (user == null)
            //    {
            //        user = new User();
            //        user.Locations = new List<LocationDateDb> {l};
            //    }
            //    else
            //    {
            //        user.Locations.Add(l);
            //    }

            //    context.Users.Add(user);
            //    context.SaveChanges();
            //}

            //return l;

            #endregion
        }