Ejemplo n.º 1
0
        private DashboardResponse.Chart GetAllTimeChartData(List <UserWord> userWords, DateTime endDate)
        {
            DashboardResponse.Chart chart  = new DashboardResponse.Chart();
            List <string>           labels = new List <string>();

            DashboardResponse.Dataset createdWords = new DashboardResponse.Dataset();
            DashboardResponse.Dataset learnedWords = new DashboardResponse.Dataset();
            DateTime today = DateTime.Today;

            var dateCount = (today.Date - endDate.Date).TotalDays;

            createdWords.Data = new int[6];
            learnedWords.Data = new int[6];

            for (int i = 0; i < 6; i++)
            {
                int addedDays = (int)dateCount / 6;

                if (i == 6)
                {
                    addedDays += (int)dateCount % 6;
                }

                DateTime currentDate = endDate.AddDays(addedDays * i);
                DateTime nextDate    = currentDate.AddDays(addedDays);

                createdWords.Data[i] = userWords.Where(w => w.CreatedDate.Date >= currentDate.Date && w.CreatedDate.Date < nextDate.Date).Count();
                learnedWords.Data[i] = userWords.Where(w => w.LearnedDate != null && w.LearnedDate.Value.Date >= currentDate.Date && w.LearnedDate < nextDate.Date).Count();

                labels.Add(currentDate.ToString("Y"));
            }

            return(chart);
        }
Ejemplo n.º 2
0
        private DashboardResponse.Chart GetLastWeekOrMonthChartData(List <UserWord> userWords, DateTime endDate)
        {
            DashboardResponse.Chart chart  = new DashboardResponse.Chart();
            List <string>           labels = new List <string>();

            DashboardResponse.Dataset createdWords = new DashboardResponse.Dataset();
            DashboardResponse.Dataset learnedWords = new DashboardResponse.Dataset();
            DateTime date      = DateTime.Today;
            int      dateEject = (int)(date - endDate).TotalDays;

            createdWords.Data = new int[dateEject];
            learnedWords.Data = new int[dateEject];

            for (int i = 0; i < dateEject; i++)
            {
                createdWords.Data[i] = userWords.Where(w => w.CreatedDate.Date == date.Date).Count();
                learnedWords.Data[i] = userWords.Where(w => w.LearnedDate != null && w.LearnedDate.Value.Date == date.Date).Count();
                labels.Add(date.ToString("m"));

                date = date.AddDays(1);
            }
            chart.Datasets.Add(createdWords);
            chart.Datasets.Add(learnedWords);


            return(chart);
        }
Ejemplo n.º 3
0
        private DashboardResponse.Chart GetLastSixMonthsCharData(List <UserWord> userWords, DateTime endDate)
        {
            DashboardResponse.Chart chart  = new DashboardResponse.Chart();
            List <string>           labels = new List <string>();

            DashboardResponse.Dataset createdWords = new DashboardResponse.Dataset();
            DashboardResponse.Dataset learnedWords = new DashboardResponse.Dataset();
            int sixMonth = 6;

            createdWords.Data = new int[sixMonth];
            learnedWords.Data = new int[sixMonth];

            for (int i = 0; i < sixMonth; i++)
            {
                DateTime currentMonth = endDate.AddMonths(i);
                DateTime nextMonth    = currentMonth.AddMonths(1);

                createdWords.Data[i] = userWords.Where(w => w.CreatedDate.Date >= currentMonth.Date && w.CreatedDate.Date < nextMonth.Date).Count();
                learnedWords.Data[i] = userWords.Where(w => w.LearnedDate != null && w.LearnedDate.Value.Date >= currentMonth.Date && w.LearnedDate < nextMonth.Date).Count();

                labels.Add(currentMonth.ToString("MMMM"));
            }

            chart.Datasets.Add(createdWords);
            chart.Datasets.Add(learnedWords);

            return(chart);
        }
Ejemplo n.º 4
0
        public DashboardResponse.Chart GetChartCard(int userId, DateRange dateRange = DateRange.LastDay)
        {
            var endDate = dateRange.GetDate();

            var wholeUserWords = _dbContext.UserWords
                                 .Where(w => w.UserId == userId && w.CreatedDate >= endDate)
                                 .ToList();

            DashboardResponse.Chart chartResponse = new DashboardResponse.Chart();
            chartResponse.Labels.Add("Added Words");
            chartResponse.Labels.Add("Learned Words");

            switch (dateRange)
            {
            case DateRange.LastDay:
                break;

            case DateRange.LastWeek:
                chartResponse = GetLastWeekOrMonthChartData(wholeUserWords, endDate);
                break;

            case DateRange.LastMonth:
                chartResponse = GetLastWeekOrMonthChartData(wholeUserWords, endDate);
                break;

            case DateRange.LastSixMonth:
                chartResponse = GetLastSixMonthsCharData(wholeUserWords, endDate);
                break;

            case DateRange.AllTime:
                chartResponse = GetAllTimeChartData(wholeUserWords, endDate);
                break;

            default:
                break;
            }

            return(chartResponse);
        }