From 926b43235a518fca4f215cf8ab067791f9090b6a Mon Sep 17 00:00:00 2001 From: Matthew R Date: Thu, 12 Nov 2020 20:37:24 -0500 Subject: [PATCH] updates to score calculations --- .../comm.libraryofcode.org/routes/report.ts | 15 +++++----- src/commands/apply.ts | 2 +- src/commands/pulldata.ts | 5 ++-- src/commands/score.ts | 5 ++-- src/commands/score_hist.ts | 9 +++--- src/intervals/score.ts | 30 ++++++++++++++++--- 6 files changed, 46 insertions(+), 20 deletions(-) diff --git a/src/api/comm.libraryofcode.org/routes/report.ts b/src/api/comm.libraryofcode.org/routes/report.ts index c5a3091..36132f6 100644 --- a/src/api/comm.libraryofcode.org/routes/report.ts +++ b/src/api/comm.libraryofcode.org/routes/report.ts @@ -5,6 +5,7 @@ import { v4 as uuid } from 'uuid'; import { TextChannel } from 'eris'; import { LocalStorage, Route, Server, RichEmbed } from '../../../class'; import { ScoreHistoricalRaw } from '../../../models/ScoreHistorical'; +import { getTotalMessageCount } from '../../../intervals/score'; export default class Report extends Route { public timeout: Set; @@ -84,7 +85,7 @@ export default class Report extends Route { else totalScore = Math.round(member.total); if (member.activity < 10) activityScore = 0; - else if (member.activity > Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))) activityScore = Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12)); + else if (member.activity > Math.floor((Math.log1p(getTotalMessageCount(this.server.client)) * 12))) activityScore = Math.floor((Math.log1p(getTotalMessageCount(this.server.client)) * 12)); else activityScore = Math.round(member.activity); if (member.roles <= 0) roleScore = 0; @@ -124,7 +125,7 @@ export default class Report extends Route { else total = Math.round(data.report.total); if (data.report.activity < 10) activity = 0; - else if (data.report.activity > Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))) activity = Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12)); + else if (data.report.activity > Math.floor((Math.log1p(getTotalMessageCount(this.server.client)) * 12))) activity = Math.floor((Math.log1p(getTotalMessageCount(this.server.client)) * 12)); else activity = Math.round(data.report.activity); if (data.report.roles <= 0) role = 0; @@ -271,7 +272,7 @@ export default class Report extends Route { let miscScore: number; if (member.activity < 10) activityScore = 0; - else if (member.activity > Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))) activityScore = Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12)); + else if (member.activity > Math.floor((Math.log1p(getTotalMessageCount(this.server.client)) * 12))) activityScore = Math.floor((Math.log1p(getTotalMessageCount(this.server.client)) * 12)); else activityScore = Math.round(member.activity); if (member.roles <= 0) roleScore = 0; @@ -304,7 +305,7 @@ export default class Report extends Route { else total = Math.round(data.report.total); if (data.report.activity < 10) activity = 0; - else if (data.report.activity > Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))) activity = Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12)); + else if (data.report.activity > Math.floor((Math.log1p(getTotalMessageCount(this.server.client)) * 12))) activity = Math.floor((Math.log1p(getTotalMessageCount(this.server.client)) * 12)); else activity = Math.round(data.report.activity); if (data.report.roles <= 0) role = 0; @@ -402,7 +403,7 @@ export default class Report extends Route { let miscScore: number; if (member.activity < 10) activityScore = 0; - else if (member.activity > Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))) activityScore = Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12)); + else if (member.activity > Math.floor((Math.log1p(getTotalMessageCount(this.server.client)) * 12))) activityScore = Math.floor((Math.log1p(getTotalMessageCount(this.server.client)) * 12)); else activityScore = Math.round(member.activity); if (member.roles <= 0) roleScore = 0; @@ -509,7 +510,7 @@ export default class Report extends Route { else totalScore = `${score.total}`; if (score.activity < 10) activityScore = '---'; - else if (score.activity > Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))) activityScore = String(Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))); + else if (score.activity > Math.floor((Math.log1p(getTotalMessageCount(this.server.client)) * 12))) activityScore = String(Math.floor((Math.log1p(getTotalMessageCount(this.server.client)) * 12))); else activityScore = `${score.activity}`; if (score.roles <= 0) roleScore = '---'; @@ -546,7 +547,7 @@ export default class Report extends Route { else total = Math.round(data.report.total); if (data.report.activity < 10) activity = 0; - else if (data.report.activity > Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))) activity = Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12)); + else if (data.report.activity > Math.floor((Math.log1p(getTotalMessageCount(this.server.client)) * 12))) activity = Math.floor((Math.log1p(getTotalMessageCount(this.server.client)) * 12)); else activity = Math.round(data.report.activity); if (data.report.roles <= 0) role = 0; diff --git a/src/commands/apply.ts b/src/commands/apply.ts index 3dc1166..5ee981c 100644 --- a/src/commands/apply.ts +++ b/src/commands/apply.ts @@ -108,7 +108,7 @@ export default class Apply extends Command { embed.setTitle('Instant Application Service [IAS]'); embed.setColor('#556cd6'); if (args[0] !== 'full') { - embed.setDescription(`*These applications are specified targeted to you based on validation conditions. Run \`${this.client.config.prefix}apply full\` for a full list of all applications.*`); + embed.setDescription(`*These applications are specifically targeted to you based on validation conditions. Run \`${this.client.config.prefix}apply full\` for a full list of all applications.*`); embed.setThumbnail(message.member.avatarURL); embed.setAuthor(message.member.username, message.member.avatarURL); } diff --git a/src/commands/pulldata.ts b/src/commands/pulldata.ts index 094d1c0..d1d2c0a 100644 --- a/src/commands/pulldata.ts +++ b/src/commands/pulldata.ts @@ -2,6 +2,7 @@ /* eslint-disable default-case */ import { Message, TextChannel } from 'eris'; import { Client, Command, RichEmbed } from '../class'; +import { getTotalMessageCount } from '../intervals/score'; export default class Score extends Command { constructor(client: Client) { @@ -61,7 +62,7 @@ export default class Score extends Command { else totalScore = `${score.total}`; if (score.activity < 10) activityScore = '---'; - else if (score.activity > Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))) activityScore = String(Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))); + else if (score.activity > Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12))) activityScore = String(Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12))); else activityScore = `${score.activity}`; if (score.roles <= 0) roleScore = '---'; @@ -88,7 +89,7 @@ export default class Score extends Command { 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', score ? `${color} ${totalScore} | ${additionalText}` : '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(getTotalMessageCount(this.client)) * 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); embed.addField('Cloud Services | N/A to 10+', cloudServicesScore || 'N/C', true); diff --git a/src/commands/score.ts b/src/commands/score.ts index 6b9b2cf..0449f2d 100644 --- a/src/commands/score.ts +++ b/src/commands/score.ts @@ -4,6 +4,7 @@ import moment from 'moment'; import { v4 as uuid } from 'uuid'; import { Message, User, TextChannel } from 'eris'; import { Client, Command, RichEmbed } from '../class'; +import { getTotalMessageCount } from '../intervals/score'; import Score_Hist from './score_hist'; import Score_Notify from './score_notify'; import Score_Pref from './score_pref'; @@ -95,7 +96,7 @@ export default class Score extends Command { else totalScore = `${score.total}`; if (score.activity < 10) activityScore = '---'; - else if (score.activity > Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))) activityScore = String(Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))); + else if (score.activity > Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12))) activityScore = String(Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12))); else activityScore = `${score.activity}`; if (score.roles <= 0) roleScore = '---'; @@ -154,7 +155,7 @@ export default class Score extends Command { if (score.total >= 700) { color = '🟢'; additionalText = 'EXCELLENT'; embed.setColor('66FF66'); } if (score.total >= 770) { color = '✨'; additionalText = 'EXCEPTIONAL'; embed.setColor('#99FFFF'); } embed.addField('CommScore™ | 200 to 800', score ? `${color} ${totalScore} | ${additionalText} | ${this.client.util.ordinal(Math.round(percentile))} 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(getTotalMessageCount(this.client)) * 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); embed.addField('Cloud Services | N/A to 10+', cloudServicesScore || 'N/C', true); diff --git a/src/commands/score_hist.ts b/src/commands/score_hist.ts index c7c299f..b7dfd22 100644 --- a/src/commands/score_hist.ts +++ b/src/commands/score_hist.ts @@ -5,6 +5,7 @@ import { median, mode, mean } from 'mathjs'; import { createPaginationEmbed } from 'eris-pagination'; import { Message, User, TextChannel } from 'eris'; import { Client, Command, RichEmbed } from '../class'; +import { getTotalMessageCount } from '../intervals/score'; export default class Score_Hist extends Command { constructor(client: Client) { @@ -55,7 +56,7 @@ export default class Score_Hist extends Command { else totalScore = `${hist.report.total}`; if (hist.report.activity < 10) activityScore = '---'; - else if (hist.report.activity > Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))) activityScore = String(Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))); + else if (hist.report.activity > Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12))) activityScore = String(Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12))); else activityScore = `${hist.report.activity}`; if (hist.report.roles <= 0) roleScore = '---'; @@ -126,7 +127,7 @@ export default class Score_Hist extends Command { else totalMode = `${stat.totalMode}`; if (stat.activityMean < 10) activityMean = '---'; - else if (stat.activityMean > Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))) activityMean = String(Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))); + else if (stat.activityMean > Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12))) activityMean = String(Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12))); else activityMean = `${stat.activityMean}`; if (stat.rolesMean <= 0) roleMean = '---'; @@ -207,7 +208,7 @@ export default class Score_Hist extends Command { else totalScore = `${hist.report.total}`; if (hist.report.activity < 10) activityScore = '---'; - else if (hist.report.activity > Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))) activityScore = String(Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))); + else if (hist.report.activity > Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12))) activityScore = String(Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12))); else activityScore = `${hist.report.activity}`; if (hist.report.roles <= 0) roleScore = '---'; @@ -278,7 +279,7 @@ export default class Score_Hist extends Command { else totalMode = `${stat.totalMode}`; if (stat.activityMean < 10) activityMean = '---'; - else if (stat.activityMean > Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))) activityMean = String(Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12))); + else if (stat.activityMean > Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12))) activityMean = String(Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12))); else activityMean = `${stat.activityMean}`; if (stat.rolesMean <= 0) roleMean = '---'; diff --git a/src/intervals/score.ts b/src/intervals/score.ts index 3737980..b1ced18 100644 --- a/src/intervals/score.ts +++ b/src/intervals/score.ts @@ -3,7 +3,7 @@ /* eslint-disable one-var-declaration-per-line */ /* eslint-disable no-await-in-loop */ import axios from 'axios'; -import { TextChannel } from 'eris'; +import { Message, TextChannel } from 'eris'; import { Client } from '../class'; interface CSResponse { @@ -18,14 +18,36 @@ interface CSResponse { let interval: NodeJS.Timeout; +export function getTotalMessageCount(client: Client): number { + const projectChannels: TextChannel[] = []; + for (const c of client.guilds.get(client.config.guildID).channels.filter((ch) => ch.type === 0)) { + const chan = c; + if (chan.parentID !== '701591772186411108') continue; + projectChannels.push(chan); + } + return (projectChannels.length * 200) + 2200 + 300 + 100 + 200; +} + export default async function calculateScore(client: Client): Promise { const start = async () => { const { members } = client.guilds.get(client.config.guildID); - const general = await ( client.guilds.get(client.config.guildID).channels.get('485680288123584525')).getMessages(3000); + const general = await ( client.guilds.get(client.config.guildID).channels.get('485680288123584525')).getMessages(2200); const programmingSupport = await ( client.guilds.get(client.config.guildID).channels.get('506970598631538708')).getMessages(300); const programmingSupport2 = await ( client.guilds.get(client.config.guildID).channels.get('554892820553531422')).getMessages(100); const cloudSupport = await ( client.guilds.get(client.config.guildID).channels.get('546457788184789013')).getMessages(200); + + const projectChannels: TextChannel[] = []; + for (const c of client.guilds.get(client.config.guildID).channels.filter((ch) => ch.type === 0)) { + const chan = c; + if (chan.parentID !== '701591772186411108') continue; + projectChannels.push(chan); + } + const projectMessages: Message[] = []; + for (const chan of projectChannels) { + const msg = await chan.getMessages(200); + projectMessages.push(...msg); + } for (const member of members.values()) { if (member.bot) continue; let score = await client.db.Score.findOne({ userID: member.user.id }); @@ -88,7 +110,7 @@ export default async function calculateScore(client: Client): Promise m.member?.id === member.id)) { if (!msg.content) continue; @@ -99,7 +121,7 @@ export default async function calculateScore(client: Client): Promise (Math.log1p(3000 + 300 + 200) * 12 + 100)) activity = Math.floor((Math.log1p(3000 + 300 + 200 + 100) * 12)); + if (activity > (Math.log1p(getTotalMessageCount(client)) * 12)) activity = Math.floor((Math.log1p(getTotalMessageCount(client)) * 12)); if (member.roles.includes('446104438969466890') || member.roles.includes('701481967149121627')) staff = 20; const response = (await axios.get(`https://api.cloud.libraryofcode.org/wh/score?id=${member.user.id}&authorization=${client.config.internalKey}`)).data;