score hist rework

master
Matthew 2021-07-08 17:06:23 -04:00
parent d7895cb8c7
commit 8db4d46835
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
2 changed files with 83 additions and 77 deletions

View File

@ -1,9 +1,7 @@
/* eslint-disable no-await-in-loop */ /* eslint-disable no-await-in-loop */
/* eslint-disable no-continue */ /* eslint-disable no-continue */
/* eslint-disable default-case */ /* eslint-disable default-case */
import moment from 'moment';
import { median, mode, mean } from 'mathjs'; import { median, mode, mean } from 'mathjs';
import { createPaginationEmbed } from 'eris-pagination';
import { Message } from 'eris'; import { Message } from 'eris';
import { Client, Command, RichEmbed } from '../class'; import { Client, Command, RichEmbed } from '../class';
import { getTotalMessageCount } from '../intervals/score'; import { getTotalMessageCount } from '../intervals/score';
@ -30,10 +28,9 @@ export default class Score_Hist extends Command {
} }
const score = await this.client.db.Score.findOne({ userID: user.id }).lean().exec(); const score = await this.client.db.Score.findOne({ userID: user.id }).lean().exec();
if (!user) return this.error(message.channel, 'Member not found.'); if (!user) return this.error(message.channel, 'Member not found.');
const hists = await this.client.db.ScoreHistorical.find({ userID: user.id }).limit(31).lean().exec(); const hists = await this.client.db.ScoreHistorical.find({ userID: user.id }).lean().exec();
if (!hists) return this.error(message.channel, 'No history found.'); if (!hists) return this.error(message.channel, 'No history found.');
if (hists.length < 1) return this.error(message.channel, 'No history found.'); if (hists.length < 1) return this.error(message.channel, 'No history found.');
const histArray: [{ name: string, value: string }?] = [];
const totalArray: number[] = []; const totalArray: number[] = [];
const activityArray: number[] = []; const activityArray: number[] = [];
const moderationArray: number[] = []; const moderationArray: number[] = [];
@ -97,7 +94,6 @@ export default class Score_Hist extends Command {
if (testDate > new Date()) hardInquiries++; if (testDate > new Date()) hardInquiries++;
}); });
data += `__CommScore™:__ ${totalScore}\n__Activity:__ ${activityScore}\n__Roles:__ ${roleScore}\n__Moderation:__ ${moderationScore}\n__Cloud Services:__ ${cloudServicesScore}\n__Other:__ ${otherScore}\n__Misc:__ ${miscScore}\n\n__Hard Inquiries:__ ${hardInquiries}\n__Soft Inquiries:__ ${score.softInquiries?.length ?? '0'}`; data += `__CommScore™:__ ${totalScore}\n__Activity:__ ${activityScore}\n__Roles:__ ${roleScore}\n__Moderation:__ ${moderationScore}\n__Cloud Services:__ ${cloudServicesScore}\n__Other:__ ${otherScore}\n__Misc:__ ${miscScore}\n\n__Hard Inquiries:__ ${hardInquiries}\n__Soft Inquiries:__ ${score.softInquiries?.length ?? '0'}`;
histArray.push({ name: moment(hist.date).calendar(), value: data });
} }
} }
@ -112,61 +108,48 @@ export default class Score_Hist extends Command {
otherMean: mean(otherArray), otherMean: mean(otherArray),
miscMean: mean(miscArray), miscMean: mean(miscArray),
}; };
const splitHist = this.client.util.splitFields(histArray);
const cmdPages: RichEmbed[] = [];
splitHist.forEach((split) => {
const embed = new RichEmbed();
embed.setTitle('Historical Community Report');
let totalMean = '0';
let totalMedian = '0';
let totalMode = '0';
let activityMean = '0';
let moderationMean = '0';
let roleMean = '0';
let cloudServicesMean = '0';
let otherMean = '0';
let miscMean = '0';
if (stat.totalMean < 200) totalMean = '---'; let totalMean = '0';
else if (stat.totalMean > 800) totalMean = '800'; let totalMedian = '0';
else totalMean = `${stat.totalMean}`; let totalMode = '0';
let activityMean = '0';
let moderationMean = '0';
let roleMean = '0';
let cloudServicesMean = '0';
let otherMean = '0';
let miscMean = '0';
if (stat.totalMedian < 200) totalMedian = '---'; if (stat.totalMean < 200) totalMean = '---';
else if (stat.totalMedian > 800) totalMedian = '800'; else if (stat.totalMean > 800) totalMean = '800';
else totalMedian = `${stat.totalMedian}`; else totalMean = `${stat.totalMean}`;
if (stat.totalMode < 200) totalMode = '---'; if (stat.totalMedian < 200) totalMedian = '---';
else if (stat.totalMode > 800) totalMode = '800'; else if (stat.totalMedian > 800) totalMedian = '800';
else totalMode = `${stat.totalMode}`; else totalMedian = `${stat.totalMedian}`;
if (stat.activityMean < 10) activityMean = '---'; if (stat.totalMode < 200) totalMode = '---';
else if (stat.activityMean > Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12))) activityMean = String(Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12))); else if (stat.totalMode > 800) totalMode = '800';
else activityMean = `${stat.activityMean}`; else totalMode = `${stat.totalMode}`;
if (stat.rolesMean <= 0) roleMean = '---'; if (stat.activityMean < 10) activityMean = '---';
else if (stat.rolesMean > 54) roleMean = '54'; else if (stat.activityMean > Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12))) activityMean = String(Math.floor((Math.log1p(getTotalMessageCount(this.client)) * 12)));
else roleMean = `${stat.rolesMean}`; else activityMean = `${stat.activityMean}`;
moderationMean = `${stat.moderationMean}`; if (stat.rolesMean <= 0) roleMean = '---';
else if (stat.rolesMean > 54) roleMean = '54';
else roleMean = `${stat.rolesMean}`;
if (stat.otherMean === 0) otherMean = '---'; moderationMean = `${stat.moderationMean}`;
else otherMean = `${stat.otherMean}`;
if (stat.miscMean <= 0) miscMean = '---'; if (stat.otherMean === 0) otherMean = '---';
else miscMean = `${stat.miscMean}`; else otherMean = `${stat.otherMean}`;
if (stat.cloudServicesMean === 0) cloudServicesMean = '---'; if (stat.miscMean <= 0) miscMean = '---';
else if (stat.cloudServicesMean > 10) cloudServicesMean = '10'; else miscMean = `${stat.miscMean}`;
else cloudServicesMean = `${stat.cloudServicesMean}`;
embed.setDescription(`__**Statistical Averages**__\n**CommScore™ Mean:** ${totalMean} | **CommScore™ Mode:** ${totalMode} | **CommScore™ Median:** ${totalMedian}\n\n**Activity Mean:** ${activityMean}\n**Roles Mean:** ${roleMean}\n**Moderation Mean:** ${moderationMean}\n**Cloud Services Mean:** ${cloudServicesMean}\n**Other Mean:** ${otherMean}\n**Misc Mean:** ${miscMean}`); if (stat.cloudServicesMean === 0) cloudServicesMean = '---';
embed.setAuthor(user.username, user.avatarURL); else if (stat.cloudServicesMean > 10) cloudServicesMean = '10';
embed.setThumbnail(user.avatarURL); else cloudServicesMean = `${stat.cloudServicesMean}`;
embed.setTimestamp();
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
split.forEach((c) => embed.addField(c.name, c.value));
return cmdPages.push(embed);
});
let name = ''; let name = '';
for (const role of this.client.util.resolveMember(message.author.id, this.mainGuild).roles.map((r) => this.mainGuild.roles.get(r)).sort((a, b) => b.position - a.position)) { for (const role of this.client.util.resolveMember(message.author.id, this.mainGuild).roles.map((r) => this.mainGuild.roles.get(r)).sort((a, b) => b.position - a.position)) {
@ -176,8 +159,14 @@ export default class Score_Hist extends Command {
await this.client.report.createInquiry(user.id, name, 1); await this.client.report.createInquiry(user.id, name, 1);
if (cmdPages.length === 1) return message.channel.createMessage({ embed: cmdPages[0] }); const embed = new RichEmbed();
return createPaginationEmbed(message, cmdPages); embed.setTitle('Historical Community Report');
embed.setAuthor(user.username, user.avatarURL);
embed.setThumbnail(user.avatarURL);
embed.setDescription(`__**Statistical Averages**__\n**CommScore™ Mean:** ${totalMean} | **CommScore™ Mode:** ${totalMode} | **CommScore™ Median:** ${totalMedian}\n\n**Activity Mean:** ${activityMean}\n**Roles Mean:** ${roleMean}\n**Moderation Mean:** ${moderationMean}\n**Cloud Services Mean:** ${cloudServicesMean}\n**Other Mean:** ${otherMean}\n**Misc Mean:** ${miscMean}`);
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
return message.channel.createMessage({ embed });
} catch (err) { } catch (err) {
return this.client.util.handleError(err, message, this); return this.client.util.handleError(err, message, this);
} }

View File

@ -1,25 +1,42 @@
import { Document, Schema, model, Types } from 'mongoose'; import { Document, Schema, model, Types } from 'mongoose';
import { ScoreInterfaceRaw } from '.';
export interface ScoreHistoricalRaw {
export interface ScoreHistoricalRaw { userID: string,
userID: string, report: {
report: ScoreInterfaceRaw, total: number,
inquiries: [ Types.ObjectId ], activity: number,
date: Date, roles: number,
} moderation: number,
cloudServices: number,
export interface ScoreHistoricalInterface extends Document { staff: number,
userID: string, other: number,
report: ScoreInterfaceRaw, },
inquiries: [ Types.ObjectId ], // inquiries: [ Types.ObjectId ],
date: Date inquiries: Types.ObjectId[],
} date: Date,
}
const ScoreHistorical: Schema = new Schema({
userID: String, export interface ScoreHistoricalInterface extends Document {
report: Object, userID: string,
inquiries: Array, report: {
date: Date, total: number,
}); activity: number,
roles: number,
export default model<ScoreHistoricalInterface>('ScoreHistorical', ScoreHistorical); moderation: number,
cloudServices: number,
staff: number,
other: number,
},
// inquiries: [ Types.ObjectId ],
inquiries: Types.ObjectId[],
date: Date
}
const ScoreHistorical: Schema = new Schema({
userID: String,
report: Object,
inquiries: Array,
date: Date,
});
export default model<ScoreHistoricalInterface>('ScoreHistorical', ScoreHistorical);