示例#1
0
        /// <summary>
        /// Get all the tasks (complete or not) for one requirement.
        /// </summary>
        /// <param name="context">Context of the database.</param>
        /// <param name="statistic">DTOStatisticView object that contains the requirement id to filter by.</param>
        /// <returns>An iqueryable collection.</returns>
        private IQueryable <Task> getTotalTasksByReqId(IDbContext context, DTOStatisticView statistic)
        {
            // Get all task by requirement id
            var allTasksByReqId = getAll <Task>(context).Where(x => x.RequirementId == statistic.ItemStatisticId).AsQueryable();

            return(allTasksByReqId);
        }
示例#2
0
        public void getAcumulativeStatisticForReq_text()
        {
            removeAll();
            int Ntasks = 10;

            var projects    = insertProjectsAndgetList(1);
            var requirement = insertAndGetRequirementCollection(1, projects.FirstOrDefault()).FirstOrDefault();
            var taskList    = insertTasksAndgetList(requirement, Ntasks);

            for (int i = 0; i < getR(5, Ntasks); i++)
            {
                var complete = insertAndGetComplete(getRandomCompleteWithIsCompleteTrue(taskList[i]));
                var timer    = insertAndGetTimer(new DTOTimer {
                    TaskId = taskList[i].Id, TimeInSeconds = getR(1500, 3000)
                });
            }

            // Arrange
            var statistic = new DTOStatisticView
            {
                ItemStatisticId = requirement.Id,
                hp = Container.createHp()
            };

            // Act
            var result = Container.createIStatisticService().getRequirementStatistic(statistic);

            // Assert
        }
示例#3
0
        public void getRequirementStatistics_getStatistics_in_DTOStatisticView()
        {
            removeAll();
            int Ntasks = 10;

            var projects    = insertProjectsAndgetList(1);
            var requirement = insertAndGetRequirementCollection(1, projects.FirstOrDefault()).FirstOrDefault();
            var taskList    = insertTasksAndgetList(requirement, Ntasks);

            for (int i = 0; i < getR(5, Ntasks); i++)
            {
                var complete = insertAndGetComplete(getRandomCompleteWithIsCompleteTrue(taskList[i]));
                var timer    = insertAndGetTimer(new DTOTimer {
                    TaskId = taskList[i].Id, TimeInSeconds = getR(1500, 3000)
                });
            }

            // Arrange
            var statistic = new DTOStatisticView
            {
                ItemStatisticId = requirement.Id,
                hp = Container.createHp()
            };

            // Act
            var result = Container.createIRequirementsRepository().getRequirementStatistics(Container.createIDbContext(), statistic);

            // Assert
            bool velocitiesAreOk = false;
            bool totalTaskShouldBeEqualOrHigherThanCompleteTask = false;

            foreach (var item in result)
            {
                velocitiesAreOk = item.VelocityInItemPerSeconds > 0;

                totalTaskShouldBeEqualOrHigherThanCompleteTask = item.TotalItems == item.CompleteItems || item.TotalItems > item.CompleteItems;
            }
            Assert.IsTrue(result != null && result.Count > 0, "It does not return a DTOStatistic collection");
            Assert.IsTrue(velocitiesAreOk && totalTaskShouldBeEqualOrHigherThanCompleteTask, "Velocities are not ok.");
        }
示例#4
0
        /// <summary>
        /// Get statistics for a requirement.
        /// </summary>
        /// <param name="context">Context of the database.</param>
        /// <param name="statistic">Statistic dto that contains the id of the requirement.</param>
        /// <returns>A collection of DTOStatistic with all the needed information to build the statistic.</returns>
        public List <DTOStatistic> getRequirementStatistics(IDbContext context, DTOStatisticView statistic)
        {
            // Get name of the requirement
            var name = getAll <Requirement>(context).Where(x => x.Id == statistic.ItemStatisticId).Select(x => x.Name).FirstOrDefault();

            // Get the total tasks and complete tasks for a requirement
            var completeTasks = getTimeForEachCompleteTaskByReqId(context, statistic).Count();
            var totalTasks    = getTotalTasksByReqId(context, statistic).Select(x => x.Id).Count();

            // Get time for each complete task
            var query = getTimeForEachCompleteTaskByReqId(context, statistic)
                        .AsEnumerable().Select((value, index) => new DTOStatistic
            {
                Id   = index,
                Name = name,

                PercentageComplete     = (double)(index + 1) / (double)totalTasks * 100,
                DescendingItemComplete = totalTasks - (index + 1),

                CompleteItems = completeTasks,
                TotalItems    = totalTasks,

                AcumulativeTimeInSeconds = value,
                VelocityInItemPerSeconds = (double)(index + 1) / (double)value,
                hp = Hp
            }).ToList();

            // Get acumulative time in seconds
            for (int i = 0; i < query.Count; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    query[i].AcumulativeTimeInSeconds += query[j].AcumulativeTimeInSeconds;
                }
            }

            return(query);
        }
示例#5
0
        public DTOStatisticView getProjectStatistic(DTOStatisticView statistic)
        {
            using (DbContext)
            {
                // Get statistics from db
                var statsFromDb = projectRepository.getProjectStatistic(DbContext, statistic);

                // Do not continue if there is not tasks.
                var projectName = projectRepository.getProjectById(DbContext, new DTOProject {
                    Id = statistic.ItemStatisticId
                }).Name;
                if (statsFromDb.Count == 0)
                {
                    return new DTOStatisticView {
                               ItemStatisticName = projectName, ReturnUrl = statistic.ReturnUrl
                    }
                }
                ;

                // Get and return DTOStatisticView
                var ret = getDTOStatisticView(statsFromDb, statistic);
                return(ret);
            }
        }
        private List <DTOProjectStatistic> getReqWithTotalTasks(IDbContext context, DTOStatisticView statistic)
        {
            var query =
                (from req in getAll <Requirement>(context).Where(x => x.ProjectId == statistic.ItemStatisticId)

                 // left join Task
                 join taskRecord in getAll <Task>(context)
                 on req.Id equals taskRecord.RequirementId into taskOuterJoin
                 from task in taskOuterJoin.DefaultIfEmpty()

                 group req by new
            {
                req.Id,
                req.ProjectId
            } into g
                 select new DTOProjectStatistic
            {
                RequirementId = g.Key.Id,
                ProjectId = g.Key.ProjectId,
                TotalTasks = g.Count(),
            }).ToList();

            return(query);
        }
示例#7
0
        private DTOStatisticView getDTOStatisticView(List <DTOStatistic> statsFromDb, DTOStatisticView statistic)
        {
            // Get acumulative graph components
            var acumulative = getAcumulativeGraphComponents(statsFromDb);

            // Get velocity graph components
            var velocity = getVelocityGraphComponents(statsFromDb, statistic);

            // Get completion graph componenets
            var completion = getCompletionGraphComponents(statsFromDb);

            // Set the properties of DTOStatisticView
            var retStatistic = statsFromDb
                               .GroupBy(x => x)
                               .Select(x => new DTOStatisticView
            {
                ItemStatisticName = x.Key.Name,
                ItemStatisticId   = x.Key.Id,
                TimeAxis          = statistic.TimeAxis,
                ReturnUrl         = statistic.ReturnUrl,

                // Acumulative
                AcumulativeGraph = acumulative,

                // Velocity
                VelocityGraph = velocity,

                // Completion
                CompletionGraph = completion,

                hp = Hp
            }).FirstOrDefault();

            // Return the statistic just built or a new one if it was null
            return((retStatistic != null) ? retStatistic : new DTOStatisticView());
        }
示例#8
0
        /// <summary>
        /// Get velocity graph components such as marking, axis, and series.
        /// </summary>
        /// <param name="statsFromDb">DTOStatistic collection from db.</param>
        /// <param name="statistic">DTOStatisticView that contains information about the id of the item.</param>
        /// <returns>A DTOVelocityStatistic object that corresponds to the velocity graph.</returns>
        private DTOVelocityStatistic getVelocityGraphComponents(List <DTOStatistic> statsFromDb, DTOStatisticView statistic)
        {
            // Get serie
            var velocitySerie = (from velocityRecord in statsFromDb.Select(z => new { Id = z.Id, Velocity = z.VelocityInItemPerSeconds })
                                 join timeRecord in statsFromDb.Select(z => new { Id = z.Id, z.AcumulativeTimeInSeconds })
                                 on velocityRecord.Id equals timeRecord.Id
                                 select new double[] { timeRecord.AcumulativeTimeInSeconds, velocityRecord.Velocity }).ToList();

            // Get average
            var averageVelocity = statsFromDb.Average(y => y.VelocityInItemPerSeconds);

            // Map dto an return it.
            return(new DTOVelocityStatistic
            {
                AverageVelocitySeconds = averageVelocity,
                VelocitySerieSeconds = velocitySerie
            });
        }
        public void getProjectStatistic_getStatistics_in_DTOStatisticView()
        {
            removeAll();
            int NRequirements       = 6;
            int NumberOfCompleteReq = 4;
            int Ntasks = 6;
            int NFrom  = 3; // <- This should be lower than NTasks

            var projects = insertProjectsAndgetList(10);

            foreach (var project in projects)
            {
                var requirements = insertAndGetRequirementCollection(NRequirements, project);
                for (int i = 0; i < requirements.Count; i++)
                {
                    var taskList = insertTasksAndgetList(requirements[i], Ntasks);

                    // Set complete requirements
                    if (i < NumberOfCompleteReq)
                    {
                        foreach (var task in taskList)
                        {
                            var complete = insertAndGetComplete(getRandomCompleteWithIsCompleteTrue(task));
                            var timer    = insertAndGetTimer(new DTOTimer {
                                TaskId = task.Id, TimeInSeconds = getR(1500, 5500)
                            });
                        }
                    }
                    // Set incomplete requirements
                    else
                    {
                        for (int j = 0; j < getR(NFrom, Ntasks); j++)
                        {
                            var complete = insertAndGetComplete(getRandomCompleteWithIsCompleteTrue(taskList[j]));
                            var timer    = insertAndGetTimer(new DTOTimer {
                                TaskId = taskList[j].Id, TimeInSeconds = getR(1500, 3000)
                            });
                        }
                    }
                }
            }
            // Arrange
            var statistic = new DTOStatisticView
            {
                ItemStatisticId = projects.FirstOrDefault().Id,
                hp = Container.createHp()
            };

            // Act
            Container.createIProjectRepository().getProjectStatistic(Container.createIDbContext(), statistic);

            // Assert
            //bool velocitiesAreOk = false;
            //bool totalTaskShouldBeEqualOrHigherThanCompleteTask = false;
            //foreach (var item in result)
            //{
            //    velocitiesAreOk = item.VelocityInTaskPerSeconds > 0;

            //    totalTaskShouldBeEqualOrHigherThanCompleteTask = item.TotalTasks == item.CompleteTasks || item.TotalTasks > item.CompleteTasks;
            //}
            //Assert.IsTrue(result != null && result.Count > 0, "It does not return a DTOStatistic collection");
            //Assert.IsTrue(velocitiesAreOk && totalTaskShouldBeEqualOrHigherThanCompleteTask, "Velocities are not ok.");
        }
示例#10
0
        private List <DTOProjectStatistic> getReqWithTaskAcumulativeTime(IDbContext context, DTOStatisticView statistic)
        {
            // Get all the requirement with task time
            var query = (from req in getAll <Requirement>(context).Where(x => x.ProjectId == statistic.ItemStatisticId)

                         // left join Task
                         join taskRecord in getAll <Task>(context)
                         on req.Id equals taskRecord.RequirementId

                         // left join complete
                         join completeRecord in getAll <Complete>(context)
                         on taskRecord.Id equals completeRecord.TaskId

                         // left join complete
                         join timerRecord in getAll <Timer>(context)
                         on taskRecord.Id equals timerRecord.TaskId
                         where completeRecord.IsComplete
                         select new DTOProjectStatistic
            {
                RequirementId = req.Id,
                ProjectId = req.ProjectId,
                Time = timerRecord.TimeInSeconds,
                FinalizationDate = completeRecord.FinalizationDate
            }).ToList();


            // Loop throuh all the requirement and calculate finalization date and acumulative time
            var reqsWithAcumulativeTime = new List <DTOProjectStatistic>();

            var reqsIdWithCompleteStatus = query.GroupBy(x => x.RequirementId).Select(x => new { Id = x.Key }).ToList();

            foreach (var req in reqsIdWithCompleteStatus)
            {
                var tasks = query.Where(x => x.RequirementId == req.Id).ToList();

                var latestFinalizationDate = tasks
                                             .OrderByDescending(x => x.FinalizationDate)
                                             .FirstOrDefault().FinalizationDate; // ORDER BY FINALIZATION DATE

                var acumulativeTime = tasks
                                      .GroupBy(x => new { x.RequirementId })
                                      .Select(x => x.Sum(z => z.Time))
                                      .FirstOrDefault(); // ORDER BY FINALIZATION DATE

                reqsWithAcumulativeTime.Add(new DTOProjectStatistic
                {
                    RequirementId    = req.Id,
                    AcumulativeTime  = acumulativeTime,
                    FinalizationDate = latestFinalizationDate
                });
            }

            return(reqsWithAcumulativeTime);
        }
示例#11
0
        /// <summary>
        /// Get project statistics from db.
        /// </summary>
        /// <param name="context">Context of the database.</param>
        /// <param name="statistic">Statistic dto object that contains the id of the project.</param>
        /// <returns>A collection of DTOStatistic objects representing the statistic for each requirement.</returns>
        public List <DTOStatistic> getProjectStatistic(IDbContext context, DTOStatisticView statistic)
        {
            // Get requirement with total tasks
            var reqsWithTotalTasks = getReqWithTotalTasks(context, statistic);

            // Get requirements with complete tasks
            var reqsWithCompleteTasks = getReqWithCompleteTasks(context, statistic);

            // Get requirements with acumulativeT
            var reqsWithAcumulativeTime = getReqWithTaskAcumulativeTime(context, statistic);

            // Get total requirements, each one with totalTasks, completeTasks, AcumulativeTime and finalizationTime.
            var totalReqs = (from totalTaskRecord in reqsWithTotalTasks
                             join completeTaskRecord in reqsWithCompleteTasks
                             on totalTaskRecord.RequirementId equals completeTaskRecord.RequirementId into completeOuterJoin
                             from complete in completeOuterJoin.DefaultIfEmpty()
                             join timeRecord in reqsWithAcumulativeTime
                             on totalTaskRecord.RequirementId equals timeRecord.RequirementId into timerOuterJoin
                             from timer in timerOuterJoin.DefaultIfEmpty()
                             select new DTOProjectStatistic
            {
                RequirementId = totalTaskRecord.RequirementId,
                TotalTasks = totalTaskRecord.TotalTasks,
                TotalCompleteTasks = complete.TotalCompleteTasks,
                AcumulativeTime = timer.AcumulativeTime,
                FinalizationDate = timer.FinalizationDate,
                Time = 0
            }).ToList();

            // Get complete requirements, each one with totalTasks, completeTasks, AcumulativeTime and finalizationTime.
            var completeReqs = totalReqs.Where(x => x.TotalTasks == x.TotalCompleteTasks)
                               .OrderBy(x => x.FinalizationDate)  // ORDER BY FINALIZATION DATE
                               .ToList();

            // Set the DTOStatistic collection
            int totalRequirements    = totalReqs.Count;
            int completeRequirements = completeReqs.Count();
            var projectName          = getAll <Project>(context).Where(x => x.Id == statistic.ItemStatisticId).Select(x => x.Name).FirstOrDefault();

            var statsFromDb = completeReqs.Select((value, index) => new DTOStatistic
            {
                Id   = index,
                Name = projectName,

                PercentageComplete     = (double)(index + 1) / (double)totalRequirements * 100,
                DescendingItemComplete = totalRequirements - (index + 1),

                TotalItems    = totalRequirements,
                CompleteItems = 0,

                AcumulativeTimeInSeconds = value.AcumulativeTime,
                VelocityInItemPerSeconds = (double)(index + 1) / (double)value.AcumulativeTime,
                hp = Hp
            }).ToList();

            // Get acumulative time in seconds
            for (int i = 0; i < statsFromDb.Count; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    statsFromDb[i].AcumulativeTimeInSeconds += statsFromDb[j].AcumulativeTimeInSeconds;
                }
            }

            return(statsFromDb);
        }
示例#12
0
        /// <summary>
        /// Get an iqueryable collection with the time for each task.
        /// </summary>
        /// <param name="context">Context of the database.</param>
        /// <param name="statistic">DTOStatisticView object that contains the id to filter by.</param>
        /// <returns>An iqueryable collection.</returns>
        private IQueryable <int> getTimeForEachCompleteTaskByReqId(IDbContext context, DTOStatisticView statistic)
        {
            var completeTasks = (from taskRecord in getTotalTasksByReqId(context, statistic)
                                 join completeRecord in getAll <Complete>(context) on taskRecord.Id equals completeRecord.TaskId
                                 join timerRecord in getAll <Timer>(context) on taskRecord.Id equals timerRecord.TaskId
                                 where completeRecord.IsComplete
                                 orderby completeRecord.FinalizationDate ascending // ORDER BY FINALIZATION DATE
                                 select timerRecord.TimeInSeconds).AsQueryable();

            return(completeTasks);
        }
示例#13
0
 // GET: Project
 public ActionResult Project(DTOStatisticView statistic)
 {
     return(View("Index", statisticService.getProjectStatistic(statistic)));
 }
示例#14
0
 // GET: Requirement
 public ActionResult Requirement(DTOStatisticView statistic)
 {
     return(View("Index", statisticService.getRequirementStatistic(statistic)));
 }