From 46a44ae9c2ec3307148be07208da616cf8c22d43 Mon Sep 17 00:00:00 2001 From: Stormwind Date: Wed, 18 Feb 2015 22:45:02 +0100 Subject: [PATCH] Get Input data into weightin process The data gets weighted. I also fixed some tiny bugs. --- lib/rubella.rb | 9 +++++++-- lib/rubella/weighting/per_value.rb | 7 ++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/rubella.rb b/lib/rubella.rb index 02bb439..4c26ef1 100644 --- a/lib/rubella.rb +++ b/lib/rubella.rb @@ -47,11 +47,16 @@ module Rubella end def create_from_string data - @input.string data + process @input.string data end def create_from_file file_name - @input.file file_name + process @input.file file_name + end + + def process inpt + weight = @weighting.new 10 + weight.parse inpt end def input_json diff --git a/lib/rubella/weighting/per_value.rb b/lib/rubella/weighting/per_value.rb index 1683809..fa03fd8 100644 --- a/lib/rubella/weighting/per_value.rb +++ b/lib/rubella/weighting/per_value.rb @@ -12,7 +12,8 @@ module Rubella self.buckets = buckets end - def parse(data) + def parse input + data = input.data # no data, no work return [] if data.length == 0 @@ -29,7 +30,7 @@ module Rubella data_list << Array.new(buckets) do amount = cores.select { |core| core >= i and core < (i+@steps)}.length i = i + @steps - amount/total_amount + amount.to_f/total_amount end end @@ -42,7 +43,7 @@ module Rubella raise ArgumentError, "Amount of buckets must be 1, 2, 5, 10, 20 or 50" end - @steps = buckets/100 + @steps = 100/buckets @buckets = buckets end