How to Decode Reputation Levels in Ruby

in #radiator8 years ago (edited)

The reputation for an account is expressed in a long numeric string (like 50453770138701). Here's how to see this value as a reputation level like the steemit.com expresses it (like 67.3260426184728).

As always, we use Radiator with bundler. You can get bundler with this command:

$ gem install bundler

I've tested it on various versions of ruby. The oldest one I got it to work was:

ruby 2.0.0p645 (2015-04-13 revision 50299) [x86_64-darwin14.4.0]

First, make a project folder:

$ mkdir radiator
$ cd radiator

Create a file named Gemfile containing:

source 'https://rubygems.org'
gem 'radiator', github: 'inertia186/radiator'

Then run the command:

$ bundle install

Create a file named rep.rb containing:

require 'rubygems'
require 'bundler/setup'

Bundler.require

puts "Usage: ruby #{__FILE__} <accounts>" and return if ARGV.empty?

api = Radiator::Api.new(url: 'https://node.steem.ws:443')

response = api.get_accounts(ARGV)
accounts = response.result

accounts.each do |account|
  name = account.name
  raw = account.reputation.to_i
  level = Math.log10(raw.abs)
  level = [level - 9, 0].max
  level = (level * 9) + 25

  puts "#{name}, level: #{level}, raw: #{raw}"
end

Then run it:

$ ruby rep.rb abit alexgr bacchist bitcoiner cheftony fubar-bdhr gavvet instructor2121 klye konti liberosist lovejoy nonlinearone patrice pharesim picokernel proctologic proglobyte proglobyte-m1 royaltiffany samupaha steemychicken1 teamsteem tingaling vi1son voteinterestpool zentat

The expected output will be something like this:

abit, level: 65.73535164480853, raw: 33585373526603
alexgr, level: 66.66987628770134, raw: 42656601738982
bacchist, level: 67.72078642058553, raw: 55815400678614
bitcoiner, level: 62.83244951862576, raw: 15981057057193
cheftony, level: 55.8479374102301, raw: 2676385086020
fubar-bdhr, level: 62.48759786991231, raw: 14631493281120
gavvet, level: 75.21807411460534, raw: 380002114065679
instructor2121, level: 66.49727938973939, raw: 40813968135714
klye, level: 69.82737173531305, raw: 95679540664538
konti, level: 60.57436835689008, raw: 8968247708037
liberosist, level: 66.21467932563426, raw: 37967221325038
lovejoy, level: 62.18071805045498, raw: 13526669984288
nonlinearone, level: 65.32512877357624, raw: 30239169803984
patrice, level: 59.28856093457256, raw: 6454165593591
pharesim, level: 67.65061394175726, raw: 54822281416023
picokernel, level: 62.468726425704766, raw: 14561020894891
proctologic, level: 60.26404469535024, raw: 8283753905851
proglobyte, level: 51.3194930033297, raw: 840210513396
proglobyte-m1, level: 43.16801803954803, raw: 104392349246
royaltiffany, level: 62.17151922080171, raw: 13494873016682
samupaha, level: 64.96604853961757, raw: 27584941035106
steemychicken1, level: 62.62124117290992, raw: 15140419487694
teamsteem, level: 67.2494175458528, raw: 49474307874465
tingaling, level: 51.66810522848794, raw: 918592305276
vi1son, level: 59.18305044478749, raw: 6282271713784
voteinterestpool, level: 58.69400903505859, raw: 5543432729679
zentat, level: 55.05530819610037, raw: 2185137088752

ruby

See my previous Ruby How To posts in: #radiator #ruby

Sort:  

This post has been ranked within the top 80 most undervalued posts in the first half of Jan 05. We estimate that this post is undervalued by $3.74 as compared to a scenario in which every voter had an equal say.

See the full rankings and details in The Daily Tribune: Jan 05 - Part I. You can also read about some of our methodology, data analysis and technical details in our initial post.

If you are the author and would prefer not to receive these comments, simply reply "Stop" to this comment.