diff options
author | emkael <emkael@tlen.pl> | 2019-12-30 12:57:11 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2019-12-30 12:57:11 +0100 |
commit | b33b987e2fc217a488c40979c219deaf536498eb (patch) | |
tree | 75a81bcb281380ebaa5c197facd518abd0058f0f /jfr_playoff | |
parent | 7a598f65372b1b694d222946fd6269033bde0e54 (diff) |
Refactoring package structure (moving MatchInfo and TournamentInfo classes)
Diffstat (limited to 'jfr_playoff')
-rw-r--r-- | jfr_playoff/data/__init__.py | 4 | ||||
-rw-r--r-- | jfr_playoff/data/info.py | 40 | ||||
-rw-r--r-- | jfr_playoff/data/match/__init__.py (renamed from jfr_playoff/matchinfo.py) | 3 | ||||
-rw-r--r-- | jfr_playoff/data/tournament/__init__.py | 42 |
4 files changed, 43 insertions, 46 deletions
diff --git a/jfr_playoff/data/__init__.py b/jfr_playoff/data/__init__.py index 494eaef..638c01f 100644 --- a/jfr_playoff/data/__init__.py +++ b/jfr_playoff/data/__init__.py @@ -2,8 +2,8 @@ from cached_property import cached_property from jfr_playoff.db import PlayoffDB from jfr_playoff.dto import Phase -from jfr_playoff.matchinfo import MatchInfo -from jfr_playoff.data.tournament import TournamentInfo +from jfr_playoff.data.match import MatchInfo +from jfr_playoff.data.info import TournamentInfo from jfr_playoff.logger import PlayoffLogger diff --git a/jfr_playoff/data/info.py b/jfr_playoff/data/info.py index 371ac6a..cb84b75 100644 --- a/jfr_playoff/data/info.py +++ b/jfr_playoff/data/info.py @@ -27,3 +27,43 @@ class ResultInfo(object): PlayoffLogger.get('resultinfo').info( '%s method returning default: %s', method, default) return default + + +from jfr_playoff.data.tournament.jfrdb import JFRDbTournamentInfo +from jfr_playoff.data.tournament.jfrhtml import JFRHtmlTournamentInfo +from jfr_playoff.data.tournament.tcjson import TCJsonTournamentInfo + + +class TournamentInfo(ResultInfo): + def __init__(self, settings, database): + self.settings = settings + ResultInfo.__init__(self, settings, database) + + def fill_client_list(self, settings, database): + clients = [] + 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) diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/data/match/__init__.py index 1c0bcd8..d61f8f8 100644 --- a/jfr_playoff/matchinfo.py +++ b/jfr_playoff/data/match/__init__.py @@ -4,8 +4,7 @@ from urlparse import urljoin import jfr_playoff.sql as p_sql from jfr_playoff.dto import Match, Team from jfr_playoff.remote import RemoteUrl as p_remote -from jfr_playoff.data.info import ResultInfo -from jfr_playoff.data.tournament import TournamentInfo +from jfr_playoff.data.info import ResultInfo, TournamentInfo from jfr_playoff.logger import PlayoffLogger diff --git a/jfr_playoff/data/tournament/__init__.py b/jfr_playoff/data/tournament/__init__.py index e86d294..9ec71dd 100644 --- a/jfr_playoff/data/tournament/__init__.py +++ b/jfr_playoff/data/tournament/__init__.py @@ -1,7 +1,3 @@ -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 @@ -18,41 +14,3 @@ class TournamentInfoClient(object): 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) |