コード例 #1
0
        public TracktorReport GetReport(DateTime?startDate, DateTime endDate, int projectID, int taskID)
        {
            Debug.Assert(!startDate.HasValue || startDate.Value.Kind != DateTimeKind.Utc, "Start Date should not be UTC!");
            Debug.Assert(endDate.Kind != DateTimeKind.Utc, "End Date should not be UTC!");

            List <TEntry> entries = GetEntries(startDate, endDate, projectID, taskID);
            var           report  = new TracktorReport(startDate, endDate.AddDays(-1));

            foreach (var entry in entries)
            {
                BucketEntry(entry, report);
            }
            return(report);
        }
コード例 #2
0
        public TSummaryModelDto BuildSummaryModel(DateTime?startDate, DateTime endDate)
        {
            Debug.Assert(!startDate.HasValue || startDate.Value.Kind != DateTimeKind.Utc, "Start Date should not be UTC!");
            Debug.Assert(endDate.Kind != DateTimeKind.Utc, "End Date should not be UTC!");

            var model = new TSummaryModelDto
            {
                Projects = _db.TProjects.Where(p => p.TUserID == mContext.TUserID).ToList().Select(p => Mapper.Map <TProjectDto>(p)).ToList()
            };

            var           taskToProject = model.Projects.SelectMany(p => p.TTasks.Select(t => new KeyValuePair <int, int>(t.TTaskID, t.TProjectID))).ToDictionary(t => t.Key, p => p.Value);
            List <TEntry> entries       = GetEntries(startDate, endDate, 0, 0);

            foreach (var taskEntry in entries.GroupBy(e => e.TTaskID))
            {
                if (taskToProject.ContainsKey(taskEntry.Key))
                {
                    var projectDto = model.Projects.SingleOrDefault(p => p.TProjectID == taskToProject[taskEntry.Key]);
                    if (projectDto != null)
                    {
                        var taskDto = projectDto.TTasks.SingleOrDefault(t => t.TTaskID == taskEntry.Key);
                        if (taskDto != null)
                        {
                            var report = new TracktorReport(startDate, endDate);
                            foreach (var entry in taskEntry)
                            {
                                var totalContrib = BucketEntry(entry, report);
                                if (!entry.EndDate.HasValue)
                                {
                                    taskDto.InProgress    = true;
                                    projectDto.InProgress = true;
                                    model.InProgress      = true;
                                }
                            }
                            taskDto.Contrib = report.GetContrib();
                        }
                    }
                }
            }

            return(model);
        }
コード例 #3
0
        protected double BucketEntry(TEntry entry, TracktorReport report)
        {
            DateTime localStart   = ToLocal(entry.StartDate).Value;
            DateTime localEnd     = ToLocal(entry.EndDate.HasValue ? entry.EndDate : DateTime.UtcNow).Value;
            DateTime firstDay     = localStart.Date;
            DateTime lastDay      = localEnd.Date;
            DateTime currentDay   = firstDay;
            double   totalContrib = 0;

            while (currentDay <= lastDay)
            {
                DateTime nextDay       = currentDay.AddDays(1);
                DateTime periodStart   = currentDay > localStart ? currentDay : localStart;
                DateTime periodEnd     = nextDay > localEnd ? localEnd : nextDay;
                var      periodContrib = (periodEnd - periodStart).TotalSeconds;
                report.AddContrib(currentDay, entry.TTaskID, periodContrib);
                currentDay    = nextDay;
                totalContrib += periodContrib;
            }
            return(totalContrib);
        }
コード例 #4
0
        public List <TEntryDto> CalculateEntryContribs(List <TEntry> entries, DateTime?startDate, DateTime endDate)
        {
            Debug.Assert(!startDate.HasValue || startDate.Value.Kind != DateTimeKind.Utc, "Start Date should not be UTC!");
            Debug.Assert(endDate.Kind != DateTimeKind.Utc, "End Date should not be UTC!");

            var dtos         = new List <TEntryDto>();
            var descriptions = _db.TTasks.Where(t => t.TProject.TUserID == mContext.TUserID).Select(t => new { TTaskID = t.TTaskID, TaskName = t.Name, ProjectName = t.TProject.Name }).
                               ToDictionary(t => t.TTaskID, t => t);
            var report = new TracktorReport(startDate, endDate);

            foreach (var entry in entries)
            {
                var entryDto    = Mapper.Map <TEntryDto>(entry);
                var description = descriptions[entry.TTaskID];
                entryDto.TaskName    = description.TaskName;
                entryDto.ProjectName = description.ProjectName;
                entryDto.Contrib     = BucketEntry(entry, report);
                entryDto.InProgress  = (!entry.EndDate.HasValue);
                EnrichTEntry(entryDto, entry);
                dtos.Add(entryDto);
            }

            return(dtos);
        }