Sha256: 0dcf9dd08f2c2dc9508b761e98ba58c2bc0d4a5416bc92d7cdc32331cc04d8e3
Contents?: true
Size: 1.44 KB
Versions: 14
Compression:
Stored size: 1.44 KB
Contents
require 'omf_oml/table' # Create a table containing 'amplitude' measurements taken at a certain time for two different # devices. # schema = [[:t, :float], [:device, :string], [:amplitude, :float], [:x, :float], [:y, :float]] table = OMF::OML::OmlTable.new 'generator', schema, :max_size => 20 table_static = OMF::OML::OmlTable.new 'generator_static', schema require 'omf_web' OMF::Web.register_datasource table OMF::Web.register_datasource table_static samples = 30 ctxt = { :timeOffset => Time.now.to_i, :timeScale => 300, # Measure every 10 minutes :radius => 10, :fluctuation => 0.1, # max disturbance of sample :rad => 2 * Math::PI / samples } def measure(i, table, ctxt) t = ctxt[:timeOffset] + ctxt[:timeScale] * i angle = i * ctxt[:rad] measure_device('Dev1', t, angle, table, ctxt) measure_device('Dev2', t, angle + ctxt[:rad] + 0.2 * (rand() - 0.5), table, ctxt) end def measure_device(name, t, angle, table, ctxt) r = ctxt[:radius] * (1 + (rand() - 0.5) * ctxt[:fluctuation]) table.add_row [t, name, r, r * Math.sin(angle), r * Math.cos(angle)] end samples.times {|i| measure(i, table, ctxt) } samples.times do |i| c = ctxt.dup c[:timeOffset] = 0 c[:timeScale] = 1 measure(i, table_static, c) end # Keep on measuring Thread.new do begin i = samples loop do sleep 0.5 measure i, table, ctxt i += 1 end rescue Exception => ex puts ex puts ex.backtrace.join("\n") end end
Version data entries
14 entries across 14 versions & 1 rubygems