def bracket_response_json(bracket_id): with session_scope() as session: bracket = session.query(Bracket).filter( Bracket.id == bracket_id).first() picked_matchups = (session.query(BracketMatchup).filter( BracketMatchup.bracket_id == bracket_id, BracketMatchup.winner_id != None, ).all()) available_matchups = (session.query(BracketMatchup).filter( BracketMatchup.bracket_id == bracket_id, BracketMatchup.team1_id != None, BracketMatchup.team2_id != None, BracketMatchup.winner_id == None, ).all()) unavailable_matchups = (session.query(BracketMatchup).filter( BracketMatchup.bracket_id == bracket_id, or_(BracketMatchup.team1_id == None, BracketMatchup.team2_id == None), ).all()) return { **bracket.to_dict(), "picked_matchups": [matchup.to_dict() for matchup in picked_matchups], "available_matchups": [matchup.to_dict() for matchup in available_matchups], "unavailable_matchups": [matchup.to_dict() for matchup in unavailable_matchups], }
def get(self, bracket_matchup_id): with session_scope() as session: bracket_matchup, bracket = get_bracket_matchup_bracket( session, bracket_matchup_id) if bracket is None or bracket_matchup is None: return None, 404 return bracket_matchup_response_json(session, bracket_matchup, bracket), 200
def __call__(self, environ, start_response): request = Request(environ) # hardcode this for now if True: with session_scope() as session: user = session.query(User).filter( User.email == "*****@*****.**").first() environ["user"] = user.to_dict() return self.app(environ, start_response) res = Response(u"Authorization failed", mimetype="text/plain", status=401) return res(environ, start_response)
def patch(self, bracket_matchup_id): with session_scope() as session: bracket_matchup, bracket = get_bracket_matchup_bracket( session, bracket_matchup_id) if bracket is None or bracket_matchup is None: return None, 404 parser = reqparse.RequestParser() parser.add_argument("winner_id", type=str) parser.add_argument("notes", type=str) parser.add_argument("confidence", type=int) args = parser.parse_args() winner_id = args["winner_id"] notes = args.get("notes", "") confidence = args.get("confidence", None) try: set_bracket_matchup_winner(session, bracket_matchup, winner_id, notes, confidence) except BracketWinnerError as e: return {"message": e.message}, 400 return bracket_matchup_response_json(session, bracket_matchup, bracket), 200
tournament_file = "ncaa_mens_2021_bracket.json" tournament_file_data = open(tournament_file_dir / tournament_file, "r") tournament_data = json.load(tournament_file_data) averages_file = ( base_path / "scripts/kenpom_scraping/averages_data" / "averages_2021.json" ) averages_file_data = open(averages_file, "r") averages_data = json.load(averages_file_data) teams_file = base_path / "scripts/kenpom_scraping/teams_data" / "teams_2021.json" teams_file_data = open(teams_file, "r") team_stats_data = json.load(teams_file_data) bracket_info = tournament_data["bracket"] with session_scope() as session: tournament = ( session.query(Tournament.id) .filter(Tournament.tournament_name == tournament_data["name"]) .first() ) for team_info in bracket_info: pos = team_info["pos"] region = get_region(get_pos_round(pos), get_pos_game_number(pos)) seed = team_info["seed"] team_name = team_info["team"] team_stats = team_stats_data["data"][team_name] team = session.query(Team).filter(Team.name == team_name).first() tournament_team = (
def get(self): user_id = request.environ["user"]["id"] with session_scope() as session: brackets = session.query(Bracket).filter( Bracket.user_id == user_id).all() return [bracket.to_dict() for bracket in brackets]