Commit Graph

2081 Commits

Author SHA1 Message Date
Javi Martín
a13a8a2270 Simplify code to calculate supports
The code is easier to read now, it returns the same results it used to
return, and performance-wise it's probably the same thing, but if it's
not, we'll trust Rails will do optimizations that we don't when we
manually pluck the IDs.
2019-05-21 13:50:18 +02:00
Javi Martín
7a79c36137 Select only distinct voters/balloters in stats
It is way more efficient because we're caching the result of that
method, and this way we only store each voter once in the cache. We were
storing many voters several times and then we were filtering them with
`uniq`.
2019-05-21 13:50:18 +02:00
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
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
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
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
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
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
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
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
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
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
Javi Martín
be68c8cdbf Add gender stats to polls 2019-05-21 13:50:15 +02:00
Javi Martín
c1b76a7ebf Simplify age groups method 2019-05-21 13:50:15 +02:00
Javi Martín
c2489e3209 Increase number of age groups
We would now like to differenciate between 70-year-old people and
90-year-old people.
2019-05-21 13:50:15 +02:00
Javi Martín
e4a032ee68 Split common and specific stats methods 2019-05-21 13:49:42 +02:00
Javi Martín
5d2f5d1d81 Move gender and age methods to a common concern
These are generic methods which only depend on the participants.
2019-05-21 13:49:42 +02:00
Javi Martín
04c920c27d Simplify calculate percentage method 2019-05-21 13:49:42 +02:00
Javi Martín
ccaa2e1a77 Remove duplication to calculate percentage 2019-05-21 13:49:42 +02:00
Javi Martín
188278296c Simplify the way we cache stats 2019-05-21 13:48:54 +02:00
Javier Martín
cbfa2c1df8 Merge pull request #3504 from consul/backport-poll_slugs
Add slug to polls
2019-05-21 13:42:47 +02:00
Javi Martín
d627215af4 Use symbols for method names 2019-05-21 13:27:03 +02:00
Javi Martín
313ffb589b Share method to generate stats 2019-05-21 13:27:03 +02:00
Javi Martín
62a97f9003 Add a common concern for budget and poll stats 2019-05-21 13:27:03 +02:00
Bertocq
b8dbdaf9a7 Move question most voted answer from boolean to a enumerable max by total_votes 2019-05-21 13:26:44 +02:00
Bertocq
84eac6ff68 Correct booth valid and total participants calculations 2019-05-21 13:26:44 +02:00
Bertocq
b2b5ab1d48 Calculate white votes percentage of the total 2019-05-21 13:26:44 +02:00
Bertocq
4be44835a8 Add calculate_percentaje helper function to stats helper 2019-05-21 13:26:44 +02:00
Bertocq
f4260788eb Add Partial Results counts to question answers 2019-05-21 13:26:44 +02:00
Bertocq
118cce2f8f Add letter origin back to poll voters 2019-05-21 13:26:44 +02:00
decabeza
43dd3d2169 Include mailer header logo on custom images list 2019-05-21 11:22:04 +02:00
Alberto
d845c6e973 Merge pull request #3476 from consul/delete-poll
Allow delete polls with associated questions and answers
2019-05-17 17:38:20 +02:00
Alberto
7c79965547 Merge pull request #3397 from consul/proposals-form
Remove question and external_url fields from proposals and legislation proposals
2019-05-17 17:08:56 +02:00
María Checa
0c6e7e7580 Adds Sluggable concern to Poll model 2019-05-17 05:41:09 +02:00
María Checa
fac99cfb10 Add web and booth participants in budget stats 2019-05-16 22:01:42 +02:00
María Checa
c2457e36a5 Add budget stats permissions for normal users and admins 2019-05-16 22:01:42 +02:00
María Checa
3291b3274a Added physical votes to stats 2019-05-16 22:01:42 +02:00