<commit_before>﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Web;
using Chutzpah.Models;
using Chutzpah.Wrappers;

namespace Chutzpah.Coverage
{
    public static class CoverageOutputGenerator
    {
        public static string WriteHtmlFile(string directory, CoverageData coverage)
        {
            var path = Path.Combine(directory, Constants.CoverageHtmlFileName);

            using (var fileStream = new FileStream(path, FileMode.Create))
            {
                GenerateHtml(coverage, fileStream);
            }

            return path;
        }


        public static string WriteJsonFile(string directory, CoverageData coverage)
        {
            var path = Path.Combine(directory, Constants.CoverageJsonFileName);

            var serializer = new JsonSerializer();
            File.WriteAllText(path, serializer.Serialize(coverage));
             
            return path;
        }


        public static void GenerateHtml(CoverageData coverage, Stream stream)
        {
            var successPercentage = coverage.SuccessPercentage.HasValue ? coverage.SuccessPercentage.Value : Constants.DefaultCodeCoverageSuccessPercentage;
           
            using (var writer = new StreamWriter(stream))
            {
                writer.WriteLine(HtmlFragments.BodyContentStartFormat, HtmlFragments.Js, HtmlFragments.Css);

                var totalLines = 0;
                var totalLinesCovered = 0;

                var fileNumber = 0;
                foreach (var pair in coverage)
                {
                    fileNumber++;
                    var fileName = pair.Key;
                    var fileData = pair.Value;
                    var totalSmts = 0;
                    var linesCovered = 0;
                    var markup = new string[fileData.SourceLines.Length + 1];

                    for (var i = 0; i < fileData.SourceLines.Length; i++)
                    {
                        markup[i + 1] = "<div class='{{executed}}'><span class=''>" + (i + 1) + "</span>" + HttpUtility.HtmlEncode(fileData.SourceLines[i]) +
                                        "</div>";
                    }

                    for (var i = 1; i < fileData.LineExecutionCounts.Length; i++)<commit_msg>Fix code coverage html formatting<commit_after>﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Web;
using Chutzpah.Models;
using Chutzpah.Wrappers;

namespace Chutzpah.Coverage
{
    public static class CoverageOutputGenerator
    {
        public static string WriteHtmlFile(string directory, CoverageData coverage)
        {
            var path = Path.Combine(directory, Constants.CoverageHtmlFileName);

            using (var fileStream = new FileStream(path, FileMode.Create))
            {
                GenerateHtml(coverage, fileStream);
            }

            return path;
        }


        public static string WriteJsonFile(string directory, CoverageData coverage)
        {
            var path = Path.Combine(directory, Constants.CoverageJsonFileName);

            var serializer = new JsonSerializer();
            File.WriteAllText(path, serializer.Serialize(coverage));
             
            return path;
        }


        public static void GenerateHtml(CoverageData coverage, Stream stream)
        {
            var successPercentage = coverage.SuccessPercentage.HasValue ? coverage.SuccessPercentage.Value : Constants.DefaultCodeCoverageSuccessPercentage;
           
            using (var writer = new StreamWriter(stream))
            {
                writer.WriteLine(HtmlFragments.BodyContentStartFormat, HtmlFragments.Js, HtmlFragments.Css);

                var totalLines = 0;
                var totalLinesCovered = 0;

                var fileNumber = 0;
                foreach (var pair in coverage)
                {
                    fileNumber++;
                    var fileName = pair.Key;
                    var fileData = pair.Value;
                    var totalSmts = 0;
                    var linesCovered = 0;
                    var markup = new string[fileData.SourceLines.Length + 1];

                    var maxLineNumberLength = fileData.SourceLines.Length.ToString(CultureInfo.InvariantCulture).Length;
                    for (var i = 0; i < fileData.SourceLines.Length; i++)
                    {
                        var lineNumber = (i+1).ToString(CultureInfo.InvariantCulture).PadLeft(maxLineNumberLength);
                        lineNumber = lineNumber.Replace(" ", "&nbsp;&nbsp;");
                        var line = HttpUtility.HtmlEncode(fileData.SourceLines[i]).Replace(" ", "&nbsp;");
                        markup[i + 1] = "<div class='{{executed}}'><span class=''>" + lineNumber + "</span>" + line +
                                        "</div>";
                    }

                    for (var i = 1; i < fileData.LineExecutionCounts.Length; i++)
{'fraction_non_alphanumeric': 0.0869047619047619, 'fraction_numerical': 0.003968253968253968, 'mean_word_length': 1.778941565600882, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6603522', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1212, 'n_words': 291}