Module: Statistic
- Defined in:
- lib/statistic/statistic.rb
Overview
module to generate the required statisitc result for the requested attribute
Class Method Summary collapse
-
.generate_ranking_for(data, rank, criteria) ⇒ Hash
method to generate a top n ranking for the given criteria.
-
.generate_ranking_for_index(index, number_of_results) ⇒ Hash
method to generate a top n ranking over the calculated index.
Class Method Details
.generate_ranking_for(data, rank, criteria) ⇒ Hash
method to generate a top n ranking for the given criteria
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/statistic/statistic.rb', line 12 def self.generate_ranking_for(data, rank, criteria) mapping = Hash.new() data.each { |entry| attribute = Entry::EntryAttributeFactory.get_attribute_to(criteria, entry) if (mapping[attribute] == nil) mapping[attribute] = 1 else mapping[attribute] += 1 end } ranking = mapping.sort_by {|k, v| [v, k] }.reverse return ranking.first(rank) end |
.generate_ranking_for_index(index, number_of_results) ⇒ Hash
method to generate a top n ranking over the calculated index
32 33 34 35 36 37 38 39 40 |
# File 'lib/statistic/statistic.rb', line 32 def self.generate_ranking_for_index(index, number_of_results) mapping = Hash.new() index.each_pair { |key, value| mapping[key] = value.length } ranking = mapping.sort_by {|k, v| [v, k] }.reverse return ranking.first(number_of_results) end |