diff --git a/index.js b/index.js index f7bf7d9..8fe33cf 100644 --- a/index.js +++ b/index.js @@ -67,10 +67,10 @@ async function add_run (runs_dir, chunks_dir, date) { await write_compressed(`./${runs_dir}/${date}.xz`, new_run) } -async function recalc_scores (runs_dir) { - console.log(`Calculating scores for ${runs_dir} directory...`) +async function recalc_detailed_scores (runs_dir) { + console.log(`Calculating detailed scores for ${runs_dir} directory...`) - const scores = [] + const result = [] console.log('Enumerating runs') const all_runs = await all_runs_sorted(runs_dir) const run_count = all_runs.length @@ -85,19 +85,34 @@ async function recalc_scores (runs_dir) { const run = await read_compressed(`./${runs_dir}/${r}`) console.log(`Calculating score for run ${runs_dir}/${r} (${i}/${run_count})`) const score = score_run(run, new_run, test_to_areas) - const row = [ + result.push({ date, - run.run_info.revision.substring(0, 9), - run.run_info.browser_version - ] + revision: run.run_info.revision.substring(0, 9), + browser_version: run.run_info.browser_version, + area_scores: area_keys.map(area => score[area]), + }) + } + + return result +} + +function generate_rows (detailed_scores) { + const result = [] - for (const area of area_keys) { - row.push(score[area]) + const { area_keys } = get_focus_areas() + for (const score of detailed_scores) { + const row = [ + score.date, + score.revision, + score.browser_version, + ] + for (const area_score of score.area_scores) { + row.push(area_score.per_mille) } - scores.push(row) + result.push(row) } - return scores + return result } async function main () { @@ -114,10 +129,16 @@ async function main () { await add_run('runs-2020', chunks_2020, date) } - const scores_2013 = await recalc_scores('runs') - const scores_2020 = await recalc_scores('runs-2020') - const scores_by_date = new Map(scores_2020.map(score => [score[0], score])) + const detailed_scores_2013 = await recalc_detailed_scores('runs') + const detailed_scores_2020 = await recalc_detailed_scores('runs-2020') + const detailed_scores = { + layout_2013: detailed_scores_2013, + layout_2020: detailed_scores_2020, + } + const scores_2013 = generate_rows(detailed_scores_2013) + const scores_2020 = generate_rows(detailed_scores_2020) + const scores_by_date = new Map(scores_2020.map(score => [score[0], score])) const scores = [] for (const score_2013 of scores_2013) { const len = scores.push(score_2013) @@ -131,7 +152,12 @@ async function main () { console.log('Writing site/scores.json') write_json_file( - './site/scores.json', { area_keys, focus_areas, scores }) + './site/scores.json', { + area_keys, + focus_areas, + scores, + detailed_scores, + }) console.log('Done') } diff --git a/process-wpt-results.js b/process-wpt-results.js index fb0edc7..1859b33 100644 --- a/process-wpt-results.js +++ b/process-wpt-results.js @@ -184,7 +184,9 @@ export function score_run (run, against_run, focus_areas_map) { for (const area of Object.keys(FOCUS_AREAS)) { scores[area] = { total_tests: 0, - total_score: 0 + score_tests: 0, + total_subtests: 0, + score_subtests: 0, } } @@ -203,29 +205,34 @@ export function score_run (run, against_run, focus_areas_map) { const subtest_names = Object.keys(subtests) if (!subtest_names.length) { for (const area of areas) { - scores[area].total_score += run_test.score + scores[area].score_tests += run_test.score + scores[area].total_subtests += 1 + scores[area].score_subtests += run_test.score } } else { - let test_score = 0 + let score = 0 for (const subtest of subtest_names) { if (Object.hasOwn(run_test.subtests, subtest)) { - test_score += run_test.subtests[subtest].score + score += run_test.subtests[subtest].score } } - test_score /= subtest_names.length for (const area of areas) { - scores[area].total_score += test_score + scores[area].score_tests += score / subtest_names.length + scores[area].total_subtests += subtest_names.length + scores[area].score_subtests += score } } } - return Object.entries(scores).reduce((scores, [area, totals]) => { - scores[area] = 0 + for (const [area, totals] of Object.entries(scores)) { if (totals.total_tests !== 0) { - scores[area] = Math.floor( - 1000 * totals.total_score / totals.total_tests + scores[area].per_mille = Math.floor( + 1000 * totals.score_tests / totals.total_tests ) + } else { + scores[area].per_mille = 0 } - return scores - }, {}) + } + + return scores } diff --git a/site/load-chart.js b/site/load-chart.js index 94c6a57..c8da9b6 100644 --- a/site/load-chart.js +++ b/site/load-chart.js @@ -1,7 +1,9 @@ /* global google */ +/* global all_scores */ google.charts.load('current', { packages: ['corechart', 'line'] }) google.charts.setOnLoadCallback(setupChart) +all_scores = null const fetchData = fetch('scores.json') const embed = location.search === '?embed' @@ -107,7 +109,6 @@ function setupChart () { const period_dropdown = document.getElementById('selected-period') const show_legacy = document.getElementById('show-legacy') const chart = new google.visualization.LineChart(node) - let all_scores Object.keys(periodRanges).forEach(date => { const selector = document.createElement('option') diff --git a/test/process-wpt-results.test.js b/test/process-wpt-results.test.js index d3d699a..3dc2053 100644 --- a/test/process-wpt-results.test.js +++ b/test/process-wpt-results.test.js @@ -166,11 +166,23 @@ describe('Scoring', () => { test2: ['all'] } let score = score_run(run, run, focus_area_map) - assert.deepEqual(score.all, 1000) + assert.deepEqual(score.all, { + per_mille: 1000, + score_subtests: 2, + score_tests: 2, + total_subtests: 2, + total_tests: 2, + }) run.test_scores.test2.score = 0 score = score_run(run, run, focus_area_map) - assert.deepEqual(score.all, 500) + assert.deepEqual(score.all, { + per_mille: 500, + score_subtests: 1, + score_tests: 1, + total_subtests: 2, + total_tests: 2, + }) }) it('calculates scores for subtests', () => { const run = { @@ -187,7 +199,13 @@ describe('Scoring', () => { } const score = score_run(run, run, { test1: ['all'] }) - assert.equal(score.all, 1000) + assert.deepEqual(score.all, { + per_mille: 1000, + score_subtests: 3, + score_tests: 1, + total_subtests: 3, + total_tests: 1, + }) }) it('calculates scores for subtests by averaging', () => { const run = { @@ -204,7 +222,13 @@ describe('Scoring', () => { } const score = score_run(run, run, { test1: ['all'] }) - assert.equal(score.all, 333) + assert.deepEqual(score.all, { + per_mille: 333, + score_subtests: 1, + score_tests: 0.3333333333333333, + total_subtests: 3, + total_tests: 1, + }) }) it('calculates scores correctly even subtest name collides with JS builtins', () => { const run = { @@ -237,7 +261,13 @@ describe('Scoring', () => { } const score = score_run(run, against_run, { test1: ['all'], test2: ['all'] }) - assert.equal(score.all, 500) + assert.deepEqual(score.all, { + per_mille: 500, + score_subtests: 1, + score_tests: 1, + total_subtests: 2, + total_tests: 2, + }) }) it('calculates scores based only on tests in new runs', () => { const old_run = { @@ -258,11 +288,23 @@ describe('Scoring', () => { test1: all, test2: all, test3: all } let score = score_run(old_run, new_run, focus_map) - assert.equal(score.all, 0) + assert.deepEqual(score.all, { + per_mille: 0, + score_subtests: 0, + score_tests: 0, + total_subtests: 1, + total_tests: 2, + }) old_run.test_scores.test3.score = 1 score = score_run(old_run, new_run, focus_map) - assert.equal(score.all, 500) + assert.deepEqual(score.all, { + per_mille: 500, + score_subtests: 1, + score_tests: 1, + total_subtests: 1, + total_tests: 2, + }) }) })