Class: Delphin::Profile
- Inherits:
-
Object
- Object
- Delphin::Profile
- Defined in:
- lib/delphin.rb
Overview
A TSDB profile
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#relations ⇒ Object
readonly
Returns the value of attribute relations.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Open the specified table file.
-
#initialize(directory) ⇒ Profile
constructor
A new instance of Profile.
- #inspect ⇒ Object
-
#statistics(table, field) ⇒ Object
Retun mean and standard deviation for numeric values in the specified field.
-
#tables ⇒ Object
A list of all the tables in the profile.
- #to_s ⇒ Object
Constructor Details
#initialize(directory) ⇒ Profile
Returns a new instance of Profile.
186 187 188 189 190 191 192 193 194 195 |
# File 'lib/delphin.rb', line 186 def initialize(directory) @directory = directory begin @relations = open(File.join(directory, "relations")) do |file| RelationsFile.new(file) end rescue Errno::ENOENT raise MissingRelationsFile.new(directory) end end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
184 185 186 |
# File 'lib/delphin.rb', line 184 def directory @directory end |
#relations ⇒ Object (readonly)
Returns the value of attribute relations.
184 185 186 |
# File 'lib/delphin.rb', line 184 def relations @relations end |
Instance Method Details
#[](name) ⇒ Object
Open the specified table file.
211 212 213 |
# File 'lib/delphin.rb', line 211 def [](name) ProfileTable.new(self, name, @relations[name]) end |
#inspect ⇒ Object
197 198 199 |
# File 'lib/delphin.rb', line 197 def inspect "#{self.class}(#{directory})" end |
#statistics(table, field) ⇒ Object
Retun mean and standard deviation for numeric values in the specified field.
217 218 219 220 221 222 223 224 225 226 |
# File 'lib/delphin.rb', line 217 def statistics(table, field) s = self[table].collect {|r| r[field].to_f} n = s.length raise EmptyDataFile.new(table, self) if n.zero? mean = (s.inject(0) {|sum, x| sum + x})/n n = n-1 if n > 1 sdev = Math.sqrt((s.inject(0) {|sum, x| sum + (x-mean)**2})/n) range = s.max - s.min Struct.new(:mean, :sdev, :range).new(mean, sdev, range) end |
#tables ⇒ Object
A list of all the tables in the profile
206 207 208 |
# File 'lib/delphin.rb', line 206 def tables @relations.keys end |
#to_s ⇒ Object
201 202 203 |
# File 'lib/delphin.rb', line 201 def to_s inspect end |