Ejemplo n.º 1
0
        public static void CreateUserStoryCumulativeDataByDay(Connect connect, DumpDataSet ds, int areaId)
        {
            List <int> workItemClosed = new List <int>();

            var workItemRevisions = WorkItemUtil.GetWorkItemRevisions(ds.WorkItemRevision);

            if (StaticUtil.CurrentFuzzFile.MaxStateIndex > 15)
            {
                throw new Exception("UserStoryCumulativeFlow.CreateUserStoryCumulativeData cannot support more than 15 states.");
            }

            DateTime currentDayEnding = FirstFriday(ds.WorkItem);


            SortedList <int, int> lastState = new SortedList <int, int>(); //key = work item ID, value = last day state

            while (currentDayEnding <= new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 23, 59, 59))
            {
                DateTime searchDate = new DateTime(currentDayEnding.Year, currentDayEnding.Month, currentDayEnding.Day, 23, 59, 59);

                DateTime searchBeginning = searchDate.Date;


                foreach (var workItem in Enumerable.Where(ds.WorkItem, x => x.CreatedDate <= searchDate))
                {
                    if (workItem.Type != "User Story" && workItem.Type != "Bug")
                    {
                        continue;
                    }

                    //all revisions up to searchDate
                    var revisions = workItemRevisions.Where(x => x.ID == workItem.ID && x.ChangedDate <= searchDate).OrderBy(y => y.Rev).ToList();

                    if (!revisions.Any())
                    {
                        continue;
                    }



                    DumpDataSet.UserStoryFlow_ByDayRow row = ds.UserStoryFlow_ByDay.NewUserStoryFlow_ByDayRow();
                    row.ID             = workItem.ID;
                    row.Title          = workItem.Title;
                    row.Type           = workItem.Type;
                    row.DayEndingState = StaticUtil.CurrentFuzzFile.GetCurrentWorkItemState(revisions.Last()).CategoryIndex;


                    if (lastState.Any(x => x.Key == workItem.ID))
                    {
                        if (lastState[workItem.ID] == row.DayEndingState)
                        {
                            continue;
                        }
                    }

                    if (workItem.CreatedDate <= searchDate && workItem.CreatedDate >= searchBeginning)
                    {
                        row.NewThisDay = 1;
                    }


                    for (int i = StaticUtil.CurrentFuzzFile.MinStateIndex; i <= StaticUtil.CurrentFuzzFile.MaxStateIndex; i++)
                    {
                        row[string.Format("State{0}Desc", i)] = StaticUtil.CurrentFuzzFile.GetStates(i).First().Category;

                        if (StaticUtil.CurrentFuzzFile.WasInState(revisions, i, searchBeginning, searchDate))
                        {
                            row[string.Format("State{0}", i)] = 1;
                        }
                        else
                        {
                            row[string.Format("State{0}", i)] = 0;
                        }

                        if (StaticUtil.CurrentFuzzFile.EnteredState(revisions, i, searchBeginning, searchDate))
                        {
                            row[string.Format("State{0}Entered", i)] = 1;
                        }
                        else
                        {
                            row[string.Format("State{0}Entered", i)] = 0;
                        }
                    }

                    row.DayEnding = currentDayEnding;

                    if (row.IsNewThisDayNull())
                    {
                        row.NewThisDay = 0;
                    }

                    if (!row.IsState2Null() && row.State2 == 1)
                    {
                        row.ActiveThisDay = 1;
                    }
                    if (!row.IsState4Null() && row.State4 == 1)
                    {
                        row.ActiveThisDay = 1;
                    }

                    if (row.IsActiveThisDayNull())
                    {
                        row.ActiveThisDay = 0;
                    }

                    //closed logic should be:  state was <=4 before this week, and >=5 by the end of this week
                    bool wasInClosedDuringThisWeek = row.DayEndingState >= 5;
                    bool wasClosedBeforeThisWeek   = false;

                    var latestRevFromLastWeek = revisions.Where(x => x.ChangedDate < searchBeginning)
                                                .OrderBy(x => x.Rev).LastOrDefault();
                    if (latestRevFromLastWeek != null)
                    {
                        if (latestRevFromLastWeek.LifecycleState >= 5)
                        {
                            wasClosedBeforeThisWeek = true;
                        }
                    }

                    row.Closed = (wasInClosedDuringThisWeek || wasClosedBeforeThisWeek) ? 1 : 0;

                    if (!wasClosedBeforeThisWeek && wasInClosedDuringThisWeek)
                    {
                        row.ClosedThisDay = 1;
                    }
                    else
                    {
                        row.ClosedThisDay = 0;
                    }

                    if (lastState.Any(x => x.Key == workItem.ID))
                    {
                        lastState[workItem.ID] = row.DayEndingState;
                    }
                    else
                    {
                        lastState.Add(workItem.ID, row.DayEndingState);
                    }

                    ds.UserStoryFlow_ByDay.AddUserStoryFlow_ByDayRow(row);
                }

                currentDayEnding = currentDayEnding.AddDays(1);
            }
        }