Abstract: I have improved this NodeJs script to compute the Median and STD for the members in the Steemit-Wechat Group. It reflects the fact that: the most wealth is possessed by a few huge whales.
I am planning to put these statistics on the Daily SteemIt Wechat Group Ranking table. The median values help better understand where you are in the big pond (are you really a minnow?)
Let’s define these measured by extending Array’s prototype in Javascript:
How to Compute Median in Javascript?
The median is the middle number or the average middle two numbers if you sort the array.
Array.prototype.median = function() {
var arr = [...this];
var len = arr.length;
if (0 == len) {
return NaN;
}
arr.sort();
var mid = Math.floor(len / 2);
if ((len % 2) == 0) {
return (arr[mid] + arr[mid - 1]) * 0.5;
}
return arr[mid];
}
How to Compute Mean/Average in Javascript?
Array.prototype.mean = function() {
var total = 0;
for (var i = this.length - 1; i >= 0; -- i){
total += this[i];
}
return total / this.length;
}
How to Compute STD (Standard Deviation) in Javascript?
STD reflects how big difference the values are from the mean/average.
Array.prototype.STD = function() {
var mean = this.mean();
var diff = [];
for (var j = this.length - 1; j >= 0; -- j){
diff.push(Math.pow((this[j] - mean), 2));
}
return (Math.sqrt(diff.reduce((a, b) => a + b) / this.length));
}
Then we just need to fetch the ranking table via the handy API.
// @justyy
var request = require("request")
var url = "https://uploadbeta.com/api/steemit/wechat/?cached";
request({
url: url,
json: true
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
var total_rep = [];
var total_sbd = [];
var total_steem = [];
var total_value = [];
var total_esp = [];
var total_vp = [];
var total_sp = [];
body.forEach(function(member) {
total_rep.push(member['rep']);
total_sbd.push(member['sbd']);
total_steem.push(member['steem']);
total_value.push(member['value']);
total_esp.push(member['esp']);
total_vp.push(member['vp']);
total_sp.push(member['sp']);
});
console.log("----Median----");
console.log("Total Members = " + total_rep.length);
console.log("Median Reputation = " + Math.round(total_rep.median() * 100) / 100);
console.log("Median SBD = " + Math.round(total_sbd.median() * 100) / 100);
console.log("Median Steem = " + Math.round(total_steem.median() * 100) / 100);
console.log("Median Effective SP = " + Math.round(total_esp.median() * 100) / 100);
console.log("Median SP = " + Math.round(total_sp.median() * 100) / 100);
console.log("Median Voting Power = " + Math.round(total_vp.median() * 100) / 100);
console.log("Median Account Value = " + Math.round(total_value.median() * 100) / 100);
console.log("----Mean----");
console.log("Mean Reputation = " + Math.round(total_rep.mean() * 100) / 100);
console.log("Mean SBD = " + Math.round(total_sbd.mean() * 100) / 100);
console.log("Mean Steem = " + Math.round(total_steem.mean() * 100) / 100);
console.log("Mean Effective SP = " + Math.round(total_esp.mean() * 100) / 100);
console.log("Mean SP = " + Math.round(total_sp.mean() * 100) / 100);
console.log("Mean Voting Power = " + Math.round(total_vp.mean() * 100) / 100);
console.log("Mean Account Value = " + Math.round(total_value.mean() * 100) / 100);
console.log("----STD----");
console.log("STD Reputation = " + Math.round(total_rep.STD() * 100) / 100);
console.log("STD SBD = " + Math.round(total_sbd.STD() * 100) / 100);
console.log("STD Steem = " + Math.round(total_steem.STD() * 100) / 100);
console.log("STD Effective SP = " + Math.round(total_esp.STD() * 100) / 100);
console.log("STD SP = " + Math.round(total_sp.STD() * 100) / 100);
console.log("STD Voting Power = " + Math.round(total_vp.STD() * 100) / 100);
console.log("STD Account Value = " + Math.round(total_value.STD() * 100) / 100);
}
})
And the results come out pretty quickly using NodeJs.
—-Median—-
Total Members = 173
Median Reputation = 50.83
Median SBD = 154.62
Median Steem = 0
Median Effective SP = 28.15
Median SP = 201.16
Median Voting Power = 93.72
Median Account Value = 2040.61
—-Mean—-
Mean Reputation = 48.56
Mean SBD = 224.75
Mean Steem = 18.99
Mean Effective SP = 18503.56
Mean SP = 1561.65
Mean Voting Power = 83.07
Mean Account Value = 2436.73
—-STD—-
STD Reputation = 13.5
STD SBD = 1093.16
STD Steem = 118.9
STD Effective SP = 99019.55
STD SP = 5977.72
STD Voting Power = 21.61
STD Account Value = 9344.65
the Wechat is very big and is used by nearly 9 hundred million (if I remember correctly), so definitely this is going to be interesting if we combine wechat and steemit.
You may also like: 数据初步分析系列 STEEM中文微信群排行榜单 – 中位数,平均,和标准方差
–EOF (The Ultimate Computing & Technology Blog) —
Last Post: Simple NodeJS Example to Show Average Scores in the Steemit-Wechat Group
Next Post: How to Compute the Modes of an Array in PHP?
