private int ScanToLastDayEntry(int current, RawBurndownHistory rawHistory) { int ind = current; while (ind < (rawHistory.Length - 1) && rawHistory.Times[ind + 1].Date == rawHistory.Times[ind].Date) { ind += 1; } return(ind); }
private int ScanToLastDayEntry(int current, RawBurndownHistory rawHistory) { int ind = current; while ( ind < (rawHistory.Length - 1) && rawHistory.Times[ind+1].Date == rawHistory.Times[ind].Date) ind += 1; return ind; }
private NormalizedBurndownHistory NormalizeHistory(HistoryKind historyKind, RawBurndownHistory rawHistory, double remainingValue) { if (!Started || rawHistory == null) { cache.predictedVelocityCache = null; return null; } if (cache.normalizedHistoryCached[(int)historyKind] != null && cache.normalizedHistoryCached[(int)historyKind].End.Date == DateTime.Now.Date) { if (remainingValue != cache.normalizedHistoryCached[(int)historyKind].Values[cache.normalizedHistoryCached[(int)historyKind].Length - 1]) { cache.normalizedHistoryCached[(int)historyKind].SetValueAt(cache.normalizedHistoryCached[(int)historyKind].Length - 1, remainingValue); cache.predictedVelocityCache = null; } } else { cache.predictedVelocityCache = null; DateTime end = DateTime.Now.Date; cache.normalizedHistoryCached[(int)historyKind] = new NormalizedBurndownHistory(Start, end); DateTime dayToCalculate = Start.Date; int pruneTo = -1; int rawInd = 0; while (rawHistory.Times[rawInd].AddDays(-1).Date < dayToCalculate) rawInd = NextDay(rawInd, rawHistory); for (int iValue = 0; iValue < cache.normalizedHistoryCached[(int)historyKind].Length; iValue += 1) { if (dayToCalculate.Date == end.Date) { cache.normalizedHistoryCached[(int)historyKind].SetValueAt(iValue, remainingValue); break; } if (dayToCalculate.Date < rawHistory.Times[0].AddDays(-1).Date) { pruneTo = iValue; cache.normalizedHistoryCached[(int)historyKind].SetValueAt(iValue, 0); dayToCalculate = dayToCalculate.AddDays(1); } else if (dayToCalculate.Date > rawHistory.Times[rawHistory.Length - 1].AddDays(-1).Date) { cache.normalizedHistoryCached[(int)historyKind].SetValueAt(iValue, rawHistory.Values[rawHistory.Length - 1]); dayToCalculate = dayToCalculate.AddDays(1); } else if (rawInd >= rawHistory.Length) { cache.normalizedHistoryCached[(int)historyKind].SetValueAt(iValue, rawHistory.Values[rawHistory.Length - 1]); dayToCalculate = dayToCalculate.AddDays(1); } else if (dayToCalculate.Date == rawHistory.Times[rawInd].AddDays(-1).Date) { cache.normalizedHistoryCached[(int)historyKind].SetValueAt(iValue, rawHistory.Values[rawInd]); dayToCalculate = dayToCalculate.AddDays(1); rawInd = NextDay(rawInd, rawHistory); } else if (dayToCalculate.Date < rawHistory.Times[rawInd].Date.AddDays(-1)) { // There is a missing value in the middle of the sequence interpolate a value DateTime precedingDate; double precedingValue; if (iValue > 0) { precedingDate = dayToCalculate.AddDays(-1); precedingValue = cache.normalizedHistoryCached[(int)historyKind].Values[iValue - 1]; } else { precedingDate = rawHistory.Times[rawInd-1].Date; precedingValue = rawHistory.Values[rawInd - 1]; } DateTime followingDate = rawHistory.Times[rawInd].Date; double followingValue = rawHistory.Values[rawInd]; if (Project.GetProject(MainProjectID).IsWorkingDay(dayToCalculate)) { TimeSpan span = followingDate - precedingDate; double delta = (followingValue - precedingValue) / span.Days; cache.normalizedHistoryCached[(int)historyKind].SetValueAt(iValue, precedingValue + delta); dayToCalculate = dayToCalculate.AddDays(1); } else { cache.normalizedHistoryCached[(int)historyKind].SetValueAt(iValue, precedingValue); dayToCalculate = dayToCalculate.AddDays(1); } } } cache.normalizedHistoryCached[(int)historyKind].PruneTo(pruneTo); } return cache.normalizedHistoryCached[(int)historyKind]; }
private int NextDay(int current, RawBurndownHistory rawHistory) { int ind = ScanToLastDayEntry(current, rawHistory); return ind+1; }
private NormalizedBurndownHistory NormalizeHistory(HistoryKind historyKind, RawBurndownHistory rawHistory, double remainingValue) { if (!Started || rawHistory == null) { cache.predictedVelocityCache = null; return(null); } if (cache.normalizedHistoryCached[(int)historyKind] != null && cache.normalizedHistoryCached[(int)historyKind].End.Date == DateTime.Now.Date) { if (remainingValue != cache.normalizedHistoryCached[(int)historyKind].Values[cache.normalizedHistoryCached[(int)historyKind].Length - 1]) { cache.normalizedHistoryCached[(int)historyKind].SetValueAt(cache.normalizedHistoryCached[(int)historyKind].Length - 1, remainingValue); cache.predictedVelocityCache = null; } } else { cache.predictedVelocityCache = null; DateTime end = DateTime.Now.Date; cache.normalizedHistoryCached[(int)historyKind] = new NormalizedBurndownHistory(Start, end); DateTime dayToCalculate = Start.Date; int pruneTo = -1; int rawInd = 0; while (rawHistory.Times[rawInd].AddDays(-1).Date < dayToCalculate) { rawInd = NextDay(rawInd, rawHistory); } for (int iValue = 0; iValue < cache.normalizedHistoryCached[(int)historyKind].Length; iValue += 1) { if (dayToCalculate.Date == end.Date) { cache.normalizedHistoryCached[(int)historyKind].SetValueAt(iValue, remainingValue); break; } if (dayToCalculate.Date < rawHistory.Times[0].AddDays(-1).Date) { pruneTo = iValue; cache.normalizedHistoryCached[(int)historyKind].SetValueAt(iValue, 0); dayToCalculate = dayToCalculate.AddDays(1); } else if (dayToCalculate.Date > rawHistory.Times[rawHistory.Length - 1].AddDays(-1).Date) { cache.normalizedHistoryCached[(int)historyKind].SetValueAt(iValue, rawHistory.Values[rawHistory.Length - 1]); dayToCalculate = dayToCalculate.AddDays(1); } else if (rawInd >= rawHistory.Length) { cache.normalizedHistoryCached[(int)historyKind].SetValueAt(iValue, rawHistory.Values[rawHistory.Length - 1]); dayToCalculate = dayToCalculate.AddDays(1); } else if (dayToCalculate.Date == rawHistory.Times[rawInd].AddDays(-1).Date) { cache.normalizedHistoryCached[(int)historyKind].SetValueAt(iValue, rawHistory.Values[rawInd]); dayToCalculate = dayToCalculate.AddDays(1); rawInd = NextDay(rawInd, rawHistory); } else if (dayToCalculate.Date < rawHistory.Times[rawInd].Date.AddDays(-1)) { // There is a missing value in the middle of the sequence interpolate a value DateTime precedingDate; double precedingValue; if (iValue > 0) { precedingDate = dayToCalculate.AddDays(-1); precedingValue = cache.normalizedHistoryCached[(int)historyKind].Values[iValue - 1]; } else { precedingDate = rawHistory.Times[rawInd - 1].Date; precedingValue = rawHistory.Values[rawInd - 1]; } DateTime followingDate = rawHistory.Times[rawInd].Date; double followingValue = rawHistory.Values[rawInd]; if (Project.GetProject(MainProjectID).IsWorkingDay(dayToCalculate)) { TimeSpan span = followingDate - precedingDate; double delta = (followingValue - precedingValue) / span.Days; cache.normalizedHistoryCached[(int)historyKind].SetValueAt(iValue, precedingValue + delta); dayToCalculate = dayToCalculate.AddDays(1); } else { cache.normalizedHistoryCached[(int)historyKind].SetValueAt(iValue, precedingValue); dayToCalculate = dayToCalculate.AddDays(1); } } } cache.normalizedHistoryCached[(int)historyKind].PruneTo(pruneTo); } return(cache.normalizedHistoryCached[(int)historyKind]); }
private int NextDay(int current, RawBurndownHistory rawHistory) { int ind = ScanToLastDayEntry(current, rawHistory); return(ind + 1); }