Esempio n. 1
0
        public void Setup()
        {
            _mock = new Mock <IRunningTrackerDataAccess>();
            List <RunningData> testRunningData = new List <RunningData>();

            testRunningData.Add(new RunningData(new PersonalData()));
            testRunningData.Add(new RunningData(new PersonalData(Gender.Female, 150, 50)));

            RunningData testData = new RunningData(new PersonalData());

            testData.AddLocation(new LocationData(20, 10, 0, 100, 50, 40));
            testData.AddLocation(new LocationData(100, 110, 0, 100, 50, 40));
            testRunningData.Add(testData);

            _mock.Setup(mock => mock.LoadPreviousRunnings()).Returns(testRunningData);

            WarningValues warningValues = new WarningValues();

            _mock.SetupGet(mock => mock.CurrentWarningValues).Returns(warningValues);

            _model = new RunningTrackerModel(_mock.Object);


            _model.GpsReady    += Model_GPS_Ready;
            _model.Warning     += Model_Warning;
            _model.UserStopped += Model_UserStopped;
        }
Esempio n. 2
0
        public void Initialize()
        {
            _mock = new Mock <IRunningTrackerDataAccess>();
            List <RunningData> testRunningData = new List <RunningData>();

            testRunningData.Add(new RunningData(new PersonalData()));
            testRunningData.Add(new RunningData(new PersonalData(Gender.Female, 150, 50)));

            RunningData testData = new RunningData(new PersonalData());

            testData.AddLocation(new LocationData(20, 10, 0, 100, 50, 40));
            testData.AddLocation(new LocationData(100, 110, 0, 100, 50, 40));
            testRunningData.Add(testData);

            _mock.Setup(mock => mock.LoadPreviousRunnings()).Returns(testRunningData);

            _model = new RunningTrackerModel(_mock.Object);
        }
Esempio n. 3
0
        /// <summary>
        /// Change the user's location
        /// </summary>
        /// <param name="location">New location</param>
        public void ChangeLocation(Location location)
        {
            if (_remaningCalibratingLocation > 0)
            {
                // Calibrating the gps
                if (location.Accuracy <= DefaultGpsAccuracy)
                {
                    _remaningCalibratingLocation--;
                }

                if (_remaningCalibratingLocation == 0)
                {
                    OnGPS_Ready(new LocationData(location.Longitude, location.Latitude));
                }
            }
            else
            {
                // The gps is calibrated
                if (_runningEnd)
                {
                    return;
                }

                if (location.Accuracy > DefaultGpsAccuracy)
                {
                    return;
                }

                if (_runningData == null)
                {
                    // The running is not started
                    if (location.Speed > 0)
                    {
                        OnUserPosition(new LocationData(location.Longitude, location.Latitude));
                        OnCameraPosition(new LocationData(location.Longitude, location.Latitude));
                    }
                    return;
                }

                OnUserPosition(new LocationData(location.Longitude, location.Latitude));

                // Reduce the warning frequencies
                if (_speedWarningFrequency > 0)
                {
                    _speedWarningFrequency--;
                }


                if (location.Speed == 0)
                {
                    if (_numOfContinuouslyStopsForSignal >= 0)
                    {
                        // If the var was 0 that will be -1, so the signal won't be sent again
                        _numOfContinuouslyStopsForSignal--;
                    }

                    if (_numOfContinuouslyStopsForSignal == 0)
                    {
                        bool near = false;
                        foreach (Position coordinate in _runningData.Stops)
                        {
                            near = location.DistanceTo(new Location("gps")
                            {
                                Longitude = coordinate.Longitude, Latitude = coordinate.Latitude
                            }) < 3 * 14;
                        }

                        if (!near)
                        {
                            OnUserStopped(new LocationData(location.Longitude, location.Latitude, 0, 0, 0, 0, RunningSpeed.Slow));
                            _runningData.AddStop(new Position(location.Latitude, location.Longitude));
                        }
                    }
                }
                else
                {
                    _numOfContinuouslyStopsForSignal = NumOfContinuouslyStopsForSignal;
                }

                // If the user's position is not changed do nothing
                if (_previousLocation != null && location.Speed == 0)
                {
                    return;
                }

                if (_checkVerticalDistanceRemaining == 0)
                {
                    _oldLocation = location;
                }

                _checkVerticalDistanceRemaining++;

                _previousLocation = _currentLocation;
                _currentLocation  = location;

                double distance         = 0;
                double verticalDistance = 0;

                if (_previousLocation != null)
                {
                    distance = _currentLocation.DistanceTo(_previousLocation);

                    if (_checkVerticalDistanceRemaining % NumOfCheckVerticalDistance == 0)
                    {
                        verticalDistance = _currentLocation.Altitude - _oldLocation.Altitude;
                        _checkVerticalDistanceRemaining = 0;
                    }
                }

                double up   = 0;
                double down = 0;

                if (verticalDistance > 0)
                {
                    up = verticalDistance;
                }
                else
                {
                    down = -verticalDistance;
                }

                double speed = location.Speed * 3.6;

                RunningSpeed runningSpeed;

                if (_remaningSameColor == 0)
                {
                    if (speed < CurrentWarningValues.MinimumSpeed)
                    {
                        runningSpeed = RunningSpeed.Slow;
                    }
                    else if (speed > CurrentWarningValues.MaximumSpeed)
                    {
                        runningSpeed = RunningSpeed.Fast;
                    }
                    else
                    {
                        runningSpeed = RunningSpeed.Normal;
                    }

                    if (runningSpeed != _previousRunningSpeed && _previousRunningSpeed != RunningSpeed.StartPoint)
                    {
                        _remaningSameColor = MinLengthOfSameColor;
                    }
                }
                else
                {
                    _remaningSameColor--;
                    runningSpeed = _previousRunningSpeed;
                }

                _previousRunningSpeed = runningSpeed;

                LocationData currentLocationData = new LocationData(location.Longitude, location.Latitude, speed, distance, up, down, runningSpeed);
                _runningData.AddLocation(currentLocationData);

                OnNewPosition(currentLocationData);

                // Send warning signals
                if (!_timeWarningYet && _runningData.Duration > CurrentWarningValues.Time)
                {
                    _timeWarningYet = true;
                    OnWarning(WarningType.Time);
                }

                if (!_distanceWarningYet && _runningData.Distance > CurrentWarningValues.Distance)
                {
                    _distanceWarningYet = true;
                    OnWarning(WarningType.Distance);
                }

                if (_speedWarningFrequency == 0)
                {
                    if (_currentLocation.Speed * 3.6 < CurrentWarningValues.MinimumSpeed)
                    {
                        _speedWarningFrequency = SpeedWarningFrequency;
                        OnWarning(WarningType.SpeedSlow);
                    }

                    if (_currentLocation.Speed * 3.6 > CurrentWarningValues.MaximumSpeed)
                    {
                        _speedWarningFrequency = SpeedWarningFrequency;
                        OnWarning(WarningType.SpeedFast);
                    }
                }
            }
        }