From 62f72396ca28ff8db5a117d4f2ab8e3b40297462 Mon Sep 17 00:00:00 2001 From: Justin Hsieh <41461549+justin-hsieh@users.noreply.github.com> Date: Thu, 9 Nov 2023 13:22:33 -0700 Subject: [PATCH] set up firebase and data loading --- app.py | 40 ++- db.ipynb | 263 ++++++++++++++++-- .../espn_api/base_league.py | 26 +- .../espn_api/football/team.py | 37 ++- fantasy_app/functions.py | 8 +- key.json | 13 - results.json | 158 +++++++++++ results1.json | 177 ++++++++++++ 8 files changed, 656 insertions(+), 66 deletions(-) delete mode 100644 key.json create mode 100644 results.json create mode 100644 results1.json diff --git a/app.py b/app.py index ade57eb..2587ae5 100644 --- a/app.py +++ b/app.py @@ -1,17 +1,24 @@ # Third-party imports from flask import Flask, jsonify, request import json - -from flask_cors import CORS, cross_origin +from dotenv import load_dotenv +import os +from flask_cors import CORS # from decouple import config from fantasy_app.functions import get_current_matchups, current_week, get_most_position_points, order_positions_by_points from fantasy_app.contest_list import contests import firebase_admin from firebase_admin import credentials, db +load_dotenv() +DATABASE_URL = os.getenv('DATABASE_URL') +CREDS = os.getenv('CREDS') -cred = credentials.Certificate("./key.json") -firebase_admin.initialize_app(cred) +cred = credentials.Certificate(CREDS) +if not firebase_admin._apps: + firebase_admin.initialize_app(cred, { + 'databaseURL': DATABASE_URL + }) # app.config['SQLALCHEMY_DATABASE_URI'] = config('DATABASE_URL') @@ -31,10 +38,6 @@ def hello1(): @app.route('/test_submodule', methods=['GET']) def submodule(): matchups = get_current_matchups() - for matchup_index, matchup in enumerate(matchups): - away = matchup.away_lineup - for player_index, player in enumerate(away): - team = matchup.away_team.team_name return jsonify(str(matchups)) @@ -63,18 +66,29 @@ def highest_score(): @app.route('/most_points_get', methods=['GET']) def calculate_most_points_get(): + contest_dict = {} stat = 'total_lb_points' points = get_most_position_points( contests[stat]['position_list'], current_week()-1) - ranks = order_positions_by_points(points) - return jsonify(ranks) + contest_dict['contest_results'] = order_positions_by_points(points) + contest_dict['contest'] = stat + return jsonify(contest_dict) @app.route('/most_points_post', methods=['POST']) def calculate_most_points_post(): + output_dict = {} + contest_dict = {} point_request = request.get_json() stat = point_request['contest'] + week = point_request['week'] + year = point_request['year'] points = get_most_position_points( - contests[stat]['position_list'], current_week()) - ranks = order_positions_by_points(points) - return jsonify(ranks) + contests[stat]['position_list'], week) + contest_dict['contest_results'] = order_positions_by_points(points) + contest_dict['contest'] = stat + output_week = "week_" + str(week) + output_dict[output_week] = contest_dict + ref = db.reference("/" + str(year)) + ref.push(output_dict) + return '{"status":"200", "data": "OK"}' diff --git a/db.ipynb b/db.ipynb index e9ec329..0ae9a20 100644 --- a/db.ipynb +++ b/db.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 15, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -16,14 +16,37 @@ "metadata": {}, "outputs": [], "source": [ - "firebase_admin.delete_app(firebase_admin.get_app())" + "#firebase_admin.delete_app(firebase_admin.get_app())" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, "outputs": [], + "source": [ + "from dotenv import load_dotenv\n", + "import os\n", + "load_dotenv()\n", + "DATABASE_URL = os.getenv('DATABASE_URL')" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "cred = credentials.Certificate(\"key.json\")\n", "firebase_admin.initialize_app(cred, {\"databaseURL\": \"https://fantasy-contests-default-rtdb.firebaseio.com/\"})" @@ -31,7 +54,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -43,34 +66,98 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "firebase_admin.get_app()" ] }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ - "ref = db.reference(\"/\")" + "ref = db.reference(\"/2023\")" ] }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'name': 'JJ'}" + "{'Week': 3,\n", + " 'contest': 'Most LB Points',\n", + " 'contest_results': [{'player1': {'game_played': 100,\n", + " 'name': 'Foyesade Oluokun',\n", + " 'score': 39.1},\n", + " 'player2': {'game_played': 100, 'name': 'Ernest Jones', 'score': 6.7},\n", + " 'rank': 1,\n", + " 'team': 'Lets Get Weird 🐸',\n", + " 'total_score': 45.800000000000004},\n", + " {'player1': {'game_played': 100, 'name': 'Bobby Okereke', 'score': 17.2},\n", + " 'player2': {'game_played': 100, 'name': 'Tremaine Edmunds', 'score': 20.6},\n", + " 'rank': 2,\n", + " 'team': 'You Hate to See That',\n", + " 'total_score': 37.8},\n", + " {'player1': {'game_played': 100, 'name': 'Bobby Wagner', 'score': 11.7},\n", + " 'player2': {'game_played': 100, 'name': 'Fred Warner', 'score': 22.4},\n", + " 'rank': 3,\n", + " 'team': 'Ma heart Mahomes',\n", + " 'total_score': 34.099999999999994},\n", + " {'player1': {'game_played': 100, 'name': 'Kyzir White', 'score': 12.4},\n", + " 'player2': {'game_played': 100, 'name': 'Devin Lloyd', 'score': 17.6},\n", + " 'rank': 4,\n", + " 'team': \"You're being a Kyren\",\n", + " 'total_score': 30.0},\n", + " {'player1': {'game_played': 100, 'name': 'Roquan Smith', 'score': 12.3},\n", + " 'player2': {'game_played': 100, 'name': 'Alex Singleton', 'score': 16.9},\n", + " 'rank': 5,\n", + " 'team': 'Maxxy Pats',\n", + " 'total_score': 29.2},\n", + " {'player1': {'game_played': 100, 'name': 'Jordan Hicks', 'score': 14.0},\n", + " 'player2': {'game_played': 100, 'name': 'Dre Greenlaw', 'score': 13.4},\n", + " 'rank': 6,\n", + " 'team': 'Baby got Dak',\n", + " 'total_score': 27.4},\n", + " {'player1': {'game_played': 100, 'name': 'Terrel Bernard', 'score': 22.8},\n", + " 'player2': {'game_played': 100, 'name': 'Cody Barton', 'score': 1.4},\n", + " 'rank': 7,\n", + " 'team': 'I h8 justin',\n", + " 'total_score': 24.2},\n", + " {'player1': {'game_played': 100, 'name': 'Zaire Franklin', 'score': 14.8},\n", + " 'player2': {'game_played': 100, 'name': 'Patrick Queen', 'score': 7.0},\n", + " 'rank': 8,\n", + " 'team': '- CircleKirk',\n", + " 'total_score': 21.8},\n", + " {'player1': {'game_played': 100, 'name': 'Quay Walker', 'score': 10.7},\n", + " 'player2': {'game_played': 100, 'name': 'Robert Spillane', 'score': 10.3},\n", + " 'rank': 9,\n", + " 'team': 'Justys Spilled Seed ',\n", + " 'total_score': 21.0},\n", + " {'player1': {'game_played': 100, 'name': 'T.J. Edwards', 'score': 2.8},\n", + " 'player2': {'game_played': 100, 'name': 'Pete Werner', 'score': 5.6},\n", + " 'rank': 10,\n", + " 'team': 'Punter? I Hardly Know Her',\n", + " 'total_score': 8.399999999999999}]}" ] }, - "execution_count": 35, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -81,31 +168,171 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'JJ'" + "{'-NiFkEYRMyUnxkHJxjMZ': {'Week': 4,\n", + " 'contest': 'Most Kicker Points',\n", + " 'contest_results': [{'player1': {'game_played': 100,\n", + " 'name': 'Foyesade Oluokun',\n", + " 'score': 39.1},\n", + " 'player2': {'game_played': 100, 'name': 'Ernest Jones', 'score': 6.7},\n", + " 'rank': 1,\n", + " 'team': 'Lets Get Weird 🐸',\n", + " 'total_score': 45.800000000000004},\n", + " {'player1': {'game_played': 100, 'name': 'Bobby Okereke', 'score': 17.2},\n", + " 'player2': {'game_played': 100, 'name': 'Tremaine Edmunds', 'score': 20.6},\n", + " 'rank': 2,\n", + " 'team': 'You Hate to See That',\n", + " 'total_score': 37.8},\n", + " {'player1': {'game_played': 100, 'name': 'Bobby Wagner', 'score': 11.7},\n", + " 'player2': {'game_played': 100, 'name': 'Fred Warner', 'score': 22.4},\n", + " 'rank': 3,\n", + " 'team': 'Ma heart Mahomes',\n", + " 'total_score': 34.099999999999994},\n", + " {'player1': {'game_played': 100, 'name': 'Kyzir White', 'score': 12.4},\n", + " 'player2': {'game_played': 100, 'name': 'Devin Lloyd', 'score': 17.6},\n", + " 'rank': 4,\n", + " 'team': \"You're being a Kyren\",\n", + " 'total_score': 30.0},\n", + " {'player1': {'game_played': 100, 'name': 'Roquan Smith', 'score': 12.3},\n", + " 'player2': {'game_played': 100, 'name': 'Alex Singleton', 'score': 16.9},\n", + " 'rank': 5,\n", + " 'team': 'Maxxy Pats',\n", + " 'total_score': 29.2},\n", + " {'player1': {'game_played': 100, 'name': 'Jordan Hicks', 'score': 14.0},\n", + " 'player2': {'game_played': 100, 'name': 'Dre Greenlaw', 'score': 13.4},\n", + " 'rank': 6,\n", + " 'team': 'Baby got Dak',\n", + " 'total_score': 27.4},\n", + " {'player1': {'game_played': 100, 'name': 'Terrel Bernard', 'score': 22.8},\n", + " 'player2': {'game_played': 100, 'name': 'Cody Barton', 'score': 1.4},\n", + " 'rank': 7,\n", + " 'team': 'I h8 justin',\n", + " 'total_score': 24.2},\n", + " {'player1': {'game_played': 100, 'name': 'Zaire Franklin', 'score': 14.8},\n", + " 'player2': {'game_played': 100, 'name': 'Patrick Queen', 'score': 7.0},\n", + " 'rank': 8,\n", + " 'team': '- CircleKirk',\n", + " 'total_score': 21.8},\n", + " {'player1': {'game_played': 100, 'name': 'Quay Walker', 'score': 10.7},\n", + " 'player2': {'game_played': 100, 'name': 'Robert Spillane', 'score': 10.3},\n", + " 'rank': 9,\n", + " 'team': 'Justys Spilled Seed ',\n", + " 'total_score': 21.0},\n", + " {'player1': {'game_played': 100, 'name': 'T.J. Edwards', 'score': 2.8},\n", + " 'player2': {'game_played': 100, 'name': 'Pete Werner', 'score': 5.6},\n", + " 'rank': 10,\n", + " 'team': 'Punter? I Hardly Know Her',\n", + " 'total_score': 8.399999999999999}]},\n", + " 'Week': 3,\n", + " 'contest': 'Most LB Points',\n", + " 'contest_results': [{'player1': {'game_played': 100,\n", + " 'name': 'Foyesade Oluokun',\n", + " 'score': 39.1},\n", + " 'player2': {'game_played': 100, 'name': 'Ernest Jones', 'score': 6.7},\n", + " 'rank': 1,\n", + " 'team': 'Lets Get Weird 🐸',\n", + " 'total_score': 45.800000000000004},\n", + " {'player1': {'game_played': 100, 'name': 'Bobby Okereke', 'score': 17.2},\n", + " 'player2': {'game_played': 100, 'name': 'Tremaine Edmunds', 'score': 20.6},\n", + " 'rank': 2,\n", + " 'team': 'You Hate to See That',\n", + " 'total_score': 37.8},\n", + " {'player1': {'game_played': 100, 'name': 'Bobby Wagner', 'score': 11.7},\n", + " 'player2': {'game_played': 100, 'name': 'Fred Warner', 'score': 22.4},\n", + " 'rank': 3,\n", + " 'team': 'Ma heart Mahomes',\n", + " 'total_score': 34.099999999999994},\n", + " {'player1': {'game_played': 100, 'name': 'Kyzir White', 'score': 12.4},\n", + " 'player2': {'game_played': 100, 'name': 'Devin Lloyd', 'score': 17.6},\n", + " 'rank': 4,\n", + " 'team': \"You're being a Kyren\",\n", + " 'total_score': 30.0},\n", + " {'player1': {'game_played': 100, 'name': 'Roquan Smith', 'score': 12.3},\n", + " 'player2': {'game_played': 100, 'name': 'Alex Singleton', 'score': 16.9},\n", + " 'rank': 5,\n", + " 'team': 'Maxxy Pats',\n", + " 'total_score': 29.2},\n", + " {'player1': {'game_played': 100, 'name': 'Jordan Hicks', 'score': 14.0},\n", + " 'player2': {'game_played': 100, 'name': 'Dre Greenlaw', 'score': 13.4},\n", + " 'rank': 6,\n", + " 'team': 'Baby got Dak',\n", + " 'total_score': 27.4},\n", + " {'player1': {'game_played': 100, 'name': 'Terrel Bernard', 'score': 22.8},\n", + " 'player2': {'game_played': 100, 'name': 'Cody Barton', 'score': 1.4},\n", + " 'rank': 7,\n", + " 'team': 'I h8 justin',\n", + " 'total_score': 24.2},\n", + " {'player1': {'game_played': 100, 'name': 'Zaire Franklin', 'score': 14.8},\n", + " 'player2': {'game_played': 100, 'name': 'Patrick Queen', 'score': 7.0},\n", + " 'rank': 8,\n", + " 'team': '- CircleKirk',\n", + " 'total_score': 21.8},\n", + " {'player1': {'game_played': 100, 'name': 'Quay Walker', 'score': 10.7},\n", + " 'player2': {'game_played': 100, 'name': 'Robert Spillane', 'score': 10.3},\n", + " 'rank': 9,\n", + " 'team': 'Justys Spilled Seed ',\n", + " 'total_score': 21.0},\n", + " {'player1': {'game_played': 100, 'name': 'T.J. Edwards', 'score': 2.8},\n", + " 'player2': {'game_played': 100, 'name': 'Pete Werner', 'score': 5.6},\n", + " 'rank': 10,\n", + " 'team': 'Punter? I Hardly Know Her',\n", + " 'total_score': 8.399999999999999}]}" ] }, - "execution_count": 34, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "db.reference(\"/name\").get()" + "db.reference(\"/2023\").get()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "db.reference(\"/name\").set('Justy')" + "ref.push({\n", + " \"Week_4\":\n", + " {\n", + " \"contest\": \"Most Kicker Points\",\n", + " \"contest_results\": [\n", + " {\n", + " \"players\":[{\n", + " \"game_played\": 100,\n", + " \"name\": \"Foyesade Oluokun\",\n", + " \"score\": 39.1\n", + " },\n", + " {\n", + " \"game_played\": 100,\n", + " \"name\": \"Ernest Jones\",\n", + " \"score\": 6.7\n", + " }],\n", + " \"rank\": 1,\n", + " \"team\": \"Lets Get Weird \\ud83d\\udc38\",\n", + " \"total_score\": 45.800000000000004\n", + " }\n", + " ]\n", + "}\n", + "})" ] } ], diff --git a/fantasy_app/espn_api_submodule/espn_api/base_league.py b/fantasy_app/espn_api_submodule/espn_api/base_league.py index 6476743..b40f837 100644 --- a/fantasy_app/espn_api_submodule/espn_api/base_league.py +++ b/fantasy_app/espn_api_submodule/espn_api/base_league.py @@ -5,13 +5,16 @@ from .utils.logger import Logger from .requests.espn_requests import EspnFantasyRequests + class BaseLeague(ABC): '''Creates a League instance for Public/Private ESPN league''' + def __init__(self, league_id: int, year: int, sport: str, espn_s2=None, swid=None, debug=False): self.logger = Logger(name=f'{sport} league', debug=debug) self.league_id = league_id self.year = year self.teams = [] + self.members = [] self.draft = [] self.player_map = {} @@ -21,12 +24,13 @@ def __init__(self, league_id: int, year: int, sport: str, espn_s2=None, swid=Non 'espn_s2': espn_s2, 'SWID': swid } - self.espn_request = EspnFantasyRequests(sport=sport, year=year, league_id=league_id, cookies=cookies, logger=self.logger) + self.espn_request = EspnFantasyRequests( + sport=sport, year=year, league_id=league_id, cookies=cookies, logger=self.logger) def __repr__(self): return 'League(%s, %s)' % (self.league_id, self.year, ) - def _fetch_league(self, SettingsClass = BaseSettings): + def _fetch_league(self, SettingsClass=BaseSettings): data = self.espn_request.get_league() self.currentMatchupPeriod = data['status']['currentMatchupPeriod'] @@ -36,11 +40,12 @@ def _fetch_league(self, SettingsClass = BaseSettings): if self.year < 2018: self.current_week = data['scoringPeriodId'] else: - self.current_week = self.scoringPeriodId if self.scoringPeriodId <= data['status']['finalScoringPeriod'] else data['status']['finalScoringPeriod'] + self.current_week = self.scoringPeriodId if self.scoringPeriodId <= data[ + 'status']['finalScoringPeriod'] else data['status']['finalScoringPeriod'] self.settings = SettingsClass(data['settings']) return data - def _fetch_teams(self, data, TeamClass, pro_schedule = None): + def _fetch_teams(self, data, TeamClass, pro_schedule=None): '''Fetch teams in league''' self.teams = [] teams = data['teams'] @@ -61,7 +66,8 @@ def _fetch_teams(self, data, TeamClass, pro_schedule = None): elif member['id'] == team['owners'][0]: break roster = team_roster[team['id']] - self.teams.append(TeamClass(team, roster=roster, member=member, schedule=schedule, year=seasonId, pro_schedule=pro_schedule)) + self.teams.append(TeamClass(team, roster=roster, member=member, + schedule=schedule, year=seasonId, pro_schedule=pro_schedule)) # sort by team ID self.teams = sorted(self.teams, key=lambda x: x.team_id, reverse=False) @@ -86,9 +92,10 @@ def _get_pro_schedule(self, scoringPeriodId: int = None): pro_game = team.get('proGamesByScoringPeriod', {}) if team['id'] != 0 and (str(scoringPeriodId) in pro_game.keys() and pro_game[str(scoringPeriodId)]): game_data = pro_game[str(scoringPeriodId)][0] - pro_team_schedule[team['id']] = (game_data['homeProTeamId'], game_data['date']) if team['id'] == game_data['awayProTeamId'] else (game_data['awayProTeamId'], game_data['date']) + pro_team_schedule[team['id']] = (game_data['homeProTeamId'], game_data['date']) if team['id'] == game_data['awayProTeamId'] else ( + game_data['awayProTeamId'], game_data['date']) return pro_team_schedule - + def _get_all_pro_schedule(self): data = self.espn_request.get_pro_schedule() @@ -101,5 +108,6 @@ def _get_all_pro_schedule(self): return pro_team_schedule def standings(self) -> List: - standings = sorted(self.teams, key=lambda x: x.final_standing if x.final_standing != 0 else x.standing, reverse=False) - return standings \ No newline at end of file + standings = sorted( + self.teams, key=lambda x: x.final_standing if x.final_standing != 0 else x.standing, reverse=False) + return standings diff --git a/fantasy_app/espn_api_submodule/espn_api/football/team.py b/fantasy_app/espn_api_submodule/espn_api/football/team.py index d09c729..4cf01ea 100644 --- a/fantasy_app/espn_api_submodule/espn_api/football/team.py +++ b/fantasy_app/espn_api_submodule/espn_api/football/team.py @@ -1,23 +1,32 @@ from .player import Player + class Team(object): '''Teams are part of the league''' + def __init__(self, data, roster, member, schedule, year, **kwargs): self.team_id = data['id'] self.team_abbrev = data['abbrev'] - self.team_name = "%s %s" % (data['location'], data['nickname']) + self.team_name = data.get('name', 'Unknown') + if self.team_name == 'Unknown': + self.team_name = "%s %s" % ( + data.get('location', 'Unknown'), data.get('nickname', 'Unknown')) self.division_id = data['divisionId'] - self.division_name = '' # set by caller + self.division_name = '' # set by caller self.wins = data['record']['overall']['wins'] self.losses = data['record']['overall']['losses'] self.ties = data['record']['overall']['ties'] self.points_for = data['record']['overall']['pointsFor'] - self.points_against = round(data['record']['overall']['pointsAgainst'], 2) - self.acquisitions = data.get('transactionCounter', {}).get('acquisitions', 0) - self.acquisition_budget_spent = data.get('transactionCounter', {}).get('acquisitionBudgetSpent', 0) + self.points_against = round( + data['record']['overall']['pointsAgainst'], 2) + self.acquisitions = data.get( + 'transactionCounter', {}).get('acquisitions', 0) + self.acquisition_budget_spent = data.get( + 'transactionCounter', {}).get('acquisitionBudgetSpent', 0) self.drops = data.get('transactionCounter', {}).get('drops', 0) self.trades = data.get('transactionCounter', {}).get('trades', 0) - self.playoff_pct = data.get('currentSimulationResults', {}).get('playoffPct', 0) * 100 + self.playoff_pct = data.get( + 'currentSimulationResults', {}).get('playoffPct', 0) * 100 self.draft_projected_rank = data.get('draftDayProjectedRank', 0) self.owner = 'None' if member: @@ -27,7 +36,7 @@ def __init__(self, data, roster, member, schedule, year, **kwargs): self.streak_type = data['record']['overall']['streakType'] self.standing = data['playoffSeed'] self.final_standing = data['rankCalculatedFinal'] - if 'logo' in data: + if 'logo' in data: self.logo_url = data['logo'] else: self.logo_url = '' @@ -37,11 +46,12 @@ def __init__(self, data, roster, member, schedule, year, **kwargs): self.outcomes = [] self.mov = [] self._fetch_schedule(schedule) + self.owners = data.get('owners', []) self._fetch_roster(roster, year) def __repr__(self): return 'Team(%s)' % (self.team_name, ) - + def _fetch_roster(self, data, year): '''Fetch teams roster''' self.roster.clear() @@ -58,22 +68,25 @@ def _fetch_schedule(self, data): if matchup['away']['teamId'] == self.team_id: score = matchup['away']['totalPoints'] opponentId = matchup['home']['teamId'] - self.outcomes.append(self._get_winner(matchup['winner'], True)) + self.outcomes.append( + self._get_winner(matchup['winner'], True)) self.scores.append(score) self.schedule.append(opponentId) elif matchup['home']['teamId'] == self.team_id: score = matchup['home']['totalPoints'] opponentId = matchup['away']['teamId'] - self.outcomes.append(self._get_winner(matchup['winner'], False)) + self.outcomes.append( + self._get_winner(matchup['winner'], False)) self.scores.append(score) self.schedule.append(opponentId) elif matchup['home']['teamId'] == self.team_id: score = matchup['home']['totalPoints'] opponentId = matchup['home']['teamId'] - self.outcomes.append(self._get_winner(matchup['winner'], False)) + self.outcomes.append( + self._get_winner(matchup['winner'], False)) self.scores.append(score) self.schedule.append(opponentId) - + def _get_winner(self, winner: str, is_away: bool) -> str: if winner == 'UNDECIDED': return 'U' diff --git a/fantasy_app/functions.py b/fantasy_app/functions.py index 2d336b6..909bb04 100644 --- a/fantasy_app/functions.py +++ b/fantasy_app/functions.py @@ -125,16 +125,22 @@ def create_dictionary(team_name, lineup, position, stat, player_dict): def new_dict(position, current_dict, lineup): count = 0 total_score = 0 + player_list = [] for player in lineup: if player.slot_position in position: + count += 1 - current_dict['player{}'.format(count)] = { + temp_dict = { 'name': player.name, 'score': player.points, 'game_played': player.game_played } + total_score += player.points + player_list.append(temp_dict) + current_dict['total_score'] = total_score + current_dict['players'] = player_list return current_dict diff --git a/key.json b/key.json deleted file mode 100644 index 79b1826..0000000 --- a/key.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "type": "service_account", - "project_id": "fantasy-contests", - "private_key_id": "666c2a25326a1a0d4026e850e881eb9f399ab6fc", - "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCulw7bps+GQB3w\n4GS130M0YwNi0YgI2gvZ/JZy1HrweSgP9ZCaiKNgEgRZPvhhMfol+qEirEpnI6Z6\nfTudyl5dxVMlVjfbcRIu06CnQdkKFz/OYeB9J+FlwnsywJMgUeZTJFhYckPnH4zu\noa+FFfH50c627uenhM4Jd1DuLMJzhf/VnL8szNnr//RofHtrs2mDBhKFUy+GfNWy\nFaPiBo2XXP/6sV1LBh3b0TWSGTZDx0lwF55uzS58PjHzw9yPlyySMsUSv9tmpACe\n65N8eiixcx7niAN8ig3toDa6afRsSFC8bVwRnNK5s9YMAYAarzSLtFmkszD8C3kh\n68RPutNZAgMBAAECggEALivFoqIJJJxFLsPw7kYGXE7JAPOfkZO0aagKU4DMqFaq\nGRpcbPmwlwH8w2tLPUz9tdiDj4tXu9HqP19qCi8P6KV7+RZFfFN5NwgBZuobjzcZ\nyScKOp721TXq5b+WyQfPrPIiKPXC7lbiKuN4au4kSWhKTgd9HMiawlcbAHm2zNzV\nUE6lh8bzYybHUz3G4nMu/TasMxivCOb2NlDG106dNDv2t9/s7p1yttNidRQg5Nfm\nQDlCHCaEBmQyB1/BzDITkbS4NaguNtubQqzaGN/4myn72XdZv6W7DrSc8Be6IQir\nRuRiBQEJeoLmy9J7Pv1P+jE8ayiMPrw4u8oBCiOVtwKBgQDmfry13mpDsxAdvDNA\noT68V/VL0GktSEHc9x6YlnKZLWyVKkyw/sz3DUvQsV33gMCt2t72SBSpSGOFulNB\nqth9tsd1GroCfm8VX5VuGRMFq9MQ1jCwBI3qQi9DXciAW+e8sh4s9aars7oFjo4U\nRqP3LfZgsJDH7kjpCqsmOgYXBwKBgQDB6LFoSJSZKQid7kIff5qQfgQTGOY5unIF\nSe6C/TZQrKgE1r/9KtBAfxjYwVl/9eRgAq4d3G3hg5VrywvOfvnX8f35C2dbzEFx\nXK81vHhBpbAFoIELANJk4FU5Rr7MtuQyPAwvXKvqKNn4r3m2afHGfaLu0ovPDJ2i\n5roSqUHKnwKBgC5ItMwwZVZC1rGh4QjRWC+p2e/nYbdeExuz48jwLQLlRDCP1eaU\nw8O4P8kgVKYmjIpcsPjzcHKtvo5T4/QDwoU79sFlJITrrpK0JuV8030IC9INsKkn\nwPeRYrw8UM61pcsWWUjd6yH/bRNAlPctWC+CYz73NZtwFeP16Hg8noxxAoGABsRH\nBJuby+h5q4E3/39ldmtfWwdAaX1PI04cK6gIcDJGPrz7wCrxT37f8Bh3NhbvnEYb\nq2EY2IjN+w//3nnh4B5KvZkfRz3OftU8LATisW/Fv7yFJEwoC2skrjYAzIYJWpNr\n3W8/dJFuYdZFyg7SaBnUSL9CL7yB98BTd/k+GYMCgYBdsdPTW+Cwnnhcx7zh4A/E\nn6F3g1Iny9qjx+OnKFL2Q+gU4Wr1GYbSL5rwBFIED2cXNcBXnPtTsdJxN8iqxHB3\nkNpqw9SdJR2qverh1AlRbjBY2KgiCM5VqrhBUBWhiEXZ+LTAoW1gfTK9sWxY8yEI\nd9Tg26imYxeYfM4O8WwQFg==\n-----END PRIVATE KEY-----\n", - "client_email": "firebase-adminsdk-atqc1@fantasy-contests.iam.gserviceaccount.com", - "client_id": "118329157944890218182", - "auth_uri": "https://accounts.google.com/o/oauth2/auth", - "token_uri": "https://oauth2.googleapis.com/token", - "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", - "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-atqc1%40fantasy-contests.iam.gserviceaccount.com", - "universe_domain": "googleapis.com" -} diff --git a/results.json b/results.json new file mode 100644 index 0000000..3c2db60 --- /dev/null +++ b/results.json @@ -0,0 +1,158 @@ +{ + "2023": { + "Week": 3, + "contest": "Most LB Points", + "contest_results": [ + { + "player1": { + "game_played": 100, + "name": "Foyesade Oluokun", + "score": 39.1 + }, + "player2": { + "game_played": 100, + "name": "Ernest Jones", + "score": 6.7 + }, + "rank": 1, + "team": "Lets Get Weird \ud83d\udc38", + "total_score": 45.800000000000004 + }, + { + "player1": { + "game_played": 100, + "name": "Bobby Okereke", + "score": 17.2 + }, + "player2": { + "game_played": 100, + "name": "Tremaine Edmunds", + "score": 20.6 + }, + "rank": 2, + "team": "You Hate to See That", + "total_score": 37.8 + }, + { + "player1": { + "game_played": 100, + "name": "Bobby Wagner", + "score": 11.7 + }, + "player2": { + "game_played": 100, + "name": "Fred Warner", + "score": 22.4 + }, + "rank": 3, + "team": "Ma heart Mahomes", + "total_score": 34.099999999999994 + }, + { + "player1": { + "game_played": 100, + "name": "Kyzir White", + "score": 12.4 + }, + "player2": { + "game_played": 100, + "name": "Devin Lloyd", + "score": 17.6 + }, + "rank": 4, + "team": "You're being a Kyren", + "total_score": 30.0 + }, + { + "player1": { + "game_played": 100, + "name": "Roquan Smith", + "score": 12.3 + }, + "player2": { + "game_played": 100, + "name": "Alex Singleton", + "score": 16.9 + }, + "rank": 5, + "team": "Maxxy Pats", + "total_score": 29.2 + }, + { + "player1": { + "game_played": 100, + "name": "Jordan Hicks", + "score": 14.0 + }, + "player2": { + "game_played": 100, + "name": "Dre Greenlaw", + "score": 13.4 + }, + "rank": 6, + "team": "Baby got Dak", + "total_score": 27.4 + }, + { + "player1": { + "game_played": 100, + "name": "Terrel Bernard", + "score": 22.8 + }, + "player2": { + "game_played": 100, + "name": "Cody Barton", + "score": 1.4 + }, + "rank": 7, + "team": "I h8 justin", + "total_score": 24.2 + }, + { + "player1": { + "game_played": 100, + "name": "Zaire Franklin", + "score": 14.8 + }, + "player2": { + "game_played": 100, + "name": "Patrick Queen", + "score": 7.0 + }, + "rank": 8, + "team": "- CircleKirk", + "total_score": 21.8 + }, + { + "player1": { + "game_played": 100, + "name": "Quay Walker", + "score": 10.7 + }, + "player2": { + "game_played": 100, + "name": "Robert Spillane", + "score": 10.3 + }, + "rank": 9, + "team": "Justys Spilled Seed ", + "total_score": 21.0 + }, + { + "player1": { + "game_played": 100, + "name": "T.J. Edwards", + "score": 2.8 + }, + "player2": { + "game_played": 100, + "name": "Pete Werner", + "score": 5.6 + }, + "rank": 10, + "team": "Punter? I Hardly Know Her", + "total_score": 8.399999999999999 + } + ] + } +} diff --git a/results1.json b/results1.json new file mode 100644 index 0000000..1963120 --- /dev/null +++ b/results1.json @@ -0,0 +1,177 @@ +{ + "week_4": { + "contest": "total_lb_points", + "contest_results": [ + { + "players": [ + { + "game_played": 100, + "name": "Foyesade Oluokun", + "score": 17.3 + }, + { + "game_played": 100, + "name": "Quincy Williams", + "score": 23.5 + } + ], + "rank": 1, + "team": "Lets Get Weird \ud83d\udc38", + "total_score": 40.8 + }, + { + "players": [ + { + "game_played": 100, + "name": "Zaire Franklin", + "score": 23.2 + }, + { + "game_played": 100, + "name": "Patrick Queen", + "score": 16.8 + } + ], + "rank": 2, + "team": "- CircleKirk", + "total_score": 40.0 + }, + { + "players": [ + { + "game_played": 100, + "name": "Bobby Wagner", + "score": 20.2 + }, + { + "game_played": 100, + "name": "Fred Warner", + "score": 17.7 + } + ], + "rank": 3, + "team": "Ma heart Mahomes", + "total_score": 37.9 + }, + { + "players": [ + { + "game_played": 100, + "name": "C.J. Mosley", + "score": 20.8 + }, + { + "game_played": 100, + "name": "Kyzir White", + "score": 14.0 + } + ], + "rank": 4, + "team": "You're being a Kyren", + "total_score": 34.8 + }, + { + "players": [ + { + "game_played": 100, + "name": "Quay Walker", + "score": 15.1 + }, + { + "game_played": 100, + "name": "Robert Spillane", + "score": 18.0 + } + ], + "rank": 5, + "team": "Justys Spilled Seed ", + "total_score": 33.1 + }, + { + "players": [ + { + "game_played": 100, + "name": "T.J. Edwards", + "score": 29.0 + }, + { + "game_played": 100, + "name": "Pete Werner", + "score": 3.9 + } + ], + "rank": 6, + "team": "Punter? I Hardly Know Her", + "total_score": 32.9 + }, + { + "players": [ + { + "game_played": 100, + "name": "Roquan Smith", + "score": 16.5 + }, + { + "game_played": 100, + "name": "Alex Singleton", + "score": 9.5 + } + ], + "rank": 7, + "team": "Maxxy Pats", + "total_score": 26.0 + }, + { + "players": [ + { + "game_played": 100, + "name": "Jordan Hicks", + "score": 10.0 + }, + { + "game_played": 100, + "name": "Dre Greenlaw", + "score": 10.6 + } + ], + "rank": 8, + "team": "Baby got Dak", + "total_score": 20.6 + }, + { + "players": [ + { + "game_played": 100, + "name": "Bobby Okereke", + "score": 14.0 + }, + { + "game_played": 100, + "name": "Tremaine Edmunds", + "score": 1.4 + } + ], + "rank": 9, + "team": "You Hate to See That", + "total_score": 15.4 + }, + { + "players": [ + { + "game_played": 100, + "name": "Terrel Bernard", + "score": 14.6 + }, + { + "game_played": 100, + "name": "Cody Barton", + "score": 0.0 + } + ], + "rank": 10, + "team": "I h8 justin", + "total_score": 14.6 + } + ] + } +}