Exemple #1
0
        public async Task <IActionResult> Get([FromQuery] ForecastRequest forecastViewModel)
        {
            var forecast =
                await _weatherClient.GetWeekForecastAsync(forecastViewModel.City, forecastViewModel.Language, forecastViewModel.Unit);

            return(Ok(forecast));
        }
Exemple #2
0
        public GetForecastInfo GetForecastRequest(ApiConnect.ApiConnect apiConnect, int IdRequest)
        {
            string[]        Headers        = new string[] { };
            ForecastRequest requestResult4 = new ForecastRequest();

            return(apiConnect.GetResult4(IdRequest, "", "GetForecast", ref Headers, requestResult4).Data as GetForecastInfo);
        }
        public async Task InvokeAsync_Returns_ViewViewComponentResult()
        {
            // Arrange
            IConfigurationSection weatherConfig = _configuration.GetSection("Weather");

            var request = new ForecastRequest
            {
                City             = weatherConfig["City"],
                CountryCode      = weatherConfig["CountryCode"],
                LanguageCode     = Language.French.ToLanguageCode(),
                TemperatureScale = TemperatureScale.Fahrenheit.ToUnitsType(),
            };

            var serviceMock = new Mock <WeatherService>();

            serviceMock.Setup(stub => stub.GetCurrentWeatherAsync(request)).ReturnsAsync(GetTestForecast());

            var viewComponent = new CurrentWeather(serviceMock.Object);

            // Act
            var result = await viewComponent.InvokeAsync(
                weatherConfig["City"], weatherConfig["CountryCode"], TemperatureScale.Fahrenheit, Language.French);

            // Assert
            Assert.IsType <ViewViewComponentResult>(result);
        }
Exemple #4
0
        public void TestMethod1()
        {
            var controller = new WeatherForecastController(new Logger <WeatherForecastController>(new LoggerFactory()));
            var request    = new ForecastRequest
            {
                Latitude  = 65,
                Longitude = 34
            };
            var response = controller.GetTemperatureByLocation(request) as ContentResult;

            Assert.AreEqual(200, response.StatusCode);
        }
        public ActionResult <ForecastResult> Projection(ForecastRequest forecastRequest)
        {
            var result = _forecastInvestments.ForecastInvestment(
                forecastRequest.LumpSumInvestment,
                forecastRequest.MonthlyInvestment,
                forecastRequest.TimescaleYears * MonthsInYear,
                forecastRequest.TargetValue,
                forecastRequest.RiskLevel);



            return(new OkObjectResult(result));
        }
Exemple #6
0
        public IActionResult GetTemperatureByLocation([FromBody] ForecastRequest ForecastRequest)
        {
            var response = new Dictionary <string, string>
            {
                { "Temperature", "78" }
            };

            return(new ContentResult
            {
                StatusCode = 200,
                Content = JsonConvert.SerializeObject(response),
                ContentType = "application/json"
            });
        }
Exemple #7
0
        public override async Task <ForecastResponse> GetForecast(ForecastRequest request, ServerCallContext context)
        {
            try
            {
                var client = _httpClientFactory.CreateClient(HttpClients.StartMicroApi);
                var result = await client.GetStringAsync(API.WeatherService.GetForecast(_settings.WeatherServiceApiUrl, request.CityName));

                var forecast = JsonConvert.DeserializeObject <ForecastResponse>(result);
                return(forecast);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                throw;
            }
        }
Exemple #8
0
        /// <summary>
        /// Returns personalized recommendation for given weather/alert/appChain results
        /// </summary>
        /// <param name="weatherCondition"></param>
        /// <param name="weatherAlertCode"></param>
        /// <param name="acr"></param>
        /// <returns></returns>
        public string GetPersonalizedRiskDescription(string weatherCondition, string weatherAlertCode, AppChainResults acr, string userName, int appId)
        {
            var currentDate = DateTime.Now.Date;

            ForecastRequest[] request = new ForecastRequest[] { new ForecastRequest {
                                                                    date = currentDate, alertCode = weatherAlertCode, weather = weatherCondition
                                                                } };

            var _s = new PersonalizedRecommendationsWorker().GetRecommendation(request, acr, userName, appId);

            if (_s != null)
            {
                return(_s[0].gtForecast);
            }
            return
                ("Personalization is not possible due to insufficient genetic data in the selected file. Choose a different genetic data file.");
        }
        private ForecastRequest GetWeatherForecast(DateTime fromUtc, DateTime toUtc, int task)
        {
            // TODO: Move this into a DAL and inject

            // Get the weather forecast for the supplied dates
            var weatherForecast = dbClient._10forecastinputsByTask
                                  .Where(w => w.DateTimeUtc >= fromUtc && w.DateTimeUtc <= toUtc && w.Task == task)
                                  .ToList();

            // Map to the right format for the ML API
            var request = new ForecastRequest()
            {
                data = this.mapper.Map <List <ForecastRequestItem> >(weatherForecast)
            };

            return(request);
        }
Exemple #10
0
        public virtual async Task <Forecast> GetCurrentWeatherAsync(ForecastRequest request)
        {
            const string WEATHER_CACHE_KEY = "Weather";

            // Look for cache key
            if (!_cache.TryGetValue(WEATHER_CACHE_KEY, out Forecast currentWeather))
            {
                // Key not in cache, so get data

                // Fetch the user secret
                string apiKey = _configuration["OpenWeatherMapApiKey"];

                if (String.IsNullOrWhiteSpace(apiKey))
                {
                    throw new ArgumentException("Unable to find an OpenWeatherMap API key in the secret store.");
                }

                IConfigurationSection weatherConfig = _configuration.GetSection("Weather");
                string baseUrl     = weatherConfig["ApiBaseUrl"];
                var    endpointUrl = $"{baseUrl}?q={request.City},{request.CountryCode}&lang={request.LanguageCode}&units={request.TemperatureScale}&appid={apiKey}";

                var response = await _httpClient.GetAsync(endpointUrl);

                response.EnsureSuccessStatusCode();
                currentWeather = await response.Content.ReadAsAsync <Forecast>();

                // Keep in cache for this duration; reset time if accessed
                var cacheEntryOptions = new MemoryCacheEntryOptions
                {
                    SlidingExpiration = TimeSpan.FromSeconds(
                        weatherConfig.GetValue <int>("CacheDuration"))
                };

                // Save data in cache
                _cache.Set(WEATHER_CACHE_KEY, currentWeather, cacheEntryOptions);
            }

            return(currentWeather);
        }
Exemple #11
0
        public async Task InvokeAsync_Returns_ViewViewComponentResult()
        {
            // Arrange
            var request = new ForecastRequest
            {
                City             = "St. Louis",
                CountryCode      = "US",
                LanguageCode     = Language.French.ToLanguageCode(),
                TemperatureScale = TemperatureScale.Fahrenheit.ToUnitsType()
            };

            var serviceMock = new Mock <WeatherService>();

            serviceMock.Setup(stub => stub.GetCurrentWeatherAsync(request)).ReturnsAsync(GetTestForecast());

            var viewComponent = new CurrentWeather(serviceMock.Object);

            // Act
            var result = await viewComponent.InvokeAsync("St. Louis", "US", TemperatureScale.Fahrenheit, Language.French);

            // Assert
            Assert.IsType <ViewViewComponentResult>(result);
        }
 public ForecastResponse GetWeatherForecastData(ForecastRequest request)
 {
     throw new NotImplementedException();
 }
        private async Task <List <Task0ForecastsPvandDemandRun1> > GetPvAndDemandForecasts(int task, ForecastRequest request)
        {
            // GET Demand Forecast
            var demandForecast = await this.demandForecaster.GetAsync(request);

            // Get PV Forecast
            var pvForecast = await this.pvForecaster.GetAsync(request);

            // Stitch together
            var forecast = new List <Task0ForecastsPvandDemandRun1>();

            for (int i = 0; i < request.data.Count; i++)
            {
                forecast.Add(new Task0ForecastsPvandDemandRun1()
                {
                    DateTimeUtc           = DateTime.Parse(request.data[i].dateTimeUTC),
                    Task0ForecsatPv       = pvForecast.result[i],
                    Task0ForecastDemandMw = demandForecast.result[i],
                    TaskName = ""
                });
            }

            return(forecast);
        }