public void Summarise_withMissingPeriods() { var task = new SummarisationDeliverableProcess(); DeliverableLine fundLine = new DeliverableLine() { CalculateVolume = true }; var result = task.SummarisePeriods(GetPeriodsData(1).Take(10).ToList(), fundLine, GetCollectionPeriods(), GetContractAllocation(GetProviders().First())); result.Count.Should().Be(67); result.Count(w => w.ActualValue == 0 && w.ActualVolume == 0).Should().Be(57); }
public void SummarisePeriodsTest_NoVolume() { var task = new SummarisationDeliverableProcess(); DeliverableLine fundLine = new DeliverableLine() { CalculateVolume = false }; var result = task.SummarisePeriods(GetPeriodsData(5), fundLine, GetCollectionPeriods(), GetContractAllocation(GetProviders().First())); result.Count.Should().Be(67); foreach (var item in result) { item.ActualValue.Should().Be(5 * periodValue); item.ActualVolume.Should().Be(0); } }
public ICollection <SummarisedActual> SummarisePeriods(ICollection <Period> periods, DeliverableLine fundLine, ICollection <CollectionPeriod> collectionPeriods, FcsContractAllocation allocation) { if (periods.All(p => (p.Value == 0 && p.Volume == 0))) { return(Array.Empty <SummarisedActual>()); } var filteredCollectonPeriods = collectionPeriods.Where(cp => cp.ActualsSchemaPeriod >= allocation.ActualsSchemaPeriodStart && cp.ActualsSchemaPeriod <= allocation.ActualsSchemaPeriodEnd); var summarisedPeriods = periods .GroupBy(g => new { g.CalendarYear, g.CalendarMonth }) .Select(pg => new { CalendarYear = pg.Key.CalendarYear, CalendarMonth = pg.Key.CalendarMonth, ActualValue = pg.Where(w => w.Value.HasValue).Sum(sw => sw.Value.Value), ActualVolume = fundLine.CalculateVolume ? pg.Where(w => w.Volume.HasValue).Sum(sw => sw.Volume.Value) : 0 }).ToList(); return((filteredCollectonPeriods .GroupJoin(summarisedPeriods, cp => new { cp.CalendarYear, cp.CalendarMonth }, p => new { p.CalendarYear, p.CalendarMonth }, (cp, p) => new { Period = p, CollectionPeriod = cp } )).SelectMany(grp => grp.Period.DefaultIfEmpty(), (outGrp, outPeriod) => new { ActualsSchemaPeriod = outGrp.CollectionPeriod.ActualsSchemaPeriod, ActualValue = outPeriod == null ? decimal.Zero : outPeriod.ActualValue, ActualVolume = outPeriod == null ? 0 : outPeriod.ActualVolume, }) .GroupBy(pg => pg.ActualsSchemaPeriod) .Select(g => new SummarisedActual { Period = g.Key, ActualValue = g.Sum(sw => sw.ActualValue), ActualVolume = g.Sum(sw => sw.ActualVolume), }).ToList()); }
public ICollection <Period> GetPeriodsForFundLine(IEnumerable <PeriodisedData> periodisedData, DeliverableLine fundLine) { if (fundLine.UseAttributes) { periodisedData = periodisedData.Where(pd => fundLine.Attributes.Contains(pd.AttributeName)); } return(periodisedData.SelectMany(fpd => fpd.Periods).ToList()); }