Revert "Extract class to manage GeozoneStats"
Back in commit383909e16, we said: > 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. Since there haven't been any changes in the last 5 years and we've found cases where using the GeozoneStats class results in a slightly worse performance, we're removing this class. The code is now a bit easier to read, and is consistent with the way we calculate participants by age. This reverts commit383909e16.
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
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
|
||||
@@ -1,7 +0,0 @@
|
||||
module PercentageCalculator
|
||||
def self.calculate(fraction, total)
|
||||
return 0.0 if total.zero?
|
||||
|
||||
(fraction * 100.0 / total).round(3)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user