Example #1
0
        private PolarValue FindValue(State state)
        {
            //get the exact values from the state
            double windSpeed = state.StateValues [StateValue.TrueWindSpeedKnots];
            double windAngle = state.StateValues [StateValue.TrueWindAngle];

            //round/normalize them to fit in our polar
            NormalizeWind(ref windAngle, ref windSpeed);

            //find the existing segment in the graph (if it exists)
            var newPolarValue = new PolarValue()
            {
                TrueWindAngle      = windAngle,
                TrueWindSpeedKnots = windSpeed,
                SpeedInKnots       = state.StateValues[StateValue.SpeedInKnots],
                Time = state.BestTime
            };
            var existing = _connection.Query <PolarValue> ("select * from Polar where TrueWindAngle=@TrueWindAngle and TrueWindSpeedKnots<=@TrueWindSpeedKnots order by SpeedInKnots desc", newPolarValue).FirstOrDefault();

            return(existing);
        }
Example #2
0
        public void Record(State state)
        {
            //make sure we have the sensor data we need, otherwise there's no point
            if (StateHasRequiredValues(state))
            {
                //using (var transaction = new TransactionScope())
                {
                    var existing = FindValue(state);

                    if (existing != null)
                    {
                        if (existing.SpeedInKnots < state.StateValues [StateValue.SpeedInKnots])
                        {
                            existing.SpeedInKnots = state.StateValues [StateValue.SpeedInKnots];
                            existing.Time         = state.BestTime;
                            _connection.Execute("update Polar set SpeedInKnots=@SpeedInKnots,Time=@Time where Id=@Id", existing);
                        }
                    }
                    else
                    {
                        double speed = state.StateValues [StateValue.TrueWindSpeedKnots];
                        double angle = state.StateValues [StateValue.TrueWindAngle];
                        NormalizeWind(ref angle, ref speed);

                        var newValue = new PolarValue()
                        {
                            Time               = state.BestTime,
                            TrueWindAngle      = angle,
                            TrueWindSpeedKnots = speed,
                            SpeedInKnots       = state.StateValues [StateValue.SpeedInKnots]
                        };
                        _connection.Execute("insert into Polar(TrueWindAngle,TrueWindSpeedKnots,SpeedInKnots,Time) values (@TrueWindAngle,@TrueWindSpeedKnots,@SpeedInKnots,@Time)", newValue);
                    }
                    //transaction.Complete();
                }
            }
        }
Example #3
0
		public void Record (State state)
		{
			//make sure we have the sensor data we need, otherwise there's no point
			if (StateHasRequiredValues(state)) 
			{
				//using (var transaction = new TransactionScope()) 
				{
					var existing = FindValue (state);

					if (existing != null) 
					{
						if (existing.SpeedInKnots < state.StateValues [StateValue.SpeedInKnots]) 
						{
							existing.SpeedInKnots = state.StateValues [StateValue.SpeedInKnots];
							existing.Time = state.BestTime;
							_connection.Execute ("update Polar set SpeedInKnots=@SpeedInKnots,Time=@Time where Id=@Id", existing);
						}
					} 
					else 
					{
						double speed = state.StateValues [StateValue.TrueWindSpeedKnots];
						double angle = state.StateValues [StateValue.TrueWindAngle];
						NormalizeWind (ref angle, ref speed);

						var newValue = new PolarValue () 
						{
							Time = state.BestTime,
							TrueWindAngle = angle,
							TrueWindSpeedKnots = speed,
							SpeedInKnots = state.StateValues [StateValue.SpeedInKnots]
						};
						_connection.Execute ("insert into Polar(TrueWindAngle,TrueWindSpeedKnots,SpeedInKnots,Time) values (@TrueWindAngle,@TrueWindSpeedKnots,@SpeedInKnots,@Time)", newValue);
					}
					//transaction.Complete();
				}
			}
		}
Example #4
0
		private PolarValue FindValue (State state)
		{
			//get the exact values from the state
			double windSpeed = state.StateValues [StateValue.TrueWindSpeedKnots];
			double windAngle = state.StateValues [StateValue.TrueWindAngle];

			//round/normalize them to fit in our polar
			NormalizeWind (ref windAngle, ref windSpeed);

			//find the existing segment in the graph (if it exists)
			var newPolarValue = new PolarValue () {
				TrueWindAngle = windAngle,
				TrueWindSpeedKnots = windSpeed,
				SpeedInKnots = state.StateValues[StateValue.SpeedInKnots],
				Time = state.BestTime
			};
			var existing = _connection.Query<PolarValue> ("select * from Polar where TrueWindAngle=@TrueWindAngle and TrueWindSpeedKnots<=@TrueWindSpeedKnots order by SpeedInKnots desc", newPolarValue).FirstOrDefault();

			return existing;
		}