From 1d847bf6b8fb8b74e0395c43b3631201782b8062 Mon Sep 17 00:00:00 2001 From: Leonardo Crauss Daronco Date: Wed, 28 Feb 2018 11:58:25 -0300 Subject: [PATCH] Review for #958, optimize queries and improve the design a bit Removed all "for"s from the module Statistics, they would make things very slow for large amounts of data. Now all stats are filtered directly in the database with SQL. Also reviewed the views and improved the design a little, made it look more like the other pages. --- .../app/manage/statistics.js.coffee | 23 +-- .../stylesheets/app/manage/statistics.scss | 35 ++--- app/controllers/manage_controller.rb | 5 +- app/views/manage/_statistics_list.html.haml | 132 ++++++++++++------ app/views/manage/statistics.html.haml | 31 ++-- app/views/manage/statistics_filter.html.haml | 16 +-- config/locales/en/mconf.yml | 31 ++-- config/locales/pt-br/mconf.yml | 31 ++-- lib/mconf/statistics_module.rb | 62 ++------ spec/controllers/manage_controller_spec.rb | 14 +- .../manage/admin_manages_statistics_spec.rb | 2 +- spec/lib/mconf/statistics_module_spec.rb | 22 +-- 12 files changed, 193 insertions(+), 211 deletions(-) diff --git a/app/assets/javascripts/app/manage/statistics.js.coffee b/app/assets/javascripts/app/manage/statistics.js.coffee index 5dfedb02b..9f2aebdb5 100644 --- a/app/assets/javascripts/app/manage/statistics.js.coffee +++ b/app/assets/javascripts/app/manage/statistics.js.coffee @@ -2,25 +2,10 @@ $ -> if isOnPage 'manage', 'statistics' uri = window.location.href - if uri.indexOf("?") < 0 - $('.starts-at-wrapper .btn.all').addClass("active") - $('.starts-at-wrapper .btn-group .btn.pick').removeClass("active") - else - $('.starts-at-wrapper .btn.all').removeClass("active") - $('.starts-at-wrapper .btn-group .btn.pick').addClass("active") - mconf.Resources.addToBind -> mconf.StatisticsFilter.bind() - filterByDate() - $('.starts-at-wrapper .btn-group .btn').on 'click', -> - filterByDate(this) - - $('.starts-at-wrapper .btn.all').on 'click', -> - window.location.replace(uri.substring(0, uri.indexOf("?"))) - -filterByDate = (el) -> - if el - selected = $(el).data('attr-value') - else - selected = $('.starts-at-wrapper .btn.all').data('attr-value') + # only kept here because this link is inside a .btn-group that disables the default + # click in the button, so we have to do the redirect it manually + $('#statistics-filters .btn.all').on 'click', -> + window.location.replace($(this).attr('href')) diff --git a/app/assets/stylesheets/app/manage/statistics.scss b/app/assets/stylesheets/app/manage/statistics.scss index 6b3708e99..5ae557910 100644 --- a/app/assets/stylesheets/app/manage/statistics.scss +++ b/app/assets/stylesheets/app/manage/statistics.scss @@ -3,18 +3,6 @@ body.manage.statistics { - .title { - font-size: 20px; - color: $m-green-logo; - font-weight: bold; - margin: 8px 0; - } - - .text { - font-size: 15px; - margin: 0 15px; - } - .page-tools-menu { padding-bottom: 5px; margin-bottom: 10px; @@ -33,8 +21,9 @@ body.manage.statistics { } } - .starts-at-wrapper { + #statistics-filters { margin-bottom: 16px; + @include mconf-clearfix; .csv { padding-top: 0; @@ -45,8 +34,7 @@ body.manage.statistics { .btn-group { white-space: nowrap; - display: table-cell; - width: 1%; + float: left; > .btn { float: none; @@ -56,13 +44,20 @@ body.manage.statistics { } } } + } - .form-group { - display: table-cell; - width: 100%; - padding-left: 8px; + #statistics-list { + .table { + margin-bottom: 30px; + + tbody td:first-child { + width: 40%; + } + tbody td:last-child { + width: 40%; + } } - } + }; .open-modal { text-decoration: none; diff --git a/app/controllers/manage_controller.rb b/app/controllers/manage_controller.rb index a99c74a7a..34551bb8f 100644 --- a/app/controllers/manage_controller.rb +++ b/app/controllers/manage_controller.rb @@ -97,9 +97,10 @@ def check_statistics_params if params[:statistics].present? from = params[:statistics][:starts_on_time] to = params[:statistics][:ends_on_time] + date_format = I18n.t('_other.datetimepicker.datepick_rails') - from.present? ? @from_date = Date.strptime(from, '%m/%d/%Y') : @from_date = Time.at(0).utc - to.present? ? @to_date = Date.strptime(to, '%m/%d/%Y') : @to_date = Time.now.utc + @from_date = from.present? ? Date.strptime(from, date_format) : Time.at(0).utc + @to_date = to.present? ? Date.strptime(to, date_format) : Time.now.utc else @from_date = Time.at(0).utc @to_date = Time.now.utc diff --git a/app/views/manage/_statistics_list.html.haml b/app/views/manage/_statistics_list.html.haml index 9a180e036..8ee1b4f50 100644 --- a/app/views/manage/_statistics_list.html.haml +++ b/app/views/manage/_statistics_list.html.haml @@ -1,52 +1,92 @@ -# locals: -.list-container.list-tablefied - .resource-filter-with-text +%div.table-wrapper - .resource-filter-without-text - .title= t('.users.title') - .text= t('.users.all', value: @statistics[:users][:all]) - .text= t('.users.approved', value: @statistics[:users][:approved]) - .text= t('.users.not_approved', value: @statistics[:users][:not_approved]) - .text= t('.users.disabled', value: @statistics[:users][:disabled]) + %table.table + %thead + %tr + %th{ colspan: 2 }= t('.users.title') + %tbody + %tr + %td= t('.users.all') + %td= @statistics[:users][:count] + %tr + %td= t('.users.approved') + %td= @statistics[:users][:approved] + %tr + %td= t('.users.not_approved') + %td= @statistics[:users][:not_approved] + %tr + %td= t('.users.disabled') + %td= @statistics[:users][:disabled] - -#.list-container.list-tablefied - .title= t('.spaces.title') - .text= t('.spaces.all', value: @statistics[:spaces][:all]) - .text= t('.spaces.private', value: @statistics[:spaces][:private]) - .text= t('.spaces.public', value: @statistics[:spaces][:public]) - .text= t('.spaces.disabled', value: @statistics[:spaces][:disabled]) + %table.table + %thead + %tr + %th{ colspan: 2 }= t('.spaces.title') + %tbody + %tr + %td= t('.spaces.all') + %td= @statistics[:spaces][:count] + %tr + %td= t('.spaces.private') + %td= @statistics[:spaces][:private] + %tr + %td= t('.spaces.public') + %td= @statistics[:spaces][:public] + %tr + %td= t('.spaces.disabled') + %td= @statistics[:spaces][:disabled] - -#.list-container.list-tablefied - .title= t('.meetings.title') - .text= t('.meetings.all', value: @statistics[:meetings][:all]) + %table.table + %thead + %tr + %th{ colspan: 2 }= t('.meetings.title') + %tbody + %tr + %td= t('.meetings.all') + %td= @statistics[:meetings][:count] + %tr + %td= t('.meetings.total') + %td + - total = @statistics[:meetings][:total_duration] + - if total.zero? + = total + - else + = distance_of_time_in_words_to_now(Time.now + total, include_seconds: false) + %tr + %td= t('.meetings.average') + %td + - average = @statistics[:meetings][:average_duration] + - if average.zero? + = average + - else + = distance_of_time_in_words_to_now(Time.now + average, include_seconds: false) - - total = @statistics[:meetings][:total] - - if total.zero? - .text= t('.meetings.total', value: total) - - else - .text= t('.meetings.total', value: distance_of_time_in_words_to_now(Time.now + total, include_seconds: false)) - - - average = @statistics[:meetings][:average] - - if average.zero? - .text= t('.meetings.average', value: average) - - else - .text= t('.meetings.average', value: distance_of_time_in_words_to_now(Time.now + average, include_seconds: false)) - - -#.list-container.list-tablefied - .title= t('.recordings.title') - .text= t('.recordings.all', value: @statistics[:recordings][:all]) - - - total = @statistics[:recordings][:total] - - if total.zero? - .text= t('.recordings.total', value: total) - - else - .text= t('.recordings.total', value: distance_of_time_in_words_to_now(Time.now + total, include_seconds: false)) - - - average = @statistics[:recordings][:average] - - if average.zero? - .text= t('.recordings.average', value: average) - - else - .text= t('.recordings.average', value: distance_of_time_in_words_to_now(Time.now + average, include_seconds: false)) - - .text= t('.recordings.size', value: human_file_size(@statistics[:recordings][:size])) + %table.table + %thead + %tr + %th{ colspan: 2 }= t('.recordings.title') + %tbody + %tr + %td= t('.recordings.all') + %td= @statistics[:recordings][:count] + %tr + %td= t('.recordings.total') + %td + - total = @statistics[:recordings][:total_duration] + - if total.zero? + = total + - else + = distance_of_time_in_words_to_now(Time.now + total, include_seconds: false) + %tr + %td= t('.recordings.average') + %td + - average = @statistics[:recordings][:average_duration] + - if average.zero? + = average + - else + = distance_of_time_in_words_to_now(Time.now + average, include_seconds: false) + %tr + %td= t('.recordings.size') + %td= human_file_size(@statistics[:recordings][:size]) diff --git a/app/views/manage/statistics.html.haml b/app/views/manage/statistics.html.haml index 5ce3d8fe2..38da0765a 100644 --- a/app/views/manage/statistics.html.haml +++ b/app/views/manage/statistics.html.haml @@ -1,26 +1,19 @@ #manage - .modal-header + #statistics-filters = simple_form_for :statistics, url: manage_statistics_path, html: { class: 'single-column' } do |f| - .modal-body - .row - .col-xs-12.col-sm-9 - .starts-at-wrapper - .csv - - starts = params[:statistics].present? ? params[:statistics][:starts_on_time] : nil - - ends = params[:statistics].present? ? params[:statistics][:ends_on_time] : nil - = link_to t('.csv'), manage_statistics_csv_path(format: :csv, statistics: { starts_on_time: starts, ends_on_time: ends }), class: 'btn btn-primary' - .btn-group{ 'data-toggle': "buttons" } + .csv + - starts = params[:statistics].present? ? params[:statistics][:starts_on_time] : nil + - ends = params[:statistics].present? ? params[:statistics][:ends_on_time] : nil + = link_to t('.csv'), manage_statistics_csv_path(format: :csv, statistics: { starts_on_time: starts, ends_on_time: ends }), class: 'btn btn-primary' - %label.btn.btn-default.all{ 'data-attr-value': '0' } - %input{ type: 'radio' } - = t('.all') + .btn-group{ 'data-toggle': "buttons" } - %label.btn.btn-default.pick{ 'data-attr-value': '1' } - %input{ type: 'radio' } - = link_to manage_statistics_filter_path, class: "open-modal tooltipped", title: t('.date') do - = icon_later - = t('.date') + = link_to manage_statistics_path, class: "btn btn-default all #{'active' unless params[:statistics].present?}" do + = t('.all') + = link_to manage_statistics_filter_path, class: "btn btn-default pick open-modal #{'active' if params[:statistics].present?}" do + = icon_date + = t('.date') -#statistics-list +#statistics-list{ 'data-filtered-by-date': params[:statistics].present?.to_s } = render partial: 'statistics_list' diff --git a/app/views/manage/statistics_filter.html.haml b/app/views/manage/statistics_filter.html.haml index 9e29bcfcd..48fe1f7b2 100644 --- a/app/views/manage/statistics_filter.html.haml +++ b/app/views/manage/statistics_filter.html.haml @@ -6,15 +6,13 @@ = t('.title') = simple_form_for :statistics, url: manage_statistics_path, method: "get", html: { class: 'single-column' } do |f| .modal-body - .row - .col-xs-12.col-sm-9 - .starts-at-wrapper - - tz = user_timezone_abbreviation(current_user) - - lang = locale_for_datetime_picker - = f.label (t('.from')), required: false - .start= f.input :starts_on_time, as: :datetime_picker, label: false, required: false, input_html: { 'data-format': t('_other.datetimepicker.datepick'), 'data-timezone': tz, 'data-language': lang, 'data-minview': 2 } - = f.label (t('.to')), required: false - .end= f.input :ends_on_time, as: :datetime_picker, label: false, required: false, input_html: { 'data-format': t('_other.datetimepicker.datepick'), 'data-timezone': tz, 'data-language': lang, 'data-minview': 2 } + .starts-at-wrapper + - tz = user_timezone_abbreviation(current_user) + - lang = locale_for_datetime_picker + = f.label (t('.from')), required: false + .start= f.input :starts_on_time, as: :datetime_picker, label: false, required: false, input_html: { 'data-format': t('_other.datetimepicker.datepick'), 'data-timezone': tz, 'data-language': lang, 'data-minview': 2 } + = f.label (t('.to')), required: false + .end= f.input :ends_on_time, as: :datetime_picker, label: false, required: false, input_html: { 'data-format': t('_other.datetimepicker.datepick'), 'data-timezone': tz, 'data-language': lang, 'data-minview': 2 } .modal-footer = f.button :wrapped, t('_other.send'), disabled: true, class: "btn btn-primary", cancel_modal: true diff --git a/config/locales/en/mconf.yml b/config/locales/en/mconf.yml index bfe3a9f71..3a996371f 100755 --- a/config/locales/en/mconf.yml +++ b/config/locales/en/mconf.yml @@ -70,6 +70,7 @@ en: confirm: Ok datetimepicker: datepick: "mm/dd/yyyy" + datepick_rails: "%m/%d/%Y" format: "mm/dd/yyyy hh:ii Z" format_rails: "%m/%d/%Y %H:%M" decline: "Decline" @@ -1064,27 +1065,27 @@ en: statistics_list: users: title: "Users Stats" - all: "All users: %{value}" - approved: "Approved users: %{value}" - not_approved: "Not approved users: %{value}" - disabled: "Disabled users: %{value}" + all: "All users" + approved: "Approved users" + not_approved: "Not approved users" + disabled: "Disabled users" spaces: title: "Spaces Stats" - all: "All spaces: %{value}" - private: "Private spaces: %{value}" - public: "Public spaces: %{value}" - disabled: "Disabled spaces: %{value}" + all: "All spaces" + private: "Private spaces" + public: "Public spaces" + disabled: "Disabled spaces" meetings: title: "Meetings Stats" - all: "All meetings: %{value}" - total: "Total meetings duration: %{value}" - average: "Average meetings duration: %{value}" + all: "All meetings" + total: "Total meetings duration" + average: "Average meetings duration" recordings: title: "Recordings Stats" - all: "All recordings: %{value}" - total: "Total recordings duration: %{value}" - average: "Average recordings duration: %{value}" - size: "Total size: %{value}" + all: "All recordings" + total: "Total recordings duration" + average: "Average recordings duration" + size: "Total size" user_item: allow_record: "Give the user permission to record conferences" auth_using: "using" diff --git a/config/locales/pt-br/mconf.yml b/config/locales/pt-br/mconf.yml index ce6f41e98..c50790ad9 100644 --- a/config/locales/pt-br/mconf.yml +++ b/config/locales/pt-br/mconf.yml @@ -69,6 +69,7 @@ pt-br: create: "Criar" datetimepicker: datepick: "dd/mm/yyyy" + datepick_rails: "%d/%m/%Y" format: "dd/mm/yyyy hh:ii Z" format_rails: "%d/%m/%Y %H:%M" decline: "Negar" @@ -1071,27 +1072,27 @@ pt-br: statistics_list: users: title: "Estatísticas de usuários" - all: "Total de usuários: %{value}" - approved: "Usuários aprovados: %{value}" - not_approved: "Usuários não aprovados: %{value}" - disabled: "Usuários desabilitados: %{value}" + all: "Total de usuários" + approved: "Usuários aprovados" + not_approved: "Usuários não aprovados" + disabled: "Usuários desabilitados" spaces: title: "Estatísticas de comunidades" - all: "Total de comunidades: %{value}" - private: "Comunidadades privadas: %{value}" - public: "Comunidades públicas: %{value}" - disabled: "Comunidades desabilitadas: %{value}" + all: "Total de comunidades" + private: "Comunidadades privadas" + public: "Comunidades públicas" + disabled: "Comunidades desabilitadas" meetings: title: "Estatísticas de reuniões" - all: "Total de reuniões: %{value}" - total: "Duração de todas as reuniões: %{value}" - average: "Média de duração por reunião: %{value}" + all: "Total de reuniões" + total: "Duração de todas as reuniões" + average: "Média de duração por reunião" recordings: title: "Estatísticas de gravações" - all: "Total de gravações: %{value}" - total: "Duração de todas as gravações: %{value}" - average: "Média de duração por gravação: %{value}" - size: "Tamanho total de todas as gravações: %{value}" + all: "Total de gravações" + total: "Duração de todas as gravações" + average: "Média de duração por gravação" + size: "Tamanho total de todas as gravações" user_item: allow_record: "Conceder permissão de gravação" auth_using: "usando" diff --git a/lib/mconf/statistics_module.rb b/lib/mconf/statistics_module.rb index bea775686..f2d504914 100644 --- a/lib/mconf/statistics_module.rb +++ b/lib/mconf/statistics_module.rb @@ -7,7 +7,7 @@ def self.total_users(from, to) users = User.with_disabled.where("created_at >= ? AND created_at <= ?", from, to) #total users - result[:all] = users.count + result[:count] = users.count # approved users result[:approved] = users.where(approved: true).count @@ -27,7 +27,7 @@ def self.total_spaces(from, to) spaces = Space.with_disabled.where("created_at >= ? AND created_at <= ?", from, to) #total_spaces - result[:all] = spaces.all.count + result[:count] = spaces.all.count # private spaces result[:private] = spaces.where(public: false).count @@ -42,64 +42,32 @@ def self.total_spaces(from, to) end def self.total_meetings(from, to) - result = {} - meetings = BigbluebuttonMeeting.where("created_at >= ? AND created_at <= ?", from, to) - total = 0 - duration = 0 - average = 0 - count = 0 - - meetings.find_each do |m| - # total duration - unless m.finish_time.blank? - duration = m.finish_time - m.create_time - end - total = total + duration - count = count + 1 - end - - # duration average - result[:all] = count - if count.zero? - result[:average] = 0 + result = {} + result[:count] = meetings.count + result[:total_duration] = meetings.sum('finish_time - create_time') + if result[:count].zero? || result[:count].nil? + result[:average_duration] = 0 else - result[:average] = total / count + result[:average_duration] = result[:total_duration] / result[:count] end - result[:total] = total result end def self.total_recordings(from, to) - result = {} - recordings = BigbluebuttonRecording.where("created_at >= ? AND created_at <= ?", from, to) - total = 0 - duration = 0 - average = 0 - count = 0 - size = 0 - - recordings.find_each do |r| - # total duration - duration = r.end_time - r.start_time - total = total + duration - size = size + r.size - count = count + 1 - end - - # duration average - result[:all] = count - result[:size] = size - if count.zero? - result[:average] = 0 + result = {} + result[:count] = recordings.count + result[:size] = recordings.sum(:size) + result[:total_duration] = recordings.sum('end_time - start_time') + if result[:count].zero? || result[:count].nil? + result[:average_duration] = 0 else - result[:average] = total / count + result[:average_duration] = result[:total_duration] / result[:count] end - result[:total] = total result end diff --git a/spec/controllers/manage_controller_spec.rb b/spec/controllers/manage_controller_spec.rb index eb32fa39f..b429cb5aa 100644 --- a/spec/controllers/manage_controller_spec.rb +++ b/spec/controllers/manage_controller_spec.rb @@ -920,7 +920,7 @@ let(:start_date) { (Time.now.utc).strftime("%m/%d/%Y").to_s } let(:end_date) { (Time.now.utc).strftime("%m/%d/%Y").to_s } let(:params) { { statistics: { starts_on_time: start_date, ends_on_time: end_date } } } - let(:data) { {:users=>{:all=>3, :approved=>3, :not_approved=>0, :disabled=>0}, :spaces=>{:all=>1, :private=>1, :public=>0, :disabled=>0}, :meetings=>{:all=>1, :average=>0, :total=>0}, :recordings=>{:all=>1, :size=>0, :average=>5, :total=>5}} } + let(:data) { {:users=>{:count=>3, :approved=>3, :not_approved=>0, :disabled=>0}, :spaces=>{:count=>1, :private=>1, :public=>0, :disabled=>0}, :meetings=>{:count=>1, :total_duration=>0, :average_duration=>0}, :recordings=>{:count=>1, :size=>0, :total_duration=>5, :average_duration=>5}} } it { assigns(:statistics).should eql(data) } end @@ -929,7 +929,7 @@ let(:start_date) { (Time.now.utc - 5.month).strftime("%m/%d/%Y").to_s } let(:end_date) { (Time.now.utc).strftime("%m/%d/%Y").to_s } let(:params) { { statistics: { starts_on_time: start_date, ends_on_time: end_date } } } - let(:data) { {:users=>{:all=>4, :approved=>3, :not_approved=>1, :disabled=>0}, :spaces=>{:all=>1, :private=>1, :public=>0, :disabled=>0}, :meetings=>{:all=>1, :average=>0, :total=>0}, :recordings=>{:all=>1, :size=>0, :average=>5, :total=>5}} } + let(:data) { {:users=>{:count=>4, :approved=>3, :not_approved=>1, :disabled=>0}, :spaces=>{:count=>1, :private=>1, :public=>0, :disabled=>0}, :meetings=>{:count=>1, :total_duration=>0, :average_duration=>0}, :recordings=>{:count=>1, :size=>0, :total_duration=>5, :average_duration=>5}} } it { assigns(:statistics).should eql(data) } end @@ -938,7 +938,7 @@ let(:start_date) { (Time.now.utc - 6.year).strftime("%m/%d/%Y").to_s } let(:end_date) { (Time.now.utc).strftime("%m/%d/%Y").to_s } let(:params) { { statistics: { starts_on_time: start_date, ends_on_time: end_date } } } - let(:data) { {:users=>{:all=>5, :approved=>4, :not_approved=>1, :disabled=>1}, :spaces=>{:all=>1, :private=>1, :public=>0, :disabled=>0}, :meetings=>{:all=>1, :average=>0, :total=>0}, :recordings=>{:all=>1, :size=>0, :average=>5, :total=>5}} } + let(:data) { {:users=>{:count=>5, :approved=>4, :not_approved=>1, :disabled=>1}, :spaces=>{:count=>1, :private=>1, :public=>0, :disabled=>0}, :meetings=>{:count=>1, :total_duration=>0, :average_duration=>0}, :recordings=>{:count=>1, :size=>0, :total_duration=>5, :average_duration=>5}} } it { assigns(:statistics).should eql(data) } end @@ -947,7 +947,7 @@ let(:start_date) { (Time.now.utc - 6.year).strftime("%m/%d/%Y").to_s } let(:end_date) { (Time.now.utc - 5.month).strftime("%m/%d/%Y").to_s } let(:params) { { statistics: { starts_on_time: start_date, ends_on_time: end_date } } } - let(:data) { {:users=>{:all=>2, :approved=>1, :not_approved=>1, :disabled=>1}, :spaces=>{:all=>0, :private=>0, :public=>0, :disabled=>0}, :meetings=>{:all=>0, :average=>0, :total=>0}, :recordings=>{:all=>0, :size=>0, :average=>0, :total=>0}} } + let(:data) { {:users=>{:count=>2, :approved=>1, :not_approved=>1, :disabled=>1}, :spaces=>{:count=>0, :private=>0, :public=>0, :disabled=>0}, :meetings=>{:count=>0, :total_duration=>0, :average_duration=>0}, :recordings=>{:count=>0, :size=>0, :total_duration=>0, :average_duration=>0}} } it { assigns(:statistics).should eql(data) } end @@ -956,7 +956,7 @@ let(:start_date) { (Time.now.utc - 9.year).strftime("%m/%d/%Y").to_s } let(:end_date) { (Time.now.utc - 7.year).strftime("%m/%d/%Y").to_s } let(:params) { { statistics: { starts_on_time: start_date, ends_on_time: end_date } } } - let(:data) { {:users=>{:all=>0, :approved=>0, :not_approved=>0, :disabled=>0}, :spaces=>{:all=>0, :private=>0, :public=>0, :disabled=>0}, :meetings=>{:all=>0, :average=>0, :total=>0}, :recordings=>{:all=>0, :size=>0, :average=>0, :total=>0}} } + let(:data) { {:users=>{:count=>0, :approved=>0, :not_approved=>0, :disabled=>0}, :spaces=>{:count=>0, :private=>0, :public=>0, :disabled=>0}, :meetings=>{:count=>0, :total_duration=>0, :average_duration=>0}, :recordings=>{:count=>0, :size=>0, :total_duration=>0, :average_duration=>0}} } it { assigns(:statistics).should eql(data) } end @@ -964,7 +964,7 @@ context "without params: result approved_user, not_approved_user, disabled_user, admin and superuser (all)" do let(:params) { {} } - let(:data) { {:users=>{:all=>5, :approved=>4, :not_approved=>1, :disabled=>1}, :spaces=>{:all=>1, :private=>1, :public=>0, :disabled=>0}, :meetings=>{:all=>1, :average=>0, :total=>0}, :recordings=>{:all=>1, :size=>0, :average=>5, :total=>5}} } + let(:data) { {:users=>{:count=>5, :approved=>4, :not_approved=>1, :disabled=>1}, :spaces=>{:count=>1, :private=>1, :public=>0, :disabled=>0}, :meetings=>{:count=>1, :total_duration=>0, :average_duration=>0}, :recordings=>{:count=>1, :size=>0, :total_duration=>5, :average_duration=>5}} } it { assigns(:statistics).should eql(data) } end @@ -986,7 +986,7 @@ end context ".csv format: download .csv" do - let(:data) {"users.all,users.approved,users.not_approved,users.disabled,spaces.all,spaces.private,spaces.public,spaces.disabled,meetings.all,meetings.average,meetings.total,recordings.all,recordings.size,recordings.average,recordings.total\n2,2,0,0,0,0,0,0,0,0,0,0,0,0,0\n"} + let(:data) {"users.count,users.approved,users.not_approved,users.disabled,spaces.count,spaces.private,spaces.public,spaces.disabled,meetings.count,meetings.total_duration,meetings.average_duration,recordings.count,recordings.size,recordings.total_duration,recordings.average_duration\n2,2,0,0,0,0,0,0,0,0,0,0,0,0,0\n"} let(:from_date) { Time.at(0).utc } let(:to_date) { Time.now.utc } diff --git a/spec/features/manage/admin_manages_statistics_spec.rb b/spec/features/manage/admin_manages_statistics_spec.rb index 9918c875f..3e9434970 100644 --- a/spec/features/manage/admin_manages_statistics_spec.rb +++ b/spec/features/manage/admin_manages_statistics_spec.rb @@ -19,7 +19,7 @@ context " testing buttons" do it { should have_css '.btn-default', :count => 3 } it { should have_css '.btn-primary', :count => 1 } - it { should have_css '.icon-mconf-later', :count => 1 } + it { should have_css '.icon-date', :count => 1 } end context "testing content" do diff --git a/spec/lib/mconf/statistics_module_spec.rb b/spec/lib/mconf/statistics_module_spec.rb index d2047c85b..3aba1185e 100644 --- a/spec/lib/mconf/statistics_module_spec.rb +++ b/spec/lib/mconf/statistics_module_spec.rb @@ -18,8 +18,8 @@ subject { Mconf::StatisticsModule } describe "total_users" do - let(:data) { {:all=>2, :approved=>2, :not_approved=>0, :disabled=>0} } - let(:nil_data) { {:all=>0, :approved=>0, :not_approved=>0, :disabled=>0} } + let(:data) { {:count=>2, :approved=>2, :not_approved=>0, :disabled=>0} } + let(:nil_data) { {:count=>0, :approved=>0, :not_approved=>0, :disabled=>0} } it "function with arguments returns 'user' and with nil returns 0" do subject.total_users(start_date, end_date).should eql(data) @@ -28,8 +28,8 @@ end describe "total_spaces" do - let(:data) { {:all=>1, :private=>1, :public=>0, :disabled=>0} } - let(:nil_data) { {:all=>0, :private=>0, :public=>0, :disabled=>0} } + let(:data) { {:count=>1, :private=>1, :public=>0, :disabled=>0} } + let(:nil_data) { {:count=>0, :private=>0, :public=>0, :disabled=>0} } it "function with arguments returns 'space' and with nil returns 0" do subject.total_spaces(start_date, end_date).should eql(data) @@ -38,8 +38,8 @@ end describe "total_meetings" do - let(:data) { {:all=>1, :average=>0, :total=>0} } - let(:nil_data) { {:all=>0, :average=>0, :total=>0} } + let(:data) { {:count=>1, :average_duration=>0, :total_duration=>0} } + let(:nil_data) { {:count=>0, :average_duration=>0, :total_duration=>0} } it "function with arguments returns 'meeting' and with nil returns 0" do subject.total_meetings(start_date, end_date).should eql(data) @@ -48,8 +48,8 @@ end describe "total_recordings" do - let(:data) { {:all=>1, :size=>0, :average=>5, :total=>5} } - let(:nil_data) { {:all=>0, :size=>0, :average=>0, :total=>0} } + let(:data) { {:count=>1, :size=>0, :average_duration=>5, :total_duration=>5} } + let(:nil_data) { {:count=>0, :size=>0, :average_duration=>0, :total_duration=>0} } it "function with arguments returns 'recording' and with nil returns 0" do subject.total_recordings(start_date, end_date).should eql(data) @@ -58,8 +58,8 @@ end describe "generate" do - let(:data) { {:users=>{:all=>2, :approved=>2, :not_approved=>0, :disabled=>0}, :spaces=>{:all=>1, :private=>1, :public=>0, :disabled=>0}, :meetings=>{:all=>1, :average=>0, :total=>0}, :recordings=>{:all=>1, :size=>0, :average=>5, :total=>5}}} - let(:nil_data) { {:users=>{:all=>0, :approved=>0, :not_approved=>0, :disabled=>0}, :spaces=>{:all=>0, :private=>0, :public=>0, :disabled=>0}, :meetings=>{:all=>0, :average=>0, :total=>0}, :recordings=>{:all=>0, :size=>0, :average=>0, :total=>0}} } + let(:data) { {:users=>{:count=>2, :approved=>2, :not_approved=>0, :disabled=>0}, :spaces=>{:count=>1, :private=>1, :public=>0, :disabled=>0}, :meetings=>{:count=>1, :total_duration=>0, :average_duration=>0}, :recordings=>{:count=>1, :size=>0, :total_duration=>5, :average_duration=>5}}} + let(:nil_data) { {:users=>{:count=>0, :approved=>0, :not_approved=>0, :disabled=>0}, :spaces=>{:count=>0, :private=>0, :public=>0, :disabled=>0}, :meetings=>{:count=>0, :average_duration=>0, :total_duration=>0}, :recordings=>{:count=>0, :size=>0, :average_duration=>0, :total_duration=>0}} } it "function with arguments returns 'user, space, meeting and recording' (all data) and with nil returns nothing" do subject.generate(start_date, end_date).should eql(data) @@ -68,7 +68,7 @@ end describe "generate_csv" do - let(:data) {"users.all,users.approved,users.not_approved,users.disabled,spaces.all,spaces.private,spaces.public,spaces.disabled,meetings.all,meetings.average,meetings.total,recordings.all,recordings.size,recordings.average,recordings.total\n2,2,0,0,1,1,0,0,1,0,0,1,0,5,5\n"} + let(:data) {"users.count,users.approved,users.not_approved,users.disabled,spaces.count,spaces.private,spaces.public,spaces.disabled,meetings.count,meetings.total_duration,meetings.average_duration,recordings.count,recordings.size,recordings.total_duration,recordings.average_duration\n2,2,0,0,1,1,0,0,1,0,0,1,0,5,5\n"} it "function with arguments returns file .csv and with nil returns nil" do subject.generate_csv(start_date, end_date).should eql(data)