Skip to content

Commit

Permalink
Pulling out logic into the Table class.
Browse files Browse the repository at this point in the history
  • Loading branch information
nstielau committed May 28, 2010
1 parent f0d51a0 commit 12ec753
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/autograph/autoperf.rb
Expand Up @@ -28,8 +28,7 @@ def generate_graphs(reports, configuration)
end

reports.keys.each_with_index do |key, index|
max = reports[key].column('conn/s').map{|x| x.to_i}.max.to_i
graphs[:max_request_rate].series << GraphSeries.new([index], [max], "Max Request Rate for '#{key}'")
graphs[:max_request_rate].series << GraphSeries.new([index], [reports[key].max('conn/s')], "Max Request Rate for '#{key}'")
end

graphs
Expand Down
4 changes: 4 additions & 0 deletions lib/autograph/table.rb
Expand Up @@ -10,6 +10,10 @@ def column(name)
@rows.map{|r| r[name.to_s.to_sym]}
end

def max(name)
@rows.map{|r| r[name.to_s.to_sym].to_i}.max
end

def <<(row_hash)
# Symbolize keys on the way in
@rows << row_hash.inject({}){|x,y| x[y[0].to_s.to_sym] = y[1]; x}
Expand Down
10 changes: 10 additions & 0 deletions test/test_table.rb
Expand Up @@ -43,6 +43,16 @@ def test_column_with_string_key
assert_equal t.column("column_b"), [2,222]
end

def test_max
zero = {:column_b => 1}
one = {:column_b => 2}
two = {'column_b' => 222}
t = Table.new(COLUMN_NAMES)
t << one
t << two
assert_equal t.max("column_b"), 222
end

def test_to_html_returns_string
assert_equal Table.new(COLUMN_NAMES).to_html.class, String
end
Expand Down

0 comments on commit 12ec753

Please sign in to comment.