Skip to content
Snippets Groups Projects
Commit a19bee41 authored by Emmanuel Raviart's avatar Emmanuel Raviart
Browse files

Use name ranges for rows

parent 1a8c434c
Branches
Tags
No related merge requests found
Pipeline #7082 failed
......@@ -255,6 +255,7 @@
[personId: string]: number
}
} = {}
const refByName: { [name: string]: string } = {}
const roleByGroupEntityKeyByPersonIdBySituationIndex: {
[situationIndex: number]: {
[personId: string]: { [groupEntityKey: string]: string }
......@@ -340,17 +341,15 @@
let table = tableByEntityKey[entityKey]
if (table === undefined) {
const entity = entityByKey[entityKey]
const header: string[] = ["Cas type", "Description", "Nom"]
const header: string[] = ["uid", "cas_type", "description", "nom"]
if (entity.is_person) {
for (const [groupEntityKey, groupEntity] of Object.entries(
entityByKey,
).sort(([key1], [key2]) => key1.localeCompare(key2))) {
if (!groupEntity.is_person) {
header.push(groupEntityKey, `Rôle dans ${groupEntityKey}`)
header.push(`role_dans_${groupEntityKey}`)
}
}
} else {
header.push("Membres")
}
table = tableByEntityKey[entityKey] = [header]
for (const [situationIndex, situation] of $testCases.entries()) {
......@@ -364,33 +363,32 @@
personIndexByIdBySituationIndex[situationIndex]
const roleByGroupEntityKeyByPersonId =
roleByGroupEntityKeyByPersonIdBySituationIndex[situationIndex]
for (const populationId of Object.keys(entitySituation).sort(
(populationId1, populationId2) =>
for (const [populationIndex, populationId] of Object.keys(
entitySituation,
)
.sort((populationId1, populationId2) =>
populationId1.localeCompare(populationId2),
)) {
)
.entries()) {
const uid = `cas_type_${situationIndex + 1}_${entityKey}_${
populationIndex + 1
}`
const row: unknown[] = [
uid,
situation.title ?? `Cas type n°${situationIndex + 1}`,
situation.description,
populationId,
]
if (entity.is_person) {
const personIndex = personIndexById[populationId]
refByName[uid] = `${entityKey}!$${personIndex + 1}:$${
personIndex + 1
}`
for (const [groupEntityKey, groupEntity] of Object.entries(
entityByKey,
).sort(([key1], [key2]) => key1.localeCompare(key2))) {
if (!groupEntity.is_person) {
const groupInfosById =
groupInfosByIdByEntityKey[groupEntityKey]
const groupInfos = Object.values(groupInfosById).find(
(groupInfos) => groupInfos.personsId.includes(populationId),
)
const groupRange = `$${groupEntityKey}.${
groupInfos.groupIndex + 1
}:${groupInfos.groupIndex + 1}`
row.push(
{
f: groupRange,
v: groupRange,
},
roleByGroupEntityKeyByPersonId[populationId][
groupEntityKey
],
......@@ -398,22 +396,19 @@
}
}
} else {
const groupInfosById = groupInfosByIdByEntityKey[entityKey]
// TODO: Add sheet, etc to each member row reference.
const membersDisjointRange = groupInfosById[
populationId
].personsId
const groupInfos =
groupInfosByIdByEntityKey[entityKey][populationId]
refByName[uid] = `${entityKey}!$${groupInfos.groupIndex + 1}:$${
groupInfos.groupIndex + 1
}`
refByName[`${uid}_membres`] = groupInfos.personsId
.map((personId) => {
const personIndex = personIndexById[personId]
return `$${personEntityKey}.${personIndex + 1}:${
return `${personEntityKey}!$${personIndex + 1}:$${
personIndex + 1
}`
})
.join(":")
row.push({
f: membersDisjointRange,
v: membersDisjointRange,
})
}
table.push(row)
}
......@@ -550,21 +545,30 @@
for (const [columnIndex, cell] of table[0].entries()) {
const variableNameWithPeriod =
typeof cell === "string" ? cell : (cell as { v: string }).v
const vectorRange = XLSX.utils.encode_range({
s: { c: columnIndex, r: 1 },
e: { c: columnIndex, r: table.length - 1 },
})
// Use variable name to name vector in sheet..
// Use variable name to name vector in sheet.
workbook.Workbook.Names.push({
// Comment:
Name: variableNameWithPeriod,
Ref: `${entityKey}!${vectorRange}`,
Ref: `${entityKey}!$${XLSX.utils.encode_col(
columnIndex,
)}$${XLSX.utils.encode_row(1)}:$${XLSX.utils.encode_col(
columnIndex,
)}$${XLSX.utils.encode_row(table.length - 1)}`,
Sheet: null,
})
}
}
// Add rows-related named ranges.
for (const [name, ref] of Object.entries(refByName)) {
workbook.Workbook.Names.push({
// Comment:
Name: name,
Ref: ref,
Sheet: null,
})
}
XLSX.writeFile(
workbook,
`leximpact_${requestedVariableName}_${$year}.xlsx`,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment