summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Klichowicz <emkael@tlen.pl>2023-10-02 22:54:02 +0200
committerMichał Klichowicz <emkael@tlen.pl>2023-10-02 22:55:17 +0200
commit68a3ee5d9f95bdf0b9941a5c1f9075dbda5852be (patch)
tree41f0f9820f38b5e884cbbb6e5669c104fc1e8a32
parentfc7daf999673acd328e2f5a1224639983341266c (diff)
Safety checks if PBN fields exists
-rw-r--r--src/main.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/main.py b/src/main.py
index d811095..f94f064 100644
--- a/src/main.py
+++ b/src/main.py
@@ -144,12 +144,15 @@ def get_current_db_score(db, round_no, segment_no, table, room, board_no):
def get_pbn_score(b):
- declarer = b.get_field('Declarer')
- contract = b.get_field('Contract').replace('*', ' x').replace('x x', 'xx')
+ contract = b.get_field('Contract').replace('*', ' x').replace('x x', 'xx') if b.has_field('Contract') else ''
+ if not contract:
+ return None, None, None, None, None
+ declarer = b.get_field('Declarer') if b.has_field('Declarer') else ''
+ lead = ''
if contract[0].isdigit():
contract = contract[0] + ' ' + contract[1:]
- result = int(b.get_field('Result')) - get_digits(contract) - 6
- score = int(b.get_field('Score').replace('NS ', '')) # co z pasami?
+ result = int(b.get_field('Result')) - get_digits(contract) - 6 if b.has_field('Result') else ''
+ score = int(b.get_field('Score').replace('NS ', '')) if b.has_field('Score') else '' # a co z pasami?
play_data = b.get_play_data()
if play_data:
play_data = ' '.join(play_data).split(' ')
@@ -170,11 +173,16 @@ def update_score(db, pbn_board, round_no, segment_no, table, room, board_no, rea
current_score = get_current_db_score(db, round_no, segment_no, table, room, board_no)
declarer, contract, result, score, lead = get_pbn_score(pbn_board)
+ if contract is None:
+ logging.info('no contract yet in board %d, table %d-%d',
+ real_board_no, table, room)
+ return
+
update_score = True
- if current_score[4] is not None:
- if not overwrite:
+ if current_score[4] or current_score == 0: # there's a score, so the result was already fully imported
+ if not overwrite: # we need to check if we should overwrite the score, if not
update_score = False
- if score != current_score[4]:
+ if score != current_score[4]: # then emit a warning if it's changed
logging.warning('result in board %d, table %d-%d changed and is NOT going to be overwritten!',
real_board_no, table, room)
else: