summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2019-02-23 17:20:07 +0100
committeremkael <emkael@tlen.pl>2019-02-23 17:20:07 +0100
commitdd7902ef7b46f598973cf85541d2e5f63ec2943d (patch)
tree21bc8a68463cac933805cfa7db888f08e421593d
parent0bf3209ac695379ad0e3ebc3f52a19b226fa73ba (diff)
Team name aliases
Fixes #32
-rw-r--r--CONFIG.md18
-rw-r--r--jfr_playoff/data.py5
-rw-r--r--jfr_playoff/matchinfo.py23
3 files changed, 40 insertions, 6 deletions
diff --git a/CONFIG.md b/CONFIG.md
index 102edb2..5492fbe 100644
--- a/CONFIG.md
+++ b/CONFIG.md
@@ -104,6 +104,24 @@ Miejsca w tabeli końcowej dla drużyn zdefiniowanych jako kończące rozgrywki
Program nie potrafi ich rozstrzygać samodzielnie remisów podczas pobierania wyników z bazy danych. Dla listy teamów pobranej ze strony wyników, zachowana jest kolejność na stronie (więc remisy rozstrzygnięte przez Teamy przed wygenerowaniem wyników).
+Ustawienia teamów - aliasy
+--------------------------
+
+Jeśli zdarzy się, że w jakichś meczach, pobieranych ze stron WWW lub bazy danych, pełna nazwa teamu nie zgadza się z nazwą zefiniowaną na liście teamów, nazwy takie można zmapować na właściwe nazwy teamów.
+
+Służy do tego sekcja `"team_aliases"`, będąca słownikiem, w którym:
+ - kluczami są docelowe (tj. obecne w liście teamów) pełne nazwy teamów
+ - wartościami są tablice nazw, które mają być mapowane na daną właściwą nazwę
+
+Na przykład:
+
+```
+"team_aliases": {
+ "SYNERGIA Lublin": ["Synergia Lublin", "Synergia", "SYNERGIA", "SYNERGIA Lublin", "SYNERGIA Lublin "]
+}
+```
+
+Wszystkie zdefiniowane w takim słowniku nazwy teamów będą rozpoznawane jako właściwe nazwy, obecne w liście teamów.
Ustawienia stylów klasyfikacji końcowej
---------------------------------------
diff --git a/jfr_playoff/data.py b/jfr_playoff/data.py
index 6adf00c..723a38d 100644
--- a/jfr_playoff/data.py
+++ b/jfr_playoff/data.py
@@ -17,6 +17,9 @@ class PlayoffData(object):
self.swiss = []
if settings.has_section('swiss'):
self.swiss = settings.get('swiss')
+ self.aliases = {}
+ if settings.has_section('team_aliases'):
+ self.aliases = settings.get('team_aliases')
self.grid = []
self.match_info = {}
self.leaderboard = []
@@ -56,7 +59,7 @@ class PlayoffData(object):
self.match_info = {}
for phase in self.phases:
for match in phase['matches']:
- match_info = MatchInfo(match, self.teams, self.database)
+ match_info = MatchInfo(match, self.teams, self.database, self.aliases)
if 'link' in phase:
match_info.set_phase_link(phase['link'])
self.match_info[match['id']] = match_info.get_info()
diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/matchinfo.py
index b1fae4f..fad8155 100644
--- a/jfr_playoff/matchinfo.py
+++ b/jfr_playoff/matchinfo.py
@@ -11,10 +11,15 @@ class MatchInfo:
matches = {}
- def __init__(self, match_config, teams, database):
+ def __init__(self, match_config, teams, database, aliases=None):
self.config = match_config
self.teams = teams
self.database = database
+ self.aliases = {}
+ if aliases:
+ for team, team_aliases in aliases.iteritems():
+ for alias in team_aliases:
+ self.aliases[alias] = team
self.info = Match()
self.__init_info()
self.__fetch_match_link()
@@ -164,9 +169,9 @@ class MatchInfo:
match_teams = []
possible_teams = []
if isinstance(self.config['teams'][i], basestring):
- teams[i].name = [self.config['teams'][i]]
+ match_teams = [self.config['teams'][i]]
elif isinstance(self.config['teams'][i], list):
- teams[i].name = self.config['teams'][i]
+ match_teams = self.config['teams'][i]
else:
if 'winner' in self.config['teams'][i]:
match_teams += [
@@ -195,6 +200,9 @@ class MatchInfo:
self.info.id, teams)
return teams
+ def __resolve_team_aliases(self, teams):
+ return [self.aliases[team] if team in self.aliases else team for team in teams]
+
def __fetch_teams_with_scores(self):
(scores_fetched, teams_fetched, self.info.teams) = self.__get_predefined_scores()
if scores_fetched:
@@ -222,8 +230,13 @@ class MatchInfo:
self.info.id, type(e).__name__, str(e))
self.info.teams = self.__get_config_teams(self.info.teams)
for team in range(0, len(self.info.teams)):
- self.info.teams[team].place = self.config['teams'][team].get(
- 'place', self.info.teams[team].place)
+ if isinstance(self.config['teams'][team], dict):
+ self.info.teams[team].place = self.config['teams'][team].get(
+ 'place', self.info.teams[team].place)
+ self.info.teams[team].name = self.__resolve_team_aliases(self.info.teams[team].name)
+ PlayoffLogger.get('matchinfo').info('team list after resolving aliases: %s', self.info.teams[team].name)
+ self.info.teams[team].possible_name = self.__resolve_team_aliases(self.info.teams[team].possible_name)
+ PlayoffLogger.get('matchinfo').info('predicted team list after resolving aliases: %s', self.info.teams[team].possible_name)
def __get_db_board_count(self):