From 0af543a6cf79df3a8157da75fb3874d2c4e737eb Mon Sep 17 00:00:00 2001 From: David Drobner Date: Tue, 15 Sep 2020 20:19:10 -0400 Subject: [PATCH 01/17] Added method to get score from TBA API --- TBA.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/TBA.py b/TBA.py index 357bf29..e7d2064 100644 --- a/TBA.py +++ b/TBA.py @@ -22,6 +22,11 @@ def verify_team(self, match_number, match_type, alliance, team): return True return False + def verify_score(self, match_number, match_type, alliance): + # Verifies the score of a given alliance in a match + match_data = self.tba.match(key=f"{self.event}_{match_type}m{match_number}") + return match_data.alliances[alliance]['score'] + def get_match_score(self, match_number, match_type, alliance): match_data = self.tba.match(key=f"{self.event}_{match_type}m{match_number}") From ae6c524ae1713547dc501bcc22ada26c710e4dc5 Mon Sep 17 00:00:00 2001 From: David Drobner Date: Tue, 15 Sep 2020 20:19:39 -0400 Subject: [PATCH 02/17] Removed TBA test file --- tba_test.py | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 tba_test.py diff --git a/tba_test.py b/tba_test.py deleted file mode 100644 index d821fd0..0000000 --- a/tba_test.py +++ /dev/null @@ -1,4 +0,0 @@ -from TBA import TBA - -tba = TBA('2020onosh') -print(tba.verify_team(4, "q", "red", 8081)) \ No newline at end of file From 590069d21b70c645a86989d36efe803bcc641bd9 Mon Sep 17 00:00:00 2001 From: David Drobner Date: Tue, 15 Sep 2020 20:42:18 -0400 Subject: [PATCH 03/17] Return boolean from verify_score instead of the actual score --- TBA.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/TBA.py b/TBA.py index e7d2064..c27b787 100644 --- a/TBA.py +++ b/TBA.py @@ -22,10 +22,12 @@ def verify_team(self, match_number, match_type, alliance, team): return True return False - def verify_score(self, match_number, match_type, alliance): + def verify_score(self, match_number, match_type, alliance, score): # Verifies the score of a given alliance in a match match_data = self.tba.match(key=f"{self.event}_{match_type}m{match_number}") - return match_data.alliances[alliance]['score'] + if match_data.alliances[alliance]['score'] == score: + return True + return False def get_match_score(self, match_number, match_type, alliance): From 1f2b7569f97872cc5c157a0a28ef80e335cb3f28 Mon Sep 17 00:00:00 2001 From: David Drobner Date: Tue, 15 Sep 2020 20:52:19 -0400 Subject: [PATCH 04/17] Renamed verify to verify_offline to separate the functionality of the two --- Verify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Verify.py b/Verify.py index accba7f..99ac494 100644 --- a/Verify.py +++ b/Verify.py @@ -2,5 +2,5 @@ class Verify: def __init__(self): pass - def verify(self): + def verify_offline(self): pass \ No newline at end of file From 8cd5fec906069252c2813b5eb95c069a83a0c1b1 Mon Sep 17 00:00:00 2001 From: David Drobner Date: Tue, 15 Sep 2020 20:58:28 -0400 Subject: [PATCH 05/17] Added method to check if score is numeric --- Verify.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Verify.py b/Verify.py index 99ac494..253859d 100644 --- a/Verify.py +++ b/Verify.py @@ -2,5 +2,12 @@ class Verify: def __init__(self): pass + def check_if_score_is_numeric(self, score): + try: + int(score) + except ValueError: + return False + return True + def verify_offline(self): pass \ No newline at end of file From defcadfe6ade6dbadb3edde5bbbe443dc907a68d Mon Sep 17 00:00:00 2001 From: David Drobner Date: Sat, 3 Oct 2020 16:19:12 -0400 Subject: [PATCH 06/17] Added comment to remind for later cleanup --- Verify.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Verify.py b/Verify.py index 253859d..c4658a4 100644 --- a/Verify.py +++ b/Verify.py @@ -2,6 +2,7 @@ class Verify: def __init__(self): pass + #TODO give better name def check_if_score_is_numeric(self, score): try: int(score) From 6b59804840d0d8ce73c3673506c46a366713ae48 Mon Sep 17 00:00:00 2001 From: David Drobner Date: Sat, 3 Oct 2020 16:19:43 -0400 Subject: [PATCH 07/17] ^^ --- main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.py b/main.py index d8a9c95..f86e278 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,9 @@ import argparse from GUI import Odin + +# TODO give source directory some structure + parser = argparse.ArgumentParser() parser.add_argument('--image', type=str) From 67fc3103819d3e86d0d2dc3089c42a78024ba5a9 Mon Sep 17 00:00:00 2001 From: David Drobner Date: Sat, 3 Oct 2020 16:27:31 -0400 Subject: [PATCH 08/17] Created constants file --- Constants.py | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Constants.py diff --git a/Constants.py b/Constants.py new file mode 100644 index 0000000..8cc6116 --- /dev/null +++ b/Constants.py @@ -0,0 +1,2 @@ +SCORE_MIN = 0 +SCORE_MAX = 250 From 5aeadf8e79829bb4e388311c3915a2bf72f5dfc4 Mon Sep 17 00:00:00 2001 From: David Drobner Date: Sat, 3 Oct 2020 16:27:42 -0400 Subject: [PATCH 09/17] Added method to check if score is within acceptable bounds --- Verify.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Verify.py b/Verify.py index c4658a4..7707be4 100644 --- a/Verify.py +++ b/Verify.py @@ -1,3 +1,5 @@ +import Constants + class Verify: def __init__(self): pass @@ -10,5 +12,10 @@ def check_if_score_is_numeric(self, score): return False return True + def check_score_bounds(self, score): + if (Constants.SCORE_MIN < score) or (Constants.SCORE_MAX < score): + return False + return True + def verify_offline(self): pass \ No newline at end of file From fc69da9231ea03bdf5ada95593ed2b90af4ac6ec Mon Sep 17 00:00:00 2001 From: David Drobner Date: Sat, 3 Oct 2020 16:31:20 -0400 Subject: [PATCH 10/17] Correct wrong comparison in score bounds check --- Verify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Verify.py b/Verify.py index 7707be4..44652e4 100644 --- a/Verify.py +++ b/Verify.py @@ -13,7 +13,7 @@ def check_if_score_is_numeric(self, score): return True def check_score_bounds(self, score): - if (Constants.SCORE_MIN < score) or (Constants.SCORE_MAX < score): + if (Constants.SCORE_MIN > score) or (Constants.SCORE_MAX < score): return False return True From 8ba6c1b3c7892cb9edf9b05e5972d0fa2c173708 Mon Sep 17 00:00:00 2001 From: David Drobner Date: Sat, 3 Oct 2020 16:35:29 -0400 Subject: [PATCH 11/17] Renamed the check for if score is an int --- Verify.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Verify.py b/Verify.py index 44652e4..294602f 100644 --- a/Verify.py +++ b/Verify.py @@ -5,7 +5,8 @@ def __init__(self): pass #TODO give better name - def check_if_score_is_numeric(self, score): + def score_isnumeric(self, score): + # Could use isnumeric() here, but it will throw an error if score is an integer try: int(score) except ValueError: From 1dab4ad71f13c28c2435d62b6d50d6b7208c9758 Mon Sep 17 00:00:00 2001 From: David Drobner Date: Sat, 3 Oct 2020 16:40:21 -0400 Subject: [PATCH 12/17] Added match bounds to constants --- Constants.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Constants.py b/Constants.py index 8cc6116..3c25997 100644 --- a/Constants.py +++ b/Constants.py @@ -1,2 +1,6 @@ SCORE_MIN = 0 SCORE_MAX = 250 +#TODO determine if match can be numbered 0 +MATCH_MIN = 1 +#TODO check if there are any super large events with >200 matches in Q +MATCH_MAX = 200 From 745b59e2074974a42cf208ed72bcbadb35bec15f Mon Sep 17 00:00:00 2001 From: David Drobner Date: Sat, 3 Oct 2020 16:47:44 -0400 Subject: [PATCH 13/17] Added method to check match bounds --- Verify.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Verify.py b/Verify.py index 294602f..cfcbdce 100644 --- a/Verify.py +++ b/Verify.py @@ -18,5 +18,10 @@ def check_score_bounds(self, score): return False return True + def check_match_bounds(self, matchno): + if (Constants.MATCH_MIN > matchno) or (Constants.MATCH_MAX < matchno): + return False + return True + def verify_offline(self): pass \ No newline at end of file From 0ad11471df8d3b07d950f97094d50f0efb28fc06 Mon Sep 17 00:00:00 2001 From: David Drobner Date: Sat, 3 Oct 2020 17:36:31 -0400 Subject: [PATCH 14/17] Added method to check if match number is numeric --- Verify.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Verify.py b/Verify.py index cfcbdce..0834900 100644 --- a/Verify.py +++ b/Verify.py @@ -18,6 +18,14 @@ def check_score_bounds(self, score): return False return True + # pretty much just copypaste but it's for readability + def match_isnumeric(self, match): + try: + int(match) + except ValueError: + return False + return True + def check_match_bounds(self, matchno): if (Constants.MATCH_MIN > matchno) or (Constants.MATCH_MAX < matchno): return False From 390f6b286fb3c6f7313b134f5029feccf9e033e1 Mon Sep 17 00:00:00 2001 From: David Drobner Date: Sat, 3 Oct 2020 17:38:48 -0400 Subject: [PATCH 15/17] Fleshed out verify_offline method --- Verify.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Verify.py b/Verify.py index 0834900..c8ce468 100644 --- a/Verify.py +++ b/Verify.py @@ -19,7 +19,7 @@ def check_score_bounds(self, score): return True # pretty much just copypaste but it's for readability - def match_isnumeric(self, match): + def match_isnumeric(self, matchno): try: int(match) except ValueError: @@ -31,5 +31,7 @@ def check_match_bounds(self, matchno): return False return True - def verify_offline(self): - pass \ No newline at end of file + def verify_offline(self, score, matchno): + if self.score_isnumeric(score) and self.check_score_bounds(score) and self.match_isnumeric(matchno) and self.check_match_bounds(matchno): + return True + return False \ No newline at end of file From 95426b7ac6a7cf37a6358fa9dbbd5148f70a82f1 Mon Sep 17 00:00:00 2001 From: David Drobner Date: Sat, 3 Oct 2020 17:46:29 -0400 Subject: [PATCH 16/17] Added verification to when the data is written --- Scan.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Scan.py b/Scan.py index b0fcb97..8868fbe 100644 --- a/Scan.py +++ b/Scan.py @@ -2,6 +2,7 @@ from pyzbar.pyzbar import ZBarSymbol from DataHandler import DataHandler from PIL import Image +from Verify import Verify import sys @@ -11,6 +12,7 @@ def __init__(self, parser): self.data_handler = DataHandler() self.parser = parser self.args = self.parser.parse_args() + self.verify = None def scan(self): self.qr_reader.create_camera() @@ -24,7 +26,10 @@ def scan(self): if data: # TODO Refactor, design is iffy yaml_data = self.data_handler.readData(data) - self.data_handler.writeData(yaml_data) + # TODO add match score to the scouting app lol + self.verify = Verify(yaml_data['_score'], yaml_data['Match Number']) + if self.verify.verify_offline(): + self.data_handler.writeData(yaml_data) # I remember there being some reason why I didn't use a break here # Either it didn't work or readability scanned = True From 2d22ceb9ee8de60a8b1bd1a575380dd59268910f Mon Sep 17 00:00:00 2001 From: David Drobner Date: Sat, 3 Oct 2020 17:48:39 -0400 Subject: [PATCH 17/17] Remove unused sys import from Scan.py --- Scan.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Scan.py b/Scan.py index 8868fbe..e954bb5 100644 --- a/Scan.py +++ b/Scan.py @@ -4,8 +4,6 @@ from PIL import Image from Verify import Verify -import sys - class Scan: def __init__(self, parser): self.qr_reader = QR()