2015-02-17 22:03:32 +01:00
|
|
|
module Rubella
|
|
|
|
|
|
|
|
class Map
|
2015-02-17 22:28:31 +01:00
|
|
|
attr_reader :input
|
|
|
|
attr_reader :output
|
|
|
|
attr_reader :weighting
|
2015-02-17 22:03:32 +01:00
|
|
|
|
2015-02-17 22:28:31 +01:00
|
|
|
def initialize(input_name, output_name, weighting_name)
|
2015-02-17 22:03:32 +01:00
|
|
|
|
2015-02-17 23:01:49 +01:00
|
|
|
# set the input type
|
2015-02-19 07:55:03 +01:00
|
|
|
input_by_name input_name
|
2015-02-17 22:03:32 +01:00
|
|
|
|
2015-02-17 23:01:49 +01:00
|
|
|
# set the output type
|
2015-02-17 22:28:31 +01:00
|
|
|
@output = case output_name
|
2015-02-17 23:01:49 +01:00
|
|
|
# add the option to set the output later
|
|
|
|
when nil then
|
|
|
|
nil
|
2015-02-17 22:03:32 +01:00
|
|
|
when "image" then
|
|
|
|
self.output_image
|
|
|
|
else
|
2015-02-17 22:28:31 +01:00
|
|
|
raise NotImplementedError, "Not supported output type "+output_name+" given"
|
2015-02-17 22:03:32 +01:00
|
|
|
end
|
|
|
|
|
2015-02-17 23:01:49 +01:00
|
|
|
# set the weighting
|
2015-02-17 22:28:31 +01:00
|
|
|
@weighting = case weighting_name
|
2015-02-17 23:01:49 +01:00
|
|
|
# add the option to set the weighting later
|
|
|
|
when nil then
|
|
|
|
nil
|
2015-02-17 22:03:32 +01:00
|
|
|
when "per_value" then
|
|
|
|
self.weighting_per_value
|
|
|
|
when "per_overall_load" then
|
|
|
|
self.weighting_per_overall_load
|
|
|
|
when "expotential" then
|
|
|
|
self.weighting_expotential
|
|
|
|
else
|
2015-02-17 22:28:31 +01:00
|
|
|
raise NotImplementedError, "Not supported weighting type "+weighting_name+" given"
|
2015-02-17 22:03:32 +01:00
|
|
|
end
|
2015-02-17 22:28:31 +01:00
|
|
|
|
2015-02-17 22:03:32 +01:00
|
|
|
end
|
|
|
|
|
2015-02-19 07:28:35 +01:00
|
|
|
# Creates a heatmap in the on construction given format. The data must be
|
|
|
|
# in the also on construction given formate.
|
|
|
|
#
|
|
|
|
# @param data string The data, which should be used
|
|
|
|
# @return binaryblob An output representation of the heatmap
|
2015-02-18 22:20:19 +01:00
|
|
|
def create_from_string data
|
2015-02-18 22:45:02 +01:00
|
|
|
process @input.string data
|
2015-02-18 22:20:19 +01:00
|
|
|
end
|
|
|
|
|
2015-02-19 07:28:35 +01:00
|
|
|
# Creates a heatmap in the on construction given format. The data must be
|
|
|
|
# in the also on construction given formate.
|
|
|
|
#
|
|
|
|
# @param file_name string
|
|
|
|
# @return binaryblob An output representation of the heatmap
|
2015-02-18 22:20:19 +01:00
|
|
|
def create_from_file file_name
|
2015-02-18 22:45:02 +01:00
|
|
|
process @input.file file_name
|
|
|
|
end
|
|
|
|
|
2015-02-19 07:28:35 +01:00
|
|
|
# Processes the creation of the heatmap, after the construction of the input
|
|
|
|
# object. So the input object is given here as parameter.
|
|
|
|
#
|
|
|
|
# @param inpt Input The inputed data
|
|
|
|
# @return binaryblob An output representation of the heatmap
|
2015-02-18 22:45:02 +01:00
|
|
|
def process inpt
|
|
|
|
weight = @weighting.new 10
|
2015-02-18 23:45:53 +01:00
|
|
|
outpt = @output.new
|
|
|
|
outpt.create weight.parse(inpt)
|
2015-02-18 22:20:19 +01:00
|
|
|
end
|
|
|
|
|
2015-02-19 07:55:03 +01:00
|
|
|
# Set the input type by the given name
|
|
|
|
#
|
|
|
|
# @param string Name of the input type in CamelCase
|
|
|
|
def input_by_name input_name
|
|
|
|
# Remove the input, if someone wants to do this
|
2015-02-19 17:22:47 +01:00
|
|
|
@input = load_by_name "Input", input_name
|
|
|
|
end
|
|
|
|
|
|
|
|
# Loads and returns the given class
|
|
|
|
#
|
|
|
|
# @param module_name string The Name of the module in CamelCase
|
|
|
|
# @param class_name string The Name of the class in CamelCase
|
|
|
|
# @return Class
|
|
|
|
# @raise NotImplementedError
|
|
|
|
def load_by_name module_name, class_name
|
|
|
|
# Remove the class, if someone wants to do this
|
|
|
|
if class_name == nil or class_name == ""
|
|
|
|
return nil
|
2015-02-19 07:55:03 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# Try to load the given class
|
2015-02-19 17:22:47 +01:00
|
|
|
require "rubella/"+module_name.downcase+"/"+class_name.downcase
|
2015-02-19 07:55:03 +01:00
|
|
|
|
|
|
|
# Try to get a class by the given name
|
2015-02-19 17:22:47 +01:00
|
|
|
return Object.const_get("Rubella").const_get(module_name).const_get(class_name)
|
2015-02-19 07:55:03 +01:00
|
|
|
|
|
|
|
# TODO raise this error, if input class is not found
|
|
|
|
# raise NotImplementedError, "Not supported input type "+input_name+" given"
|
2015-02-17 22:03:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def output_image
|
|
|
|
require "rubella/output/image"
|
2015-02-17 22:28:31 +01:00
|
|
|
Output::Image
|
2015-02-17 22:03:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def weighting_per_value
|
|
|
|
require "rubella/weighting/per_value"
|
2015-02-17 22:28:31 +01:00
|
|
|
Weighting::PerValue
|
2015-02-17 22:03:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def weighting_per_overall_load
|
|
|
|
require "rubella/weighting/per_overall_load"
|
2015-02-17 22:28:31 +01:00
|
|
|
Weighting::PerOverallLoad
|
2015-02-17 22:03:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def weighting_expotential
|
|
|
|
require "rubella/weighting/expotential"
|
2015-02-17 22:28:31 +01:00
|
|
|
Weighting::Expotential
|
2015-02-17 22:03:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|