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

Version Path
wukong-3.0.0.pre old/examples/contrib/jeans/normalize.rb
wukong-2.0.2 examples/contrib/jeans/normalize.rb
wukong-2.0.1 examples/contrib/jeans/normalize.rb
wukong-2.0.0 examples/contrib/jeans/normalize.rb
wukong-1.5.4 examples/contrib/jeans/normalize.rb
wukong-1.5.3 examples/contrib/jeans/normalize.rb
wukong-1.5.2 examples/contrib/jeans/normalize.rb
wukong-1.5.1 examples/contrib/jeans/normalize.rb
wukong-1.5.0 examples/contrib/jeans/normalize.rb
wukong-1.4.12 examples/contrib/jeans/normalize.rb
wukong-1.4.11 examples/contrib/jeans/normalize.rb
wukong-1.4.10 examples/contrib/jeans/normalize.rb
wukong-1.4.9 examples/contrib/jeans/normalize.rb
wukong-1.4.7 examples/contrib/jeans/normalize.rb
wukong-1.4.6 examples/contrib/jeans/normalize.rb
wukong-1.4.5 examples/contrib/jeans/normalize.rb