es_sfgtools.data_models.metadata.utils module
- class es_sfgtools.data_models.metadata.utils.AttributeUpdater
Bases:
object- set_value(key, value)
Set the value of an attribute and update the class instance.
This also validates the updated instance.
- Parameters:
key (str) – The key.
value (Any) – The value.
- update_attributes(additional_data: Dict[str, Any])
Update the class attributes based on the provided dictionary.
This handles nested objects with the AttributeUpdater (e.g Location) class. This class is helpful for the notebook where the user will be passing empty strings if they don’t want to update a field. This function will only reset the value if not empty. If other keys are provided in the dictionary, it will print a warning.
- Parameters:
additional_data (Dict[str, Any]) – A dictionary of additional attributes to update.
- class es_sfgtools.data_models.metadata.utils.Location(*, latitude: Annotated[float | None, Ge(ge=-90), Le(le=90)] = None, longitude: Annotated[float | None, Ge(ge=-180), Le(le=180)] = None, elevation: float | None = None)
Bases:
AttributeUpdater,BaseModel- elevation: float | None
- latitude: float | None
- longitude: float | None
- model_computed_fields = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields = {'elevation': FieldInfo(annotation=Union[float, NoneType], required=False, default=None, description='The elevation of the location.'), 'latitude': FieldInfo(annotation=Union[float, NoneType], required=False, default=None, description='The latitude of the location.', metadata=[Ge(ge=-90), Le(le=90)]), 'longitude': FieldInfo(annotation=Union[float, NoneType], required=False, default=None, description='The longitude of the location.', metadata=[Ge(ge=-180), Le(le=180)])}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- es_sfgtools.data_models.metadata.utils.check_dates(cls, end, values)
Check that the end date is after the start date.
- Parameters:
cls (class) – The class.
end (datetime) – The end date.
values (dict) – The values.
- Returns:
The end date.
- Return type:
datetime
- es_sfgtools.data_models.metadata.utils.check_fields_for_empty_strings(cls, value)
Check if the field is an empty string and replace it with None.
- Parameters:
cls (class) – The class.
value (str) – The value.
- Returns:
The value or None.
- Return type:
str | None
- es_sfgtools.data_models.metadata.utils.convert_custom_objects_to_dict(d: dict) dict
Recursively convert custom objects in a dictionary to dictionaries.
- Parameters:
d (dict) – The dictionary to update.
- Returns:
The updated dictionary with custom objects converted to dictionaries.
- Return type:
dict
- es_sfgtools.data_models.metadata.utils.convert_to_datetime(date_str: str | datetime) datetime
Convert ISO string format to datetime if a string is provided.
- Parameters:
date_str (Union[str, datetime]) – The date string or datetime object to convert.
- Returns:
The converted datetime object, always timezone-aware in UTC.
- Return type:
datetime
- Raises:
ValueError – If the date string is not in a valid ISO format.
- es_sfgtools.data_models.metadata.utils.if_zero_than_none(cls, value)
If the value is 0, return None.
- Parameters:
cls (class) – The class.
value (int) – The value.
- Returns:
The value or None.
- Return type:
int | None
- es_sfgtools.data_models.metadata.utils.only_one_is_true(*args)
Check that only one of the arguments is True.
- Parameters:
*args – The arguments to check.
- Returns:
True if only one of the arguments is True, False otherwise.
- Return type:
bool
- es_sfgtools.data_models.metadata.utils.parse_datetime(cls, value)
Parse a datetime string.
- Parameters:
cls (class) – The class.
value (str) – The datetime string.
- Returns:
The parsed datetime.
- Return type:
datetime