def team_route(): """Returns team represented as json. """ if "team_id" not in request.args: return "team_id is missing in the request.", 400 team_id = int(request.args["team_id"]) try: team = get_team(team_id) except Exception as e: return f"invalid team id {e}", 400 return team.to_json()
def get_results(): """Returns a score, Dict[int, float] represented as json. Example: { 0 : 0.25, 1 : 1., 2 : 0., 3 : 0.5, 4 : 0.5 } """ if "team_id" not in request.args: return "team_id is missing in the request.", 400 team_id = int(request.args["team_id"]) team = get_team(team_id) score = onsite_score(team) return json.dumps(score)
def connect(): """Register that user_1 (`from`) needs to work with user_2 (`to`). """ data = request.json # validate input if "from" not in data: return "from user_from is missing in the request.", 400 user_from = int(data["from"]) if "to" not in data: return "to user_to is missing in the request.", 400 user_to = int(data["to"]) if "team_id" not in data: return "team_id is missing in the request.", 400 team_id = int(data["team_id"]) # check no self loop if user_from == user_to: return "cannot want to work with yourself", 400 # validate users try: get_user(user_from) get_user(user_to) except Exception as e: return f"invalid user id {e}", 400 # validate team try: team = get_team(team_id) except Exception as e: return f"invalid team id {e}", 400 team.add_connection(user_from, user_to) return "added connection", 200
from persistence import load_data, get_team from score_calculator import average_score, synergy_score, onsite_score load_data() at = get_team(1) fs = average_score(at) gs = synergy_score(at) scores = onsite_score(at) print("Full scores: " + str([f"{k}:{v:.3f}" for k, v in fs.items()])) print("Full scores: " + str([f"{k}:{v:.3f}" for k, v in gs.items()])) print("Full scores: " + str([f"{k}:{v:.3f}" for k, v in scores.items()]))
G, pos=nx.fruchterman_reingold_layout(G, fixed=G.nodes, pos=pos, ), with_labels=True, node_size=3000, ) plt.show() def plot_liking(team): x = [] y = [] c = [] for dy, user in enumerate(team.users): for i, day in enumerate(Weekdays.all_days): liking = getattr(user, day) x.append(i + dy * 0.07 - 0.07) y.append(liking) c.append(user.first_name) sns.scatterplot(x, y, c) # plt.scatter( x, y, c=c) plt.show() if __name__ == '__main__': load_data() team = get_team(1) plot_team_connections(team) plot_liking(team)