From 52294bedb1445ed1c3d199aacffc0d37ad6a97d7 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Fri, 18 Jul 2025 23:30:01 +0100 Subject: [PATCH 1/2] Sort tests by name when creating servo score report Signed-off-by: Nico Burns --- index.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/index.js b/index.js index ad544c1..510a160 100644 --- a/index.js +++ b/index.js @@ -59,9 +59,44 @@ async function process_chunks (path) { delete scored_chunk.run_info result = merge_nonoverlap(result, scored_chunk) } + + sort_test_results(result) + return result } +// Sorts the keys of the test_scores object alphabetically +function sort_test_results (result) { + result.test_scores = sort_object(result.test_scores) +} + +// Sorts the keys of an objects +// +// JS objects serialize keys in insertion order, so to control the order of JSON serialized output +// we can: +// +// - Convert the object into an array +// - Sort the array by test object key +// - Reinsert the results into a new object in order +// +// This sort is not perfect as JS will still serialize keys that can be parsed as integers before +// all other keys, but it's a lot better than nothing. +function sort_object (obj) { + const arr = Object.entries(obj).map(([key, value]) => ({ key, value })) + arr.sort((a, b) => { + if (a.key < b.key) return -1 + if (a.key > b.key) return 1 + return 0 + }) + + const obj2 = {} + for (const entry of arr) { + obj2[entry.key] = entry.value + } + + return obj2 +} + async function add_run (runs_dir, chunks_dir, date) { const new_run = await process_chunks(chunks_dir) await write_compressed(`./${runs_dir}/${date}.xz`, new_run) From a6e667990fa13ab61f3b45bcd65ad2aa046ebdee Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Thu, 14 Aug 2025 11:30:27 +0100 Subject: [PATCH 2/2] Use Map for non-quirky sorting order Signed-off-by: Nico Burns --- index.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 510a160..b3a0c61 100644 --- a/index.js +++ b/index.js @@ -36,6 +36,7 @@ async function all_runs_sorted (runs_dir) { const dir = await opendir(`./${runs_dir}`) const runs = [] for await (const run of dir) { + if (run.name === '.DS_Store') continue runs.push(run.name) } @@ -47,6 +48,8 @@ async function process_chunks (path) { const dir = await opendir(path) let result = {} for await (const chunk of dir) { + if (chunk.name === '.DS_Store') continue + console.log(`Processing chunk ${chunk.name}`) const chunk_run = await read_json_file(`${path}/${chunk.name}`) const scored_chunk = process_raw_results(chunk_run) if (!result.run_info) { @@ -67,21 +70,21 @@ async function process_chunks (path) { // Sorts the keys of the test_scores object alphabetically function sort_test_results (result) { - result.test_scores = sort_object(result.test_scores) + console.log('Sorting results') + result.test_scores = into_sorted_map(result.test_scores) } -// Sorts the keys of an objects +// Convert an object into a sorted Map // -// JS objects serialize keys in insertion order, so to control the order of JSON serialized output +// JS Maps serialize keys in insertion order, so to control the order of JSON serialized output // we can: // // - Convert the object into an array // - Sort the array by test object key -// - Reinsert the results into a new object in order +// - Reinsert the results into a new Map in order // -// This sort is not perfect as JS will still serialize keys that can be parsed as integers before -// all other keys, but it's a lot better than nothing. -function sort_object (obj) { +// Storing the result in a Map rather a regular object allows us to have full control over the order +function into_sorted_map (obj) { const arr = Object.entries(obj).map(([key, value]) => ({ key, value })) arr.sort((a, b) => { if (a.key < b.key) return -1 @@ -89,12 +92,12 @@ function sort_object (obj) { return 0 }) - const obj2 = {} + const map = new Map() for (const entry of arr) { - obj2[entry.key] = entry.value + map[entry.key] = entry.value } - return obj2 + return map } async function add_run (runs_dir, chunks_dir, date) {