hard-coded partitioning on ruby side

pull/6827/head
Markus Kahl 14 years ago
parent 9ff9b16948
commit 16511e0127
  1. 28
      lib/report/result.rb

@ -40,7 +40,33 @@ class Report::Result
data = group_by do |entry|
# index for group is a hash
# i.e. { :foo => 10, :bar => 20 } <= this is just the KEY!!!!
fields.inject({}) { |hash, key| hash.merge key => entry.fields[key] }
fields.inject({}) do |hash, key|
val = entry.fields[key]
if key =~ /^number_of.*/
if val.to_i >= 10
val = "10+"
end
end
hash.merge key => val # entry.fields[key]
end
end
if data.keys.size > 0
num = data.keys[0].keys.find { |key| key =~ /^number_of.*/ }
data.keys.find_all { |key| key[num].to_i >= 10 }.each do |key|
unique_results = []
data[key].each do |result|
pkey = result.fields.except num, "count"
if (tuple = unique_results.find { |t| t[0] == pkey })
ures = tuple[1]
ures.fields["count"] = (ures.fields["count"].to_i + result.fields["count"].to_i).to_s
else
ures = result
ures.fields[num] = "10+"
unique_results << [pkey, ures]
end
end
data[key] = unique_results.collect { |tuple| tuple[1] }
end
end
# map group back to array, all fields with same key get grouped into one list
data.keys.map { |f| engine::Result.new data[f], f, type, important_fields }

Loading…
Cancel
Save