Class: OmfEc::Graph::GraphDescription

Inherits:
Object
  • Object
show all
Defined in:
omf_ec/lib/omf_ec/graph/graph_description.rb

Overview

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

Constant Summary

@@gds =
{}

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) create(name = nil)



14
15
16
17
18
19
20
# File 'omf_ec/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

Instance Method Details

- (Object) _report



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'omf_ec/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

- (Object) _report_meta



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'omf_ec/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.(@name, descr, :graph)
end

- (Object) caption(text)



83
84
85
# File 'omf_ec/lib/omf_ec/graph/graph_description.rb', line 83

def caption(text)
  @caption = text
end

- (Object) mapping(mhash)

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

Parameters:

  • mhash

    Hash of mappings specific to the graph ifentified by 'type'



67
68
69
# File 'omf_ec/lib/omf_ec/graph/graph_description.rb', line 67

def mapping(mhash)
  @mapping = mhash
end

- (Object) ms(ms_name, context = :default)

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.

Parameters:

  • ms_name
  • context (defaults to: :default)


39
40
41
42
43
44
45
46
# File 'omf_ec/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

- (Object) opts(additional_opts = {})



87
88
89
# File 'omf_ec/lib/omf_ec/graph/graph_description.rb', line 87

def opts(additional_opts = {})
  @opts = additional_opts
end

- (Object) postfix(text)

Define text to be shown above the graph

Parameters:

  • text


26
27
28
# File 'omf_ec/lib/omf_ec/graph/graph_description.rb', line 26

def postfix(text)
  @postfix = text
end

- (Object) sql(raw_sql, context = :default)

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.

Parameters:

  • sql
  • context (defaults to: :default)


58
59
60
61
# File 'omf_ec/lib/omf_ec/graph/graph_description.rb', line 58

def sql(raw_sql, context = :default)
  @ms[context] = raw_sql
  raw_sql
end

- (Object) type(gtype)



71
72
73
# File 'omf_ec/lib/omf_ec/graph/graph_description.rb', line 71

def type(gtype)
  @gtype = gtype
end

- (Object) xaxis(props)



75
76
77
# File 'omf_ec/lib/omf_ec/graph/graph_description.rb', line 75

def xaxis(props)
  (@axis ||= {})[:x] = props
end

- (Object) yaxis(props)



79
80
81
# File 'omf_ec/lib/omf_ec/graph/graph_description.rb', line 79

def yaxis(props)
  (@axis ||= {})[:y] = props
end