public static void WeatherStationObserverPatternExample() { WeatherStation station = new WeatherStation(); ConsoleWheaterViewer consoleWeatherViewer = new ConsoleWheaterViewer(station); PhoneWeatherViewer phoneWeatherViewer = new PhoneWeatherViewer(station); station.AddObserver(consoleWeatherViewer); station.AddObserver(phoneWeatherViewer); station.Temperature = 100; station.Temperature = 99; }
private async void MainForm_Load(object sender, EventArgs e) { driver = new WH2310Driver(); station = WeatherStation.Create(driver, false); station.Refresh(); await Task.Delay(250); RefreshData(); station.Start(); timer.Start(); }
// GET: WeatherStations/Delete/5 public ActionResult Delete(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } WeatherStation weatherStation = db.WeatherStations.Find(id); if (weatherStation == null) { return(HttpNotFound()); } return(View(weatherStation)); }
public ObserverPatternRunner() { rnd = new Random(); display = new ForecastDisplay(); general = new GeneralDisplay(); stats = new StatsDisplay(); station = new WeatherStation(); data = new WeatherData(); station.AddObserver(display); station.AddObserver(general); station.AddObserver(stats); station.State = data; }
public void GetAverageAllDayTest() { WeatherStation target = new WeatherStation(); Assert.IsTrue(target.SetMeasurementAtPeriod(10, 20, 50)); Assert.IsTrue(target.SetMeasurementAtPeriod(11, 22, 55)); Assert.IsTrue(target.SetMeasurementAtPeriod(12, 24, 60)); double temp; double hum; target.GetAverageAllDay(out temp, out hum); Assert.AreEqual(22, temp, 0.001, "Durchschnittstemperatur stimmt nicht"); Assert.AreEqual(55, hum, 0.001, "Durchschnittsluftfeuchte stimmt nicht"); }
LogEntry GetCurrentLogEntry(WeatherStation station) { using (var db = new WeatherDb()) { var entry = db.LogEntry.Where(l => l.StationId.Equals(station.Id)).OrderByDescending(l => l.Timestamp).FirstOrDefault(); if (entry != null && DateTime.UtcNow.Subtract(entry.Timestamp).TotalHours <= CURRENT_LOG_ENTRY_HOURS_FILTER) { return(entry); } } return(null); }
public void tableShouldGetCreated() { var weather1 = new WeatherStation() { Place = "her", Celcius = 20, Humidity = 50 }; _DbContext.WeatherStations.Add(weather1); _DbContext.SaveChanges(); Assert.Equal(1, _DbContext.WeatherStations.Count()); }
public static void Sort(WeatherStation[] weathers) { for (int i = 0; i < weathers.Length - 1; i++) { for (int j = 0; j < weathers.Length - i - 1; j++) { if (weathers[j].mean < weathers[j + 1].mean) { WeatherStation temp = weathers[j]; weathers[j] = weathers[j + 1]; weathers[j + 1] = temp; } } } }
public void Notify_Notifies() { WeatherStation s = new WeatherStation(); var observer = new TestObserver(); var observer2 = new TestObserver(); s.Add(observer); s.Add(observer2); s.ChangeWeather(); s.Notify(); Assert.True(observer.wasNotified); Assert.True(observer2.wasNotified); }
public static void Main(string[] args) { Console.WriteLine("Hello World"); WeatherStation wStation = new WeatherStation(); SmartPhone phone = new SmartPhone(wStation); WebSite site = new WebSite(wStation); wStation.Add(phone); wStation.SetTemperature(12.3); wStation.Add(site); wStation.SetTemperature(13.2); wStation.Remove(phone); wStation.SetTemperature(11.9); }
private void ProcessLeafWetness(NameValueCollection data, WeatherStation station) { if (data["leafwetness"] != null) { station.DoLeafWetness(Convert.ToDouble(data["leafwetness"], CultureInfo.InvariantCulture), 1); } // Though Ecowitt supports up to 8 sensors, MX only supports the first 4 for (var i = 2; i <= 4; i++) { if (data["leafwetness" + i] != null) { station.DoLeafWetness(Convert.ToDouble(data["leafwetness" + i], CultureInfo.InvariantCulture), i - 1); } } }
private void ProcessSoilTemps(NameValueCollection data, WeatherStation station) { if (data["soiltempf"] != null) { station.DoSoilTemp(ConvertTempFToUser(Convert.ToDouble(data["soiltempf"], CultureInfo.InvariantCulture)), 1); } for (var i = 2; i <= 16; i++) { if (data["soiltemp" + i + "f"] != null) { station.DoSoilTemp(ConvertTempFToUser(Convert.ToDouble(data["soiltemp" + i + "f"], CultureInfo.InvariantCulture)), i - 1); } } }
private static void SubscribeToWeatherStationEvents( WeatherStation weatherStation, MainPageViewModel viewModel) { TimeFormatter timeFormatter = new TimeFormatter(); DateFormatter dateFormatter = new DateFormatter(); HumidityFormatter humidityFormatter = new HumidityFormatter(); weatherStation.MinuteChanged += (s, newTime) => viewModel.Time = newTime.Format(timeFormatter); weatherStation.DayChanged += (s, newDate) => viewModel.Date = newDate.Format(dateFormatter); weatherStation.OutdoorTemperatureChanged += (sender, newTemp) => viewModel.OutdoorTemperature = newTemp.Value; weatherStation.OutdoorHumidityChanged += (sender, newHumidity) => viewModel.OutdoorHumidity = newHumidity.Format(humidityFormatter); weatherStation.IndoorTemperatureChanged += (sender, newTemp) => viewModel.IndoorTemperature = newTemp.Value; weatherStation.IndoorHumidityChanged += (sender, newHumidity) => viewModel.IndoorHumidity = newHumidity.Format(humidityFormatter); }
public async Task <bool> AddFavoriteStationValidator(WeatherStation model, string id) { var userFavoriteWeatherStation = await GetByUserId(id); bool isAny = userFavoriteWeatherStation.Any(x => x.WeatherStationId == model.WeatherStationId); if (isAny) { return(false); } else { return(true); } }
public static WeatherStation GenerateValues(WeatherStation station) { Random random = new Random(); int[] measurements = new int[MAX_MEASUREMENTS]; for (int i = 0; i < measurements.Length; i++) { measurements[i] = random.Next(MIN_VALUE, MAX_VALUE + 1); } station.measurements = measurements; station.max = Max(station.measurements); station.min = Min(station.measurements); station.mean = Mean(station.measurements); return(station); }
public void WeatherStationVerificationTest() { WeatherStation WeatherStation = new WeatherStation() { Name = "TestWeatherStation", ExternalKey = "ED234AC345AT1" }; Mock <IWeatherStationRepository> mockWeatherStationRepository = new Mock <IWeatherStationRepository>(); mockWeatherStationRepository.Setup(x => x.GetWeatherStationByExternalKey(WeatherStation.ExternalKey)).Returns(WeatherStation); var ws = new WeatherStationLogic(mockWeatherStationRepository.Object); WeatherStation results = ws.GetWeatherStation(WeatherStation.ExternalKey.ToString()); Assert.NotNull(results); Assert.Equal(WeatherStation, results); }
public async Task <IHttpActionResult> AddToFavorite(WeatherStation model) { var id = authRepository.GetUserId(); if (model == null) { return(BadRequest("model cannot be null")); } if (await favoriteRepository.AddFavoriteStationValidator(model, id) == false) { return(BadRequest("There is already same weather station")); } await favoriteRepository.Add(model, id); return(Ok()); }
public static void Main(string[] args) { WeatherData wdata = new WeatherData(); WeatherStation weatherStation = new WeatherStation(); Console.WriteLine("Параметры погоды"); wdata.NewWeatherEvent += weatherStation.WeatherCheckEvent; if (Console.ReadKey().Key == ConsoleKey.Escape) { Console.WriteLine("Статистика"); wdata.Stop(); weatherStation.StatisticReport(); } Console.ReadKey(); }
public async Task AddToFavorite_should_return_ok() { WeatherStation model = new WeatherStation() { CityName = "Krakow", Latitude = 1, Longitude = 1, WeatherStationId = 2 }; _favoriteRepositoryMock.Setup(x => x.AddFavoriteStationValidator(model, It.IsAny <string>())) .ReturnsAsync(true); var actionResult = await FavoriteController.AddToFavorite(model); Assert.IsInstanceOfType(actionResult, typeof(OkResult)); }
public static void Main(string[] args) { WeatherStation station = new WeatherStation(); var data = new List <IReportVeiw> { new CurrentConditionReport(), new StatistcReport() }; WeatherController controller = new WeatherController(station, data); for (int i = 0; i < 100; i++) { controller.Update(); } //TODO : System.Timers.Timer; }
static void Main(string[] args) { WeatherStation station = new WeatherStation(); PrintMediaDisplay printMediaDisplay = new PrintMediaDisplay(station); NewsChannelDisplay newsChannelDisplay = new NewsChannelDisplay(station); station.Add(printMediaDisplay); station.Add(newsChannelDisplay); var timer = new System.Threading.Timer((e) => { station.Notify(); }, null, TimeSpan.Zero, TimeSpan.FromSeconds(10)); Console.ReadKey(); }
public WeatherStationViewModel(WeatherStation pWeatherStation) { this.WeatherStationId = pWeatherStation.WeatherStationId; this.Name = pWeatherStation.Name; this.Position = pWeatherStation.Position; this.DateOfInstallation = pWeatherStation.DateOfInstallation; this.DateOfService = pWeatherStation.DateOfService; this.GiveET = pWeatherStation.GiveET; this.Model = pWeatherStation.Model; this.StationType = pWeatherStation.StationType; this.UpdateTime = pWeatherStation.UpdateTime; this.WebAddress = pWeatherStation.WebAddress; this.WirelessTransmission = pWeatherStation.WirelessTransmission; this.Latitude = pWeatherStation.Position.Latitude; this.Longitude = pWeatherStation.Position.Longitude; this.Enabled = pWeatherStation.Enabled; }
private void ProcessCo2(NameValueCollection data, WeatherStation station) { // co2 - [int, ppm] // co2_in - [int, ppm] // co2_in_24h - [float, ppm] /* * if (data["co2_in"] != null) * { * station.CO2 = Convert.ToInt32(data["co2_in"], CultureInfo.InvariantCulture); * } * if (data["co2_in_24"] != null) * { * station.CO2_24h = Convert.ToInt32(data["co2_in_24"], CultureInfo.InvariantCulture); * } */ // From FOSKplugin // co2lvl // pm25_AQIlvl_co2 // pm25_AQIlvl_24h_co2 // pm10_AQIlvl_co2 // pm10_AQIlvl_24h_co2 if (data["co2lvl"] != null) { station.CO2 = Convert.ToInt32(data["co2lvl"], CultureInfo.InvariantCulture); } if (data["pm25_AQIlvl_co2"] != null) { station.CO2_pm2p5 = Convert.ToDouble(data["pm25_AQIlvl_co2"], CultureInfo.InvariantCulture); } if (data["pm25_AQIlvl_24h_co2"] != null) { station.CO2_pm2p5_24h = Convert.ToDouble(data["pm25_AQIlvl_24h_co2"], CultureInfo.InvariantCulture); } if (data["pm10_AQIlvl_co2"] != null) { station.CO2_pm10 = Convert.ToDouble(data["pm10_AQIlvl_co2"], CultureInfo.InvariantCulture); } if (data["pm10_AQIlvl_24h_co2"] != null) { station.CO2_pm10_24h = Convert.ToDouble(data["pm10_AQIlvl_24h_co2"], CultureInfo.InvariantCulture); } }
public HttpStationEcowitt(Cumulus cumulus, WeatherStation station = null) : base(cumulus) { this.station = station; if (station == null) { cumulus.LogMessage("Creating HTTP Station (Ecowitt)"); } else { cumulus.LogMessage("Creating Extra Sensors - HTTP Station (Ecowitt)"); } //cumulus.StationOptions.CalculatedWC = true; // GW1000 does not provide average wind speeds // Do not set these if we are only using extra sensors if (station == null) { cumulus.StationOptions.UseWind10MinAve = true; cumulus.StationOptions.UseSpeedForAvgCalc = false; // GW1000 does not send DP, so force MX to calculate it cumulus.StationOptions.CalculatedDP = true; // Same for Wind Chill cumulus.StationOptions.CalculatedWC = true; } cumulus.Manufacturer = cumulus.ECOWITT; if (station == null || (station != null && cumulus.EcowittExtraUseAQI)) { cumulus.AirQualityUnitText = "µg/m³"; } if (station == null || (station != null && cumulus.EcowittExtraUseSoilMoist)) { cumulus.SoilMoistureUnitText = "%"; } // Only perform the Start-up if we are a proper station, not a Extra Sensor if (station == null) { Start(); } else { cumulus.LogMessage("Extra Sensors - HTTP Station (Ecowitt) - Waiting for data..."); } }
public async Task AddToFavorite_should_return_BadRequest_when_there_is_same_weather_station_in_database() { WeatherStation model = new WeatherStation() { CityName = "Krakow", Latitude = 1, Longitude = 1, WeatherStationId = 2 }; _favoriteRepositoryMock.Setup(x => x.AddFavoriteStationValidator(model, It.IsAny <string>())) .ReturnsAsync(false); var actionResult = await FavoriteController.AddToFavorite(model) as BadRequestErrorMessageResult; Assert.IsInstanceOfType(actionResult, typeof(BadRequestErrorMessageResult)); Assert.AreEqual(actionResult.Message, "There is already same weather station"); }
public static void Main() { int track = 0; WeatherStation weatherStation = new WeatherStation(); DisplayForecast displayForecast = new DisplayForecast(); DisplayStatistics displayStatistics = new DisplayStatistics(); weatherStation.Register(displayStatistics); weatherStation.Register(displayForecast); do { weatherStation.SetData(new Random().Next(100), new Random().Next(100)); track++; Thread.Sleep(5000); } while (track < 5); }
private static void Observer_Pattern() { // TODO The Observer pattern defines one to many dependencies between objects so that when one object changes its state // TODO all of its dependencies are notified and updated automatically var weatherStation = new WeatherStation(); IObserver phoneDisplay = new PhoneDisplay(weatherStation); IObserver tabletDisplay = new TabletDisplay(weatherStation); // push the observer in the list weatherStation.Add(phoneDisplay); weatherStation.Add(tabletDisplay); Console.WriteLine("Observable Weather Station received new Temperature so it will update the observers"); //poll the date from observable for each observer in the list weatherStation.Notify(); }
static void Main(string[] args) { var data = WeatherStation.GetWeatherStation(); var data2 = WeatherStation.GetWeatherStation(); var forecastApi = new ForecastApi(new PercentageDisplay()); var forecastPlatform = new ForecastPlatform(new HeatIndexDisplay()); var forecastApi2 = new ForecastApi(new NormalDisplay()); data.Register(forecastApi); data.Register(forecastPlatform); data.Register(forecastApi2); data.SetMeasurements(1.2f, 1.5f, 10f); data.SetMeasurements(25f, 12f, 19f); //SingletonTest data2.SetMeasurements(213f, 21f, 61f); }
public void WeatherChanged_AlwaysTrue() { // Assign var station = new WeatherStation(); var person = new ConcretePerson1(station, "krk"); var startTemperature = person.Temperature; // Act foreach (var localization in station.WeatherList) { localization.ChangeWeather("krk", 10); } var endTemperature = person.Temperature; // Assert Assert.IsTrue(startTemperature != endTemperature); }
public async Task <IActionResult> Range(string id) { WeatherStation entity = null; try { if (string.IsNullOrEmpty(id)) { await writeEventAsync("Search without id", LogEvent.err); return(new BadRequestResult()); } entity = await db.weatherStation.byIdAsync(id); if (entity == null) { await writeEventAsync("Not found id: " + id, LogEvent.err); return(new NotFoundResult()); } // Set data for the view ViewBag.ws_name = entity.name; ViewBag.ws_id = entity.id; // Get data var cp = await db.crop.listEnableAsync(); // List <CropYieldRange> entities = new List <CropYieldRange>(); foreach (var r in entity.ranges) { entities.Add(new CropYieldRange(r, cp)); } // Fill the select list ViewBag.crop = new SelectList(cp, "id", "name"); await writeEventAsync("Search id: " + id, LogEvent.rea); return(View(entities)); } catch (Exception ex) { await writeExceptionAsync(ex); return(View()); } }