From 6d9eecb5e55d525cc7862997140748a5456d0837 Mon Sep 17 00:00:00 2001 From: Stormwind Date: Sat, 25 Apr 2015 22:09:16 +0200 Subject: [PATCH] Add implementation of Rubella::Weighting::PerOverallLoad --- lib/rubella/weighting/per_overall_load.rb | 49 ++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/rubella/weighting/per_overall_load.rb b/lib/rubella/weighting/per_overall_load.rb index 073cdf5..63d8e35 100644 --- a/lib/rubella/weighting/per_overall_load.rb +++ b/lib/rubella/weighting/per_overall_load.rb @@ -1,7 +1,54 @@ +require "rubella/weighting/base" + module Rubella module Weighting - class PerOverallLoad + # The Rubella::Weighting::PerOverallValue object summarizes the load of all + # cores in a time and computes how much load is one percent. Then it uses + # this as factor to weight the summarized load of every bucket. + # So your representation will show you the higher load cores more + # intensive, then the cores with lower load, depending on the current load. + # + class PerOverallLoad < Base + + # Creates a output readable list. + # This list is Array within a subarrays, which contain the buckets for + # every time value unit. + # + # @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| + + # Add all loads to compute how much % is one % load + load_sum = 0 + cores.each { |core| load_sum = load_sum + core } + percent_load = 100.0/load_sum + + # every 10 load percent one heatpoint + i = 0 + data_list << Array.new(buckets) do + # Select all current cores + selected_cores = cores.select { |core| core >= i and core < (i+@steps)} + i = i + @steps + + # add the load of the resulting cores and multiply it with the overall value + load_sum = 0 + selected_cores.each { |core| load_sum = load_sum + core } + (load_sum.to_f*percent_load)/100 + end + end + + Rubella::Storage.new data_list + end + end end