Skip to content

Commit

Permalink
Merge pull request #20 from MLDERES/dev
Browse files Browse the repository at this point in the history
Fixing issue #18
  • Loading branch information
MLDERES authored Aug 21, 2020
2 parents ba6bec8 + ce7f75b commit 93cbff3
Show file tree
Hide file tree
Showing 26 changed files with 769 additions and 138 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
{
"python.testing.pytestArgs": [
"src"
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true
}
10 changes: 10 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

The MIT License (MIT)
Copyright (c) 2020, Michael Dereszynski

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

21 changes: 19 additions & 2 deletions conf/base/catalog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pfr_passing:
date_range_type : "year"
start_year : 2019

pfr_receiving:
pfr_receiving:
type: phantasyfootballer.io.CSVRemoteDataSet
data_source : 'phantasyfootballer.data_providers.pro_fb_ref.fetch_receiving_data'
date_range_type : "year"
Expand All @@ -57,7 +57,7 @@ cbs_projections_remote:
local_filepath: data/01_raw/cbs_sports_projection.csv


fp_projections:
fp_projections_local:
<<: *csv
filepath: data/01_raw/fantasy_pros_projection.csv
#versioned: True
Expand All @@ -72,6 +72,23 @@ projections:
filepath: data/02_intermediate/projections.csv
#versioned: True

scoring.ppr:
<<: *csv
filepath: data/03_primary/scoring_ppr.csv

scoring.half_ppr:
<<: *csv
filepath: data/03_primary/scoring_half_ppr.csv

scoring.standard:
<<: *csv
filepath: data/03_primary/scoring_std.csv

scoring_custom:
<<: *csv
filepath: data/03_primary/scoring_custom.csv





Expand Down
5 changes: 5 additions & 0 deletions conf/base/pipelines/data_engineering/catalog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This is a boilerplate catalog config generated for pipeline 'data_engineering'
# using Kedro 0.16.4.
#
# Documentation for this file format can be found in "The Data Catalog"
# Link: https://kedro.readthedocs.io/en/stable/04_user_guide/04_data_catalog.html
5 changes: 5 additions & 0 deletions conf/base/pipelines/data_engineering/parameters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This is a boilerplate parameters config generated for pipeline 'data_engineering'
# using Kedro 0.16.4.
#
# Documentation for this file format can be found in
# https://kedro.readthedocs.io/en/stable/04_user_guide/03_configuration.html#parameters
4 changes: 3 additions & 1 deletion conf/base/scoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ full_ppr:
half_ppr:
<<: *standard_scoring
rcv_rec: 0.5


custom:
<<: *standard_scoring
137 changes: 125 additions & 12 deletions notebooks/analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"proj_path = current_dir.parent # point back to the root of the project\n",
"context = load_context(proj_path)\n",
"catalog = context.catalog\n",
"\n",
"from phantasyfootballer.settings import *"
"\n"
]
},
{
Expand All @@ -36,7 +35,10 @@
},
"outputs": [],
"source": [
"df_proj = catalog.load('projections')"
"from phantasyfootballer.settings import *\n",
"from phantasyfootballer.common import Stats\n",
"df_ppr = catalog.load('scoring.ppr')\n",
"\n"
]
},
{
Expand All @@ -45,19 +47,43 @@
"metadata": {},
"outputs": [],
"source": [
"stat_columns = ['pass_att', 'pass_comp',\n",
" 'pass_int', 'pass_tds', 'pass_yds', 'rcv_rec', 'rcv_tds', 'rcv_yds',\n",
" 'rush_att', 'rush_yds', 'rush_tds', 'fumble_lost']\n",
"point_columns = ['standard_pts','full_ppr_pts', 'half_ppr_pts']\n",
"rank_columns = ['standard_rank', 'full_ppr_rank','half_ppr_rank']\n",
"df_ppr.sort_values(Stats.POS_RANK)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"\n",
"df_ppr[Stats.POS_RANK] = df_ppr.groupby(POSITION)[Stats.FANTASY_POINTS].rank(na_option=\"bottom\", ascending=False)\n",
"df_ppr.sort_values(Stats.POS_RANK, ascending=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class projections():\n",
"\n",
" def __init__(self, data):\n",
" self._data = data\n",
" self._support_stats = set(Stats.ALL_STATS).intersection(data.columns)\n",
" self._supported_features = None\n",
"\n",
" def stats(self):\n",
" return self._data[stat_columns]\n",
" return self._data[self._support_stats]\n",
"\n",
" def pts(self):\n",
" return self._data[[Stats.points('full_ppr'), Stats.points('half_ppr'), Stats.points('standard')]]\n",
" \n",
" def features(self):\n",
" return None\n",
"\n"
]
},
Expand All @@ -68,15 +94,102 @@
"outputs": [],
"source": [
"df_pos_proj = df_proj.groupby(POSITION).mean()\n",
"df_pos_proj[stat_columns]\n",
"df_proj[rank_columns]"
"pos_proj = projections(df_proj)\n",
"pos_proj.stats()\n",
"pos_proj.pts()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pos_proj._data[[Stats.points('full_ppr'), Stats.points('half_ppr'), Stats.points('standard')]]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df_full_projections = df_proj.join(df_pos_proj[[Stats.points('full_ppr'), Stats.points('half_ppr'),Stats.points('standard')]], on=POSITION, rsuffix='_apr')\n",
"df_full_projections.columns"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def pct_avg_value(df, col):\n",
" df[f'pct_of_avg_{col}'] = df[Stats.points(col)] / df[f'{Stats.points(col)}_apr']\n",
"\n",
"def pct_median_value(df, col):\n",
" df[f'pct_of_avg_{col}'] = df[Stats.points(col)] / df[f'{Stats.points(col)}_apr']\n",
"\n",
"\n",
"pct_value(df_full_projections,'full_ppr')\n",
"pct_value(df_full_projections,'half_ppr')\n",
"pct_value(df_full_projections,'standard')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df_full_projections.sort_values('pct_of_avg_full_ppr', ascending=False)[[PLAYER_NAME,'pct_of_avg_full_ppr','pct_of_avg_standard','pct_of_avg_half_ppr']]\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df_full_projections.query('player==\"Travis Kelce\"')\n",
"df_pos_proj.loc[TE]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from matplotlib import pyplot as plt \n",
"import seaborn as sns\n",
"top_rb = df_full_projections.query('position == \"RB\"').sort_values('pct_of_avg_full_ppr',ascending=False)[:36]\n",
"top_wr = df_full_projections.query('position == \"WR\"').sort_values('pct_of_avg_full_ppr',ascending=False)[:36]\n",
"top_te = df_full_projections.query('position == \"TE\"').sort_values('pct_of_avg_full_ppr',ascending=False)[:36]\n",
"top_qb = df_full_projections.query('position == \"QB\"').sort_values('pct_of_avg_full_ppr',ascending=False)[:36]\n",
"#.plot(kind='bar',x=PLAYER_NAME,y='pct_of_avg_full_ppr');"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"top_rb.plot(kind='bar',x=PLAYER_NAME,y='pct_of_avg_full_ppr');\n",
"top_qb.plot(kind='bar',x=PLAYER_NAME,y='pct_of_avg_full_ppr');\n",
"top_wr.plot(kind='bar',x=PLAYER_NAME,y='pct_of_avg_full_ppr');\n",
"top_te.plot(kind='bar',x=PLAYER_NAME,y='pct_of_avg_full_ppr');"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.3 64-bit",
"name": "python_defaultSpec_1597939435737"
"name": "python_defaultSpec_1598024082108"
},
"language_info": {
"codemirror_mode": {
Expand Down
62 changes: 61 additions & 1 deletion notebooks/sample.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,72 @@
"\n",
" _calculate_expiration_hours('8H')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from phantasyfootballer.settings import *\n",
"from phantasyfootballer.common import combine_data_horizontal\n",
"\n",
"df = context.catalog.load('scoring.half_ppr')\n",
"df_left = df[KEEPER_COLUMNS]\n",
"df_right = df_left.copy()\n",
"df_right['NEW_COL'] = 'new_data'\n",
"combine_data_horizontal(df_left,df_right)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from phantasyfootballer.settings import *\n",
"from phantasyfootballer.common import Stats\n",
"data = context.catalog.load('scoring.ppr')\n",
"#data.head()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"pos_data = data.groupby(POSITION)[Stats.FANTASY_POINTS].mean()\n",
"joined = data.join(pos_data,on=POSITION,rsuffix='avg')\n",
"data[Stats.PCT_AVERAGE] = joined[Stats.FANTASY_POINTS]/joined['fpavg']\n",
"joined.head()\n",
"data.head()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.3 64-bit",
"name": "python_defaultSpec_1597939322536"
"name": "python_defaultSpec_1598023361223"
},
"language_info": {
"codemirror_mode": {
Expand Down
Loading

0 comments on commit 93cbff3

Please sign in to comment.