I was looking for a method to quickly calculate the flag weight, taking invalid flags into account. The result is shown below, together with this fiddle: http://jsfiddle.net/DHDuH/6/
TL;DR: Click at the fiddle for a dynamic flag weight calculator.
I have created two calculators:
Additional flags
- Specify the current flag weight (default 0).
- Enter the number of additional flags
- Optionally, enter a list of expected invalid flags
- Hit Calculate, and spectate your flag weight after correctly flagging __ additional times. During the calculation, when the flag weight has exceeded 750, the function will terminate earlier.
Desired flag weight
- Specify the current flag weight (default 0)
- Specify the desired flag weight
- Optionally, paste a list of invalid flags.
- Press Calculate. The result is required number of flags to reach a certain flag weight.
Extra: Code to count and calculate the number of flags + flag weight.
First, paste snippet #1
in the developer console. Start at the last page of the flags, and execute the function at each page, backwards (e.g. page 9, 9, ...2, 1). After finishing these steps, localStorage.getItem("flagScript")
will hold an array, holding the indexes of invalid flags. The first element counts the number of flags.
localStorage.setItem("flagScript", JSON.stringify(getInvalid(JSON.parse(localStorage.getItem("flagScript"))||[0])));
function getInvalid(current){if(!(current instanceof Array))current =[current];var flagged = document.getElementsByClassName("flag-outcome"),i=flagged.length-1,totalflags=0;for(;i>=0;i--){if(/Helpful/.test(flagged[i].className))totalflags++;if(/Declined/.test(flagged[i].className))current.push(current[0]+current.length-1+totalflags)}current[0]+=totalflags;return current}document.body.scrollIntoView(!1);localStorage.getItem("flagScript");
/*End of #1 - localstorage.flagScript is modified*/
Get the created array, and paste the contents at the form. The getScript
's first element holds the count of the current number of calculated elements.
var tmp=JSON.parse(localStorage.getItem("flagScript"));
console.log("Counted flags " + tmp[0]);console.log(tmp.splice(1));
/*End of #2 localStorage.flagScript is still existing*/
Once you're finished, clear the temporary flagScript
variable:
localStorage.removeItem("flagScript");
Bonus: JavaScript functions
Recursive formula to calculate the flag weight on-the-fly, after flagging n times, starting at flag weight 0.
function f(n) /* flag weight after flagging n times */
{if(n<=500)return 10*n;var fn=f(n-1);return fn+Math.pow(10,1-(fn-500)*.008)}
Preparation #1
getInvalid([0]);function getInvalid(current){
if(!(current instanceof Array)) current = [current];
var flagged = document.getElementsByClassName("flag-outcome"),
i = flagged.length - 1,
totalflags = 0;
for(; i>=0; i--) {
if(/Helpful/.test(flagged[i].className)) totalflags++;
if(/Declined/.test(flagged[i].className)) {
current.push(current[0] + current.length - 1 + totalflags);
}
}
current[0] += totalflags;
return current
}
Counting flag weight
The method to calculate flag weight is shown below. The function consists of two blocks. Below flag weight 510, a linear function is used. Once the flag weight (minus penalty for invalid flags) has reached 510, a different formula is used.
After reaching flag weight 750 or reaching the additional flagCount
, the function terminates, and returns the number of flags and flagweight.
function countFlagWeight(flagweight, flagCount, invalid){
flagweight = +flagweight || 0;
if(!(invalid instanceof Array)) invalid = [];
else invalid = invalid.splice(0).sort(function(x,y){return x-y});
var flag = 1;
for (; flag <= flagCount && flagweight < 510; flag++) {
if (invalid.length && invalid[0] == flag) {
flagweight -= 10;
while (invalid.length && invalid[0] == flag) invalid.shift();
} else {
flagweight += 10;
}
}
for(; flag <= flagCount && flagweight <= 750; flag++) {
if (invalid.length && invalid[0] == flag) {
flagweight -= 10;
while (invalid.length && invalid[0] == flag) invalid.shift();
} else {
flagweight += Math.pow(10, 1 - (flagweight - 500) * 0.008)
}
}
return [flag-1, flagweight];
}
Function flagsTillGoal(current, goal, invalid)
looks similar to countFlagWeight()
. For the exact function, have a look at the fiddle.