diff --git a/Constants.py b/Constants.py new file mode 100644 index 0000000..3c25997 --- /dev/null +++ b/Constants.py @@ -0,0 +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 diff --git a/Scan.py b/Scan.py index b0fcb97..e954bb5 100644 --- a/Scan.py +++ b/Scan.py @@ -2,8 +2,7 @@ from pyzbar.pyzbar import ZBarSymbol from DataHandler import DataHandler from PIL import Image - -import sys +from Verify import Verify class Scan: def __init__(self, parser): @@ -11,6 +10,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 +24,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 diff --git a/TBA.py b/TBA.py index 357bf29..c27b787 100644 --- a/TBA.py +++ b/TBA.py @@ -22,6 +22,13 @@ def verify_team(self, match_number, match_type, alliance, team): return True return False + 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}") + if match_data.alliances[alliance]['score'] == score: + return True + return False + def get_match_score(self, match_number, match_type, alliance): match_data = self.tba.match(key=f"{self.event}_{match_type}m{match_number}") diff --git a/Verify.py b/Verify.py index accba7f..c8ce468 100644 --- a/Verify.py +++ b/Verify.py @@ -1,6 +1,37 @@ +import Constants + class Verify: def __init__(self): pass - def verify(self): - pass \ No newline at end of file + #TODO give better name + 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: + return False + return True + + def check_score_bounds(self, score): + if (Constants.SCORE_MIN > score) or (Constants.SCORE_MAX < score): + return False + return True + + # pretty much just copypaste but it's for readability + def match_isnumeric(self, matchno): + 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 + return True + + 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 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) 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