Exemple #1
0
 /// <inheritdoc/>
 public bool Equals(IReadingValues other)
 {
     return(null != other &&
            (IsTemperatureValid ? other.Temperature == Temperature : !other.IsTemperatureValid) &&
            (IsPressureValid ? other.Pressure == Pressure : !other.IsPressureValid) &&
            (IsHumidityValid ? other.Humidity == Humidity : !other.IsHumidityValid) &&
            (IsWindDirectionValid ? other.WindDirection == WindDirection : !other.IsWindDirectionValid) &&
            (IsWindSpeedValid ? other.WindSpeed == WindSpeed : !other.IsWindSpeedValid)
            );
 }
Exemple #2
0
 public ReadingValues(IReadingValues values)
 {
     if (null == values)
     {
         Temperature   = Double.NaN;
         Pressure      = Double.NaN;
         Humidity      = Double.NaN;
         WindDirection = Double.NaN;
         WindSpeed     = Double.NaN;
     }
     else
     {
         Temperature   = values.Temperature;
         Pressure      = values.Pressure;
         Humidity      = values.Humidity;
         WindDirection = values.WindDirection;
         WindSpeed     = values.WindSpeed;
     }
 }
Exemple #3
0
 public Reading(DateTime timeStamp, IReadingValues values)
     : base(values)
 {
     TimeStamp = timeStamp;
 }
Exemple #4
0
        public void SetValues(ISensor sensor, IReadingValues reading)
        {
            ReadingValuesConverter <IReadingValues, ReadingValues> converter = null;

            if (null != sensor)
            {
                int n;
                sensorNameLabel.Text = (Int32.TryParse(sensor.Name, out n) && 0 <= n && n < 26)
                                        ? ((char)((byte)('A') + (byte)n)).ToString()
                                        : sensor.Name;
                if (null != ConverterCache && sensor is ISensorInfo)
                {
                    var si = sensor as ISensorInfo;
                    converter = ConverterCache.Get(
                        si.TemperatureUnit, TemperatureUnit,
                        si.SpeedUnit, SpeedUnit,
                        si.PressureUnit, PressureUnit
                        );
                }
            }
            else
            {
                sensorNameLabel.Text = "Sensor";
            }

            const string na = "N/A";

            if (null != reading && reading.IsValid)
            {
                var data = null == converter
                                    ? reading
                                    : converter.Convert(reading)
                ;

                string tempText;
                if (data.IsTemperatureValid)
                {
                    tempText = data.Temperature.ToString("F1") + ' ' + UnitUtility.GetFriendlyName(TemperatureUnit);
                }
                else
                {
                    tempText = na;
                }

                string presText;
                if (data.IsPressureValid)
                {
                    var presUnit = PressureUnit;
                    presText = Math.Round(data.Pressure, presUnit == PressureUnit.Millibar ? 1 : 2).ToString()
                               + ' '
                               + UnitUtility.GetFriendlyName(presUnit)
                    ;
                }
                else
                {
                    presText = na;
                }

                string speedText;
                if (data.IsWindSpeedValid)
                {
                    speedText = data.WindSpeed.ToString("F2") + ' ' + UnitUtility.GetFriendlyName(SpeedUnit);
                }
                else
                {
                    speedText = na;
                }

                string dirText;
                if (data.IsWindDirectionValid)
                {
                    dirText = Math.Round(data.WindDirection).ToString()
                              + "\xb0 "
                              + Vector2D.CardinalDirection.DegreesToBestCardinalName(reading.WindDirection)
                    ;
                }
                else
                {
                    dirText = na;
                }

                tempValue.Text     = tempText;
                pressureValue.Text = presText;
                humidityValue.Text = data.IsHumidityValid
                                        ? (Math.Round(data.Humidity * 100.0, 1).ToString() + '%')
                                        : na
                ;
                windSpeedValue.Text = speedText;
                windDirValue.Text   = dirText;
            }
            else
            {
                tempValue.Text      = na;
                pressureValue.Text  = na;
                humidityValue.Text  = na;
                windSpeedValue.Text = na;
                windDirValue.Text   = na;
            }
        }
Exemple #5
0
        public void SetValues(ISensor sensor, IReadingValues reading)
        {
            ReadingValuesConverter<IReadingValues, ReadingValues> converter = null;
            if (null != sensor) {
                int n;
                sensorNameLabel.Text = (Int32.TryParse(sensor.Name, out n) && 0 <= n && n < 26)
                    ? ((char) ((byte) ('A') + (byte) n)).ToString()
                    : sensor.Name;
                if(null != ConverterCache && sensor is ISensorInfo) {
                    var si = sensor as ISensorInfo;
                    converter = ConverterCache.Get(
                        si.TemperatureUnit, TemperatureUnit,
                        si.SpeedUnit, SpeedUnit,
                        si.PressureUnit, PressureUnit
                    );
                }
            }
            else {
                sensorNameLabel.Text = "Sensor";
            }

            const string na = "N/A";
            if (null != reading && reading.IsValid) {
                var data = null == converter
                    ? reading
                    : converter.Convert(reading)
                ;

                string tempText;
                if(data.IsTemperatureValid) {
                    tempText = data.Temperature.ToString("F1") + ' ' + UnitUtility.GetFriendlyName(TemperatureUnit);
                }else {
                    tempText = na;
                }

                string presText;
                if(data.IsPressureValid) {
                    var presUnit = PressureUnit;
                    presText = Math.Round(data.Pressure,presUnit == PressureUnit.Millibar ? 1 : 2).ToString()
                        + ' '
                        + UnitUtility.GetFriendlyName(presUnit)
                    ;
                }else {
                    presText = na;
                }

                string speedText;
                if(data.IsWindSpeedValid) {
                    speedText = data.WindSpeed.ToString("F2") + ' ' + UnitUtility.GetFriendlyName(SpeedUnit);
                }else {
                    speedText = na;
                }

                string dirText;
                if(data.IsWindDirectionValid) {
                    dirText = Math.Round(data.WindDirection).ToString()
                        + "\xb0 "
                        + Vector2D.CardinalDirection.DegreesToBestCardinalName(reading.WindDirection)
                    ;

                }else {
                    dirText = na;
                }

                tempValue.Text = tempText;
                pressureValue.Text = presText;
                humidityValue.Text = data.IsHumidityValid
                    ? (Math.Round(data.Humidity * 100.0, 1).ToString() + '%')
                    : na
                ;
                windSpeedValue.Text = speedText;
                windDirValue.Text = dirText;

            }
            else {
                tempValue.Text = na;
                pressureValue.Text = na;
                humidityValue.Text = na;
                windSpeedValue.Text = na;
                windDirValue.Text = na;
            }
        }
Exemple #6
0
            public static PackedReading GetCurrentReading(DateTime now, Random rand, IReadingValues lastReading)
            {
                double averagePressure = 1014.23;
                double pressureRange   = 100.0;

                double pressure         = (rand.NextDouble() * pressureRange) - (pressureRange / 2) + averagePressure;
                double windDirectionRad = (rand.NextDouble() * Math.PI * 2.0);


                //double windDirectionDeg = Vector2D.RadiansToDegrees(windDirectionRad);
                //Vector2D windDirectionVec = new Vector2D((Math.Cos(windDirectionRad) * 2.0), (Math.Sin(windDirectionRad) * 2.0));
                //double windDirectionDeg = windDirectionVec.GetNorthRelativeClockwiseAngularDegrees();


                double averageWindSpeed = 9;
                double averageTemp      = 51.0;
                double tempRange        = 10.0;
                double averageHumM      = 79;
                double averageHumA      = 58;

                switch (now.Month)
                {
                case 1: {
                    averageWindSpeed = 10.4;
                    averageTemp      = 27.5;
                    averageHumM      = 77;
                    averageHumA      = 66;
                    break;
                }

                case 2: {
                    averageWindSpeed = 10.3;
                    averageTemp      = 30.5;
                    averageHumM      = 75;
                    averageHumA      = 62;
                    break;
                }

                case 3: {
                    averageWindSpeed = 10.6;
                    averageTemp      = 39.8;
                    averageHumM      = 76;
                    averageHumA      = 57;
                    break;
                }

                case 4: {
                    averageWindSpeed = 10.2;
                    averageTemp      = 49.9;
                    averageHumM      = 74;
                    averageHumA      = 51;
                    break;
                }

                case 5: {
                    averageWindSpeed = 8.7;
                    averageTemp      = 60.0;
                    averageHumM      = 77;
                    averageHumA      = 52;
                    break;
                }

                case 6: {
                    averageWindSpeed = 8;
                    averageTemp      = 68.4;
                    averageHumM      = 80;
                    averageHumA      = 53;
                    break;
                }

                case 7: {
                    averageWindSpeed = 7.3;
                    averageTemp      = 72.6;
                    averageHumM      = 83;
                    averageHumA      = 54;
                    break;
                }

                case 8: {
                    averageWindSpeed = 6.8;
                    averageTemp      = 71;
                    averageHumM      = 86;
                    averageHumA      = 56;
                    break;
                }

                case 9: {
                    averageWindSpeed = 7.4;
                    averageTemp      = 64.0;
                    averageHumM      = 87;
                    averageHumA      = 57;
                    break;
                }

                case 10: {
                    averageWindSpeed = 8.3;
                    averageTemp      = 52.5;
                    averageHumM      = 82;
                    averageHumA      = 55;
                    break;
                }

                case 11: {
                    averageWindSpeed = 9.7;
                    averageTemp      = 42.3;
                    averageHumM      = 79;
                    averageHumA      = 62;
                    break;
                }

                case 12: {
                    averageWindSpeed = 10.1;
                    averageTemp      = 32.5;
                    averageHumM      = 78;
                    averageHumA      = 67;
                    break;
                }
                }
                averageTemp      = UnitUtility.ConvertUnit(averageTemp, TemperatureUnit.Fahrenheit, TemperatureUnit.Celsius);
                tempRange        = 4;
                averageWindSpeed = UnitUtility.ConvertUnit(averageWindSpeed, SpeedUnit.MilesPerHour, SpeedUnit.MetersPerSec) * 4.0;

                double humidityRange = Math.Abs(averageHumM - averageHumA) * 1.5;
                double humidity      = (humidityRange * rand.NextDouble()) - (humidityRange / 2.0) + ((averageHumM + averageHumA) / 2.0);

                humidity /= 100.0;
                double temp = (rand.NextDouble() * tempRange) - (tempRange / 2.0) + averageTemp;

                double windSpeed = rand.NextDouble();

                windSpeed = (windSpeed > 0.5) ? 0 : 4.0 * averageWindSpeed * windSpeed * windSpeed;

                double windDirectionDeg = (((rand.NextDouble() * 360.0) * 4) + 90) / 5.0;           // 4 parts random, 1 part 90 degrees

                var newValues = new ReadingValues(
                    temp,
                    pressure,
                    humidity,
                    windDirectionDeg,
                    windSpeed
                    );

                if (null != lastReading && lastReading.IsValid)
                {
                    var readings = new[] { lastReading, lastReading, lastReading, newValues };

                    var meanCalc = new ReadingValuesMeanCalculator <IReadingValues>();
                }

                var stamp = now.Date.Add(new TimeSpan(now.Hour, now.Minute, now.Second));

                return(new PackedReading(
                           stamp,
                           new PackedReadingValues(newValues)
                           ));
            }
Exemple #7
0
 public Reading(DateTime timeStamp, IReadingValues values)
     : base(values)
 {
     TimeStamp = timeStamp;
 }