From c4e8dc828bef2f80cf41b9ea7b420442a83a6d50 Mon Sep 17 00:00:00 2001 From: Sendou Date: Mon, 10 Feb 2020 18:56:00 +0200 Subject: [PATCH] voting with counts --- .../src/components/plus/SummaryLists.js | 8 ++++++-- .../src/graphql/queries/summaries.js | 4 ++-- graphql-schemas/plus.js | 18 ++++-------------- mongoose-models/summary.js | 6 ++++-- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/frontend-react/src/components/plus/SummaryLists.js b/frontend-react/src/components/plus/SummaryLists.js index 1bb58a731..ebeb96283 100644 --- a/frontend-react/src/components/plus/SummaryLists.js +++ b/frontend-react/src/components/plus/SummaryLists.js @@ -22,8 +22,12 @@ const summaryMap = summary => { {score.total}% {" "} - (EU {score.eu}% | NA{" "} - {score.na}%) + {score.eu_count.length > 0 && ( + <> + (EU {score.eu_count.join("/")} | NA{" "} + {score.na_count.join("/")}) + + )} {summary.vouched && ( acc + cur) const other_total = other_region.reduce((acc, cur) => acc + cur) - const same_score = +( - ((same_total / same_region.length + 2) / 4) * - 100 - ).toFixed(2) - - const other_score = +( - ((other_total / other_region.length + 1) / 2) * - 100 - ).toFixed(2) - const total_score = +( ((same_total / same_region.length + other_total / other_region.length + @@ -660,10 +648,12 @@ const resolvers = { const scoreIndex = scoreMap[cur] if (!acc[scoreIndex]) acc[scoreIndex] = 1 else acc[scoreIndex] = acc[scoreIndex] + 1 + + return acc } - const same_count = same_region.reduce(countReducer, []) - const other_count = other_region.reduce(countReducer, []) + const same_count = same_region.reduce(countReducer, [0, 0, 0, 0]) + const other_count = other_region.reduce(countReducer, [0, 0, 0, 0]) const summary = { discord_id, diff --git a/mongoose-models/summary.js b/mongoose-models/summary.js index d98e4477a..59da3465a 100644 --- a/mongoose-models/summary.js +++ b/mongoose-models/summary.js @@ -9,8 +9,10 @@ const summarySchema = new mongoose.Schema({ suggested: Boolean, score: { total: { type: Number, required: true, min: 0, max: 100 }, - eu: { type: Number, required: true, min: 0, max: 100 }, - na: { type: Number, required: true, min: 0, max: 100 }, + eu: { type: Number, min: 0, max: 100 }, + na: { type: Number, min: 0, max: 100 }, + eu_count: [Number], + na_count: [Number], }, })