Add and apply Performance/Sum rubocop rule
We're not adding it for performance reasons but because it simplifies the code.
This commit is contained in:
@@ -217,6 +217,9 @@ Performance/EndWith:
|
|||||||
Performance/StartWith:
|
Performance/StartWith:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
Performance/Sum:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
Rails/ActiveRecordCallbacksOrder:
|
Rails/ActiveRecordCallbacksOrder:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class Budget::Stats
|
|||||||
end
|
end
|
||||||
|
|
||||||
def total_votes
|
def total_votes
|
||||||
budget.ballots.pluck(:ballot_lines_count).reduce(0) { |sum, x| sum + x }
|
budget.ballots.pluck(:ballot_lines_count).sum
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_selected_investments
|
def total_selected_investments
|
||||||
@@ -72,18 +72,18 @@ class Budget::Stats
|
|||||||
end
|
end
|
||||||
|
|
||||||
groups[:total] = Hash.new(0)
|
groups[:total] = Hash.new(0)
|
||||||
groups[:total][:total_investments_count] = groups.map { |_k, v| v[:total_investments_count] }.sum
|
groups[:total][:total_investments_count] = groups.sum { |_k, v| v[:total_investments_count] }
|
||||||
groups[:total][:total_participants_support_phase] = groups.map { |_k, v| v[:total_participants_support_phase] }.sum
|
groups[:total][:total_participants_support_phase] = groups.sum { |_k, v| v[:total_participants_support_phase] }
|
||||||
groups[:total][:total_participants_vote_phase] = groups.map { |_k, v| v[:total_participants_vote_phase] }.sum
|
groups[:total][:total_participants_vote_phase] = groups.sum { |_k, v| v[:total_participants_vote_phase] }
|
||||||
groups[:total][:total_participants_every_phase] = groups.map { |_k, v| v[:total_participants_every_phase] }.sum
|
groups[:total][:total_participants_every_phase] = groups.sum { |_k, v| v[:total_participants_every_phase] }
|
||||||
|
|
||||||
budget.headings.each do |heading|
|
budget.headings.each do |heading|
|
||||||
groups[heading.id].merge!(calculate_heading_stats_with_totals(groups[heading.id], groups[:total], heading.population))
|
groups[heading.id].merge!(calculate_heading_stats_with_totals(groups[heading.id], groups[:total], heading.population))
|
||||||
end
|
end
|
||||||
|
|
||||||
groups[:total][:percentage_participants_support_phase] = groups.map { |_k, v| v[:percentage_participants_support_phase] }.sum
|
groups[:total][:percentage_participants_support_phase] = groups.sum { |_k, v| v[:percentage_participants_support_phase] }
|
||||||
groups[:total][:percentage_participants_vote_phase] = groups.map { |_k, v| v[:percentage_participants_vote_phase] }.sum
|
groups[:total][:percentage_participants_vote_phase] = groups.sum { |_k, v| v[:percentage_participants_vote_phase] }
|
||||||
groups[:total][:percentage_participants_every_phase] = groups.map { |_k, v| v[:percentage_participants_every_phase] }.sum
|
groups[:total][:percentage_participants_every_phase] = groups.sum { |_k, v| v[:percentage_participants_every_phase] }
|
||||||
|
|
||||||
groups
|
groups
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ class Legislation::Process < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def total_comments
|
def total_comments
|
||||||
questions.sum(:comments_count) + draft_versions.map(&:total_comments).sum
|
questions.sum(:comments_count) + draft_versions.sum(&:total_comments)
|
||||||
end
|
end
|
||||||
|
|
||||||
def status
|
def status
|
||||||
|
|||||||
@@ -18,6 +18,6 @@ module RemoteTranslations::Microsoft::SentencesParser
|
|||||||
end
|
end
|
||||||
|
|
||||||
def characters_count(texts)
|
def characters_count(texts)
|
||||||
texts.map(&:size).reduce(:+)
|
texts.sum(&:size)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -384,7 +384,7 @@ namespace :proposal_actions do
|
|||||||
5
|
5
|
||||||
]
|
]
|
||||||
|
|
||||||
votes_count = expected_supports.reduce(0.0) { |sum, x| sum + x }
|
votes_count = expected_supports.sum
|
||||||
goal_votes = Setting["votes_for_proposal_success"].to_f
|
goal_votes = Setting["votes_for_proposal_success"].to_f
|
||||||
cached_votes_up = 0
|
cached_votes_up = 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user