Calculate age stats based on the participation date

We were calculating the age stats based on the age of the users who
participated... at the moment where we were calculating the stats. That
means that, if 20 years ago, 1000 people who were 16 years old
participated, they would be shown as having 36 years in the stats.

Instead, we want to show the stats at the time when the process took
place, so we're implementing a `participation_date` method.

Note that, for polls, we could actually use the `age` column in the
`poll_voters` table. However, doing so would be harder, would only work
for polls but not for budgets, and it wouldn't be statistically very
relevant, since the stats are shown by age groups, and only a small
percentage of people would change their age group (and only to the
nearest one) between the time they participate and the time the process
ends.

We might use the `poll_voters` table in the future, though, since we
have a similar issue with geozones and genders, and using the
information in `poll_voters` would solve it as well (only for polls,
though).

Also note that we're using the `ends_at` dates because some people but
be too young to vote when a process starts but old enough to vote when
the process ends.

Finally, note that we might need to change the way we calculate the
participation date for a budget, since some budgets might not enabled
every phase. Not sure how stats work in that scenario (even before these
changes).
This commit is contained in:
Javi Martín
2024-05-13 01:28:56 +02:00
parent 947953641d
commit 1d85a63e7c
8 changed files with 155 additions and 8 deletions

View File

@@ -37,6 +37,10 @@ class Budget::Stats
budget.finished?
end
def participation_date
send("#{phases.last}_phase_participation_date")
end
def total_participants
participants.distinct.count
end
@@ -98,6 +102,14 @@ class Budget::Stats
phases.map { |phase| self.class.send("#{phase}_phase_methods") }.flatten
end
def support_phase_participation_date
budget.phases.selecting.ends_at
end
def vote_phase_participation_date
budget.phases.balloting.ends_at
end
def participant_ids
phases.map { |phase| send("participant_ids_#{phase}_phase") }.flatten.uniq
end