Skip to content

Commit

Permalink
Clean up ipynb files, directories and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik-luszcz committed Jul 25, 2024
1 parent 54e40c0 commit 2401178
Show file tree
Hide file tree
Showing 40 changed files with 901 additions and 3,926 deletions.
9 changes: 0 additions & 9 deletions Luszalytics/client/src/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import React from "react";
import { useNavigate } from 'react-router-dom'
import { AwesomeButton } from 'react-awesome-button';
import AwesomeButtonStyles from 'react-awesome-button/src/styles/styles.scss';



const Home = (props) => {
const { loggedIn, email } = props
const navigate = useNavigate()

const onButtonClick = () => {
// You'll update this function later
}


return (
Expand Down
4 changes: 2 additions & 2 deletions Luszalytics/client/src/pages/pwaa_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ const SearchPWAA = () => {
textAnchor="middle"
style={{ fontSize: 11 }}
x={100} y={100}
text={[position === 'G' ? 'High Danger' : "PK xGoals Against", position === 'G' ? highDanger.toFixed(2) : pkXGoalsA.toFixed(2) == 0.00 ? 'N/A' : pkXGoalsA.toFixed(2)]}
text={[position === 'G' ? 'High Danger' : "PK xGoals Against", position === 'G' ? highDanger.toFixed(2) : pkXGoalsA.toFixed(2) === 0.00 ? 'N/A' : pkXGoalsA.toFixed(2)]}
/>

</svg>
Expand Down Expand Up @@ -324,7 +324,7 @@ const SearchPWAA = () => {
textAnchor="middle"
style={{ fontSize: 13 }}
x={100} y={100}
text={[position === 'G' ? "" : "PP Chances", position === 'G' ? "" : ppChances.toFixed(2) == 0.00 ? 'N/A' : ppChances.toFixed(2)]}
text={[position === 'G' ? "" : "PP Chances", position === 'G' ? "" : ppChances.toFixed(2) === 0.00 ? 'N/A' : ppChances.toFixed(2)]}
/>

</svg>
Expand Down
Empty file removed PWAA_forwards
Empty file.
1,486 changes: 0 additions & 1,486 deletions centerPer60.csv

This file was deleted.

File renamed without changes.
1,086 changes: 0 additions & 1,086 deletions defencemen.csv

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
53 changes: 21 additions & 32 deletions extract_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -36,7 +36,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -83,7 +83,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -94,7 +94,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -117,7 +117,6 @@
" if \"I_F_goals\" in df.columns:\n",
" df[\"finishing\"] = df[\"I_F_goals\"] - df[\"I_F_xGoals\"]\n",
" elif \"goals\" in df.columns:\n",
" print(\"HI\")\n",
" df[\"GSAE\"] = df[\"xGoals\"] - df[\"goals\"]\n",
" df[\"Low_Danger\"] = df[\"lowDangerxGoals\"] - df[\"lowDangerGoals\"]\n",
" df[\"Medium_Danger\"] = df[\"mediumDangerxGoals\"] - df[\"mediumDangerGoals\"]\n",
Expand All @@ -128,7 +127,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -145,7 +144,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -159,7 +158,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -236,17 +235,18 @@
}
],
"source": [
"# Extract data from each position\n",
"defencemen, centers, left_wing, right_wing, forwards, goalies = extract_skater_data()\n",
"\n",
"\n",
"defencemen.drop(columns=[\"faceoffsWon\", \"faceoffsLost\", \"I_F_faceOffsWon\"], inplace=True)\n",
"print(defencemen)\n",
"goalies.to_csv(\"./goalies.csv\", index=False)"
"goalies.to_csv(\"./extractDataTestCSVs/goalies.csv\", index=False)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 14,
"metadata": {},
"outputs": [
{
Expand All @@ -266,6 +266,7 @@
}
],
"source": [
"# Extract situational data for defence\n",
"evenStrengthD, powerPlayD, penaltyKillD, allSituationsD, otherD = extract_skater_situational_data(defencemen)\n",
"%store evenStrengthD\n",
"%store penaltyKillD\n",
Expand All @@ -275,6 +276,7 @@
"powerPlayD_names, powerPlayD_data = split_data_and_names(powerPlayD)\n",
"penaltyKillD_names, penaltyKillD_data = split_data_and_names(penaltyKillD)\n",
"\n",
"# Transform data to per 60 \n",
"transformed_defence_data = transform_data_per_60(evenStrengthD_data)\n",
"transformed_ppD_data = transform_data_per_60(powerPlayD_data)\n",
"transformed_pkD_data = transform_data_per_60(penaltyKillD_data)\n",
Expand All @@ -288,12 +290,12 @@
"%store penaltyKillD_names\n",
"\n",
"test_df = pd.concat([evenStrengthD_names, transformed_defence_data], axis=1)\n",
"test_df.to_csv(\"./evenStrengthDPer60.csv\", index=False)"
"test_df.to_csv(\"./extractDataTestCSVs/evenStrengthDPer60.csv\", index=False)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 15,
"metadata": {},
"outputs": [
{
Expand All @@ -313,7 +315,8 @@
}
],
"source": [
"forwards.to_csv(\"./forwards.csv\", index=False)\n",
"# Extract situational data for forwards\n",
"forwards.to_csv(\"./extractDataTestCSVs/forwards.csv\", index=False)\n",
"evenStrengthF, powerPlayF, penaltyKillF, allSituationsF, otherF = extract_skater_situational_data(forwards)\n",
"%store evenStrengthF\n",
"%store powerPlayF\n",
Expand All @@ -323,6 +326,7 @@
"powerPlayF_names, powerPlayF_data = split_data_and_names(powerPlayF)\n",
"penaltyKillF_names, penaltyKillF_data = split_data_and_names(penaltyKillF)\n",
"\n",
"# Transform data to per 60 rates\n",
"transformed_forward_data = transform_data_per_60(evenStrengthF_data)\n",
"transformed_ppF_data = transform_data_per_60(powerPlayF_data)\n",
"transformed_pkF_data = transform_data_per_60(penaltyKillF_data)\n",
Expand All @@ -338,7 +342,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 18,
"metadata": {},
"outputs": [
{
Expand All @@ -348,21 +352,6 @@
"Stored 'evenStrengthG' (DataFrame)\n",
"Stored 'powerPlayG' (DataFrame)\n",
"Stored 'penaltyKillG' (DataFrame)\n",
"2 5666667\n",
"7 4000000\n",
"12 1500000\n",
"17 5000000\n",
"22 5000000\n",
" ... \n",
"322 4750000\n",
"327 766666\n",
"332 1100000\n",
"337 5250000\n",
"342 962500\n",
"Name: cap_hit, Length: 69, dtype: int64\n",
"HI\n",
"HI\n",
"HI\n",
"Stored 'transformed_goalie_data' (DataFrame)\n",
"Stored 'evenStrengthG_names' (DataFrame)\n",
"Stored 'transformed_ppG_data' (DataFrame)\n",
Expand All @@ -373,19 +362,19 @@
}
],
"source": [
"# Extract situational data for goalies\n",
"evenStrengthG, powerPlayG, penaltyKillG, allSituationsG, otherG = extract_skater_situational_data(goalies)\n",
"%store evenStrengthG\n",
"%store powerPlayG\n",
"%store penaltyKillG\n",
"\n",
"print(evenStrengthG[\"cap_hit\"])\n",
"\n",
"\n",
"evenStrengthG, powerPlayG, penaltyKillG = remove_barely_played(evenStrengthG), remove_barely_played(powerPlayG), remove_barely_played(penaltyKillG)\n",
"evenStrengthG_names, evenStrengthG_data = split_data_and_names(evenStrengthG)\n",
"powerPlayG_names, powerPlayG_data = split_data_and_names(powerPlayG)\n",
"penaltyKillG_names, penaltyKillG_data = split_data_and_names(penaltyKillG)\n",
"\n",
"# Transform goalie data to per 60 rates\n",
"transformed_goalie_data = transform_data_per_60(evenStrengthG_data)\n",
"transformed_ppG_data = transform_data_per_60(powerPlayG_data)\n",
"transformed_pkG_data = transform_data_per_60(penaltyKillG_data)\n",
Expand Down Expand Up @@ -416,7 +405,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.9.12"
}
},
"nbformat": 4,
Expand Down
50 changes: 11 additions & 39 deletions percentile.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -14,7 +14,6 @@
"from sqlalchemy import create_engine\n",
"\n",
"np.warnings = warnings\n",
"import import_ipynb\n",
"%store -r transformed_defence_data\n",
"%store -r evenStrengthD_names\n",
"%store -r transformed_ppD_data\n",
Expand All @@ -32,52 +31,27 @@
"%store -r transformed_ppG_data\n",
"%store -r powerPlayG_names\n",
"%store -r transformed_pkG_data\n",
"%store -r penaltyKillG_names\n",
"\n",
"offensive_stats = transformed_defence_data.filter(regex=\"I_F\").columns\n",
"OnIce = transformed_defence_data.filter(regex=\"OnIce_F\").columns\n",
"offensive_stats = offensive_stats.append(OnIce)\n",
"offensive_stats = offensive_stats.drop([\"I_F_takeaways\", \"I_F_hits\", \"I_F_dZoneGiveaways\", 'I_F_oZoneShiftStarts', 'I_F_dZoneShiftStarts',\n",
" 'I_F_neutralZoneShiftStarts', 'I_F_flyShiftStarts',\n",
" 'I_F_oZoneShiftEnds', 'I_F_dZoneShiftEnds', 'I_F_neutralZoneShiftEnds',\n",
" 'I_F_flyShiftEnds', 'I_F_shifts', 'I_F_penalityMinutes'])\n",
"\n",
"defensive_other = transformed_defence_data.filter(items=[\"I_F_takeaways\", \"I_F_dZoneGiveaways\", \"shotsBlockedByPlayer\"]).columns\n",
"defensive_stats = transformed_defence_data.filter(regex=\"OnIce_A\").columns\n",
"defensive_stats = defensive_stats.append(defensive_other)\n",
"defensive_stats = defensive_stats.append(transformed_defence_data.filter(items=[\"team_rank\"]).columns)\n",
"\n",
"#involve both offensive and defensive stats\n",
"general_stats = transformed_defence_data.filter(items=[\"onIce_xGoalsPercentage\", \"onIce_corsiPercentage\", \n",
" \"onIce_fenwickPercentage\", \"gameScore\"]).columns\n",
"#both_stats = [\"onIce_xGoalsPercentage\", \"onIce_corsiPercentage\", \"onIce_fenwickPercentage\"]\n",
"\n",
"penalty_stats_negative = [\"penalties\", \"I_F_penalityMinutes\"]\n",
"penalty_stats_positive = [\"penalityMinutesDrawn\", \"penaltiesDrawn\"]\n",
"penalty_stats = [\"penalties\", \"I_F_penalityMinutes\", \"penalityMinutesDrawn\", \"penaltiesDrawn\"]\n",
"\n",
"hits = [\"I_F_hits\"]\n",
"\n",
"original_forward_team_rank = transformed_forward_data[\"team_rank\"]\n",
"original_defense_team_rank = transformed_defence_data[\"team_rank\"]"
"%store -r penaltyKillG_names"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Return the percentile of each player's stats in a given dataframe\n",
"def get_percentile_rank(df):\n",
" return df.rank(pct=True).mul(100)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# Calculate the percentile ranks and put them inside the postgres database\n",
"def create_postgres_percentile_tables(position, evenStrengthData, evenStrengthNames, powerPlayData, powerPlayNames,\n",
" penaltyKillData, penaltyKillNames):\n",
"\n",
Expand All @@ -103,18 +77,16 @@
" evenStrength.to_sql(\"evGoaliePercentile\", engine, if_exists=\"replace\", index=False, schema=\"Percentile\")\n",
" powerPlay.to_sql(\"ppGoaliePercentile\", engine, if_exists=\"replace\", index=False, schema=\"Percentile\")\n",
" penaltyKill.to_sql(\"pkGoaliePercentile\", engine, if_exists=\"replace\", index=False, schema=\"Percentile\")\n",
" \n",
" \n",
"\n",
"\n"
" "
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# Add prefixes for each situation\n",
"transformed_forward_data = transformed_forward_data.add_prefix(\"EV_\")\n",
"transformed_defence_data = transformed_defence_data.add_prefix(\"EV_\")\n",
"transformed_goalie_data = transformed_goalie_data.add_prefix(\"EV_\")\n",
Expand All @@ -130,7 +102,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -159,7 +131,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.9.12"
}
},
"nbformat": 4,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 2401178

Please sign in to comment.