Revert "Extract class to manage GeozoneStats"

Back in commit 383909e16, 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 commit 383909e16.
This commit is contained in:
Javi Martín
2024-04-08 19:27:31 +02:00
parent 6eadf3cea6
commit bcc9fd97f5
4 changed files with 9 additions and 84 deletions

View File

@@ -114,19 +114,23 @@ module Statisticable
end
def participants_by_geozone
geozone_stats.to_h do |stats|
geozones.to_h do |geozone|
count = participants.where(geozone: geozone).count
[
stats.name,
geozone.name,
{
count: stats.count,
percentage: stats.percentage
count: count,
percentage: calculate_percentage(count, total_participants)
}
]
end
end
def calculate_percentage(fraction, total)
PercentageCalculator.calculate(fraction, total)
return 0.0 if total.zero?
(fraction * 100.0 / total).round(3)
end
def version
@@ -178,10 +182,6 @@ module Statisticable
Geozone.order("name")
end
def geozone_stats
geozones.map { |geozone| GeozoneStats.new(geozone, participants) }
end
def range_description(start, finish)
if finish > 200
I18n.t("stats.age_more_than", start: start)