From cfe3f95f5c91c636874fc497b18fcd69ff4d3453 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 16 May 2016 14:10:27 +0200 Subject: [PATCH 01/15] moves graphs to individual views --- app/controllers/admin/stats_controller.rb | 13 +++++++++- app/helpers/stats_helper.rb | 29 +++++++++++++---------- app/views/admin/stats/_graph.html.erb | 4 ++++ app/views/admin/stats/graph.html.erb | 5 ++++ app/views/admin/stats/show.html.erb | 25 +++++++------------ config/locales/en/admin.yml | 7 +++++- config/locales/es/admin.yml | 7 +++++- config/routes/admin.rb | 1 + 8 files changed, 58 insertions(+), 33 deletions(-) create mode 100644 app/views/admin/stats/_graph.html.erb create mode 100644 app/views/admin/stats/graph.html.erb diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index 352232d55..e865b530d 100644 --- a/app/controllers/admin/stats_controller.rb +++ b/app/controllers/admin/stats_controller.rb @@ -1,7 +1,7 @@ class Admin::StatsController < Admin::BaseController def show - @event_types = Ahoy::Event.group(:name).count + @event_types = Ahoy::Event.pluck(:name).uniq.sort @visits = Visit.count @debates = Debate.with_hidden.count @@ -31,6 +31,17 @@ class Admin::StatsController < Admin::BaseController @investments = Budget::Investment.where(budget_id: budgets_ids).count end + def graph + @name = params[:id] + @event = params[:event] + + if params[:event] + @count = Ahoy::Event.where(name: params[:event]).count + else + @count = params[:count] + end + end + def proposal_notifications @proposal_notifications = ProposalNotification.all @proposals_with_notifications = @proposal_notifications.select(:proposal_id).distinct.count diff --git a/app/helpers/stats_helper.rb b/app/helpers/stats_helper.rb index b36977b3e..57db7166a 100644 --- a/app/helpers/stats_helper.rb +++ b/app/helpers/stats_helper.rb @@ -1,24 +1,27 @@ module StatsHelper - def events_chart_tag(events, opt = {}) - events = events.join(",") if events.is_a? Array + def chart_tag(opt = {}) opt[:data] ||= {} - opt[:data][:graph] = admin_api_stats_path(events: events) + opt[:data][:graph] = admin_api_stats_path(chart_data(opt)) content_tag :div, "", opt end - def visits_chart_tag(opt = {}) - events = events.join(",") if events.is_a? Array - opt[:data] ||= {} - opt[:data][:graph] = admin_api_stats_path(visits: true) - content_tag :div, "", opt + def chart_data(opt = {}) + data = nil + if opt[:id].present? + data = { opt[:id] => true } + elsif opt[:event].present? + data = { event: opt[:event] } + end + data end - def spending_proposals_chart_tag(opt = {}) - events = events.join(",") if events.is_a? Array - opt[:data] ||= {} - opt[:data][:graph] = admin_api_stats_path(spending_proposals: true) - content_tag :div, "", opt + def graph_link_text(event) + text = t("admin.stats.graph.#{event}") + if text.to_s.match(/translation missing/) + text = event + end + text end def budget_investments_chart_tag(opt = {}) diff --git a/app/views/admin/stats/_graph.html.erb b/app/views/admin/stats/_graph.html.erb new file mode 100644 index 000000000..529574a28 --- /dev/null +++ b/app/views/admin/stats/_graph.html.erb @@ -0,0 +1,4 @@ +
+

<%= t "admin.stats.graph.#{name || event}" %>(<%= count %>)

+ <%= chart_tag id: name, event: event %> +
diff --git a/app/views/admin/stats/graph.html.erb b/app/views/admin/stats/graph.html.erb new file mode 100644 index 000000000..af6d1111a --- /dev/null +++ b/app/views/admin/stats/graph.html.erb @@ -0,0 +1,5 @@ +<% content_for :head do %> + <%= javascript_include_tag "stat_graphs", 'data-turbolinks-track' => true %> +<% end %> + +<%= render 'graph', name: @name, event: @event, count: @count %> diff --git a/app/views/admin/stats/show.html.erb b/app/views/admin/stats/show.html.erb index 86855a15b..1a2820086 100644 --- a/app/views/admin/stats/show.html.erb +++ b/app/views/admin/stats/show.html.erb @@ -1,7 +1,7 @@ <% content_for :head do %> <%= javascript_include_tag "stat_graphs", "data-turbolinks-track" => true %> <% end %> -
+

<%= t "admin.stats.show.stats_title" %>

@@ -22,7 +22,8 @@
@@ -119,24 +120,14 @@
-

<%= t "admin.stats.show.visits_title" %>

- <%= visits_chart_tag id: "visits" %> -
- -
- <% @event_types.each do |event, count| %> -

<%= event.titleize %> (<%= count %>)

- <%= events_chart_tag event %> + <% @event_types.each do |event| %> +

+ <%= link_to graph_link_text(event), + graph_admin_stats_path(event: event) %> +

<% end %>
- <% if feature?(:spending_proposals) %> -
-

<%= t "admin.stats.show.spending_proposals_title" %>

- <%= spending_proposals_chart_tag id: "spending_proposals" %> -
- <% end %> - <% if feature?(:budgets) %>

<%= t "admin.stats.show.budgets_title" %>

diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index ad66ad884..7baa7a31c 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -1453,11 +1453,16 @@ en: votes: Total votes spending_proposals_title: Spending Proposals budgets_title: Participatory budgeting - visits_title: Visits direct_messages: Direct messages proposal_notifications: Proposal notifications incomplete_verifications: Incomplete verifications polls: Polls + graph: + debate_created: Debates + spending_proposals: Investment projects + visit: Visits + level_2_user: Level 2 users + proposal_created: Citizen proposals direct_messages: title: Direct messages total: Total diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index b55e1dae8..6124e2e6d 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -1452,11 +1452,16 @@ es: votes: Votos spending_proposals_title: Propuestas de inversión budgets_title: Presupuestos participativos - visits_title: Visitas direct_messages: Mensajes directos proposal_notifications: Notificaciones de propuestas incomplete_verifications: Verificaciones incompletas polls: Votaciones + graph: + debate_created: Debates + spending_proposals: Propuestas de inversión + visit: Visitas + level_2_user: Usuarios nivel 2 + proposal_created: Propuestas Ciudadanas direct_messages: title: Mensajes directos total: Total diff --git a/config/routes/admin.rb b/config/routes/admin.rb index c5b350528..7824c062a 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -194,6 +194,7 @@ namespace :admin do end resource :stats, only: :show do + get :graph, on: :member get :proposal_notifications, on: :collection get :direct_messages, on: :collection get :polls, on: :collection From a31b62526ba78bd458c09694f3f0849d8a75a778 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 16 May 2016 14:10:42 +0200 Subject: [PATCH 02/15] removes unused multiple lines per graph --- app/controllers/admin/api/stats_controller.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/api/stats_controller.rb b/app/controllers/admin/api/stats_controller.rb index af8ffb3aa..6e05e7e6f 100644 --- a/app/controllers/admin/api/stats_controller.rb +++ b/app/controllers/admin/api/stats_controller.rb @@ -1,7 +1,7 @@ class Admin::Api::StatsController < Admin::Api::BaseController def show - unless params[:events].present? || + unless params[:event].present? || params[:visits].present? || params[:spending_proposals].present? || params[:budget_investments].present? @@ -10,11 +10,8 @@ class Admin::Api::StatsController < Admin::Api::BaseController ds = Ahoy::DataSource.new - if params[:events].present? - event_types = params[:events].split "," - event_types.each do |event| - ds.add event.titleize, Ahoy::Event.where(name: event).group_by_day(:time).count - end + if params[:event].present? + ds.add params[:event].titleize, Ahoy::Event.where(name: params[:event]).group_by_day(:time).count end if params[:visits].present? From 94a3e7e61ad45b33cabbde035ad89d7ef09c1b64 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 16 May 2016 14:12:26 +0200 Subject: [PATCH 03/15] does not exclude ahoy events --- config/initializers/ahoy.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/initializers/ahoy.rb b/config/initializers/ahoy.rb index c7c93b89c..a6bf60769 100644 --- a/config/initializers/ahoy.rb +++ b/config/initializers/ahoy.rb @@ -8,4 +8,8 @@ class Ahoy::Store < Ahoy::Stores::ActiveRecordStore event.ip = request.ip end end + + def exclude? + false + end end From 1f8d19c8bad3834c9e749ee9b7cc54858289d57d Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 16 May 2016 14:13:02 +0200 Subject: [PATCH 04/15] adds basic graph specs --- spec/features/admin/stats_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/features/admin/stats_spec.rb b/spec/features/admin/stats_spec.rb index 1e3cb5087..7422f0e2a 100644 --- a/spec/features/admin/stats_spec.rb +++ b/spec/features/admin/stats_spec.rb @@ -102,6 +102,25 @@ feature "Stats" do end + context "graphs" do + scenario "event graphs", :js do + campaign = create(:campaign) + + visit root_path(track_id: campaign.track_id) + visit admin_stats_path + + within("#stats") do + click_link campaign.name + end + + expect(page).to have_content "#{campaign.name}(1)" + within("#graph") do + event_created_at = Ahoy::Event.where(name: campaign.name).first.time + expect(page).to have_content event_created_at.strftime("%Y-%m-%d") + end + end + end + context "Proposal notifications" do scenario "Summary stats" do From 73d35e2c192bd15bd3b52850764b67358f4cf143 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 16 May 2016 14:21:22 +0200 Subject: [PATCH 05/15] removes chart js from stats summary --- app/views/admin/stats/show.html.erb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/views/admin/stats/show.html.erb b/app/views/admin/stats/show.html.erb index 1a2820086..6d99ab3eb 100644 --- a/app/views/admin/stats/show.html.erb +++ b/app/views/admin/stats/show.html.erb @@ -1,6 +1,3 @@ -<% content_for :head do %> - <%= javascript_include_tag "stat_graphs", "data-turbolinks-track" => true %> -<% end %>
From 0d9ff07ff5930c05c92e7446f357c371b44e6a48 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 17 May 2016 23:36:08 +0200 Subject: [PATCH 06/15] adds back button from graph --- app/views/admin/stats/_graph.html.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/admin/stats/_graph.html.erb b/app/views/admin/stats/_graph.html.erb index 529574a28..44124b12d 100644 --- a/app/views/admin/stats/_graph.html.erb +++ b/app/views/admin/stats/_graph.html.erb @@ -1,3 +1,5 @@ +<%= back_link_to %> +

<%= t "admin.stats.graph.#{name || event}" %>(<%= count %>)

<%= chart_tag id: name, event: event %> From b6286317698c3db736c54be019fcb769b277b7b8 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 17 May 2016 23:36:20 +0200 Subject: [PATCH 07/15] fixes specs --- app/views/admin/stats/_graph.html.erb | 2 +- config/locales/en/admin.yml | 1 - config/locales/es/admin.yml | 1 - .../admin/api/stats_controller_spec.rb | 35 +------------------ spec/features/admin/stats_spec.rb | 2 +- spec/features/campaigns_spec.rb | 11 +++++- 6 files changed, 13 insertions(+), 39 deletions(-) diff --git a/app/views/admin/stats/_graph.html.erb b/app/views/admin/stats/_graph.html.erb index 44124b12d..1a8975289 100644 --- a/app/views/admin/stats/_graph.html.erb +++ b/app/views/admin/stats/_graph.html.erb @@ -1,6 +1,6 @@ <%= back_link_to %>
-

<%= t "admin.stats.graph.#{name || event}" %>(<%= count %>)

+

<%= t "admin.stats.graph.#{name || event}" %> (<%= count %>)

<%= chart_tag id: name, event: event %>
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 7baa7a31c..96c302be6 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -1451,7 +1451,6 @@ en: verified_users_who_didnt_vote_proposals: Verified users who didn't votes proposals visits: Visits votes: Total votes - spending_proposals_title: Spending Proposals budgets_title: Participatory budgeting direct_messages: Direct messages proposal_notifications: Proposal notifications diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 6124e2e6d..16ed55b4c 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -1450,7 +1450,6 @@ es: verified_users_who_didnt_vote_proposals: Usuarios verificados que no han votado propuestas visits: Visitas votes: Votos - spending_proposals_title: Propuestas de inversión budgets_title: Presupuestos participativos direct_messages: Mensajes directos proposal_notifications: Notificaciones de propuestas diff --git a/spec/controllers/admin/api/stats_controller_spec.rb b/spec/controllers/admin/api/stats_controller_spec.rb index d9a2cdeb4..291c100d8 100644 --- a/spec/controllers/admin/api/stats_controller_spec.rb +++ b/spec/controllers/admin/api/stats_controller_spec.rb @@ -31,23 +31,13 @@ describe Admin::Api::StatsController do it "returns single events formated for working with c3.js" do sign_in user - get :show, params: { events: "foo" } + get :show, params: { event: "foo" } expect(response).to be_ok data = JSON.parse(response.body) expect(data).to eq "x" => ["2015-01-01", "2015-01-02"], "Foo" => [2, 1] end - - it "returns combined comma separated events formated for working with c3.js" do - sign_in user - get :show, params: { events: "foo,bar" } - - expect(response).to be_ok - - data = JSON.parse(response.body) - expect(data).to eq "x" => ["2015-01-01", "2015-01-02", "2015-01-03"], "Foo" => [2, 1, 0], "Bar" => [1, 0, 2] - end end context "visits present" do @@ -69,29 +59,6 @@ describe Admin::Api::StatsController do end end - context "visits and events present" do - it "returns combined events and visits formated for working with c3.js" do - time_1 = Time.zone.local(2015, 01, 01) - time_2 = Time.zone.local(2015, 01, 02) - - create :ahoy_event, name: "foo", time: time_1 - create :ahoy_event, name: "foo", time: time_2 - create :ahoy_event, name: "foo", time: time_2 - - create :visit, started_at: time_1 - create :visit, started_at: time_1 - create :visit, started_at: time_2 - - sign_in user - get :show, params: { events: "foo", visits: true } - - expect(response).to be_ok - - data = JSON.parse(response.body) - expect(data).to eq "x" => ["2015-01-01", "2015-01-02"], "Foo" => [1, 2], "Visits" => [2, 1] - end - end - context "budget investments present" do it "returns budget investments formated for working with c3.js" do time_1 = Time.zone.local(2017, 04, 01) diff --git a/spec/features/admin/stats_spec.rb b/spec/features/admin/stats_spec.rb index 7422f0e2a..64af655cf 100644 --- a/spec/features/admin/stats_spec.rb +++ b/spec/features/admin/stats_spec.rb @@ -97,7 +97,7 @@ feature "Stats" do visit admin_stats_path - expect(page).to have_content "Level 2 User (1)" + expect(page).to have_content "Level two users 1" end end diff --git a/spec/features/campaigns_spec.rb b/spec/features/campaigns_spec.rb index 681cd33c1..517c95481 100644 --- a/spec/features/campaigns_spec.rb +++ b/spec/features/campaigns_spec.rb @@ -15,8 +15,13 @@ feature "Email campaigns" do 5.times { visit root_url(track_id: @campaign2.track_id) } visit admin_stats_path + click_link @campaign1.name expect(page).to have_content "#{@campaign1.name} (3)" + + click_link "Go back" + click_link @campaign2.name + expect(page).to have_content "#{@campaign2.name} (5)" end @@ -25,9 +30,13 @@ feature "Email campaigns" do visit root_url(track_id: "999") visit admin_stats_path + click_link @campaign1.name expect(page).to have_content "#{@campaign1.name} (1)" + + click_link "Go back" + expect(page).not_to have_content @campaign2.name.to_s end -end \ No newline at end of file +end From be757f79d06824065ab0cab86d9304e00c249c80 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Tue, 17 May 2016 23:41:34 +0200 Subject: [PATCH 08/15] cleans up --- app/views/admin/stats/show.html.erb | 2 +- spec/features/admin/stats_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/admin/stats/show.html.erb b/app/views/admin/stats/show.html.erb index 6d99ab3eb..b8580322d 100644 --- a/app/views/admin/stats/show.html.erb +++ b/app/views/admin/stats/show.html.erb @@ -120,7 +120,7 @@ <% @event_types.each do |event| %>

<%= link_to graph_link_text(event), - graph_admin_stats_path(event: event) %> + graph_admin_stats_path(event: event) %>

<% end %>
diff --git a/spec/features/admin/stats_spec.rb b/spec/features/admin/stats_spec.rb index 64af655cf..03dcc3dd9 100644 --- a/spec/features/admin/stats_spec.rb +++ b/spec/features/admin/stats_spec.rb @@ -113,7 +113,7 @@ feature "Stats" do click_link campaign.name end - expect(page).to have_content "#{campaign.name}(1)" + expect(page).to have_content "#{campaign.name} (1)" within("#graph") do event_created_at = Ahoy::Event.where(name: campaign.name).first.time expect(page).to have_content event_created_at.strftime("%Y-%m-%d") From 5121c9b6d8d2771e4f87c6a979402c65b1b74066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Sat, 18 Feb 2017 13:13:27 +0100 Subject: [PATCH 09/15] removes booth message from admin interface --- app/views/layouts/admin.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 6b231ce49..c08412903 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -33,7 +33,7 @@
<%= render "layouts/flash" %> - <%= render "layouts/officing_booth" %> + <%= render "layouts/officing_booth" if session[:booth_id].present? %> <%= yield %>
From 135984d535e702c701191b7c199ee2684131056a Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Mon, 20 Feb 2017 12:59:51 +0100 Subject: [PATCH 10/15] removes budget countdown --- app/helpers/budgets_helper.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb index 15fdc91a8..d8425c217 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -44,10 +44,6 @@ module BudgetsHelper end end - def display_budget_countdown?(budget) - budget.balloting? - end - def css_for_ballot_heading(heading) return "" if current_ballot.blank? || @current_filter == "unfeasible" current_ballot.has_lines_in_heading?(heading) ? "is-active" : "" From 11437a1d4085708717310f66bdd8706ba760cb2f Mon Sep 17 00:00:00 2001 From: rgarcia Date: Mon, 13 Mar 2017 20:43:24 +0100 Subject: [PATCH 11/15] add budget investment stats --- app/controllers/admin/api/stats_controller.rb | 6 +- app/controllers/admin/stats_controller.rb | 20 +++++ .../admin/stats/budget_investments.html.erb | 45 +++++++++++ app/views/admin/stats/show.html.erb | 2 + config/initializers/vote_extensions.rb | 1 + config/locales/en/admin.yml | 6 ++ config/locales/es/admin.yml | 6 ++ config/routes/admin.rb | 1 + spec/features/admin/stats_spec.rb | 77 +++++++++++++++++++ 9 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 app/views/admin/stats/budget_investments.html.erb diff --git a/app/controllers/admin/api/stats_controller.rb b/app/controllers/admin/api/stats_controller.rb index 6e05e7e6f..37be264bf 100644 --- a/app/controllers/admin/api/stats_controller.rb +++ b/app/controllers/admin/api/stats_controller.rb @@ -4,7 +4,8 @@ class Admin::Api::StatsController < Admin::Api::BaseController unless params[:event].present? || params[:visits].present? || params[:spending_proposals].present? || - params[:budget_investments].present? + params[:budget_investments].present? || + params[:user_supported_budgets].present? return render json: {}, status: :bad_request end @@ -26,6 +27,9 @@ class Admin::Api::StatsController < Admin::Api::BaseController ds.add "Budget Investments", Budget::Investment.group_by_day(:created_at).count 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 end end diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index e865b530d..c65b04162 100644 --- a/app/controllers/admin/stats_controller.rb +++ b/app/controllers/admin/stats_controller.rb @@ -52,9 +52,29 @@ class Admin::StatsController < Admin::BaseController @users_who_have_sent_message = DirectMessage.select(:sender_id).distinct.count 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 @polls = ::Poll.current @participants = ::Poll::Voter.where(poll: @polls) 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 diff --git a/app/views/admin/stats/budget_investments.html.erb b/app/views/admin/stats/budget_investments.html.erb new file mode 100644 index 000000000..c3942cc5c --- /dev/null +++ b/app/views/admin/stats/budget_investments.html.erb @@ -0,0 +1,45 @@ +<% content_for :head do %> + <%= javascript_include_tag "stat_graphs", "data-turbolinks-track" => true %> +<% end %> + +
+
+
+ +
+ +
+

+ <%= t("admin.stats.budget_investments.participant_count") %> +
+ + <%= @participant_count %> + +

+
+
+
+ +<%= render "graph", name: "user_supported_budgets", event: "", count: @participant_count %> + + + + + + <% @voters_in_heading.each do |heading, count| %> + + + + + <% end %> +
<%= t("admin.stats.budget_investments.groups") %><%= t("admin.stats.budget_investments.users") %>
+ <%= heading.name %> + + <%= number_with_delimiter count %> +
diff --git a/app/views/admin/stats/show.html.erb b/app/views/admin/stats/show.html.erb index b8580322d..0f213776d 100644 --- a/app/views/admin/stats/show.html.erb +++ b/app/views/admin/stats/show.html.erb @@ -6,6 +6,8 @@
<%= link_to t("admin.stats.show.polls"), 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"), direct_messages_admin_stats_path, class: "button hollow" %> <%= link_to t("admin.stats.show.proposal_notifications"), diff --git a/config/initializers/vote_extensions.rb b/config/initializers/vote_extensions.rb index 548d75350..374013e99 100644 --- a/config/initializers/vote_extensions.rb +++ b/config/initializers/vote_extensions.rb @@ -2,6 +2,7 @@ ActsAsVotable::Vote.class_eval do include Graphqlable belongs_to :signature + belongs_to :budget_investment, foreign_key: "votable_id", class_name: "Budget::Investment" scope :public_for_api, -> do where(%{(votes.votable_type = 'Debate' and votes.votable_id in (?)) or diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 96c302be6..5be2340ba 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -1452,6 +1452,7 @@ en: visits: Visits votes: Total votes budgets_title: Participatory budgeting + participatory_budgets: Participatory Budgets direct_messages: Direct messages proposal_notifications: Proposal notifications incomplete_verifications: Incomplete verifications @@ -1462,6 +1463,11 @@ en: visit: Visits level_2_user: Level 2 users proposal_created: Citizen proposals + budget_investments: + groups: Group + users: Users + vote_count: Votes + participant_count: Participants direct_messages: title: Direct messages total: Total diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 16ed55b4c..b4db6fb6a 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -1451,6 +1451,7 @@ es: visits: Visitas votes: Votos budgets_title: Presupuestos participativos + participatory_budgets: Presupuestos Participativos direct_messages: Mensajes directos proposal_notifications: Notificaciones de propuestas incomplete_verifications: Verificaciones incompletas @@ -1461,6 +1462,11 @@ es: visit: Visitas level_2_user: Usuarios nivel 2 proposal_created: Propuestas Ciudadanas + budget_investments: + groups: Grupo + users: Usuarios + vote_count: Votos + participant_count: Participantes direct_messages: title: Mensajes directos total: Total diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 7824c062a..6b17b9d2b 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -195,6 +195,7 @@ namespace :admin do resource :stats, only: :show do get :graph, on: :member + get :budget_investments, on: :collection get :proposal_notifications, on: :collection get :direct_messages, on: :collection get :polls, on: :collection diff --git a/spec/features/admin/stats_spec.rb b/spec/features/admin/stats_spec.rb index 03dcc3dd9..f99952885 100644 --- a/spec/features/admin/stats_spec.rb +++ b/spec/features/admin/stats_spec.rb @@ -102,6 +102,83 @@ feature "Stats" do 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 scenario "event graphs", :js do campaign = create(:campaign) From 5be54b57dadd4973d8b6e85aab376963b6f2e89e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Wed, 24 May 2017 12:48:44 +0200 Subject: [PATCH 12/15] reduces current admin budget stats as supporting phase --- app/controllers/admin/stats_controller.rb | 20 +++++++++++---- ...ts.html.erb => budget_supporting.html.erb} | 16 +++++++----- app/views/admin/stats/budgets.html.erb | 16 ++++++++++++ app/views/admin/stats/show.html.erb | 4 +-- config/locales/en/admin.yml | 7 +++++- config/locales/es/admin.yml | 7 +++++- config/routes/admin.rb | 3 ++- spec/features/admin/stats_spec.rb | 25 +++++++++++++------ 8 files changed, 75 insertions(+), 23 deletions(-) rename app/views/admin/stats/{budget_investments.html.erb => budget_supporting.html.erb} (68%) create mode 100644 app/views/admin/stats/budgets.html.erb diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index c65b04162..75d79b57b 100644 --- a/app/controllers/admin/stats_controller.rb +++ b/app/controllers/admin/stats_controller.rb @@ -52,14 +52,24 @@ class Admin::StatsController < Admin::BaseController @users_who_have_sent_message = DirectMessage.select(:sender_id).distinct.count end - def budget_investments - votes = Vote.for_budget_investments(Budget::Investment.all) + + def budgets + @budgets = Budget.all + end + + def budget_supporting + @budget = Budget.find(params[:budget_id]) + heading_ids = @budget.heading_ids + + votes = Vote.where(votable_type: "Budget::Investment"). + includes(:budget_investment). + where(budget_investments: { heading_id: heading_ids }) + @vote_count = votes.count - @participant_count = votes.select(:voter_id).distinct.count + @user_count = votes.select(:voter_id).distinct.count @voters_in_heading = {} - budget = Budget.last - budget.headings.each do |heading| + @budget.headings.each do |heading| @voters_in_heading[heading] = voters_in_heading(heading) end end diff --git a/app/views/admin/stats/budget_investments.html.erb b/app/views/admin/stats/budget_supporting.html.erb similarity index 68% rename from app/views/admin/stats/budget_investments.html.erb rename to app/views/admin/stats/budget_supporting.html.erb index c3942cc5c..ba079c1c8 100644 --- a/app/views/admin/stats/budget_investments.html.erb +++ b/app/views/admin/stats/budget_supporting.html.erb @@ -2,11 +2,15 @@ <%= javascript_include_tag "stat_graphs", "data-turbolinks-track" => true %> <% end %> +<%= back_link_to budgets_admin_stats_path %> + +

<%= @budget.name %> - <%= t("admin.stats.budget_supporting.title") %>

+

- <%= t("admin.stats.budget_investments.participant_count") %> + <%= t("admin.stats.budget_supporting.participant_count") %>
- <%= @participant_count %> + <%= @user_count %>

-<%= render "graph", name: "user_supported_budgets", event: "", count: @participant_count %> +<%= render "graph", name: "user_supported_budgets", event: "", count: @user_count %> - - + + <% @voters_in_heading.each do |heading, count| %> diff --git a/app/views/admin/stats/budgets.html.erb b/app/views/admin/stats/budgets.html.erb new file mode 100644 index 000000000..8976884ec --- /dev/null +++ b/app/views/admin/stats/budgets.html.erb @@ -0,0 +1,16 @@ +<%= back_link_to admin_stats_path %> + +

<%= t("admin.stats.budgets.title") %>

+ +<% @budgets.each do |budget| %> +
<%= t("admin.stats.budget_investments.groups") %><%= t("admin.stats.budget_investments.users") %><%= t("admin.stats.budget_supporting.groups") %><%= t("admin.stats.budget_supporting.users") %>
+ + + + +
+ <%= budget.name %> + + <%= link_to t("admin.stats.budgets.supporting_phase"), budget_supporting_admin_stats_path(budget_id: budget.id), class: "button hollow" %> +
+<% end %> diff --git a/app/views/admin/stats/show.html.erb b/app/views/admin/stats/show.html.erb index 0f213776d..650f23fe5 100644 --- a/app/views/admin/stats/show.html.erb +++ b/app/views/admin/stats/show.html.erb @@ -7,7 +7,7 @@ <%= link_to t("admin.stats.show.polls"), polls_admin_stats_path, class: "button hollow" %> <%= link_to t("admin.stats.show.participatory_budgets"), - budget_investments_admin_stats_path, class: "button hollow" %> + budgets_admin_stats_path, class: "button hollow" %> <%= link_to t("admin.stats.show.direct_messages"), direct_messages_admin_stats_path, class: "button hollow" %> <%= link_to t("admin.stats.show.proposal_notifications"), @@ -22,7 +22,7 @@
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 5be2340ba..8dfc1ac7a 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -1463,7 +1463,12 @@ en: visit: Visits level_2_user: Level 2 users proposal_created: Citizen proposals - budget_investments: + budgets: + title: "Participatory Budgets - Participation stats" + supporting_phase: Supporting phase + balloting_phase: Final voting + budget_supporting: + title: "Supporting phase stats" groups: Group users: Users vote_count: Votes diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index b4db6fb6a..d26806ecf 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -1462,7 +1462,12 @@ es: visit: Visitas level_2_user: Usuarios nivel 2 proposal_created: Propuestas Ciudadanas - budget_investments: + budgets: + title: "Presupuestos participativos - Estadisticas de participación" + supporting_phase: Fase de apoyos + balloting_phase: Votación final + budget_supporting: + title: "Estadísticas fase de apoyos" groups: Grupo users: Usuarios vote_count: Votos diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 6b17b9d2b..378758c24 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -195,7 +195,8 @@ namespace :admin do resource :stats, only: :show do get :graph, on: :member - get :budget_investments, on: :collection + get :budgets, on: :collection + get :budget_supporting, on: :member get :proposal_notifications, on: :collection get :direct_messages, on: :collection get :polls, on: :collection diff --git a/spec/features/admin/stats_spec.rb b/spec/features/admin/stats_spec.rb index f99952885..0d5d33223 100644 --- a/spec/features/admin/stats_spec.rb +++ b/spec/features/admin/stats_spec.rb @@ -105,20 +105,24 @@ feature "Stats" do 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) + @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) + group_2 = create(:budget_group, budget: @budget) + investment1 = create(:budget_investment, heading: create(:budget_heading, group: group_2)) + investment2 = create(:budget_investment, heading: @heading_all_city) 1.times { create(:vote, votable: investment1) } 2.times { create(:vote, votable: investment2) } visit admin_stats_path click_link "Participatory Budgets" + within("#budget_#{@budget.id}") do + click_link "Supporting phase" + end expect(page).to have_content "Votes 3" end @@ -128,8 +132,9 @@ feature "Stats" do user2 = create(:user, :level_two) user3 = create(:user, :level_two) - investment1 = create(:budget_investment) - investment2 = create(:budget_investment) + group_2 = create(:budget_group, budget: @budget) + investment1 = create(:budget_investment, heading: create(:budget_heading, group: group_2)) + investment2 = create(:budget_investment, heading: @heading_all_city) create(:vote, votable: investment1, voter: user1) create(:vote, votable: investment1, voter: user2) @@ -137,6 +142,9 @@ feature "Stats" do visit admin_stats_path click_link "Participatory Budgets" + within("#budget_#{@budget.id}") do + click_link "Supporting phase" + end expect(page).to have_content "Participants 2" end @@ -161,6 +169,9 @@ feature "Stats" do visit admin_stats_path click_link "Participatory Budgets" + within("#budget_#{budget.id}") do + click_link "Supporting phase" + end within("#budget_heading_#{all_city.id}") do expect(page).to have_content all_city.name From 110ee961e39bfdfa31812abc20ff587110ab0113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Wed, 24 May 2017 14:26:36 +0200 Subject: [PATCH 13/15] adds budget stats for final voting to admin stats --- app/controllers/admin/stats_controller.rb | 11 + app/models/budget.rb | 1 + .../admin/stats/budget_balloting.html.erb | 57 ++++++ .../admin/stats/budget_supporting.html.erb | 2 +- app/views/admin/stats/budgets.html.erb | 1 + config/locales/en/admin.yml | 8 +- config/locales/es/admin.yml | 8 +- config/routes/admin.rb | 1 + spec/features/admin/stats_spec.rb | 190 ++++++++++++------ 9 files changed, 209 insertions(+), 70 deletions(-) create mode 100644 app/views/admin/stats/budget_balloting.html.erb diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index 75d79b57b..b6a926792 100644 --- a/app/controllers/admin/stats_controller.rb +++ b/app/controllers/admin/stats_controller.rb @@ -74,6 +74,17 @@ class Admin::StatsController < Admin::BaseController end end + def budget_balloting + @budget = Budget.find(params[:budget_id]) + @user_count = @budget.ballots.select {|ballot| ballot.lines.any? }.count + + @vote_count = @budget.lines.count + + @vote_count_by_heading = @budget.lines.group(:heading_id).count.collect {|k,v| [Budget::Heading.find(k).name, v]}.sort + + @user_count_by_district = User.where.not(balloted_heading_id: nil).group(:balloted_heading_id).count.collect {|k,v| [Budget::Heading.find(k).name, v]}.sort + end + def polls @polls = ::Poll.current @participants = ::Poll::Voter.where(poll: @polls) diff --git a/app/models/budget.rb b/app/models/budget.rb index 8c34e030d..8cc5c9b8f 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -31,6 +31,7 @@ class Budget < ApplicationRecord has_many :ballots, dependent: :destroy has_many :groups, dependent: :destroy has_many :headings, through: :groups + has_many :lines, through: :ballots, class_name: "Budget::Ballot::Line" has_many :phases, class_name: Budget::Phase has_one :poll diff --git a/app/views/admin/stats/budget_balloting.html.erb b/app/views/admin/stats/budget_balloting.html.erb new file mode 100644 index 000000000..72d1d6a54 --- /dev/null +++ b/app/views/admin/stats/budget_balloting.html.erb @@ -0,0 +1,57 @@ +<%= back_link_to budgets_admin_stats_path %> + +

<%= @budget.name %> - <%= t("admin.stats.budget_balloting.title") %>

+ +
+
+
+ +
+ +
+

+ <%= t("admin.stats.budget_balloting.participant_count") %> +
+ + <%= @user_count %> + +

+
+
+
+ + + + + <% @vote_count_by_heading.each do |heading_name, count| %> + + + + + <% end %> +
<%= t("admin.stats.budget_balloting.votes_per_heading") %>
+ <%= heading_name %> + + <%= number_with_delimiter count %> +
+ + + + + <% @user_count_by_district.each do |heading_name, count| %> + + + + + <% end %> +
<%= t("admin.stats.budget_balloting.participants_per_district") %>
+ <%= heading_name %> + + <%= number_with_delimiter count %> +
diff --git a/app/views/admin/stats/budget_supporting.html.erb b/app/views/admin/stats/budget_supporting.html.erb index ba079c1c8..6eb995a15 100644 --- a/app/views/admin/stats/budget_supporting.html.erb +++ b/app/views/admin/stats/budget_supporting.html.erb @@ -33,7 +33,7 @@ <%= render "graph", name: "user_supported_budgets", event: "", count: @user_count %> - + <% @voters_in_heading.each do |heading, count| %> diff --git a/app/views/admin/stats/budgets.html.erb b/app/views/admin/stats/budgets.html.erb index 8976884ec..2c12b6b37 100644 --- a/app/views/admin/stats/budgets.html.erb +++ b/app/views/admin/stats/budgets.html.erb @@ -10,6 +10,7 @@
<%= t("admin.stats.budget_supporting.groups") %><%= t("admin.stats.budget_supporting.headings") %> <%= t("admin.stats.budget_supporting.users") %> <%= link_to t("admin.stats.budgets.supporting_phase"), budget_supporting_admin_stats_path(budget_id: budget.id), class: "button hollow" %> + <%= link_to t("admin.stats.budgets.balloting_phase"), budget_balloting_admin_stats_path(budget_id: budget.id), class: "button hollow" %>
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 8dfc1ac7a..f47b0eb19 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -1467,9 +1467,15 @@ en: title: "Participatory Budgets - Participation stats" supporting_phase: Supporting phase balloting_phase: Final voting + budget_balloting: + title: "Final voting stats" + vote_count: Votes + participant_count: Participants + votes_per_heading: Votes per heading + participants_per_district: Participants per district budget_supporting: title: "Supporting phase stats" - groups: Group + headings: Headings users: Users vote_count: Votes participant_count: Participants diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index d26806ecf..c78902915 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -1466,9 +1466,15 @@ es: title: "Presupuestos participativos - Estadisticas de participación" supporting_phase: Fase de apoyos balloting_phase: Votación final + budget_balloting: + title: "Estadísticas votación final" + vote_count: Votos + participant_count: Participantes + votes_per_heading: Votos por partida + participants_per_district: Participantes por distrito budget_supporting: title: "Estadísticas fase de apoyos" - groups: Grupo + headings: Partidas users: Usuarios vote_count: Votos participant_count: Participantes diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 378758c24..917f1447c 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -197,6 +197,7 @@ namespace :admin do get :graph, on: :member get :budgets, on: :collection get :budget_supporting, on: :member + get :budget_balloting, on: :member get :proposal_notifications, on: :collection get :direct_messages, on: :collection get :polls, on: :collection diff --git a/spec/features/admin/stats_spec.rb b/spec/features/admin/stats_spec.rb index 0d5d33223..d4117879e 100644 --- a/spec/features/admin/stats_spec.rb +++ b/spec/features/admin/stats_spec.rb @@ -103,91 +103,147 @@ feature "Stats" do 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 - group_2 = create(:budget_group, budget: @budget) - investment1 = create(:budget_investment, heading: create(:budget_heading, group: group_2)) - investment2 = create(:budget_investment, heading: @heading_all_city) - - 1.times { create(:vote, votable: investment1) } - 2.times { create(:vote, votable: investment2) } - - visit admin_stats_path - click_link "Participatory Budgets" - within("#budget_#{@budget.id}") do - click_link "Supporting phase" + context "Supporting phase" 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 - expect(page).to have_content "Votes 3" - end + scenario "Number of supports in investment projects" do + group_2 = create(:budget_group, budget: @budget) + investment1 = create(:budget_investment, heading: create(:budget_heading, group: group_2)) + investment2 = create(:budget_investment, heading: @heading_all_city) - 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) + 1.times { create(:vote, votable: investment1) } + 2.times { create(:vote, votable: investment2) } - group_2 = create(:budget_group, budget: @budget) - investment1 = create(:budget_investment, heading: create(:budget_heading, group: group_2)) - investment2 = create(:budget_investment, heading: @heading_all_city) + visit admin_stats_path + click_link "Participatory Budgets" + within("#budget_#{@budget.id}") do + click_link "Supporting phase" + end - 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" - within("#budget_#{@budget.id}") do - click_link "Supporting phase" + expect(page).to have_content "Votes 3" end - expect(page).to have_content "Participants 2" - end + scenario "Number of users that have supported an investment project" do + user1 = create(:user, :level_two) + user2 = create(:user, :level_two) + user3 = create(:user, :level_two) - scenario "Number of users that have voted a investment project per geozone" do - budget = create(:budget) + group_2 = create(:budget_group, budget: @budget) + investment1 = create(:budget_investment, heading: create(:budget_heading, group: group_2)) + investment2 = create(:budget_investment, heading: @heading_all_city) - group_all_city = create(:budget_group, budget: budget) - group_districts = create(:budget_group, budget: budget) + create(:vote, votable: investment1, voter: user1) + create(:vote, votable: investment1, voter: user2) + create(:vote, votable: investment2, voter: user1) - all_city = create(:budget_heading, group: group_all_city) - carabanchel = create(:budget_heading, group: group_districts) - barajas = create(:budget_heading, group: group_districts) + visit admin_stats_path + click_link "Participatory Budgets" + within("#budget_#{@budget.id}") do + click_link "Supporting phase" + end - 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) + expect(page).to have_content "Participants 2" end - visit admin_stats_path - click_link "Participatory Budgets" - within("#budget_#{budget.id}") do - click_link "Supporting phase" - end + scenario "Number of users that have supported investments projects per geozone" do + budget = create(:budget) - within("#budget_heading_#{all_city.id}") do - expect(page).to have_content all_city.name - expect(page).to have_content 1 - end + group_all_city = create(:budget_group, budget: budget) + group_districts = create(:budget_group, budget: budget) - within("#budget_heading_#{carabanchel.id}") do - expect(page).to have_content carabanchel.name - expect(page).to have_content 2 - end + all_city = create(:budget_heading, group: group_all_city) + carabanchel = create(:budget_heading, group: group_districts) + barajas = create(:budget_heading, group: group_districts) - within("#budget_heading_#{barajas.id}") do - expect(page).to have_content barajas.name - expect(page).to have_content 0 + 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_#{budget.id}") do + click_link "Supporting phase" + end + + 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 "Balloting phase" do + scenario "Number of votes in investment projects" do + budget = create(:budget, :balloting) + ballot_1 = create(:budget_ballot, budget: budget) + ballot_2 = create(:budget_ballot, budget: budget) + + group_1 = create(:budget_group, budget: budget) + heading_1 = create(:budget_heading, group: group_1) + investment_1 = create(:budget_investment, :feasible, :selected, heading: heading_1) + + group_2 = create(:budget_group, budget: budget) + heading_2 = create(:budget_heading, group: group_2) + investment_2 = create(:budget_investment, :feasible, :selected, heading: heading_2) + + create(:budget_ballot_line, ballot: ballot_1, investment: investment_1) + create(:budget_ballot_line, ballot: ballot_1, investment: investment_2) + create(:budget_ballot_line, ballot: ballot_2, investment: investment_2) + + visit admin_stats_path + click_link "Participatory Budgets" + within("#budget_#{budget.id}") do + click_link "Final voting" + end + + expect(page).to have_content "Votes 3" + end + + scenario "Number of users that have voted a investment project" do + user_1 = create(:user, :level_two) + user_2 = create(:user, :level_two) + user_3 = create(:user, :level_two) + + budget = create(:budget, :balloting) + ballot_1 = create(:budget_ballot, budget: budget, user: user_1) + ballot_2 = create(:budget_ballot, budget: budget, user: user_2) + ballot_3 = create(:budget_ballot, budget: budget, user: user_3) + + group = create(:budget_group, budget: budget) + heading = create(:budget_heading, group: group) + investment = create(:budget_investment, :feasible, :selected, heading: heading) + + create(:budget_ballot_line, ballot: ballot_1, investment: investment) + create(:budget_ballot_line, ballot: ballot_2, investment: investment) + + visit admin_stats_path + click_link "Participatory Budgets" + within("#budget_#{budget.id}") do + click_link "Final voting" + end + + expect(page).to have_content "Participants 2" + end + end + end context "graphs" do From f22a97468bc6952969f2c8f52ae44ef74c368d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Wed, 24 May 2017 15:09:02 +0200 Subject: [PATCH 14/15] makes code heading_id agnostic --- spec/features/admin/stats_spec.rb | 39 ++++++++++++++----------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/spec/features/admin/stats_spec.rb b/spec/features/admin/stats_spec.rb index d4117879e..bc5bb3a2c 100644 --- a/spec/features/admin/stats_spec.rb +++ b/spec/features/admin/stats_spec.rb @@ -191,26 +191,28 @@ feature "Stats" do end context "Balloting phase" do + background do + @budget = create(:budget, :balloting) + @group = create(:budget_group, budget: @budget) + @heading = create(:budget_heading, group: @group) + @investment = create(:budget_investment, :feasible, :selected, heading: @heading) + end + scenario "Number of votes in investment projects" do - budget = create(:budget, :balloting) - ballot_1 = create(:budget_ballot, budget: budget) - ballot_2 = create(:budget_ballot, budget: budget) + ballot_1 = create(:budget_ballot, budget: @budget) + ballot_2 = create(:budget_ballot, budget: @budget) - group_1 = create(:budget_group, budget: budget) - heading_1 = create(:budget_heading, group: group_1) - investment_1 = create(:budget_investment, :feasible, :selected, heading: heading_1) - - group_2 = create(:budget_group, budget: budget) + group_2 = create(:budget_group, budget: @budget) heading_2 = create(:budget_heading, group: group_2) investment_2 = create(:budget_investment, :feasible, :selected, heading: heading_2) - create(:budget_ballot_line, ballot: ballot_1, investment: investment_1) + create(:budget_ballot_line, ballot: ballot_1, investment: @investment) create(:budget_ballot_line, ballot: ballot_1, investment: investment_2) create(:budget_ballot_line, ballot: ballot_2, investment: investment_2) visit admin_stats_path click_link "Participatory Budgets" - within("#budget_#{budget.id}") do + within("#budget_#{@budget.id}") do click_link "Final voting" end @@ -222,21 +224,16 @@ feature "Stats" do user_2 = create(:user, :level_two) user_3 = create(:user, :level_two) - budget = create(:budget, :balloting) - ballot_1 = create(:budget_ballot, budget: budget, user: user_1) - ballot_2 = create(:budget_ballot, budget: budget, user: user_2) - ballot_3 = create(:budget_ballot, budget: budget, user: user_3) + ballot_1 = create(:budget_ballot, budget: @budget, user: user_1) + ballot_2 = create(:budget_ballot, budget: @budget, user: user_2) + ballot_3 = create(:budget_ballot, budget: @budget, user: user_3) - group = create(:budget_group, budget: budget) - heading = create(:budget_heading, group: group) - investment = create(:budget_investment, :feasible, :selected, heading: heading) - - create(:budget_ballot_line, ballot: ballot_1, investment: investment) - create(:budget_ballot_line, ballot: ballot_2, investment: investment) + create(:budget_ballot_line, ballot: ballot_1, investment: @investment) + create(:budget_ballot_line, ballot: ballot_2, investment: @investment) visit admin_stats_path click_link "Participatory Budgets" - within("#budget_#{budget.id}") do + within("#budget_#{@budget.id}") do click_link "Final voting" end From d5c7858f6c69d944c5bb3a47bfb1ee4c813b48c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Mon, 2 Oct 2017 16:36:52 +0200 Subject: [PATCH 15/15] Removed officer alert in admin section --- app/views/layouts/admin.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index c08412903..0f9a82856 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -33,7 +33,7 @@
<%= render "layouts/flash" %> - <%= render "layouts/officing_booth" if session[:booth_id].present? %> + <%= render "layouts/officing_booth" if controller.class.parent == Officing && session[:booth_id].present? %> <%= yield %>