def _born(self) -> Tuple[Person, Person]: # TODO: consider delete if not using anymore """Simulate the born process. Choose random mom and dad. Returns: Tuple[Person, Person]: Two person objects: mom and dad """ matrix = load_matrix() people_dict = matrix.people_dict male_list = [] female_list = [] for key in people_dict: if people_dict[key].gender == Gender.FEMALE.value: female_list.append(key) elif people_dict[key].gender == Gender.MALE.value: male_list.append(key) else: log(text=f'Some gender are undefined', level=Logging.ERROR.value) if male_list and female_list: mom = random.choice(female_list) dad = random.choice(male_list) return people_dict[mom], people_dict[dad] else: log(text=f"Was not able to find a mom and a dad!", level=Logging.INFO.value)
def delete_person(self, uid: str) -> str: """Remove a person from the matrix using uid string Args: uid (str): uuid string Returns: str: output from this function """ output = "" try: uid = UUID(uid) except ValueError: log(text=f"Maybe try a valid uuid?", level=Logging.ERROR.value) return output if uid in self.people_dict: # output += f"{self.people_dict[uid].name} have been removed!" del self.people_dict[uid] else: output += 'That person does not exist!' return output
def choose_parents(self) -> Tuple[Person, Person]: """Choose random mom and dad. Returns: Tuple[Person, Person]: Two person objects: mom and dad """ male_list = [] female_list = [] # get a list of female and male UUIDs for key in self.people_dict: if self.people_dict[key].gender == Gender.FEMALE.value: female_list.append(key) elif self.people_dict[key].gender == Gender.MALE.value: male_list.append(key) else: log(text=f'Some gender are undefined', level=Logging.ERROR.value) # choose a random set of parents if there is at least 1 from each if male_list and female_list: mom = random.choice(female_list) dad = random.choice(male_list) return self.people_dict[mom], self.people_dict[dad] else: log(text=f"Was not able to find a mom and a dad!", level=Logging.INFO.value)
def delete_thing(self, thing_id: str) -> str: """Remove a thing from the matrix Args: thing_id (str): uid of item Returns: str: output string """ output = "" try: uid = UUID(thing_id) except ValueError: log(text=f"Maybe try a valid uuid?", level=Logging.ERROR.value) return output if uid in self.thing_dict: self.remove_item_possession(uid=uid) else: output += 'That thing does not exist!' return output
def __init__(self, mom: Person, dad: Person): super().__init__(mom.first_name, dad.last_name) log(text=f"A baby named {mom.first_name} {dad.last_name} was born.", level=Logging.INFO.value)