Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose test and subtest counts in scores.json #35

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 41 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 () {
Expand All @@ -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)
Expand All @@ -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')
}
Expand Down
31 changes: 19 additions & 12 deletions process-wpt-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand All @@ -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
}
3 changes: 2 additions & 1 deletion site/load-chart.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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')
Expand Down
56 changes: 49 additions & 7 deletions test/process-wpt-results.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand All @@ -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,
})
})
})

Expand Down