class OmfEc::Graph::GraphDescription

Describes a graph which can be displayed through the web interface or any other defined graph visualiser.

Public Class Methods

create(name = nil) click to toggle source
# File lib/omf_ec/graph/graph_description.rb, line 14
def self.create(name = nil)
  if name
    @@gds[name.to_sym] ||= self.new(name)
  else
    self.new("Unknown #{self.object_id}")
  end
end
new(name) click to toggle source
# File lib/omf_ec/graph/graph_description.rb, line 136
def initialize(name)
  @name = name
  @ms = {}
  # Create a generic Sequel object which can be used to serialize the query.
  # TODO: Make sure this is generic enough
  @db = Sequel.postgres
  @db.instance_variable_set('@server_version', 90105)
end

Public Instance Methods

_report() click to toggle source
# File lib/omf_ec/graph/graph_description.rb, line 91
def _report
  _report_meta
  info "REPORT:START: #{@name}"
  info "REPORT:TYPE: #{@gtype}"
  info "REPORT:POSTFIX: #{URI.encode(@postfix)}" if @postfix
  @ms.each do |ctxt, a|
    a.each do |ms|
      sql = ms.is_a?(String) ? ms : ms.sql
      info "REPORT:MS:#{ctxt}: #{URI.encode(sql)}"
    end
  end
  info "REPORT:MAPPING: #{URI.encode(@mapping.to_json)}"
  if @axis
    info "REPORT:AXIS: #{URI.encode(@axis.to_json)}"
  end
  info "REPORT:CAPTION: #{URI.encode(@caption)}" if @caption
  info "REPORT:OPTS: #{URI.encode(@opts.to_json)}" if @opts
  info "REPORT:STOP"
end
_report_meta() click to toggle source
# File lib/omf_ec/graph/graph_description.rb, line 111
def _report_meta
  h = {
    type: @gtype,
    mapping: @mapping,
    caption: @caption
  }
  h[:postfix] = @postfix if @postfix
  dss = h[:dss] = {}
  @ms.each do |ctxt, a|
    a.each do |ms|
      dss[ctxt] = ms.sql
    end
  end
  if @axis
    h[:axis] = @axis
  end

  h[:opts] = @opts if @opts

  descr = h.to_json
  OmfEc.experiment.log_metadata(@name, descr, :graph)
end
caption(text) click to toggle source
# File lib/omf_ec/graph/graph_description.rb, line 83
def caption(text)
  @caption = text
end
mapping(mhash) click to toggle source

Defines the mapping of columns in the measurement tuples to properties of the visualization.

@param mhash Hash of mappings specific to the graph ifentified by ‘type’

# File lib/omf_ec/graph/graph_description.rb, line 67
def mapping(mhash)
  @mapping = mhash
end
ms(ms_name, context = :default) click to toggle source

Define the measurement stream to be visualized in the graph. The optional ‘context’ parameter defines the context in which the MS is used in the graph. This is necessary for graphs, such as ‘networks’ which need more than one MS to describe the visualization.

@param ms_name @param context

# File lib/omf_ec/graph/graph_description.rb, line 39
def ms(ms_name, context = :default)
  if (table_name = OmfEc.experiment.mp_table_names[ms_name])
    (@ms[context] ||= []) << (msb = MSBuilder.new(@db[table_name.to_sym]))
  else
    warn "Measurement point '#{ms_name}' NOT defined"
  end
  msb
end
opts(additional_opts = {}) click to toggle source
# File lib/omf_ec/graph/graph_description.rb, line 87
def opts(additional_opts = {})
  @opts = additional_opts
end
postfix(text) click to toggle source

Define text to be shown above the graph

@param text

# File lib/omf_ec/graph/graph_description.rb, line 26
def postfix(text)
  @postfix = text
end
sql(raw_sql, context = :default) click to toggle source

Define the measurement stream to be visualized in the graph through a raw SQL query string. The optional ‘context’ parameter defines the context in which the stream is used in the graph. This is necessary for graphs, such as ‘networks’ which need more than one MS to describe the visualization.

@param sql @param context

# File lib/omf_ec/graph/graph_description.rb, line 58
def sql(raw_sql, context = :default)
  @ms[context] = raw_sql
  raw_sql
end
type(gtype) click to toggle source
# File lib/omf_ec/graph/graph_description.rb, line 71
def type(gtype)
  @gtype = gtype
end
xaxis(props) click to toggle source
# File lib/omf_ec/graph/graph_description.rb, line 75
def xaxis(props)
  (@axis ||= {})[:x] = props
end
yaxis(props) click to toggle source
# File lib/omf_ec/graph/graph_description.rb, line 79
def yaxis(props)
  (@axis ||= {})[:y] = props
end