Commit Graph

13615 Commits

Author SHA1 Message Date
Javi Martín
875cfac406 Cache poll participants
It looks like generating the poll takes sometime due to that method.
2019-05-21 13:50:18 +02:00
Javi Martín
6b0b9db969 Display only poll stats for used channels
So if there's no vote using by mail (which is the case in some places),
no stats related to voting via mail are displayed.
2019-05-21 13:50:18 +02:00
Javi Martín
4843959c7d Use poll voters valid origins as stats channels
They're the same thing, and duplicating them led into a typo saying
"mail" instead of "letter".
2019-05-21 13:50:18 +02:00
Javi Martín
793bfed372 Display only existing stats
So if we don't have information regarding gender, age or geozone, stats
regarding those topics will not be shown.

Note we're using `spec/models/statisticable_spec.rb` because having the
same file in `spec/models/concerns` caused the tests to be executed
twice.

Also note the implementation behind the `gender?`, `age?` and `geozone?`
methods is a bit primitive. We might need to make it more robust in the
future.
2019-05-21 13:50:18 +02:00
Javi Martín
76c7827cf4 Use stats objects instead of hashes
It will make it far easier to call other methods on the stats object,
and we're already caching the methods.

We had to remove the view fragment caching because the stats object
isn't as easy to cache. The good thing about it is the view will
automatically be updated when we change logic regarding which stats to
show, and the methods taking long to execute are cached in the model.
2019-05-21 13:50:18 +02:00
Javi Martín
eba30d1585 Use "Fully blank" instead of "white votes"
We were mistranslating the Spanish word "blanco", which can mean "blank"
or "white".

We've also decided to use "fully blank" because polls may have many
questions, and only votes leaving everything blank count as blank votes.
2019-05-21 13:50:18 +02:00
Javi Martín
e3063cd24f Remove complex poll stats
For now we think showing them would be showing too much data and it
would be a bit confusing.

I've been tempted to just remove the view and keep the methods in the
model in case they're used by other institutions using CONSUL. However,
it's probably better to wait until we're asked to re-implement them, and
in the meantime we don't maintain code nobody uses. The code wasn't that
great to start with (I know it because I wrote it).
2019-05-21 13:50:17 +02:00
decabeza
fdeef72189 Fix lint warnings on stats scss 2019-05-21 13:50:17 +02:00
decabeza
f6701373c4 Change i18n participation to participants 2019-05-21 13:50:17 +02:00
decabeza
844d2c41db Replace stats web icon 2019-05-21 13:50:17 +02:00
decabeza
a886b8ae59 Make stats numbers smaller
The number of total participants is still written using a larger font
because it's the most important number.
2019-05-21 13:50:17 +02:00
Javi Martín
dc077bb03c Simplify budget stats in voting phase
So we only show the total number of participants, and not divided by web
participants and booth participants.
2019-05-21 13:50:17 +02:00
Javi Martín
d42454a1a8 Include booth users in participants in vote phase
We were expecting `balloters` to include `poll_ballot_voters` (that's
why we're substracting them to calculate web participants), but reality
has proven `poll_ballot_voters` aren't included in `balloters`.
2019-05-21 13:50:17 +02:00
Javi Martín
cf32cc940b Exclude nil balloters from vote phase participants
The `user_id` can be `nil` for ballots.
2019-05-21 13:50:17 +02:00
Javi Martín
0a578f2775 Create less records in budget stats specs
Creating only the necessary data for each test makes tests easier to
read. It also makes tests slightly faster.
2019-05-21 13:50:17 +02:00
Javi Martín
20b1085dc8 Simplify budget stats data generation
Configuring associations in the factories makes it easier to generate
headings, polls and ballots in the tests.
2019-05-21 13:50:17 +02:00
Javi Martín
7362b8233a Remove unrelated text
The number refers to the total number of participants, and not the total
number of votes.
2019-05-21 13:50:17 +02:00
Javi Martín
bc056d907e Add missing translation 2019-05-21 13:50:17 +02:00
decabeza
6410d4c3e5 Replace data equalizer with css
Data equalizer was used to show a border to separate sidebar from the content. Now is the same with only css avoiding use js.
2019-05-21 13:50:17 +02:00
Javi Martín
2d7b8bc8df Use new design for advanced budget stats 2019-05-21 13:50:17 +02:00
Javi Martín
6ad3bc063c Move budget stats translations to stats files
We were using custom translations, but now this code is going to be
included in the main CONSUL repository.
2019-05-21 13:50:17 +02:00
Javi Martín
cf32dcd6d5 Use the new stats layout in budget stats
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.
2019-05-21 13:50:17 +02:00
decabeza
b2ad1e796f Replace images with transparent png 2019-05-21 13:50:17 +02:00
Javi Martín
8f69113233 Add poll stats by geozone and channel 2019-05-21 13:50:17 +02:00
Javi Martín
202fb44008 Add poll stats by age and channel 2019-05-21 13:50:17 +02:00
Javi Martín
7b408a4b88 Add poll stats by gender and channel 2019-05-21 13:50:17 +02:00
Javi Martín
553af8e95b Add poll stats by channel
Note we currently don't have a way to get the votes by mail, so that
section is always blank.
2019-05-21 13:50:17 +02:00
Javi Martín
8f0bccf5b3 Add mail votes stub to poll stats
So far we don't know about implemenation details.
2019-05-21 13:50:16 +02:00
Javi Martín
a9bb3eba26 Add headings for advanced statistics 2019-05-21 13:50:16 +02:00
Javi Martín
90fe746d27 Add geozone stats to polls 2019-05-21 13:50:16 +02:00
Javi Martín
49f4a53569 Remove duplication in web percentage stats
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.
2019-05-21 13:50:16 +02:00
Javi Martín
a552645e7f Add tests to poll stats
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.
2019-05-21 13:50:16 +02:00
decabeza
70dbbbd1b9 Add stack class to polls stats table
This class improve tables layout on mobile screen sizes.
2019-05-21 13:50:16 +02:00
decabeza
1975b6ae7c Remove sticky on polls stats links 2019-05-21 13:50:16 +02:00
Javi Martín
4d520a3a47 Rename age_groups method
The name was confusing because it seemed to return a list of age groups.
2019-05-21 13:50:16 +02:00
Javi Martín
c4c0301f3f Simplify stats images styles
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.
2019-05-21 13:50:16 +02:00
Javi Martín
4ade857a1b Extract method to render number and info
We're going to use it in many places, so removing duplication is useful.
2019-05-21 13:50:16 +02:00
Javi Martín
1c9552b922 Add number-with-info HTML class to stats
So it can be reused in advanced statistics.
2019-05-21 13:50:16 +02:00
Javi Martín
573e04ef8f Move common stats to partials 2019-05-21 13:50:16 +02:00
Javi Martín
88daaee9fe Simplify code 2019-05-21 13:50:16 +02:00
Javi Martín
7dbe1dce86 Refactor web and booth votes calculations 2019-05-21 13:50:16 +02:00
Javi Martín
0e2e5a27c3 Refactor valid, white and null votes calculations 2019-05-21 13:50:16 +02:00
Javi Martín
f7d4507ebe Keep sticky elements after AJAX requests
Turbolinks doesn't get on well with Foundation's Sticky, and so we need
to manually trigger the event on Turbolinks' `page:load`.
2019-05-21 13:50:16 +02:00
Javi Martín
b4a1f0db51 Rename file to initialize Foundation
Naming it "Dropdown" was misleading.
2019-05-21 13:50:16 +02:00
decabeza
b91b766e96 Adds styles and updates html markup to stats 2019-05-21 13:50:16 +02:00
Javi Martín
7ce57f649f Use a <meter> tag to display age percentages 2019-05-21 13:50:16 +02:00
Javi Martín
0037ce5546 Reorder poll stats method names
So related methods are on the same line.
2019-05-21 13:50:16 +02:00
Javi Martín
57a2945590 Use let for stats in budget stats spec
The rest of the `before` block still uses instance variables, but at
least the rest of the file doesn't use instance variables anymore.
2019-05-21 13:50:15 +02:00
Javi Martín
1a1ca13525 Add age stats to polls 2019-05-21 13:50:15 +02:00
Javi Martín
9a01ff5323 Refactor age groups method
We try to make the method return data which is easier to handle in the
view.
2019-05-21 13:50:15 +02:00