cadrumo.domain.calculations.registry.revision_order module¶
Modelo revision ordering, period-selector overlap, and temporal coexistence.
Orders a ModeloDefinition’s revisions into validity sequence and
offers the two distinct “are these two revisions the same period” questions
that cross-revision policy keys on: revisions_overlap(), which reads
period selectors alone, and revisions_coexist(), which additionally
requires the revisions’ validity windows to intersect.
- revisions_overlap(left, right)[source]¶
Whether two revisions’ declared period selectors address a common period.
This is a selector-only question: it asks whether the two revisions name at least one shared filing year and period code, and says NOTHING about when either revision is in force. Two consecutive editions of a modelo that serve the same period vocabulary – successive census editions both serving
alta/modificacion/baja, or successive ad-hoc editions both servingAD-HOC– overlap under this predicate even when their validity windows merely meet end-to-start and can never be live at the same time. Callers asking “could both of these be in force at once” wantrevisions_coexist()instead.ModeloRevision.period_selectoris a REQUIRED field (neverNone), and every caller passes real, fully-constructedModeloRevisioninstances; no production code builds aModeloRevisionviamodel_construct. Reading.period_selectordirectly (nevergetattr(..., default=None)guarded by anisinstancefallback toTrue) means a rename of the field fails loud instead of silently making every revision pair register as “overlapping” – which is NOT a safe default here, because consumers that only run their own check when a pair does NOT overlap would be silently disabled, with nothing downstream to catch the loss.- Return type:
- Parameters:
left (ModeloRevision)
right (ModeloRevision)
- revision_windows_intersect(left, right)[source]¶
Whether two revisions’ inclusive validity windows share at least one day.
This is the project’s single answer to “are these two revisions ever in force on the same day”, and it says NOTHING about period selectors; pair it with
revisions_overlap()– or userevisions_coexist(), which is exactly that conjunction – when the question is simultaneity for one and the same period.Inclusivity:
valid_fromandvalid_toare both inclusive bounds, so a revision is in force ON itsvalid_todate. Two windows that merely MEET end-to-start – one ending 2025-02-02 and the next starting 2025-02-03 – therefore do NOT intersect, while two that share a single day (valid_to == valid_from) DO.Open ends:
valid_toofNonedenotes an open-ended window with no end date. An open-ended revision intersects every window that starts on or after itsvalid_from, and every window that has not itself closed before thatvalid_from.valid_fromis required and neverNone, so there is no open START to consider.The predicate is symmetric:
f(a, b)equalsf(b, a)for every pair, and argument order carries no “earlier”/”later” meaning. It assumes each revision’s own window is well formed (valid_tonot beforevalid_from); a schema-invalid inverted window is not defended against here, because the schema is the owner of that invariant.Core types:
ModeloRevision.- Return type:
- Parameters:
left (ModeloRevision)
right (ModeloRevision)
- revisions_coexist(left, right)[source]¶
Whether two revisions could both be in force for one and the same period.
The conjunction of the two independent conditions that must both hold for a genuine simultaneity: the revisions’ inclusive validity windows intersect (
valid_toofNonemeaning open-ended) AND their period selectors address a common period. Variant schemas that share a validity window are alternative shapes of one period and coexist; successive editions whose windows only meet end-to-start do not, however identical their period vocabularies happen to be.This is the predicate for policy that asks “is this pair simultaneous, or is it a real temporal succession”.
revisions_overlap()answers only the selector half and reports successive editions of a stable period vocabulary as overlapping.Core types:
ModeloRevision.- Return type:
- Parameters:
left (ModeloRevision)
right (ModeloRevision)
- ordered_revisions(modelo)[source]¶
Return a modelo’s revisions in validity order, ties broken by id.
Core types:
ModeloDefinition.- Return type:
- Parameters:
modelo (ModeloDefinition)