Exemple #1
0
        public ActionResult <APILibrary.DarkSky.Response> Get(decimal lat, decimal lng)
        {
            var function = $"{_api.APIKey}/{lat},{lng}";
            var response = _api.Get <APILibrary.DarkSky.Response>(function);

            return(response);
        }
        public async Task <EnergryFutures> Get()
        {
            var amberData = await _amberService.Get(_options.Value.PostCode);

            var darkData = await _darkSkyService.Get();

            if (darkData == null)
            {
                return(null);
            }

            var sunrise = darkData.Daily.Data[0].SunriseDateTime.Value.DateTime.AddHours(0);
            var sunset  = darkData.Daily.Data[0].SunsetDateTime.Value.DateTime.AddHours(0);

            var futures = new EnergryFutures()
            {
                Futures = new List <EnergyFuture>()
            };


            var currentAd = amberData.data.variablePricesAndRenewables.Last(_ => _.periodType == "ACTUAL");//TZ for the AE is based on Brisbane, so may be wrong in Summer time.
            var currentDp = darkData.Currently;

            var startTime = currentAd.period.Subtract(TimeSpan.FromDays(14)).ToUniversalTime().ConvertToISO();
            var endTime   = DateTime.Now.ToUniversalTime().ConvertToISO();



            var history = await _influxService.Query("house",
                                                     $"SELECT mean(\"SolarOutput\") FROM \"currentStatus\" WHERE time >= '{startTime}' AND time <= '{endTime}' GROUP BY time(30m)");

            var historyPairs = new List <DateDouble>();

            if (history.Results[0].Series != null)
            {
                foreach (var i in history.Results[0].Series[0].Values)
                {
                    historyPairs.Add(new DateDouble {
                        Interval = (DateTime)i[0], Value = Convert.ToDouble(i[1])
                    });
                }
            }


            futures.Futures.Add(_getEnergyFuture(currentAd, currentDp, sunrise, sunset, false, historyPairs));


            foreach (var ad in amberData.data.variablePricesAndRenewables.Where(_ => _.periodType == "FORECAST"))
            {
                var ds = _pair(ad, darkData);
                futures.Futures.Add(_getEnergyFuture(ad, ds, sunrise, sunset, true, historyPairs));
            }

            return(futures);
        }