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

Improve stats interface #1932

Closed
wants to merge 43 commits into from
Closed

Improve stats interface #1932

wants to merge 43 commits into from

Conversation

javierm
Copy link

@javierm javierm commented Mar 18, 2019

References

Objectives

  • Add a missing translationg
  • Show city heading first in budget stats
  • Simplify stats for voting phases

Visual Changes

Before these changes:

There are unneeded stats related to budget phases

After these changes:

Only two stats appear related to budget phases

Does this PR need a Backport to CONSUL?

Yes, backport when backporting everything related to stats.

javierm and others added 30 commits March 18, 2019 13:24
We would now like to differenciate between 70-year-old people and
90-year-old people.
This way we can easily see the h3 tag's parent is the h2 tag.
We try to make the method return data which is easier to handle in the
view.
The rest of the `before` block still uses instance variables, but at
least the rest of the file doesn't use instance variables anymore.
So related methods are on the same line.
Naming it "Dropdown" was misleading.
Turbolinks doesn't get on well with Foundation's Sticky, and so we need
to manually trigger the event on Turbolinks' `page:load`.
So it can be reused in advanced statistics.
We're going to use it in many places, so removing duplication is useful.
This way we don't need to manually define the width we think the image
we insert in the `::before` pseudoclass is going to take.
The name was confusing because it seemed to return a list of age groups.
This class improve tables layout on mobile screen sizes.
It was still using "web" as origin.
The factories were creating strange database relations:

* The voter belonged to a poll, to a booth and to an officer
* The booth belonged to a different poll
* The officer belonged to a different booth

The code uses an unusual syntax because the following code:

association :booth_assignment,
            factory: :poll_booth_assignment,
            poll: poll

Would generate the following error:

ActiveRecord::AssociationTypeMismatch: Poll(#46976420451940) expected,
got FactoryBot::Declaration::Implicit
Adding the option to assign a poll to a poll recount factory meant we
didn't need to create so much data.

Also note we're removing the `create(:poll_voter, origin: "booth")`
code, since it isn't used in the stats calculations.
While we already had "one test to rule all stats", testing each method
individually makes reading, adding and changing tests easier.

Note we need to make all methods being tested public. We could also test
them using methods like `stats.generate[:total_valid_votes]` instead of
`stats.total_valid_votes`, but then the tests would be more difficult to
read.
We didn't use metaprogramming from the start because the
`null_percentage_web` method had a particular behaviour.

However, the behaviour (due to a typo) didn't really matter because
there are no null web votes, and so the `null_percentage_web` is always
zero.
javierm and others added 13 commits March 18, 2019 13:27
So far we don't know about implemenation details.
Note we currently don't have a way to get the votes by mail, so that
section is always blank.
It was only defined in the custom routes file.
So now stats by gender and age are replaced by shared participation
stats (which also includes stats by district), reusing the code already
used in poll stats, and advanced statistics (which used to be at the top
of the page) are now displayed after partipation stats.
We were using custom translations, but now this code is going to be
included in the main CONSUL repository.
Data equalizer was used to show a border to separate sidebar from the content. Now is the same with only css avoiding use js.
end

end

context "#headings" do

it "returns headings data" do
heading_stats = @stats[:headings][@heading.id]
heading_stats = stats[:headings][@heading.id]

Choose a reason for hiding this comment

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

RSpec/InstanceVariable: Use let instead of an instance variable. (http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/InstanceVariable)

end

let(:stats) { Budget::Stats.new(@budget).generate }

Choose a reason for hiding this comment

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

RSpec/InstanceVariable: Use let instead of an instance variable. (http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/InstanceVariable)

end
second_total = Poll::Answer.where(answer: "En blanco", question: poll.questions.second).pluck(:author_id).count
second_total -= (Poll::Answer.where(answer: poll.questions.first.question_answers.where(given_order: 1).first.title, question: poll.questions.first).pluck(:author_id) & Poll::Answer.where(answer: "En blanco", question: poll.questions.second).pluck(:author_id)).uniq.count
second_total -= (Poll::Answer.where(answer: poll.questions.first.question_answers.where(given_order: 2).first.title, question: poll.questions.first).pluck(:author_id) & Poll::Answer.where(answer: "En blanco", question: poll.questions.second).pluck(:author_id)).uniq.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. [275/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)

calculate_percentage(total_web_null, total_web_valid)
end
second_total = Poll::Answer.where(answer: "En blanco", question: poll.questions.second).pluck(:author_id).count
second_total -= (Poll::Answer.where(answer: poll.questions.first.question_answers.where(given_order: 1).first.title, question: poll.questions.first).pluck(:author_id) & Poll::Answer.where(answer: "En blanco", question: poll.questions.second).pluck(:author_id)).uniq.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. [275/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)

def null_percentage_web
calculate_percentage(total_web_null, total_web_valid)
end
second_total = Poll::Answer.where(answer: "En blanco", question: poll.questions.second).pluck(:author_id).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. [116/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)

}

&.mail::before {
content: image-url('stats_mail.png');

Choose a reason for hiding this comment

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

Prefer double-quoted strings

}

&.booth::before {
content: image-url('stats_booth.png');

Choose a reason for hiding this comment

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

Prefer double-quoted strings

}

&.web::before {
content: image-url('stats_web.png');

Choose a reason for hiding this comment

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

Prefer double-quoted strings

}

&.mail::before {
content: image-url('stats_mail.png');

Choose a reason for hiding this comment

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

Prefer double-quoted strings

}

&.booth::before {
content: image-url('stats_booth.png');

Choose a reason for hiding this comment

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

Prefer double-quoted strings

@javierm
Copy link
Author

javierm commented Mar 18, 2019

I changed the compare branch instead of the base branch while opening this pull request 😅. Wrong branch!

@javierm javierm closed this Mar 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants