You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.3 KiB
39 lines
1.3 KiB
const Matrices = {
|
|
// A x A array of nulls; null-null relationships are omitted in chord diagram.
|
|
createEmptyMatrix: (len) => {
|
|
const empty = Array.apply(null, Array(len));
|
|
return empty.map(() => empty.map(() => null));
|
|
},
|
|
|
|
// Identical structure of chord matrix but with { game, team }.
|
|
buildMetaMatrix: (json, eventKey) => {
|
|
const teams = json.tourneys[eventKey].teams;
|
|
const matrix = Matrices.createEmptyMatrix(teams.length);
|
|
|
|
json.tourneys[eventKey].games.forEach(g => {
|
|
const i1 = teams.indexOf(g.t1);
|
|
const i2 = teams.indexOf(g.t2);
|
|
|
|
matrix[i1][i2] = { game: g, team: g.t1 };
|
|
matrix[i2][i1] = { game: g, team: g.t2 };
|
|
}, []);
|
|
|
|
return matrix;
|
|
},
|
|
|
|
// Scalar data points (sum of goals scored).
|
|
buildChordMatrix: (json, eventKey) => {
|
|
const teams = json.tourneys[eventKey].teams;
|
|
const matrix = Matrices.createEmptyMatrix(teams.length);
|
|
|
|
json.tourneys[eventKey].games.forEach(g => {
|
|
const i1 = teams.indexOf(g.t1);
|
|
const i2 = teams.indexOf(g.t2);
|
|
|
|
matrix[i1][i2] = g.s1 + g.se1 + g.sp1;
|
|
matrix[i2][i1] = g.s2 + g.se2 + g.sp2;
|
|
}, []);
|
|
|
|
return matrix;
|
|
},
|
|
};
|
|
|