From d3531e8d2b1601be4bd7fa5cf7d559f37e02a0f3 Mon Sep 17 00:00:00 2001 From: Stormwind Date: Tue, 17 Feb 2015 22:03:32 +0100 Subject: [PATCH] Started implementation of rubella Dunno why there is no earlier commit... Map class is probably a little bit too static. I will rewort this later, but first we'll finish some of the other stuff. --- lib/rubella.rb | 55 +++++++++++++++++++++++ lib/rubella/input/json.rb | 29 ++++++++++++ lib/rubella/output/image.rb | 0 lib/rubella/weighting/exponential.rb | 0 lib/rubella/weighting/per_overall_load.rb | 0 lib/rubella/weighting/per_value.rb | 24 ++++++++++ 6 files changed, 108 insertions(+) create mode 100644 lib/rubella.rb create mode 100644 lib/rubella/input/json.rb create mode 100644 lib/rubella/output/image.rb create mode 100644 lib/rubella/weighting/exponential.rb create mode 100644 lib/rubella/weighting/per_overall_load.rb create mode 100644 lib/rubella/weighting/per_value.rb diff --git a/lib/rubella.rb b/lib/rubella.rb new file mode 100644 index 0000000..93b1304 --- /dev/null +++ b/lib/rubella.rb @@ -0,0 +1,55 @@ +module Rubella + + class Map + + def initialize(input, output, weighting) + + case input + when "json" then + self.input_json + else + raise NotImplementedError, "Not supported input type "+input+" given" + end + + case output + when "image" then + self.output_image + else + raise NotImplementedError, "Not supported output type "+output+" given" + end + + case weighting + 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 + raise NotImplementedError, "Not supported weighting type "+weighting+" given" + end + + end + + def input_json + require "rubella/input/json" + end + + def output_image + require "rubella/output/image" + end + + def weighting_per_value + require "rubella/weighting/per_value" + end + + def weighting_per_overall_load + require "rubella/weighting/per_overall_load" + end + + def weighting_expotential + require "rubella/weighting/expotential" + end + + end +end \ No newline at end of file diff --git a/lib/rubella/input/json.rb b/lib/rubella/input/json.rb new file mode 100644 index 0000000..38e5d70 --- /dev/null +++ b/lib/rubella/input/json.rb @@ -0,0 +1,29 @@ +require 'json' + +module Rubella + module Input + + # + # + class JSON + + attr_reader :data + + def initialize(json_string) + data = ::JSON::load(json_string) + end + + def self.string(json_string) + self.new(json_string) + end + + def self.file(json_file) + self.new File.new(json_file, 'r') + end + + # private :new + + end + + end +end \ No newline at end of file diff --git a/lib/rubella/output/image.rb b/lib/rubella/output/image.rb new file mode 100644 index 0000000..e69de29 diff --git a/lib/rubella/weighting/exponential.rb b/lib/rubella/weighting/exponential.rb new file mode 100644 index 0000000..e69de29 diff --git a/lib/rubella/weighting/per_overall_load.rb b/lib/rubella/weighting/per_overall_load.rb new file mode 100644 index 0000000..e69de29 diff --git a/lib/rubella/weighting/per_value.rb b/lib/rubella/weighting/per_value.rb new file mode 100644 index 0000000..5c24b35 --- /dev/null +++ b/lib/rubella/weighting/per_value.rb @@ -0,0 +1,24 @@ +module Rubella + module Weigthing + + # Gets an input object and prepares the data for the output. + # + # This class weights the input data per value. + # Which means, that all values together make 100%. So you need all values at + # the same level, to get the maximum color intensity. + # + # The output is an Array which contains again an Array per every point of + # time, which contains the load in the given steps (default is 10% per step) + # and the value in percentage for the representative olor intensity. + # + class PerValue + + def initialize + end + + + + end + + end +end