From 49b2c7e788ad5db54cf36614e098b8b420fffe52 Mon Sep 17 00:00:00 2001 From: Mati Dastugue Date: Mon, 3 Feb 2020 11:13:02 -0300 Subject: [PATCH 1/3] Fixed MKR Responsiveness logic --- src/components/Home/helpers.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/Home/helpers.tsx b/src/components/Home/helpers.tsx index 593efc5..7093520 100644 --- a/src/components/Home/helpers.tsx +++ b/src/components/Home/helpers.tsx @@ -472,14 +472,19 @@ export const getTimeTakenForExecutives = executives => { } export const getMKRResponsiveness = executives => { + const countedEvents = {} const events = executives.flatMap(vote => vote.timeLine .filter(tl => tl.type === VOTING_ACTION_ADD || tl.type === VOTING_ACTION_LOCK) - .map(v => ({ - ...v, - vote_date: vote.timestamp, - mkr: v.type === VOTING_ACTION_ADD ? v.locked : v.wad, - })), + .map(v => { + if (countedEvents[v.id]) return [] + else countedEvents[v.id] = true + return { + ...v, + vote_date: vote.timestamp, + mkr: v.type === VOTING_ACTION_ADD ? v.locked : v.wad, + } + }), ) const buckets = Array.from({ length: 30 }, (v, i) => i).map(num => ({ from: num, From 42b82f282196844801fec3e679e564b3fddd8d02 Mon Sep 17 00:00:00 2001 From: Mati Dastugue Date: Mon, 3 Feb 2020 13:04:58 -0300 Subject: [PATCH 2/3] Updated fix for MKR Responsiveness --- src/components/Home/helpers.tsx | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/components/Home/helpers.tsx b/src/components/Home/helpers.tsx index 7093520..d291d62 100644 --- a/src/components/Home/helpers.tsx +++ b/src/components/Home/helpers.tsx @@ -473,12 +473,17 @@ export const getTimeTakenForExecutives = executives => { export const getMKRResponsiveness = executives => { const countedEvents = {} + const addEvents = {} const events = executives.flatMap(vote => vote.timeLine .filter(tl => tl.type === VOTING_ACTION_ADD || tl.type === VOTING_ACTION_LOCK) .map(v => { - if (countedEvents[v.id]) return [] - else countedEvents[v.id] = true + const addId = `${vote.id}-${v.sender}` + + if (countedEvents[v.id] || addEvents[addId]) return [] + if (v.type === VOTING_ACTION_ADD) addEvents[addId] = true + countedEvents[v.id] = true + return { ...v, vote_date: vote.timestamp, @@ -504,6 +509,7 @@ export const getMKRResponsiveness = executives => { } export const getPollsMKRResponsiveness = async polls => { + const countedEvents = {} const days = Math.max( ...polls.map(poll => { const start = poll.startDate >= 1e12 ? (poll.startDate / 1e3).toFixed(0) : poll.startDate @@ -526,16 +532,20 @@ export const getPollsMKRResponsiveness = async polls => { return { voters: poll.timeLine .filter(v => v.type === POLL_VOTE_ACTION) - .reduce( - (accum, v) => ({ + .reduce((accum, v) => { + if (countedEvents[v.id]) + return { + ...accum, + } + else countedEvents[v.id] = true + return { ...accum, [v.sender]: accum[v.sender] && accum[v.sender].timestamp < v.timestamp ? accum[v.sender] : { ...v, poll_startDate: poll.startDate, poll_endDate: poll.endDate, poll_id: poll.id }, - }), - {}, - ), + } + }, {}), } }) From 3ce1e392e15e1c156af51a99c137db944d28585d Mon Sep 17 00:00:00 2001 From: Mati Dastugue Date: Mon, 3 Feb 2020 13:29:54 -0300 Subject: [PATCH 3/3] Update Polls Mkr Responsiveness --- src/components/Home/helpers.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/Home/helpers.tsx b/src/components/Home/helpers.tsx index d291d62..2306f76 100644 --- a/src/components/Home/helpers.tsx +++ b/src/components/Home/helpers.tsx @@ -510,6 +510,7 @@ export const getMKRResponsiveness = executives => { export const getPollsMKRResponsiveness = async polls => { const countedEvents = {} + const voteEvents = {} const days = Math.max( ...polls.map(poll => { const start = poll.startDate >= 1e12 ? (poll.startDate / 1e3).toFixed(0) : poll.startDate @@ -533,11 +534,14 @@ export const getPollsMKRResponsiveness = async polls => { voters: poll.timeLine .filter(v => v.type === POLL_VOTE_ACTION) .reduce((accum, v) => { - if (countedEvents[v.id]) + const voteId = `${v.id}-${v.sender}` + if (countedEvents[v.id] || voteEvents[voteId]) return { ...accum, } - else countedEvents[v.id] = true + countedEvents[v.id] = true + countedEvents[voteId] = true + return { ...accum, [v.sender]: