add percentiles

pull/29/head
Matthew 2020-10-06 15:06:02 -04:00
parent 329a4cce9c
commit 036355dce6
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
1 changed files with 10 additions and 1 deletions

View File

@ -1,3 +1,4 @@
/* eslint-disable no-continue */
/* eslint-disable default-case */ /* eslint-disable default-case */
import { Message, User, TextChannel } from 'eris'; import { Message, User, TextChannel } from 'eris';
import { Client, Command, RichEmbed } from '../class'; import { Client, Command, RichEmbed } from '../class';
@ -137,6 +138,14 @@ export default class Score extends Command {
else cloudServicesScore = `${score.cloudServices}`; else cloudServicesScore = `${score.cloudServices}`;
} // else return this.error(message.channel, 'Community Score has not been calculated yet.'); } // 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(); const embed = new RichEmbed();
embed.setTitle('Community Score'); embed.setTitle('Community Score');
embed.setAuthor(user.username, user.avatarURL); 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 >= 630) { color = '🟡'; additionalText = 'GOOD'; embed.setColor('FFFF00'); }
if (score.total >= 700) { color = '🟢'; additionalText = 'EXCELLENT'; embed.setColor('66FF66'); } if (score.total >= 700) { color = '🟢'; additionalText = 'EXCELLENT'; embed.setColor('66FF66'); }
if (score.total >= 770) { color = '✨'; additionalText = 'EXCEPTIONAL'; embed.setColor('#99FFFF'); } 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(`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('Roles | 1 to N/A', roleScore || 'N/C', true);
embed.addField('Moderation | N/A to 2' || 'N/C', moderationScore, true); embed.addField('Moderation | N/A to 2' || 'N/C', moderationScore, true);