Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Constants.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 6 additions & 3 deletions Scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
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):
self.qr_reader = QR()
self.data_handler = DataHandler()
self.parser = parser
self.args = self.parser.parse_args()
self.verify = None

def scan(self):
self.qr_reader.create_camera()
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions TBA.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
35 changes: 33 additions & 2 deletions Verify.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
import Constants

class Verify:
def __init__(self):
pass

def verify(self):
pass
#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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if A and B and C
  return True
return False

return A and B and C

Copy link
Copy Markdown

@andrewazores andrewazores Oct 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing generally applies to methods above, too. Just not ones that use exception handling, I guess.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh thanks for pointing that out, didn't think about using boolean operators in a return.

3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
4 changes: 0 additions & 4 deletions tba_test.py

This file was deleted.