Skip to content

Commit

Permalink
[DEMAD-421] Cambios
Browse files Browse the repository at this point in the history
  • Loading branch information
vanessasotob committed Jul 11, 2022
1 parent 3392045 commit 1018216
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions app/models/budget/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 1018216

Please sign in to comment.