예제 #1
0
def view_player(id):
    session = Session()

    player = session.query(Player).filter(Player.id == id).one()
    players = session.query(Player).all()
    decks = session.query(Deck).all()

    pmap = {}
    for d in players:
        pmap[d.id] = d

    dmap = {}
    for d in decks:
        dmap[d.id] = d

    rank_manager = RankingManager()
    ranking = rank_manager.get_ranking()
    rank_data = ranking.get_player_ranking(id)

    table = rank_manager.ranking_table([rank_data], True)

    games_data, decks_data = get_player_info(id)

    titles = rank_manager.get_titles(id)

    return render_template('players/view_player.html',
                           player=player,
                           players=pmap,
                           decks=dmap,
                           ranking_table=table,
                           games_data=games_data,
                           decks_data=decks_data,
                           titles=titles)
예제 #2
0
파일: decks.py 프로젝트: jhonatandarosa/mtm
def index_view():
    session = Session()
    decks = session.query(Deck).all()

    team = {}

    for deck in decks:
        _class = ''
        if deck.status == 'inactive':
            _class = 'blue-grey lighten-5'
        team[deck.id] = {'name': deck.name, '_class': _class}

    admin = request.args.get('admin', '') == 'True'

    rank_manager = RankingManager()
    ranking = rank_manager.get_ranking()

    table = rank_manager.ranking_table(ranking.decks, True)

    return render_template('decks/index.html',
                           admin=admin,
                           rank_table=table,
                           teams=team)
예제 #3
0
파일: decks.py 프로젝트: jhonatandarosa/mtm
def tier_view():
    session = Session()
    decks = session.query(Deck).all()

    team = {}

    for deck in decks:
        _class = ''
        if deck.status == 'inactive':
            _class = 'blue-grey lighten-5'
        team[deck.id] = {
            'name': deck.name,
            '_class': _class,
            'status': deck.status
        }

    admin = request.args.get('admin', '') == 'True'

    rank_manager = RankingManager()
    ranking = rank_manager.get_ranking()

    tiers = tier_sort(ranking.decks[:])

    tiers = [x for x in tiers if team[x['id']]['status'] != 'inactive']

    for deck in ranking.decks:
        data = team[deck['id']]

        if data['_class'] == '':
            data['_class'] = get_tier_class(deck['tier'])

    table = rank_manager.ranking_table(tiers, True)

    return render_template('decks/index.html',
                           admin=admin,
                           rank_table=table,
                           teams=team)
예제 #4
0
def year_view(year):
    rank_manager = RankingManager()
    ranking = rank_manager.get_ranking(year)

    return send_player_ranking(ranking.players, 'Players (%s)' % year,
                               ranking.titles)
예제 #5
0
def index_view():
    rank_manager = RankingManager()
    ranking = rank_manager.get_ranking()

    return send_player_ranking(ranking.players, 'Players', ranking.titles)
예제 #6
0
def player_ranking_by_tournament_type(type, block_name, year=None):
    rank_manager = RankingManager()
    ranking = rank_manager.get_ranking(year)

    ranking_players = ranking.tournaments_types[type.value]
    return send_player_ranking(ranking_players, block_name, ranking.titles)
예제 #7
0
    def get_available_decks_for_next_tournament(self, tier):
        session = Session()

        ds = session.query(Deck).filter(Deck.status == 'active').all()
        parts = session.query(Participant).all()
        # tournaments = session.query(Tournament).filter(Tournament.status == 'finished').order_by(
        #     Tournament.id.asc()).all()

        decks = {}
        participants = {}

        for p in parts:
            participants[p.id] = p

        for deck in ds:
            decks[deck.id] = deck

        rank_manager = RankingManager()
        ranking = rank_manager.get_ranking()
        # for tournament in tournaments:
        #     if tournament.type == TournamentType.DRAFT.value:
        #         continue
        #     t = ranking.get_tournament_ranking(tournament.id)
        #     winner = self.get_winner_deck_id(tournament, participants, t)
        #
        #     deck = decks[winner]
        #
        #     result.remove(deck)

        # sort decks
        play_map = {}
        for deck_data in ranking.decks:
            mp = deck_data['tp']

            play_map[deck_data['id']] = mp

        def deck_sort(a, b):
            ga = play_map[a['id']]
            gb = play_map[b['id']]

            return (ga > gb) - (ga < gb)

        tiers = group_by_key(ranking.decks, 'tier')

        sort_grouped_lists(tiers, deck_sort)

        for t in tiers:
            lst = tiers[t]
            tiers[t] = randomize_grouped_by_matchs_played(lst, play_map)

        if tier == 'T1':
            order = ['T1', 'T2', 'T3']
        elif tier == 'T2':
            order = ['T2', 'T3', 'T1']
        else:
            order = ['T3', 'T2', 'T1']

        result = []
        for t in order:
            lst = tiers[t]
            for d in lst:
                did = d['id']
                if did not in decks:
                    continue
                result.append(decks[did])

        return result