update scoring model

pull/29/head
Matthew 2020-09-13 22:20:55 -04:00
parent 298d7c82f9
commit 231fb618f6
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
3 changed files with 52 additions and 6 deletions

View File

@ -95,7 +95,7 @@ export default class Score extends Command {
let desc = '__**Hard Inquiries**__\n*These inquiries will fall off your report within 3 months, try to keep your hard inquiries to a minimum. If you want to file a dispute, please DM Ramirez.*\n\n'; let desc = '__**Hard Inquiries**__\n*These inquiries will fall off your report within 3 months, try to keep your hard inquiries to a minimum. If you want to file a dispute, please DM Ramirez.*\n\n';
score.inquiries.forEach((inq) => { score.inquiries.forEach((inq) => {
const testDate = (new Date(new Date(inq.date).setHours(2190))); const testDate = (new Date(new Date(inq.date).setHours(2190)));
if (testDate > inq.date) desc += `**Department/Service:** ${inq.name}\n**Reason:** ${inq.reason}\n**Date:** ${inq.date.toLocaleString('en-us')} ET\n\n`; if (testDate > new Date()) desc += `**Department/Service:** ${inq.name}\n**Reason:** ${inq.reason}\n**Date:** ${inq.date.toLocaleString('en-us')} ET\n\n`;
}); });
embed.setDescription(desc); embed.setDescription(desc);
} }
@ -104,11 +104,11 @@ export default class Score extends Command {
if (score.total >= 300) { color = '🟠'; embed.setColor('FFA500'); } if (score.total >= 300) { color = '🟠'; embed.setColor('FFA500'); }
if (score.total >= 500) { color = '🟡'; embed.setColor('FFFF00'); } if (score.total >= 500) { color = '🟡'; embed.setColor('FFFF00'); }
if (score.total >= 700) { color = '🟢'; embed.setColor('66FF66'); } if (score.total >= 700) { color = '🟢'; embed.setColor('66FF66'); }
embed.addField('Total | 200 - 800', `${color} ${totalScore}`, true); embed.addField('Total | 200 to 800', `${color} ${totalScore}`, true);
embed.addField(`Activity | 10 - ${Math.floor(Math.log1p(5000 + 300 + 200 + 100) * 12)}`, activityScore, true); embed.addField(`Activity | 10 to ${Math.floor(Math.log1p(5000 + 300 + 200 + 100) * 12)}`, activityScore, true);
embed.addField('Roles | 1 - 54', roleScore, true); embed.addField('Roles | 1 to 54', roleScore, true);
embed.addField('Moderation | -50 - 2', moderationScore, true); embed.addField('Moderation | -50 to 2', moderationScore, true);
embed.addField('Cloud Services | -20 - 50', cloudServicesScore, true); embed.addField('Cloud Services | N/A to 21', cloudServicesScore, true);
embed.addField('Misc', miscScore, true); embed.addField('Misc', miscScore, true);
if (score.lastUpdate) { if (score.lastUpdate) {
embed.setFooter('Report last updated', this.client.user.avatarURL); embed.setFooter('Report last updated', this.client.user.avatarURL);

View File

@ -1,9 +1,20 @@
/* eslint-disable no-continue */ /* eslint-disable no-continue */
/* 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 { TextChannel } from 'eris'; import { TextChannel } from 'eris';
import { Client } from '../class'; import { Client } from '../class';
interface CSResponse {
found: boolean,
tier: number,
totalReferrals?: number,
createdAt?: Date,
warns?: Date[],
locks?: Date[],
deletes?: Date[],
}
let interval: NodeJS.Timeout; let interval: NodeJS.Timeout;
export default async function calculateScore(client: Client): Promise<NodeJS.Timeout> { export default async function calculateScore(client: Client): Promise<NodeJS.Timeout> {
@ -59,6 +70,40 @@ export default async function calculateScore(client: Client): Promise<NodeJS.Tim
if (activity > (Math.log1p(5000 + 300 + 200) * 12 + 100)) activity = Math.floor((Math.log1p(5000 + 300 + 200 + 100) * 12)); if (activity > (Math.log1p(5000 + 300 + 200) * 12 + 100)) activity = Math.floor((Math.log1p(5000 + 300 + 200 + 100) * 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;
if (response.found === true) {
let negatives = 0;
let positives = 0;
const csCreatedTestDate = (new Date(new Date(response.createdAt).setHours(730)));
if (csCreatedTestDate > new Date()) {
negatives -= 10;
}
if (response.warns.length === 0) positives += 5;
else {
for (const warn of response.warns) {
const date = (new Date(new Date(warn).setHours(730)));
if (date > new Date()) negatives -= 2;
}
}
if (response.locks.length === 0) positives += 10;
else {
for (const lock of response.locks) {
const date = (new Date(new Date(lock).setHours(1460)));
if (date > new Date()) negatives -= 5;
}
}
if (response.deletes.length === 0) {
for (const del of response.deletes) {
const date = (new Date(new Date(del).setHours(3650)));
if (date > new Date()) negatives -= 20;
}
}
if (response.tier === 2) positives += 2;
else if (response.tier === 3) positives += 3;
if (negatives < 0) cloudServices = Math.floor((negatives * 1.2) + (positives * 0.06));
else cloudServices = Math.floor(positives * 0.61);
}
total = Math.floor(((total + activity + roles + moderation + cloudServices + staff) * 5.13) * 1.87); total = Math.floor(((total + activity + roles + moderation + cloudServices + staff) * 5.13) * 1.87);
await score.updateOne({ $set: { total, activity, roles, moderation, cloudServices, staff, lastUpdate: new Date() } }); await score.updateOne({ $set: { total, activity, roles, moderation, cloudServices, staff, lastUpdate: new Date() } });

1
types/index.d.ts vendored
View File

@ -6,4 +6,5 @@ export declare interface Config {
emailPass: string; emailPass: string;
webhookID: string; webhookID: string;
webhookToken: string; webhookToken: string;
internalKey: string;
} }