Source code for module.utils.set_person_frames

from typing import List, Dict
import avesterra as av
from utils import create_person_entity


[docs] def set_person_frames( people_data: List[av.AvEntity], auth: av.AvAuthorization ) -> av.AvEntity: """ Orchestra provides a powerful construct called frames. A frame is similar to a table or Excel spreadsheet. Think of a frame as a row in a table. Each frame has the same field headings and each frame (row) has a unique key. :param people_data: List of people to add to frame. :param auth: The Orchestra server authorization that allows entity operations. """ # Create a report entity that will contain the frames of people report_entity = create_person_entity.create_entity(name="People Report", auth=auth) # Add a LIST fact to the report entity to store the list of people frames. av.set_fact( entity=report_entity, attribute=av.av.AvAttribute.LIST, authorization=auth ) # Create the set of common field headings (column names) av.include_field( entity=report_entity, attribute=av.av.AvAttribute.LIST, name="Name", authorization=auth, ) av.include_field( entity=report_entity, attribute=av.av.AvAttribute.LIST, name="PersonEID", authorization=auth, ) av.include_field( entity=report_entity, attribute=av.av.AvAttribute.LIST, name="Occupation", authorization=auth, ) av.include_field( entity=report_entity, attribute=av.av.AvAttribute.LIST, name="Company", authorization=auth, ) # Create each frame with its people data. There are two people entities in the people # data list, so we'll be creating two frames. Note that each frame has the same # key which is the peron's entity ID represented as a string. for person in people_data: av.set_frame( entity=report_entity, attribute=av.AvAttribute.LIST, name="PersonEID", key=str(person), value=av.AvValue.encode(person), authorization=auth, ) av.set_frame( entity=report_entity, attribute=av.AvAttribute.LIST, name="Name", key=str(person), value=av.AvValue.encode(av.entity_name(entity=person, authorization=auth)), authorization=auth, ) occupation = av.get_fact( entity=person, attribute=av.AvAttribute.OCCUPATION, authorization=auth ) av.set_frame( entity=report_entity, attribute=av.AvAttribute.LIST, name="Occupation", key=str(person), value=occupation, authorization=auth, ) company = av.get_fact( entity=person, attribute=av.AvAttribute.COMPANY, authorization=auth ) av.set_frame( entity=report_entity, attribute=av.AvAttribute.LIST, name="Company", key=str(person), value=company, authorization=auth, ) return report_entity