"""A share of a whole, bounded to the inclusive zero-to-one interval.Business-use percentages, usage ratios, prorrata shares and classifierconfidences are all the same quantity: a Decimal share of one. The bound wasopen-coded as ``Decimal("0") <= value <= Decimal("1")`` at nine sites acrossthe ledger, renta, transactions and usage-ratio surfaces and the CLI, plus twofurther local constant pairs spelling the same two numbers.The predicate lives here so every caller asks the same question. Callers keeptheir own refusal: the ledger raises a transaction error, the renta models arenta error, and the CLI raises an operator-facing message naming the offendingvalue and its percentage. That difference is deliberate and worth preserving --the operator's first instructive surface should say ``0.5 means 50 %`` wherethe domain need only say the invariant broke. What must not differ is where theinterval ends.The interval is INCLUSIVE at both ends: a zero share and a whole share are bothlegitimate answers, and a caller that needs to exclude one says so itself."""from__future__importannotationsfromdecimalimportDecimalfromtypingimportAnnotated,FinalfrompydanticimportField#: The smallest legitimate share: none of the whole.UNIT_PROPORTION_MIN:Final[Decimal]=Decimal("0")#: The largest legitimate share: all of the whole.UNIT_PROPORTION_MAX:Final[Decimal]=Decimal("1")UnitProportion=Annotated[Decimal,Field(ge=UNIT_PROPORTION_MIN,le=UNIT_PROPORTION_MAX)]"""A Decimal share of one, for a model field that carries the bound in its type."""UnitFraction=Annotated[float,Field(ge=0.0,le=1.0)]"""A share of one carried as a float, for a score rather than a money share.Deliberately separate from :obj:`UnitProportion`. A confidence, a completenessratio or a coverage figure is a measurement whose last bits do not have tosurvive arithmetic; a share of a taxable amount is money and stays Decimal.Mixing them would let a float creep into a financial path through an alias."""
[docs]defis_unit_proportion(value:Decimal)->bool:"""Whether ``value`` is a share of one, inclusive at both ends."""returnUNIT_PROPORTION_MIN<=value<=UNIT_PROPORTION_MAX