<commit_before>const path = require('path');
const fs = require('fs');
const os = require('os');
const {spawn, exec} = require('child_process');

const chromepath = require('chrome-location');
spawn(chromepath, ['--remote-debugging-port=9222', '--no-first-run', `--user-data-dir=${path.join(os.tmpdir(), 'temp-profile')}`]);

const PWMetrics = require('pwmetrics');

const staticDir = path.join(__dirname, 'static');

const variants = fs
  .readdirSync(staticDir)
  .filter(filename => path.parse(filename).ext === '' && filename[0] !== '.');

let entries = [];

variants.forEach(variant => {
  const variantDir = path.join(staticDir, variant);

  const apps = fs
    .readdirSync(variantDir)
    .filter(filename => path.parse(filename).ext === '' && filename[0] !== '.');

  const appEntries = apps.map(app => {
    return fs
      .readdirSync(path.join(variantDir, app))
      .filter(filename => path.parse(filename).ext === '.html')
      .map(filename => ({
        app: app,
        variant: variant,
        file: filename
      }));
  });

  let partial = appEntries.reduce((acc, arr) => {
    return acc.concat(arr);
  }, []);
  entries = entries.concat(partial);
});

const urls = entries.map(url);

function test(remaining) {
  if (remaining >= 0) {
    const p = new PWMetrics(urls[remaining], {json: true});
    p.then((results) => {
      console.log(urls[remaining]);
      console.log(results);
      test(remaining - 1);
    });
  } else {
    process.exit(0);
  }
}

setTimeout(_ => test(urls.length - 1), 3000);

function url({app, file, variant}) {
  return path.join('http://localhost:8080', variant, app, file);
}<commit_msg>summary<commit_after>const path = require('path');
const fs = require('fs');
const os = require('os');
const {spawn, exec} = require('child_process');

const chromepath = require('chrome-location');
spawn(chromepath, ['--remote-debugging-port=9222', '--no-first-run', `--user-data-dir=${path.join(os.tmpdir(), 'temp-profile')}`]);

const PWMetrics = require('pwmetrics');

const staticDir = path.join(__dirname, 'static');

const variants = fs
  .readdirSync(staticDir)
  .filter(filename => path.parse(filename).ext === '' && filename[0] !== '.');

let entries = [];

let resultsArr = [];

variants.forEach(variant => {
  const variantDir = path.join(staticDir, variant);

  const apps = fs
    .readdirSync(variantDir)
    .filter(filename => path.parse(filename).ext === '' && filename[0] !== '.');

  const appEntries = apps.map(app => {
    return fs
      .readdirSync(path.join(variantDir, app))
      .filter(filename => path.parse(filename).ext === '.html')
      .map(filename => ({
        app: app,
        variant: variant,
        file: filename
      }));
  });

  let partial = appEntries.reduce((acc, arr) => {
    return acc.concat(arr);
  }, []);
  entries = entries.concat(partial);
});

const urls = entries.map(url);

function test(remaining) {
  if (remaining >= 0) {
    const p = new PWMetrics(urls[remaining], {json: true});
    p.then((results) => {
      console.log(urls[remaining]);
      console.log(results);
      resultsArr.push(JSON.parse(results));
      test(remaining - 1);
    });
  } else {
    summary();
  }
}



function summary() {
  const totals = resultsArr.reduce((acc, result, i) => {
    const reversed = entries.reverse();
    const entry = reversed[i];
    const wut = {
      app: entry.app,
      variant: entry.variant,
      library: path.parse(entry.file).name,
      tti: result.timings[5].value
    };
    acc.push(wut);
    return acc;
  }, []);
  console.log('SUMMARY');
  console.log('===========');
  console.log(JSON.stringify(totals, null, 2));
  process.exit(0);
}

setTimeout(_ => test(urls.length - 1), 3000);

function url({app, file, variant}) {
  return path.join('http://localhost:8080', variant, app, file);
}
{'fraction_non_alphanumeric': 0.195822454308094, 'fraction_numerical': 0.009921671018276762, 'mean_word_length': 3.5390995260663507, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, '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': '5187840', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1255, 'n_words': 251}