@@ -2,6 +2,22 @@ class Admin::StatsController < Admin::BaseController
|
|||||||
|
|
||||||
def show
|
def show
|
||||||
@event_types = Ahoy::Event.group(:name).count
|
@event_types = Ahoy::Event.group(:name).count
|
||||||
|
|
||||||
|
@visits = Visit.count
|
||||||
|
@debates = Debate.with_hidden.count
|
||||||
|
@proposals = Proposal.with_hidden.count
|
||||||
|
@comments = Comment.with_hidden.count
|
||||||
|
|
||||||
|
@debate_votes = Vote.where(votable_type: 'Debate').count
|
||||||
|
@proposal_votes = Vote.where(votable_type: 'Proposal').count
|
||||||
|
@comment_votes = Vote.where(votable_type: 'Comment').count
|
||||||
|
@votes = Vote.count
|
||||||
|
|
||||||
|
@user_level_two = User.with_hidden.level_two_verified.count
|
||||||
|
@user_level_three = User.with_hidden.level_three_verified.count
|
||||||
|
@verified_users = User.with_hidden.level_two_or_three_verified.count
|
||||||
|
@unverified_users = User.with_hidden.unverified.count
|
||||||
|
@users = User.with_hidden.count
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ module Verification
|
|||||||
scope :level_three_verified, -> { where.not(verified_at: nil) }
|
scope :level_three_verified, -> { where.not(verified_at: nil) }
|
||||||
scope :level_two_verified, -> { where("users.confirmed_phone IS NOT NULL AND users.residence_verified_at IS NOT NULL") }
|
scope :level_two_verified, -> { where("users.confirmed_phone IS NOT NULL AND users.residence_verified_at IS NOT NULL") }
|
||||||
scope :level_two_or_three_verified, -> { where("users.verified_at IS NOT NULL OR (users.confirmed_phone IS NOT NULL AND users.residence_verified_at IS NOT NULL)") }
|
scope :level_two_or_three_verified, -> { where("users.verified_at IS NOT NULL OR (users.confirmed_phone IS NOT NULL AND users.residence_verified_at IS NOT NULL)") }
|
||||||
scope :unverified, -> { where("users.verified_at IS NULL AND (users.confirmed_phone IS NULL OR users.residence_verified_at IS NOT NULL)") }
|
scope :unverified, -> { where("users.verified_at IS NULL AND (users.residence_verified_at IS NULL OR users.confirmed_phone IS NULL)") }
|
||||||
end
|
end
|
||||||
|
|
||||||
def verification_email_sent?
|
def verification_email_sent?
|
||||||
|
|||||||
@@ -4,15 +4,32 @@
|
|||||||
<div class="stats row-full">
|
<div class="stats row-full">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<h2>Stats</h2>
|
<h1><%= t "admin.stats.show.stats_title" %></h1>
|
||||||
|
|
||||||
|
<h2><%= t "admin.stats.show.summary_title" %></h2>
|
||||||
|
<ul>
|
||||||
|
<li><strong><%= t "admin.stats.show.summary.visits" %>: <%= @visits %></strong></li>
|
||||||
|
<li><%= t "admin.stats.show.summary.debates" %>: <%= @debates %></li>
|
||||||
|
<li><%= t "admin.stats.show.summary.proposals" %>: <%= @proposals %></li>
|
||||||
|
<li><%= t "admin.stats.show.summary.comments" %>: <%= @comments %></li>
|
||||||
|
<li><%= t "admin.stats.show.summary.debate_votes" %>: <%= @debate_votes %></li>
|
||||||
|
<li><strong><%= t "admin.stats.show.summary.proposal_votes" %>: <%= @proposal_votes %></strong></li>
|
||||||
|
<li><%= t "admin.stats.show.summary.comment_votes" %>: <%= @comment_votes %></li>
|
||||||
|
<li><%= t "admin.stats.show.summary.votes" %>: <%= @votes %></li>
|
||||||
|
<li><%= t "admin.stats.show.summary.user_level_two" %>: <%= @user_level_two %></li>
|
||||||
|
<li><%= t "admin.stats.show.summary.user_level_three" %>: <%= @user_level_three %></li>
|
||||||
|
<li><strong><%= t "admin.stats.show.summary.verified_users" %>: <%= @verified_users %></strong></li>
|
||||||
|
<li><strong><%= t "admin.stats.show.summary.unverified_users" %>: <%= @unverified_users %><strong></li>
|
||||||
|
<li><strong><%= t "admin.stats.show.summary.users" %>: <%= @users %></strong></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
<div class="small-12 medium-6 column">
|
<div class="small-12 medium-6 column">
|
||||||
<h3>Visits</h3>
|
<h3><%= t "admin.stats.show.combined_title" %></h3>
|
||||||
<%= visits_chart_tag id: "visits" %>
|
<%= visits_chart_tag id: "visits" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-12 medium-6 column">
|
<div class="small-12 medium-6 column">
|
||||||
<h3>Combined</h3>
|
<h3><%= t "admin.stats.show.visits_title" %></h3>
|
||||||
<%= events_chart_tag @event_types.keys, id: 'combined' %>
|
<%= events_chart_tag @event_types.keys, id: 'combined' %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -147,3 +147,23 @@ en:
|
|||||||
hide: Hidden
|
hide: Hidden
|
||||||
restore: Restored
|
restore: Restored
|
||||||
block: Blocked
|
block: Blocked
|
||||||
|
stats:
|
||||||
|
show:
|
||||||
|
summary_title: Summary
|
||||||
|
stats_title: Stats
|
||||||
|
visits_title: Visits
|
||||||
|
combined_title: Combined
|
||||||
|
summary:
|
||||||
|
visits: Visits
|
||||||
|
debates: Debates
|
||||||
|
proposals: Proposals
|
||||||
|
comments: Comments
|
||||||
|
debate_votes: Debate votes
|
||||||
|
proposal_votes: Proposal votes
|
||||||
|
comment_votes: Comment votes
|
||||||
|
votes: Total votes
|
||||||
|
user_level_three: Level three users
|
||||||
|
user_level_two: Level two users
|
||||||
|
unverified_users: Unverified users
|
||||||
|
verified_users: Verified users
|
||||||
|
users: Total users
|
||||||
@@ -147,3 +147,23 @@ es:
|
|||||||
hide: Ocultado
|
hide: Ocultado
|
||||||
restore: Restaurado
|
restore: Restaurado
|
||||||
block: Bloqueado
|
block: Bloqueado
|
||||||
|
stats:
|
||||||
|
show:
|
||||||
|
summary_title: Resumen
|
||||||
|
stats_title: Estadísticas
|
||||||
|
visits_title: Visitas
|
||||||
|
combined_title: Combinado
|
||||||
|
summary:
|
||||||
|
visits: Visitas
|
||||||
|
debates: Debates
|
||||||
|
proposals: Propuestas
|
||||||
|
comments: Comentarios
|
||||||
|
debate_votes: Votes en debates
|
||||||
|
proposal_votes: Votos en propuestas
|
||||||
|
comment_votes: Votso en comentarios
|
||||||
|
votes: Votos
|
||||||
|
user_level_three: Usuarios de nivel tres
|
||||||
|
user_level_two: Usuarios de nivel dos
|
||||||
|
unverified_users: Usuarios sin verificar
|
||||||
|
verified_users: Usuarios verificados
|
||||||
|
users: Usuarios
|
||||||
|
|||||||
@@ -2,17 +2,73 @@ require 'rails_helper'
|
|||||||
|
|
||||||
feature 'Stats' do
|
feature 'Stats' do
|
||||||
|
|
||||||
scenario 'Level 2 user' do
|
background do
|
||||||
admin = create(:administrator)
|
admin = create(:administrator)
|
||||||
user = create(:user)
|
login_as(admin.user)
|
||||||
login_as(user)
|
end
|
||||||
|
|
||||||
|
context 'Summary' do
|
||||||
|
|
||||||
|
scenario 'General' do
|
||||||
|
create(:debate)
|
||||||
|
2.times { create(:proposal) }
|
||||||
|
3.times { create(:comment, commentable: Debate.first) }
|
||||||
|
4.times { create(:visit) }
|
||||||
|
|
||||||
|
visit admin_stats_path
|
||||||
|
|
||||||
|
expect(page).to have_content "Debates: 1"
|
||||||
|
expect(page).to have_content "Proposals: 2"
|
||||||
|
expect(page).to have_content "Comments: 3"
|
||||||
|
expect(page).to have_content "Visits: 4"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Votes' do
|
||||||
|
debate = create(:debate)
|
||||||
|
create(:vote, votable: debate)
|
||||||
|
|
||||||
|
proposal = create(:proposal)
|
||||||
|
2.times { create(:vote, votable: proposal) }
|
||||||
|
|
||||||
|
comment = create(:comment)
|
||||||
|
3.times { create(:vote, votable: comment) }
|
||||||
|
|
||||||
|
visit admin_stats_path
|
||||||
|
|
||||||
|
expect(page).to have_content "Debate votes: 1"
|
||||||
|
expect(page).to have_content "Proposal votes: 2"
|
||||||
|
expect(page).to have_content "Comment votes: 3"
|
||||||
|
expect(page).to have_content "Total votes: 6"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Users' do
|
||||||
|
Administrator.destroy_all
|
||||||
|
User.all.map(&:really_destroy!)
|
||||||
|
|
||||||
|
1.times { create(:user, :level_three) }
|
||||||
|
2.times { create(:user, :level_two) }
|
||||||
|
3.times { create(:user) }
|
||||||
|
|
||||||
|
admin = create(:administrator)
|
||||||
|
login_as(admin.user)
|
||||||
|
|
||||||
|
visit admin_stats_path
|
||||||
|
|
||||||
|
expect(page).to have_content "Level three users: 1"
|
||||||
|
expect(page).to have_content "Level two users: 2"
|
||||||
|
expect(page).to have_content "Verified users: 3"
|
||||||
|
expect(page).to have_content "Unverified users: 4"
|
||||||
|
expect(page).to have_content "Total users: 7"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Level 2 user' do
|
||||||
visit account_path
|
visit account_path
|
||||||
click_link 'Verify my account'
|
click_link 'Verify my account'
|
||||||
verify_residence
|
verify_residence
|
||||||
confirm_phone
|
confirm_phone
|
||||||
|
|
||||||
login_as(admin.user)
|
|
||||||
visit admin_stats_path
|
visit admin_stats_path
|
||||||
|
|
||||||
expect(page).to have_content "Level 2 User (1)"
|
expect(page).to have_content "Level 2 User (1)"
|
||||||
|
|||||||
Reference in New Issue
Block a user