summaryrefslogtreecommitdiff
path: root/jfr_playoff/data/tournament/__init__.py
blob: e86d294f9d6b12a39bfd0122eb01b40f1457dbc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from jfr_playoff.logger import PlayoffLogger
from jfr_playoff.data.info import ResultInfo


class TournamentInfoClient(object):
    def __init__(self, settings, database=None):
        self.settings = settings
        self.database = database

    def get_results_link(self, suffix):
        pass

    def is_finished(self):
        pass

    def get_tournament_results(self):
        pass

    def get_exceptions(self, method):
        pass


class TournamentInfo(ResultInfo):
    def __init__(self, settings, database):
        self.settings = settings
        ResultInfo.__init__(self, settings, database)

    def fill_client_list(self, settings, database):
        clients = []
        from jfr_playoff.data.tournament.jfrdb import JFRDbTournamentInfo
        from jfr_playoff.data.tournament.jfrhtml import JFRHtmlTournamentInfo
        from jfr_playoff.data.tournament.tcjson import TCJsonTournamentInfo
        if (database is not None) and ('database' in settings):
            clients.append(JFRDbTournamentInfo(settings, database))
        if 'link' in settings:
            if settings['link'].endswith('leaderb.html'):
                clients.append(JFRHtmlTournamentInfo(settings))
            clients.append(TCJsonTournamentInfo(settings))
        return clients

    def get_tournament_results(self):
        teams = self.call_client('get_tournament_results', [])
        if self.is_finished():
            final_positions = self.settings.get('final_positions', [])
            PlayoffLogger.get('tournamentinfo').info(
                'setting final positions from tournament results: %s',
                final_positions)
            for position in final_positions:
                if len(teams) >= position:
                    teams[position-1] = (teams[position-1] + [None] * 4)[0:4]
                    teams[position-1][3] = position
        return teams

    def is_finished(self):
        return self.call_client('is_finished', True)

    def get_results_link(self, suffix='leaderb.html'):
        return self.call_client('get_results_link', None, suffix)