Source code for ts_ids_core.schema.value_unit

from __future__ import annotations

from typing_extensions import deprecated

from ts_ids_core.annotations import Nullable, Required
from ts_ids_core.base.ids_element import IdsElement
from ts_ids_core.base.ids_field import IdsField


[docs] class ValueUnit(IdsElement): """A quantity, represented by a value with a unit.""" value: Required[Nullable[float]] = IdsField(description="A numerical value.") unit: Required[Nullable[str]] = IdsField( description="Unit for the numerical value." )
[docs] @deprecated( "Use RawValueRawUnit, which also records the unit as it was expressed in the " "primary data.", category=None, ) class RawValueUnit(ValueUnit): """A value with a unit, including the raw representation of the value from the primary data.""" raw_value: Required[Nullable[str]] = IdsField( description="The raw, untransformed value from the primary data." )
# RawValueRawUnit extends ValueUnit so that a raw quantity is also a ValueUnit. # It redeclares the inherited fields without Required because every field here is # nullable, so a missing field and a null field mean the same thing.
[docs] class RawValueRawUnit(ValueUnit): """A value with a unit, including the raw representations of the value and the unit from the primary data.""" value: Nullable[float] = IdsField(description="A numerical value.") unit: Nullable[str] = IdsField(description="Unit for the numerical value.") raw_value: Nullable[str] = IdsField( description="The raw, untransformed value from the primary data." ) raw_unit: Nullable[str] = IdsField( description="The raw, untransformed unit from the primary data." )