Class: DataInput::DataRepository
- Inherits:
-
Object
- Object
- DataInput::DataRepository
- Defined in:
- lib/data/data_repository.rb
Overview
This class serves as a data repository storing the read data and handling the meta information
Instance Attribute Summary collapse
-
#repository ⇒ Hash
readonly
Mapping (MetaData::VisMetaData => DataSeries).
Instance Method Summary collapse
-
#add_data(filename) ⇒ VisMetaData
reads the file and creates meta information and data of its content.
-
#add_data_with_default_meta(filename) ⇒ VisMetaData
reads the file and creates data of its content with default meta information.
-
#build_meta_string(data_series, filename) ⇒ Array
private
method to build the meta string that is uses for default MetaData::VisMetaData.
-
#check_for_existenz(key) ⇒ Object
private
checks if a given key already exists in the repository.
-
#check_for_metadata(data) ⇒ VisMetaData
private
checks for meta data in the first line of the raw data and creates meta information from it.
-
#create_dataseries(data) ⇒ DataSeries
private
creates DataSets of the parsed data and stores it into a DataSeries.
-
#data_complete?(meta_data) ⇒ boolean
checks if all data sets in a data_series have the dimension specified in the MetaData::VisMetaData information.
-
#dataset_dimension_correct?(meta_data) ⇒ boolean
checks if the dimension of each dataset is consistent with the information of the corresponding MetaData::VisMetaData.
-
#get_data_values(data_set) ⇒ Hash
private
method to retireve the number of data values in the x and y dimension based on the size of the DataSet.
-
#get_domain_values(meta_data) ⇒ Hash
private
method to retrieve the number of data values in the x and y dimension based on the MetaData::VisMetaData information.
-
#initialize(filename = nil, key = nil) ⇒ DataRepository
constructor
initialization.
-
#print_domain_mismatch(index, domain_values, data_values) ⇒ Object
private
method to print a warning if the dimension of the meta data does not fit with the dimension of the actual dataset.
-
#read_file(filename) ⇒ Array
private
calls the FileReader to get the content of the file.
-
#z_dimension_correct?(meta_data) ⇒ boolean
private
checks if all data sets in a data_series have the dimension in z specified in the MetaData::VisMetaData information.
Constructor Details
#initialize(filename = nil, key = nil) ⇒ DataRepository
initialization
17 18 19 20 21 22 23 24 |
# File 'lib/data/data_repository.rb', line 17 def initialize(filename = nil,key = nil) @repository = Hash.new() (filename) if (key == nil && filename != nil) if (filename != nil && key != nil) data = read_file(filename) @repository[key] = create_dataseries(data) end end |
Instance Attribute Details
#repository ⇒ Hash (readonly)
Returns mapping (MetaData::VisMetaData => DataInput::DataSeries).
12 13 14 |
# File 'lib/data/data_repository.rb', line 12 def repository @repository end |
Instance Method Details
#add_data(filename) ⇒ VisMetaData
reads the file and creates meta information and data of its content
29 30 31 32 33 34 35 |
# File 'lib/data/data_repository.rb', line 29 def add_data(filename) data = read_file(filename) = (data) check_for_existenz() @repository[] = create_dataseries(data) return end |
#add_data_with_default_meta(filename) ⇒ VisMetaData
reads the file and creates data of its content with default meta information
41 42 43 44 45 46 47 48 49 |
# File 'lib/data/data_repository.rb', line 41 def (filename) data = read_file(filename) data_series = create_dataseries(data) = (data_series, filename) = MetaData::VisMetaData.new() @repository[] = data_series return end |
#build_meta_string(data_series, filename) ⇒ Array (private)
method to build the meta string that is uses for default
{MetaData::VisMetaData}
167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/data/data_repository.rb', line 167 def (data_series, filename) = ["#{filename}", \ 'X', 0, data_series.series[0].data[0].size - 1, 1, \ 'Y', 0, data_series.series[0].data.size - 1, 1] if (data_series.series.size > 1) .concat( ['Z', 0, data_series.series.size, 1] ) else .concat( ['Z', 0, 1, 1] ) end return end |
#check_for_existenz(key) ⇒ Object (private)
checks if a given key already exists in the repository
201 202 203 204 205 |
# File 'lib/data/data_repository.rb', line 201 def check_for_existenz(key) if (@repository[key] != nil) puts 'Info: A data set with this key already exists. Overwriting...' end end |
#check_for_metadata(data) ⇒ VisMetaData (private)
checks for meta data in the first line of the raw data and creates meta information from it
192 193 194 195 196 197 |
# File 'lib/data/data_repository.rb', line 192 def (data) = data[0] data.delete_at(1) data.delete_at(0) MetaData::VisMetaData.new() end |
#create_dataseries(data) ⇒ DataSeries (private)
creates DataInput::DataSets of the parsed data and stores it into a DataInput::DataSeries
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/data/data_repository.rb', line 143 def create_dataseries(data) raw_data = Array.new() value = DataSeries.new() # parse multiple data sets (but at least 1) data.each { |line| if (line.empty?) value.add_data_set(DataSet.new(raw_data)) raw_data = Array.new() else raw_data << line end } # get the last data set, since the loop ended before putting it there value.add_data_set(DataSet.new(raw_data)) return value end |
#data_complete?(meta_data) ⇒ boolean
checks if all data sets in a data_series have the dimension specified in the MetaData::VisMetaData information
56 57 58 |
# File 'lib/data/data_repository.rb', line 56 def data_complete?() dataset_dimension_correct?() || z_dimension_correct?() end |
#dataset_dimension_correct?(meta_data) ⇒ boolean
checks if the dimension of each dataset is consistent with the information of the corresponding MetaData::VisMetaData
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/data/data_repository.rb', line 65 def dataset_dimension_correct?() domain_values = get_domain_values() @repository[].series.each_with_index { |data_set, index| data_values = get_data_values(data_set) if (domain_values[:x] != data_values[:x] || domain_values[:y] != data_values[:y]) print_domain_mismatch(index, domain_values, data_values) return false end } return true end |
#get_data_values(data_set) ⇒ Hash (private)
method to retireve the number of data values in the x and y dimension based on the size of the DataInput::DataSet
98 99 100 101 102 103 |
# File 'lib/data/data_repository.rb', line 98 def get_data_values(data_set) data_values = Hash.new() data_values[:x] = data_set.data[0].size data_values[:y] = data_set.data.size return data_values end |
#get_domain_values(meta_data) ⇒ Hash (private)
method to retrieve the number of data values in the x and y dimension based on the MetaData::VisMetaData information
87 88 89 90 91 92 |
# File 'lib/data/data_repository.rb', line 87 def get_domain_values() domain_values = Hash.new() domain_values[:x] = .domain_x.number_of_values domain_values[:y] = .domain_y.number_of_values return domain_values end |
#print_domain_mismatch(index, domain_values, data_values) ⇒ Object (private)
method to print a warning if the dimension of the meta data does not fit with the dimension of the actual dataset
112 113 114 115 116 117 |
# File 'lib/data/data_repository.rb', line 112 def print_domain_mismatch(index, domain_values, data_values) puts " Warning: Size of dataset #{index + 1} does not match " \ "with meta data information.".yellow puts " meta_data: #{domain_values[:x]}, #{domain_values[:y]}".yellow puts " data_set: #{data_values[:x]}, #{data_values[:y]}".yellow end |
#read_file(filename) ⇒ Array (private)
calls the FileReader to get the content of the file
184 185 186 |
# File 'lib/data/data_repository.rb', line 184 def read_file(filename) RubyUtils::FileReader.new(filename, ',').data end |
#z_dimension_correct?(meta_data) ⇒ boolean (private)
checks if all data sets in a data_series have the dimension in z specified in the MetaData::VisMetaData information
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/data/data_repository.rb', line 124 def z_dimension_correct?() data_series = @repository[] number_value_z = .domain_z.number_of_values number_data_z = data_series.series.size if (number_value_z != number_data_z) puts ' Warning: Size of dataseries does not match with' \ ' meta data information.'.yellow puts " meta_data: #{number_value_z} datasets to data_series: " \ "#{number_data_z} datasets".yellow return false end return true end |