Skip to content

Instantly share code, notes, and snippets.

@ohac
Created May 5, 2014 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohac/5140ca01ef9b62237aab to your computer and use it in GitHub Desktop.
Save ohac/5140ca01ef9b62237aab to your computer and use it in GitHub Desktop.
NOMP Viewer
!!!
%html
%head
%title NOMP Viewer
%body
- coins.each do |coinname, rounds|
%h1 #{coinname}
- rounds.each do |round, shares|
%h2 #{round}
%table
%tr
- shares.each do |addr, share|
%td= addr
%td= '%.4f' % share
#!/usr/bin/ruby
require 'redis'
require 'sinatra'
require 'haml'
get '/' do
redis = Redis.new
roundcurrents = redis.keys("*_shares:roundCurrent").sort
coinnames = roundcurrents.map do |coin|
coin.split('_')[0]
end
coins = coinnames.map do |coinname|
roundkeys = redis.keys("#{coinname}_shares:round[0-9]*").sort
rounds = roundkeys.map do |roundkey|
round = roundkey.split(':round')[1].to_i
reward = 50.0 # TODO
sum = 0.0
shares = redis.hscan_each(roundkey).inject({}) do |ss, kv|
k, v = kv
v = v.to_f
sum += v
ss[k] = v
ss
end
shares = shares.map do |k, v|
[k, v * reward / sum]
end
[round, shares]
end
[coinname, rounds]
end
haml :index, :locals => { :coins => coins }
end
@ohac
Copy link
Author

ohac commented May 5, 2014

gistはディレクトリをサポートしていないので、index.hamlをviewsに移動して使う必要がある。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment