Skip to content

Commit

Permalink
Fixes for unittesting & fixup for player names
Browse files Browse the repository at this point in the history
  • Loading branch information
MLDERES committed Aug 31, 2020
1 parent ccfec07 commit 1cdbbe5
Show file tree
Hide file tree
Showing 19 changed files with 259 additions and 112 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python"
"ms-python.python",
"2gua.rainbow-brackets"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"python.testing.pytestArgs": [
"src"
"src",
"showlocals"
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
Expand Down
16 changes: 10 additions & 6 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
Copyright 2020 Michael Dereszynski

The MIT License (MIT)
Copyright (c) 2020, Michael Dereszynski
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

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:
http://www.apache.org/licenses/LICENSE-2.0

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.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
37 changes: 30 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,26 @@ notebook_convert:
kedro jupyter convert --all

## Clean up the raw data files
clean_raw:
clean-raw:
rm -fv data/01_raw/*

## Clean up intermediate and primary data
clean_de: clean_intermediate clean_features
rm -fv data/03_primary/*

## Clean intermediate files
clean_intermediate:
clean-intermediate:
rm -fv data/02_intermediate/*

## Clean primary data
clean-primary:
rm -fv data/03_primary/*

## Remove files associated with data engineering
clean-de: clean-primary clean-intermediate

## delete data features
clean_features:
clean-features:
rm -fv data/04_feature/*

## delete all generated data
clean-data: clean-features clean-primary clean-intermediate clean-raw

## Clean up the old files
clean:
Expand All @@ -46,6 +51,24 @@ clean:
package: clean
kedro package

## Do all the pre-checks
pre-check:
black .
flake8
mypy

## Update version for a patch (these get pulled into the repo)
patch: pre-check
bump2version --tag --commit patch

## Update version on each commit
build: pre-check
bump2version build

## Update version that will be released (takes off the dev tag)
release: pre-check
bump2version release

## Build api odx using Sphinx
docs:
kedro build-docs
Expand Down
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# phantasyfootballer

[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![license: Apache](https://img.shields.io/github/license/MLDERES/phantasyfootballer)](http://www.apache.org/licenses/LICENSE-2.0.html)
[forks](https://img.shields.io/github/forks/MLDERES/phantasyfootballer)
[stars](https://img.shields.io/github/stars/MLDERES/phantasyfootballer)

## Overview

Expand All @@ -14,58 +18,57 @@ Declare any dependencies in `src/requirements.txt` for `pip` installation and `s

To install them, run:

```
```bash
kedro install
```

## Running Kedro

You can run your Kedro project with:

```
```bash
kedro run
```

## Testing Kedro

Have a look at the file `src/tests/test_run.py` for instructions on how to write your tests. You can run your tests with the following command:

```
```bash
kedro test
```

To configure the coverage threshold, please have a look at the file `.coveragerc`.


## Working with Kedro from notebooks

In order to use notebooks in your Kedro project, you need to install Jupyter:

```
```bash
pip install jupyter
```

For using Jupyter Lab, you need to install it:

```
```bash
pip install jupyterlab
```

After installing Jupyter, you can start a local notebook server:

```
```bash
kedro jupyter notebook
```

You can also start Jupyter Lab:

```
```sh
kedro jupyter lab
```

And if you want to run an IPython session:

```
```sh
kedro ipython
```

Expand All @@ -77,13 +80,16 @@ scope: `proj_dir`, `proj_name`, `conf`, `io`, `parameters` and `startup_error`.
Once you are happy with a notebook, you may want to move your code over into the Kedro project structure for the next stage in your development. This is done through a mixture of [cell tagging](https://jupyter-notebook.readthedocs.io/en/stable/changelog.html#cell-tags) and Kedro CLI commands.

By adding the `node` tag to a cell and running the command below, the cell's source code will be copied over to a Python file within `src/<package_name>/nodes/`.
```

```sh
kedro jupyter convert <filepath_to_my_notebook>
```

> *Note:* The name of the Python file matches the name of the original notebook.
Alternatively, you may want to transform all your notebooks in one go. To this end, you can run the following command to convert all notebook files found in the project root directory and under any of its sub-folders.
```

```sh
kedro jupyter convert --all
```

Expand All @@ -97,7 +103,7 @@ In order to automatically strip out all output cell contents before committing t

In order to package the project's Python code in `.egg` and / or a `.wheel` file, you can run:

```
```sh
kedro package
```

Expand All @@ -107,7 +113,7 @@ After running that, you can find the two packages in `src/dist/`.

To build API docs for your code using Sphinx, run:

```
```sh
kedro build-docs
```

Expand All @@ -117,7 +123,7 @@ See your documentation by opening `docs/build/html/index.html`.

To generate or update the dependency requirements for your project, run:

```
```sh
kedro build-reqs
```

Expand Down
Empty file added conf/base/globals.yml
Empty file.
8 changes: 7 additions & 1 deletion conf/base/parameters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ player_filter:
max_players: 100
TE:
max_players: 40
min_fp: 30
min_fp: 30

player_name_alias:
Mitchell Trubisky:
- Mitch Trubisky
Gardner Minshew:
- Gardner Minshew II
1 change: 0 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#
import re


from kedro.framework.cli.utils import find_stylesheets # noqa: F401
from phantasyfootballer import __version__ as release
from recommonmark.transform import AutoStructify
Expand Down
43 changes: 33 additions & 10 deletions notebooks/analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
"warnings.simplefilter('ignore')\n",
"\n",
"pd.set_option('display.multi_sparse', False)\n",
"pd.set_option('display.max_rows', 500)"
"pd.set_option('display.max_rows', 500)\n",
"pd.set_option('precision', 4)\n",
"pd.set_option('display.notebook_repr_html',True)\n",
"pd.set_option('display.precision', 4)\n",
"pd.set_option('display.html.table_schema', True)\n",
"pd.set_option('display.float_format', lambda x: '%.5f' % x)\n"
]
},
{
Expand Down Expand Up @@ -159,15 +164,6 @@
"Looking at all the players, ranking them by their overall draft value based on the number of points expected over the average player, and the median player."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df[Stats.]"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -192,6 +188,33 @@
"source": [
"df_all[[POSITION, Stats.POS_VALUE, Stats.POS_VALUE_REM]].sort_values(Stats.POS_VALUE_REM, ascending = False)[:200]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df_pivot = df_all.pivot_table(index=[POSITION, PLAYER_NAME], values=[Stats.POS_VALUE, Stats.POS_VALUE_REM])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import HTML\n",
"def highlight_gaps(value):\n",
" return 'background-color: yellow' if value < -0.16 else ''\n",
"\n",
"qb_pivot = df_pivot.xs('QB').sort_values(Stats.POS_VALUE_REM, ascending=False)\n",
"qb_pivot['pct_change'] = qb_pivot[Stats.POS_VALUE_REM].pct_change()\n",
"pd.qcut(qb_pivot['pct_change'],10)\n",
"qb_pivot.style.applymap(highlight_gaps, subset=['pct_change'])\n",
"\n",
" "
]
}
],
"metadata": {
Expand Down
24 changes: 24 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,27 @@ line_length=88
[mypy]
files=src
ignore_missing_imports=true

[bumpversion]
current_version = 0.3.0-dev0
commit = False
tag=False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
serialize =
{major}.{minor}.{patch}-{release}{build}
{major}.{minor}.{patch}

[bumpversion:part:release]
optional_value = prod
first_value = dev
values =
dev
prod

[bumpversion:part:build]

[bumpversion:file:src/setup.py]

[bumpversion:file:src/phantasyfootballer/__init__.py]


2 changes: 1 addition & 1 deletion src/phantasyfootballer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
"""phantasyfootballer
"""

__version__ = "0.1"
__version__ = "0.3.1-dev0"
from .common import *
16 changes: 14 additions & 2 deletions src/phantasyfootballer/common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from pathlib import Path
from typing import Any, List, Sequence, Union
from typing import Any, Dict, List, Sequence, Union, Optional

import pandas as pd
from kedro.config import TemplatedConfigLoader
from pandas.core.dtypes.inference import is_list_like

BASE_DIR = Path(__file__).parents[2]
Expand Down Expand Up @@ -60,7 +61,8 @@ class Stats:
# Only the top players are used in the evaluation of value
TOP_PLAYER = "is_top_player"
POS_VALUE = "positional_value"
POS_VALUE_REM = "pos_value_left"
POS_VALUE_REM = "pos_value_remaining"
DIFF_POS_VALUE_REM = "pos_value_remaining_diff"
# The percent of points that will be scored by all players in the league
OVR_VALUE = "overall_value"
# The percent points left after this player is taken
Expand Down Expand Up @@ -212,3 +214,13 @@ def get_list(item: Union[Any, List[Any]], errors="ignore"):
else:
retVal = [item]
return retVal


def get_config(
file_glob: str, globals_dict: Optional[Dict[str, Any]] = None
) -> Dict[str, Any]:
conf_paths = [str(BASE_DIR / "conf/base"), str(BASE_DIR / "conf/local")]
config_loader = TemplatedConfigLoader(
conf_paths, globals_pattern="*globals.yml", globals_dict=globals_dict
)
return config_loader.get(file_glob)
4 changes: 2 additions & 2 deletions src/phantasyfootballer/data_providers/cbs_sports.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"fl Fumbles Lost": Stats.MISC_FL,
}
FLEX_COL_MAP = {
"Player": PLAYER_NAME,
"att Rushing Attempts": Stats.RUSH_ATT,
"yds Rushing Yards": Stats.RUSH_YDS,
"td Rushing Touchdowns": Stats.RUSH_TDS,
Expand All @@ -36,7 +37,6 @@
"td Receiving Touchdowns": Stats.RCV_TDS,
"fl Fumbles Lost": Stats.MISC_FL,
"rec Receptions": Stats.RCV_REC,
"Player": PLAYER_NAME,
}


Expand Down Expand Up @@ -98,5 +98,5 @@ def _get_projections(position, year):


if __name__ == "__main__":
df = fetch_projections(2020)
df = fetch_projections(year=2020)
df.to_csv(DATA_DIR / "cbs_sports.csv")
Loading

0 comments on commit 1cdbbe5

Please sign in to comment.