Sha256: 5c34149bb638cea762ee2f8a3a32c41648f4f946e3961988b178bf161e4856f4
Contents?: true
Size: 530 Bytes
Versions: 16
Compression:
Stored size: 530 Bytes
Contents
#!/usr/bin/env ruby # run like so: # $> ruby normalize.rb --run=local data/sizes.tsv data/normalized_sizes.tsv require 'rubygems' require 'wukong' require 'active_support/core_ext/enumerable' # for array#sum module Normalize class Mapper < Wukong::Streamer::RecordStreamer def process(country, *sizes) sizes.map!(&:to_i) sum = sizes.sum.to_f normalized = sizes.map{|x| 100 * x/sum } s = normalized.join(",") yield [country, s] end end end Wukong::Script.new(Normalize::Mapper, nil).run
Version data entries
16 entries across 16 versions & 1 rubygems