Skip to content

Commit

Permalink
feat: better grouping system
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsenta committed Sep 6, 2023
1 parent 660ff7a commit ddf1952
Showing 1 changed file with 57 additions and 10 deletions.
67 changes: 57 additions & 10 deletions aggregate-into-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,76 @@ 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) {
leading.push(`**${group || 'Other'}**`);
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]})`;
Expand Down Expand Up @@ -90,7 +133,11 @@ inputs.forEach((input, index) => {
const col = [name, versionCell];

// 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);
Expand Down

0 comments on commit ddf1952

Please sign in to comment.