Public
Edited
Oct 17, 2024
Paused
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function restructure(standard) {
// Group standard by section
let nestedData = d3.group(standard, data => data.section);

let result = {
performance_standard: "PS1", // Assuming "PS1" for now, can be dynamic
sections: []
};

nestedData.forEach((sectionData, sectionName) => {
// Create the section object with heading as its "ref"
let section = {
section: sectionName,
ref: {
id: sectionData[0].id,
page: sectionData[0].page,
document_element: sectionData[0].document_element
},
paragraph_group: {
provisions: [] // This will hold the paragraph provisions
},
clauses: [] // This will hold clauses at the section level
};

// Handle paragraph provisions for this section
sectionData.forEach(item => {
if (item.provision_paragraph) {
// Push paragraph provision into the paragraph group
section.paragraph_group.provisions.push({
provision_paragraph: item.provision_paragraph,
ref: {
id: item.id,
page: item.page,
paragraph: item.paragraph,
document_element: item.document_element
}
});
}
// Handle clause entries separately
if (item.provision_clausal) {
section.clauses.push({
provision_clausal: item.provision_clausal,
ref: {
id: item.id,
page: item.page,
paragraph: item.paragraph,
clause_number: item.clause_number || "",
document_element: item.document_element
}
});
}
});

// If there are no paragraph provisions, remove the empty paragraph_group
if (section.paragraph_group.provisions.length === 0) {
delete section.paragraph_group;
}

// Add the section to the result
result.sections.push(section);
});

return result;
}
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more