From 036355dce60420eaf4d03e252a0ab49e8f43f3ed Mon Sep 17 00:00:00 2001 From: Matthew R Date: Tue, 6 Oct 2020 15:06:02 -0400 Subject: [PATCH] add percentiles --- src/commands/score.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/commands/score.ts b/src/commands/score.ts index 94717ca..c42bb26 100644 --- a/src/commands/score.ts +++ b/src/commands/score.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-continue */ /* eslint-disable default-case */ import { Message, User, TextChannel } from 'eris'; import { Client, Command, RichEmbed } from '../class'; @@ -137,6 +138,14 @@ export default class Score extends Command { else cloudServicesScore = `${score.cloudServices}`; } // else return this.error(message.channel, 'Community Score has not been calculated yet.'); + const set = []; + const accounts = await this.client.db.Score.find().lean().exec(); + for (const sc of accounts) { + if (sc.total < 200) { continue; } + if (sc.total > 800) { set.push(800); continue; } + set.push(sc.total); + } + const percentile = this.client.util.percentile(set, score.total); const embed = new RichEmbed(); embed.setTitle('Community Score'); embed.setAuthor(user.username, user.avatarURL); @@ -162,7 +171,7 @@ export default class Score extends Command { if (score.total >= 630) { color = '🟡'; additionalText = 'GOOD'; embed.setColor('FFFF00'); } if (score.total >= 700) { color = '🟢'; additionalText = 'EXCELLENT'; embed.setColor('66FF66'); } if (score.total >= 770) { color = '✨'; additionalText = 'EXCEPTIONAL'; embed.setColor('#99FFFF'); } - embed.addField('Total | 200 to 800', `${color} ${totalScore} | ${additionalText}`, true); + embed.addField('Total | 200 to 800', score ? `${color} ${totalScore} | ${additionalText} | ${this.client.util.ordinal(Math.round(percentile))}` : 'N/C', true); embed.addField(`Activity | 10 to ${Math.floor(Math.log1p(3000 + 300 + 200 + 100) * 12)}`, activityScore || 'N/C', true); embed.addField('Roles | 1 to N/A', roleScore || 'N/C', true); embed.addField('Moderation | N/A to 2' || 'N/C', moderationScore, true);