<commit_before>(function(module, cwd)
{

    'use strict';

    var fs = require('fs');
    var os = require('os');
    var filesize = require('file-size');

    var m = function(url, results)
    {

        var html_report = fs.readFileSync(cwd + '/templates/report.html', {encoding: 'utf8'});
        var html_item = fs.readFileSync(cwd + '/templates/item.html', {encoding: 'utf8'});
        var html_rule = fs.readFileSync(cwd + '/templates/rule.html', {encoding: 'utf8'});

        this.build = function(callback)
        {
            for (var index in results)
            {
                html_report = html_report.replace('<!--results-->', _buildItem(results[index]) + '<!--results-->');
            }
            html_report = html_report.replace(new RegExp('{{url}}', 'g'), url);
            callback(html_report);
        };

        var _buildItem = function(result)
        {
            var html = html_item;
            for (var strategy in result)
            {
                var placeholders = {};

                placeholders.url = result[strategy].id;
                placeholders.encoded_url = encodeURIComponent(result[strategy].id);
                placeholders.title = result[strategy].title;
                placeholders.strategy = strategy;

                if (typeof result[strategy].ruleGroups.SPEED !== 'undefined')
                {
                    placeholders.speed_score = _fixScore(result[strategy].ruleGroups.SPEED.score, result[strategy].formattedResults.ruleResults, 'SPEED');
                    placeholders.speed_class = result[strategy].ruleGroups.SPEED.score >= 50 ? (result[strategy].ruleGroups.SPEED.score >= 90 ? 'green' : 'orange') : 'red';
                }
                else
                {
                    placeholders.speed_score = '?';
                    placeholders.speed_class = '';
                }

                if (typeof result[strategy].ruleGroups.USABILITY !== 'undefined')
                {
                    placeholders.usability_score = _fixScore(result[strategy].ruleGroups.USABILITY.score, result[strategy].formattedResults.ruleResults, 'USABILITY');
                    placeholders.usability_class = result[strategy].ruleGroups.USABILITY.score >= 50 ? (result[strategy].ruleGroups.USABILITY.score >= 90 ? 'green' : 'orange') : 'red';
                }
                else
                {
                    placeholders.usability_score = '?';
                    placeholders.usability_class = '';
                }

                placeholders.html_size = filesize(parseInt(result[strategy].pageStats.htmlResponseBytes)).human();
                placeholders.css_size = filesize(parseInt(result[strategy].pageStats.cssResponseBytes)).human();
                placeholders.js_size = filesize(parseInt(result[strategy].pageStats.javascriptResponseBytes)).human();
                placeholders.img_size = filesize(parseInt(result[strategy].pageStats.imageResponseBytes)).human();
                placeholders.request_size = filesize(parseInt(result[strategy].pageStats.totalRequestBytes)).human();

                placeholders.total_resources = result[strategy].pageStats.numberResources;
                placeholders.css_resources = result[strategy].pageStats.numberCssResources;
                placeholders.js_resources = result[strategy].pageStats.numberJsResources;

                for (var placeholder in placeholders)
                {
                    html = html.replace(new RegExp('{{' + strategy + '.' + placeholder + '}}', 'g'), placeholders[placeholder]);
                }

                var has_rules = false;
                for (var index in result[strategy].formattedResults.ruleResults)
                {
                    var rule = result[strategy].formattedResults.ruleResults[index];
                    if (typeof rule.ruleImpact !== 'undefined' && rule.ruleImpact > 0)
                    {
                        html = html.replace('<!--' + strategy + '.rules-->', _buildRule(rule) + '<!--' + strategy + '.rules-->');
                        has_rules = true;
                    }
                }
                if (!has_rules)
                {
                    html_report.replace('<!--' + strategy + '.rules-->', html_rule.replace('{{title}}', 'Nothing do to'), html_rule.replace('{{text}}', 'All rules are correct.'));
                }
            }
            return html;
        };

        var _fixScore = function(score, rules, group)
        {<commit_msg>Refactors report.js<commit_after>(function(module, cwd)
{

    'use strict';

    var fs = require('fs');
    var os = require('os');
    var filesize = require('file-size');

    var m = function(url, results)
    {

        var html_report = fs.readFileSync(cwd + '/templates/report.html', {encoding: 'utf8'});
        var html_item = fs.readFileSync(cwd + '/templates/item.html', {encoding: 'utf8'});
        var html_rule = fs.readFileSync(cwd + '/templates/rule.html', {encoding: 'utf8'});

        this.build = function(callback)
        {
            for (var index in results)
            {
                html_report = html_report.replace('<!--results-->', _buildItem(results[index]) + '<!--results-->');
            }
            html_report = html_report.replace(new RegExp('{{url}}', 'g'), url);
            callback(html_report);
        };

        var _buildItem = function(result)
        {
            var html = html_item;
            for (var strategy in result)
            {
                var placeholders = {};
                var rule_groups = result[strategy].ruleGroups;
                var rule_results = result[strategy].formattedResults.ruleResults;
                var page_stats = result[strategy].pageStats;

                placeholders.url = result[strategy].id;
                placeholders.encoded_url = encodeURIComponent(result[strategy].id);
                placeholders.title = result[strategy].title;
                placeholders.strategy = strategy;

                if (typeof rule_groups.SPEED !== 'undefined')
                {
                    placeholders.speed_score = _fixScore(rule_groups.SPEED.score, rule_results, 'SPEED');
                    placeholders.speed_class = rule_groups.SPEED.score >= 50 ? (rule_groups.SPEED.score >= 90 ? 'green' : 'orange') : 'red';
                }
                else
                {
                    placeholders.speed_score = '?';
                    placeholders.speed_class = '';
                }

                if (typeof rule_groups.USABILITY !== 'undefined')
                {
                    placeholders.usability_score = _fixScore(rule_groups.USABILITY.score, rule_results, 'USABILITY');
                    placeholders.usability_class = rule_groups.USABILITY.score >= 50 ? (rule_groups.USABILITY.score >= 90 ? 'green' : 'orange') : 'red';
                }
                else
                {
                    placeholders.usability_score = '?';
                    placeholders.usability_class = '';
                }

                placeholders.html_size = filesize(parseInt(page_stats.htmlResponseBytes)).human();
                placeholders.css_size = filesize(parseInt(page_stats.cssResponseBytes)).human();
                placeholders.js_size = filesize(parseInt(page_stats.javascriptResponseBytes)).human();
                placeholders.img_size = filesize(parseInt(page_stats.imageResponseBytes)).human();
                placeholders.request_size = filesize(parseInt(page_stats.totalRequestBytes)).human();

                placeholders.total_resources = page_stats.numberResources;
                placeholders.css_resources = page_stats.numberCssResources;
                placeholders.js_resources = page_stats.numberJsResources;

                for (var placeholder in placeholders)
                {
                    html = html.replace(new RegExp('{{' + strategy + '.' + placeholder + '}}', 'g'), placeholders[placeholder]);
                }

                var has_rules = false;
                for (var index in rule_results)
                {
                    var rule = rule_results[index];
                    if (typeof rule.ruleImpact !== 'undefined' && rule.ruleImpact > 0)
                    {
                        html = html.replace('<!--' + strategy + '.rules-->', _buildRule(rule) + '<!--' + strategy + '.rules-->');
                        has_rules = true;
                    }
                }
                if (!has_rules)
                {
                    html_report.replace('<!--' + strategy + '.rules-->', html_rule.replace('{{title}}', 'Nothing do to'), html_rule.replace('{{text}}', 'All rules are correct.'));
                }
            }
            return html;
        };

        var _fixScore = function(score, rules, group)
        {
{'fraction_non_alphanumeric': 0.12641466727025805, 'fraction_numerical': 0.002716161158895428, 'mean_word_length': 1.7885768381192806, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, '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': '292938', 'n_tokens_mistral': 2364, 'n_tokens_neox': 2219, 'n_words': 382}