Commit Graph

13615 Commits

Author SHA1 Message Date
decabeza
6734054330 Prevent map overlaps the support button 2019-05-22 12:41:54 +02:00
decabeza
4b3172912e Add spec to show sticky button on mobile screens
Also remove some unnecessary css lines that were causing some unrelated specs to fail.
2019-05-22 12:41:52 +02:00
decabeza
13dfaedf06 Replace load to init sticky 2019-05-22 12:41:49 +02:00
Julian Herrero
2c45f178cb Reset sticky component before clicking back button on browser 2019-05-22 12:41:44 +02:00
Julian Herrero
eca4d773a0 Reset sticky component before leaving the page using Turbolinks 2019-05-22 12:41:38 +02:00
Julian Herrero
0237565ece Set correct attributes for data-sticky component 2019-05-22 12:41:25 +02:00
decabeza
8684835857 Adds sticky on proposals supports for mobile version 2019-05-22 12:40:12 +02:00
Javi Martín
45a3d8daf0 Add option to enable advanced stats 2019-05-22 11:50:03 +02:00
Javi Martín
a34b97e843 Extract partials to show advanced stats 2019-05-22 11:50:03 +02:00
Javi Martín
4f4dc2c2af Add show results and stats form to budgets 2019-05-22 11:50:03 +02:00
Javi Martín
e3d6dbacab Simplify finished budget factory creation 2019-05-22 11:50:03 +02:00
Javi Martín
c00203f7f5 Move budget stats permission tests to the model
They're easier to test and to read in the model.
2019-05-22 11:50:03 +02:00
Javi Martín
eb13994999 Extract partial for form to show results and stats 2019-05-22 11:50:03 +02:00
Javi Martín
1c2e38ea00 Use metaprogramming for report methods
We're going to add an `advanced_stats` report, and having 3 identical
sets of methods would be too much duplication.
2019-05-22 11:50:03 +02:00
Javi Martín
354b183e17 Create reports
This table will store which reports (stats, results, ...) will be shown
for a certain process (polls, budgets, ...).

Note Rails fails to save a poll and its report when both are new records
if we add a `validate :process, presence: true` rule. Since it caused a
lot of trouble when creating records for tests during factories rule
completely. Instead, I've created the `results_enabled=` and
`stats_enabled=` methods, so tests are easier to set up, while also
automatically creating a report if it doesn't already exist. This also
decouples form structure and database implemenation.

Originally I named this table `enabled_reports` and instead of having
`stats` and `results` columns, it had an `enabled` column and a `kind`
column, which would be set to "stats" or "results". However, although
that table would allow us to add arbitrary reports easily, I found the
way we had to handle the `has_many` relationship was a bit too complex.
2019-05-22 11:50:03 +02:00
Javi Martín
2d29243a9e Simplify code to link to a poll with one question 2019-05-22 11:49:35 +02:00
Alberto
ac1d8195f2 Merge pull request #3488 from consul/basic-yml
Admin basic customization texts
2019-05-21 21:43:07 +02:00
Javi Martín
5ca528d2ce Extract method to link to a poll 2019-05-21 17:30:46 +02:00
Javier Martín
82e3c41aa9 Merge pull request #3512 from consul/backport-stats
Change stats layout
2019-05-21 17:18:47 +02:00
Javier Martín
f4891819db Merge pull request #3511 from consul/backport-gender_participants
Refactor gender and age stats methods
2019-05-21 17:17:53 +02:00
Javier Martín
07d55116ef Merge pull request #3510 from consul/backport-refactor_stats_module
Simplify stats caching
2019-05-21 17:16:37 +02:00
Raimond Garcia
7846a4f8bd Merge pull request #3516 from consul/deploy_secrets
Add deploy-secrets.yml.example file
2019-05-21 14:33:17 +02:00
Javier Martín
d57025696f Merge pull request #3503 from consul/backport-blank_votes
Improve poll stats
2019-05-21 14:23:13 +02:00
decabeza
a2cb7501f7 Create new basic tab for admin information texts 2019-05-21 14:06:58 +02:00
Javi Martín
1135441cbd Simplify getting I18nContent translations
This code might be slightly slower because it performs one query per
field in the form, but I didn't notice any differences on my development
machine, and the code is now much easier to understand.
2019-05-21 13:53:39 +02:00
Javi Martín
dc8c4a998f Fix budget stats social meta tags
We had forgotten to update these tags for stats after updating them for
budget results in commit 153b46b4 and commit a6baaa93.
2019-05-21 13:50:19 +02:00
Javi Martín
42a25ded3f Fix booth recounts poll stats discrepancies
Due to technical issues, sometimes users voted in booths and their vote
couldn't be added to the database. So we're including them in the users
with no demographic data.
2019-05-21 13:50:19 +02:00
Javi Martín
483ebffb47 Fix statisticable concern definition
Methods defined inside "included" cannot be called using `super` from
a class including the module.
2019-05-21 13:50:19 +02:00
Javi Martín
e2a3398ec0 Increase poll stats performance
Using SQL's `select` instead of converting the records to a ruby array
increases performance dramatically when there are thousands of records.
For a poll with 200000 voters, calculating stats took more than 7
minutes, and now it takes less than 2 minutes.
2019-05-21 13:50:19 +02:00
Javi Martín
13dd77dd1b Add tasks to generate and expire stats cache
We're generating stats every 2 hours because it's less than the time it
will take to generate stats for every process. Once stats are generated,
this task should take less than a second.

The regenerate task has been added so we can manually execute it.
2019-05-21 13:50:19 +02:00
Javi Martín
aa0e813970 Use ruby cache for stats helper methods
These methods are only used while stats are being generated; once stats
are generated, they aren't used anymore. So there's no need to store
them using the Dalli cache.

Furthermore, there are polls (and even budgets) with hundreds of
thousands of participants. Calculating stats for them takes a very long
time because we can't store all those records in the Dalli cache.

However, since these records aren't used once the stats are generated,
we can store them in an instance variable while we generate the stats,
speeding up the process.
2019-05-21 13:50:19 +02:00
Javi Martín
7c0e499eee Add table to store stats versions
We need a way to manually expire the cache for a budget or poll without
expiring the cache of every budget or poll.

Using the `updated_at` column would be dangerous because most of the
times we update a budget or a poll, we don't need to regenerate their
stats.

We've considered adding a `stats_updated_at` column to each of these
tables. However, in that case we would also need to add a similar column
in the future to every process type whose stats we want to generate.
2019-05-21 13:50:19 +02:00
Javi Martín
9335c51cfc Include hidden users in stats
If users participated and were hidden after participating, we should
still count them in the participants stats.

In the tests, we set users' `hidden_at` attribute before they vote.
Although in real life they would vote first and then they would be
hidden, I've written the tests like this for the sake of simplicity.
2019-05-21 13:50:19 +02:00
Javi Martín
1f4707facd Extract method to get stats participant_ids
This way we can share the `participants` method between budget and poll
stats.
2019-05-21 13:50:19 +02:00
Javi Martín
944bd2d418 Don't capitalize common nouns 2019-05-21 13:50:19 +02:00
Javi Martín
04a5e38874 Expire budget stats cache when a phase is finished
This way we recalculate all data including the participants in the phase
which has just finished.
2019-05-21 13:50:19 +02:00
Javi Martín
66ecb2835b Show only available budget stats phases
This way we can show statistics for the supports phase before the vote
phase is over.
2019-05-21 13:50:18 +02:00
Javi Martín
bf2292ba18 Rename budget stats "all phase" to "every phase"
"All phase" doesn't sound right in English, and we're going to refactor
the code related to the phases.
2019-05-21 13:50:18 +02:00
Javi Martín
ba67bb2f98 Move survey district styles to stats stylesheet
So these styles are available in CONSUL.

Note we're not including these styles inside `.participation-stats`
because this class is used in Plaza de España's statistics.
2019-05-21 13:50:18 +02:00
Javi Martín
8bb0fa4726 Add Budget#valuating_or_later? method
We're going to use it so we know if a budget has finished its support
phase.
2019-05-21 13:50:18 +02:00
Javi Martín
1f225c59ed Use PHASE_KINDS to calculate "or_later?" methods
This implementation is a bit more robust because we don't have to change
any of the "or_later?" methods if we add or remove a new phase.

We could also use metaprogramming to reduce code duplication in these
methods. So far, I've decided to keep the code simple since the
duplication seems reasonable.
2019-05-21 13:50:18 +02:00
Javi Martín
c8146e13db Indent private methods following our syntax rules 2019-05-21 13:50:18 +02:00
Javi Martín
005a708adc Don't use find_by in scopes
As the Rails guides say:

> All scope methods will return an ActiveRecord::Relation object

That means `find_by_kind` will return a relation when nothing is found;
the expected behaviour is to return `nil`, like all `find_by` methods
do.

Using scopes also means strange things happen when we try to chain
scopes like `phases.published.drafting`. With scopes, the `drafting`
part would be ignored and all published phases would be returned.
2019-05-21 13:50:18 +02:00
Javi Martín
2215971a6b Remove unused code 2019-05-21 13:50:18 +02:00
Javi Martín
e146fafb60 Only show "no demographic data" when necessary
If there's demographic data for all participants, it doesn't make sense
to show the message.

We're using translations instead of an `if` in the view because the text
is also different when there's only one participant. In some languages
the text might also be different depending on how many people with no
demographic data participated.

Another possibility would be to use an `if` in the view so we don't
display an empty paragraph when the cont is zero, and then using
translation for `one` and `other`. I haven't gone that way because I
thought the logic would be more complex and the benefits wouldn't be
that great.
2019-05-21 13:50:18 +02:00
Javi Martín
ae4cd06c24 Include no geozone in no demographic data 2019-05-21 13:50:18 +02:00
Javi Martín
383909e16c Extract class to manage GeozoneStats
Even if this class looks very simple now, we're trying a few things
related to these stats. Having a class for it makes future changes
easier and, if there weren't any future changes, at least it makes
current experiments easier.

Note we keep the method `participants_by_geozone` to return a hash
because we're caching the stats and storing GeozoneStats objects would
need a lot more memory and we would get an error.
2019-05-21 13:50:18 +02:00
Javi Martín
558070d530 Remove geozone participation percentage
We currently don't store geozone population.
2019-05-21 13:50:18 +02:00
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