Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .github/workflows/nextjs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Deploy Next.js site to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
# branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down Expand Up @@ -43,9 +43,13 @@ jobs:
- name: Run Python script
run: |
set -e
python scripts/team_data.py
python scripts/qb_weekly.py
python scripts/qb_season.py
python run_scripts.py
# python scripts/ngs_passing.py
# python scripts/ngs_receiving.py
# python scripts/ngs_rushing.py
# python scripts/qb_season.py
# python scripts/qb_weekly.py
# python scripts/team_data.py

# Upload the file the script produced
- name: Upload Python output
Expand All @@ -57,6 +61,9 @@ jobs:
scripts/generated-files/team-data.ts
scripts/generated-files/qb-data-weekly.ts
scripts/generated-files/qb-data-season.ts
scripts/generated-files/ngs-data-passing.ts
scripts/generated-files/ngs-data-receiving.ts
scripts/generated-files/ngs-data-rushing.ts

# Build job
build:
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ npm-debug.log*
next-env.d.ts

# script outputs
/scripts/generated-files/*.ts
/scripts/generated-files/*.ts

# temporary
/public/qb_test/*
/public/images/players/*
/public/qb_headshots 22.31.32/*
10 changes: 7 additions & 3 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import "@/styles/globals.css";
import type { AppProps } from "next/app";
import "@/styles/globals.css"
import type { AppProps } from "next/app"

export default function App({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />;
return (
<section className="w-full max-w-[1200px] m-auto">
<Component {...pageProps} />
</section>
)
}
24 changes: 11 additions & 13 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { nGSStatsPassing } from "@/scripts/generated-files/ngs-data-passing"
import { nGSStatsReceiving } from "@/scripts/generated-files/ngs-data-receiving"
import { nGSStatsRushing } from "@/scripts/generated-files/ngs-data-rushing"
import { qbDataSeason } from "@/scripts/generated-files/qb-data-season"
import { qbDataWeekly } from "@/scripts/generated-files/qb-data-weekly"
import { teamData } from "@/scripts/generated-files/team-data"
Expand All @@ -12,19 +15,14 @@ export default function Home() {
<main>
<div>
<h1>NFL Stats</h1>
<span className="block">
{teamData ? "has fetched team data" : "has not fetched team data"}
</span>
<span className="block">
{qbDataSeason
? "has fetched QB season data"
: "has not fetched QB data"}
</span>
<span className="block">
{qbDataWeekly
? "has fetched QB weekly data"
: "has not fetched QB data"}
</span>
<ul>
<li>{teamData && "has fetched team data"}</li>
<li>{qbDataSeason && "has fetched QB season data"}</li>
<li>{qbDataWeekly && "has fetched QB weekly data"}</li>
<li>{nGSStatsPassing && "has fetched NGS passing"}</li>
<li>{nGSStatsReceiving && "has fetched NGS passing"}</li>
<li>{nGSStatsRushing && "has fetched NGS passing"}</li>
</ul>
</div>
</main>
</div>
Expand Down
50 changes: 50 additions & 0 deletions pages/qb/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { qbDataSeason } from "@/scripts/generated-files/qb-data-season"
import Head from "next/head"
import Image from "next/image"

export default function Home() {
const qbsSortedTDs = qbDataSeason.sort((a, b) =>
a.passing_tds + a.rushing_tds > b.passing_tds + b.rushing_tds ? -1 : 1
)

return (
<div>
<Head>
<title>NFL Stats</title>
</Head>
<main>
<h1>Quarterback Stats</h1>
<section>
{qbsSortedTDs.map((qb, key) => (
<div key={key} className="flex border-2 border-black p-1 gap-2">
<div className="w-20 h-20 block relative rounded-full">
<Image
// src={qb.headshot_url}
src={`/images/players/qbs/${qb.player_name.replace(
".",
""
)}.jpg`}
alt={qb.player_display_name}
unoptimized
// width="320"
// height="245"
fill={true}
objectFit="cover"
// className="border-2 border-blue-400"
/>
</div>

<div className="flex flex-col border-2 border-red-200">
<div className="flex justify-between">
<span>Name: {qb.player_name}</span>
<span>TDs: {qb.passing_tds + qb.rushing_tds}</span>
</div>
Passing: {qb.passing_tds} Rushing: {qb.rushing_tds}
</div>
</div>
))}
</section>
</main>
</div>
)
}
5 changes: 5 additions & 0 deletions run_scripts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from pathlib import Path
import subprocess

for script in sorted(Path("scripts").glob("*.py")):
subprocess.run(["python", script], check=True)
7 changes: 7 additions & 0 deletions scripts/ngs_passing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from utils.fetch_ngs import parse_ngs

StatType = "passing"
OutputFile = "ngs-data-" + StatType
VariableName = "nGSStats" + StatType.capitalize()

parse_ngs(StatType, OutputFile, VariableName)
7 changes: 7 additions & 0 deletions scripts/ngs_receiving.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from utils.fetch_ngs import parse_ngs

StatType = "receiving"
OutputFile = "ngs-data-" + StatType
VariableName = "nGSStats" + StatType.capitalize()

parse_ngs(StatType, OutputFile, VariableName)
7 changes: 7 additions & 0 deletions scripts/ngs_rushing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from utils.fetch_ngs import parse_ngs

StatType = "rushing"
OutputFile = "ngs-data-" + StatType
VariableName = "nGSStats" + StatType.capitalize()

parse_ngs(StatType, OutputFile, VariableName)
7 changes: 6 additions & 1 deletion scripts/qb_season.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from utils.fetch_qb_data import parse_qbs

parse_qbs("reg", "qb_season", "qb-data-season", "qbDataSeason")
SummaryLevel = "season"
TriggerFileName = "qb_" + SummaryLevel
OutputFileName = "qb-data-" + SummaryLevel
OutputConstName = "qbData" + SummaryLevel.capitalize()

parse_qbs("reg", TriggerFileName, OutputFileName, OutputConstName)
7 changes: 6 additions & 1 deletion scripts/qb_weekly.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from utils.fetch_qb_data import parse_qbs

parse_qbs("week", "qb_weekly", "qb-data-weekly", "qbDataWeekly")
SummaryLevel = "weekly"
TriggerFileName = "qb_" + SummaryLevel
OutputFileName = "qb-data-" + SummaryLevel
OutputConstName = "qbData" + SummaryLevel.capitalize()

parse_qbs("week", TriggerFileName, OutputFileName, OutputConstName)
31 changes: 31 additions & 0 deletions scripts/utils/fetch_ngs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import json
import polars as pl
import nflreadpy as nfl
from pathlib import Path
from typing import Literal

IStatType = Literal["passing", "receiving", "rushing"]

def parse_ngs(statType: IStatType, outputFileName: str, variableName: str):
"""
Fetch current-season next-gen stats and write them to a .ts file
"""
try:
# Fetch next-gen stats (current season by default)
player_stats = nfl.load_nextgen_stats(stat_type=statType).to_dicts()

# Write the data to a TypeScript file
output_path = Path("scripts/generated-files") / f"{outputFileName}.ts"
output_path.parent.mkdir(parents=True, exist_ok=True)

with open(output_path, "w", encoding="utf-8") as f:
f.write("// file generated by fetch_ngs.py\n\n")
f.write("export const " + variableName + " = ")
json.dump(player_stats, f, indent=2)
f.write(";\n")

print(f"Created file {output_path} with {len(player_stats)} " + statType)

except Exception as e:
print(f"ERROR: {e}")
raise
5 changes: 4 additions & 1 deletion scripts/utils/fetch_qb_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
import polars as pl
import nflreadpy as nfl
from pathlib import Path
from typing import Literal

def parse_qbs(summaryLevel, triggerFileName, outputFileName, outputConstName):
ISummaryLevel = Literal["week", "reg", "post", "reg+post"]

def parse_qbs(summaryLevel: ISummaryLevel, triggerFileName: str, outputFileName: str, outputConstName: str):
"""
Fetch current-season QB stats and write them to scripts/qb-data.ts
"""
Expand Down