Ejemplo n.º 1
0
        public override void Initialize(IList<IMeasure> input, ref Location currLocation, ref bool unknown)
        {
            using (var uow = ModelHelper.GetUnitOfWork())
            {
                var locations = uow.GetAll<Location>();
                if (locations.Count > 0)
                {
                    foreach (var location in locations)
                    {
                        if (location.TestInput(input) >= 0)
                        {
                            currLocation = location;

                            currLocation.StartActivities();

                            currLocation.SetUpCurrentTimeStats();

                            location.UpdateStats(input);
                            break;
                        }
                    }
                }
                uow.Commit();
            }

            if (currLocation == null)
            {
                currLocation = ModelHelper.EntitiesFactory
                                      .CreateLocation(LocationLocalizer.Unknown, input);
                unknown = true;
            }
        }
Ejemplo n.º 2
0
 private WherelessViewModel()
 {
     // Current Location is defaulted to Unknown. It will be updated by the LocationService
     _currentLocation = ModelHelper.EntitiesFactory.CreateLocation("Unknown");
     _currentLocation.TotalTime = 0;
     _locations = ModelHelper.GetLocationRepository().GetAll();
 }
Ejemplo n.º 3
0
 public override void ForceUnknown(IList<IMeasure> input, ref Location currLocation, ref bool unknown)
 {
     using (var uow = ModelHelper.GetUnitOfWork())
     {
         currLocation = ModelHelper.EntitiesFactory
                           .CreateLocation(LocationLocalizer.Unknown, input);
         unknown = true;
         uow.Commit();
     }
 }
Ejemplo n.º 4
0
        public override void ForceLocation(string name, IList<IMeasure> input, ref Location currLocation, ref bool unknown)
        {
            using (var uow = ModelHelper.GetUnitOfWork())
            {
                currLocation = uow.GetLocationByName(name);
                Debug.Assert(currLocation != null, "currLocation != null");

                currLocation.ForceLocation(input);

                currLocation.StartActivities();

                unknown = false;
                uow.Commit();
            }
        }
Ejemplo n.º 5
0
        public override void Initialize(IList<IMeasure> input, ref Location currLocation, ref bool unknown)
        {
            using (var uow = ModelHelper.GetUnitOfWork())
            {
                Location candidateLocation = null;
                var locations = uow.GetAll<Location>();
                if (locations.Count > 0)
                {
                    double min = Double.MaxValue;
                    foreach (var location in locations)
                    {
                        double curr = location.TestInput(input);
                        if (curr.CompareTo(0D) >= 0 && curr.CompareTo(min) < 0)
                        {
                            min = curr;
                            candidateLocation = location;
                        }
                    }
                    if (candidateLocation != null)
                    {
                        currLocation = candidateLocation;

                        currLocation.StartActivities();

                        currLocation.SetUpCurrentTimeStats();

                        currLocation.UpdateStats(input);
                    }
                }
                uow.Commit();
            }

            if (currLocation == null)
            {
                currLocation = ModelHelper.EntitiesFactory
                                      .CreateLocation(LocationLocalizer.Unknown, input);
                unknown = true;
            }
        }
Ejemplo n.º 6
0
 // REMARK Use it in the LocationService as delegate value
 public void UpdateCurrentLocation(Location location)
 {
     CurrentLocation = location;
     Log.Debug("ViewModel Current Location updated: " + location);
 }
Ejemplo n.º 7
0
        public void AddActivityToLocation(Location location, string activityName, string pathfile, string argument, string activityType)
        {
            var a = ModelHelper.EntitiesFactory.CreateActivity(activityName, pathfile, argument, activityType);

            location.AddActivity(a);
            var rep = ModelHelper.GetRepository<Location>();
            rep.Update(location);

            Log.Debug("Activity added to Location:" + location);
        }
Ejemplo n.º 8
0
        public override void Localize(IList<IMeasure> input, ref Location currLocation, ref bool unknown)
        {
            using (var uow = ModelHelper.GetUnitOfWork())
            {
                // currLocation may be updated by other threads
                if (!unknown)
                {
                    Log.Debug("Trying to retrieve Location " + currLocation.Name);
                    currLocation = uow.GetLocationByName(currLocation.Name);
                    Log.Debug(currLocation == null ? "Nothing Retrieved " : "Retrieved " + currLocation.Name);
                }

                // currLocation may be null if updated by others threads
                //it could also be unknown
                // proximity bias
                if (currLocation != null && !unknown && currLocation.TestInput(input) >= 0)
                {
                        currLocation.UpdateStats(input);
                }
                else
                {
                    String oldLocationName = null;
                    if (currLocation != null)
                    {
                        oldLocationName = currLocation.Name;
                    }
                    if (!unknown)
                    {
                        currLocation = null;
                    }

                    Log.Debug("Trying to retrieve all locations");
                    var locations = uow.GetAll<Location>();
                    Log.Debug("All locations retrieved");

                    if (locations.Count > 0)
                    {
                        foreach (var location in locations
                            .Where(location => oldLocationName == null || !location.Name.Equals(oldLocationName)))
                        {
                            if (location.TestInput(input) >= 0)
                            {
                                unknown = false;
                                currLocation = location;

                                currLocation.StartActivities();

                                currLocation.SetUpCurrentTimeStats();

                                location.UpdateStats(input);
                                break;
                            }
                        }
                    }

                    if (unknown)
                    {
                        Debug.Assert(currLocation != null, "currLocation != null");
                        if (currLocation.TestInput(input) >= 0)
                        {
                            currLocation.UpdateStats(input);
                        }
                        else
                        {
                            currLocation = null;
                        }
                    }
                    if (currLocation == null)
                    {
                        currLocation = ModelHelper.EntitiesFactory
                                                  .CreateLocation(LocationLocalizer.Unknown, input);
                        unknown = true;
                    }
                }
                uow.Commit();
            }
        }
Ejemplo n.º 9
0
 public override void RegisterLocation(string name, IList<IMeasure> input, ref Location currLocation, ref bool unknown)
 {
     using (var uow = ModelHelper.GetUnitOfWork())
     {
         if (!unknown)
         {
             currLocation = ModelHelper.EntitiesFactory
                                        .CreateLocation(name, input);
         }
         else
         {
             currLocation.Name = name;
             unknown = false;
         }
         uow.Save(currLocation);
         uow.Commit();
     }
 }
Ejemplo n.º 10
0
 public abstract void RegisterLocation(string name, IList<IMeasure> input, ref Location currLocation, ref bool unknown);
Ejemplo n.º 11
0
 public abstract void Localize(IList<IMeasure> input, ref Location currLocation, ref bool unknown);
Ejemplo n.º 12
0
 public abstract void ForceUnknown(IList<IMeasure> input, ref Location currLocation, ref bool unknown);
Ejemplo n.º 13
0
        public override void Localize(IList<IMeasure> input, ref Location currLocation, ref bool unknown)
        {
            using (var uow = ModelHelper.GetUnitOfWork())
            {
                // currLocation may be updated by other threads
                if (!unknown)
                {
                    Log.Debug("Trying to retrieve Location " + currLocation.Name);
                    currLocation = uow.GetLocationByName(currLocation.Name);
                    Log.Debug(currLocation == null ? "Nothing Retrieved " : "Retrieved " + currLocation.Name);

                    // Learning phase
                    if (currLocation != null && currLocation.GetObservations() <= LearningTresh)
                    {
                        Log.Debug("Learning Phase "+ currLocation.Name + ": step = " + currLocation.GetObservations());
                        currLocation.UpdateStats(input);
                        uow.Commit();
                        return;
                    }
                }

                Log.Debug("Trying to retrieve all locations");
                var locations = uow.GetAll<Location>();
                Log.Debug("All locations retrieved");

                Location candidateLocation = null;
                if (locations.Count > 0)
                {
                    double min = Double.MaxValue;
                    foreach (var location in locations)
                    {
                        double curr = location.TestInput(input);
                        if (curr.CompareTo(0D) >= 0 && curr.CompareTo(min) < 0)
                        {
                            candidateLocation = location;
                            min = curr;
                        }
                    }
                }

                if (candidateLocation != null)
                {
                    unknown = false;
                    if (currLocation == null || !currLocation.Name.Equals(candidateLocation.Name))
                    {
                        currLocation = candidateLocation;
                        currLocation.StartActivities();
                        currLocation.SetUpCurrentTimeStats();
                    }
                    Debug.Assert(currLocation.Name.Equals(candidateLocation.Name),
                                 "currLocation.Name.Equals(candidateLocation.Name)");
                    currLocation.UpdateStats(input);
                }
                else
                {
                    if (unknown)
                    {
                        Debug.Assert(currLocation != null, "currLocation != null");
                        if (currLocation.TestInput(input).CompareTo(0D) >= 0)
                        {
                            currLocation.UpdateStats(input);
                        }
                        else
                        {
                            unknown = false;
                        }
                    }

                    if (!unknown)
                    {
                        currLocation = ModelHelper.EntitiesFactory
                                                  .CreateLocation(LocationLocalizer.Unknown, input);
                        unknown = true;
                    }
                }
                uow.Commit();
            }
        }