detail_validator
Class for converting a record's detail before the Pydantic model validation.
Classes:
-
DetailValidator
–In Heurist, a record's "detail" is what is more commonly known as an attribute, dimension, or a data field.
DetailValidator
In Heurist, a record's "detail" is what is more commonly known as an attribute, dimension, or a data field.
This class features methods to extract the key value from Heurist's JSON formatting for all data types in Heurist's system.
Methods:
-
convert
–Based on the data type, convert the record's nested detail to a flat value.
-
validate_date
–Build the variable date value into a structured dictionary.
-
validate_enum
–Extract the value of an enum field.
-
validate_file
–Extract the value of a file field.
-
validate_geo
–Extract the value of a geo field.
-
validate_resource
–Extract the value of a resource (foreign key) field.
convert
classmethod
convert(detail: dict) -> str | int | list | dict | None
Based on the data type, convert the record's nested detail to a flat value.
Parameters:
-
detail
dict
) –One of the record's details (data fields).
Returns:
-
str | int | list | dict | None
–str | int | list | dict | None: Flattened value of the data field.
validate_date
classmethod
validate_date(detail: dict) -> dict
Build the variable date value into a structured dictionary.
Examples:
>>> # Test temporal object
>>> from heurist.mock_data.date.compound_single import DETAIL
>>> value = DetailValidator.convert(DETAIL)
>>> value['start']['earliest']
datetime.datetime(1180, 1, 1, 0, 0)
>>> # Test direct date value
>>> from heurist.mock_data.date.simple_single import DETAIL
>>> value = DetailValidator.convert(DETAIL)
>>> value['value']
datetime.datetime(2024, 3, 19, 0, 0)
Parameters:
-
detail
dict
) –Record's detail.
Returns:
-
dict
(dict
) –Structured metadata for a Heurist date object.
validate_enum
classmethod
validate_enum(detail: dict) -> str
Extract the value of an enum field.
Parameters:
-
detail
dict
) –Record's detail.
Returns:
-
str
(str
) –Value of record's detail.
validate_file
classmethod
validate_file(detail: dict) -> str
Extract the value of a file field.
Parameters:
-
detail
dict
) –Record's detail.
Returns:
-
str
(str
) –Value of record's detail.
validate_geo
classmethod
validate_geo(detail: dict) -> str
Extract the value of a geo field.
Examples:
>>> from heurist.mock_data.geo.single import DETAIL_POINT
>>> DetailValidator.convert(DETAIL_POINT)
'POINT(2.19726563 48.57478991)'
Parameters:
-
detail
dict
) –Record's detail.
Returns:
-
str
(str
) –Value of record's detail.
validate_resource
classmethod
validate_resource(detail: dict) -> int
Extract the value of a resource (foreign key) field.
Parameters:
-
detail
dict
) –Record's detail.
Returns:
-
int
(int
) –Heurist ID of the referenced record.