From de9134c47b5ff76261fa18ce9f64cdac178c87a6 Mon Sep 17 00:00:00 2001 From: Sendou Date: Mon, 6 Jan 2020 20:01:47 +0200 Subject: [PATCH] endvoting switched to counts --- graphql-schemas/plus.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/graphql-schemas/plus.js b/graphql-schemas/plus.js index d378aa96b..f88569009 100644 --- a/graphql-schemas/plus.js +++ b/graphql-schemas/plus.js @@ -93,8 +93,8 @@ const typeDef = gql` type Score { total: Float! - eu: Float! - na: Float! + eu_count: [Int]! + na_count: [Int]! } "Voting result of a player" @@ -585,6 +585,16 @@ const resolvers = { 100 ).toFixed(2) + const countReducer = (acc, cur) => { + const scoreMap = { "-2": 0, "-1": 1, "1": 2, "2": 3 } + const scoreIndex = scoreMap[cur] + if (!acc[scoreIndex]) acc[scoreIndex] = 1 + else acc[scoreIndex] = acc[scoreIndex] + 1 + } + + const same_count = same_region.reduce(countReducer, []) + const other_count = other_region.reduce(countReducer, []) + const summary = { discord_id, plus_server: arrays_plus_server, @@ -592,8 +602,8 @@ const resolvers = { year, score: { total: total_score, - eu: plus_region === "EU" ? same_score : other_score, - na: plus_region === "EU" ? other_score : same_score, + eu_count: plus_region === "EU" ? same_count : other_count, + na_count: plus_region === "EU" ? other_count : same_count, }, }