Class: Graph
- Inherits:
-
Object
- Object
- Graph
- Includes:
- YAMLInteraction
- Defined in:
- lib/html_compilation/classes/builders/graph.rb
Instance Attribute Summary collapse
-
#chart ⇒ Object
Returns the value of attribute chart.
-
#graph_length ⇒ Object
readonly
Returns the value of attribute graph_length.
Instance Method Summary collapse
- #app_listed(app, dl) ⇒ Object
- #array_slicer(values) ⇒ Object
- #generate_graph(app_object, ddl = "./data") ⇒ Object
-
#initialize ⇒ Graph
constructor
A new instance of Graph.
- #populate_graph ⇒ Object
- #update_yaml(app, score, dl) ⇒ Object
Methods included from YAMLInteraction
Constructor Details
#initialize ⇒ Graph
Returns a new instance of Graph.
11 12 13 |
# File 'lib/html_compilation/classes/builders/graph.rb', line 11 def initialize @graph_length = 30 end |
Instance Attribute Details
#chart ⇒ Object
Returns the value of attribute chart.
6 7 8 |
# File 'lib/html_compilation/classes/builders/graph.rb', line 6 def chart @chart end |
#graph_length ⇒ Object (readonly)
Returns the value of attribute graph_length.
8 9 10 |
# File 'lib/html_compilation/classes/builders/graph.rb', line 8 def graph_length @graph_length end |
Instance Method Details
#app_listed(app, dl) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/html_compilation/classes/builders/graph.rb', line 62 def app_listed(app, dl) if read_yaml(dl, app) != nil true else false end end |
#array_slicer(values) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/html_compilation/classes/builders/graph.rb', line 43 def array_slicer(values) if values.length > graph_length output = values[((values.length - 1) - (graph_length - 1))..(values.length - 1)] else output = values end output end |
#generate_graph(app_object, ddl = "./data") ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/html_compilation/classes/builders/graph.rb', line 15 def generate_graph(app_object, ddl = "./data") gs = "/graph_scores.yaml" app = app_object.application_name.upcase.tr(' ', '_') score = app_object.calculate_app_score update_yaml(app, score, ddl + gs) values = array_slicer(read_yaml(ddl + gs, app).split(',').map(&:to_i)) max = values.sort.last.to_i split = (max / 5).to_i value = 0 string = '0|' values.length > graph_length ? end_range = graph_length : end_range = values.length 4.times {value += split; string += value.to_s + '|'} self.send("chart=", Gchart.new({:type => 'bar', :data => values, :axis_with_labels => 'x,y', :axis_labels => [(1..end_range).to_a.reverse, string], :axis_range => [nil, [0, max]], :title => "#{app.downcase.tr('_', ' ')} #{app_object.env}", :legend => ['total score'], :bg => {:color => 'white', :type => 'solid'}, :bar_colors => 'ADEFD1FF', :size => '1000x200', :filename => "#{ddl}/output/files/chart.png"})) end |
#populate_graph ⇒ Object
39 40 41 |
# File 'lib/html_compilation/classes/builders/graph.rb', line 39 def populate_graph chart.file end |
#update_yaml(app, score, dl) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/html_compilation/classes/builders/graph.rb', line 52 def update_yaml(app, score, dl) app_up = app.upcase.tr(' ', '_') if !app_listed(app_up, dl) key_value_add(dl, app_up, score.to_s) else cur_val = read_yaml(dl, app_up) key_value_add(dl, app_up, cur_val + "," + score.to_s) end end |