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

Add budget stats #3438

Merged
merged 42 commits into from
May 16, 2019
Merged

Add budget stats #3438

merged 42 commits into from
May 16, 2019

Conversation

javierm
Copy link
Member

@javierm javierm commented Apr 15, 2019

app/views/budgets/stats/show.html.erb Outdated Show resolved Hide resolved
app/views/budgets/stats/show.html.erb Outdated Show resolved Hide resolved
app/models/budget/stats.rb Outdated Show resolved Hide resolved
app/models/budget/stats.rb Outdated Show resolved Hide resolved
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. [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

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

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))

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

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

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)

spec/models/budget/stats_spec.rb Outdated Show resolved Hide resolved
spec/models/budget/stats_spec.rb Outdated Show resolved Hide resolved
spec/models/budget/stats_spec.rb Outdated Show resolved Hide resolved
spec/models/budget/stats_spec.rb Outdated Show resolved Hide resolved
spec/models/budget/stats_spec.rb Outdated Show resolved Hide resolved
spec/features/budgets/stats_spec.rb Outdated Show resolved Hide resolved
spec/features/budgets/stats_spec.rb Outdated Show resolved Hide resolved
spec/features/budgets/stats_spec.rb Outdated Show resolved Hide resolved
spec/features/budgets/stats_spec.rb Outdated Show resolved Hide resolved

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. [127/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)

@javierm javierm force-pushed the backport-stats branch 4 times, most recently from 047f57b to 0c802f9 Compare April 15, 2019 21:09
app/views/budgets/results/show.html.erb Outdated Show resolved Hide resolved
spec/models/abilities/common_spec.rb Outdated Show resolved Hide resolved
spec/models/abilities/common_spec.rb Outdated Show resolved Hide resolved
spec/models/abilities/common_spec.rb Outdated Show resolved Hide resolved
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. [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 }

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) }

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 }

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 }

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 } }

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)

@javierm javierm force-pushed the backport-stats branch 12 times, most recently from 6909b72 to b6400f3 Compare April 15, 2019 23:01
@javierm javierm changed the title [WIP] Budget stats Budget stats Apr 16, 2019
@javierm javierm force-pushed the backport-stats branch 2 times, most recently from 917935a to f0ff973 Compare April 16, 2019 11:53
Copy link
Member

@voodoorai2000 voodoorai2000 left a comment

Choose a reason for hiding this comment

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

🙌

bertocq and others added 22 commits May 16, 2019 22:01
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
@javierm javierm changed the title Budget stats Add budget stats May 16, 2019
@javierm javierm merged commit 525eb90 into master May 16, 2019
@javierm javierm deleted the backport-stats branch May 16, 2019 20:46
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

9 participants