<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using ExpertiseExplorer.Algorithms.RepositoryManagement;

namespace GitHistoryAnalyzer
{
    class Program
    {
        public enum Operation { FindNewcomers, CountContributors };
        
        static void Main(string[] args)
        {
            Operation currentOperation;

            if (args.Length != 3 && args.Length != 4 ||
                !Enum.TryParse<Operation>(args[0], true, out currentOperation) ||
                !File.Exists(args[1]))
            {
                PrintUsage();
            }
            else
            {
                string gitLogFile = args[1];
                string outputCsvFile = args[2];

                string[] gitLog = File.ReadAllLines(gitLogFile);

                AliasFinder af = new AliasFinder();
                if (args.Length == 4)
                {
                    string authorList = args[3];

                    if (!File.Exists(authorList))
                    {       // author list does not exist yet, will be created
                        IEnumerable<IEnumerable<string>> authorAliasList =
                            af.Consolidate(
                                gitLog
                                    .Where(line => line.StartsWith("Author: "))
                                    .Select(line => line.Substring("Author: ".Length))
                                    .ToArray()
                            );
                        File.WriteAllLines(outputCsvFile,
                                authorAliasList
                                    .Select(aliases => string.Join(";", aliases))
                                    .OrderBy(s => s)
                            );
                    }
                    af.InitializeMappingFromAuthorList(File.ReadAllLines(authorList));
                }

                switch (currentOperation)
                {
                    case Operation.FindNewcomers:
                        FindNewcomers(outputCsvFile, gitLog, af);
                        break;
                    case Operation.CountContributors:
                        CountContributors(outputCsvFile, gitLog, af);
                        break;
                    default:
                        throw new NotImplementedException("Operation " + currentOperation + " is not yet implemented.");
                }
            }
        }

        private static void CountContributors(string outputCsvFile, string[] gitLog, AliasFinder af)
        {
            File.WriteAllText(<commit_msg>Bugfix: Authorlist written to wrong file<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using ExpertiseExplorer.Algorithms.RepositoryManagement;

namespace GitHistoryAnalyzer
{
    class Program
    {
        public enum Operation { FindNewcomers, CountContributors };
        
        static void Main(string[] args)
        {
            Operation currentOperation;

            if (args.Length != 3 && args.Length != 4 ||
                !Enum.TryParse<Operation>(args[0], true, out currentOperation) ||
                !File.Exists(args[1]))
            {
                PrintUsage();
            }
            else
            {
                string gitLogFile = args[1];
                string outputCsvFile = args[2];

                string[] gitLog = File.ReadAllLines(gitLogFile);

                AliasFinder af = new AliasFinder();
                if (args.Length == 4)
                {
                    string authorList = args[3];

                    if (!File.Exists(authorList))
                    {       // author list does not exist yet, will be created
                        IEnumerable<IEnumerable<string>> authorAliasList =
                            af.Consolidate(
                                gitLog
                                    .Where(line => line.StartsWith("Author: "))
                                    .Select(line => line.Substring("Author: ".Length))
                                    .ToArray()
                            );
                        File.WriteAllLines(authorList,
                                authorAliasList
                                    .Select(aliases => string.Join(";", aliases))
                                    .OrderBy(s => s)
                            );
                    }
                    af.InitializeMappingFromAuthorList(File.ReadAllLines(authorList));
                }

                switch (currentOperation)
                {
                    case Operation.FindNewcomers:
                        FindNewcomers(outputCsvFile, gitLog, af);
                        break;
                    case Operation.CountContributors:
                        CountContributors(outputCsvFile, gitLog, af);
                        break;
                    default:
                        throw new NotImplementedException("Operation " + currentOperation + " is not yet implemented.");
                }
            }
        }

        private static void CountContributors(string outputCsvFile, string[] gitLog, AliasFinder af)
        {
            File.WriteAllText(
{'fraction_non_alphanumeric': 0.08083270817704426, 'fraction_numerical': 0.003000750187546887, 'mean_word_length': 1.1538772213247173, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4568073', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1153, 'n_words': 248}