<commit_before>'use strict';

const fs = require('fs'),
  helpers = require('../../support/helpers'),
  Promise = require('bluebird'),
  path = require('path'),
  merge = require('lodash.merge'),
  get = require('lodash.get'),
  log = require('intel'),
  packageInfo = require('../../../package'),
  renderer = require('./renderer'),
  isEmpty = require('lodash.isempty');

Promise.promisifyAll(fs);

const TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';

class HTMLBuilder {
  constructor(context, options) {
    this.storageManager = context.storageManager;
    this.timestamp = context.timestamp.format(TIME_FORMAT);
    this.options = options;
    this.dataCollection = context.dataCollection;
    this.summary = {};
    this.budget = context.budget;
    this.context = context;
  }

  render() {
    const options = this.options;
    const dataCollection = this.dataCollection;

    log.info('Render HTML for %s page(s) ', Object.keys(dataCollection.urlPages).length);
    const errors = dataCollection.getErrorPages();

    if (Object.keys(errors).length > 0) {
      this.summary.errors = {
        errors,
        menu: 'errors'
      };
    }

    const validPages = dataCollection.getValidPages();
    this.summary.pages = {
      pageTitle: 'Overview of all tested pages',
      pageDescription: 'See all the tested pages on a high level.',
      pages: validPages
    };

    this.summary.index = {
      pageTitle: 'Summary of the sitespeed.io result',
      pageDescription: 'Executive summary of the sitespeed.io result. Act on red/yellow/green.',
      boxes: dataCollection.getSummaryBoxes()
    };

    this.summary.detailed = {
      pageTitle: 'In details summary of the sitespeed.io result.',
      pageDescription: 'Get all the details you need to fast track things you need to change.',
      metrics: dataCollection.getDetailedBoxes()
    };

    this.summary.domains = {
      pageTitle: 'The most used domains',
      pageDescription: 'A list of the most used domains and the respective timings'
    };

    this.summary.assets = {
      pageTitle: 'Most used assets',
      pageDescription: 'A list of the most used assets for the analyzed pages.'
    };

    this.summary.toplist = {
      pageTitle: 'Largest assets by type ',
      pageDescription: 'A list of the largest assets for the analyzed pages.'
    };

    if (options.budget) {
      let totalFailing = 0;
      let totalWorking = 0;
      for (const url of Object.keys(this.budget.failing )) {
        totalFailing = totalFailing + this.budget.failing[url].length;
      }
      for (const url of Object.keys(this.budget.working )) {
        totalWorking = totalWorking + this.budget.working[url].length;
      }
      this.summary.budget = {
        pageTitle: 'Performance budget ',
        pageDescription: 'The list of failing and working performance budgets.',
        budget: this.budget,
        totalFailing,
        totalWorking
      };
    }<commit_msg>more informative page titles<commit_after>'use strict';

const fs = require('fs'),
  helpers = require('../../support/helpers'),
  Promise = require('bluebird'),
  path = require('path'),
  merge = require('lodash.merge'),
  get = require('lodash.get'),
  log = require('intel'),
  packageInfo = require('../../../package'),
  renderer = require('./renderer'),
  isEmpty = require('lodash.isempty');

Promise.promisifyAll(fs);

const TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';

class HTMLBuilder {
  constructor(context, options) {
    this.storageManager = context.storageManager;
    this.timestamp = context.timestamp.format(TIME_FORMAT);
    this.options = options;
    this.dataCollection = context.dataCollection;
    this.summary = {};
    this.budget = context.budget;
    this.context = context;
  }

  render() {
    const options = this.options;
    const dataCollection = this.dataCollection;
    const name = this.context.name;
    const timestamp = this.timestamp;
    const nTestedPages = Object.keys(dataCollection.urlPages).length;
    log.info('Render HTML for %s page(s) ', nTestedPages);
    const errors = dataCollection.getErrorPages();

    if (Object.keys(errors).length > 0) {
      this.summary.errors = {
        errors,
        menu: 'errors'
      };
    }

    const validPages = dataCollection.getValidPages();
    this.summary.pages = {
      pageTitle: `Overview of ${helpers.plural(nTestedPages,'page')} for ${name} at ${timestamp}`,
      pageDescription: 'See all the tested pages on a high level.',
      pages: validPages
    };

    this.summary.index = {
      pageTitle: `Executive Summary for ${name} tested ${helpers.plural(nTestedPages,'page')} at ${timestamp}`,
      pageDescription: 'Executive summary of the sitespeed.io result. Act on red/yellow/green.',
      boxes: dataCollection.getSummaryBoxes()
    };

    this.summary.detailed = {
      pageTitle: `In details summary for ${name} tested ${helpers.plural(nTestedPages,'page')} at ${timestamp}`,
      pageDescription: 'Get all the details you need to fast track things you need to change.',
      metrics: dataCollection.getDetailedBoxes()
    };

    this.summary.domains = {
      pageTitle: `The most used domains for ${name} tested at ${timestamp}`,
      pageDescription: 'A list of the most used domains and the respective timings'
    };

    this.summary.assets = {
      pageTitle: `Most used assets for ${name} tested at ${timestamp}`,
      pageDescription: 'A list of the most used assets for the analyzed pages.'
    };

    this.summary.toplist = {
      pageTitle: `Largest assets by type for ${name} tested at ${timestamp}`,
      pageDescription: 'A list of the largest assets for the analyzed pages.'
    };

    if (options.budget) {
      let totalFailing = 0;
      let totalWorking = 0;
      for (const url of Object.keys(this.budget.failing )) {
        totalFailing = totalFailing + this.budget.failing[url].length;
      }
      for (const url of Object.keys(this.budget.working )) {
        totalWorking = totalWorking + this.budget.working[url].length;
      }
      this.summary.budget = {
        pageTitle: 'Performance budget ',
        pageDescription: 'The list of failing and working performance budgets.',
        budget: this.budget,
        totalFailing,
        totalWorking
      };
    }
{'fraction_non_alphanumeric': 0.12324617346938775, 'fraction_numerical': 0.0009566326530612245, 'mean_word_length': 2.9879211697393515, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6864381', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1778, 'n_words': 490}