Пример #1
0
def synergy_score(team: Team) -> Dict[int, float]:
    """Synergy score shows if the day facilitates cooperation between people in joint projects.

    It's normalized from 0 to 1."""

    scores = defaultdict(list)

    for user in team.users:
        connected = team.connections[user.user_id]
        for other_id in connected:
            other = get_user(other_id)
            for i, day in enumerate(Weekdays.all_days):
                score1 = getattr(user, day)
                score2 = getattr(other, day)
                scores[i].append(score1 * score2)

    n_connections = 0
    for uid, connected in team.connections.items():
        n_connections += len(connected)

    if not n_connections:
        return {i: 0.5 for i in range(5)}

    scores_raw = {
        k: (sum(v) / n_connections / 16)**0.5
        for k, v in scores.items()
    }
    return scores_raw
Пример #2
0
def artefact(artefact_id):
    try:
        [artefact] = get_artefacts(artefact_id)
    except ValueError as e:
        flash("Couldn't find that Artefact!")
        return redirect(url_for('artefacts'))

    if artefact.owner in family_user_ids(current_user.family_id):

        artefact_images = get_artefact_images_metadata(artefact_id)

        owner = get_user(artefact.owner)

        if artefact.stored_with == "user":
            location = get_user_loc(artefact.stored_with_user)

        else:
            location = artefact.stored_at_loc

        tags = get_tags_of_artefacts([artefact.artefact_id])

        return view_artefact(artefact, artefact_images, current_user.id,
                             location, owner, tags)

    else:
        flash("You don't have access to this item")
        return unauthorized()
Пример #3
0
def post_rule():
    """A rule is actually a preference of a user, on a given day. """

    data = request.json
    if "user_id" not in data:
        return "user_id is missing in the request.", 400
    user_id = int(data["user_id"])

    if "day" not in data:
        return "day is missing in the request.", 400
    day = int(data["day"])

    if "preference" not in data:
        return "preference is missing in the request.", 400
    preference = int(data["preference"])

    try:
        user = get_user(user_id)
    except Exception as e:
        return f"invalid user id {e}", 400

    if day == 0:
        user.monday = preference
    elif day == 1:
        user.tuesday = preference
    elif day == 2:
        user.wednesday = preference
    elif day == 3:
        user.thursday = preference
    elif day == 4:
        user.friday = preference
    else:
        return "invalid day id, must be between 0 and 4", 400

    return "Successfully posted the rule", 200
Пример #4
0
    def __init__(self, username, password):
        # Check if user exists, if not, create
        juser = ps.get_user(username)

        if hashlib.sha512(password).hexdigest() == str(juser["password"]):
            self.username = username
            self.about = juser["about"]
            self.passwd = juser["password"]
            self.valid = True
        else:
            self.valid = False
Пример #5
0
def plot_team_connections(team):
    G = nx.Graph()
    for user in team.users:
        G.add_node(user.first_name)

    for source, connections in team.connections.items():
        for target in connections:
            u1 = get_user(source)
            u2 = get_user(target)
            G.add_edge(u1.first_name, u2.first_name)

    import random
    pos = {n: (random.random(), random.random()) for n in G.nodes}

    nx.draw(
        G,
        pos=nx.fruchterman_reingold_layout(G, fixed=G.nodes, pos=pos, ),
        with_labels=True,
        node_size=3000,
    )
    plt.show()
Пример #6
0
def user_route():
    """Returns user represented as json. """

    if "user_id" not in request.args:
        return "user_id is missing in the request.", 400
    user_id = int(request.args["user_id"])

    try:
        user = get_user(user_id)
    except Exception as e:
        return f"invalid user id {e}", 400

    return user.to_json()
Пример #7
0
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
Пример #8
0
def view_question(question_id=None):
    question = persistence.get_item_by_id("question", question_id)
    questions_answer = persistence.get_item_by_foreign_key(
        'answer', question_id, "question_id")
    question_comment = persistence.get_item_by_foreign_key(
        'comment', question_id, "question_id")
    answer_ids = logic.get_answer_ids(questions_answer)
    answer_comment = logic.get_answer_comments(answer_ids)
    labels = logic.get_list_of_headers(question)
    labels_answer = logic.get_list_of_headers(questions_answer)
    labels_question_comment = logic.get_list_of_headers(question_comment)
    labels_answer_comment = logic.get_list_of_headers(answer_comment)
    user = persistence.get_user(question[0]['user_id'])
    return render_template('display_question.html',
                           question=question,
                           questions_answer=questions_answer,
                           labels=labels,
                           question_id=question_id,
                           labels_answer=labels_answer,
                           question_comment=question_comment,
                           answer_comment=answer_comment,
                           labels_question_comment=labels_question_comment,
                           labels_answer_comment=labels_answer_comment,
                           user=user[0])
Пример #9
0
def get_user_if_validated(user_data):
    return persistence.get_user(user_data)
Пример #10
0
def display_name(firstname):
    userInfo = persistence.get_user(firstname)
    return userInfo.firstname + ' ' + userInfo.lastname
Пример #11
0
def get_user_by_id(userID):
    return persistence.get_user(userID)
Пример #12
0
def get_all_questions_answers_comments_and_user(userID):
    questions = persistence.get_all_users_questions(userID)
    answers = persistence.get_all_users_answers(userID)
    comments = persistence.get_all_users_comments(userID)
    user = persistence.get_user(userID)
    return questions, answers, comments, user