コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var httpClient      = new HttpClient();
            var emissionsClient = new EmissionsClient(httpClient);

            emissionsClient.BaseUrl = "http://localhost:5000/";

            var emissions = emissionsClient.GetMostRecentEmissionsAsync().Result;

            foreach (var emission in emissions)
            {
                System.Console.WriteLine($"{emission.Region}: {emission.EmissionTimeUTC}, {emission.Emission}");
            }

            var prognosisClient = new PrognosisClient(httpClient);

            prognosisClient.BaseUrl = "http://localhost:5000/";

            var consumptionRecommendation = prognosisClient.OptimalConsumptionTimeAsync("DK1", 2, DateTimeOffset.UtcNow.ToString("o"), DateTimeOffset.UtcNow.AddDays(1).ToString("o")).Result;

            System.Console.WriteLine($"{consumptionRecommendation.Best.Emissions}g at {consumptionRecommendation.Best.StartUTC.ToLocalTime().ToString("o")}");
            System.Console.WriteLine($"{consumptionRecommendation.Earliest.Emissions}g at {consumptionRecommendation.Earliest.StartUTC.ToLocalTime().ToString("o")}");
            System.Console.WriteLine($"{consumptionRecommendation.Latest.Emissions}g at {consumptionRecommendation.Latest.StartUTC.ToLocalTime().ToString("o")}");
        }
コード例 #2
0
ファイル: GreenergyService.cs プロジェクト: sorbra/greenergy
        private async void SyncEmissionData(object state)
        {
            try
            {
                var noEarlierThan = DateTimeOffset.MinValue;
                var mostRecent    = await EmissionsClient.GetMostRecentEmissionsAsync();

                if (mostRecent.Count() > 0)
                {
                    noEarlierThan = mostRecent.First().EmissionTimeUTC;
                }

                if (noEarlierThan.CompareTo(DateTimeOffset.MinValue) == 0)
                {
                    noEarlierThan = _config.Value.BootstrapDate;
                }

                var emissions = await _energinetAPI.GetRecentEmissions(noEarlierThan);

                _logger.LogInformation("Received " + emissions.Count + " emissions records from energinet.dk that are new since " + noEarlierThan.ToString());

                await EmissionsClient.UpdateEmissionsAsync(emissions);
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex, "Exception in GreenergyService.SyncEmissionData", null);
            }
        }
コード例 #3
0
 public async Task <ActionResult <ICollection <EmissionDataDTO> > > Getemissions()
 {
     try
     {
         return(new ActionResult <ICollection <EmissionDataDTO> >(await EmissionsClient.GetMostRecentEmissionsAsync()));
     }
     catch (System.Exception ex)
     {
         _logger.LogError(ex, ex.Message, null);
         return(StatusCode(StatusCodes.Status500InternalServerError));
     }
 }
コード例 #4
0
        // private async Task<ActionResult<DialogFlowResponseDTO>> HandleConsumeElectricityExplain(DialogFlowRequestDTO request)
        // {
        //     try
        //     {
        //         Parameters parameters = request.queryResult.outputContexts
        //                     .FirstOrDefault(oc => oc.name.EndsWith("consumeelectricity-followup"))
        //                     .parameters;

        //         DialogFlowResponseDTO response = new DialogFlowResponseDTO();
        //         response.outputContexts = request.queryResult.outputContexts;
        //         var co2perkwh = parameters.initialemissions;

        //         response.fulfillmentText = request.queryResult.fulfillmentText
        //                     .Replace("$initialemissions", parameters.initialemissions.ToString())
        //                     .Replace("$optimalemissions", parameters.optimalemissions.ToString())
        //                     .Replace("$savingspercentage", parameters.savingspercentage.ToString());
        //         return response;
        //     }
        //     catch (Exception ex)
        //     {
        //         _logger.LogError(ex, ex.Message, null);
        //         return StatusCode(StatusCodes.Status500InternalServerError);
        //     }
        // }

        private async Task <ActionResult <DialogFlowResponseDTO> > HandleCurrentCo2QueryIntent(DialogFlowRequestDTO request)
        {
            try
            {
                var currentEmission = (await EmissionsClient.GetMostRecentEmissionsAsync()).FirstOrDefault().Emission;

                DialogFlowResponseDTO response = new DialogFlowResponseDTO();
                response.fulfillmentText = request.queryResult.fulfillmentText.Replace("$co2perkwh", currentEmission.ToString());

                return(response);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message, null);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }