contacts
¶
Module Contents¶
Classes¶
A contact event object keeps track of the initial timestep and total |
|
Class to keep track of every time 2 agents come in close proximity |
Functions¶
|
Utility function to update a dictionary to add data to existing value if |
- contacts.update_data_dictionary(datadict: dict, key: Hashable, data: Union[float, int]) dict ¶
Utility function to update a dictionary to add data to existing value if the key exist or create new key:value pair if not
- Parameters:
datadict (dict) – the dictionary to update
key (str) – key for the value to update
data (float or int) – the value to add to current value
- Returns:
the updated dictionary
- Return type:
dict
- class contacts.ContactEvent(floor_number: int, location: int, position: Tuple[int, int], current_step: int)¶
A contact event object keeps track of the initial timestep and total duration as well as the list of xy positions, locations and floor numbers of a contact (e.g. two people walking together).
- class contacts.ContactEvents¶
Class to keep track of every time 2 agents come in close proximity
- add_contact(agent1: citam.engine.core.agent.Agent, agent2: citam.engine.core.agent.Agent, current_step: int, position: Tuple[int, int]) None ¶
Add single contact event between two agents. If there was a contact event in the previous step, update its duration and list of locations. The floor number is extracted from the first agent’s position.
..note: a contact event is identified
- count() int ¶
compute the total number of unique contact events. A unique contact event involves two specific agents and has a start and end time.
..Note: two agents can have more than 1 unique contact event.
- Returns:
total number of unique contact events
- Return type:
int
- save_pairwise_contacts(filename: str) None ¶
Save pairwise contact data to file. The file is saved in a CSV format with the following columns: Agent1, Agent2, total contacts and total contact duration.
..note: this is an aggregate over all the contacts between two agents.
- Parameters:
filename (str) – name of the file
- extract_statistics() List[Dict[str, Any]] ¶
Extract important contact statistics from contact data.
- Returns:
list of dictionaries of important statistics. Each stat is given by its name, value and unit.
- Return type:
list[dict[str, Dict]]
- get_floor_contact_coords(key: str, floor_number: int) List[Tuple[int, int]] ¶
Iterate over all contact events associated with key (referring to two specific agents), and return the ones that took place on given floor number.
- Parameters:
key (str) – the pair of agents given by a key of the form <agent1_id>-<agent2_id> where agent1_id < agent2_id.
floor_number (int) – index of the floor of interest.
- Returns:
the xy coordinates of where contacts took place
- Return type:
List[Tuple[int, int]]
- get_contacts_per_coordinates(floor_number: int) Dict[Tuple[int, int], int] ¶
Save per coordinate contact data to file.
- Parameters:
step (int) – Simulation step for which to extract contact data.
floor_number (int) – Floor number for which to extract data.
- Returns:
Dictionary of contacts per location with xy positions as keys
- Return type:
Dict[Tuple[int, int], int]
- save_raw_contact_data(filename: str) None ¶
Save all contact data to file.
This will write all the contact information in this simulation to file (can be big). The data will be converted to a dictionary of list of dictionaries where the top dictionary is keyed by agent_id - agent_id with their corresponding list of contacts. Each contact event is represented by a dictionary with property names and values of the ContactEvent class.
- Parameters:
filename (str) – The file path to save the data