import avesterra as av
[docs]
def set_facet_and_factors(person_entity: av.AvEntity, home_address: str, work_address: str, auth: av.AvAuthorization):
"""
A person can have multiple addresses. Features, Facets/Factors & Factors, and
Frames are Avial constructs that can be used to add additional attributes to a Fact.
This function shows how facets and factors can be used for multiple addresses. When to use
Features, facets, or Frames is a modeling discussion and not applicable to this lesson.
:param person_entity: The entity ID of the person entity to add the feature.
:param home_address: Person's home address.
:param work_address: Person's work address.
:param auth: The Orchestra server authorization that allows entity operations.
"""
av.set_facet(
entity=person_entity,
attribute=av.AvAttribute.ADDRESS,
name='Home Address',
value=av.AvValue.encode_string(home_address),
authorization=auth,
)
av.set_facet(
entity=person_entity,
attribute=av.AvAttribute.ADDRESS,
name='Work Address',
value=av.AvValue.encode_string(work_address),
authorization=auth,
)
# To demonstrate factors, assume we need to store the city, zipcode, and state
# separate from the street address. We're only showing adding factors to the
# Work Address and not the Home Address.
# The following factors belongs to the Work Address facet because the name='Work Address'
# matches the facet's Work Address name.
av.set_factor(
entity=person_entity,
attribute=av.AvAttribute.ADDRESS,
value=av.AvValue.encode_string("San Diego"),
name='Work Address',
key="city",
authorization=auth
)
av.set_factor(
entity=person_entity,
attribute=av.AvAttribute.ADDRESS,
value=av.AvValue.encode_string('California'),
name='Work Address', # This factor belongs to the Work Address facet.
key="state",
authorization=auth
)
av.set_factor(
entity=person_entity,
attribute=av.AvAttribute.ADDRESS,
value=av.AvValue.encode_string("21135"),
name="Work Address", # This factor belongs to the Work Address facet.
key="zip",
authorization=auth
)