public ITemperature Convert(ITemperature temperature, Unit unit) { if (converterFactory == null) { throw new Exception("There is no converters defined."); } if (temperature.Unit == unit) { return(temperature); } ITemperature tempInKelvin; if (temperature.Unit == Unit.Kelvin) { tempInKelvin = temperature; } else { var fromConverter = GetConverter(temperature.Unit); tempInKelvin = fromConverter.ToKelvin(temperature); } if (unit == Unit.Kelvin) { return(tempInKelvin); } var toConverter = GetConverter(unit); return(toConverter.FromKelvin(tempInKelvin)); }
protected void UpdateLastTemperature() { LastTemperature = TemperatureService.Current(); UpdateTemperatureUI(); UpdateTimestampUI(); }
public static ControlThinkTemperature?ToControlThinkType(this ITemperature input) { if (input == null) { return(null); } decimal value; ControlThinkTemperatureScale scale; if (input is FahrenheitTemperature) { value = (int)Math.Round(input.Value); scale = ControlThinkTemperatureScale.Fahrenheit; } else { value = (int)(Math.Round(input.Celsius.Value)); scale = ControlThinkTemperatureScale.Celsius; } var result = new ControlThinkTemperature(value, scale); return(result); }
public void SetSetpoint(ThermostatSetpointType setpointType, ITemperature temperature) { var controlThinkSetpointType = setpointType.ToControlThinkType().Value; var controlThinkTemperature = temperature.ToControlThinkType().Value; _device.DoDeviceOperation(() => _thermostat.ThermostatSetpoints[controlThinkSetpointType].Temperature = controlThinkTemperature); }
public MainViewModel(IAccelerometer accelerometer = null, IGyroscope gyroscope = null, IMagnetometer magnetometer = null, ICompass compass = null, IAmbientLight ambientLight = null, IBarometer barometer = null, IPedometer pedometer = null, IProximity proximity = null, IHeartRateMonitor heartRate = null, IHumidity humidity = null, ITemperature temperature = null) { this.Sensors = new List <ISensorViewModel>(); this.AddIf(accelerometer, "G"); this.AddIf(gyroscope, "G"); this.AddIf(magnetometer, "M"); this.AddIf(compass, "D"); this.AddIf(ambientLight, "Light"); this.AddIf(barometer, "Pressure"); this.AddIf(pedometer, "Steps"); this.AddIf(proximity, "Near"); this.AddIf(heartRate, "Heart Rate (bpm)"); this.AddIf(humidity, "Humidity"); this.AddIf(temperature, "Temp"); }
/// <summary> /// Calculates the CO2 assimilated by the partial canopy during photosynthesis, /// and the water used by the process /// </summary> public void DoPhotosynthesis(ITemperature temperature, Transpiration transpiration) { // Initialise at the current temperature pathways.ForEach(p => p.SetConditions(temperature.AirTemperature, LAI)); // Determine initial results UpdateAssimilation(transpiration); // Store the initial results in case the subsequent updates fail CO2AssimilationRate = GetCO2Rate(); WaterUse = GetWaterUse(); // Only attempt to converge result if there is sufficient assimilation if (CO2AssimilationRate < 0.5 || WaterUse == 0) { return; } // Repeat calculation 3 times to let solution converge for (int n = 0; n < 3; n++) { UpdateAssimilation(transpiration); // If the additional updates fail, stop the process (meaning the initial results used) if (GetCO2Rate() == 0 || GetWaterUse() == 0) { return; } } // Update results only if convergence succeeds CO2AssimilationRate = GetCO2Rate(); WaterUse = GetWaterUse(); }
public static T TemperatureConvert <T>(this ITemperature current) where T : ITemperature, new() { T obj = new T(); // if conversion of same types if (current.GetType() == typeof(T)) { obj.Value = current.Value; } // converting to kelvin if (obj.GetType() == typeof(Kelvin)) { obj.Value = current.GetType() == typeof(Celsius) ? current.Value + 273.15 : (current.Value + 459.67) * (5.0 / 9.0); } // converting to Celcius if (obj.GetType() == typeof(Celsius)) { obj.Value = current.GetType() == typeof(Kelvin) ? current.Value - 273.15 : (current.Value - 32) * (5.0 / 9.0); } if (obj.GetType() == typeof(Fahrenheit)) { obj.Value = current.GetType() == typeof(Kelvin) ? ((current.Value * (9.0 / 5.0)) - 459.67) : (current.Value * (9.0 / 5.0) + 32); } // Automatically round to 2 precicision points obj.Value = Math.Round(obj.Value, 2); return(obj); }
public static TimeSpan Next(ITemperature lastTemperature, DateTime now) { // when no temperature was stored yet if (lastTemperature == null) { return(TimeSpan.Zero); } // when it's after 20:00, plan for tomorrow 6:53 if (now.Hour >= 20) { return(now.Date.AddDays(1).AddHours(6).AddMinutes(53) - now); } // when it's before 6:53, plan for this date if (now.Hour <= 6 && now.Minute < 53) { return(now.Date.AddHours(6).AddMinutes(53) - now); } // when last temperature is older than 1 hour if ((now - lastTemperature.MeasuredAt) > TimeSpan.FromHours(1)) { return(TimeSpan.Zero); } // plan next retreival for next hour at XX:53 if (now.Minute > 53) { return(now.Date.AddHours(now.Hour + 1).AddMinutes(53) - now); } // this hour at XX:53 return(now.Date.AddHours(now.Hour).AddMinutes(53) - now); }
private void PrintAdapterResults(ITemperature target) { var c = target.GetTemperature(TemperatureType.C); var k = target.GetTemperature(TemperatureType.K); var f = target.GetTemperature(TemperatureType.F); Console.WriteLine($"Adapter: C = {c}, K = {k}, F = {f}"); }
public string Get(string id, string temp, string wind) { new ApplicationAction("Starting Weather Api Calls", "user", "WeatherTest for " + id).Save(); new ApplicationAction("Using AutoFac", "user", "DI using a Framework").Save(); //Dependency Injection with framework Autofac var builder = new ContainerBuilder(); builder.RegisterType <ProcessApi>().As <IProcessApi>(); builder.RegisterType <Config>().As <IConfig>(); IContainer Container = builder.Build(); TempType UserSelectTemp = (TempType)Enum.Parse(typeof(TempType), temp.ToUpper()); WindType UserSelectWind = (WindType)Enum.Parse(typeof(WindType), wind.ToUpper()); //List of Apis to call all based on the Strategy pattern var WeatherApis = new List <IWeatherStrategy>(); // add new API which would have been created - TODO make this a dynaimc process so this file does not need to be edited WeatherApis.Add(new WeatherDataCollectorBbc()); WeatherApis.Add(new WeatherDataCollectorAccu()); new ApplicationAction("Added Apis", "user", "Two Apis").Save(); //List to hold API call data var LocationDataSets = new List <string>(); using (var scope = Container.BeginLifetimeScope()) { foreach (IWeatherStrategy api in WeatherApis) { // call each of the APIs and store the result LocationDataSets.Add(api.gatherData(id, scope.Resolve <IProcessApi>(), scope.Resolve <IConfig>())); } } new ApplicationAction("Creating objects", "user", "Using factory pattern").Save(); ITemperatureFactory tempFactory = new TemperatureFactory(); ITemperature selectedTemp = tempFactory.CreateTemperature(UserSelectTemp); IWindFactory windFactory = new WindFactory(); IWind selectedWind = windFactory.CreateWind(UserSelectWind); new ApplicationAction("Calcuating results", "user", "Aggregated result data").Save(); //call the aggregator to work out the results var calculatedLocationWeather = new Aggregator(selectedTemp, selectedWind).AggregateData(LocationDataSets); calculatedLocationWeather.Location = id; new ApplicationAction("Completed prcoessing", "user", "TReturn data to client").Save(); //return to client final result return(JsonConvert.SerializeObject(calculatedLocationWeather)); }
public virtual void UpdateTemperature(ITemperature temperature) { if (Temperature.Unit != temperature.Unit) { throw new Exception(string.Format("Sorry this is a basic thermometer. A {0} unit was recieved but the thermometer is set to {1} unit.", temperature.Unit, ThermometerUnit)); } Temperature = temperature; }
public void Execute(IDataCommand dataCommand) { ITemperature control = dataCommand.GetDevice() as ITemperature; if (control != null) { control.DecrementTemperature(); } }
public void Undo(IDataCommand dataCommand) { ITemperature control = dataCommand.GetDevice() as ITemperature; if (control != null) { control.IncrementTemperature(); } }
private void ConvertFromCelsius(CelsiusTemperature celsiusTemperature, ref ITemperature output) { switch (output) { case FahrenheitTemperature fahrenheitTemperature: fahrenheitTemperature.SetValue(celsiusTemperature.Value * 1.8 + 32); break; } }
public static Temperature CreateFrom(ITemperature temperature) { return(new Temperature { Swimmer = temperature.Swimmer, NonSwimmer = temperature.NonSwimmer, KidSplash = temperature.KidSplash, MeasuredAt = temperature.MeasuredAt }); }
protected BaseTemperature(ITemperature temperature) { if (temperature == null) { throw new ArgumentNullException("Temperature is null"); } Date = temperature.Date; Value = temperature.Value; }
/// <summary> /// Updates the current temparature /// </summary> /// <param name="temperature"></param> public override void UpdateTemperature(ITemperature temperature) { var temp = temperature.Unit != ThermometerUnit ? temperature.Convert(ThermometerUnit) : temperature; base.UpdateTemperature(temp); TemperatureChanged?.Invoke(null, new TemperatureChangedEventArgs(Temperature)); }
internal static bool EqualsHelper(ITemperature one, object obj) { var two = obj as ITemperature; if (two == null && obj != null) { return false; } return EqualsHelper(one, two); }
internal void Update(ThermostatSetpointType setpointType, ITemperature temperature) { if (_setpoints.ContainsKey(setpointType)) { _setpoints[setpointType] = temperature; } else { _setpoints.Add(setpointType, temperature); } }
public ITemperatureControl(Device device, List <Device> devicesList, DeviceManager manager) { this.manager = manager; this.device = device; deviceId = device.Id; heater = (ITemperature)device; devices = devicesList; InitializeType(); Initializer(); InitializerBase(); }
internal static bool EqualsHelper(ITemperature one, object obj) { var two = obj as ITemperature; if (two == null && obj != null) { return(false); } return(EqualsHelper(one, two)); }
/// <summary> /// Converts the temparature to kelvin /// </summary> /// <param name="temperature"></param> /// <param name="unit"></param> /// <returns></returns> private static ITemperature ToKelvin(ITemperature temperature, Unit unit) { if (unit == Unit.Fahrenheit) { return(new Temperature((temperature.Value + 459.67m) * 5 / 9, Unit.Fahrenheit)); } if (unit == Unit.Celsius) { return(new Temperature(temperature.Value + 273.15m, Unit.Celsius)); } throw new Exception("There is no convertion defined."); }
public static void AssertTemperatureEqual(ITemperature one, ITemperature two) { if (one == null && two == null) { return; } AssertHelperHelper(one, two); Assert.That(one.GetType(), Is.EqualTo(two.GetType())); Assert.That(one.Value, Is.EqualTo(two.Value)); }
public void Init() { if (Utilities.IsDesktopComputer()) { Controller = new TemperatureSensorMock(); } else { Controller = new OneWireTemperatureSensor(); } Controller.Init(); }
public override void UpdateTemperature(ITemperature temperature) { if (Temperature.Unit != temperature.Unit && Converter == null) { throw new MemberAccessException(string.Format("There is no converters with this thermometer. A {0} unit was recieved but the thermometer is set to {1} unit.", temperature.Unit, ThermometerUnit)); } var temp = temperature.Unit != ThermometerUnit ? Converter.Convert(temperature, ThermometerUnit) : temperature; base.UpdateTemperature(temp); }
//TODO unit test this internal static bool EqualsHelper(ITemperature one, ITemperature two) { if (one == two) { return(true); } if (one == null || two == null) { return(false); } var result = Math.Abs(one.Celsius.Value - two.Celsius.Value) < .001; return(result); }
//TODO unit test this internal static bool EqualsHelper(ITemperature one, ITemperature two) { if (one == two) { return true; } if (one == null || two == null) { return false; } var result = Math.Abs(one.Celsius.Value - two.Celsius.Value) < .001; return result; }
public DCAPSTModel( ISolarGeometry solar, ISolarRadiation radiation, ITemperature temperature, IPathwayParameters pathway, ICanopyAttributes canopy, Transpiration trans ) { Solar = solar; Radiation = radiation; Temperature = temperature; this.pathway = pathway; Canopy = canopy; transpiration = trans; }
/// <summary> /// Initializes a new instance of the <see cref="WeatherReport"/> class. /// </summary> /// <param name="time">The value of time.</param> /// <param name="temperature">The value of temperature.</param> /// <param name="pressure">The value of atmospheric pressure.</param> /// <param name="humidity">The value of humidity.</param> /// <param name="wind">The value of wind.</param> /// <param name="cloudiness">The value of cloudiness.</param> /// <param name="precipitation">The value of precipitation.</param> public WeatherReport( DateTime time, ITemperature temperature, IPressure pressure, IHumidity humidity, IWind wind, ICloudiness cloudiness, IPrecipitation precipitation) { this.Time = time; this.Temperature = temperature; this.Pressure = pressure; this.Humidity = humidity; this.Wind = wind; this.Cloudiness = cloudiness; this.Precipitation = precipitation; }
public static bool TryParse(string input, out ITemperature output) { #region Prepare Variables string capInput = input.ToUpperInvariant(); string extraction = input.ExtractNumberComponentFromMeasurementString(); double conversion = 0; #endregion #region Convert To Double bool failed = !double.TryParse(extraction, out conversion); if (failed) { Debug.AddDetailMessage("Measurement Input not successfully converted."); Debug.AddDetailMessage("----" + capInput); output = new Temperatures.DegreeCelsius(0); return(false); } #endregion #endregion #region Convert To Temperature if (capInput.EndsWithAny(Suffixes.DegreeCelcius)) { output = new Temperatures.DegreeCelsius(conversion); return(true); } if (capInput.EndsWithAny(Suffixes.DegreeKelvin)) { output = new Temperatures.DegreeKelvin(conversion); return(true); } if (capInput.EndsWithAny(Suffixes.DegreeFahrenheit)) { output = new Temperatures.DegreeFahrenheit(conversion); return(true); } #endregion #region ... Conversion #region Type Unrecognised Debug.AddDetailMessage("No Type for input Temperature conversion. Break here for details..."); Debug.AddDetailMessage("----" + capInput); output = new Temperatures.DegreeCelsius(0); return(false); #endregion }
public bool Convert(ITemperature input, ITemperature output) { var isValid = _validator.Validate(input, out var message); if (!isValid) { throw new Exception(message); } switch (input) { case CelsiusTemperature celsiusTemperature: ConvertFromCelsius(celsiusTemperature, ref output); return(true); default: return(false); } }
public void GetAllDataByType(char typeOfSensor) { switch (typeOfSensor) { case 't': foreach (Sensor sensor in sensors) { if (sensor is ITemperature) { ITemperature ts = sensor as ITemperature; ts.Unit = unit; Console.WriteLine("{0}: {1} {2}", sensor.Name, ts.Temperature, ts.Unit); } } break; case 'h': foreach (Sensor sensor in sensors) { if (sensor is IHumidity) { IHumidity hs = sensor as IHumidity; Console.WriteLine("{0}: {1}%", sensor.Name, hs.Humidity); } } break; case 'p': foreach (Sensor sensor in sensors) { if (sensor is IPressure) { IPressure ps = sensor as IPressure; Console.WriteLine("{0}: {1} hPA", sensor.Name, ps.Pressure); } } break; default: throw new Exception("Wrong switch case!"); } }
public void SetSetpoint(ThermostatSetpointType setpointType, ITemperature temperature) { var setpoint = _setpoints[setpointType]; setpoint.SetValue(temperature); }
public void SetTemperature(ITemperature obj) { Console.WriteLine("Установите температуру"); int tmp = Int32.Parse(Console.ReadLine()); ((ITemperature)obj).Temperature = tmp; }