summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2019-12-30 12:34:48 +0100
committeremkael <emkael@tlen.pl>2019-12-30 12:34:48 +0100
commitf77bac9b5406c6bf6b1c819f155164568ef4af36 (patch)
tree972f2851f7ebe76842ff668bce0002ed961a43fe
parent5a5326bf17a4ed3402255493efefd69544afe0d0 (diff)
Preparing result info class refactoring
-rw-r--r--jfr_playoff/data.py32
-rw-r--r--jfr_playoff/matchinfo.py11
-rw-r--r--jfr_playoff/tournamentinfo/__init__.py47
3 files changed, 55 insertions, 35 deletions
diff --git a/jfr_playoff/data.py b/jfr_playoff/data.py
index 6649e68..132ee02 100644
--- a/jfr_playoff/data.py
+++ b/jfr_playoff/data.py
@@ -1,10 +1,40 @@
+from jfr_playoff.logger import PlayoffLogger
+
+
+class ResultInfo(object):
+ def __init__(self, *args):
+ self.clients = self.fill_client_list(*args)
+
+ def fill_client_list(self, settings, database):
+ return []
+
+ def call_client(self, method, default, *args):
+ PlayoffLogger.get('resultinfo').info(
+ 'calling %s on result info clients', method)
+ for client in self.clients:
+ try:
+ ret = getattr(client, method)(*args)
+ PlayoffLogger.get('resultinfo').info(
+ '%s method returned %s', method, ret)
+ return ret
+ except Exception as e:
+ if type(e) in client.get_exceptions(method):
+ PlayoffLogger.get('resultinfo').warning(
+ '%s method raised %s(%s)',
+ method, type(e).__name__, str(e))
+ else:
+ raise
+ PlayoffLogger.get('resultinfo').info(
+ '%s method returning default: %s', method, default)
+ return default
+
+
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.tournamentinfo import TournamentInfo
-from jfr_playoff.logger import PlayoffLogger
class PlayoffData(object):
diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/matchinfo.py
index fad8155..9d48b57 100644
--- a/jfr_playoff/matchinfo.py
+++ b/jfr_playoff/matchinfo.py
@@ -4,10 +4,11 @@ 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 import ResultInfo
from jfr_playoff.tournamentinfo import TournamentInfo
from jfr_playoff.logger import PlayoffLogger
-class MatchInfo:
+class MatchInfo(ResultInfo):
matches = {}
@@ -20,10 +21,14 @@ class MatchInfo:
for team, team_aliases in aliases.iteritems():
for alias in team_aliases:
self.aliases[alias] = team
+ ResultInfo.__init__(self, match_config, database)
self.info = Match()
self.__init_info()
self.__fetch_match_link()
+ def fill_client_list(self, settings, database):
+ return []
+
def __init_info(self):
self.info.id = self.config['id']
MatchInfo.matches[self.info.id] = self.info
@@ -363,8 +368,8 @@ class MatchInfo:
pass
if boards_played > 0:
self.info.running = -1 \
- if boards_played >= boards_to_play \
- else boards_played
+ if boards_played >= boards_to_play \
+ else boards_played
def __determine_outcome(self):
if (self.info.teams[0].known_teams == 1) \
diff --git a/jfr_playoff/tournamentinfo/__init__.py b/jfr_playoff/tournamentinfo/__init__.py
index 67cc8f6..21cd62a 100644
--- a/jfr_playoff/tournamentinfo/__init__.py
+++ b/jfr_playoff/tournamentinfo/__init__.py
@@ -1,4 +1,5 @@
from jfr_playoff.logger import PlayoffLogger
+from jfr_playoff.data import ResultInfo
class TournamentInfoClient(object):
@@ -19,22 +20,26 @@ class TournamentInfoClient(object):
pass
-class TournamentInfo:
+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.tournamentinfo.jfrdb import JFRDbTournamentInfo
from jfr_playoff.tournamentinfo.jfrhtml import JFRHtmlTournamentInfo
from jfr_playoff.tournamentinfo.tcjson import TCJsonTournamentInfo
- self.clients = []
- if (database is not None) and ('database' in self.settings):
- self.clients.append(JFRDbTournamentInfo(settings, database))
- if 'link' in self.settings:
- if self.settings['link'].endswith('leaderb.html'):
- self.clients.append(JFRHtmlTournamentInfo(settings))
- self.clients.append(TCJsonTournamentInfo(settings))
+ 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', [])
+ teams = self.call_client('get_tournament_results', [])
if self.is_finished():
final_positions = self.settings.get('final_positions', [])
PlayoffLogger.get('tournamentinfo').info(
@@ -47,27 +52,7 @@ class TournamentInfo:
return teams
def is_finished(self):
- return self.__call_client('is_finished', True)
+ return self.call_client('is_finished', True)
def get_results_link(self, suffix='leaderb.html'):
- return self.__call_client('get_results_link', None, suffix)
-
- def __call_client(self, method, default, *args):
- PlayoffLogger.get('tournamentinfo').info(
- 'calling %s on tournament info clients', method)
- for client in self.clients:
- try:
- ret = getattr(client, method)(*args)
- PlayoffLogger.get('tournamentinfo').info(
- '%s method returned %s', method, ret)
- return ret
- except Exception as e:
- if type(e) in client.get_exceptions(method):
- PlayoffLogger.get('tournamentinfo').warning(
- '%s method raised %s(%s)',
- method, type(e).__name__, str(e))
- else:
- raise
- PlayoffLogger.get('tournamentinfo').info(
- '%s method returning default: %s', method, default)
- return default
+ return self.call_client('get_results_link', None, suffix)