Class: DatasetScaling
- Inherits:
 - 
      Object
      
        
- Object
 - DatasetScaling
 
 
- Defined in:
 - lib/scaling/dataset_scaling.rb
 
Overview
Helper class to generate a scaled DataSet from a (MetaData::VisMetaData, DataSet) pair with the scaling based on the size of the terminal where the script is started.
Instance Attribute Summary collapse
- 
  
    
      #columns  ⇒ Integer 
    
    
  
  
  
  
    
      readonly
    
    
  
  private
  
  
  
  
    
The number of fields per row of the used terminal.
 - 
  
    
      #lines  ⇒ Integer 
    
    
  
  
  
  
    
      readonly
    
    
  
  private
  
  
  
  
    
The number of lines of the used terminal.
 - 
  
    
      #meta_data  ⇒ VisMetaData 
    
    
  
  
  
  
    
      readonly
    
    
  
  private
  
  
  
  
    
The original MetaData::VisMetaData of the DataSet.
 - 
  
    
      #scaled_data_set  ⇒ DataSet 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The scaled DataSet.
 - 
  
    
      #scaled_meta  ⇒ VisMetaData 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The VisMetaData of the scaled DataSet.
 
Instance Method Summary collapse
- 
  
    
      #add_domain_information(data_domain, new_step)  ⇒ Array 
    
    
  
  
  
  
  private
  
  
  
  
    
method to add the required parameter to the MetaData::VisMetaData string.
 - 
  
    
      #calculate_new_resolution_meta  ⇒ Object 
    
    
  
  
  
  
  private
  
  
  
  
    
method to create the meta data object for the scaled dataset.
 - 
  
    
      #calculate_scaled_dataset(data_set)  ⇒ Dataset 
    
    
  
  
  
  
  private
  
  
  
  
    
method to create the scaled dataset by interpolating new data values.
 - 
  
    
      #calculated_dimension_delta(data_domain)  ⇒ Float 
    
    
  
  
  
  
  private
  
  
  
  
    
method to calculate the half distance of a data domain.
 - 
  
    
      #check_value_boundaries  ⇒ Object 
    
    
  
  
  
  
  private
  
  
  
  
    
method to check if the dimensions of the terminal are big enough to create a useful result.
 - 
  
    
      #create_new_data_dimensions  ⇒ Array 
    
    
  
  
  
  
  private
  
  
  
  
    
method to create the entris for the x and y domain of the scaled meta data.
 - 
  
    
      #determine_coordinates  ⇒ Hash 
    
    
  
  
  
  
  private
  
  
  
  
    
method to retrieve the central coordinate of the dataset.
 - 
  
    
      #determine_values  ⇒ Hash 
    
    
  
  
  
  
  private
  
  
  
  
    
method to calculate the required parameter values for the interpolation.
 - 
  
    
      #initialize(meta_data, data_set)  ⇒ DatasetScaling 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
initialization.
 
Constructor Details
#initialize(meta_data, data_set) ⇒ DatasetScaling
initialization
      22 23 24 25 26 27 28 29 30  | 
    
      # File 'lib/scaling/dataset_scaling.rb', line 22 def initialize(, data_set) @meta_data = ts = TerminalSize::TerminalSize.new() @lines = ts.lines - 14 @columns = ts.columns - 10 check_value_boundaries @scaled_data_set = calculate_scaled_dataset(data_set) end  | 
  
Instance Attribute Details
#columns ⇒ Integer (readonly, private)
Returns the number of fields per row of the used terminal.
      38 39 40  | 
    
      # File 'lib/scaling/dataset_scaling.rb', line 38 def columns @columns end  | 
  
#lines ⇒ Integer (readonly, private)
Returns the number of lines of the used terminal.
      36 37 38  | 
    
      # File 'lib/scaling/dataset_scaling.rb', line 36 def lines @lines end  | 
  
#meta_data ⇒ VisMetaData (readonly, private)
Returns the original MetaData::VisMetaData of the DataSet.
      34 35 36  | 
    
      # File 'lib/scaling/dataset_scaling.rb', line 34 def @meta_data end  | 
  
#scaled_data_set ⇒ DataSet (readonly)
Returns the scaled DataSet.
      16 17 18  | 
    
      # File 'lib/scaling/dataset_scaling.rb', line 16 def scaled_data_set @scaled_data_set end  | 
  
#scaled_meta ⇒ VisMetaData (readonly)
Returns the VisMetaData of the scaled DataSet.
      14 15 16  | 
    
      # File 'lib/scaling/dataset_scaling.rb', line 14 def @scaled_meta end  | 
  
Instance Method Details
#add_domain_information(data_domain, new_step) ⇒ Array (private)
method to add the required parameter to the MetaData::VisMetaData string
      89 90 91  | 
    
      # File 'lib/scaling/dataset_scaling.rb', line 89 def add_domain_information(data_domain, new_step) [data_domain.name, data_domain.lower, data_domain.upper, new_step] end  | 
  
#calculate_new_resolution_meta ⇒ Object (private)
method to create the meta data object for the scaled dataset
      52 53 54 55 56 57 58 59 60  | 
    
      # File 'lib/scaling/dataset_scaling.rb', line 52 def # determine new meta information and create ne meta object = [@meta_data.name] .concat(create_new_data_dimensions) .concat(add_domain_information(@meta_data.domain_z, @meta_data.domain_z.step)) # return the new meta data object @scaled_meta = MetaData::VisMetaData.new() end  | 
  
#calculate_scaled_dataset(data_set) ⇒ Dataset (private)
method to create the scaled dataset by interpolating new data values
      43 44 45 46 47 48 49  | 
    
      # File 'lib/scaling/dataset_scaling.rb', line 43 def calculate_scaled_dataset(data_set) coordinates = determine_coordinates values = determine_values TerminalVis::Interpolation.region_interpolation(@meta_data, data_set, coordinates, values) end  | 
  
#calculated_dimension_delta(data_domain) ⇒ Float (private)
method to calculate the half distance of a data domain
      118 119 120  | 
    
      # File 'lib/scaling/dataset_scaling.rb', line 118 def calculated_dimension_delta(data_domain) ((data_domain.upper - data_domain.lower) / 2).round(3) end  | 
  
#check_value_boundaries ⇒ Object (private)
method to check if the dimensions of the terminal are big enough to create a useful result
      64 65 66 67 68 69  | 
    
      # File 'lib/scaling/dataset_scaling.rb', line 64 def check_value_boundaries if (@lines < 9 || @columns < 20) raise ArgumentError, ' Error: The terminal size is to small for scaled output'.red end end  | 
  
#create_new_data_dimensions ⇒ Array (private)
method to create the entris for the x and y domain of the scaled meta data
      73 74 75 76 77 78 79 80 81  | 
    
      # File 'lib/scaling/dataset_scaling.rb', line 73 def create_new_data_dimensions # map the meta information to the resolution delta_x = ((@meta_data.domain_x.upper - @meta_data.domain_x.lower) / @columns).round(3) * 2 delta_y = ((@meta_data.domain_y.upper - @meta_data.domain_y.lower) / @lines).round(3) = add_domain_information(@meta_data.domain_x, delta_x) .concat(add_domain_information(@meta_data.domain_y, delta_y)) end  | 
  
#determine_coordinates ⇒ Hash (private)
method to retrieve the central coordinate of the dataset
      96 97 98 99 100 101 102 103  | 
    
      # File 'lib/scaling/dataset_scaling.rb', line 96 def determine_coordinates coordinates = Hash.new() coordinates[:x] = @scaled_meta.domain_x.lower + calculated_dimension_delta(@scaled_meta.domain_x) coordinates[:y] = @scaled_meta.domain_y.lower + calculated_dimension_delta(@scaled_meta.domain_y) return coordinates end  | 
  
#determine_values ⇒ Hash (private)
method to calculate the required parameter values for the interpolation
      107 108 109 110 111 112  | 
    
      # File 'lib/scaling/dataset_scaling.rb', line 107 def determine_values { :inter_x => calculated_dimension_delta(@scaled_meta.domain_x), :delta_x => @scaled_meta.domain_x.step, :inter_y => calculated_dimension_delta(@scaled_meta.domain_y), :delta_y => @scaled_meta.domain_y.step } end  |