def get_pretty_string(pref: Preferences, teams: [[]]) -> str: """Builds and returns a string describing teams made from pref. Parameters: - pref: preferences of the teamed students. - teams: contains the teams which have to be scored. Returns: a string description of the teams. """ strings = [] for team in teams: string = [] team = set(team) for s in team: if s == DUMMY: string.append(DUMMY) continue greens = set(pref.get_greens(s)) if greens: if greens & team: string.append(f'{Fore.GREEN}{s}{Style.RESET_ALL}') else: string.append(f'{Fore.YELLOW}{s}{Style.RESET_ALL}') else: string.append(s) strings.append(','.join(string)) return '\n'.join(strings)
def get_teaming_score(pref: Preferences, teams: [[]]) -> float: """Scores a teaming. The score is maximum when every team in the teaming consists of people who want to work with each other. Parameters: - pref: preferences of the teamed students. - teams: contains the teams which have to be scored. Returns: The score for matching. """ team_scores = [] n = len(teams[0]) for team in teams: actual_score = perfect_score = 0 for s in team: if s == DUMMY: continue greens = pref.get_greens(s) if (num_greens := min(n, len(greens))): actual_score += sum( (1 for t in team if t in greens and t != DUMMY)) perfect_score += num_greens if perfect_score: team_scores.append(actual_score / perfect_score)