Skip to content

Commit 15d3934

Browse files
committed
Added ability to select a team for the salary vs rating graphs
1 parent 74d84a3 commit 15d3934

2 files changed

Lines changed: 41 additions & 17 deletions

File tree

src/StatViz.md

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ toc: false
77
```js
88
// Load the data files
99
const stats = await FileAttachment("./data/stats.json").json();
10+
11+
const teamSelector = Inputs.select(["All", ...stats.teams], {label: "Select Team:"});
12+
const selectedTeam = Generators.input(teamSelector);
13+
1014
```
1115

1216
<h3>Goal Distribution</h3>
@@ -59,30 +63,47 @@ ${Plot.plot({
5963
]
6064
})}
6165

66+
${teamSelector}
67+
68+
```js
69+
const forwards = stats.contractRanking.filter(s => ((selectedTeam === "All") || (s.Team === selectedTeam)) && (s.Position === "F"));
70+
const defencemen = stats.contractRanking.filter(s => ((selectedTeam === "All") || (s.Team === selectedTeam)) && (s.Position === "D"));
71+
const goalies = stats.contractRanking.filter(s => ((selectedTeam === "All") || (s.Team === selectedTeam)) && (s.Position === "G"));
72+
```
73+
6274
<h3>Forwards Salary vs Rating</h3>
6375
${Plot.plot({
6476
marks: [
65-
Plot.dot(stats.contractRanking.filter(s => s.Position === "F"), { x: "Salary", y: "Rating"}),
66-
Plot.linearRegressionY(stats.contractRanking.filter(s => s.Position === "F"), {x: "Salary", y: "Rating", stroke: "red"}),
67-
Plot.tip(stats.contractRanking.filter(s => s.Position === "F"), Plot.pointer({ x: "Salary", y: "Rating", title: (d) => d.Name }))
77+
Plot.dot(forwards, { x: "Salary", y: "Rating"}),
78+
Plot.linearRegressionY(forwards, {x: "Salary", y: "Rating", stroke: "red"}),
79+
Plot.tip(forwards, Plot.pointer({ x: "Salary", y: "Rating", title: (d) => d.Name }))
6880
]
6981
})}
7082

7183
<h3>Defencemen Salary vs Rating</h3>
7284
${Plot.plot({
7385
marks: [
74-
Plot.dot(stats.contractRanking.filter(s => s.Position === "D"), { x: "Salary", y: "Rating"}),
75-
Plot.linearRegressionY(stats.contractRanking.filter(s => s.Position === "F"), {x: "Salary", y: "Rating", stroke: "red"}),
76-
Plot.tip(stats.contractRanking.filter(s => s.Position === "D"), Plot.pointer({ x: "Salary", y: "Rating", title: (d) => d.Name }))
86+
Plot.dot(defencemen, { x: "Salary", y: "Rating"}),
87+
Plot.linearRegressionY(defencemen, {x: "Salary", y: "Rating", stroke: "red"}),
88+
Plot.tip(defencemen, Plot.pointer({ x: "Salary", y: "Rating", title: (d) => d.Name }))
7789
]
7890
})}
7991

8092
<h3>Goalies Salary vs Rating</h3>
81-
${Plot.plot({
82-
marks: [
83-
Plot.dot(stats.contractRanking.filter(s => s.Position === "G"), { x: "Salary", y: "Rating"}),
84-
Plot.linearRegressionY(stats.contractRanking.filter(s => s.Position === "F"), {x: "Salary", y: "Rating", stroke: "red"}),
85-
Plot.tip(stats.contractRanking.filter(s => s.Position === "G"), Plot.pointer({ x: "Salary", y: "Rating", title: (d) => d.Name })),
86-
]
87-
})}
93+
${
94+
(selectedTeam === "All") ?
95+
Plot.plot({
96+
marks: [
97+
Plot.dot(goalies, { x: "Salary", y: "Rating"}),
98+
Plot.linearRegressionY(goalies, {x: "Salary", y: "Rating", stroke: "red"}),
99+
Plot.tip(goalies, Plot.pointer({ x: "Salary", y: "Rating", title: (d) => d.Name })),
100+
]
101+
}) :
102+
Plot.plot({
103+
marks: [
104+
Plot.dot(goalies, { x: "Salary", y: "Rating"}),
105+
Plot.tip(goalies, Plot.pointer({ x: "Salary", y: "Rating", title: (d) => d.Name })),
106+
]
107+
})
108+
}
88109

src/data/stats.json.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
import { readCsvFile, getOverallStats, latestStatsFile, mapPosition } from "../components/loadfiles.js";
1+
import { readCsvFile, getOverallStats, latestStatsFile, latestRosterFile, mapPosition } from "../components/loadfiles.js";
22

33
const contracts = await readCsvFile("src/data/contracts.csv");
44
const players = await readCsvFile("src/data/player_info.csv");
5+
const teamInfo = await readCsvFile("src/data/team_info.csv");
56

67
const contractRanking = contracts.map(info => {
78

89
const stats = latestStatsFile.find(s => s.hockeyRef === info.ID) || {};
10+
const roster = latestRosterFile.find(r => r.ID === info.ID) || {};
911
const position = mapPosition(stats.pos);
1012
const playerStats = getOverallStats(position, stats);
1113
return {
1214
Name: players.find(p => p.ID === info.ID)?.Name || "Unknown",
15+
Team: roster.ABBR,
1316
Position: position,
1417
Salary: info.Salary || 0,
1518
Rating: playerStats.games_played ? playerStats.rating : 0,
16-
};
17-
});
19+
};
20+
});
1821

1922

2023
// Extract goal distribution - count players by goal totals
@@ -126,4 +129,4 @@ const gstatRanges = Object.keys(gstatDistribution)
126129
}))
127130
.sort((a, b) => a.gstat - b.gstat);
128131

129-
process.stdout.write(JSON.stringify({ goalRanges, assistRanges, toughnessRanges, dstatRanges, gstatRanges, contractRanking }));
132+
process.stdout.write(JSON.stringify({ goalRanges, assistRanges, toughnessRanges, dstatRanges, gstatRanges, contractRanking, teams: teamInfo.map(team => team.ABBR) }));

0 commit comments

Comments
 (0)