Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }