Skip to content

Commit 4d7d22e

Browse files
mregodelan
andcommitted
Add information about number of tests and subtests
This modifies the scores.json file so it now provides more data: * total_tests: The total number of tests * total_score: The total scores for the tests * per_mille: Per mille value of dividing total_score by total_tests * total_subtests: The total number of subtests * total_subtests_passed: The number of subtests that pass * per_mille_subtests: Per mille value of dividing total_subtests by total_subtests_passed This is based on previous work by Delan Azabani at #35. Co-authored-by: Delan Azabani <[email protected]> Signed-off-by: Manuel Rego Casasnovas <[email protected]>
1 parent a85f53e commit 4d7d22e

File tree

3 files changed

+232
-22
lines changed

3 files changed

+232
-22
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,17 @@ async function main () {
113113
}
114114

115115
const scores = await recalc_scores('runs-2020')
116+
const scores_last_run = scores[scores.length - 1]
116117

117118
const { area_keys, area_names: focus_areas } = get_focus_areas()
118119

119120
console.log('Writing site/scores.json')
120121
await mkdir('./site', { recursive: true })
121122
write_json_file(
122123
'./site/scores.json', { area_keys, focus_areas, scores })
124+
console.log('Writing site/scores-last-run.json')
125+
write_json_file(
126+
'./site/scores-last-run.json', { area_keys, focus_areas, scores_last_run })
123127

124128
console.log('Done')
125129
}

process-wpt-results.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -199,48 +199,44 @@ export function score_run (run, against_run, focus_areas_map) {
199199
for (const area of Object.keys(FOCUS_AREAS)) {
200200
scores[area] = {
201201
total_tests: 0,
202-
total_score: 0
202+
total_score: 0,
203+
total_subtests: 0,
204+
total_subtests_passed: 0
203205
}
204206
}
205207

206208
for (const [test, { subtests }] of Object.entries(against_run.test_scores)) {
207209
const areas = focus_areas_map[test]
210+
const subtest_names = Object.keys(subtests)
208211

209212
for (const area of areas) {
210213
scores[area].total_tests += 1
214+
scores[area].total_subtests += !subtest_names.length ? 1 : subtest_names.length
211215
}
212216

213217
const run_test = run.test_scores[test]
214218

215219
// score new tests not present in older runs
216220
if (!run_test) continue
217221

218-
const subtest_names = Object.keys(subtests)
219222
if (!subtest_names.length) {
220223
for (const area of areas) {
221224
scores[area].total_score += run_test.score
225+
scores[area].total_subtests_passed += run_test.score
222226
}
223227
} else {
224-
let test_score = 0
228+
let subtests_passed = 0
225229
for (const subtest of subtest_names) {
226230
if (Object.hasOwn(run_test.subtests, subtest)) {
227-
test_score += run_test.subtests[subtest].score
231+
subtests_passed += run_test.subtests[subtest].score
228232
}
229233
}
230-
test_score /= subtest_names.length
231234
for (const area of areas) {
232-
scores[area].total_score += test_score
235+
scores[area].total_score += subtests_passed / subtest_names.length
236+
scores[area].total_subtests_passed += subtests_passed
233237
}
234238
}
235239
}
236240

237-
return Object.entries(scores).reduce((scores, [area, totals]) => {
238-
scores[area] = 0
239-
if (totals.total_tests !== 0) {
240-
scores[area] = Math.floor(
241-
1000 * totals.total_score / totals.total_tests
242-
)
243-
}
244-
return scores
245-
}, {})
241+
return scores
246242
}

test/process-wpt-results.test.js

Lines changed: 217 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ describe('Process wpt result', () => {
146146
})
147147
})
148148

149+
function checkScore (actual, expected) {
150+
actual.per_mille = Math.floor(1000 * actual.total_score / actual.total_tests)
151+
actual.per_mille_subtests = Math.floor(1000 * actual.total_subtests_passed / actual.total_subtests)
152+
assert.deepEqual(actual, expected)
153+
}
154+
149155
describe('Scoring', () => {
150156
it('calculates scores for individual tests', () => {
151157
const run = {
@@ -166,11 +172,109 @@ describe('Scoring', () => {
166172
test2: ['all']
167173
}
168174
let score = score_run(run, run, focus_area_map)
169-
assert.deepEqual(score.all, 1000)
175+
checkScore(score.all,
176+
{
177+
total_tests: 2,
178+
total_score: 2,
179+
per_mille: 1000,
180+
total_subtests: 2,
181+
total_subtests_passed: 2,
182+
per_mille_subtests: 1000
183+
})
170184

171185
run.test_scores.test2.score = 0
172186
score = score_run(run, run, focus_area_map)
173-
assert.deepEqual(score.all, 500)
187+
checkScore(score.all,
188+
{
189+
total_tests: 2,
190+
total_score: 1,
191+
per_mille: 500,
192+
total_subtests: 2,
193+
total_subtests_passed: 1,
194+
per_mille_subtests: 500
195+
})
196+
})
197+
it('calculates subtests count', () => {
198+
const run = {
199+
test_scores: {
200+
test1: {
201+
score: 1,
202+
subtests: {
203+
subtest1: { score: 1 },
204+
subtest2: { score: 1 },
205+
subtest3: { score: 1 }
206+
}
207+
},
208+
test2: {
209+
score: 0,
210+
subtests: {
211+
subtest1: { score: 1 },
212+
subtest2: { score: 0 }
213+
}
214+
}
215+
}
216+
}
217+
218+
const focus_area_map = {
219+
test1: ['all'],
220+
test2: ['all']
221+
}
222+
const score = score_run(run, run, focus_area_map)
223+
checkScore(score.all,
224+
{
225+
total_tests: 2,
226+
total_score: 1.5,
227+
per_mille: 750,
228+
total_subtests: 5,
229+
total_subtests_passed: 4,
230+
per_mille_subtests: 800
231+
})
232+
})
233+
it('calculates subtests counts with simple tests', () => {
234+
const run = {
235+
test_scores: {
236+
test1: {
237+
score: 1,
238+
subtests: {
239+
subtest1: { score: 1 },
240+
subtest2: { score: 1 },
241+
subtest3: { score: 1 }
242+
}
243+
},
244+
test2: {
245+
score: 0,
246+
subtests: {
247+
subtest1: { score: 1 },
248+
subtest2: { score: 0 }
249+
}
250+
},
251+
test3: {
252+
score: 1,
253+
subtests: {}
254+
},
255+
test4: {
256+
score: 0,
257+
subtests: {}
258+
}
259+
}
260+
}
261+
262+
const focus_area_map = {
263+
test1: ['all'],
264+
test2: ['all'],
265+
test3: ['all'],
266+
test4: ['all']
267+
}
268+
const score = score_run(run, run, focus_area_map)
269+
checkScore(score.all,
270+
{
271+
total_tests: 4,
272+
total_score: 2.5,
273+
per_mille: 625,
274+
total_subtests: 7,
275+
total_subtests_passed: 5,
276+
per_mille_subtests: 714
277+
})
174278
})
175279
it('calculates scores for subtests', () => {
176280
const run = {
@@ -187,7 +291,15 @@ describe('Scoring', () => {
187291
}
188292

189293
const score = score_run(run, run, { test1: ['all'] })
190-
assert.equal(score.all, 1000)
294+
checkScore(score.all,
295+
{
296+
total_tests: 1,
297+
total_score: 1,
298+
per_mille: 1000,
299+
total_subtests: 3,
300+
total_subtests_passed: 3,
301+
per_mille_subtests: 1000
302+
})
191303
})
192304
it('calculates scores for subtests by averaging', () => {
193305
const run = {
@@ -204,7 +316,15 @@ describe('Scoring', () => {
204316
}
205317

206318
const score = score_run(run, run, { test1: ['all'] })
207-
assert.equal(score.all, 333)
319+
checkScore(score.all,
320+
{
321+
total_tests: 1,
322+
total_score: 1 / 3,
323+
per_mille: 333,
324+
total_subtests: 3,
325+
total_subtests_passed: 1,
326+
per_mille_subtests: 333
327+
})
208328
})
209329
it('calculates scores correctly even subtest name collides with JS builtins', () => {
210330
const run = {
@@ -237,7 +357,15 @@ describe('Scoring', () => {
237357
}
238358

239359
const score = score_run(run, against_run, { test1: ['all'], test2: ['all'] })
240-
assert.equal(score.all, 500)
360+
checkScore(score.all,
361+
{
362+
total_tests: 2,
363+
total_score: 1,
364+
per_mille: 500,
365+
total_subtests: 2,
366+
total_subtests_passed: 1,
367+
per_mille_subtests: 500
368+
})
241369
})
242370
it('calculates scores based only on tests in new runs', () => {
243371
const old_run = {
@@ -258,11 +386,93 @@ describe('Scoring', () => {
258386
test1: all, test2: all, test3: all
259387
}
260388
let score = score_run(old_run, new_run, focus_map)
261-
assert.equal(score.all, 0)
389+
checkScore(score.all,
390+
{
391+
total_tests: 2,
392+
total_score: 0,
393+
per_mille: 0,
394+
total_subtests: 2,
395+
total_subtests_passed: 0,
396+
per_mille_subtests: 0
397+
})
398+
old_run.test_scores.test3.score = 1
399+
score = score_run(old_run, new_run, focus_map)
400+
checkScore(score.all,
401+
{
402+
total_tests: 2,
403+
total_score: 1,
404+
per_mille: 500,
405+
total_subtests: 2,
406+
total_subtests_passed: 1,
407+
per_mille_subtests: 500
408+
})
409+
})
410+
it('calculates scores based only on subtests in new runs', () => {
411+
const old_run = {
412+
test_scores: {
413+
test1: {
414+
score: 0,
415+
subtests: {
416+
subtest1: { score: 1 },
417+
subtest2: { score: 0 }
418+
}
419+
},
420+
test3: {
421+
score: 0,
422+
subtests: {
423+
subtest1: { score: 0 },
424+
subtest2: { score: 1 }
425+
}
426+
}
427+
}
428+
}
429+
const new_run = {
430+
test_scores: {
431+
test2: {
432+
score: 1,
433+
subtests: {
434+
subtest1: { score: 1 },
435+
subtest2: { score: 1 },
436+
subtest3: { score: 1 },
437+
subtest4: { score: 1 }
438+
}
439+
},
440+
test3: {
441+
score: 1,
442+
subtests: {
443+
subtest1: { score: 1 },
444+
subtest2: { score: 1 }
445+
}
446+
}
447+
}
448+
}
262449

450+
const all = ['all']
451+
const focus_map = {
452+
test1: all, test2: all, test3: all
453+
}
454+
let score = score_run(old_run, new_run, focus_map)
455+
checkScore(score.all,
456+
{
457+
total_tests: 2,
458+
total_score: 0.5,
459+
per_mille: 250,
460+
total_subtests: 6,
461+
total_subtests_passed: 1,
462+
per_mille_subtests: 166
463+
})
263464
old_run.test_scores.test3.score = 1
465+
old_run.test_scores.test3.subtests.subtest1.score = 1
264466
score = score_run(old_run, new_run, focus_map)
265-
assert.equal(score.all, 500)
467+
checkScore(score.all,
468+
{
469+
total_tests: 2,
470+
total_score: 1,
471+
per_mille: 500,
472+
total_subtests: 6,
473+
total_subtests_passed: 2,
474+
per_mille_subtests: 333
475+
})
266476
})
267477
})
268478

0 commit comments

Comments
 (0)