public async Task <JObject> makeRequest() { HttpClient client = new HttpClient(); var response = await client.GetAsync($"https://api.openweathermap.org/data/2.5/onecall/timemachine?lat={latitude}&lon={longitude}&dt={startOfDay}&appid={apiKey}"); string stringresult = await response.Content.ReadAsStringAsync(); OpenWeatherMapModel OWMM = new OpenWeatherMapModel(); OWMM = JsonConvert.DeserializeObject <OpenWeatherMapModel>(stringresult); //find 'Hourly' closest to scan time Hourly FoundItem = OWMM.hourly.OrderBy(x => Math.Abs(x.dt - scanDateTimeEpoch)).First(); int result = FoundItem.clouds; string dataQuality = "high"; if (result > 33) { dataQuality = "medium"; if (result > 66) { dataQuality = "low"; } } return(JObject.Parse($"{{'clouds': {result}, 'dataQuality': '{dataQuality}'}}")); }
protected OpenWeatherMapModel GetWeatherInformation() { OpenWeatherMapModel weather = null; try { using (OpenWeatherMapAPIController openWeatherMap = new OpenWeatherMapAPIController()) { weather = JsonConvert.DeserializeObject <OpenWeatherMapModel>(openWeatherMap.GetOpenWeatherMapData()); weather.HasAPIError = false; } } catch (WebException ex) { weather = new OpenWeatherMapModel { HasAPIError = true, ErrorMessage = ex.Message }; } return(weather); }
public async Task <WindModel> GetCurrentWindResultDataAsync <T>(ILogger <T> logger, string cityName, OpenWeatherMapModel resourceData) { var resultData = new WindModel(); await Task.Run(() => { var config = new MapperConfiguration(cfg => cfg.CreateMap <OpenWeatherMapModel, LogInfo>()); var mapper = new Mapper(config); var logInfo = mapper.Map <LogInfo>(resourceData); logger.LogInformation(logInfo.ToString()); resultData = new WindModel { City = cityName, Speed = resourceData.Wind.Speed, Direction = WindDirectionHelper.FormatWindDirection(resourceData.Wind.WindDirection) }; }); return(resultData); }
public async Task <WeatherModel> GetCurrentWeatherResultDataAsync <T>(ILogger <T> logger, string cityName, string metric, OpenWeatherMapModel resourceData) { var resultData = new WeatherModel(); await Task.Run(() => { var config = new MapperConfiguration(cfg => cfg.CreateMap <OpenWeatherMapModel, LogInfo>()); var mapper = new Mapper(config); var logInfo = mapper.Map <LogInfo>(resourceData); logger.LogInformation(logInfo.ToString()); var resultTemperature = metric.Equals("celsius") ? resourceData.Main.Temp : MetricHelper.CToF(resourceData.Main.Temp); resultData = new WeatherModel { City = cityName, Temperature = resultTemperature, Date = DateTime.Now.ToString(), TemperatureMetric = metric }; }); return(resultData); }