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

namespace RepoStats
{
    class OutputWriter
    {
        public static void OutputCheckinDetails(Dictionary<string, GitFileInfo> gitFileInfos, Dictionary<string, GitCommitterInfo> gitComitterInfos)
        {
            string fileInfoChangesTableString = tableTemplate;
            
            StringBuilder trFileInfosContent = new StringBuilder();
            foreach (GitFileInfo fileInfo in gitFileInfos.Values.OrderByDescending(c => (c.LinesDeleted + c.LinesAdded)))
            {
                trFileInfosContent.AppendFormat(
                    trTemplate, 
                    fileInfo.LinesAdded, 
                    fileInfo.LinesDeleted, 
                    fileInfo.NumberOfCommits,
                    fileInfo.Path);
            }

            fileInfoChangesTableString = String.Format(
                fileInfoChangesTableString
                    .Replace("{0}", "%0%")
                    .Replace("{1}", "%1%")
                    .Replace("{", "{{")
                    .Replace("}", "}}")
                    .Replace("%0%", "{0}")
                    .Replace("%1%", "{1}"), trFileInfosContent);

            File.WriteAllText("report.html",
                String.Concat(
                    htmlPreTemplate,
                    fileInfoChangesTableString,
                    tableFillerTemplate,
                    fileInfoChangesTableString,
                    htmlPostTemplate));
        }

        private static string trTemplate = @" <tr>
              <td valign=top style='width:50pt;border:solid #BDD6EE 1.0pt;
              border-top:none;padding:0in 5.4pt 0in 5.4pt'>
              <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
              normal'>{0}</p>
              </td>
              <td valign=top style='width:50pt;border-top:none;border-left:
              none;border-bottom:solid #BDD6EE 1.0pt;border-right:solid #BDD6EE 1.0pt;
              padding:0in 5.4pt 0in 5.4pt'>
              <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
              normal'>{1}</p>
              </td>
              <td valign=top style='width:100pt;border-top:none;border-left:
              none;border-bottom:solid #BDD6EE 1.0pt;border-right:solid #BDD6EE 1.0pt;
              padding:0in 5.4pt 0in 5.4pt'>
              <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
              normal'>{2}</p>
              </td>
              <td valign=top style='width:500pt;border-top:none;border-left:
              none;border-bottom:solid #BDD6EE 1.0pt;border-right:solid #BDD6EE 1.0pt;
              padding:0in 5.4pt 0in 5.4pt'>
              <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
              normal'>{3}</p>
              </td><commit_msg>add committer details to the table too<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RepoStats
{
    class OutputWriter
    {
        public static void OutputCheckinDetails(Dictionary<string, GitFileInfo> gitFileInfos, Dictionary<string, GitCommitterInfo> gitComitterInfos)
        {
            string fileInfoChangesTableString = tableTemplate;
            StringBuilder trFileInfosContent = new StringBuilder();

            foreach (GitFileInfo fileInfo in gitFileInfos.Values.OrderByDescending(c => (c.LinesDeleted + c.LinesAdded)))
            {
                trFileInfosContent.AppendFormat(
                    trTemplate, 
                    fileInfo.LinesAdded, 
                    fileInfo.LinesDeleted, 
                    fileInfo.NumberOfCommits,
                    fileInfo.Path);
            }

            fileInfoChangesTableString = String.Format(
                fileInfoChangesTableString
                    .Replace("{0}", "%0%")
                    .Replace("{1}", "%1%")
                    .Replace("{", "{{")
                    .Replace("}", "}}")
                    .Replace("%0%", "{0}")
                    .Replace("%1%", "{1}"), trFileInfosContent);


            string committerInfoTableString = tableTemplate;
            StringBuilder trCommitterInfosContent = new StringBuilder();

            foreach (GitCommitterInfo committerInfo in gitComitterInfos.Values.OrderByDescending(c => (c.LinesDeleted + c.LinesAdded)))
            {
                trCommitterInfosContent.AppendFormat(
                    trTemplate,
                    committerInfo.LinesAdded,
                    committerInfo.LinesDeleted,
                    committerInfo.NumberOfCommits,
                    committerInfo.Author);
            }

            committerInfoTableString = String.Format(
                committerInfoTableString
                    .Replace("{0}", "%0%")
                    .Replace("{1}", "%1%")
                    .Replace("{", "{{")
                    .Replace("}", "}}")
                    .Replace("%0%", "{0}")
                    .Replace("%1%", "{1}"), trCommitterInfosContent);
            
            File.WriteAllText("report.html",
                String.Concat(
                    htmlPreTemplate,
                    fileInfoChangesTableString,
                    tableFillerTemplate,
                    committerInfoTableString,
                    htmlPostTemplate));
        }

        private static string trTemplate = @" <tr>
              <td valign=top style='width:50pt;border:solid #BDD6EE 1.0pt;
              border-top:none;padding:0in 5.4pt 0in 5.4pt'>
              <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
              normal'>{0}</p>
              </td>
              <td valign=top style='width:50pt;border-top:none;border-left:
              none;border-bottom:solid #BDD6EE 1.0pt;border-right:solid #BDD6EE 1.0pt;
              padding:0in 5.4pt 0in 5.4pt'>
              <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
              normal'>{1}</p>
              </td>
              <td valign=top style='width:100pt;border-top:none;border-left:
              none;border-bottom:solid #BDD6EE 1.0pt;border-right:solid #BDD6EE 1.0pt;
              padding:0in 5.4pt 0in 5.4pt'>
              <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
              normal'>{2}</p>
              </td>
              <td valign=top style='width:500pt;border-top:none;border-left:
              none;border-bottom:solid #BDD6EE 1.0pt;border-right:solid #BDD6EE 1.0pt;
              padding:0in 5.4pt 0in 5.4pt'>
              <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
              normal'>{3}</p>
              </td>
{'fraction_non_alphanumeric': 0.11695821888101779, 'fraction_numerical': 0.02631198496458002, 'mean_word_length': 1.7474185861795075, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2099855', 'n_tokens_mistral': 2036, 'n_tokens_neox': 1892, 'n_words': 311}