Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_years function for adding new brackets #19

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
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
52 changes: 49 additions & 3 deletions bracketology/brackets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json
from schema import Schema, And, Use, Optional, SchemaError
from pkg_resources import resource_filename

filepath = resource_filename('bracketology', 'data/brackets.json')
with open(filepath, 'r') as f:
brackets_dict = json.load(f)
Expand Down Expand Up @@ -314,9 +316,9 @@ def __init__(self, year):
year : int
Year of the NCAA tournament
"""
valid_years = [y for y in range(1985, 2019+1)]
if year not in valid_years:
raise ValueError("Year must be between 1985 and 2019")
valid_years = brackets_dict.keys()
if year not in brackets_dict.keys():
raise ValueError(f"Year must be between {min(valid_years)} and {max(valid_years)}")

# Set year
self.year = str(year)
Expand Down Expand Up @@ -552,6 +554,50 @@ def score(self, sim_func=None, verbose=True):
print(f"Total Score: {self.total_score}/192")


def add_year(year: dict):
"""
Adds year dict to brackets_dict after validating schema

Parameters
----------
year : dictionary, schema validated as defined below
"""
year_schema = Schema({
# Year
str : {
"Region": {
# East, West, Midwest, South
str: [{
"Team": str,
"Seed": int
}]
},
Optional("Results"): {
# Rounds
str: [{
"Team": str,
"Seed": int
}]
},
Optional("Finals"): {
"game1": {
# Regions: Midwest, South
"team1": str,
"team2": str
},
"game2": {
# Regions: West, East
"team1": str,
"team2": str
}
}

}
})

year_schema.validate(year)

brackets_dict.update()



Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
schema~=0.7.5