Public
Edited
Feb 28, 2023
Insert cell
Insert cell
Insert cell
create_winloss_chart(conf)
Insert cell
Insert cell
Insert cell
Insert cell
function create_winloss_chart(conference) {
let conference_games = games_by_conference.get(conference);
let teams = _.uniq(
conference_games.map((o) => [o.WTeamName, o.LTeamName]).flat()
);
let losses_by_team = d3.rollup(
conference_games,
(a) => a.length,
(o) => o.LTeamName
);
let wins_by_team = d3.rollup(
conference_games,
(a) => a.length,
(o) => o.WTeamName
);
let div = d3
.create("div")
.style("position", "relative")
.style("width", "260px")
.style("background", "#dedede")
.style("border-radius", "10px")
.style("border", "solid 0.2px #666");

div.append("h3").text(conference_games[0].WTeamConf);
let table = div
.append("table")
.style("width", "240px")
.style("margin-left", "10px");
let head = table.append("tr");
head.append("th").text("Team");
head.append("th").style("text-align", "center").text("Record");
d3.sort(teams, (team) => -wins_by_team.get(team)).forEach(function (team) {
if (team) {
let row = table.append("tr");
row.append("td").text(team.replace(/_/g, " "));
row
.append("td")
.style("text-align", "center")
.text(
`${wins_by_team.get(team) || 0}-${losses_by_team.get(team) || 0}`
);
}
});
return div.node();
}
Insert cell
games_by_conference = d3.group(
games.filter((g) => g.WTeamConfAbbrev == g.LTeamConfAbbrev),
(g) => g.WTeamConfAbbrev
)
Insert cell
games = {
let [games, teams, conferences, team_conferences] = await Promise.all([
FileAttachment("games@1.csv").csv(),
FileAttachment("teams.csv").csv(),
FileAttachment("conferences.csv").csv(),
FileAttachment("team_conferences.csv").csv()
]);

let teamid_to_teamname = d3.rollup(
teams,
(a) => a[0].TeamName,
(o) => o.TeamID
);

let teamid_to_confAbbrev = d3.rollup(
team_conferences,
(a) => a[0].ConfAbbrev,
(o) => o.TeamID
);

let confAbbrev_to_Conference = d3.rollup(
conferences,
(a) => a[0].Description,
(o) => o.ConfAbbrev
);

let teamid_to_conf = (id) =>
confAbbrev_to_Conference.get(teamid_to_confAbbrev.get(id));

games.forEach(function (g) {
g.WTeamName = teamid_to_teamname.get(g.WTeamID);
g.LTeamName = teamid_to_teamname.get(g.LTeamID);
g.WTeamConfAbbrev = teamid_to_confAbbrev.get(g.WTeamID);
g.LTeamConfAbbrev = teamid_to_confAbbrev.get(g.LTeamID);
g.WTeamConf = teamid_to_conf(g.WTeamID);
g.LTeamConf = teamid_to_conf(g.LTeamID);
});

return games;
}
Insert cell
// Ranking based on RPI according to
// https://www.teamrankings.com/ncaa-basketball/rpi-ranking/rpi-rating-by-conf?date=2023-02-27
ranked_conferences = [
"big_twelve",
"sec",
"big_ten",
"mwc",
"big_east",
"acc",
"pac_twelve",
"wcc",
"cusa",
"aac",
"a_ten",
"wac",
"mvc",
"sun_belt",
"ivy",
"a_sun",
"big_west",
"summit",
"mac",
"caa",
"maac",
"aec",
"southern",
"horizon",
"big_sky",
"big_south",
"meac",
"patriot",
"ovc",
"southland",
"nec",
"swac",
"ind"
]
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more