public async void GetForecast_OpenW() { // prepare WeatherGroup output = null; using (var stream = new BufferedStream(File.OpenRead("./Resources/OpenW_onecall_SI.json"), 8192)) { var mockHttp = new MockHttpMessageHandler(); mockHttp .When(OpenWeatherService.EndPointRoot + "*") .Respond("application/json", stream); // execute output = await _factory.Create(WeatherFactory.OpenWeatherServiceId, "a_valid_key", mockHttp) .GetForecast(BolognaLatitude, BolognaLongitude, Unit.Imperial, Language.Italian); stream.Close(); } // asserts output.TimeZone.ShouldNotBeNullOrEmpty(); output.TimeZoneOffset.ShouldBe(1.0f); output.Coordinates.ShouldNotBeNull(); output.Coordinates.Latitude.ShouldNotBe(0.0f); output.Coordinates.Longitude.ShouldNotBe(0.0f); output.Count.ShouldBeGreaterThan(0); var today = 1609711216.ToDateTimeOffset().UtcDateTime; for (int i = 0; i < output.Count; i++) { Check_Forecast_Output(output[i], today.AddDays(i), 1.0f); } }
public ControlCondition(WireAndWeather wireAndWeather) { this.wireAndCoefficient = wireAndWeather.WireAndCoefficient; this.weatherGroup = wireAndWeather.WeatherGroup; WeatherAndControlspanList = new SortedList <double, Weather>(); this.WeatherAndControlspanListSet(); }
public async Task <WeatherGroup> GetForecast(double latitude, double longitude, Unit unit = Unit.Auto, Language language = Language.English) { DSModel.Forecast src = await _service.GetForecast(latitude, longitude, (DSModel.DSUnit) unit, language); var output = new WeatherGroup(src.Daily?.Data?.Count ?? 16); TinyMapper.Map <DSModel.Forecast, WeatherGroup>(src, output); foreach (var dataPoint in src.Daily.Data) { // convert datapoints patching/normalizing some values var weatherOftheDay = TinyMapper.Map <Weather>(dataPoint); if (string.IsNullOrEmpty(weatherOftheDay.TimeZone)) { weatherOftheDay.TimeZone = output.TimeZone; } if (weatherOftheDay.TimeZoneOffset == 0.0f) { weatherOftheDay.TimeZoneOffset = output.TimeZoneOffset; } if (weatherOftheDay.Coordinates == null) { weatherOftheDay.Coordinates = output.Coordinates; } // normalize time unix utc if (Math.Abs(output.TimeZoneOffset) > 0.4f) { weatherOftheDay.UnixTime += (int)(3600 * output.TimeZoneOffset); } output.Add(weatherOftheDay); } return(output); }
public WireAndWeather(WireAndCoefficient conductor, WeatherGroup weatherGroup, ISetEWeatherCode setEWeatherCode, ISetMaxWindCode setMaxWindCode) { WireAndCoefficient = conductor; WeatherGroup = weatherGroup.Clone(); this.setMaxWindCode = setMaxWindCode; this.setEWeatherCode = setEWeatherCode; SetWindWeather(); }
public WireLoadGroup(WireAndWeather wireAndWeather, ILoadCode loadCode, IELoadCode eLoadCode) { abstractWire = wireAndWeather.WireAndCoefficient.Conductor; weatherGroup = wireAndWeather.WeatherGroup; this.loadCode = loadCode; this.eLoadCode = eLoadCode; SetP(); }
/// <summary> /// /// </summary> public async Task <Weather> GetWeatherByDate(double latitude, double longitude, DateTime date, Unit unit = Unit.Auto, Language language = Language.English) { // if the date is today, return current weather if (date.Date == DateTime.UtcNow.Date) { return(await GetCurrentWeather(latitude, longitude, unit, language)); } // get the forecast WeatherGroup output = await GetForecast(latitude, longitude, unit, language); // select the requested date var theRightWeather = output.Find(d => (d.SunriseTime != null) && (d.SunriseTime.Value.Date.Equals(date.Date))); if (theRightWeather == null) { // generate an empty forecast theRightWeather = new Weather { Coordinates = output[0]?.Coordinates ?? new GeoCoordinates(latitude, longitude), TimeZone = output[0]?.TimeZone, TimeZoneOffset = output[0]?.TimeZoneOffset ?? 0.0f, UnixTime = date.Date.ToUnixTime(), Alerts = new[] { new Alert { Title = "NO AVAILABLE FORECAST FOR THE REQUESTED DATE.", Description = $"You requested a forecast for {date.Date:o}", Severity = Severity.Warning, StartUnixTime = DateTime.UtcNow.ToUnixTime(), ExpiresUnixTime = date.Date.AddDays(-7).ToUnixTime(), } }.ToList(), }; } return(theRightWeather); //if ((output.Daily?.Count ?? 0) > 0) { // // if there are more info on the daily data, copy it on output.Currently // var sameDay = src.Daily.FirstOrDefault(d => // (d.SunriseTime != null) && // (d.SunriseTime.Value.Date.Equals(output.Currently.Time.Date))); // if (sameDay != null) src.Currently = // var currently = output.Currently; // //src.Currently = // var output = TinyMapper.Map<Weather>(src); // === ALTERNATIVE using GetCurrentWeather //var innerW = await _service.GetForecast(latitude, longitude, (OWModel.OWUnit)unit, language); //var output = TinyMapper.Map<Model.Weather>((object)innerW); // === // === do some adaptation that TinyMapper does not do quickly // TODO Map this: output.Hourly = innerW.Hourly, }
/// <summary> /// 采用OTL默认规则 /// </summary> /// <param name="conductor"></param> /// <param name="weatherGroup"></param> public WireAndWeather(WireAndCoefficient conductor, WeatherGroup weatherGroup) { WireAndCoefficient = conductor; WeatherGroup = weatherGroup.Clone(); Assembly assembly = Assembly.LoadFrom("Standard.dll"); var cType = assembly.GetType("Standard." + OTL.OTLProject.ProjectInfo.ELoadCode); setEWeatherCode = (ISetEWeatherCode)Activator.CreateInstance(cType); cType = assembly.GetType("Standard." + OTL.OTLProject.ProjectInfo.LoadCode); setMaxWindCode = (ISetMaxWindCode)Activator.CreateInstance(cType); SetWindWeather(); }
public WireLoadGroup(WireAndWeather wireAndWeather) { abstractWire = wireAndWeather.WireAndCoefficient.Conductor; weatherGroup = wireAndWeather.WeatherGroup; Assembly assembly = Assembly.LoadFrom("Standard.dll"); var cType = assembly.GetType("Standard." + OTL.OTLProject.ProjectInfo.LoadCode); loadCode = (ILoadCode)Activator.CreateInstance(cType); cType = assembly.GetType("Standard." + OTL.OTLProject.ProjectInfo.ELoadCode); eLoadCode = (IELoadCode)Activator.CreateInstance(cType); SetP(); }
//NearbyWeather public WeatherGroup GetNearbyWeather(WeatherGroup defaultWeatherGroup) { var localSettings = ApplicationData.Current.LocalSettings; var nearbyWeather = localSettings.Values["nearbyWeather"]; if(nearbyWeather == null) { return defaultWeatherGroup; } else { return (WeatherGroup)nearbyWeather; } }
public void DataPointList_to_WeatherGroup() { // prepare List <OWModel.DataPointDSL> src = PrepareForecastData().Daily; // execute WeatherGroup output = new WeatherGroup(TinyMapper.Map <List <Weather> >(src)); // assert output.Count.ShouldBe(src.Count); output.ShouldAllBe(dp => dp.Visibility > 0); output.ShouldAllBe(dp => dp.Temperature != null); output.ShouldAllBe(dp => dp.Temperature.Daily != 0.0f); output.ShouldAllBe(dp => !string.IsNullOrWhiteSpace(dp.Summary)); }
public async Task <WeatherGroup> GetForecast(double latitude, double longitude, Unit unit = Unit.Auto, Language language = Language.English) { OWModel.ForecastDSL src = await _service.GetForecastDSL(latitude, longitude, (OWModel.OWUnit) unit, language); //var output_meno = await _service.GetForecastDSL(14.93122218816076, -23.519346790741995, (OWModel.OWUnit)unit, Language.Italian); //var output_zero = await _service.GetForecastDSL(51.53027816900633, 0.08310560054000066, (OWModel.OWUnit)unit, Language.Italian); //var output_piu = await _service.GetForecastDSL(44.482732, 11.352134, (OWModel.OWUnit)unit, Language.Italian); var output = new WeatherGroup(src.Daily?.Count ?? 0); output = TinyMapper.Map <OWModel.ForecastDSL, WeatherGroup>(src, output); // do some normalization (convert time offset from seconds to hours) if (src.TimeZoneOffset != 0) { output.TimeZoneOffset = (float)Math.Round(output.TimeZoneOffset / 3600.0f, 1); } // now add the days if ((src.Daily?.Count ?? 0) > 0) { output.AddRange(TinyMapper.Map <List <Weather> >(src.Daily)); foreach (var daily in output) { if (string.IsNullOrEmpty(daily.TimeZone)) { daily.TimeZone = output.TimeZone; } if (daily.TimeZoneOffset == 0.0f) { daily.TimeZoneOffset = output.TimeZoneOffset; } if (daily.Coordinates == null) { daily.Coordinates = output.Coordinates; } // normalize time unix utc if (src.TimeZoneOffset != 0) { daily.UnixTime += src.TimeZoneOffset; } } } return(output); }
public WeatherGroupWrapper(WeatherGroup group) { _group = group; }
public static FlowDocument Report(WeatherGroup weatherGroup, List <(Voltage, WireAndCoefficient)> wireList)
public void SetNearbyWeather(WeatherGroup weatherGroup) { var localSettings = ApplicationData.Current.LocalSettings; localSettings.Values["nearbyWeather"] = (uint)weatherGroup; }