Even if this class looks very simple now, we're trying a few things related to these stats. Having a class for it makes future changes easier and, if there weren't any future changes, at least it makes current experiments easier. Note we keep the method `participants_by_geozone` to return a hash because we're caching the stats and storing GeozoneStats objects would need a lot more memory and we would get an error.
25 lines
410 B
Ruby
25 lines
410 B
Ruby
class GeozoneStats
|
|
attr_reader :geozone, :participants
|
|
|
|
def initialize(geozone, participants)
|
|
@geozone = geozone
|
|
@participants = participants
|
|
end
|
|
|
|
def geozone_participants
|
|
participants.where(geozone: geozone)
|
|
end
|
|
|
|
def name
|
|
geozone.name
|
|
end
|
|
|
|
def count
|
|
geozone_participants.count
|
|
end
|
|
|
|
def percentage
|
|
PercentageCalculator.calculate(count, participants.count)
|
|
end
|
|
end
|