Class: Delphin::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/delphin.rb

Overview

A TSDB profile

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#directoryObject (readonly)

Returns the value of attribute directory.



184
185
186
# File 'lib/delphin.rb', line 184

def directory
  @directory
end

#relationsObject (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

#inspectObject



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.

Raises:



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

#tablesObject

A list of all the tables in the profile



206
207
208
# File 'lib/delphin.rb', line 206

def tables
  @relations.keys
end

#to_sObject



201
202
203
# File 'lib/delphin.rb', line 201

def to_s
  inspect
end