From f561b2c769bbf335f1b9c025ca09f06d936db7e9 Mon Sep 17 00:00:00 2001 From: Stormwind Date: Sat, 25 Apr 2015 22:52:20 +0200 Subject: [PATCH] Make interface for weighting input smaller The input object must now only respond to each and must contain arrays. --- lib/rubella/weighting/base.rb | 4 ++-- lib/rubella/weighting/expotential.rb | 15 +++++---------- lib/rubella/weighting/per_overall_load.rb | 6 +----- lib/rubella/weighting/per_value.rb | 13 ++++--------- 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/lib/rubella/weighting/base.rb b/lib/rubella/weighting/base.rb index 7f26cd0..d2c0ac6 100644 --- a/lib/rubella/weighting/base.rb +++ b/lib/rubella/weighting/base.rb @@ -20,7 +20,7 @@ module Rubella # @return Rubella::Weighting::Base # @raise ArgumentError # - def initialize(buckets = 10) + def initialize buckets = 10 self.buckets = buckets end @@ -31,7 +31,7 @@ module Rubella # def buckets= buckets # Must be divideable by 100 - if([1, 2, 5, 10, 20, 50].index(buckets) == nil) + if [1, 2, 5, 10, 20, 50].index(buckets) == nil raise ArgumentError.new "Amount of buckets must be 1, 2, 5, 10, 20 "+ "or 50" end diff --git a/lib/rubella/weighting/expotential.rb b/lib/rubella/weighting/expotential.rb index 5034eb6..65dd44d 100644 --- a/lib/rubella/weighting/expotential.rb +++ b/lib/rubella/weighting/expotential.rb @@ -17,18 +17,13 @@ module Rubella # @param input Rubella::Input An input object # @return Rubella::Storage def parse input - data = input.data - # no data, no work - return [] if data.length == 0 - - # total amount of cores - total_amount = data[0].length - # prepare data - data_list = Array.new() - bucket_no = 0 + data_list = Array.new() + bucket_no = 0 + total_amount = nil - data.each do |cores| + input.each do |cores| + total_amount = cores.length if total_amount.nil? # every 10 load percent one heatpoint i = 0 data_list << Array.new(buckets) do diff --git a/lib/rubella/weighting/per_overall_load.rb b/lib/rubella/weighting/per_overall_load.rb index 63d8e35..a60687b 100644 --- a/lib/rubella/weighting/per_overall_load.rb +++ b/lib/rubella/weighting/per_overall_load.rb @@ -18,14 +18,10 @@ module Rubella # @param input Rubella::Input An input object # @return Rubella::Storage def parse input - data = input.data - # no data, no work - return [] if data.length == 0 - # prepare data data_list = Array.new() - data.each do |cores| + input.each do |cores| # Add all loads to compute how much % is one % load load_sum = 0 diff --git a/lib/rubella/weighting/per_value.rb b/lib/rubella/weighting/per_value.rb index 10456a9..2d5a8d6 100644 --- a/lib/rubella/weighting/per_value.rb +++ b/lib/rubella/weighting/per_value.rb @@ -4,7 +4,7 @@ module Rubella module Weighting # The Rubella::Weighting::PerValue object weights every bucket set to 1 in - # ammount. So if you have have for example four cores, every core is + # amount. So if you have have for example four cores, every core is # weighted to 0.25 no matter how much the load of a single core is. It's # just a "as is" weighting. # @@ -17,17 +17,12 @@ module Rubella # @param input Rubella::Input An input object # @return Rubella::Storage def parse input - data = input.data - # no data, no work - return [] if data.length == 0 - - # total amount of cores - total_amount = data[0].length - # prepare data data_list = Array.new() + total_amount = nil - data.each do |cores| + input.each do |cores| + total_amount = cores.length if total_amount.nil? # every 10 load percent one heatpoint i = 0 data_list << Array.new(buckets) do