From 84ec845e8bf18e06bb726c225c50d30eb1431961 Mon Sep 17 00:00:00 2001 From: Ben Burlingham Date: Wed, 26 Oct 2016 20:09:13 -0700 Subject: [PATCH] Built sorters goals for, goals against. --- js/diagram.js | 51 ++++++++++++++++++++++++++++++++++++++++++++------- js/sorter.js | 4 ++-- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/js/diagram.js b/js/diagram.js index f0bcd7c..ba0a354 100644 --- a/js/diagram.js +++ b/js/diagram.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]; }); }, }; diff --git a/js/sorter.js b/js/sorter.js index 727687c..3c03a3b 100644 --- a/js/sorter.js +++ b/js/sorter.js @@ -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; }