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.
 
 
 
 
 

33 lines
951 B

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));
},
// Scalar data points (sum of goals scored).
buildMatrix: (json, eventKey) => {
const teams = json.tourneys[eventKey].teams;
const matrix = Matrices.createEmptyMatrix(teams.length);
json.tourneys[eventKey].games.forEach(g => {
const i1 = teams.findIndex(v => v.tId === g.t1);
const i2 = teams.findIndex(v => v.tId === g.t2);
matrix[i1][i2] = g.s1 + g.se1 + g.sp1;
matrix[i2][i1] = g.s2 + g.se2 + g.sp2;
}, []);
return matrix;
},
swapIndices: (arr, i, j) => {
const tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
return arr;
},
};
export default Matrices;