Use publication date instead of signature date and be explicit
This commit is contained in:
parent
576537ebe7
commit
6e497cf7fc
1 changed files with 69 additions and 50 deletions
|
@ -39,7 +39,7 @@ interface Context {
|
||||||
articleById: Record<string, JorfArticle | LegiArticle>
|
articleById: Record<string, JorfArticle | LegiArticle>
|
||||||
consolidatedTextCid: string
|
consolidatedTextCid: string
|
||||||
consolidatedTextInternalIds: Set<string>
|
consolidatedTextInternalIds: Set<string>
|
||||||
consolidatedTextModifyingTextsIdsByActionByDate: Record<
|
consolidatedTextModifyingTextsIdsByActionByPublicationDate: Record<
|
||||||
string,
|
string,
|
||||||
Partial<Record<Action, Set<string>>>
|
Partial<Record<Action, Set<string>>>
|
||||||
>
|
>
|
||||||
|
@ -83,7 +83,7 @@ interface TextelrNode extends NodeBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TexteManquant {
|
interface TexteManquant {
|
||||||
date: string
|
publicationDate: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const minDateObject = new Date("1971-01-01")
|
const minDateObject = new Date("1971-01-01")
|
||||||
|
@ -93,6 +93,7 @@ const oneDay = 24 * 60 * 60 // hours * minutes * seconds
|
||||||
async function addArticleToTree(
|
async function addArticleToTree(
|
||||||
context: Context,
|
context: Context,
|
||||||
tree: TextelrNode,
|
tree: TextelrNode,
|
||||||
|
publicationDate: string,
|
||||||
encounteredArticlesIds: Set<string>,
|
encounteredArticlesIds: Set<string>,
|
||||||
lienArticle:
|
lienArticle:
|
||||||
| JorfTextelrLienArt
|
| JorfTextelrLienArt
|
||||||
|
@ -108,6 +109,7 @@ async function addArticleToTree(
|
||||||
await addArticleToTreeNode(
|
await addArticleToTreeNode(
|
||||||
context,
|
context,
|
||||||
tree,
|
tree,
|
||||||
|
publicationDate,
|
||||||
article.CONTEXTE.TEXTE.TM,
|
article.CONTEXTE.TEXTE.TM,
|
||||||
lienArticle,
|
lienArticle,
|
||||||
article,
|
article,
|
||||||
|
@ -117,6 +119,7 @@ async function addArticleToTree(
|
||||||
async function addArticleToTreeNode(
|
async function addArticleToTreeNode(
|
||||||
context: Context,
|
context: Context,
|
||||||
node: SectionTaNode | TextelrNode,
|
node: SectionTaNode | TextelrNode,
|
||||||
|
publicationDate: string,
|
||||||
tm: JorfArticleTm | LegiArticleTm | undefined,
|
tm: JorfArticleTm | LegiArticleTm | undefined,
|
||||||
lienArticle:
|
lienArticle:
|
||||||
| JorfTextelrLienArt
|
| JorfTextelrLienArt
|
||||||
|
@ -136,15 +139,15 @@ async function addArticleToTreeNode(
|
||||||
const sortedTitreTmArray = tm.TITRE_TM.toSorted((titreTm1, titreTm2) =>
|
const sortedTitreTmArray = tm.TITRE_TM.toSorted((titreTm1, titreTm2) =>
|
||||||
titreTm1["@debut"].localeCompare(titreTm2["@debut"]),
|
titreTm1["@debut"].localeCompare(titreTm2["@debut"]),
|
||||||
)
|
)
|
||||||
if (lienArticle["@debut"] < sortedTitreTmArray[0]["@debut"]) {
|
if (publicationDate < sortedTitreTmArray[0]["@debut"]) {
|
||||||
// Assume that the @debut of the first TITRE_TM is wrong.
|
// Assume that the @debut of the first TITRE_TM is wrong.
|
||||||
foundTitreTm = sortedTitreTmArray[0]
|
foundTitreTm = sortedTitreTmArray[0]
|
||||||
} else if (lienArticle["@debut"] >= sortedTitreTmArray.at(-1)!["@fin"]) {
|
} else if (publicationDate >= sortedTitreTmArray.at(-1)!["@fin"]) {
|
||||||
// Assume that the @fin of the last TITRE_TM is wrong.
|
// Assume that the @fin of the last TITRE_TM is wrong.
|
||||||
foundTitreTm = sortedTitreTmArray.at(-1)!
|
foundTitreTm = sortedTitreTmArray.at(-1)!
|
||||||
} else {
|
} else {
|
||||||
foundTitreTm = sortedTitreTmArray.find(
|
foundTitreTm = sortedTitreTmArray.find(
|
||||||
(titreTm) => lienArticle["@debut"] < titreTm["@fin"],
|
(titreTm) => publicationDate < titreTm["@fin"],
|
||||||
)!
|
)!
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -154,11 +157,25 @@ async function addArticleToTreeNode(
|
||||||
const children = (node.children ??= [])
|
const children = (node.children ??= [])
|
||||||
const lastChild = children.at(-1)
|
const lastChild = children.at(-1)
|
||||||
if (foundTitreTm["@id"] === lastChild?.titreTm["@id"]) {
|
if (foundTitreTm["@id"] === lastChild?.titreTm["@id"]) {
|
||||||
addArticleToTreeNode(context, lastChild, tm.TM, lienArticle, article)
|
addArticleToTreeNode(
|
||||||
|
context,
|
||||||
|
lastChild,
|
||||||
|
publicationDate,
|
||||||
|
tm.TM,
|
||||||
|
lienArticle,
|
||||||
|
article,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
const newChild: SectionTaNode = { titreTm: foundTitreTm }
|
const newChild: SectionTaNode = { titreTm: foundTitreTm }
|
||||||
children.push(newChild)
|
children.push(newChild)
|
||||||
addArticleToTreeNode(context, newChild, tm.TM, lienArticle, article)
|
addArticleToTreeNode(
|
||||||
|
context,
|
||||||
|
newChild,
|
||||||
|
publicationDate,
|
||||||
|
tm.TM,
|
||||||
|
lienArticle,
|
||||||
|
article,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,30 +189,30 @@ async function addModifyingArticleId(
|
||||||
modifiedDateFin: string,
|
modifiedDateFin: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const modifyingArticle = await getOrLoadArticle(context, modifyingArticleId)
|
const modifyingArticle = await getOrLoadArticle(context, modifyingArticleId)
|
||||||
const modifyingArticleDateSignature =
|
const modifyingArticlePublicationDate =
|
||||||
modifyingArticle.CONTEXTE.TEXTE["@date_signature"]
|
modifyingArticle.CONTEXTE.TEXTE["@date_publi"]
|
||||||
if (modifyingArticleDateSignature === undefined) {
|
if (modifyingArticlePublicationDate === undefined) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Article modificateur ${modifyingArticleId} of ${modifiedId} has no CONTEXTE.TEXTE["@date_signature"]`,
|
`Article modificateur ${modifyingArticleId} of ${modifiedId} has no CONTEXTE.TEXTE["@date_publi"]`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
action === "CREATE" &&
|
action === "CREATE" &&
|
||||||
modifyingArticleDateSignature !== "2999-01-01" &&
|
modifyingArticlePublicationDate !== "2999-01-01" &&
|
||||||
modifyingArticleDateSignature > modifiedDateDebut
|
modifyingArticlePublicationDate > modifiedDateDebut
|
||||||
) {
|
) {
|
||||||
console.warn(
|
console.warn(
|
||||||
`Ignoring article créateur ${modifyingArticleId} because its date signature ${modifyingArticleDateSignature} doesn't match date début ${modifiedDateDebut} of ${modifiedId}`,
|
`Ignoring article créateur ${modifyingArticleId} because its publication date ${modifyingArticlePublicationDate} doesn't match start date ${modifiedDateDebut} of ${modifiedId}`,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
action === "DELETE" &&
|
action === "DELETE" &&
|
||||||
modifyingArticleDateSignature !== "2999-01-01" &&
|
modifyingArticlePublicationDate !== "2999-01-01" &&
|
||||||
modifyingArticleDateSignature > modifiedDateFin
|
modifyingArticlePublicationDate > modifiedDateFin
|
||||||
) {
|
) {
|
||||||
console.warn(
|
console.warn(
|
||||||
`Ignoring article suppresseur ${modifyingArticleId} because its date signature ${modifyingArticleDateSignature} doesn't match date fin ${modifiedDateFin} of ${modifiedId}`,
|
`Ignoring article suppresseur ${modifyingArticleId} because its publication date ${modifyingArticlePublicationDate} doesn't match end date ${modifiedDateFin} of ${modifiedId}`,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -215,8 +232,8 @@ async function addModifyingArticleId(
|
||||||
existingModifyingArticleId,
|
existingModifyingArticleId,
|
||||||
)
|
)
|
||||||
if (
|
if (
|
||||||
existingModifyingArticle.CONTEXTE.TEXTE["@date_signature"]! <
|
existingModifyingArticle.CONTEXTE.TEXTE["@date_publi"]! <
|
||||||
modifyingArticleDateSignature
|
modifyingArticlePublicationDate
|
||||||
) {
|
) {
|
||||||
modifyingArticleIdByAction[action] = modifyingArticleId
|
modifyingArticleIdByAction[action] = modifyingArticleId
|
||||||
}
|
}
|
||||||
|
@ -251,41 +268,43 @@ async function addModifyingTextId(
|
||||||
if (modifyingTexteVersion === null) {
|
if (modifyingTexteVersion === null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const modifyingTextDateSignature =
|
const modifyingTextPublicationDate =
|
||||||
modifyingTexteVersion.META.META_SPEC.META_TEXTE_CHRONICLE.DATE_TEXTE
|
modifyingTexteVersion.META.META_SPEC.META_TEXTE_CHRONICLE.DATE_PUBLI
|
||||||
if (modifyingTextDateSignature === undefined) {
|
if (modifyingTextPublicationDate === undefined) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Texte modificateur ${modifyingTextId} of ${modifiedId} has no META.META_SPEC.META_TEXTE_CHRONICLE.DATE_TEXTE`,
|
`Texte modificateur ${modifyingTextId} of ${modifiedId} has no META.META_SPEC.META_TEXTE_CHRONICLE.DATE_PUBLI`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modifiedId.startsWith("JORFTEXT") || modifiedId.startsWith("LEGITEXT")) {
|
if (modifiedId.startsWith("JORFTEXT") || modifiedId.startsWith("LEGITEXT")) {
|
||||||
// A consolidated text doesn't change. Only its content changes.
|
// A consolidated text doesn't change. Only its content changes.
|
||||||
const date =
|
const publicationDate =
|
||||||
modifyingTexteVersion.META.META_SPEC.META_TEXTE_CHRONICLE.DATE_PUBLI
|
modifyingTexteVersion.META.META_SPEC.META_TEXTE_CHRONICLE.DATE_PUBLI
|
||||||
const consolidatedTextModifyingTextsIdsByAction =
|
const consolidatedTextModifyingTextsIdsByAction =
|
||||||
(context.consolidatedTextModifyingTextsIdsByActionByDate[date] ??= {})
|
(context.consolidatedTextModifyingTextsIdsByActionByPublicationDate[
|
||||||
|
publicationDate
|
||||||
|
] ??= {})
|
||||||
const consolidatedTextModifyingTextsIds =
|
const consolidatedTextModifyingTextsIds =
|
||||||
(consolidatedTextModifyingTextsIdsByAction[action] ??= new Set())
|
(consolidatedTextModifyingTextsIdsByAction[action] ??= new Set())
|
||||||
consolidatedTextModifyingTextsIds.add(modifyingTextId)
|
consolidatedTextModifyingTextsIds.add(modifyingTextId)
|
||||||
} else {
|
} else {
|
||||||
if (
|
if (
|
||||||
action === "CREATE" &&
|
action === "CREATE" &&
|
||||||
modifyingTextDateSignature !== "2999-01-01" &&
|
modifyingTextPublicationDate !== "2999-01-01" &&
|
||||||
modifyingTextDateSignature > modifiedDateDebut
|
modifyingTextPublicationDate > modifiedDateDebut
|
||||||
) {
|
) {
|
||||||
console.warn(
|
console.warn(
|
||||||
`Ignoring creating text ${modifyingTextId} because its date signature ${modifyingTextDateSignature} doesn't match date début ${modifiedDateDebut} of ${modifiedId}`,
|
`Ignoring creating text ${modifyingTextId} because its publication date ${modifyingTextPublicationDate} doesn't match start date ${modifiedDateDebut} of ${modifiedId}`,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
action === "DELETE" &&
|
action === "DELETE" &&
|
||||||
modifyingTextDateSignature !== "2999-01-01" &&
|
modifyingTextPublicationDate !== "2999-01-01" &&
|
||||||
modifyingTextDateSignature > modifiedDateFin
|
modifyingTextPublicationDate > modifiedDateFin
|
||||||
) {
|
) {
|
||||||
console.warn(
|
console.warn(
|
||||||
`Ignoring texte suppresseur ${modifyingTextId} because its date signature ${modifyingTextDateSignature} doesn't match date fin ${modifiedDateFin} of ${modifiedId}`,
|
`Ignoring texte suppresseur ${modifyingTextId} because its publication date ${modifyingTextPublicationDate} doesn't match end date ${modifiedDateFin} of ${modifiedId}`,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -309,7 +328,7 @@ async function addModifyingTextId(
|
||||||
))!
|
))!
|
||||||
if (
|
if (
|
||||||
existingModifyingTexteVersion.META.META_SPEC.META_TEXTE_CHRONICLE
|
existingModifyingTexteVersion.META.META_SPEC.META_TEXTE_CHRONICLE
|
||||||
.DATE_TEXTE! < modifyingTextDateSignature
|
.DATE_PUBLI! < modifyingTextPublicationDate
|
||||||
) {
|
) {
|
||||||
modifyingTextIdByAction[action] = modifyingTextId
|
modifyingTextIdByAction[action] = modifyingTextId
|
||||||
;((context.idsByActionByTexteMoficateurId[modifyingTextId] ??= {})[
|
;((context.idsByActionByTexteMoficateurId[modifyingTextId] ??= {})[
|
||||||
|
@ -340,7 +359,7 @@ async function exportConsolidatedTextToGit(
|
||||||
articleById: {},
|
articleById: {},
|
||||||
consolidatedTextCid: consolidatedTextId, // Temporary value, overrided below
|
consolidatedTextCid: consolidatedTextId, // Temporary value, overrided below
|
||||||
consolidatedTextInternalIds: new Set([consolidatedTextId]),
|
consolidatedTextInternalIds: new Set([consolidatedTextId]),
|
||||||
consolidatedTextModifyingTextsIdsByActionByDate: {},
|
consolidatedTextModifyingTextsIdsByActionByPublicationDate: {},
|
||||||
currentInternalIds: new Set(),
|
currentInternalIds: new Set(),
|
||||||
idsByActionByTexteMoficateurId: {},
|
idsByActionByTexteMoficateurId: {},
|
||||||
jorfCreatorIdById: {},
|
jorfCreatorIdById: {},
|
||||||
|
@ -520,29 +539,28 @@ async function exportConsolidatedTextToGit(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const modifyingTextsIdByDate: Record<string, string[]> = {}
|
const modifyingTextsIdByPublicationDate: Record<string, string[]> = {}
|
||||||
for (const modifyingTextId of modifyingTextsIds) {
|
for (const modifyingTextId of modifyingTextsIds) {
|
||||||
let date: string
|
|
||||||
let modifyingTexteVersion:
|
let modifyingTexteVersion:
|
||||||
| JorfTexteVersion
|
| JorfTexteVersion
|
||||||
| LegiTexteVersion
|
| LegiTexteVersion
|
||||||
| TexteManquant = context.texteManquantById[
|
| TexteManquant = context.texteManquantById[
|
||||||
modifyingTextId
|
modifyingTextId
|
||||||
] as TexteManquant
|
] as TexteManquant
|
||||||
|
let publicationDate: string
|
||||||
if (modifyingTexteVersion === undefined) {
|
if (modifyingTexteVersion === undefined) {
|
||||||
modifyingTexteVersion = (await getOrLoadTexteVersion(
|
modifyingTexteVersion = (await getOrLoadTexteVersion(
|
||||||
context,
|
context,
|
||||||
modifyingTextId,
|
modifyingTextId,
|
||||||
)) as JorfTexteVersion | LegiTexteVersion
|
)) as JorfTexteVersion | LegiTexteVersion
|
||||||
date =
|
publicationDate =
|
||||||
modifyingTexteVersion.META.META_SPEC.META_TEXTE_CHRONICLE.DATE_TEXTE
|
modifyingTexteVersion.META.META_SPEC.META_TEXTE_CHRONICLE.DATE_PUBLI
|
||||||
} else {
|
} else {
|
||||||
date = modifyingTexteVersion.date
|
publicationDate = modifyingTexteVersion.publicationDate
|
||||||
}
|
|
||||||
let modifyingTextsId = modifyingTextsIdByDate[date]
|
|
||||||
if (modifyingTextsId === undefined) {
|
|
||||||
modifyingTextsId = modifyingTextsIdByDate[date] = []
|
|
||||||
}
|
}
|
||||||
|
const modifyingTextsId = (modifyingTextsIdByPublicationDate[
|
||||||
|
publicationDate
|
||||||
|
] ??= [])
|
||||||
modifyingTextsId.push(modifyingTextId)
|
modifyingTextsId.push(modifyingTextId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,10 +677,10 @@ async function exportConsolidatedTextToGit(
|
||||||
message: "Création du dépôt Git",
|
message: "Création du dépôt Git",
|
||||||
})
|
})
|
||||||
|
|
||||||
for (const [date, modifyingTextsId] of Object.entries(
|
for (const [publicationDate, modifyingTextsId] of Object.entries(
|
||||||
modifyingTextsIdByDate,
|
modifyingTextsIdByPublicationDate,
|
||||||
).toSorted(([date1], [date2]) => date1.localeCompare(date2))) {
|
).toSorted(([date1], [date2]) => date1.localeCompare(date2))) {
|
||||||
console.log(date)
|
console.log(publicationDate)
|
||||||
for (const modifyingTextId of modifyingTextsId.toSorted()) {
|
for (const modifyingTextId of modifyingTextsId.toSorted()) {
|
||||||
// Generate tree of SectionTa & articles at this date
|
// Generate tree of SectionTa & articles at this date
|
||||||
const t0 = performance.now()
|
const t0 = performance.now()
|
||||||
|
@ -688,7 +706,7 @@ async function exportConsolidatedTextToGit(
|
||||||
.trim()
|
.trim()
|
||||||
.replace(/\s+\(\d+\)$/, "")
|
.replace(/\s+\(\d+\)$/, "")
|
||||||
} else {
|
} else {
|
||||||
modifyingTextTitle = `!!! Texte non trouvé ${date} !!!`
|
modifyingTextTitle = `!!! Texte non trouvé ${publicationDate} !!!`
|
||||||
}
|
}
|
||||||
console.log(` ${modifyingTextId} ${modifyingTextTitle}`)
|
console.log(` ${modifyingTextId} ${modifyingTextTitle}`)
|
||||||
const idsByAction =
|
const idsByAction =
|
||||||
|
@ -733,6 +751,7 @@ async function exportConsolidatedTextToGit(
|
||||||
await addArticleToTree(
|
await addArticleToTree(
|
||||||
context,
|
context,
|
||||||
tree,
|
tree,
|
||||||
|
publicationDate,
|
||||||
encounteredArticlesIds,
|
encounteredArticlesIds,
|
||||||
lienArticle,
|
lienArticle,
|
||||||
)
|
)
|
||||||
|
@ -770,6 +789,7 @@ async function exportConsolidatedTextToGit(
|
||||||
await addArticleToTree(
|
await addArticleToTree(
|
||||||
context,
|
context,
|
||||||
tree,
|
tree,
|
||||||
|
publicationDate,
|
||||||
encounteredArticlesIds,
|
encounteredArticlesIds,
|
||||||
lienArticle,
|
lienArticle,
|
||||||
)
|
)
|
||||||
|
@ -869,8 +889,7 @@ async function exportConsolidatedTextToGit(
|
||||||
.map(([key, value]) => `${key}: ${value}`)
|
.map(([key, value]) => `${key}: ${value}`)
|
||||||
.join("\n")
|
.join("\n")
|
||||||
}
|
}
|
||||||
const dateObject = new Date(date)
|
let timestamp = Math.floor(new Date(publicationDate).getTime() / 1000)
|
||||||
let timestamp = Math.floor(dateObject.getTime() / 1000)
|
|
||||||
if (timestamp < minDateTimestamp) {
|
if (timestamp < minDateTimestamp) {
|
||||||
const diffDays = Math.round(
|
const diffDays = Math.round(
|
||||||
Math.abs((minDateTimestamp - timestamp) / oneDay),
|
Math.abs((minDateTimestamp - timestamp) / oneDay),
|
||||||
|
@ -1654,7 +1673,7 @@ async function registerLegiArticleModifiers(
|
||||||
] ??= {})
|
] ??= {})
|
||||||
if (modifyingTextIdByAction.CREATE === undefined) {
|
if (modifyingTextIdByAction.CREATE === undefined) {
|
||||||
const consolidatedTextModifyingTextsIds =
|
const consolidatedTextModifyingTextsIds =
|
||||||
context.consolidatedTextModifyingTextsIdsByActionByDate[
|
context.consolidatedTextModifyingTextsIdsByActionByPublicationDate[
|
||||||
articleDateDebut
|
articleDateDebut
|
||||||
]?.CREATE
|
]?.CREATE
|
||||||
if (consolidatedTextModifyingTextsIds !== undefined) {
|
if (consolidatedTextModifyingTextsIds !== undefined) {
|
||||||
|
@ -1703,7 +1722,7 @@ async function registerLegiArticleModifiers(
|
||||||
if (modifyingTextIdByAction.CREATE === undefined) {
|
if (modifyingTextIdByAction.CREATE === undefined) {
|
||||||
const texteManquantId = `ZZZZ TEXTE MANQUANT ${articleDateDebut}`
|
const texteManquantId = `ZZZZ TEXTE MANQUANT ${articleDateDebut}`
|
||||||
context.texteManquantById[texteManquantId] ??= {
|
context.texteManquantById[texteManquantId] ??= {
|
||||||
date: articleDateDebut,
|
publicationDate: articleDateDebut,
|
||||||
}
|
}
|
||||||
modifyingTextIdByAction.CREATE = texteManquantId
|
modifyingTextIdByAction.CREATE = texteManquantId
|
||||||
;((context.idsByActionByTexteMoficateurId[texteManquantId] ??=
|
;((context.idsByActionByTexteMoficateurId[texteManquantId] ??=
|
||||||
|
|
Loading…
Add table
Reference in a new issue