Esempio n. 1
0
        public override Task <InvertorProducingStatistic> GetStationStatisticAsync(StationProducingStatisticRequest request, ServerCallContext context)
        {
            try
            {
                InvertorProducingStatistic statisticsNow = null;
                if (db.InvertorProducingStatistics.Where(x => x.StationId == request.StationId).ToList().Any())
                {
                    statisticsNow = db.InvertorProducingStatistics.Where(x => x.StationId == request.StationId).ToList().Last();
                }

                InvertorProducingStatistic statisticsOnRequestDate = null;
                if (db.InvertorProducingStatistics.Where(x => x.StationId == request.StationId && x.Date == request.Date).ToList().Any())
                {
                    statisticsOnRequestDate = db.InvertorProducingStatistics.Where(x => x.StationId == request.StationId && x.Date == request.Date).ToList().Last();
                }

                InvertorProducingStatistic statisticsResult = statisticsNow;
                if (statisticsResult != null)
                {
                    if (statisticsOnRequestDate != null)
                    {
                        statisticsResult.PredictedProducing -= statisticsOnRequestDate.PredictedProducing;
                        statisticsResult.ActivePower        -= statisticsOnRequestDate.ActivePower;
                        statisticsResult.ProducedEnergy     -= statisticsOnRequestDate.ProducedEnergy;
                    }
                    statisticsResult.ErrorCount = db.Events.Where(x => x.StationId == statisticsResult.StationId && x.Date >= request.Date).Count();
                    if (powerInMW)
                    {
                        statisticsResult.PredictedProducing /= 1000;
                        statisticsResult.ActivePower        /= 1000;
                        statisticsResult.ProducedEnergy     /= 1000;
                    }
                    return(Task.FromResult(statisticsResult));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(Task.FromResult(new InvertorProducingStatistic()));
        }
Esempio n. 2
0
 public override async Task GetStationStatisticForChartAsync(StationProducingStatisticRequest request, IServerStreamWriter <InvertorProducingStatistic> responseStream, ServerCallContext context)
 {
     try
     {
         List <InvertorProducingStatistic> statistics = db.InvertorProducingStatistics.Where(x => x.StationId == request.StationId && x.Date >= request.Date).ToList();
         foreach (InvertorProducingStatistic item in statistics)
         {
             if (powerInMW)
             {
                 item.ProducedEnergy     /= 1000;
                 item.PredictedProducing /= 1000;
             }
             await responseStream.WriteAsync(item);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         await responseStream.WriteAsync(new InvertorProducingStatistic());
     }
 }