File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -59,9 +59,41 @@ async function process_chunks (path) {
59
59
delete scored_chunk . run_info
60
60
result = merge_nonoverlap ( result , scored_chunk )
61
61
}
62
+
63
+ sort_test_results ( result )
64
+
62
65
return result
63
66
}
64
67
68
+ // Sorts the keys of the test_scores object alphabetically
69
+ function sort_test_results ( result ) {
70
+ result . test_scores = sort_object ( result . test_scores )
71
+ }
72
+
73
+ // Sorts the keys of an objects
74
+ //
75
+ // JS objects serialize keys in insertion order, so to control the order of JSON serialized output
76
+ // we can:
77
+ //
78
+ // - Convert the object into an array
79
+ // - Sort the array by test object key
80
+ // - Reinsert the results into a new object in order
81
+ function sort_object ( obj ) {
82
+ const arr = Object . entries ( obj ) . map ( ( [ key , value ] ) => ( { key, value } ) )
83
+ arr . sort ( ( a , b ) => {
84
+ if ( a . key < b . key ) return - 1
85
+ if ( a . key > b . key ) return 1
86
+ return 0
87
+ } )
88
+
89
+ const obj2 = { }
90
+ for ( const entry of arr ) {
91
+ obj2 [ entry . key ] = entry . value
92
+ }
93
+
94
+ return obj2
95
+ }
96
+
65
97
async function add_run ( runs_dir , chunks_dir , date ) {
66
98
const new_run = await process_chunks ( chunks_dir )
67
99
await write_compressed ( `./${ runs_dir } /${ date } .xz` , new_run )
You can’t perform that action at this time.
0 commit comments