public void apportionToPeriod352() { ApportionmentManager apportionmentManager; List<Chunk> list; List<Chunk> list1; apportionmentManager = new ApportionmentManager(); Chunk[] chunks = new Chunk[3]; Chunk s0 = default(Chunk); s0.StartDate = new DateTime(4611686018427387903L & 1L, (DateTimeKind)(1uL >> 62)); s0.EndDate = default(DateTime); s0.Amount = 1; chunks[0] = s0; Chunk s1 = default(Chunk); s1.StartDate = new DateTime(4611686018427387903L & 4611686018427387904L, (DateTimeKind)(4611686018427387904uL >> 62)); s1.EndDate = default(DateTime); s1.Amount = 3; chunks[1] = s1; Chunk s2 = default(Chunk); s2.StartDate = default(DateTime); s2.EndDate = new DateTime(4611686018427387903L & 562949953421312L, (DateTimeKind)(562949953421312uL >> 62)); s2.Amount = 2; chunks[2] = s2; list = new List<Chunk>((IEnumerable<Chunk>)chunks); list1 = this.apportionToPeriod(apportionmentManager, list, default(DateTime), new DateTime(4611686018427387903L & 1L, (DateTimeKind)(1uL >> 62)), AppotionmentPeriod.Annually); Assert.IsNotNull((object)list1); Assert.AreEqual<int>(4, list1.Capacity); Assert.AreEqual<int>(1, list1.Count); Assert.IsNotNull((object)apportionmentManager); }
public void apportion715() { ApportionmentManager apportionmentManager; List<Chunk> list; List<Chunk> list1; apportionmentManager = new ApportionmentManager(); Chunk[] chunks = new Chunk[5]; Chunk s0 = default(Chunk); s0.StartDate = new DateTime(4611686018427387903L & 3155090124447490815L, (DateTimeKind)(3155090124447490815uL >> 62)); s0.EndDate = default(DateTime); s0.Amount = 2; chunks[0] = s0; Chunk s1 = default(Chunk); s1.StartDate = new DateTime(4611686018427387903L & 3155090124447490815L, (DateTimeKind)(3155090124447490815uL >> 62)); s1.EndDate = default(DateTime); s1.Amount = 3; chunks[1] = s1; Chunk s2 = default(Chunk); s2.StartDate = new DateTime(4611686018427387903L & 3155090124447490815L, (DateTimeKind)(3155090124447490815uL >> 62)); s2.EndDate = default(DateTime); s2.Amount = 1; chunks[2] = s2; Chunk s3 = default(Chunk); s3.StartDate = new DateTime(4611686018427387903L & 3154913963112081406L, (DateTimeKind)(3154913963112081406uL >> 62)); s3.EndDate = default(DateTime); s3.Amount = 5; chunks[3] = s3; Chunk s4 = default(Chunk); s4.StartDate = new DateTime(4611686018427387903L & 7766599981539469310L, (DateTimeKind)(7766599981539469310uL >> 62)); s4.EndDate = default(DateTime); s4.Amount = 4; chunks[4] = s4; list = new List<Chunk>((IEnumerable<Chunk>)chunks); list1 = this.apportion(apportionmentManager, list, list); Assert.IsNotNull((object)list1); Assert.AreEqual<int>(0, list1.Capacity); Assert.AreEqual<int>(0, list1.Count); Assert.IsNotNull((object)apportionmentManager); }
public void apportion450() { ApportionmentManager apportionmentManager; List<Chunk> list; List<Chunk> list1; apportionmentManager = new ApportionmentManager(); Chunk[] chunks = new Chunk[5]; Chunk s0 = default(Chunk); s0.StartDate = new DateTime(4611686018427387903L & 1L, (DateTimeKind)(1uL >> 62)); s0.EndDate = default(DateTime); s0.Amount = 3; chunks[0] = s0; Chunk s1 = default(Chunk); s1.StartDate = new DateTime(4611686018427387903L & 1L, (DateTimeKind)(1uL >> 62)); s1.EndDate = default(DateTime); s1.Amount = 2; chunks[1] = s1; Chunk s2 = default(Chunk); s2.StartDate = new DateTime(4611686018427387903L & 1L, (DateTimeKind)(1uL >> 62)); s2.EndDate = default(DateTime); s2.Amount = 4; chunks[2] = s2; Chunk s3 = default(Chunk); s3.StartDate = default(DateTime); s3.EndDate = new DateTime(4611686018427387903L & 1L, (DateTimeKind)(1uL >> 62)); s3.Amount = 5; chunks[3] = s3; Chunk s4 = default(Chunk); s4.StartDate = default(DateTime); s4.EndDate = default(DateTime); s4.Amount = 1; chunks[4] = s4; list = new List<Chunk>((IEnumerable<Chunk>)chunks); list1 = this.apportion(apportionmentManager, list, list); Assert.IsNotNull((object)list1); Assert.AreEqual<int>(8, list1.Capacity); Assert.AreEqual<int>(5, list1.Count); Assert.IsNotNull((object)apportionmentManager); }
public void apportionToPeriod222() { ApportionmentManager apportionmentManager; List<Chunk> list; List<Chunk> list1; apportionmentManager = new ApportionmentManager(); Chunk[] chunks = new Chunk[3]; Chunk s0 = default(Chunk); s0.StartDate = new DateTime(4611686018427387903L & 3074457345618214912L, (DateTimeKind)(3074457345618214912uL >> 62)); s0.EndDate = default(DateTime); s0.Amount = 1; chunks[0] = s0; Chunk s1 = default(Chunk); s1.StartDate = new DateTime(4611686018427387903L & 2305843009213706240L, (DateTimeKind)(2305843009213706240uL >> 62)); s1.EndDate = new DateTime(4611686018427387903L & 2305843009213693952L, (DateTimeKind)(2305843009213693952uL >> 62)); s1.Amount = 3; chunks[1] = s1; Chunk s2 = default(Chunk); s2.StartDate = new DateTime(4611686018427387903L & 2305843009213707265L, (DateTimeKind)(2305843009213707265uL >> 62)); s2.EndDate = new DateTime(4611686018427387903L & 3080462145121419265L, (DateTimeKind)(3080462145121419265uL >> 62)); s2.Amount = 2; chunks[2] = s2; list = new List<Chunk>((IEnumerable<Chunk>)chunks); list1 = this.apportionToPeriod(apportionmentManager, list, default(DateTime), new DateTime(4611686018427387903L & 32L, (DateTimeKind)(32uL >> 62)), AppotionmentPeriod.Annually); Assert.IsNotNull((object)list1); Assert.AreEqual<int>(0, list1.Capacity); Assert.AreEqual<int>(0, list1.Count); Assert.IsNotNull((object)apportionmentManager); }
public void apportionToPeriod604() { ApportionmentManager apportionmentManager; List<Chunk> list; List<Chunk> list1; apportionmentManager = new ApportionmentManager(); Chunk[] chunks = new Chunk[2]; Chunk s0 = default(Chunk); s0.StartDate = new DateTime(4611686018427387903L & 576460752303423491L, (DateTimeKind)(576460752303423491uL >> 62)); s0.EndDate = default(DateTime); s0.Amount = 1; chunks[0] = s0; Chunk s1 = default(Chunk); s1.StartDate = default(DateTime); s1.EndDate = new DateTime(4611686018427387903L & 2882303761517117440L, (DateTimeKind)(2882303761517117440uL >> 62)); s1.Amount = 2; chunks[1] = s1; list = new List<Chunk>((IEnumerable<Chunk>)chunks); list1 = this.apportionToPeriod(apportionmentManager, list, new DateTime(4611686018427387903L & 2305843009213693954L, (DateTimeKind)(2305843009213693954uL >> 62)), new DateTime(4611686018427387903L & 2305860601399738369L, (DateTimeKind)(2305860601399738369uL >> 62)), AppotionmentPeriod.Weekly); Assert.IsNotNull((object)list1); Assert.AreEqual<int>(0, list1.Capacity); Assert.AreEqual<int>(0, list1.Count); Assert.IsNotNull((object)apportionmentManager); }
public void apportionToPeriod599() { ApportionmentManager apportionmentManager; List<Chunk> list; List<Chunk> list1; apportionmentManager = new ApportionmentManager(); Chunk[] chunks = new Chunk[2]; list = new List<Chunk>((IEnumerable<Chunk>)chunks); list1 = this.apportionToPeriod(apportionmentManager, list, new DateTime(4611686018427387903L & 1L, (DateTimeKind)(1uL >> 62)), default(DateTime), (AppotionmentPeriod)0); Assert.IsNull((object)list1); Assert.IsNotNull((object)apportionmentManager); }
public List<Chunk> getDataAtProperty(int propertyId, string startDate, string endDate, int intervalId, int dataTypeId) { Property property = mediator.DataManager.getProperty(propertyId); ///setup vairable for apportionment manager DateTime start = Convert.ToDateTime(startDate); DateTime end = Convert.ToDateTime(endDate); AppotionmentPeriod interval = (AppotionmentPeriod)intervalId; ///property apportioned consumption requires a list of sub-lists, each sub-list the result of interval apportion on that ///meter. the final list returned is the sum of each chunk on the sub list. SO... ///create reference list for dates List<Chunk> datedChunks = mediator.setupDatedChunksForApportionToPeriod(start, end, interval); ///List<Chunk> datedChunks = mediator.getDataFromMeterByInterval(property.Meters.ElementAt(0).Id, startDate, endDate, intervalId, dataTypeId); ///create the containing master list, which will have one list for each meter List<List<Chunk>> masterList = new List<List<Chunk>>(); ///add a new list for each meter, where the list is the result of apportioning the meter by interval foreach (Meter meter in property.Meters) { List<Chunk> apportionedData = mediator.getDataFromMeterByInterval(meter.Id, startDate, endDate, intervalId, dataTypeId); if (apportionedData != null) { masterList.Add(apportionedData); } } ///create result list that will have one list of chunks List<Chunk> resultsList = new List<Chunk>(); foreach (Chunk chunk in datedChunks) { Chunk newChunk = new Chunk() { StartDate = chunk.StartDate, EndDate = chunk.EndDate }; foreach (List<Chunk> subList in masterList) { Chunk matchingChunk = subList.Find(chk => chk.StartDate == chunk.StartDate); try { newChunk.Amount += matchingChunk.Amount; } catch { ///here there is no chunk on the subList at the required index ///can proceed to the next chunk in datedChunks } } resultsList.Add(newChunk); } return resultsList; }
public void apportionThrowsNullReferenceException114() { ApportionmentManager apportionmentManager; List<Chunk> list; List<Chunk> list1; apportionmentManager = new ApportionmentManager(); Chunk[] chunks = new Chunk[3]; Chunk s0 = default(Chunk); s0.StartDate = new DateTime(4611686018427387903L & 720575941453021185L, (DateTimeKind)(720575941453021185uL >> 62)); s0.EndDate = default(DateTime); s0.Amount = 1; chunks[0] = s0; Chunk s1 = default(Chunk); s1.StartDate = new DateTime(4611686018427387903L & 648518346341351426L, (DateTimeKind)(648518346341351426uL >> 62)); s1.EndDate = default(DateTime); s1.Amount = 3; chunks[1] = s1; Chunk s2 = default(Chunk); s2.StartDate = new DateTime(4611686018427387903L & 2954361355555045379L, (DateTimeKind)(2954361355555045379uL >> 62)); s2.EndDate = default(DateTime); s2.Amount = 2; chunks[2] = s2; list = new List<Chunk>((IEnumerable<Chunk>)chunks); list1 = this.apportion(apportionmentManager, (List<Chunk>)null, list); }
public void apportionToPeriodThrowsArgumentOutOfRangeException910() { ApportionmentManager apportionmentManager; List<Chunk> list; List<Chunk> list1; apportionmentManager = new ApportionmentManager(); Chunk[] chunks = new Chunk[2]; Chunk s0 = default(Chunk); s0.StartDate = new DateTime(4611686018427387903L & 3L, (DateTimeKind)(3uL >> 62)); s0.EndDate = default(DateTime); s0.Amount = 1; chunks[0] = s0; Chunk s1 = default(Chunk); s1.StartDate = default(DateTime); s1.EndDate = new DateTime(4611686018427387903L & 2305843009213693952L, (DateTimeKind)(2305843009213693952uL >> 62)); s1.Amount = 2; chunks[1] = s1; list = new List<Chunk>((IEnumerable<Chunk>)chunks); list1 = this.apportionToPeriod(apportionmentManager, list, new DateTime(4611686018427387903L & 1L, (DateTimeKind)(1uL >> 62)), new DateTime(4611686018427387903L & 2305843009213693952L, (DateTimeKind)(2305843009213693952uL >> 62)), (AppotionmentPeriod)0); }
public void apportionToPeriod817() { ApportionmentManager apportionmentManager; List<Chunk> list; List<Chunk> list1; apportionmentManager = new ApportionmentManager(); Chunk[] chunks = new Chunk[2]; Chunk s0 = default(Chunk); s0.StartDate = new DateTime(4611686018427387903L & 3L, (DateTimeKind)(3uL >> 62)); s0.EndDate = default(DateTime); s0.Amount = 1; chunks[0] = s0; Chunk s1 = default(Chunk); s1.StartDate = default(DateTime); s1.EndDate = new DateTime(4611686018427387903L & 35184372088832L, (DateTimeKind)(35184372088832uL >> 62)); s1.Amount = 2; chunks[1] = s1; list = new List<Chunk>((IEnumerable<Chunk>)chunks); list1 = this.apportionToPeriod(apportionmentManager, list, new DateTime(4611686018427387903L & 2L, (DateTimeKind)(2uL >> 62)), new DateTime(4611686018427387903L & 35184372088833L, (DateTimeKind)(35184372088833uL >> 62)), AppotionmentPeriod.Annually); Assert.IsNotNull((object)list1); Assert.AreEqual<int>(0, list1.Capacity); Assert.AreEqual<int>(0, list1.Count); Assert.IsNotNull((object)apportionmentManager); }
public void apportionToPeriod674() { ApportionmentManager apportionmentManager; List<Chunk> list; List<Chunk> list1; apportionmentManager = new ApportionmentManager(); Chunk[] chunks = new Chunk[3]; Chunk s0 = default(Chunk); s0.StartDate = new DateTime(4611686018427387903L & 1537223721734442314L, (DateTimeKind)(1537223721734442314uL >> 62)); s0.EndDate = new DateTime(4611686018427387903L & 262144L, (DateTimeKind)(262144uL >> 62)); s0.Amount = 1; chunks[0] = s0; Chunk s1 = default(Chunk); s1.StartDate = new DateTime(4611686018427387903L & 44259974186992L, (DateTimeKind)(44259974186992uL >> 62)); s1.EndDate = default(DateTime); s1.Amount = 3; chunks[1] = s1; Chunk s2 = default(Chunk); s2.StartDate = new DateTime(4611686018427387903L & 576505012279189504L, (DateTimeKind)(576505012279189504uL >> 62)); s2.EndDate = new DateTime(4611686018427387903L & 2305843009213693952L, (DateTimeKind)(2305843009213693952uL >> 62)); s2.Amount = 2; chunks[2] = s2; list = new List<Chunk>((IEnumerable<Chunk>)chunks); list1 = this.apportionToPeriod(apportionmentManager, list, new DateTime(4611686018427387903L & 2L, (DateTimeKind)(2uL >> 62)), new DateTime(4611686018427387903L & 274877906945L, (DateTimeKind)(274877906945uL >> 62)), AppotionmentPeriod.Annually); Assert.IsNotNull((object)list1); Assert.AreEqual<int>(0, list1.Capacity); Assert.AreEqual<int>(0, list1.Count); Assert.IsNotNull((object)apportionmentManager); }
public void apportionThrowsNullReferenceException944() { ApportionmentManager apportionmentManager; List<Chunk> list; List<Chunk> list1; apportionmentManager = new ApportionmentManager(); Chunk[] chunks = new Chunk[4]; list = new List<Chunk>((IEnumerable<Chunk>)chunks); list1 = this.apportion(apportionmentManager, (List<Chunk>)null, list); }
public void apportionThrowsNullReferenceException783() { ApportionmentManager apportionmentManager; List<Chunk> list; List<Chunk> list1; apportionmentManager = new ApportionmentManager(); Chunk[] chunks = new Chunk[3]; Chunk s0 = default(Chunk); s0.StartDate = default(DateTime); s0.EndDate = default(DateTime); s0.Amount = 2; chunks[0] = s0; Chunk s1 = default(Chunk); s1.StartDate = new DateTime(4611686018427387903L & 1L, (DateTimeKind)(1uL >> 62)); s1.EndDate = default(DateTime); s1.Amount = 1; chunks[1] = s1; Chunk s2 = default(Chunk); s2.StartDate = default(DateTime); s2.EndDate = default(DateTime); s2.Amount = 3; chunks[2] = s2; list = new List<Chunk>((IEnumerable<Chunk>)chunks); list1 = this.apportion(apportionmentManager, (List<Chunk>)null, list); }
public void apportionThrowsNullReferenceException579() { ApportionmentManager apportionmentManager; List<Chunk> list; List<Chunk> list1; apportionmentManager = new ApportionmentManager(); Chunk[] chunks = new Chunk[5]; Chunk s0 = default(Chunk); s0.StartDate = new DateTime(4611686018427387903L & -6067993060854775810L, (DateTimeKind)(12378751012854775806uL >> 62)); s0.EndDate = default(DateTime); s0.Amount = 1; chunks[0] = s0; Chunk s1 = default(Chunk); s1.StartDate = new DateTime(4611686018427387903L & 3155378975999999998L, (DateTimeKind)(3155378975999999998uL >> 62)); s1.EndDate = default(DateTime); s1.Amount = 4; chunks[1] = s1; Chunk s2 = default(Chunk); s2.StartDate = new DateTime(4611686018427387903L & 3155378975999999998L, (DateTimeKind)(3155378975999999998uL >> 62)); s2.EndDate = default(DateTime); s2.Amount = 3; chunks[2] = s2; Chunk s3 = default(Chunk); s3.StartDate = default(DateTime); s3.EndDate = default(DateTime); s3.Amount = 5; chunks[3] = s3; Chunk s4 = default(Chunk); s4.StartDate = default(DateTime); s4.EndDate = default(DateTime); s4.Amount = 2; chunks[4] = s4; list = new List<Chunk>((IEnumerable<Chunk>)chunks); list1 = this.apportion(apportionmentManager, (List<Chunk>)null, list); }
public void apportionThrowsNullReferenceException520() { ApportionmentManager apportionmentManager; List<Chunk> list; List<Chunk> list1; apportionmentManager = new ApportionmentManager(); Chunk[] chunks = new Chunk[3]; Chunk s0 = default(Chunk); s0.StartDate = new DateTime(4611686018427387903L & 2306406027886592000L, (DateTimeKind)(2306406027886592000uL >> 62)); s0.EndDate = default(DateTime); s0.Amount = 2; chunks[0] = s0; Chunk s1 = default(Chunk); s1.StartDate = new DateTime(4611686018427387903L & 563018672898049L, (DateTimeKind)(563018672898049uL >> 62)); s1.EndDate = default(DateTime); s1.Amount = 3; chunks[1] = s1; Chunk s2 = default(Chunk); s2.StartDate = new DateTime(4611686018427387903L & 2305843009213693952L, (DateTimeKind)(2305843009213693952uL >> 62)); s2.EndDate = default(DateTime); s2.Amount = 1; chunks[2] = s2; list = new List<Chunk>((IEnumerable<Chunk>)chunks); list1 = this.apportion(apportionmentManager, (List<Chunk>)null, list); }
public void apportionToPeriod630() { ApportionmentManager apportionmentManager; List<Chunk> list; List<Chunk> list1; apportionmentManager = new ApportionmentManager(); Chunk[] chunks = new Chunk[0]; list = new List<Chunk>((IEnumerable<Chunk>)chunks); list1 = this.apportionToPeriod(apportionmentManager, list, default(DateTime), default(DateTime), (AppotionmentPeriod)0); Assert.IsNull((object)list1); Assert.IsNotNull((object)apportionmentManager); }
/// <summary> /// Converts a list of invoices into a list of Chunks suitable for apportionment /// </summary> /// <param name="invoices"></param> /// <returns></returns> public List<Chunk> convertInvoicesToChunks(List<Invoice> invoices) { List<Chunk> result = new List<Chunk>(); TimeSpan oneDay = new TimeSpan(1, 0, 0, 0); invoices = invoices.OrderBy(inv => inv.StartDate).ToList(); foreach (Invoice inv in invoices) { Chunk chunk = new Chunk(); chunk.StartDate = inv.StartDate; chunk.EndDate = inv.EndDate; chunk.Amount = inv.ConsumptionCharge + inv.StandingCharge + inv.OtherCharge; result.Add(chunk); } return result; }
public void apportionToPeriod768() { ApportionmentManager apportionmentManager; List<Chunk> list; List<Chunk> list1; apportionmentManager = new ApportionmentManager(); Chunk[] chunks = new Chunk[2]; Chunk s0 = default(Chunk); s0.StartDate = new DateTime(4611686018427387903L & 1L, (DateTimeKind)(1uL >> 62)); s0.EndDate = default(DateTime); s0.Amount = 1; chunks[0] = s0; Chunk s1 = default(Chunk); s1.StartDate = default(DateTime); s1.EndDate = default(DateTime); s1.Amount = 2; chunks[1] = s1; list = new List<Chunk>((IEnumerable<Chunk>)chunks); list1 = this.apportionToPeriod(apportionmentManager, list, new DateTime(4611686018427387903L & 1L, (DateTimeKind)(1uL >> 62)), new DateTime(4611686018427387903L & 2305843009213693952L, (DateTimeKind)(2305843009213693952uL >> 62)), (AppotionmentPeriod)0); Assert.IsNull((object)list1); Assert.IsNotNull((object)apportionmentManager); }
//CONVERSION METHODS //CONVERTING READINGS & INVOICES INTO CHUNKS /// <summary> /// Converts a list of meter readings into a list of chunks suitable for apportionment /// </summary> /// <param name="readings">meter readings to convert</param> /// <returns>List[Chunk] from meter readings</returns> public List<Chunk> convertReadingsToChunks(List<MeterReading> readings) { List<Chunk> result = new List<Chunk>(); TimeSpan oneDay = new TimeSpan(1, 0, 0, 0); readings = readings.OrderBy(rdg => rdg.Date).ToList(); foreach (MeterReading rdg in readings) { Chunk chunk = new Chunk(); try { ///start date calculated from date of reading + one day chunk.StartDate = readings.First(r => r.Date == rdg.Date).Date + oneDay; ///end date calulated from date of next reading chunk.EndDate = readings.First(r => r.Date > rdg.Date).Date; ///consumption calculated from consumption of next reading chunk.Amount = readings.First(r => r.Date > rdg.Date).Consumption; } catch { ///no chunk added if there is an error (ie are outside boundaries of list) break; } result.Add(chunk); } return result; }
public void apportionToPeriodThrowsArgumentOutOfRangeException539() { ApportionmentManager apportionmentManager; List<Chunk> list; List<Chunk> list1; apportionmentManager = new ApportionmentManager(); Chunk[] chunks = new Chunk[2]; list = new List<Chunk>((IEnumerable<Chunk>)chunks); list1 = this.apportionToPeriod(apportionmentManager, list, default(DateTime), default(DateTime), (AppotionmentPeriod)0); }
/// <summary> /// Creates List[Chunk], with regular start and end dates for required intervals. Amount = 0 for all Chunks. /// </summary> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <param name="interval"></param> /// <returns>List[Chunk] for required duration, each Chunk covering one interval.</returns> public List<Chunk> setupDatedChunksForApportionToPeriod(DateTime startDate, DateTime endDate, AppotionmentPeriod interval) { ///calendar object used for adding days/months/years to start date System.Globalization.Calendar calendar = System.Globalization.CultureInfo.CurrentCulture.Calendar; ///set up apportionment requirements List<Chunk> datedChunks = new List<Chunk>(); int periodType = (int)interval; ///i used to keep track of how many Chunks have already been created & adds appropriate no. of intervals to start date. int i = 0; ///create list of chunks with correct required start dates do { Chunk chunk = new Chunk(); TimeSpan oneDay = new TimeSpan(1, 0, 0); ///one day timespan needed to calculate end dates switch (periodType) { case 1: ///interval is daily /// chunk.StartDate = calendar.AddDays(startDate, i); chunk.EndDate = calendar.AddDays(chunk.StartDate, 1); break; case 2: ///interval is weekly /// chunk.StartDate = calendar.AddWeeks(startDate, i); chunk.EndDate = calendar.AddWeeks(chunk.StartDate, 1); break; case 3: ///interval is monthly /// chunk.StartDate = calendar.AddMonths(startDate, i); chunk.EndDate = calendar.AddMonths(chunk.StartDate, 1); break; case 4: ///interval is quarterly /// chunk.StartDate = calendar.AddMonths(startDate, 3 * i); chunk.EndDate = calendar.AddMonths(chunk.StartDate, 3 * 1); break; case 5: ///interval is annually /// chunk.StartDate = calendar.AddYears(startDate, i); chunk.EndDate = calendar.AddYears(chunk.StartDate, 1); break; } ///take on day off each date date to avoid overlapping date ranges chunk.EndDate = chunk.EndDate.Subtract(oneDay); datedChunks.Add(chunk); i++; } while (datedChunks.ElementAt(i - 1).EndDate <= endDate); return datedChunks; }
//APPORTIONMENT METHODS /// <summary> /// Takes a list of Chunks with irregular (but consecutive) start and end dates and creates another List[Chunk] with regular start /// and end dates, the consumption of each caclulated from available data. /// Backwards apportionment (where the requested interval is smaller than the interval between readings/invoices) will result in the /// average over the whole period being applied to that chunk. /// Interval, start and end dates for the whole period are determined from the list of Chunks provided. /// </summary> /// <param name="datedChunks"> /// List[Chunk] containing Chunks with regular start/end date for the duration of the period required. /// Create using setupDatedChunksForApportionToPeriod(DateTime startDate, DateTime endDate, AppotionmentPeriod interval) /// </param> /// <param name="dataIn"> /// List[Chunk] containing source data. /// Create using convertReadingsToChunks(List[MeterReading] readings) OR convertInvoicesToChunks(List[Invoices] invoices) /// </param> /// <returns>List[Chunk] of apportioned data.</returns> public List<Chunk> apportion(List<Chunk> datedChunks, List<Chunk> dataIn) { ///create list to store resulting chunks List<Chunk> resultChunks = new List<Chunk>(); ///ensure provided list is in ascending date order dataIn = dataIn.OrderBy(chunk => chunk.StartDate).ToList(); ///determine max start and end dates from dataIn DateTime maxStart = dataIn.First().StartDate; DateTime maxEnd = dataIn.Last().EndDate; ///do the apportioning foreach (Chunk datedChunk in datedChunks) { ///list for storing the chunks from dataIn that are relevant to this results chunk List<Chunk> relevantChunks = new List<Chunk>(); double averageDailyRateOverPeriod = 0; double totalAmountOverPeriod = 0; double periodLength = 0; ///get all relevant chunks in the dataIn list that lie within the date boundaries of this chunk of the results list foreach (Chunk chunk in dataIn) { ///track average daily amount to fill in gaps in 'backwards' apportionment (ie where interval < time between reads) TimeSpan tsInChunk = chunk.EndDate - chunk.StartDate; periodLength += tsInChunk.Days; totalAmountOverPeriod += chunk.Amount; averageDailyRateOverPeriod = totalAmountOverPeriod / periodLength; ///check whether this chunk falls in the chunk on datedChunks & is therefore relevant to calculating ///the total for this datedChunk if ((chunk.StartDate >= datedChunk.StartDate && chunk.StartDate <= datedChunk.EndDate) | (chunk.EndDate >= datedChunk.StartDate && chunk.EndDate <= datedChunk.EndDate)) { relevantChunks.Add(chunk); } } double knownAmount = 0; double estimatedAmount = 0; ///calculate the known amount for this datedChunk using all the relevant chunks gathered in relevantChunks above foreach (Chunk relevantChunk in relevantChunks) { knownAmount += relevantChunk.Amount; } ///determine number of days required by this results chunk TimeSpan ts = datedChunk.EndDate - datedChunk.StartDate; double numbDaysRequired = ts.TotalDays; double dailyRate = 0; ///determine number of days covered by the chunks in this result chunk double numbDaysCovered = new double(); if (relevantChunks.Count != 0) { ts = relevantChunks.ElementAt(relevantChunks.Count - 1).EndDate - relevantChunks.ElementAt(0).StartDate; numbDaysCovered = ts.TotalDays; } else { ///in this case we have to use the average of the whole period calculated above numbDaysCovered = 0; dailyRate = averageDailyRateOverPeriod; } ///determine number of missing days that require estimation double missingDays = numbDaysRequired - numbDaysCovered; ///determine average daily amount from known amount if (numbDaysCovered != 0) { dailyRate = knownAmount / numbDaysCovered; } ///calculate estimated amount estimatedAmount = missingDays * dailyRate; ///create new, final result chunk and add to list Chunk resultChunk = new Chunk { StartDate = datedChunk.StartDate, EndDate = datedChunk.EndDate, Amount = knownAmount + estimatedAmount ///NB if the length of the chunk is greater than required, missingDays will be negative and the total amount ///adjusted downward as necessary }; ///check if chunk lies inside the maxStart and maxEnd range (ie not outide all data available) if ((resultChunk.StartDate >= maxStart && resultChunk.StartDate <= maxEnd) | (resultChunk.EndDate >= maxStart && resultChunk.EndDate <= maxEnd)) { resultChunks.Add(resultChunk); } } return resultChunks; }
public void apportionThrowsInvalidOperationException285() { ApportionmentManager apportionmentManager; List<Chunk> list; List<Chunk> list1; apportionmentManager = new ApportionmentManager(); Chunk[] chunks = new Chunk[0]; list = new List<Chunk>((IEnumerable<Chunk>)chunks); list1 = this.apportion(apportionmentManager, (List<Chunk>)null, list); }