def search(): # check if logged in w/ google if not google_auth.is_logged_in(): return(redirect(url_for("google_auth.login"))) form = TeamSearchForm(request.form) # if POST request, validate form and redirect to info route w/ team # if form.validate(): team_number = form.team_number.data return(redirect(url_for("team.profile", team_number=team_number)))
def match(match_number): # check if logged in w/ google if not google_auth.is_logged_in(): return (redirect(url_for("google_auth.login"))) form = TeamSearchForm() match = Match.query.filter_by(match=match_number).join(MatchReport).first() return (render_template("match_scout/match.html", match=match, form=form))
def all_stats(): # check if logged in w/ google if not google_auth.is_logged_in(): return (redirect(url_for("google_auth.login"))) form = TeamSearchForm(request.form) teams = Team.query.join(TeamStats).all() return (render_template("stats/all_stats.html", form=form, teams=teams))
def all_matches(): # check if logged in w/ google if not google_auth.is_logged_in(): return (redirect(url_for("google_auth.login"))) form = TeamSearchForm() matches = Match.query.order_by(Match.match).join(MatchReport).all() return (render_template("match_scout/all_matches.html", matches=matches, form=form))
def all_reports(): # check if logged in w/ google if not google_auth.is_logged_in(): return (redirect(url_for("google_auth.login"))) form = TeamSearchForm() teams = Team.query.order_by(Team.team_number).join(PitReport).all() return (render_template("pit_scout/all_reports.html", teams=teams, form=form))
def display_suggestions(): form = TeamSearchForm() alliance_suggestions_1 = AllianceSuggestion.query.filter( AllianceSuggestion.pick_number == 1).all() alliance_suggestions_2 = AllianceSuggestion.query.filter( AllianceSuggestion.pick_number == 2).all() return (render_template("/alliance_suggestions/display_suggestions.html", form=form, alliance_suggestions_1=alliance_suggestions_1, alliance_suggestions_2=alliance_suggestions_2))
def pit_report(team_number): # check if logged in w/ google if not google_auth.is_logged_in(): return (redirect(url_for("google_auth.login"))) form = TeamSearchForm() team = Team.query.filter_by(team_number=team_number).first() pit_reports = PitReport.query.filter_by(team_id=team.id).all() return (render_template("pit_scout/pit_report.html", pit_reports=pit_reports, team_number=team_number, form=form))
def display_bookmarks(): # check if logged in w/ google if not google_auth.is_logged_in(): return (redirect(url_for("google_auth.login"))) form = TeamSearchForm() user_info = google_auth.get_user_info() user = User.query.filter(User.user_id == user_info["id"]).first() all_bookmarks = Bookmark.query.filter( db.not_(Bookmark.user_id == user.id)).join(User).all() user_bookmarks = Bookmark.query.filter( Bookmark.user_id == user.id).join(User).all() return (render_template("bookmarks/display_bookmarks.html", all_bookmarks=all_bookmarks, user_bookmarks=user_bookmarks, form=form))
def profile(team_number): # check if logged in w/ google if not google_auth.is_logged_in(): return(redirect(url_for("google_auth.login"))) form = TeamSearchForm() # get team team = Team.query.filter_by(team_number=team_number).first() # get bookmark bookmark = Bookmark.query.filter(Bookmark.team_number == team_number).first() # get team info from TBA API response = requests.get(f"https://www.thebluealliance.com/api/v3/team/frc{team_number}", headers={"X-TBA-Auth-Key": TBA_AUTH_KEY}) team_info = response.json() # get events from TBA API response = requests.get(f"https://www.thebluealliance.com/api/v3/team/frc{team_number}/events/2020", headers={"X-TBA-Auth-Key": TBA_AUTH_KEY}) events = response.json() # get event statuses from TBA API response = requests.get(f"https://www.thebluealliance.com/api/v3/team/frc{team_number}/events/2020/statuses", headers={"X-TBA-Auth-Key": TBA_AUTH_KEY}) event_statuses = response.json() # get OPRs (OPR, DPR, CCWM) from TBA API oprs = {} for event in event_statuses: response = requests.get(f"https://www.thebluealliance.com/api/v3/event/{event}/oprs", headers={"X-TBA-Auth-Key": TBA_AUTH_KEY}) response = response.json() oprs[event] = response # get district from TBA API response = requests.get(f"https://www.thebluealliance.com/api/v3/team/frc{team_number}/districts", headers={"X-TBA-Auth-Key": TBA_AUTH_KEY}) response = response.json() if response: district = response[len(response) - 1] else: district = None # get district ranking from TBA API if district: response = requests.get(f"https://www.thebluealliance.com/api/v3/district/{district.get('key')}/rankings", headers={"X-TBA-Auth-Key": TBA_AUTH_KEY}) response = response.json() district_ranking = list(filter(lambda x:x["team_key"]==f"frc{team_number}", response)) else: district_ranking = None if team: # get alliance suggestion 1st pick alliance_suggestion_1 = AllianceSuggestion.query.filter(AllianceSuggestion.team_id == team.id, AllianceSuggestion.pick_number == 1).first() # get alliance suggestion 2nd pick alliance_suggestion_2 = AllianceSuggestion.query.filter(AllianceSuggestion.team_id == team.id, AllianceSuggestion.pick_number == 2).first() match_reports = MatchReport.query.filter_by(team_id=team.id).join(Match).all() team_stats = TeamStats.query.filter_by(team_id=team.id).first() pit_reports = PitReport.query.filter_by(team_id=team.id).all() team_photos = TeamPhoto.query.filter_by(team_id=team.id).all() else: alliance_suggestion_1 = None alliance_suggestion_2 = None match_reports = None team_stats = None pit_reports = None team_photos = None return(render_template("team/profile.html", team_number=team_number, match_reports=match_reports, team_stats=team_stats, team_photos=team_photos, pit_reports=pit_reports, team_info=team_info, event_statuses=event_statuses, form=form, bookmark=bookmark, events=events, district=district, district_ranking=district_ranking, oprs=oprs, alliance_suggestion_1=alliance_suggestion_1, alliance_suggestion_2=alliance_suggestion_2))