public override Task <InvertorProducingStatistic> GetAllStationsStatistics(EmptyRequest request, ServerCallContext context) { try { InvertorProducingStatistic result = new InvertorProducingStatistic(); for (int i = 1; i <= 6; i++) { InvertorProducingStatistic stationResult = null; if (db.InvertorProducingStatistics.Where(x => x.StationId == i).ToList().Any()) { stationResult = db.InvertorProducingStatistics.Where(x => x.StationId == i).ToList().Last(); } if (stationResult != null) { stationResult.ErrorCount = db.Events.Where(x => x.StationId == i).Count(); result.ProducedEnergy += stationResult.ProducedEnergy; result.PredictedProducing += stationResult.PredictedProducing; result.ActivePower += stationResult.ActivePower; result.ErrorCount += stationResult.ErrorCount; } } if (powerInMW) { result.PredictedProducing /= 1000; result.ActivePower /= 1000; result.ProducedEnergy /= 1000; } return(Task.FromResult(result)); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(Task.FromResult(new InvertorProducingStatistic())); }
public override Task <InvertorProducingStatistic> GetInvertorStatisticsAsync(InvertorProducingStatisticRequest request, ServerCallContext context) { try { InvertorProducingStatistic statisticsNow = db.InvertorProducingStatistics.Where(x => x.InvertorId == request.InvertorId && x.Date >= request.FromDate).First(); if (powerInMW) { statisticsNow.PredictedProducing /= 1000; statisticsNow.ActivePower /= 1000; statisticsNow.ProducedEnergy /= 1000; } return(Task.FromResult(statisticsNow)); } catch (Exception ex) { Console.WriteLine(ex.Message); return(Task.FromResult(new InvertorProducingStatistic())); } }
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())); }