Пример #1
0
def set_player_codes():
    """
    Set players codes in all the Match objects
    """
    for match in Match.objects():
        for number in match.players_number:
            match.players_code.append(Team.objects(number=number).get().code)
        match.save()
Пример #2
0
def resolve_hash(hash_value):
    game = Game.objects(hash=hash_value).first()
    if game:
        return game.number
    try:
        return Team.objects(hash=hash_value).get().code
    except DoesNotExist:
        raise BadenException(
            "No teams nor games found for hash {}".format(hash_value))
Пример #3
0
def get_section_score(section):
    """
    Get the mean score of a given section
    :param section: a section name
    :return: the mean score
    """
    scores = list()
    teams = Team.objects(section=section)
    for team in teams:
        if not team.ignore_score:
            scores.append(get_score(team.code)[0])
    return sum(scores) / len(scores)
Пример #4
0
    def teams(self, password=None, **unknown_args):
        login_page = request_login("teams", password, 2)
        if login_page:
            return login_page
        match_quantity = model.match.get_match_quantity()
        code_list = list()
        code_list.append(open(join(HTML_DIR, "header_admin.html"), 'r').read())
        with html.div(code_list,
                      'class="table-responsive-sm text-nowrap text-center"'):
            with html.table(code_list,
                            'class="table table-bordered table-hover"'):
                with html.thead(code_list, 'class="thead-light"'):
                    with html.tr(code_list):
                        with html.th(code_list, scope="col"):
                            with html.a(code_list, "/admin"):
                                code_list.append("Teams")
                        with html.th(code_list, scope="col"):
                            code_list.append("Score")
                        with html.th(code_list, scope="col"):
                            code_list.append("V")
                        with html.th(code_list, scope="col"):
                            code_list.append("E")
                        with html.th(code_list, scope="col"):
                            code_list.append("D")
                        for i in range(1, match_quantity + 1):
                            with html.th(code_list, scope="col"):
                                code_list.append("t{}".format(i))
                with html.tbody(code_list):
                    for team in Team.objects().order_by('code'):
                        score, victories, evens, defeat = service.get_score(
                            team.code)
                        with html.tr(code_list):
                            color_tag = "table-primary" if team.sex == "M" else "table-danger"
                            with html.th(
                                    code_list,
                                    scope="row",
                                    params='class="{}"'.format(color_tag)):
                                code_list.append(team.code)
                            with html.td(code_list):
                                code_list.append(str(score))
                            with html.td(code_list):
                                code_list.append(str(victories))
                            with html.td(code_list):
                                code_list.append(str(evens))
                            with html.td(code_list):
                                code_list.append(str(defeat))
                            for match in team.matches:
                                if not match.recorded:
                                    color_tag = ""
                                elif match.even:
                                    color_tag = "table-warning"
                                elif match.winner == team.code:
                                    color_tag = "table-success"
                                else:
                                    color_tag = "table-danger"
                                with html.td(code_list,
                                             'class="{}"'.format(color_tag)):
                                    with html.a(
                                            code_list,
                                            "/admin/match?mid={}".format(
                                                match.id)):
                                        code_list.append(str(
                                            match.game_number))

        code_list.append(open(join(HTML_DIR, "footer.html"), 'r').read())
        return ''.join(code_list)
Пример #5
0
def get_section(team_code):
    return Team.objects(code=team_code).get().section
Пример #6
0
def is_team(team_code):
    return Team.objects(code=team_code).count() > 0
Пример #7
0
def test_score(distributed_clean_db):
    service.set_winner(1, "A1", "I3")
    service.set_even(2, "A1", "A4")
    service.set_winner(1, "A2", "A3")
    service.set_winner(2, "A2", "I2")
    service.set_even(2, "A3", "B1")
    service.set_even(3, "A3", "I1")
    assert service.get_score("A1")[0] == 3, "Team A1 should have 3 points"
    assert service.get_score("A1")[1] == 1, "Team A1 should have 1 victory"
    assert service.get_score("A1")[2] == 1, "Team A1 should have 1 even"
    assert service.get_score("A2")[0] == 4, "Team A2 should have 4 points"
    assert service.get_score("A2")[1] == 2, "Team A2 should have 2 victories"
    assert service.get_score("A2")[2] == 0, "Team A2 should have 0 evens"
    assert service.get_score("A3")[0] == 2, "Team A3 should have 2 points"
    assert service.get_score("A3")[1] == 0, "Team A3 should have 0 victories"
    assert service.get_score("A3")[2] == 2, "Team A3 should have 2 evens"
    assert service.get_score("A3")[3] == 1, "Team A3 should have 1 defeat"
    assert service.get_score("A4")[0] == 1, "Team A4 should have 1 points"
    assert service.get_score("A4")[1] == 0, "Team A4 should have 0 victories"
    assert service.get_score("A4")[2] == 1, "Team A4 should have 1 even"
    a_section = Team.objects(code="A1").first().section
    assert service.get_section_score(
        a_section) == 10 / 5, "{} mean score should be {}".format(
            a_section, 10 / 5)

    service.set_winner(24, "J3", "Q1")
    service.set_even(22, "J3", "J2")
    service.set_winner(29, "J5", "M4")
    service.set_winner(30, "J5", "O2")
    service.set_even(29, "J6", "O5")
    service.set_even(30, "J6", "M7")
    assert service.get_score("J3")[0] == 3, "Team J3 should have 3 points"
    assert service.get_score("J3")[1] == 1, "Team J3 should have 1 victory"
    assert service.get_score("J3")[2] == 1, "Team J3 should have 1 even"
    assert service.get_score("J5")[0] == 4, "Team J5 should have 4 points"
    assert service.get_score("J5")[1] == 2, "Team J5 should have 2 victories"
    assert service.get_score("J5")[2] == 0, "Team J5 should have 0 evens"
    assert service.get_score("J6")[0] == 2, "Team J6 should have 2 points"
    assert service.get_score("J6")[1] == 0, "Team J6 should have 0 victories"
    assert service.get_score("J6")[2] == 2, "Team J6 should have 2 evens"
    assert service.get_score("J2")[0] == 1, "Team J2 should have 1 points"
    assert service.get_score("J2")[1] == 0, "Team J2 should have 0 victories"
    assert service.get_score("J2")[2] == 1, "Team J2 should have 1 even"
    j_section = Team.objects(code="J1").first().section
    assert service.get_section_score(
        j_section) == 10 / 6, "{} mean score should be {}".format(
            j_section, 10 / 6)

    global_section_ranking = service.get_ranking_by_section()
    assert global_section_ranking[0][
        0] == a_section, "{} should be first in the ranking".format(a_section)
    assert global_section_ranking[1][
        0] == j_section, "{} should be second in the ranking".format(j_section)

    assert service.get_ranking_by_section("F")[0][
        0] == a_section, "{} should be first in the girls ranking".format(
            a_section)
    assert service.get_ranking_by_section("M")[0][
        0] == j_section, "{} should be first in the boys  ranking".format(
            j_section)

    service.set_winner(27, "J5", "L6")
    service.set_winner(32, "J3", "M8")
    global_ranking = service.get_ranking()
    assert global_ranking[0][0] == "J5", "Global first team should be J5"
    assert global_ranking[1][0] == "J3", "Global second team should be J3"
    assert global_ranking[2][0] == "A2", "Global third team should be A2"
    assert global_ranking[3][0] == "A1", "Global fourth team should be A1"

    boys_ranking = service.get_ranking("M")
    assert boys_ranking[0][0] == "J5", "Boys first team should be J5"
    assert boys_ranking[1][0] == "J3", "Boys second team should be J3"
    assert boys_ranking[2][0] == "J6", "Boys third team should be J6"
    assert boys_ranking[3][0] == "J2", "Boys fourth team should be J2"

    girls_ranking = service.get_ranking("F")
    assert girls_ranking[0][0] == "A2", "Girls first team should be A2"
    assert girls_ranking[1][0] == "A1", "Girls second team should be A1"
    assert girls_ranking[2][0] == "A3", "Girls third team should be A3"
    assert girls_ranking[3][0] == "A4", "Girls fourth team should be A4"