From 101821658fa6f2775b4bb766a6fec000be27ca73 Mon Sep 17 00:00:00 2001 From: VanessaSoto Date: Mon, 11 Jul 2022 14:21:32 +0200 Subject: [PATCH] [DEMAD-421] Cambios --- app/models/budget/stats.rb | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/app/models/budget/stats.rb b/app/models/budget/stats.rb index f9bb3780fd2..f25405984a1 100644 --- a/app/models/budget/stats.rb +++ b/app/models/budget/stats.rb @@ -19,7 +19,7 @@ def self.every_phase_methods end def stats_methods - base_stats_methods + participation_methods + phase_methods + super + base_stats_methods + participation_methods + phase_methods end def phases @@ -61,7 +61,7 @@ def total_participants_accepting_gender def total_participants_support_phase - User.where("users.id in (?)",voters).pluck(:id).uniq.count + voters.count end def total_participants_support_gender @@ -72,7 +72,7 @@ def total_participants_support_gender end def total_participants_vote_phase - participant_ids_vote_phase.uniq.count + (balloters + poll_ballot_voters).uniq.count end def total_participants_vote_gender @@ -83,7 +83,7 @@ def total_participants_vote_gender end def total_participants_every_phase - User.where("users.id in (?)", (voters + authors + balloters + poll_ballot_voters)).pluck(:id).count + (voters + authors + balloters + poll_ballot_voters).uniq.count end def total_budget_investments @@ -154,19 +154,17 @@ def participant_ids end def participant_ids_accepting_phase - User.where("users.id in (?)",authors).pluck(:id).uniq + authors.uniq end def participant_ids_support_phase - User.where("users.id in (?)",(voters)).pluck(:id).uniq + voters.uniq end def participant_ids_vote_phase - User.where("users.id in (?)",(balloters + poll_ballot_voters)).pluck(:id).uniq + (balloters + poll_ballot_voters).uniq end - - def voters @voters ||= supports(budget).distinct.pluck(:voter_id) end @@ -180,24 +178,24 @@ def poll_ballot_voters end def balloters_by_heading(heading_id) - User.where("users.id in (?)",budget.ballots.joins(:lines) + budget.ballots.joins(:lines) .where(budget_ballot_lines: { heading_id: heading_id} ) - .distinct.pluck(:user_id)).pluck(:id) + .distinct.pluck(:user_id) end def voters_by_heading(heading) - User.where("users.id in (?)",supports(heading).distinct.pluck(:voter_id)).pluck(:id) + supports(heading).distinct.pluck(:voter_id) end def accepting_by_heading(heading) - User.where("users.id in (?)", heading.investments.distinct.pluck(:author_id)) + heading.investments.distinct.pluck(:author_id) end def poll_voters_by_heading(heading) if !budget.poll.blank? - User.where("users.id in (?)",budget.poll.voters.where(votable: heading.investments) - .distinct.pluck(:user_id)).pluck(:id) + budget.poll.voters.where(votable: heading.investments) + .distinct.pluck(:user_id) else [] end @@ -209,10 +207,10 @@ def calculate_heading_totals(heading) total_investments_male_count: User.where("id in (?) and upper(gender) = 'MALE'", heading.investments.pluck(:author_id)).distinct.pluck(:id).count, total_investments_female_count: User.where("id in (?) and upper(gender) = 'FEMALE'", heading.investments.pluck(:author_id)).distinct.pluck(:id).count, total_investments_other_count: User.where("id in (?) and (gender is null or gender = '')", heading.investments.pluck(:author_id)).distinct.pluck(:id).count, - total_participants_accepting_phase: accepting_by_heading(heading).distinct.pluck(:id).count, - total_participants_accepting_male: accepting_by_heading(heading).where("upper(gender) = 'MALE'").distinct.pluck(:id).count, - total_participants_accepting_female: accepting_by_heading(heading).where("upper(gender) = 'FEMALE'").distinct.pluck(:id).count, - total_participants_accepting_other: accepting_by_heading(heading).where("(gender is null or gender = '')").distinct.pluck(:id).count, + total_participants_accepting_phase: accepting_by_heading(heading).count, + total_participants_accepting_male: User.where("id in (?) and upper(gender) = 'MALE'", accepting_by_heading(heading)).distinct.pluck(:id).count, + total_participants_accepting_female: User.where("id in (?) and upper(gender) = 'FEMALE'", accepting_by_heading(heading)).distinct.pluck(:id).count, + total_participants_accepting_other: User.where("id in (?) and (gender is null or gender = '')",accepting_by_heading(heading) ).distinct.pluck(:id).count, total_participants_support_phase: voters_by_heading(heading).count, total_participants_support_male: User.where("id in (?) and upper(gender) = 'MALE'", voters_by_heading(heading)).distinct.pluck(:id).count, total_participants_support_female: User.where("id in (?) and upper(gender) = 'FEMALE'", voters_by_heading(heading)).distinct.pluck(:id).count,