Example #1
0
        public IList <GroupedStatistic> Group(IList <Commit> commits, DateTime from, DateTime to)
        {
            var      weekStart = weekDatesService.WeekStartDate(from);
            var      result    = new List <GroupedStatistic>();
            DateTime weekEnd;

            do
            {
                weekEnd = weekStart.AddDays(7);
                var suitableCommits = commits
                                      .Where(x => x.Date.Date >= weekStart.Date && x.Date.Date < weekEnd.Date)
                                      .ToList();

                if (suitableCommits.Any())
                {
                    var statistic        = new StatisticCalculationHelper(suitableCommits).Calculte();
                    var groupedStatistic = new GroupedStatistic(statistic, weekStart, weekEnd);
                    result.Add(groupedStatistic);
                }

                weekStart = weekEnd;
            } while (weekEnd.Date < to.Date);

            return(result);
        }
Example #2
0
        public string Merge(Command.Infrastructure.Models.Command command)
        {
            var authors   = command.Args.Split(' ');
            var statistic = storage.Get();

            if (CheckAuthors(authors, statistic) != null)
            {
                return(CheckAuthors(authors, statistic));
            }

            var mergeModel = ParseMergeModel(authors, statistic);

            if (mergeModel.ErrorMessage != null)
            {
                return(mergeModel.ErrorMessage);
            }

            var commits = statistic.Commits
                          .Select(commit =>
                                  mergeModel.Duplicates.Contains(commit.Author.Id)
                        ? new Commit(commit.Name, mergeModel.MainAuthor, commit.Insertions, commit.Deletions, commit.Date)
                        : commit).ToList();

            var newStatistic = new StatisticCalculationHelper(commits).Calculte();

            storage.Save(newStatistic);

            return(ReportBuilder.BuildReport(newStatistic));
        }
Example #3
0
        public IList <GroupedStatistic> GroupBy(GroupingArgs args)
        {
            if (groupingService.GroupBy == args.Method)
            {
                return(groupingService.Group(args.Commits, args.From, args.To));
            }

            var statistic = new StatisticCalculationHelper(args.Commits).Calculte();

            return(new List <GroupedStatistic> {
                new GroupedStatistic(statistic, args.From, args.To)
            });
        }