data = {
const parseDate = d3.timeParse("%b %d %Y");
let file_data = await FileAttachment("msu_2021_record@1.csv").csv({typed: true});
file_data = file_data.reverse();
file_data.map((d,i) => {
d.date = parseDate(d.date);
d.won = d.runs_scored > d.runs_allowed;
if (i === 0) {
d.runs_scored_total = d.runs_scored;
d.runs_allowed_total = d.runs_allowed;
d.wins = d.won ? 1 : 0;
d.losses = d.won ? 0 : 1;
} else {
d.runs_scored_total = d.runs_scored + file_data[i-1].runs_scored_total;
d.runs_allowed_total = d.runs_allowed + file_data[i-1].runs_allowed_total;
d.wins = d.won ? file_data[i-1].wins + 1 : file_data[i-1].wins;
d.losses = d.won ? file_data[i-1].losses : file_data[i-1].losses + 1;
}
});
return file_data;
}