From 012ce15b1c3b8cfa5a9b2b3415c9a321641b1a4d Mon Sep 17 00:00:00 2001 From: nicidob Date: Sun, 23 Aug 2020 15:06:48 -0400 Subject: [PATCH] added basketball stats --- src/ui/views/Draft.tsx | 9 ++ src/ui/views/DraftScouting/DraftClass.tsx | 15 ++- .../core/player/genCollegeStats.basketball.ts | 112 ++++++++++++++++++ src/worker/core/player/genCollegeStats.ts | 10 ++ src/worker/core/player/generate.ts | 2 + src/worker/views/draft.ts | 2 + src/worker/views/draftScouting.ts | 7 +- 7 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 src/worker/core/player/genCollegeStats.basketball.ts create mode 100644 src/worker/core/player/genCollegeStats.ts diff --git a/src/ui/views/Draft.tsx b/src/ui/views/Draft.tsx index 33370ccaca..91ce95fddf 100644 --- a/src/ui/views/Draft.tsx +++ b/src/ui/views/Draft.tsx @@ -120,6 +120,9 @@ const Draft = ({ "Age", "Ovr", "Pot", + "stat:pts", + "stat:trb", + "stat:ast", "Draft", ); colsUndrafted[1].width = "100%"; @@ -151,6 +154,9 @@ const Draft = ({ p.age, !challengeNoRatings ? p.ratings.ovr : null, !challengeNoRatings ? p.ratings.pot : null, + p.draft.stats.pts, + p.draft.stats.reb, + p.draft.stats.ast,
= 0 ? p.age : null, p.pid >= 0 && !challengeNoRatings ? p.ratings.ovr : null, p.pid >= 0 && !challengeNoRatings ? p.ratings.pot : null, + null, // beyond me + null, + null, ]; if (fantasyDraft || expansionDraft) { diff --git a/src/ui/views/DraftScouting/DraftClass.tsx b/src/ui/views/DraftScouting/DraftClass.tsx index 37ee9946f9..83238bf9aa 100644 --- a/src/ui/views/DraftScouting/DraftClass.tsx +++ b/src/ui/views/DraftScouting/DraftClass.tsx @@ -24,7 +24,17 @@ const DraftClass = ({ const [showImportForm, setShowImportForm] = useState(false); const [status, setStatus] = useState<"exporting" | "loading" | undefined>(); - const cols = getCols("#", "Name", "Pos", "Age", "Ovr", "Pot"); + const cols = getCols( + "#", + "Name", + "Pos", + "Age", + "Ovr", + "Pot", + "stat:pts", + "stat:trb", + "stat:ast", + ); const rows = players.map(p => { return { @@ -38,6 +48,9 @@ const DraftClass = ({ p.age, !challengeNoRatings ? p.ovr : null, !challengeNoRatings ? p.pot : null, + p.draft.pts, + p.draft.reb, + p.draft.ast, ], }; }); diff --git a/src/worker/core/player/genCollegeStats.basketball.ts b/src/worker/core/player/genCollegeStats.basketball.ts new file mode 100644 index 0000000000..829bcf6feb --- /dev/null +++ b/src/worker/core/player/genCollegeStats.basketball.ts @@ -0,0 +1,112 @@ +import type { PlayerRatings } from "../../../common/types.basketball"; +import { helpers } from "../../util"; + +const genCollegeStatsBasketball = ( + ratings: PlayerRatings, +): Record => { + const ratingsPCA = { + stre: [ + -1.1957165757730195e-5, + -4.453965364797136e-5, + 0.00010640966922795406, + ], + spd: [-1.5212440648288379e-5, 8.55433941486269e-5, 0.0001384653780109442], + jmp: [-1.521772287466695e-5, 8.597019189612675e-5, 0.00013909806853692463], + endu: [-6.785704603510037e-6, 6.372144097151289e-6, 1.8332595343908894e-6], + ins: [-9.87840453428284e-6, -9.560840707275353e-5, -1.895865125161545e-5], + dnk: [ + -1.142622342117044e-5, + -4.6973032434937114e-5, + 0.00015301011775222147, + ], + ft: [-1.0577661869240935e-5, 6.593115872306804e-5, -4.0036404757528906e-5], + fg: [-1.059031380633017e-5, 6.593871478474993e-5, -3.958149438851853e-5], + tp: [-1.0572818214344663e-5, 6.563161248023762e-5, -4.011677983637406e-5], + oiq: [ + -7.969437900770308e-6, + -8.947535801699055e-6, + -0.00010341249600635312, + ], + diq: [-8.149386301838323e-6, -4.051564134201123e-5, -9.300493866457778e-5], + drb: [-1.3061947879877261e-5, 3.40811567941367e-5, -0.00015104368632591029], + pss: [ + -1.2086636169940184e-5, + 2.2431001311058523e-5, + -0.0001690471861140337, + ], + reb: [ + -1.258550762820505e-5, + -9.346464479107998e-5, + -0.00011990679173511645, + ], + hgt: [-1.3809375087572575e-5, -0.0001352125223682471, 9.450968663108081e-5], + }; + const pcaWeights = { + pts: [-4951.373, -201.241, 44.672, -25.301], + orb: [-528.388, -160.513, -2.362, -2.632], + drb: [-1417.591, -327.953, 6.586, -6.587], + ast: [-1186.993, 133.778, -309.548, -6.791], + stl: [-551.645, 3.296, -4.414, -2.901], + blk: [-237.62, -54.105, 38.411, -1.178], + min: [-5052.907, -58.646, -28.55, -7.304], + }; + // uhh... properties aren't string-accessible in ratings?? + const pca = [0, 1, 2].map( + x => + ratings.diq * ratingsPCA.diq[x] + + ratings.dnk * ratingsPCA.dnk[x] + + ratings.drb * ratingsPCA.drb[x] + + ratings.endu * ratingsPCA.endu[x] + + ratings.fg * ratingsPCA.fg[x] + + ratings.ft * ratingsPCA.ft[x] + + ratings.hgt * ratingsPCA.hgt[x] + + ratings.ins * ratingsPCA.ins[x] + + ratings.jmp * ratingsPCA.jmp[x] + + ratings.oiq * ratingsPCA.oiq[x] + + ratings.pss * ratingsPCA.pss[x] + + ratings.reb * ratingsPCA.reb[x] + + ratings.spd * ratingsPCA.spd[x] + + ratings.stre * ratingsPCA.stre[x] + + ratings.tp * ratingsPCA.tp[x], + ); + const res = { + pts: Math.round( + helpers.bound( + pca[0] * pcaWeights.pts[0] + + pca[1] * pcaWeights.pts[1] + + pca[2] * pcaWeights.pts[2] + + pcaWeights.pts[3], + 0, + 50, + ), + ), + reb: Math.round( + helpers.bound( + pca[0] * pcaWeights.orb[0] + + pca[1] * pcaWeights.orb[1] + + pca[2] * pcaWeights.orb[2] + + pcaWeights.orb[3] + + pca[0] * pcaWeights.drb[0] + + pca[1] * pcaWeights.drb[1] + + pca[2] * pcaWeights.drb[2] + + pcaWeights.drb[3], + 0, + 50, + ), + ), + ast: Math.round( + helpers.bound( + pca[0] * pcaWeights.ast[0] + + pca[1] * pcaWeights.ast[1] + + pca[2] * pcaWeights.ast[2] + + pcaWeights.ast[3], + 0, + 50, + ), + ), + }; + //console.log(ratings.ovr,pca,res); + return res; +}; + +export default genCollegeStatsBasketball; diff --git a/src/worker/core/player/genCollegeStats.ts b/src/worker/core/player/genCollegeStats.ts new file mode 100644 index 0000000000..dca729edac --- /dev/null +++ b/src/worker/core/player/genCollegeStats.ts @@ -0,0 +1,10 @@ +import genCollegeStatsBasketball from "./genCollegeStats.basketball"; + +const genCollegeStats = (ratings: any) => { + if (process.env.SPORT === "football") { + return { pts: 0, reb: 0, ast: 0 }; + } + return genCollegeStatsBasketball(ratings); +}; + +export default genCollegeStats; diff --git a/src/worker/core/player/generate.ts b/src/worker/core/player/generate.ts index e28d821a7d..df37ea83f4 100644 --- a/src/worker/core/player/generate.ts +++ b/src/worker/core/player/generate.ts @@ -6,6 +6,7 @@ import type { PlayerWithoutKey, } from "../../../common/types"; import genWeight from "./genWeight"; +import genCollegeStats from "./genCollegeStats"; const generate = ( tid: number, @@ -41,6 +42,7 @@ const generate = ( pot: 0, ovr: 0, skills: [], + stats: genCollegeStats(ratings), }, face: face.generate(), firstName, diff --git a/src/worker/views/draft.ts b/src/worker/views/draft.ts index d3d9177192..8ab79a392d 100644 --- a/src/worker/views/draft.ts +++ b/src/worker/views/draft.ts @@ -70,6 +70,7 @@ const updateDraft = async (inputs: unknown, updateEvents: UpdateEvents) => { "abbrev", "tid", "valueFuzz", + "draft", ], ratings: ["ovr", "pot", "skills", "pos"], stats, @@ -118,6 +119,7 @@ const updateDraft = async (inputs: unknown, updateEvents: UpdateEvents) => { "watch", "prevTid", "prevAbbrev", + "draft", ], ratings: ["ovr", "pot", "skills", "pos"], stats: ["per", "ewa"], diff --git a/src/worker/views/draftScouting.ts b/src/worker/views/draftScouting.ts index 46a3666be3..8b466e5fa3 100644 --- a/src/worker/views/draftScouting.ts +++ b/src/worker/views/draftScouting.ts @@ -6,7 +6,7 @@ import type { UpdateEvents, Player, ThenArg } from "../../common/types"; const getSeason = async (playersAll: Player[], season: number) => { const playersAllFiltered = playersAll.filter(p => p.draft.year === season); const players = await idb.getCopies.playersPlus(playersAllFiltered, { - attrs: ["pid", "nameAbbrev", "age", "valueFuzz", "watch"], + attrs: ["pid", "nameAbbrev", "age", "valueFuzz", "watch", "draft"], ratings: ["ovr", "pot", "skills", "fuzz", "pos"], showNoStats: true, showRookies: true, @@ -25,6 +25,11 @@ const getSeason = async (playersAll: Player[], season: number) => { pot: pa.ratings[0].pot, skills: pa.ratings[0].skills, pos: pa.ratings[0].pos, + draft: { + pts: pa.draft.stats.pts, + reb: pa.draft.stats.reb, + ast: pa.draft.stats.ast, + }, rank: i + 1, }));