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.
 
 
 
 
 

56 lines
1.4 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));
},
// 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);
let s1 = matrix[i1][i2] || 0;
let s2 = matrix[i2][i1] || 0;
if (g.sp1 !== null) {
s1 += g.sp1;
}
else if (g.se1 !== null) {
s1 += g.se1;
}
else {
s1 += g.s1;
}
if (g.sp2 !== null) {
s2 += g.sp2;
}
else if (g.se2 !== null) {
s2 += g.se2;
}
else {
s2 += g.s2;
}
matrix[i1][i2] = s1;
matrix[i2][i1] = s2;
}, []);
return matrix;
},
swapIndices: (arr, i, j) => {
const tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
return arr;
},
};
export default Matrices;