add budget investment stats
This commit is contained in:
@@ -4,7 +4,8 @@ class Admin::Api::StatsController < Admin::Api::BaseController
|
|||||||
unless params[:event].present? ||
|
unless params[:event].present? ||
|
||||||
params[:visits].present? ||
|
params[:visits].present? ||
|
||||||
params[:spending_proposals].present? ||
|
params[:spending_proposals].present? ||
|
||||||
params[:budget_investments].present?
|
params[:budget_investments].present? ||
|
||||||
|
params[:user_supported_budgets].present?
|
||||||
return render json: {}, status: :bad_request
|
return render json: {}, status: :bad_request
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -26,6 +27,9 @@ class Admin::Api::StatsController < Admin::Api::BaseController
|
|||||||
ds.add "Budget Investments", Budget::Investment.group_by_day(:created_at).count
|
ds.add "Budget Investments", Budget::Investment.group_by_day(:created_at).count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if params[:user_supported_budgets].present?
|
||||||
|
ds.add "User supported budgets", Vote.where(votable_type: "Budget::Investment").group_by_day(:updated_at).count
|
||||||
|
end
|
||||||
render json: ds.build
|
render json: ds.build
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -52,9 +52,29 @@ class Admin::StatsController < Admin::BaseController
|
|||||||
@users_who_have_sent_message = DirectMessage.select(:sender_id).distinct.count
|
@users_who_have_sent_message = DirectMessage.select(:sender_id).distinct.count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def budget_investments
|
||||||
|
votes = Vote.for_budget_investments(Budget::Investment.all)
|
||||||
|
@vote_count = votes.count
|
||||||
|
@participant_count = votes.select(:voter_id).distinct.count
|
||||||
|
|
||||||
|
@voters_in_heading = {}
|
||||||
|
budget = Budget.last
|
||||||
|
budget.headings.each do |heading|
|
||||||
|
@voters_in_heading[heading] = voters_in_heading(heading)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def polls
|
def polls
|
||||||
@polls = ::Poll.current
|
@polls = ::Poll.current
|
||||||
@participants = ::Poll::Voter.where(poll: @polls)
|
@participants = ::Poll::Voter.where(poll: @polls)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def voters_in_heading(heading)
|
||||||
|
Vote.where(votable_type: "Budget::Investment").
|
||||||
|
includes(:budget_investment).
|
||||||
|
where(budget_investments: { heading_id: heading.id }).
|
||||||
|
select("votes.voter_id").distinct.count
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
45
app/views/admin/stats/budget_investments.html.erb
Normal file
45
app/views/admin/stats/budget_investments.html.erb
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<% content_for :head do %>
|
||||||
|
<%= javascript_include_tag "stat_graphs", "data-turbolinks-track" => true %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div class="stats">
|
||||||
|
<div class="row stats-numbers">
|
||||||
|
<div class="small-12 medium-3 column">
|
||||||
|
<p class="featured">
|
||||||
|
<%= t("admin.stats.budget_investments.vote_count") %>
|
||||||
|
<br>
|
||||||
|
<span id="total_votes_count" class="number">
|
||||||
|
<%= @vote_count %>
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="small-12 medium-6 column end">
|
||||||
|
<p>
|
||||||
|
<%= t("admin.stats.budget_investments.participant_count") %>
|
||||||
|
<br>
|
||||||
|
<span id="total_participants_count" class="number">
|
||||||
|
<%= @participant_count %>
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= render "graph", name: "user_supported_budgets", event: "", count: @participant_count %>
|
||||||
|
|
||||||
|
<table class="investment-projects-summary">
|
||||||
|
<th><%= t("admin.stats.budget_investments.groups") %></th>
|
||||||
|
<th><%= t("admin.stats.budget_investments.users") %></th>
|
||||||
|
|
||||||
|
<% @voters_in_heading.each do |heading, count| %>
|
||||||
|
<tr id="<%= dom_id(heading) %>">
|
||||||
|
<td class="name">
|
||||||
|
<%= heading.name %>
|
||||||
|
</td>
|
||||||
|
<td class="name">
|
||||||
|
<%= number_with_delimiter count %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
@@ -6,6 +6,8 @@
|
|||||||
<div class="float-right clear">
|
<div class="float-right clear">
|
||||||
<%= link_to t("admin.stats.show.polls"),
|
<%= link_to t("admin.stats.show.polls"),
|
||||||
polls_admin_stats_path, class: "button hollow" %>
|
polls_admin_stats_path, class: "button hollow" %>
|
||||||
|
<%= link_to t("admin.stats.show.participatory_budgets"),
|
||||||
|
budget_investments_admin_stats_path, class: "button hollow" %>
|
||||||
<%= link_to t("admin.stats.show.direct_messages"),
|
<%= link_to t("admin.stats.show.direct_messages"),
|
||||||
direct_messages_admin_stats_path, class: "button hollow" %>
|
direct_messages_admin_stats_path, class: "button hollow" %>
|
||||||
<%= link_to t("admin.stats.show.proposal_notifications"),
|
<%= link_to t("admin.stats.show.proposal_notifications"),
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ ActsAsVotable::Vote.class_eval do
|
|||||||
include Graphqlable
|
include Graphqlable
|
||||||
|
|
||||||
belongs_to :signature
|
belongs_to :signature
|
||||||
|
belongs_to :budget_investment, foreign_key: "votable_id", class_name: "Budget::Investment"
|
||||||
|
|
||||||
scope :public_for_api, -> do
|
scope :public_for_api, -> do
|
||||||
where(%{(votes.votable_type = 'Debate' and votes.votable_id in (?)) or
|
where(%{(votes.votable_type = 'Debate' and votes.votable_id in (?)) or
|
||||||
|
|||||||
@@ -1452,6 +1452,7 @@ en:
|
|||||||
visits: Visits
|
visits: Visits
|
||||||
votes: Total votes
|
votes: Total votes
|
||||||
budgets_title: Participatory budgeting
|
budgets_title: Participatory budgeting
|
||||||
|
participatory_budgets: Participatory Budgets
|
||||||
direct_messages: Direct messages
|
direct_messages: Direct messages
|
||||||
proposal_notifications: Proposal notifications
|
proposal_notifications: Proposal notifications
|
||||||
incomplete_verifications: Incomplete verifications
|
incomplete_verifications: Incomplete verifications
|
||||||
@@ -1462,6 +1463,11 @@ en:
|
|||||||
visit: Visits
|
visit: Visits
|
||||||
level_2_user: Level 2 users
|
level_2_user: Level 2 users
|
||||||
proposal_created: Citizen proposals
|
proposal_created: Citizen proposals
|
||||||
|
budget_investments:
|
||||||
|
groups: Group
|
||||||
|
users: Users
|
||||||
|
vote_count: Votes
|
||||||
|
participant_count: Participants
|
||||||
direct_messages:
|
direct_messages:
|
||||||
title: Direct messages
|
title: Direct messages
|
||||||
total: Total
|
total: Total
|
||||||
|
|||||||
@@ -1451,6 +1451,7 @@ es:
|
|||||||
visits: Visitas
|
visits: Visitas
|
||||||
votes: Votos
|
votes: Votos
|
||||||
budgets_title: Presupuestos participativos
|
budgets_title: Presupuestos participativos
|
||||||
|
participatory_budgets: Presupuestos Participativos
|
||||||
direct_messages: Mensajes directos
|
direct_messages: Mensajes directos
|
||||||
proposal_notifications: Notificaciones de propuestas
|
proposal_notifications: Notificaciones de propuestas
|
||||||
incomplete_verifications: Verificaciones incompletas
|
incomplete_verifications: Verificaciones incompletas
|
||||||
@@ -1461,6 +1462,11 @@ es:
|
|||||||
visit: Visitas
|
visit: Visitas
|
||||||
level_2_user: Usuarios nivel 2
|
level_2_user: Usuarios nivel 2
|
||||||
proposal_created: Propuestas Ciudadanas
|
proposal_created: Propuestas Ciudadanas
|
||||||
|
budget_investments:
|
||||||
|
groups: Grupo
|
||||||
|
users: Usuarios
|
||||||
|
vote_count: Votos
|
||||||
|
participant_count: Participantes
|
||||||
direct_messages:
|
direct_messages:
|
||||||
title: Mensajes directos
|
title: Mensajes directos
|
||||||
total: Total
|
total: Total
|
||||||
|
|||||||
@@ -195,6 +195,7 @@ namespace :admin do
|
|||||||
|
|
||||||
resource :stats, only: :show do
|
resource :stats, only: :show do
|
||||||
get :graph, on: :member
|
get :graph, on: :member
|
||||||
|
get :budget_investments, on: :collection
|
||||||
get :proposal_notifications, on: :collection
|
get :proposal_notifications, on: :collection
|
||||||
get :direct_messages, on: :collection
|
get :direct_messages, on: :collection
|
||||||
get :polls, on: :collection
|
get :polls, on: :collection
|
||||||
|
|||||||
@@ -102,6 +102,83 @@ feature "Stats" do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "Budget investments" do
|
||||||
|
|
||||||
|
background do
|
||||||
|
budget = create(:budget)
|
||||||
|
group_all_city = create(:budget_group, budget: budget)
|
||||||
|
heading_all_city = create(:budget_heading, group: group_all_city)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Number of supports in investment projects" do
|
||||||
|
investment1 = create(:budget_investment)
|
||||||
|
investment2 = create(:budget_investment)
|
||||||
|
|
||||||
|
1.times { create(:vote, votable: investment1) }
|
||||||
|
2.times { create(:vote, votable: investment2) }
|
||||||
|
|
||||||
|
visit admin_stats_path
|
||||||
|
click_link "Participatory Budgets"
|
||||||
|
|
||||||
|
expect(page).to have_content "Votes 3"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Number of users that have voted a investment project" do
|
||||||
|
user1 = create(:user, :level_two)
|
||||||
|
user2 = create(:user, :level_two)
|
||||||
|
user3 = create(:user, :level_two)
|
||||||
|
|
||||||
|
investment1 = create(:budget_investment)
|
||||||
|
investment2 = create(:budget_investment)
|
||||||
|
|
||||||
|
create(:vote, votable: investment1, voter: user1)
|
||||||
|
create(:vote, votable: investment1, voter: user2)
|
||||||
|
create(:vote, votable: investment2, voter: user1)
|
||||||
|
|
||||||
|
visit admin_stats_path
|
||||||
|
click_link "Participatory Budgets"
|
||||||
|
|
||||||
|
expect(page).to have_content "Participants 2"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Number of users that have voted a investment project per geozone" do
|
||||||
|
budget = create(:budget)
|
||||||
|
|
||||||
|
group_all_city = create(:budget_group, budget: budget)
|
||||||
|
group_districts = create(:budget_group, budget: budget)
|
||||||
|
|
||||||
|
all_city = create(:budget_heading, group: group_all_city)
|
||||||
|
carabanchel = create(:budget_heading, group: group_districts)
|
||||||
|
barajas = create(:budget_heading, group: group_districts)
|
||||||
|
|
||||||
|
all_city_investment = create(:budget_investment, heading: all_city)
|
||||||
|
carabanchel_investment = create(:budget_investment, heading: carabanchel)
|
||||||
|
carabanchel_investment = create(:budget_investment, heading: carabanchel)
|
||||||
|
|
||||||
|
Budget::Investment.all.each do |investment|
|
||||||
|
create(:vote, votable: investment)
|
||||||
|
end
|
||||||
|
|
||||||
|
visit admin_stats_path
|
||||||
|
click_link "Participatory Budgets"
|
||||||
|
|
||||||
|
within("#budget_heading_#{all_city.id}") do
|
||||||
|
expect(page).to have_content all_city.name
|
||||||
|
expect(page).to have_content 1
|
||||||
|
end
|
||||||
|
|
||||||
|
within("#budget_heading_#{carabanchel.id}") do
|
||||||
|
expect(page).to have_content carabanchel.name
|
||||||
|
expect(page).to have_content 2
|
||||||
|
end
|
||||||
|
|
||||||
|
within("#budget_heading_#{barajas.id}") do
|
||||||
|
expect(page).to have_content barajas.name
|
||||||
|
expect(page).to have_content 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "graphs" do
|
context "graphs" do
|
||||||
scenario "event graphs", :js do
|
scenario "event graphs", :js do
|
||||||
campaign = create(:campaign)
|
campaign = create(:campaign)
|
||||||
|
|||||||
Reference in New Issue
Block a user