示例#1
0
        private WaterUsageOverviewDto GetWaterUsageOverviewDtoForParcelIDs(List <int> parcelIDs)
        {
            var parcelMonthlyEvapotranspirationDtos =
                ParcelMonthlyEvapotranspiration.ListByParcelID(_dbContext, parcelIDs).ToList();

            var cumulativeWaterUsageByYearDtos = parcelMonthlyEvapotranspirationDtos.GroupBy(x => x.WaterYear).Select(x =>
                                                                                                                      new CumulativeWaterUsageByYearDto
            {
                Year = x.Key, CumulativeWaterUsage = GetCurrentWaterUsageOverview(x)
            }).ToList();

            var historicWaterUsageOverview =
                GetHistoricWaterUsageOverview(cumulativeWaterUsageByYearDtos.SelectMany(x => x.CumulativeWaterUsage).ToList());

            // the chart needs value to be non null, so we need to set the cumulativewaterusage values to be 0 for the null ones; we need them to be null originally when calculating historic since we don't want them to count
            foreach (var cumulativeWaterUsageByMonthDto in cumulativeWaterUsageByYearDtos
                     .SelectMany(x => x.CumulativeWaterUsage).Where(y => y.CumulativeWaterUsageInAcreFeet == null))
            {
                cumulativeWaterUsageByMonthDto.CumulativeWaterUsageInAcreFeet = 0;
            }

            var waterUsageOverviewDto = new WaterUsageOverviewDto
            {
                Current = cumulativeWaterUsageByYearDtos, Historic = historicWaterUsageOverview
            };

            return(waterUsageOverviewDto);
        }
示例#2
0
        public ActionResult <ParcelAllocationAndConsumptionDto> GetAllocationAndConsumption([FromRoute] int parcelID)
        {
            var parcelDto = Parcel.GetByParcelID(_dbContext, parcelID);

            if (ThrowNotFound(parcelDto, "Parcel", parcelID, out var actionResult))
            {
                return(actionResult);
            }

            var parcelMonthlyEvapotranspirationDtos = ParcelMonthlyEvapotranspiration.ListByParcelID(_dbContext, parcelID);

            return(Ok(parcelMonthlyEvapotranspirationDtos));
        }