-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add budget stats #3438
Add budget stats #3438
Conversation
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]) |
There was a problem hiding this comment.
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. [129/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
end | ||
|
||
groups[:total][:percentage_participants_support_phase] = groups.collect {|_k, v| v[:percentage_participants_support_phase]}.sum | ||
groups[:total][:percentage_participants_vote_phase] = groups.collect {|_k, v| v[:percentage_participants_vote_phase]}.sum |
There was a problem hiding this comment.
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. [131/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
groups[heading.id].merge!(calculate_heading_stats_with_totals(groups[heading.id], groups[:total], heading.population)) | ||
end | ||
|
||
groups[:total][:percentage_participants_support_phase] = groups.collect {|_k, v| v[:percentage_participants_support_phase]}.sum |
There was a problem hiding this comment.
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. [137/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
groups[:total][:total_participants_all_phase] = groups.collect {|_k, v| v[:total_participants_all_phase]}.sum | ||
|
||
@budget.headings.each do |heading| | ||
groups[heading.id].merge!(calculate_heading_stats_with_totals(groups[heading.id], groups[:total], heading.population)) |
There was a problem hiding this comment.
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. [130/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
groups[:total] = Hash.new(0) | ||
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 |
There was a problem hiding this comment.
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. [119/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
|
||
groups[:total] = Hash.new(0) | ||
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 |
There was a problem hiding this comment.
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. [121/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 |
There was a problem hiding this comment.
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)
047f57b
to
0c802f9
Compare
end | ||
|
||
def supports(supportable) | ||
ActsAsVotable::Vote.where(votable_type: "Budget::Investment", votable_id: supportable.investments.pluck(:id)) |
There was a problem hiding this comment.
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 | ||
|
||
def total_participants_with_gender | ||
stats_cache("total_participants_with_gender") { participants.where.not(gender: nil).distinct.count } |
There was a problem hiding this comment.
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. [108/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
end | ||
|
||
def balloters | ||
stats_cache("balloters") { @budget.ballots.where("ballot_lines_count > ?", 0).pluck(:user_id) } |
There was a problem hiding this comment.
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 | ||
|
||
def female_percentage | ||
stats_cache("female_percentage") { total_female_participants / total_participants_with_gender.to_f * 100 } |
There was a problem hiding this comment.
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. [114/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
end | ||
|
||
def male_percentage | ||
stats_cache("male_percentage") { total_male_participants / total_participants_with_gender.to_f * 100 } |
There was a problem hiding this comment.
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. [110/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
end | ||
|
||
def total_votes | ||
stats_cache("total_votes") { @budget.ballots.pluck(:ballot_lines_count).inject(0) { |sum, x| sum + x } } |
There was a problem hiding this comment.
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. [112/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
6909b72
to
b6400f3
Compare
917935a
to
f0ff973
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌
This spec was leaving the DB "dirty" because it was creating records in a before(:all) hook. These records are not cleaned up automatically when using the :transaction strategy for DatabaseCleaner. Using before(:each), however, causes another problem. Some of the code depends on the heading id being 1 (see app/models/budget/ballot/line.rb#L48). Because of SQL auto-increment, this is only the case the first time the hook is run, as different id's are assigned on subsequent runs. This is fixed by forcing the id to always be 1.
This tab will show all winner investments projects with milestones
'Results' and 'Execution' tabs are now shown to the user regardless of the budget's current status
Note that we are relying on the existing `sort_by_name`[1] method in the `Budget::Heading` class. This method sorts by DESC group name first and then ASC heading name. [1] AyuntamientoMadrid#1875
References
Objectives
Add stats to budgets
Visual Changes