From c4e8dc828bef2f80cf41b9ea7b420442a83a6d50 Mon Sep 17 00:00:00 2001 From: Sendou Date: Mon, 10 Feb 2020 18:56:00 +0200 Subject: [PATCH 1/3] 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], }, }) From edeced70249aac05a7c2036130f0267c20342bd6 Mon Sep 17 00:00:00 2001 From: Sendou Date: Sat, 15 Feb 2020 00:41:49 +0200 Subject: [PATCH 2/3] xPowers query --- graphql-schemas/plus.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/graphql-schemas/plus.js b/graphql-schemas/plus.js index 9b234f4bf..d23c2fa96 100644 --- a/graphql-schemas/plus.js +++ b/graphql-schemas/plus.js @@ -9,11 +9,14 @@ const Suggested = require("../mongoose-models/suggested") const Summary = require("../mongoose-models/summary") const VotedPerson = require("../mongoose-models/votedperson") const State = require("../mongoose-models/state") +const Player = require("../mongoose-models/player") +const Placement = require("../mongoose-models/placement") const typeDef = gql` extend type Query { plusInfo: PlusGeneralInfo hasAccess(discord_id: String!, server: String!): Boolean! + xPowers(discord_id: String!): [Int]! suggestions: [Suggested!] vouches: [User!] usersForVoting: UsersForVoting! @@ -226,6 +229,36 @@ const resolvers = { eligible_voters, } }, + xPowers: async (root, args, ctx) => { + const user = await User.findOne({ discord_id: args.discord_id }) + if (!user || !user.twitter_name) return [null, null, null, null] + + const twitter = user.twitter_name.toLowerCase() + + const player = await Player.findOne({ + twitter, + }) + + if (!player) return [null, null, null, null] + + const placements = await Placement.find({ unique_id: player.unique_id }) + + return placements.reduce( + (acc, cur) => { + const modeIndex = cur.mode - 1 + const xPower = Math.floor(cur.x_power / 100) * 100 + + if (acc[modeIndex] === null) { + acc[modeIndex] = xPower + } else if (xPower > acc[modeIndex]) { + acc[modeIndex] = xPower + } + + return acc + }, + [null, null, null, null] + ) + }, usersForVoting: async (root, args, ctx) => { if (!ctx.user) throw new UserInputError("Not logged in") if (!ctx.user.plus || !ctx.user.plus.membership_status) From 629ce13083fac727bff2055462c6bb653703ad26 Mon Sep 17 00:00:00 2001 From: Sendou Date: Sat, 15 Feb 2020 13:25:11 +0200 Subject: [PATCH 3/3] hasAccess new version --- graphql-schemas/plus.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/graphql-schemas/plus.js b/graphql-schemas/plus.js index d23c2fa96..27ee59d57 100644 --- a/graphql-schemas/plus.js +++ b/graphql-schemas/plus.js @@ -15,7 +15,7 @@ const Placement = require("../mongoose-models/placement") const typeDef = gql` extend type Query { plusInfo: PlusGeneralInfo - hasAccess(discord_id: String!, server: String!): Boolean! + hasAccess(discord_id: String!): String xPowers(discord_id: String!): [Int]! suggestions: [Suggested!] vouches: [User!] @@ -179,10 +179,7 @@ const resolvers = { ? "ONE" : membership_code - if (membership_code === "ONE") return true - if (membership_code === "TWO" && args.server === "TWO") return true - - return false + return membership_code }, plusInfo: async (root, args, ctx) => { if (!ctx.user) return null