
Here's another tip for Steemit devs! When you retrieve a user's information from Steemit the reputation is a huge number, as you can see on sites like Steemd. This is usually called the "raw" reputation score.
My reputation at the moment of writing this post is over 1.2 trillion, but Steemit only shows it as 52
Simplified Reputation Score
Steemit and apps like eSteem show a "simplified" reputation score instead, a more human readable number roughly between -25 and 100*, with new users starting at 25.
The calculation to do this uses a base 10 logarithmic scale and a multiplication by 9, which effectively makes the reputation needed for going up 9 levels about 10x harder. Or to make it a little easier, see the following table
Simplified Reputation | Raw Reputation |
---|---|
25 | 1,000,000,000 |
34 | 10,000,000,000 |
43 | 100,000,000,000 |
52 | 1,000,000,000,000 |
61 | 10,000,000,000,000 |
70 | 100,000,000,000,000 |
et cetera.
* Theoretically this number can go up to 100 and even above, but practically this probably won't happen for years. I don't think anyone has even reached 80 yet
The JavaScript
Here's the code that you can use to calculate this score:
function simplifyReputation(raw) {
const isNegative = (raw < 0);
let reputation = Math.log10(Math.abs(raw));
reputation = Math.max(reputation - 9, 0);
reputation *= isNegative ? -9 : 9;
reputation += 25;
return Math.floor(reputation);
}
The base 10 logarithm of a negative number always results in NaN
, which is why we remember whether it was negative at first and then turn it positive on line 2, only to turn it back to negative again when multiplying by 9.
By the way, the original code from which I adapted this can be found on GitHub starting at the export const repLog10
line (line 46 as of this writing). It's a lot messier and even a little less exact, though probably more performant than my version.
Bonus content: an Angular Pipe
If you're developing an Angular app like me, you probably want to hide this all behind a pipe, so you can simply use something like this in your templates:
<span class="rep">{{user.reputation | reputation}}</span>
So here it is:
reputation.pipe.ts
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({
name: 'reputation'
})
export class ReputationPipe implements PipeTransform {
transform(value: number) {
const isNegative = (value < 0);
let reputation = Math.log10(Math.abs(value));
reputation = Math.max(reputation - 9, 0);
reputation *= isNegative ? -9 : 9;
reputation += 25;
return Math.floor(reputation);
}
}
I hope this will be of use to Steemit developers! If you have any questions or suggestions for improvement let me know in the comments ⬇️