Add web and booth participants in budget stats

This commit is contained in:
María Checa
2018-07-05 18:41:14 +02:00
committed by Javi Martín
parent c2457e36a5
commit fac99cfb10
5 changed files with 48 additions and 9 deletions

View File

@@ -6,9 +6,11 @@ class Budget
end
def generate
stats = %w[total_participants total_participants_support_phase total_participants_vote_phase total_budget_investments total_votes
total_selected_investments total_unfeasible_investments total_male_participants total_female_participants total_supports
total_unknown_gender_or_age age_groups male_percentage female_percentage headings]
stats = %w[total_participants total_participants_support_phase total_participants_vote_phase
total_budget_investments total_votes total_selected_investments
total_unfeasible_investments total_male_participants total_female_participants
total_supports total_unknown_gender_or_age age_groups male_percentage
female_percentage headings total_participants_web total_participants_booths]
stats.map { |stat_name| [stat_name.to_sym, send(stat_name)] }.to_h
end
@@ -22,6 +24,16 @@ class Budget
stats_cache("total_participants_support_phase") { voters.uniq.count }
end
def total_participants_web
stats_cache("total_participants_web") do
(balloters - poll_ballot_voters).uniq.compact.count
end
end
def total_participants_booths
stats_cache("total_participants_booths") { poll_ballot_voters.uniq.count }
end
def total_participants_vote_phase
stats_cache("total_participants_vote_phase") { balloters.uniq.count }
end
@@ -96,7 +108,7 @@ class Budget
def participants
stats_cache("participants") do
User.where(id: (authors + voters + balloters + poll_ballot_voters).uniq)
User.where(id: (authors + voters + balloters + poll_ballot_voters).uniq.compact)
end
end

View File

@@ -76,11 +76,18 @@
<%= @stats[:total_supports] %> <em><%= t("budgets.stats.supports") %></em><br>
</span>
<span class="label balloting"></span>&nbsp;
<span class="uppercase"><strong><%= t("budgets.stats.total_participants_vote_phase") %></strong></span>:
<span id="total_participants_vote_phase">
<%= @stats[:total_participants_vote_phase] %> <em><%= t("budgets.stats.participants") %></em>,
<%= @stats[:total_votes] %> <em><%= t("budgets.stats.votes") %></em><br>
<br>
<span class="label"></span>&nbsp;
<span class="uppercase"><strong><%= t("budgets.stats.total_participants_web") %></strong></span>:
<span id="total_participants_web">
<%= @stats[:total_participants_web] %><br>
</span>
<span class="label"></span>&nbsp;
<span class="uppercase"><strong><%= t("budgets.stats.total_participants_booths") %></strong></span>:
<span id="total_participants_booths">
<%= @stats[:total_participants_booths] %><br>
</span>
</p>
</div>

View File

@@ -200,6 +200,8 @@ en:
total_selected_investments: Proposals on final phase
total_unfeasible_investments: Unfeasible proposals
total_participants_support_phase: Support phase
total_participants_web: Vote phase web participants
total_participants_booths: Vote phase booth participants
participants: Participants
supports: Supports
votes: Votes

View File

@@ -200,6 +200,8 @@ es:
total_selected_investments: Propuestas en la fase final
total_unfeasible_investments: Propuestas inviables
total_participants_support_phase: Fase de apoyos
total_participants_web: Participantes web en votación final
total_participants_booths: Participantes en urnas votación final
participants: Participantes
supports: Apoyos
votes: Votos

View File

@@ -68,6 +68,22 @@ describe Budget::Stats do
end
context "#total_participants_web" do
it "returns the number of total participants in the votes phase via web" do
expect(@stats[:total_participants_web]).to be 3
end
end
context "#total_participants_booths" do
it "returns the number of total participants in the votes phase in booths" do
expect(@stats[:total_participants_booths]).to be 1
end
end
context "#total_budget_investments" do
it "returns the number of total budget investments" do