-
Notifications
You must be signed in to change notification settings - Fork 4
/
Release.cs
911 lines (825 loc) · 35.8 KB
/
Release.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HPMSdk;
namespace Hansoft.ObjectWrapper
{
/// <summary>
/// Represents a Release item in the Schedule view of Hansoft.
/// </summary>
public class Release : Task
{
static Dictionary<int, CachedData> cachedData = new Dictionary<int, CachedData>();
CachedData cache;
internal class CachedData
{
internal DateTime remainingWorkdaysCachedReleaseDate = DateTime.MinValue;
internal DateTime remainingWorkdaysCachedUpdated = DateTime.MinValue;
internal int remainingWorkDaysCached;
// Index 0: Points, Index 1: Estimated Days, Index 2: WorkRemaining
internal NormalizedBurndownHistory[] normalizedHistoryCached = new NormalizedBurndownHistory[3];
// Index 0: Points, Index 1: Estimated Days, Index 2: WorkRemaining
internal RawBurndownHistory[] rawHistoryCached = new RawBurndownHistory[3];
internal Dictionary<int, double>[] predictedVelocityCache = new Dictionary<int, double>[3];
}
internal static Release GetRelease(HPMUniqueID uniqueID, HPMUniqueID uniqueTaskID)
{
return new Release(uniqueID, uniqueTaskID);
}
private Release(HPMUniqueID uniqueID, HPMUniqueID uniqueTaskID)
: base(uniqueID, uniqueTaskID)
{
if (cachedData.ContainsKey(uniqueTaskID.m_ID))
cache = cachedData[uniqueTaskID.m_ID];
else
{
cache = new CachedData();
cachedData.Add(uniqueTaskID.m_ID, cache);
}
}
/// <summary>
/// The project view that this release belongs to.
/// </summary>
public override ProjectView ProjectView
{
get
{
return Project.Schedule;
}
}
/// <summary>
/// The date of the release.
/// </summary>
public DateTime Date
{
get
{
HPMTaskTimeZones tzData = Session.TaskGetTimeZones(UniqueTaskID);
return HPMUtilities.FromHPMDateTime(tzData.m_Zones[0].m_Start);
}
//TODO: Implement the setter.
}
/// <summary>
/// Returns true if the release has been started (a burndown exists based on a sprint is tagged to the release)
/// </summary>
public bool Started
{
get
{
if (Sprints.Count > 0)
return Sprints.Min(s => s.Start) <= DateTime.Now.Date;
else
return false;
}
}
/// <summary>
/// The start of the release, i.e., the first day of the earliest sprint that is tagged to this release.
/// </summary>
public DateTime Start
{
get
{
if (Sprints.Count > 0)
return Sprints.Min(s => s.Start);
else
return DateTime.MinValue;
}
}
/// <summary>
/// The number of remaining working days before the release date counted from tomorrow.
/// </summary>
public int RemainingWorkDays
{
get
{
if ((cache.remainingWorkDaysCached >= 0 && cache.remainingWorkdaysCachedUpdated != DateTime.Now.Date) || cache.remainingWorkdaysCachedReleaseDate != Date)
{
cache.remainingWorkDaysCached = 0;
DateTime day = DateTime.Now.Date;
cache.remainingWorkdaysCachedUpdated = day;
cache.remainingWorkdaysCachedReleaseDate = Date;
day = day.AddDays(1);
DateTime end = Date.Date;
while (day <= end)
{
if (Project.IsWorkingDay(day))
cache.remainingWorkDaysCached += 1;
day = day.AddDays(1);
}
}
return cache.remainingWorkDaysCached;
}
}
/// <summary>
/// Get all items currently contributing to the burndown, i.e., the items that either are in a sprint tagged to
/// the release, or items that are not committed to a sprint but tagged to the release in the product backlog.
/// </summary>
public List<ProductBacklogItem> ContributingItems
{
get
{
List<ProductBacklogItem> contributors = new List<ProductBacklogItem>();
foreach (Sprint sprint in Sprints)
foreach (ProductBacklogItemInSprint item in sprint.DeepChildren.FindAll(item => item is ProductBacklogItemInSprint))
contributors.Add(item);
// Note!!! This is inlined to optimize performance needed for assigning release risks.
HPMTaskEnum tasks = Session.TaskRefUtilEnumChildren(Project.ProductBacklog.UniqueID, true);
foreach (HPMUniqueID id in tasks.m_Tasks)
{
if (Session.UtilIsIDValid(id) && !Session.TaskRefUtilHasChildren(id))
{
HPMUniqueID idTask = Session.TaskRefGetTask(id);
if (Session.TaskGetLinkedToSprint(idTask) == -1)
{
HPMTaskLinkedToMilestones relIDs = Session.TaskGetLinkedToMilestones(idTask);
foreach (HPMUniqueID relID in relIDs.m_Milestones)
{
if (relID.m_ID == UniqueID.m_ID)
{
contributors.Add((ProductBacklogItem)Task.GetTask(id));
break;
}
}
}
}
}
return contributors;
}
}
enum HistoryKind {Points = 0, EstimatedDays = 1, WorkRemaining = 2}
internal class RawBurndownHistory
{
ulong lastTimeEntry;
DateTime[] times;
double[] values;
internal RawBurndownHistory(int length, ulong lastTimeEntry)
{
this.lastTimeEntry = lastTimeEntry;
this.times = new DateTime[length];
this.values = new double[length];
}
internal void InsertAt(uint index, DateTime dt, double value)
{
times[index] = dt;
values[index] = value;
}
internal int Length
{
get { return values.Length; }
}
internal ulong LastTimeEntry
{
get { return lastTimeEntry; }
}
internal DateTime[] Times
{
get { return times; }
}
internal double[] Values
{
get { return values; }
}
}
private RawBurndownHistory GetRawHistory(HistoryKind historyKind)
{
HPMDataHistoryGetHistoryParameters getHistoryParameters = new HPMDataHistoryGetHistoryParameters();
if (historyKind == HistoryKind.Points)
getHistoryParameters.m_FieldID = EHPMStatisticsField.ComplexityPoints;
else if (historyKind == HistoryKind.EstimatedDays)
getHistoryParameters.m_FieldID = EHPMStatisticsField.EstimatedIdealDays;
getHistoryParameters.m_DataIdent0 = EHPMStatisticsScope.Milestone;
getHistoryParameters.m_DataIdent1 = (uint)UniqueID.m_ID;
int nTries = 0;
HPMDataHistory history = null;
while (nTries < 25)
{
// TODO: Consider to move the reponsibility to the client to register a callback instead. It really isn't kosher to do polling here.
history = Session.DataHistoryGetHistory(getHistoryParameters);
if (history == null)
{
++nTries;
System.Threading.Thread.Sleep(100);
}
else
break;
}
if (history != null && (cache.rawHistoryCached[(int)historyKind] == null || history.m_Latests.m_Time > cache.rawHistoryCached[(int)historyKind].LastTimeEntry))
{
cache.rawHistoryCached[(int)historyKind] = new RawBurndownHistory(history.m_HistoryEntries.Length, history.m_Latests.m_Time);
for (uint j = 0; j < history.m_HistoryEntries.Length; j += 1 )
{
HPMDataHistoryEntry historyEntry = history.m_HistoryEntries[j];
ulong time = historyEntry.m_Time;
DateTime date = HPMUtilities.FromHPMDateTime(time);
if (historyEntry.m_bHasDataRecorded && historyEntry.m_EntryType == EHPMDataHistoryEntryType.Statistics_AbsoluteValue)
{
HPMVariantData data = Session.DataHistoryGetEntryData(history, j);
HPMStatisticsMultiFrequency value = Session.VariantDecode_HPMStatisticsMultiFrequency(data);
cache.rawHistoryCached[(int)historyKind].InsertAt(j, date, value.m_FrequencyEntries[1].m_FrequencyFP);
}
}
cache.normalizedHistoryCached[(int)historyKind] = null;
}
return cache.rawHistoryCached[(int)historyKind];
}
/// <summary>
/// The historic burndown data based on points as stored in the Hansoft database
/// </summary>
internal RawBurndownHistory RawPointsHistory
{
get
{
return GetRawHistory(HistoryKind.Points);
}
}
/// <summary>
/// The historic burndown data based on points as stored in the Hansoft database
/// </summary>
internal RawBurndownHistory RawEstimatedDaysHistory
{
get
{
return GetRawHistory(HistoryKind.EstimatedDays);
}
}
/// <summary>
/// The burndown history for a release, normalized so that one value per day is provided.
/// </summary>
public class NormalizedBurndownHistory
{
DateTime start;
DateTime end;
int length;
double[] values;
internal NormalizedBurndownHistory(DateTime start, DateTime end)
{
this.start = start.Date;
this.end = end.Date;
length = Math.Max((end - start).Days + 1, 0);
values = new double[length];
}
/// <summary>
/// The value of the release burndown for a particular day.
/// </summary>
/// <param name="day">The day to get the bunrndown value for.</param>
/// <returns>THe burndown value.</returns>
public double ValueAt(DateTime day)
{
return values[(day.Date - start).Days];
}
/// <summary>
/// The number of days in the burndown.
/// </summary>
public int Length
{
get { return length; }
}
/// <summary>
/// The first day in the burndown.
/// </summary>
public DateTime Start
{
get { return start; }
}
/// <summary>
/// The last day in the burndown.
/// </summary>
public DateTime End
{
get { return end; }
}
/// <summary>
/// The value for each day in the burndown.
/// </summary>
public double[] Values
{
get { return values; }
}
internal void SetValueAt(int index, double value)
{
values[index] = value;
}
internal void PruneTo(int index)
{
if (index > 0)
{
this.start = start.AddDays(index + 1);
length = length - (index+1);
double[] newValues = new double[length];
for (int i = 0; i < length; i += 1)
{
newValues[i] = values [i + index + 1];
}
values = newValues;
}
}
}
/// <summary>
/// The historic burndown data based on points in a such a way that it reflects the burndown graph in the Hansoft client meaning,
/// there will be a single value in the dataset from the start of the release to the current day. Values will be interpolated and/or pruned
/// as necessary. If no history exists null is returned.
/// </summary>
public NormalizedBurndownHistory NormalizedPointsHistory
{
get
{
if (Started)
return NormalizeHistory(HistoryKind.Points, GetRawHistory(HistoryKind.Points), RemainingPoints);
else
return null;
}
}
/// <summary>
/// The historic burndown data based on estimated days in a such a way that it reflects the burndown graph in the Hansoft client meaning,
/// there will be a single value in the dataset from the start of the release to the current day. Values will be interpolated and/or pruned
/// as necessary. If no history exists null is returned.
/// </summary>
public NormalizedBurndownHistory NormalizedEstimatedDaysHistory
{
get
{
if (Started)
return NormalizeHistory(HistoryKind.EstimatedDays, GetRawHistory(HistoryKind.EstimatedDays), RemainingEstimatedDays);
else
return null;
}
}
private int NextDay(int current, RawBurndownHistory rawHistory)
{
int ind = ScanToLastDayEntry(current, rawHistory);
return ind+1;
}
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];
}
/// <summary>
/// The predicted veclocity in points. The length of the average is determined by the sprint prediction method set
/// in the project options in Hansoft.
/// </summary>
public double PredictedPointsVelocity
{
get
{
NormalizedBurndownHistory normalizedPointsHistory = NormalizedPointsHistory;
if (normalizedPointsHistory!= null && normalizedPointsHistory.Length > 1)
return GetPredictedVelocity(HistoryKind.Points, normalizedPointsHistory, true);
else
return 0;
}
}
/// <summary>
/// The predicted veclocity in estimated datys. The length of the average is determined by the sprint prediction method set
/// in the project options in Hansoft.
/// </summary>
public double PredictedEstimatedDaysVelocity
{
get
{
NormalizedBurndownHistory normalizedEstimatedDaysHistory = NormalizedEstimatedDaysHistory;
if (normalizedEstimatedDaysHistory != null && normalizedEstimatedDaysHistory.Length > 1)
return GetPredictedVelocity(HistoryKind.EstimatedDays, normalizedEstimatedDaysHistory, true);
else
return 0;
}
}
private double GetPredictedVelocity(HistoryKind historyKind, NormalizedBurndownHistory normalizedHistory, bool ignoreNonWorkingdays)
{
int nDays = Project.GetProject(MainProjectID).AverageVelocitySpan;
if (cache.predictedVelocityCache != null && cache.predictedVelocityCache[(int)historyKind].ContainsKey(nDays))
return cache.predictedVelocityCache[(int)historyKind][nDays];
double weightedValueSum = 0;
double weightedDaysSum = 0;
int iDay = nDays;
DateTime day = DateTime.Now.Date;
if (ignoreNonWorkingdays && !Project.IsWorkingDay(day))
day = Project.GetPreviousWorkingDay(day);
DateTime previousDay = day.AddDays(-1);
if (ignoreNonWorkingdays && !Project.IsWorkingDay(previousDay))
previousDay = Project.GetPreviousWorkingDay(previousDay);
for (int i = 0; i < nDays; i += 1)
{
if (previousDay < normalizedHistory.Start)
break;
double velocityOneDay = normalizedHistory.ValueAt(previousDay.Date) - normalizedHistory.ValueAt(day.Date);
weightedValueSum += velocityOneDay * iDay;
weightedDaysSum += iDay;
iDay -= 1;
day = previousDay;
previousDay = previousDay.AddDays(-1);
if (ignoreNonWorkingdays && !Project.IsWorkingDay(previousDay))
previousDay = Project.GetPreviousWorkingDay(day);
}
double prediction = 0;
if (weightedDaysSum > 0)
prediction = weightedValueSum / weightedDaysSum;
if (cache.predictedVelocityCache == null)
{
cache.predictedVelocityCache = new Dictionary<int, double>[3];
for (int i = 0; i < cache.predictedVelocityCache.Length - 1; i += 1)
cache.predictedVelocityCache[i] = new Dictionary<int, double>();
}
cache.predictedVelocityCache[(int)historyKind].Add(nDays, prediction);
return prediction;
}
/// <summary>
/// The future predicted burndown based on the points history.
/// </summary>
public Dictionary<DateTime, double> PointsPredictedBurndown
{
get
{
return GetPredictedBurndown(ExcessPointsPrediction, PredictedPointsVelocity);
}
}
/// <summary>
/// The future predicted burndown based on the estimated days history.
/// </summary>
public Dictionary<DateTime, double> EstimatedDaysPredictedBurndown
{
get
{
return GetPredictedBurndown(ExcessEstimatedDaysPrediction, PredictedEstimatedDaysVelocity);
}
}
private Dictionary<DateTime, double> GetPredictedBurndown(double excessValue, double predictedVelocity)
{
Dictionary<DateTime, double> predictedBurndown = new Dictionary<DateTime, double>();
double excess = excessValue;
DateTime day = DateTime.Now.Date.AddDays(1);
while (day.Date <= Date.Date && excess > 0)
{
if (Project.IsWorkingDay(day))
excess -= predictedVelocity;
predictedBurndown.Add(day.Date, excess);
}
return predictedBurndown;
}
/// <summary>
/// The estimated number of points that will be undone on the current release date.
/// </summary>
public double ExcessPointsPrediction
{
get
{
return RemainingPoints - RemainingWorkDays * PredictedPointsVelocity;
}
}
/// <summary>
/// The estimated number of estimated days that will be undone on the current release date.
/// </summary>
public double ExcessEstimatedDaysPrediction
{
get
{
return RemainingEstimatedDays - RemainingWorkDays * PredictedEstimatedDaysVelocity;
}
}
/// <summary>
/// The predicted date when all items will be completed based on points
/// </summary>
public DateTime PredictedPointsCompletion
{
get
{
return GetPredictedCompletion(ExcessPointsPrediction, PredictedPointsVelocity);
}
}
/// <summary>
/// The predicted date when all items will be completed based on estimated days
/// </summary>
public DateTime PredictedEstimatedDaysCompletion
{
get
{
return GetPredictedCompletion(ExcessEstimatedDaysPrediction, PredictedEstimatedDaysVelocity);
}
}
private DateTime GetPredictedCompletion(double predictedExcess, double predictedVelocity)
{
double excess = predictedExcess;
if (excess == 0)
return Date;
if (predictedVelocity <= 0)
return DateTime.MaxValue;
DateTime prediction = Date.Date;
if (excess > 0)
{
while (excess > 0)
{
prediction = prediction.AddDays(1);
if (Project.IsWorkingDay(prediction))
excess -= predictedVelocity;
}
return prediction;
}
else if (excess < 0)
{
while (excess < 0 && Math.Abs(excess) > predictedVelocity)
{
prediction = prediction.AddDays(-1);
if (Project.IsWorkingDay(prediction))
excess += predictedVelocity;
}
return prediction;
}
return prediction;
}
/// <summary>
/// The current items that are completed and tagged to the release.
/// </summary>
public List<ProductBacklogItem> CompletedItems
{
get
{
List<ProductBacklogItem> completed = new List<ProductBacklogItem>();
foreach (ProductBacklogItem item in ContributingItems)
if (item is ProductBacklogItemInSprint && item.HasChildren)
{
if (!item.DeepChildren.Exists(subitem => (EHPMTaskStatus)((Task)subitem).Status.Value != EHPMTaskStatus.Completed))
completed.Add(item);
}
else if ((EHPMTaskStatus)item.Status.Value == EHPMTaskStatus.Completed)
completed.Add(item);
return completed;
}
}
/// <summary>
/// The current items that are remaining and tagged to the release.
/// </summary>
public List<ProductBacklogItem> RemainingItems
{
get
{
List<ProductBacklogItem> remainingItems = new List<ProductBacklogItem>();
List<ProductBacklogItem> completedItems = CompletedItems;
foreach (ProductBacklogItem item in ContributingItems)
{
bool found = false;
foreach (ProductBacklogItem cItem in completedItems)
{
if (cItem.UniqueTaskID.m_ID == item.UniqueTaskID.m_ID)
{
found = true;
break;
}
}
if (!found)
remainingItems.Add(item);
}
return remainingItems;
}
}
/// <summary>
/// The sum of the points for all non-completed product backlog items in the release
/// </summary>
public double RemainingPoints
{
get
{
return RemainingItems.Sum(item => item.Points);
}
}
/// <summary>
/// The sum of the estimated days for all non-completed product backlog items in the release
/// </summary>
public double RemainingEstimatedDays
{
get
{
return RemainingItems.Sum(item => item.EstimatedDays);
}
}
/// <summary>
/// The non-completed items in the release sorted by priority from higher to lower.
/// </summary>
public List<ProductBacklogItem> RemainingItemsSortedByPriority
{
get
{
return HPMUtilities.SortByPriority(Project, RemainingItems);
}
}
private double[] GetRiskLimits(int remainingWorkDays, double predictedVelocity, double lowRiskLimit, double highRiskLimit)
{
double[] limits = new double[2];
limits[0] = remainingWorkDays * predictedVelocity * lowRiskLimit/100;
limits[1] = remainingWorkDays * predictedVelocity * highRiskLimit/100;
return limits;
}
private double[] GetRiskLimitsPoints(double lowRiskLimit, double highRiskLimit)
{
return GetRiskLimits(RemainingWorkDays, PredictedPointsVelocity, lowRiskLimit, highRiskLimit);
}
private double[] GetRiskLimitsEstimatedDays(double lowRiskLimit, double highRiskLimit)
{
return GetRiskLimits(RemainingWorkDays, PredictedEstimatedDaysVelocity, lowRiskLimit, highRiskLimit);
}
/// <summary>
/// Based on the points history, get the items categorized in to low/medium/high risk to complete by the release date.
/// </summary>
/// <param name="lowRiskLimit">Lower limit value in percent. Items that fit in within the given percentage of remaining estimated capacity will be low risk.</param>
/// <param name="highRiskLimit">Upper limit value in percent. Items that fit in within the given percentage of remaining estimated capacity will be medium risk.</param>
/// <returns></returns>
public List<ProductBacklogItem>[] GetRemainingItemsByRiskPoints(double lowRiskLimit, double highRiskLimit)
{
return RemainingItemsByRisk(RemainingItemsSortedByPriority, HistoryKind.Points, GetRiskLimitsPoints(lowRiskLimit, highRiskLimit));
}
/// <summary>
/// Based on the estimated days history, get the items categorized in to low/medium/high risk to complete by the release date.
/// </summary>
/// <param name="lowRiskLimit">Lower limit value in percent. Items that fit in within the given percentage of remaining estimated capacity will be low risk.</param>
/// <param name="highRiskLimit">Upper limit value in percent. Items that fit in within the given percentage of remaining estimated capacity will be medium risk.</param>
/// <returns></returns>
public List<ProductBacklogItem>[] GetRemainingItemsByRiskEstimatedDays(double lowRiskLimit, double highRiskLimit)
{
return RemainingItemsByRisk(RemainingItemsSortedByPriority, HistoryKind.EstimatedDays, GetRiskLimitsEstimatedDays(lowRiskLimit, highRiskLimit));
}
private List<ProductBacklogItem>[] RemainingItemsByRisk(List<ProductBacklogItem> remainingItemsPriorityOrder, HistoryKind historyKind, double[] limits)
{
List<ProductBacklogItem>[] remainingItemsByRisk = new List<ProductBacklogItem>[3];
remainingItemsByRisk[0] = new List<ProductBacklogItem>();
remainingItemsByRisk[1] = new List<ProductBacklogItem>();
remainingItemsByRisk[2] = new List<ProductBacklogItem>();
double aggregated = 0;
foreach (ProductBacklogItem item in remainingItemsPriorityOrder)
{
double delta = 0;
if (historyKind == HistoryKind.Points)
delta = item.Points;
else if (historyKind == HistoryKind.EstimatedDays)
delta = item.EstimatedDays;
if (aggregated+delta >= limits[1])
remainingItemsByRisk[2].Add(item);
else if (aggregated+delta >= limits[0])
remainingItemsByRisk[1].Add(item);
else
remainingItemsByRisk[0].Add(item);
aggregated += delta;
}
return remainingItemsByRisk;
}
/// <summary>
/// The sprints that are tagged to this release.
/// </summary>
public List<Sprint> Sprints
{
get
{
List<Sprint> taggedToRelease = new List<Sprint>();
foreach (Sprint s in Project.GetProject(MainProjectID).Sprints)
if (s.IsTaggedToRelease(this))
taggedToRelease.Add(s);
return taggedToRelease;
}
}
/// <summary>
/// The scheduled tasks that are tagged to this release.
/// </summary>
public List<ScheduledTask> ScheduledTasks
{
get
{
List<ScheduledTask> taggedToRelease = new List<ScheduledTask>();
foreach (ScheduledTask s in Project.GetProject(MainProjectID).ScheduledTasks)
if (s.IsTaggedToRelease(this))
taggedToRelease.Add(s);
return taggedToRelease;
}
}
/// <summary>
/// The product backlog items that are committed to the schedule and are tagged to this release.
/// </summary>
public List<ProductBacklogItemInSchedule> ProductBacklogItemsInSchedule
{
get
{
List<ProductBacklogItemInSchedule> taggedToRelease = new List<ProductBacklogItemInSchedule>();
foreach (ProductBacklogItemInSchedule s in Project.GetProject(MainProjectID).ProductBacklogItemsInSchedule)
if (s.IsTaggedToRelease(this))
taggedToRelease.Add(s);
return taggedToRelease;
}
}
/// <summary>
/// The product backlog items that are tagged to this release.
/// </summary>
public List<ProductBacklogItem> ProductBacklogItems
{
get
{
List<ProductBacklogItem> taggedToRelease = new List<ProductBacklogItem>();
foreach (ProductBacklogItem s in Project.ProductBacklogItems)
if (s.IsTaggedToRelease(this))
taggedToRelease.Add(s);
return taggedToRelease;
}
}
/// <summary>
/// Not applicable for releases.
/// </summary>
public override HansoftEnumValue Priority
{
get
{
return new HansoftEnumValue(MainProjectID, EHPMProjectDefaultColumn.SprintPriority, EHPMTaskAgilePriorityCategory.None, (int)EHPMTaskAgilePriorityCategory.None);
}
set
{
}
}
}
}