Refactored userSchema.statics.findProfile()'s tokebot profile generation procedure.
This commit is contained in:
parent
e9b9539477
commit
42ad17072f
3 changed files with 40 additions and 48 deletions
|
|
@ -152,50 +152,6 @@ statSchema.statics.tattooToke = async function(toke){
|
|||
await stats.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets toke count from statistics document
|
||||
* @returns {Number} Number of tokes across the entire site
|
||||
*/
|
||||
statSchema.statics.getTokeCount = async function(){
|
||||
//get stats doc
|
||||
const stats = await this.getStats();
|
||||
|
||||
//return toke count
|
||||
return stats.tokes.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets toke counts for each individual callout in a map
|
||||
* @returns {Map} Map of toke counts for each individual callout registered to the server
|
||||
*/
|
||||
statSchema.statics.getTokeCommandCounts = async function(){
|
||||
//get stats doc
|
||||
const stats = await this.getStats()
|
||||
//Create empty map to hold toke command counts
|
||||
const count = new Map();
|
||||
|
||||
//for each toke
|
||||
stats.tokes.forEach((toke) => {
|
||||
//For each toke command called in the current toke
|
||||
toke.toke.forEach((command) => {
|
||||
//Get the current count for the current command
|
||||
var curCount = count.get(command);
|
||||
|
||||
//if the current count is null
|
||||
if(curCount == null){
|
||||
//Set it to one
|
||||
count.set(command, 1);
|
||||
}else{
|
||||
//Set it to ++curCount
|
||||
count.set(command, curCount + 1);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//return the toke command count
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ingests legacy tokes handed over by the migration model
|
||||
* @param {Array} rawLegacyTokes - List of strings containing contents of legacy cytube/fore.st toke logs
|
||||
|
|
@ -282,7 +238,7 @@ statSchema.statics.dropLegacyTokes = async function(){
|
|||
statDB.tokes = tokes;
|
||||
|
||||
//Save the stat document
|
||||
statDB.save();
|
||||
await statDB.save();
|
||||
|
||||
//Tell of our success
|
||||
console.log("Removed migration tokes!");
|
||||
|
|
@ -292,4 +248,36 @@ statSchema.statics.dropLegacyTokes = async function(){
|
|||
|
||||
}
|
||||
|
||||
//Methods
|
||||
|
||||
/**
|
||||
* Gets toke counts for each individual callout in a map
|
||||
* @returns {Map} Map of toke counts for each individual callout registered to the server
|
||||
*/
|
||||
statSchema.methods.calculateTokeCommandCounts = async function(){
|
||||
//Create empty map to hold toke command counts
|
||||
const count = new Map();
|
||||
|
||||
//for each toke
|
||||
this.tokes.forEach((toke) => {
|
||||
//For each toke command called in the current toke
|
||||
toke.toke.forEach((command) => {
|
||||
//Get the current count for the current command
|
||||
var curCount = count.get(command);
|
||||
|
||||
//if the current count is null
|
||||
if(curCount == null){
|
||||
//Set it to one
|
||||
count.set(command, 1);
|
||||
}else{
|
||||
//Set it to ++curCount
|
||||
count.set(command, curCount + 1);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//return the toke command count
|
||||
return count;
|
||||
}
|
||||
|
||||
module.exports = mongoose.model("statistics", statSchema);
|
||||
Loading…
Add table
Add a link
Reference in a new issue