From e40a7571fb733003bfb4285dd19731c90de4f7e8 Mon Sep 17 00:00:00 2001 From: Laurent Senta Date: Wed, 16 Aug 2023 17:00:04 +0200 Subject: [PATCH] feat: better grouping system --- aggregate-into-table.js | 68 +++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 10 deletions(-) diff --git a/aggregate-into-table.js b/aggregate-into-table.js index 7c9104fc8..72a31d044 100644 --- a/aggregate-into-table.js +++ b/aggregate-into-table.js @@ -13,33 +13,77 @@ const inputs = files.map((file) => { }); // merge all the unique keys & metadata from all the inputs -let keys = new Set(); const metadata = {} inputs.forEach((input) => { Object.keys(input).forEach((key) => { - keys.add(key); - - // add metadata keys (do not care about different metadatas for now) metadata[key] = { ...metadata[key], ...input[key]["meta"] || {} }; }); }); +delete metadata[TestMetadata]; // Extract TestMetadata which is a special case + +// generate groups: an array of {group, key} objects +// where group is the group name (or undefined), and key is the test key name (or undefined) +// It represents the table leftmost column. +// +// Group1 +// Group1 - Test1 +// Group1 - Test2 +// Group2 +// ... +const groups = [] +const groupsAdded = new Set(); +Object.entries(metadata).forEach(([key, value]) => { + const group = value[METADATA_TEST_GROUP] || undefined; + + if (!groupsAdded.has(group)) { + groups.push({ group, key: undefined }); + groupsAdded.add(group); + } + + groups.push({ group, key }); +}); + +// sort the groups so that the tests are ordered by group, then by key. +// undefined groups are always at the end. +groups.sort((a, b) => { + if (a.group === b.group) { + if (a.key === undefined) { + return -1; + } + if (b.key === undefined) { + return 1; + } + return a.key.localeCompare(b.key); + } + + if (a.group === undefined) { + return 1; + } + + if (b.group === undefined) { + return -1; + } -keys.delete(TestMetadata); // Extract TestMetadata which is a special case -keys = Array.from(keys).sort(); + return a.group.localeCompare(b.group); +}); // generate a table const columns = []; // add the leading column ("gateway", "version", "key1", "key2", ... "keyN") const leading = ["gateway", "version"]; -keys.forEach((key) => { +groups.forEach(({ group, key }) => { + if (key === undefined) { + const group = group || 'Other'; + leading.push(`**${group}**`); + return; + } + const m = metadata[key]; // Skip the "Test" prefix let niceKey = key.replace(/^Test/, ''); - niceKey = m[METADATA_TEST_GROUP] || niceKey; - // Add ipip link if available if (m[METADATA_IPIP]) { niceKey = `[${niceKey}](https://specs.ipfs.tech/ipips/${m[METADATA_IPIP]})`; @@ -79,7 +123,11 @@ inputs.forEach((input, index) => { const col = [name, version]; // extract results - keys.forEach((key) => { + groups.forEach(({ group, key }) => { + if (key === undefined) { + col.push(null); + return; + } col.push(cellRender(input[key] || null)); }); columns.push(col);