public IReadOnlyList <PerDayStatistic> GetPerDayForLastMonthStatistic() { var dateFinish = DateTime.UtcNow; var dateStart = dateFinish.AddDays(-30).Date; var groupedStatistic = CompletedStatistics .Where(x => x.Date >= dateStart.Date) .ToLookup(x => x.Date.Date); var statistic = new List <PerDayStatistic>(); for (var date = dateStart; date < dateFinish; date = date.AddDays(1)) { var dayStatistic = groupedStatistic[date].ToList(); var perDayStatistic = new PerDayStatistic() { Date = new StatisticDate(date.Day, date.Month, date.Year), CompletedTasksCount = dayStatistic.Count(i => i.Type == ItemTypes.Task), CompletedTextCount = dayStatistic.Count(i => i.Type == ItemTypes.Text), CompletedVideoCount = dayStatistic.Count(i => i.Type == ItemTypes.Video), }; statistic.Add(perDayStatistic); } return(statistic); }
public static PerDayStatisticModel GetApplicationModel(PerDayStatistic domainModel) { var applicationModel = new PerDayStatisticModel() { Date = StatisticDateModelFactory.GetApplicationModel(domainModel.Date), CompletedTasksCount = domainModel.CompletedTasksCount, CompletedTextCount = domainModel.CompletedTextCount, CompletedVideoCount = domainModel.CompletedVideoCount, }; return(applicationModel); }
public static IEnumerable <object[]> GetPerDayForLastMonthStatistic_ReturnExpectedResult_Data() { var userId = Guid.NewGuid(); var dates = DateTimeFactory.GetDateSequence(DateTime.Now, 60); var videosPerDay = new Dictionary <DateTime, IReadOnlyList <CompletedEnglishMultimedia> >(); var textsPerDay = new Dictionary <DateTime, IReadOnlyList <CompletedEnglishMultimedia> >(); var tasksPerDay = new Dictionary <DateTime, IReadOnlyList <CompletedEnglishTask> >(); foreach (var date in dates) { videosPerDay[date] = CompletedEnglishMultimediaFactory.GetSimpleModels(_random.Next(1, 5), date: date, multimediaType: MultimediaType.Video); textsPerDay[date] = CompletedEnglishMultimediaFactory.GetSimpleModels(_random.Next(1, 5), date: date, multimediaType: MultimediaType.Text); tasksPerDay[date] = CompletedEnglishTaskFactory.GetSimpleModels(_random.Next(1, 5), date: date); } var allMultimedias = videosPerDay .SelectMany(x => x.Value) .Concat(textsPerDay.SelectMany(x => x.Value)) .ToList(); var allTasks = tasksPerDay.SelectMany(x => x.Value).ToList(); var expectedModels = new List <PerDayStatistic>(); for (var i = 0; i < 31; i++) { var date = dates[i]; var statisticDate = new StatisticDate(date.Day, date.Month, date.Year); var perDayStatistic = new PerDayStatistic() { Date = new StatisticDate(date.Day, date.Month, date.Year), CompletedTasksCount = tasksPerDay[date].Count, CompletedTextCount = textsPerDay[date].Count, CompletedVideoCount = videosPerDay[date].Count, }; expectedModels.Add(perDayStatistic); } yield return(new object[] { allMultimedias, allTasks, expectedModels }); }