Built sorters goals for, goals against.

master
Ben Burlingham 9 years ago
parent d21b3022f9
commit 84ec845e8b
  1. 51
      js/diagram.js
  2. 4
      js/sorter.js

@ -101,11 +101,47 @@ const Diagram = {
return data.countries[countryId].n;
},
// getGoalsFor: (data, eventIndex, n) => {
// data.tourneys[eventIndex].games.reduce(
//
// return Math.round(100 * Math.random);
// },
getGoalsFor: (data, eventIndex, n) => {
const teamId = data.tourneys[eventIndex].teams[n];
if (goalsFor[teamId] === undefined) {
goalsFor[teamId] = data.tourneys[eventIndex].games.reduce((acc, v) => {
if (v.t1 === teamId) {
return acc + v.s1 + v.se1 + v.sp1;
}
if (v.t2 === teamId) {
return acc + v.s2 + v.se2 + v.sp2;
}
return acc;
}, 0);
}
return goalsFor[teamId];
},
getGoalsAgainst: (data, eventIndex, n) => {
const teamId = data.tourneys[eventIndex].teams[n];
if (goalsAgainst[teamId] === undefined) {
goalsAgainst[teamId] = data.tourneys[eventIndex].games.reduce((acc, v) => {
if (v.t2 === teamId) {
return acc + v.s1 + v.se1 + v.sp1;
}
if (v.t1 === teamId) {
return acc + v.s2 + v.se2 + v.sp2;
}
return acc;
}, 0);
}
return goalsAgainst[teamId];
},
build: (data, eventIndex, metaMatrix, chordMatrix) => {
const svg = d3.select("svg"),
@ -122,6 +158,7 @@ const Diagram = {
const sortedChords = Sorter.sort(chords, 0, chords.groups.length - 1,
Diagram.getCountryName.bind(null, data, eventIndex),
// Diagram.getGoalsFor.bind(null, data, eventIndex),
// Diagram.getGoalsAgainst.bind(null, data, eventIndex),
Diagram.swapGroups.bind(null, data, eventIndex));
const arc = d3.arc()
@ -204,8 +241,8 @@ const Diagram = {
// STRANGE EXTENDED TIME CHILE-BRAZIL - FIX BY HAND? IS BECAUE se1 IS SCORE __GOING INTO__ EXTENDED TIME
// console.info(metaMatrix[d.index])
const t = data.tourneys[eventIndex].teams[d.index];
return data.countries[data.teams[t]].n + ' ' + d.index;
const teamId = data.tourneys[eventIndex].teams[d.index];
return data.countries[data.teams[teamId]].n + ' ' + goalsAgainst[teamId];
});
},
};

@ -30,8 +30,8 @@ const Sorter = {
break;
}
this.sort(chords, start, right, getVal, swap);
this.sort(chords, left, end, getVal, swap);
Sorter.sort(chords, start, right, getVal, swap);
Sorter.sort(chords, left, end, getVal, swap);
return chords;
}

Loading…
Cancel
Save