updates to score calculations

pull/29/head
Matthew 2020-11-12 20:37:24 -05:00
parent b3d267b328
commit 926b43235a
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
6 changed files with 46 additions and 20 deletions

View File

@ -5,6 +5,7 @@ import { v4 as uuid } from 'uuid';
import { TextChannel } from 'eris'; import { TextChannel } from 'eris';
import { LocalStorage, Route, Server, RichEmbed } from '../../../class'; import { LocalStorage, Route, Server, RichEmbed } from '../../../class';
import { ScoreHistoricalRaw } from '../../../models/ScoreHistorical'; import { ScoreHistoricalRaw } from '../../../models/ScoreHistorical';
import { getTotalMessageCount } from '../../../intervals/score';
export default class Report extends Route { export default class Report extends Route {
public timeout: Set<string>; public timeout: Set<string>;
@ -84,7 +85,7 @@ export default class Report extends Route {
else totalScore = Math.round(member.total); else totalScore = Math.round(member.total);
if (member.activity < 10) activityScore = 0; 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); else activityScore = Math.round(member.activity);
if (member.roles <= 0) roleScore = 0; if (member.roles <= 0) roleScore = 0;
@ -124,7 +125,7 @@ export default class Report extends Route {
else total = Math.round(data.report.total); else total = Math.round(data.report.total);
if (data.report.activity < 10) activity = 0; 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); else activity = Math.round(data.report.activity);
if (data.report.roles <= 0) role = 0; if (data.report.roles <= 0) role = 0;
@ -271,7 +272,7 @@ export default class Report extends Route {
let miscScore: number; let miscScore: number;
if (member.activity < 10) activityScore = 0; 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); else activityScore = Math.round(member.activity);
if (member.roles <= 0) roleScore = 0; if (member.roles <= 0) roleScore = 0;
@ -304,7 +305,7 @@ export default class Report extends Route {
else total = Math.round(data.report.total); else total = Math.round(data.report.total);
if (data.report.activity < 10) activity = 0; 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); else activity = Math.round(data.report.activity);
if (data.report.roles <= 0) role = 0; if (data.report.roles <= 0) role = 0;
@ -402,7 +403,7 @@ export default class Report extends Route {
let miscScore: number; let miscScore: number;
if (member.activity < 10) activityScore = 0; 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); else activityScore = Math.round(member.activity);
if (member.roles <= 0) roleScore = 0; if (member.roles <= 0) roleScore = 0;
@ -509,7 +510,7 @@ export default class Report extends Route {
else totalScore = `${score.total}`; else totalScore = `${score.total}`;
if (score.activity < 10) activityScore = '---'; 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}`; else activityScore = `${score.activity}`;
if (score.roles <= 0) roleScore = '---'; if (score.roles <= 0) roleScore = '---';
@ -546,7 +547,7 @@ export default class Report extends Route {
else total = Math.round(data.report.total); else total = Math.round(data.report.total);
if (data.report.activity < 10) activity = 0; 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); else activity = Math.round(data.report.activity);
if (data.report.roles <= 0) role = 0; if (data.report.roles <= 0) role = 0;

View File

@ -108,7 +108,7 @@ export default class Apply extends Command {
embed.setTitle('Instant Application Service [IAS]'); embed.setTitle('Instant Application Service [IAS]');
embed.setColor('#556cd6'); embed.setColor('#556cd6');
if (args[0] !== 'full') { 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.setThumbnail(message.member.avatarURL);
embed.setAuthor(message.member.username, message.member.avatarURL); embed.setAuthor(message.member.username, message.member.avatarURL);
} }

View File

@ -2,6 +2,7 @@
/* eslint-disable default-case */ /* eslint-disable default-case */
import { Message, TextChannel } from 'eris'; import { Message, TextChannel } from 'eris';
import { Client, Command, RichEmbed } from '../class'; import { Client, Command, RichEmbed } from '../class';
import { getTotalMessageCount } from '../intervals/score';
export default class Score extends Command { export default class Score extends Command {
constructor(client: Client) { constructor(client: Client) {
@ -61,7 +62,7 @@ export default class Score extends Command {
else totalScore = `${score.total}`; else totalScore = `${score.total}`;
if (score.activity < 10) activityScore = '---'; 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}`; else activityScore = `${score.activity}`;
if (score.roles <= 0) roleScore = '---'; 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 >= 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', score ? `${color} ${totalScore} | ${additionalText}` : 'N/C', true); 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('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);
embed.addField('Cloud Services | N/A to 10+', cloudServicesScore || 'N/C', true); embed.addField('Cloud Services | N/A to 10+', cloudServicesScore || 'N/C', true);

View File

@ -4,6 +4,7 @@ import moment from 'moment';
import { v4 as uuid } from 'uuid'; import { v4 as uuid } from 'uuid';
import { Message, User, TextChannel } from 'eris'; import { Message, User, TextChannel } from 'eris';
import { Client, Command, RichEmbed } from '../class'; import { Client, Command, RichEmbed } from '../class';
import { getTotalMessageCount } from '../intervals/score';
import Score_Hist from './score_hist'; import Score_Hist from './score_hist';
import Score_Notify from './score_notify'; import Score_Notify from './score_notify';
import Score_Pref from './score_pref'; import Score_Pref from './score_pref';
@ -95,7 +96,7 @@ export default class Score extends Command {
else totalScore = `${score.total}`; else totalScore = `${score.total}`;
if (score.activity < 10) activityScore = '---'; 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}`; else activityScore = `${score.activity}`;
if (score.roles <= 0) roleScore = '---'; 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 >= 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('CommScore™ | 200 to 800', score ? `${color} ${totalScore} | ${additionalText} | ${this.client.util.ordinal(Math.round(percentile))} Percentile` : 'N/C', true); 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('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);
embed.addField('Cloud Services | N/A to 10+', cloudServicesScore || 'N/C', true); embed.addField('Cloud Services | N/A to 10+', cloudServicesScore || 'N/C', true);

View File

@ -5,6 +5,7 @@ import { median, mode, mean } from 'mathjs';
import { createPaginationEmbed } from 'eris-pagination'; import { createPaginationEmbed } from 'eris-pagination';
import { Message, User, TextChannel } from 'eris'; import { Message, User, TextChannel } from 'eris';
import { Client, Command, RichEmbed } from '../class'; import { Client, Command, RichEmbed } from '../class';
import { getTotalMessageCount } from '../intervals/score';
export default class Score_Hist extends Command { export default class Score_Hist extends Command {
constructor(client: Client) { constructor(client: Client) {
@ -55,7 +56,7 @@ export default class Score_Hist extends Command {
else totalScore = `${hist.report.total}`; else totalScore = `${hist.report.total}`;
if (hist.report.activity < 10) activityScore = '---'; 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}`; else activityScore = `${hist.report.activity}`;
if (hist.report.roles <= 0) roleScore = '---'; if (hist.report.roles <= 0) roleScore = '---';
@ -126,7 +127,7 @@ export default class Score_Hist extends Command {
else totalMode = `${stat.totalMode}`; else totalMode = `${stat.totalMode}`;
if (stat.activityMean < 10) activityMean = '---'; 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}`; else activityMean = `${stat.activityMean}`;
if (stat.rolesMean <= 0) roleMean = '---'; if (stat.rolesMean <= 0) roleMean = '---';
@ -207,7 +208,7 @@ export default class Score_Hist extends Command {
else totalScore = `${hist.report.total}`; else totalScore = `${hist.report.total}`;
if (hist.report.activity < 10) activityScore = '---'; 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}`; else activityScore = `${hist.report.activity}`;
if (hist.report.roles <= 0) roleScore = '---'; if (hist.report.roles <= 0) roleScore = '---';
@ -278,7 +279,7 @@ export default class Score_Hist extends Command {
else totalMode = `${stat.totalMode}`; else totalMode = `${stat.totalMode}`;
if (stat.activityMean < 10) activityMean = '---'; 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}`; else activityMean = `${stat.activityMean}`;
if (stat.rolesMean <= 0) roleMean = '---'; if (stat.rolesMean <= 0) roleMean = '---';

View File

@ -3,7 +3,7 @@
/* eslint-disable one-var-declaration-per-line */ /* eslint-disable one-var-declaration-per-line */
/* eslint-disable no-await-in-loop */ /* eslint-disable no-await-in-loop */
import axios from 'axios'; import axios from 'axios';
import { TextChannel } from 'eris'; import { Message, TextChannel } from 'eris';
import { Client } from '../class'; import { Client } from '../class';
interface CSResponse { interface CSResponse {
@ -18,14 +18,36 @@ interface CSResponse {
let interval: NodeJS.Timeout; 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 = <TextChannel> 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<NodeJS.Timeout> { export default async function calculateScore(client: Client): Promise<NodeJS.Timeout> {
const start = async () => { const start = async () => {
const { members } = client.guilds.get(client.config.guildID); const { members } = client.guilds.get(client.config.guildID);
const general = await (<TextChannel> client.guilds.get(client.config.guildID).channels.get('485680288123584525')).getMessages(3000); const general = await (<TextChannel> client.guilds.get(client.config.guildID).channels.get('485680288123584525')).getMessages(2200);
const programmingSupport = await (<TextChannel> client.guilds.get(client.config.guildID).channels.get('506970598631538708')).getMessages(300); const programmingSupport = await (<TextChannel> client.guilds.get(client.config.guildID).channels.get('506970598631538708')).getMessages(300);
const programmingSupport2 = await (<TextChannel> client.guilds.get(client.config.guildID).channels.get('554892820553531422')).getMessages(100); const programmingSupport2 = await (<TextChannel> client.guilds.get(client.config.guildID).channels.get('554892820553531422')).getMessages(100);
const cloudSupport = await (<TextChannel> client.guilds.get(client.config.guildID).channels.get('546457788184789013')).getMessages(200); const cloudSupport = await (<TextChannel> 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 = <TextChannel> c;
if (chan.parentID !== '701591772186411108') continue;
projectChannels.push(chan);
}
const projectMessages: Message<TextChannel>[] = [];
for (const chan of projectChannels) {
const msg = await chan.getMessages(200);
projectMessages.push(...msg);
}
for (const member of members.values()) { for (const member of members.values()) {
if (member.bot) continue; if (member.bot) continue;
let score = await client.db.Score.findOne({ userID: member.user.id }); let score = await client.db.Score.findOne({ userID: member.user.id });
@ -88,7 +110,7 @@ export default async function calculateScore(client: Client): Promise<NodeJS.Tim
if (activeMods <= 0) moderation = 2; if (activeMods <= 0) moderation = 2;
let messageCountTotal = 0; let messageCountTotal = 0;
const allMessagesArray = [...general, ...programmingSupport, ...programmingSupport2, ...cloudSupport]; const allMessagesArray = [...general, ...programmingSupport, ...programmingSupport2, ...cloudSupport, ...projectMessages];
for (const msg of allMessagesArray.filter((m) => m.member?.id === member.id)) { for (const msg of allMessagesArray.filter((m) => m.member?.id === member.id)) {
if (!msg.content) continue; if (!msg.content) continue;
@ -99,7 +121,7 @@ export default async function calculateScore(client: Client): Promise<NodeJS.Tim
const activityTotal = messageCountTotal; const activityTotal = messageCountTotal;
activity = Math.floor(Math.log1p(activityTotal) * 12); activity = Math.floor(Math.log1p(activityTotal) * 12);
if (activity > (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; if (member.roles.includes('446104438969466890') || member.roles.includes('701481967149121627')) staff = 20;
const response = <CSResponse> (await axios.get(`https://api.cloud.libraryofcode.org/wh/score?id=${member.user.id}&authorization=${client.config.internalKey}`)).data; const response = <CSResponse> (await axios.get(`https://api.cloud.libraryofcode.org/wh/score?id=${member.user.id}&authorization=${client.config.internalKey}`)).data;