0
0
Fork 0

Add Rubella::Weighting::PerCount

The Rubella::Weighting::PerCount create a field of each given value.
The weighting is based on the maximum value.
So you are able to create i.e. commit per day maps.
This commit is contained in:
Stormwind 2015-05-05 21:45:23 +02:00
parent 496e96be91
commit 46044b843f
1 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,61 @@
require "rubella/weighting/base"
module Rubella
module Weighting
# The Rubella::Weighting::PerCount create a field of each given value.
# The weighting is based on the maximum value.
#
class PerCount < Base
# Constructor
# Creates a new Rubella::Weighting::PerCount object.
#
# @param buckets int
# @return Rubella::Weighting::Base
# @raise ArgumentError
#
def initialize buckets = 7
super buckets
end
# Sets the buckets
#
# @param buckets int The amount of buckets
# @raise ArgumentError
#
def buckets= buckets
@buckets = buckets
end
# 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
# prepare data
data_list = Array.new()
# Get the maximum of commits
max = input.sort.pop
i = 0
input.each do |commits|
data_list << Array.new() if i == 0
data_list.last << commits.to_f/max
if i == (buckets-1)
i = 0
else
i = i + 1
end
end
Rubella::Storage.new data_list
end
end
end
end