From 2b1d7f881c19c4d4b5afae194e02d3300c7675d0 Mon Sep 17 00:00:00 2001 From: Patrick Simianer
Date: Tue, 5 Jul 2016 11:01:46 +0200 Subject: mv --- avg-weights | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 avg-weights (limited to 'avg-weights') diff --git a/avg-weights b/avg-weights new file mode 100755 index 0000000..36b051a --- /dev/null +++ b/avg-weights @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby + +require 'zipf' +require 'trollop' +require 'zlib' + +conf = Trollop::options do + opt :weights_files, "a number of weights files: name value", :required => true + opt :filter, "Filter if key does not appear in every file.", :type => :bool, :default => false +end + +h = {} +ARGV.each { |fn| + f = ReadFile.new fn + while line = f.gets + k, v = line.split + v = v.to_f + if h.has_key? k + h[k] << v + else + h[k] = [v] + end + end + f.close +} + +n = ARGV.size.to_f + +h.each_pair { |k,w| + next if conf[:filter] and w.size < n + puts "#{k} #{w.inject(:+)/n}" +} + -- cgit v1.2.3