diff --git a/Gemfile b/Gemfile index a1c2c94e0..54f32939d 100644 --- a/Gemfile +++ b/Gemfile @@ -71,8 +71,7 @@ gem 'redis-search' gem 'syslog-logger' gem "recaptcha", :require => "recaptcha/rails" -gem 'puma' -gem 'request-log-analyzer' +gem "chartkick" gem 'usagewatch' # Gems used only for assets and not required diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f28f15a67..2f41f71d8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,5 +1,5 @@ module ApplicationHelper - + Time.zone = ActiveSupport::TimeZone[+8.hours] FLASH_NOTICE_KEYS = [:error, :notice, :warning] @@ -223,25 +223,49 @@ module ApplicationHelper end def display_visitors(options={}) - Impression.where(options).and(:referrer.ne => nil).distinct(:session_hash).count + Impression.where(options).count end def display_visitors_today - display_visitors(created_at: {'$gte' => Date.today.beginning_of_day, '$lte' => Date.today.end_of_day}) + display_visitors(created_at: {'$gte' => Time.now.beginning_of_day, '$lte' => Time.now}) end def display_visitors_this_week - display_visitors(created_at: {'$gte' => Date.today.beginning_of_week, '$lte' => Date.today.end_of_week}) + display_visitors(created_at: {'$gte' => Time.now-7.days, '$lte' => Time.now}) end def display_visitors_this_month - display_visitors(created_at: {'$gte' => Date.today.beginning_of_month, '$lte' => Date.today.end_of_month}) + display_visitors(created_at: {'$gte' => Time.now-30.days, '$lte' => Time.now}) end def display_visitors_this_year - display_visitors(created_at: {'$gte' => Date.today.beginning_of_year, '$lte' => Date.today.end_of_year}) + display_visitors(created_at: {'$gte' => Time.now-365.days, '$lte' => Time.now}) end + def get_month_traffic + result = [] + (0..30).each do |i| + visits = Impression.where( created_at: { + '$gte' => Time.now.beginning_of_day-i.days, + '$lte' => Time.now.end_of_day-i.days} + ).count + result.push([ Time.now.beginning_of_day-i.days, visits]) + end + [:name=> t(:visitors_count),:data=>result] + end + + # def get_today_traffic + # result = [] + # (0..30).each do |i| + # the_day = i.day.ago + # visits = Impression.where( created_at: {'$gte' => the_day.beginning_of_day, '$lte' => the_day.end_of_day}).count + # # result.push([ the_day.to_time.to_i, visits]) + # result.push([ the_day.strftime("%m %d"), visits]) + # # result.push({'x'=> i, 'y'=> visits}) + # end + # result + # end + def display_date_time(object) object.strftime("%Y-%m-%d %H:%M") end diff --git a/app/views/admin/dashboards/_server_loading.erb b/app/views/admin/dashboards/_server_loading.erb index 6ff3fa003..c2122cc35 100644 --- a/app/views/admin/dashboards/_server_loading.erb +++ b/app/views/admin/dashboards/_server_loading.erb @@ -2,399 +2,45 @@