Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify stats caching #3510

Merged
merged 4 commits into from
May 21, 2019
Merged

Simplify stats caching #3510

merged 4 commits into from
May 21, 2019

Conversation

javierm
Copy link
Member

@javierm javierm commented May 20, 2019

References

Objectives

  • Simplify the code in Poll::Stats and Budget::Stats so it's easier to read
  • Introduce a common concern to handle stats

@javierm javierm self-assigned this May 20, 2019
total_participants_booth total_booth_valid total_booth_white total_booth_null
total_valid_votes total_white_votes total_null_votes valid_percentage_web valid_percentage_booth
total_valid_percentage white_percentage_web white_percentage_booth total_white_percentage
null_percentage_web null_percentage_booth total_null_percentage total_participants_web_percentage

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [104/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)

def self.stats_methods
%i[total_participants total_participants_web total_web_valid total_web_white total_web_null
total_participants_booth total_booth_valid total_booth_white total_booth_null
total_valid_votes total_white_votes total_null_votes valid_percentage_web valid_percentage_booth

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [103/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)

end
end
def supports(supportable)
ActsAsVotable::Vote.where(votable_type: "Budget::Investment", votable_id: supportable.investments.pluck(:id))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [115/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)

percentage_participants_vote_phase: participants_percent(heading_totals, groups_totals, :total_participants_vote_phase),
percentage_district_population_vote_phase: population_percent(population, heading_totals[:total_participants_vote_phase]),
percentage_participants_all_phase: participants_percent(heading_totals, groups_totals, :total_participants_all_phase),
percentage_district_population_all_phase: population_percent(population, heading_totals[:total_participants_all_phase])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [127/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)

percentage_district_population_support_phase: population_percent(population, heading_totals[:total_participants_support_phase]),
percentage_participants_vote_phase: participants_percent(heading_totals, groups_totals, :total_participants_vote_phase),
percentage_district_population_vote_phase: population_percent(population, heading_totals[:total_participants_vote_phase]),
percentage_participants_all_phase: participants_percent(heading_totals, groups_totals, :total_participants_all_phase),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [126/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)

groups
end
end
groups[:total][:percentage_participants_support_phase] = groups.collect {|_k, v| v[:percentage_participants_support_phase]}.sum

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [133/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)

supports(heading).pluck(:voter_id)
end
budget.headings.each do |heading|
groups[heading.id].merge!(calculate_heading_stats_with_totals(groups[heading.id], groups[:total], heading.population))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [126/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)

groups[:total][:total_investments_count] = groups.collect {|_k, v| v[:total_investments_count]}.sum
groups[:total][:total_participants_support_phase] = groups.collect {|_k, v| v[:total_participants_support_phase]}.sum
groups[:total][:total_participants_vote_phase] = groups.collect {|_k, v| v[:total_participants_vote_phase]}.sum
groups[:total][:total_participants_all_phase] = groups.collect {|_k, v| v[:total_participants_all_phase]}.sum

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [115/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)

groups[:total] = Hash.new(0)
groups[:total][:total_investments_count] = groups.collect {|_k, v| v[:total_investments_count]}.sum
groups[:total][:total_participants_support_phase] = groups.collect {|_k, v| v[:total_participants_support_phase]}.sum
groups[:total][:total_participants_vote_phase] = groups.collect {|_k, v| v[:total_participants_vote_phase]}.sum

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [117/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)

end
groups[:total] = Hash.new(0)
groups[:total][:total_investments_count] = groups.collect {|_k, v| v[:total_investments_count]}.sum
groups[:total][:total_participants_support_phase] = groups.collect {|_k, v| v[:total_participants_support_phase]}.sum

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [123/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)

end
end
groups[:total] = Hash.new(0)
groups[:total][:total_investments_count] = groups.collect {|_k, v| v[:total_investments_count]}.sum

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [105/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)

stats_cache("balloters") { @budget.ballots.where("ballot_lines_count > ?", 0).pluck(:user_id) }
def balloters_by_heading(heading_id)
stats_cache("balloters_by_heading_#{heading_id}") do
budget.ballots.joins(:lines).where(budget_ballot_lines: {heading_id: heading_id}).pluck(:user_id)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [105/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)

@javierm javierm changed the base branch from backport-blank_votes to master May 20, 2019 12:54
@javierm javierm changed the base branch from master to backport-blank_votes May 20, 2019 12:54
@javierm javierm force-pushed the backport-refactor_stats_module branch from a942e78 to 1882782 Compare May 21, 2019 11:49
@javierm javierm changed the base branch from backport-blank_votes to master May 21, 2019 12:23
@javierm javierm merged commit 07d5511 into master May 21, 2019
@javierm javierm deleted the backport-refactor_stats_module branch May 21, 2019 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants