Exemplo n.º 1
0
        public async Task <ChartVm> GetBurndownChart(Guid id)
        {
            try
            {
                var board = await _context.Boards.Where(b => b.Id == id && b.IsActive == true).FirstOrDefaultAsync();

                if (board == null)
                {
                    return(null);
                }

                var from      = board.BoardStart;
                var to        = board.BoardEnd;
                var totalDays = (to - from).Days < 7 ? (to - from).Days : 7;

                var taskData = new ChartDataVm();
                taskData.Label = "Actual Hours";
                List <string> dateLables = new List <string>();
                for (int i = 0; i < totalDays; i++)
                {
                    taskData.Data.Add(await _context.DailyData
                                      .Where(e => e.Date.Date == DateTime.Now.AddDays(i * -1).Date&& e.BoardId == id)
                                      .Select(x => x.LoggedHours)
                                      .FirstOrDefaultAsync());
                    dateLables.Add("Day " + (i + 1));
                }

                var timeList = await _context.AgileItems
                               .Where(c => c.IsActive && c.BoardId == id && c.AgileItemType == Models.Types.AgileItemType.Task)
                               .Select(x => Convert.ToInt32(x.EstimatedTime)).ToListAsync();

                var countTasks = 0;
                foreach (var time in timeList)
                {
                    countTasks += time;
                }

                var timePerDay        = countTasks / totalDays;
                var estimatedTaskData = new ChartDataVm();
                estimatedTaskData.Label = "Estimated Hours";
                for (int i = 0; i < totalDays; i++)
                {
                    if (i != 0)
                    {
                        estimatedTaskData.Data.Add(estimatedTaskData.Data[i - 1] + timePerDay);
                    }
                    else
                    {
                        estimatedTaskData.Data.Add(timePerDay);
                    }
                }

                estimatedTaskData.Data.Reverse();
                taskData.Data.Reverse();

                return(new ChartVm
                {
                    ChartData = taskData,
                    ChartComparisonData = estimatedTaskData,
                    ChartTitle = board.BoardName + " Burndown",
                    DataLabels = dateLables,
                });
            }
            catch (Exception e)
            {
                // exception getting burndown chart
            }
            return(null);
        }
Exemplo n.º 2
0
        public ChartDataVm GetChartData(AnalyticsChartDataParams @params)
        {
            var result = new ChartDataVm();

            var impQuery = ImportRepository.ImportedFilesQuery();
            var delQuery = ImportRepository.FileUploadQuery().Include(f => f.ImportedFile);

            if (@params.MasterAccountId != 0)
            {
                impQuery = impQuery.Where(f => f.MasterAccountId == @params.MasterAccountId);
                delQuery = delQuery.Where(f => f.ImportedFile.MasterAccountId == @params.MasterAccountId);
            }

            if (@params.FtpCredentialId != 0)
            {
                impQuery = impQuery.Where(f => f.FtpCredentialId == @params.FtpCredentialId);
                delQuery = delQuery.Where(f => f.ImportedFile.FtpCredentialId == @params.FtpCredentialId);
            }

            var srcFilesData = new ChartDataVm.DataSet {
                Label = "Source files"
            };
            var impFilesData = new ChartDataVm.DataSet {
                Label = "Imported files"
            };
            var delFilesData = new ChartDataVm.DataSet {
                Label = "ZOHO files"
            };
            var sentFilesData = new ChartDataVm.DataSet {
                Label = "Sent ZOHO files"
            };

            var periods = @params.Periods.ToPeriodList().ToList();

            periods.ToList().ForEach(period =>
            {
                var srcFiles = impQuery.Count(f =>
                                              DbFunctions.TruncateTime(f.FileCreateDate) >= DbFunctions.TruncateTime(period.FromDate) &&
                                              DbFunctions.TruncateTime(f.FileCreateDate) <= DbFunctions.TruncateTime(period.ToDate));

                var impFiles = impQuery.Count(f =>
                                              DbFunctions.TruncateTime(f.FileCreateDate) >= DbFunctions.TruncateTime(period.FromDate) &&
                                              DbFunctions.TruncateTime(f.FileCreateDate) <= DbFunctions.TruncateTime(period.ToDate) &&
                                              f.ImportedDate != null);

                var delFiles = delQuery.Count(f =>
                                              DbFunctions.TruncateTime(f.ImportedFile.FileCreateDate) >=
                                              DbFunctions.TruncateTime(period.FromDate) &&
                                              DbFunctions.TruncateTime(f.ImportedFile.FileCreateDate) <= DbFunctions.TruncateTime(period.ToDate));

                var sentFiles = delQuery.Count(f => f.IsSent &&
                                               DbFunctions.TruncateTime(f.ImportedFile.FileCreateDate) >=
                                               DbFunctions.TruncateTime(period.FromDate) &&
                                               DbFunctions.TruncateTime(f.ImportedFile.FileCreateDate) <=
                                               DbFunctions.TruncateTime(period.ToDate));

                srcFilesData.Data.Add(srcFiles);
                impFilesData.Data.Add(impFiles);
                delFilesData.Data.Add(delFiles);
                sentFilesData.Data.Add(sentFiles);
            });

            result.Data   = new[] { srcFilesData, impFilesData, delFilesData, sentFilesData };
            result.Labels = TradeUtils.GetPeriodLabels(periods).ToArray();

            return(result);
        }