Example #1
0
 private static void WriteCommitMetrics(ProjectCommitsMetrics commitMetrics, StringBuilder metricsStringBuilder)
 {
     metricsStringBuilder.AppendLine($"user-count: {commitMetrics.UniqueUsers.Count()}");
     foreach (var user in commitMetrics.UniqueUsers)
     {
         metricsStringBuilder.AppendLine(user);
     }
 }
Example #2
0
        private static ProjectCommitsMetrics CalcMetrics(UserFixMapping[] userFixMappings, string logPath, string projectName, List <UserProjectWork> userProjectWorks)
        {
            var metrics = new ProjectCommitsMetrics()
            {
                ProjectName = projectName
            };

            var uniqueUsers = new HashSet <string>();

            var text  = File.ReadAllText(logPath);
            var lines = text.Split("\r\n");

            var startDate  = default(DateTime?);
            var finishDate = default(DateTime?);

            foreach (var line in lines)
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                var decomposited = line.Split('|');

                var userName = decomposited[1].Trim();

                foreach (var mapping in userFixMappings)
                {
                    if (string.Equals(mapping.InvalidUserName.Trim(), userName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        userName = mapping.TargetUserName;
                        break;
                    }
                }

                uniqueUsers.Add(userName);

                var projectWork = userProjectWorks.SingleOrDefault(x => x.UserName == userName);
                if (projectWork == null)
                {
                    projectWork = new UserProjectWork
                    {
                        UserName = userName,
                        Projects = new HashSet <string> {
                            projectName
                        },
                        CommitCount = 1
                    };

                    userProjectWorks.Add(projectWork);
                }
                else
                {
                    projectWork.Projects.Add(projectName);
                    projectWork.CommitCount++;
                }

                if (startDate == null)
                {
                    startDate = UnixTimeStampToDateTime(long.Parse(decomposited[0]));
                }

                finishDate = UnixTimeStampToDateTime(long.Parse(decomposited[0]));
            }

            metrics.UniqueUsers = uniqueUsers.ToArray();
            metrics.StartDate   = startDate.GetValueOrDefault();
            metrics.FinishDate  = finishDate.GetValueOrDefault();

            return(metrics);
        }