diff options
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | src/bcdd/PBNBoard.py | 4 | ||||
-rw-r--r-- | src/main.py | 24 |
3 files changed, 20 insertions, 9 deletions
@@ -40,6 +40,7 @@ As for `settings` section: * `pbn_round` is the round in PBN file for which the boards should be read (filtered by `[Round "X"]` fields) * `teamy_round` and `teamy_segment` point to the round and segment in JFR Teamy event database into which data is imported * `fetch_lineups` enables reading lineups from PBN files, strict comparison of full name + surname is conducted, and players have to be in correct Teamy rosters + * `lineup_board_no` specifies from which board lineups should be read, if not set, first board of the segment is taken; set to `0` to read from any board * `overwrite_scores` enables overwriting existing scores: otherwise, if a score in board points has changed in PBN from the one present in Teamy database, a warning is emitted * `info_messages` controls logging verbosity: 0 = warnings and errors, 1 = info messages, warnings and errors, 2 = debug output * `job_interval` is number of seconds between subsequent runs diff --git a/src/bcdd/PBNBoard.py b/src/bcdd/PBNBoard.py index e76252d..eb7ad2d 100644 --- a/src/bcdd/PBNBoard.py +++ b/src/bcdd/PBNBoard.py @@ -40,10 +40,12 @@ class PBNBoard(object): return True return False - def get_field(self, key): + def get_field(self, key, default=None): for field in self.fields: if key == field.key: return field.value + if default is not None: + return default raise FieldNotFoundException(key + ' field not found') def delete_field(self, key): diff --git a/src/main.py b/src/main.py index 32cd135..c4784e7 100644 --- a/src/main.py +++ b/src/main.py @@ -67,24 +67,32 @@ def get_round_lineup(db, round_no, segment_no): return round_lineup -def get_pbn_lineups(pbn, round_no): +def get_pbn_lineups(pbn, round_no, board_no=None): tables = {} for b in pbn.boards: if b.has_field('Round'): if b.get_field('Round') == str(round_no): - table = b.get_field('Table') - if table not in tables: - tables[table] = {} - tables[table][b.get_field('Room')] = [ - [b.get_field('North'), b.get_field('South')], - [b.get_field('East'), b.get_field('West')] + if not board_no or (str(board_no) == b.get_field('Board')): + table = b.get_field('Table') + if table not in tables: + tables[table] = {} + if board_no: + logging.info('Fetching lineups from board no %d, table %s %s', board_no, table, b.get_field('Room')) + tables[table][b.get_field('Room')] = [ + [b.get_field('North', ''), b.get_field('South', '')], + [b.get_field('East', ''), b.get_field('West', '')] ] return tables def fetch_lineups(pbn, db, settings): rosters = get_team_rosters(db) - tables = get_pbn_lineups(pbn, settings['pbn_round']) + lineup_board_no = settings.get('lineup_board_no', None) + if lineup_board_no is None: + board_mapping = get_board_mapping(db, settings['teamy_round'], settings['teamy_segment']) + lineup_board_no = list(board_mapping.keys())[list(board_mapping.values()).index(1)] + logging.info('No lineup board number specified in config, reverting to first board of segment: %d', lineup_board_no) + tables = get_pbn_lineups(pbn, settings['pbn_round'], lineup_board_no) round_lineup = get_round_lineup(db, settings['teamy_round'], settings['teamy_segment']) for t, rooms in tables.items(): |