From c9adfa65a073e3071c3083fc36397a222b1aa2dc Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 5 Feb 2015 11:18:11 +1100 Subject: [PATCH] FEATURE: dashboard stats for application traffic --- .../javascripts/admin/templates/dashboard.hbs | 21 ++++++++++ app/models/admin_dashboard_data.rb | 6 ++- app/models/report.rb | 38 +++++++++++++++++++ config/locales/client.en.yml | 2 + config/locales/server.en.yml | 16 ++++++++ 5 files changed, 82 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/admin/templates/dashboard.hbs b/app/assets/javascripts/admin/templates/dashboard.hbs index 7c9aecd5f61..706af40595d 100644 --- a/app/assets/javascripts/admin/templates/dashboard.hbs +++ b/app/assets/javascripts/admin/templates/dashboard.hbs @@ -62,6 +62,27 @@ +
+ + + + + + + + + + + + {{#unless loading}} + {{ render 'admin_report_counts' anon_reqs }} + {{ render 'admin_report_counts' logged_in_reqs }} + {{ render 'admin_report_counts' crawler_reqs}} + {{ render 'admin_report_counts' total_reqs}} + {{/unless}} +
{{i18n 'admin.dashboard.traffic_short'}}{{i18n 'admin.dashboard.reports.today'}}{{i18n 'admin.dashboard.reports.yesterday'}}{{i18n 'admin.dashboard.reports.last_7_days'}}{{i18n 'admin.dashboard.reports.last_30_days'}}{{i18n 'admin.dashboard.reports.all'}}
+
+
diff --git a/app/models/admin_dashboard_data.rb b/app/models/admin_dashboard_data.rb index ccb1db1d69d..8da27511536 100644 --- a/app/models/admin_dashboard_data.rb +++ b/app/models/admin_dashboard_data.rb @@ -16,7 +16,11 @@ class AdminDashboardData 'system_private_messages', 'moderator_warning_private_messages', 'notify_moderators_private_messages', - 'notify_user_private_messages' + 'notify_user_private_messages', + 'anon_reqs', + 'crawler_reqs', + 'logged_in_reqs', + 'total_reqs' ] def problems diff --git a/app/models/report.rb b/app/models/report.rb index 3cabe43497f..7ce3e7fcbb7 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -45,6 +45,44 @@ class Report report end + def self.req_report(report, filter=nil) + data = ApplicationRequest.all + + if mapped = ApplicationRequest.req_types[filter] + data = data.where(req_type: mapped) + end + + filtered_results = data.where('date >= ? AND date <= ?', report.start_date.to_date, report.end_date.to_date) + + + report.data = [] + filtered_results.group(:date) + .sum(:count) + .each do |date, count| + + report.data << {x: date, y: count} + end + + report.total = data.sum(:count) + report.prev30Days = filtered_results.sum(:count) + end + + def self.report_anon_reqs(report) + req_report(report, :anon) + end + + def self.report_crawler_reqs(report) + req_report(report, :crawler) + end + + def self.report_logged_in_reqs(report) + req_report(report, :logged_in) + end + + def self.report_total_reqs(report) + req_report(report) + end + def self.report_visits(report) basic_report_about report, UserVisit, :by_day, report.start_date, report.end_date end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 9f6238d1355..158d0081aec 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1535,6 +1535,8 @@ en: space_free: "{{size}} free" uploads: "uploads" backups: "backups" + traffic_short: "Application Traffic" + traffic: "Application web requests" reports: today: "Today" diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index a75be34e8d1..7d8575f5f2d 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -588,6 +588,22 @@ en: title: "Top Referred Topics" xaxis: "Topic" num_clicks: "Clicks" + anon_reqs: + title: "Anonymous" + xaxis: "Day" + yaxis: "Anonymous application requests" + logged_in_reqs: + title: "Logged In" + xaxis: "Day" + yaxis: "Logged In application requests" + crawler_reqs: + title: "Crawler" + xaxis: "Day" + yaxis: "Crawler application requests" + total_reqs: + title: "Total" + xaxis: "Day" + yaxis: "Total application requests" dashboard: rails_env_warning: "Your server is running in %{env} mode."