private Dictionary <TaskItemType, ScatterPlotData> PopulateScatterPlotLeadTimeInfo(TaskItem[] rawData, Dictionary <TaskItemType, ScatterPlotData> scatterPlotData)
        {
            var taskItemHelper = new TaskItemHelper();

            foreach (var taskItem in rawData)
            {
                try
                {
                    if (taskItemHelper.TaskItemTypeIsSelected(Product, Engineering, Unanticipated, taskItem) &&
                        taskItemHelper.TaskItemDevTeamIsSelected(AssessmentsTeam, EnterpriseTeam, taskItem))
                    {
                        var typeIndex = (int)taskItem.Type - 1;

                        var newData = new Datum
                        {
                            x = taskItem.FinishTime,
                            y = taskItem.CalculateLeadTimeHours()
                        };
                        if (newData.x < new DateTimeOffset(DateTime.Now.AddYears(-1)))
                        {
                            continue;
                        }

                        scatterPlotData[taskItem.Type].data.Add(newData);
                    }
                }
                catch (Exception ex)
                {
                    // ignored
                }
            }

            return(scatterPlotData);
        }
Esempio n. 2
0
        public async Task <BoxGraphData> GetLeadTimeBoxGraphData(DateTimeOffset startDate, DateTimeOffset finishDate,
                                                                 bool product, bool engineering, bool unanticipated, bool assessmentsTeam, bool enterpriseTeam)
        {
            Product         = product;
            Engineering     = engineering;
            Unanticipated   = unanticipated;
            AssessmentsTeam = assessmentsTeam;
            EnterpriseTeam  = enterpriseTeam;

            var boxGraphData = new BoxGraphData
            {
                Entries = new List <BoxGraphDataEntry>
                {
                    new BoxGraphDataEntry(),
                    new BoxGraphDataEntry(),
                    new BoxGraphDataEntry(),
                    new BoxGraphDataEntry()
                },
                Outliers = new List <object[]>()
            };

            var taskItems = await taskItemRepository.GetTaskItemListAsync(startDate, finishDate);

            var taskItemsByType = new[]
            {
                new List <TaskItem>(),
                new List <TaskItem>(),
                new List <TaskItem>()
            };

            var finalTaskItemList = new List <TaskItem>();

            foreach (var item in taskItems
                     .Where(item => taskItemHelper.TaskItemDevTeamIsSelected(AssessmentsTeam, EnterpriseTeam, item)))
            {
                taskItemsByType[(int)item.Type - 1].Add(item);
                if (taskItemHelper.TaskItemTypeIsSelected(Product, Engineering, Unanticipated, item))
                {
                    finalTaskItemList.Add(item);
                }
            }

            foreach (var itemList in taskItemsByType)
            {
                if (itemList.Count > 0)
                {
                    var sortedItemList = SortByLeadTime(itemList);
                    var index          = (int)itemList[0].Type - 1;
                    boxGraphData = CalculateBoxGraphData(sortedItemList, boxGraphData, index);
                }
            }

            boxGraphData = CalculateBoxGraphData(SortByLeadTime(finalTaskItemList), boxGraphData, 3);
            boxGraphData.Entries[3].TaskItemType = "Selected Task Items";

            return(boxGraphData);
        }
        public async Task <MultinomialLogisticRegressionAnalysisItemList> GetLogisticRegressionAnalysisData(
            DateTimeOffset?startDate, DateTimeOffset?finishDate,
            bool product, bool engineering, bool unanticipated, bool assessmentsTeam, bool enterpriseTeam)
        {
            var logisticRegressionData = new MultinomialLogisticRegressionAnalysisItemList();

            var taskItemRepository = new TaskItemRepository();
            var taskItemList       = await taskItemRepository.GetTaskItemListAsync(startDate, finishDate);

            logisticRegressionData.UserIds = GetUserIds(taskItemList);

            var inputs         = new List <List <double> >();
            var outputList     = new List <int>();
            var ids            = new List <int>();
            var titles         = new List <string>();
            var taskItemHelper = new TaskItemHelper();

            foreach (var logisticRegressionTaskItem
                     in from taskItem in taskItemList
                     where taskItem.StartTime != null &&
                     taskItem.FinishTime != null &&
                     taskItemHelper.TaskItemDevTeamIsSelected(assessmentsTeam, enterpriseTeam, taskItem)
                     select GetLogisticRegressionTaskItem(taskItem))
            {
                ids.Add(logisticRegressionTaskItem.Id);
                titles.Add(logisticRegressionTaskItem.Title);
                inputs.Add(new List <double>
                {
                    logisticRegressionTaskItem.Lifetime.TotalDays,
                    logisticRegressionTaskItem.LeadTime.TotalDays,
                    logisticRegressionTaskItem.TimeSpentInBacklog.TotalDays,
                    (logisticRegressionTaskItem.DevTeamIsAssessments ? 1.0 : 0.0),
                    (logisticRegressionTaskItem.DevTeamIsEnterprise ? 1.0 : 0.0),
                    logisticRegressionTaskItem.NumRevisions
                });

                foreach (var user in logisticRegressionData.UserIds)
                {
                    inputs.Last().Add(logisticRegressionTaskItem.CreatedById == user ? 1.0 : 0.0);
                }

                foreach (var user in logisticRegressionData.UserIds)
                {
                    inputs.Last().Add(logisticRegressionTaskItem.LastChangedBy.Id == user ? 1.0 : 0.0);
                }

                outputList.Add((int)logisticRegressionTaskItem.TaskItemType);
            }

            var inputArray    = inputs.Select(inputList => inputList.ToArray()).ToArray();
            var actualResults = outputList.ToArray();

            var lbnr = new LowerBoundNewtonRaphson()
            {
                MaxIterations = 100,
                Tolerance     = 1e-6
            };

            var mlr = lbnr.Learn(inputArray, actualResults);

            var predictions = mlr.Decide(inputArray);

            var probabilities = mlr.Probabilities(inputArray);

            logisticRegressionData.Error = new ZeroOneLoss(actualResults).Loss(predictions);

            for (var i = 0; i < ids.Count; i++)
            {
                if (taskItemHelper.TaskItemTypeIsSelected(product, engineering, unanticipated, actualResults[i]))
                {
                    var probability = probabilities[i].Max();

                    var logisticRegressionItem = new MultinomialLogisticRegressionAnalysisItem
                    {
                        Id          = ids[i],
                        Inputs      = inputs[i],
                        Title       = titles[i],
                        Actual      = actualResults[i],
                        Prediction  = predictions[i],
                        Probability = probability
                    };

                    if (logisticRegressionItem.Actual != logisticRegressionItem.Prediction)
                    {
                        logisticRegressionData.Items.Add(logisticRegressionItem);
                    }
                }
            }

            return(logisticRegressionData);
        }
Esempio n. 4
0
        public async Task <CumulativeFlowData> GetCumulativeFlowDataAsync(DateTimeOffset startTime, DateTimeOffset finishTime,
                                                                          bool product, bool engineering, bool unanticipated, bool assessmentsTeam, bool enterpriseTeam)
        {
            var cumulativeFlowData = new CumulativeFlowData();

            var taskList = await GetTaskItemsAsync(startTime, finishTime);

            var startDate   = GetStartDate(taskList, startTime);
            var finishDate  = GetFinishDate(taskList, finishTime);
            var currentDate = startDate;
            var rawData     = new Dictionary <DateTimeOffset, Dictionary <TaskItemState, int> >();
            var dates       = new List <DateTimeOffset>();

            while (currentDate <= finishDate)
            {
                dates.Add(currentDate);
                cumulativeFlowData.dates.Add(currentDate.ToString("M"));
                rawData.Add(currentDate, new Dictionary <TaskItemState, int>
                {
                    { TaskItemState.Backlog, 0 },
                    { TaskItemState.TopPriority, 0 },
                    { TaskItemState.InProcess, 0 },
                    { TaskItemState.Released, 0 }
                });
                currentDate = currentDate.AddDays(1);
            }

            var taskItemHelper = new TaskItemHelper();

            foreach (var task in taskList)
            {
                if (taskItemHelper.TaskItemTypeIsSelected(product, engineering, unanticipated, task) &&
                    taskItemHelper.TaskItemDevTeamIsSelected(assessmentsTeam, enterpriseTeam, task))
                {
                    HistoryEvent lastHistoryEvent = null;
                    foreach (var historyEvent in task.HistoryEvents)
                    {
                        if (historyEvent.TaskItemState == TaskItemState.None ||
                            historyEvent.EventDate.Date < startDate ||
                            historyEvent.EventDate.Date > finishDate)
                        {
                            continue;
                        }

                        var date = historyEvent.EventDate.Date;

                        while (date <= finishDate)
                        {
                            rawData[date][historyEvent.TaskItemState]++;
                            if (lastHistoryEvent != null)
                            {
                                rawData[date][lastHistoryEvent.TaskItemState]--;
                            }

                            date = date.AddDays(1);
                        }

                        lastHistoryEvent = historyEvent;
                    }
                }
            }

            var backlogData     = new List <int>();
            var topPriorityData = new List <int>();
            var inProcessData   = new List <int>();
            var releasedData    = new List <int>();

            foreach (var date in dates)
            {
                backlogData.Add(rawData[date][TaskItemState.Backlog]);
                topPriorityData.Add(rawData[date][TaskItemState.TopPriority]);
                inProcessData.Add(rawData[date][TaskItemState.InProcess]);
                releasedData.Add(rawData[date][TaskItemState.Released]);
            }

            cumulativeFlowData.data.Add(new CumulativeFlowDataRow {
                name = "Backlog",
                data = backlogData
            });
            cumulativeFlowData.data.Add(new CumulativeFlowDataRow {
                name = "Top Priority",
                data = topPriorityData
            });
            cumulativeFlowData.data.Add(new CumulativeFlowDataRow {
                name = "In Process",
                data = inProcessData
            });
            cumulativeFlowData.data.Add(new CumulativeFlowDataRow {
                name = "Released",
                data = releasedData
            });

            return(cumulativeFlowData);
        }