DEV: moves each report in its own file (#7277)

DEV: moves each report in its own file (#7277)

diff --git a/app/models/report.rb b/app/models/report.rb
index 9a5726e..c866d73 100644
--- a/app/models/report.rb
+++ b/app/models/report.rb
@@ -214,48 +214,6 @@ class Report
     report
   end
 
-  def self.report_consolidated_page_views(report)
-    filters = %w[
-      page_view_logged_in
-      page_view_anon
-      page_view_crawler
-    ]
-
-    report.modes = [:stacked_chart]
-
-    tertiary = ColorScheme.hex_for_name('tertiary') || '0088cc'
-    danger = ColorScheme.hex_for_name('danger') || 'e45735'
-
-    requests = filters.map do |filter|
-      color = report.rgba_color(tertiary)
-
-      if filter == "page_view_anon"
-        color = report.rgba_color(tertiary, 0.5)
-      end
-
-      if filter == "page_view_crawler"
-        color = report.rgba_color(danger, 0.75)
-      end
-
-      {
-        req: filter,
-        label: I18n.t("reports.consolidated_page_views.xaxis.#{filter}"),
-        color: color,
-        data: ApplicationRequest.where(req_type: ApplicationRequest.req_types[filter])
-      }
-    end
-
-    requests.each do |request|
-      request[:data] = request[:data].where('date >= ? AND date <= ?', report.start_date, report.end_date)
-        .order(date: :asc)
-        .group(:date)
-        .sum(:count)
-        .map { |date, count| { x: date, y: count } }
-    end
-
-    report.data = requests
-  end
-
   def self.req_report(report, filter = nil)
     data =
       if filter == :page_view_total
@@ -287,198 +245,6 @@ class Report
       ).sum(:count)
   end
 
-  def self.report_visits(report)
-    report.group_filtering = true
-    report.icon = 'user'
-
-    basic_report_about report, UserVisit, :by_day, report.start_date, report.end_date, report.group_id
-    add_counts report, UserVisit, 'visited_at'
-
-    report.prev30Days = UserVisit.where("visited_at >= ? and visited_at < ?", report.start_date - 30.days, report.start_date).count
-  end
-
-  def self.report_mobile_visits(report)
-    basic_report_about report, UserVisit, :mobile_by_day, report.start_date, report.end_date
-    report.total      = UserVisit.where(mobile: true).count
-    report.prev30Days = UserVisit.where(mobile: true).where("visited_at >= ? and visited_at < ?", report.start_date - 30.days, report.start_date).count
-  end
-
-  def self.report_signups(report)
-    report.group_filtering = true
-
-    report.icon = 'user-plus'
-
-    if report.group_id
-      basic_report_about report, User.real, :count_by_signup_date, report.start_date, report.end_date, report.group_id
-      add_counts report, User.real, 'users.created_at'
-    else
-      report_about report, User.real, :count_by_signup_date
-    end
-
-    # add_prev_data report, User.real, :count_by_signup_date, report.prev_start_date, report.prev_end_date
-  end
-
-  def self.report_new_contributors(report)
-    report.data = []
-
-    data = User.real.count_by_first_post(report.start_date, report.end_date)
-
-    if report.facets.include?(:prev30Days)
-      prev30DaysData = User.real.count_by_first_post(report.start_date - 30.days, report.start_date)
-      report.prev30Days = prev30DaysData.sum { |k, v| v }
-    end
-
-    if report.facets.include?(:total)
-      report.total = User.real.count_by_first_post
-    end
-
-    if report.facets.include?(:prev_period)
-      prev_period_data = User.real.count_by_first_post(report.prev_start_date, report.prev_end_date)
-      report.prev_period = prev_period_data.sum { |k, v| v }
-      # report.prev_data = prev_period_data.map { |k, v| { x: k, y: v } }
-    end
-
-    data.each do |key, value|
-      report.data << { x: key, y: value }
-    end
-  end
-
-  def self.report_daily_engaged_users(report)
-    report.average = true
-
-    report.data = []
-
-    data = UserAction.count_daily_engaged_users(report.start_date, report.end_date)
-
-    if report.facets.include?(:prev30Days)
-      prev30DaysData = UserAction.count_daily_engaged_users(report.start_date - 30.days, report.start_date)
-      report.prev30Days = prev30DaysData.sum { |k, v| v }
-    end
-
-    if report.facets.include?(:total)
-      report.total = UserAction.count_daily_engaged_users
-    end
-
-    if report.facets.include?(:prev_period)
-      prev_data = UserAction.count_daily_engaged_users(report.prev_start_date, report.prev_end_date)
-
-      prev = prev_data.sum { |k, v| v }
-      if prev > 0
-        prev = prev / ((report.end_date - report.start_date) / 1.day)
-      end
-      report.prev_period = prev
-    end
-
-    data.each do |key, value|
-      report.data << { x: key, y: value }
-    end
-  end
-
-  def self.report_dau_by_mau(report)
-    report.labels = [
-      {
-        type: :date,
-        property: :x,
-        title: I18n.t("reports.default.labels.day")
-      },
-      {
-        type: :percent,
-        property: :y,
-        title: I18n.t("reports.default.labels.percent")
-      },
-    ]
-
-    report.average = true
-    report.percent = true
-
-    data_points = UserVisit.count_by_active_users(report.start_date, report.end_date)
-
-    report.data = []
-
-    compute_dau_by_mau = Proc.new { |data_point|
-      if data_point["mau"] == 0
-        0
-      else
-        ((data_point["dau"].to_f / data_point["mau"].to_f) * 100).ceil(2)
-      end
-    }
-
-    dau_avg = Proc.new { |start_date, end_date|
-      data_points = UserVisit.count_by_active_users(start_date, end_date)
-      if !data_points.empty?
-        sum = data_points.sum { |data_point| compute_dau_by_mau.call(data_point) }
-        (sum.to_f / data_points.count.to_f).ceil(2)
-      end
-    }
-
-    data_points.each do |data_point|
-      report.data << { x: data_point["date"], y: compute_dau_by_mau.call(data_point) }
-    end
-
-    if report.facets.include?(:prev_period)
-      report.prev_period = dau_avg.call(report.prev_start_date, report.prev_end_date)
-    end
-
-    if report.facets.include?(:prev30Days)
-      report.prev30Days = dau_avg.call(report.start_date - 30.days, report.start_date)
-    end
-  end
-
-  def self.report_profile_views(report)
-    report.group_filtering = true
-    start_date = report.start_date
-    end_date = report.end_date
-    basic_report_about report, UserProfileView, :profile_views_by_day, start_date, end_date, report.group_id
-
-    report.total = UserProfile.sum(:views)
-    report.prev30Days = UserProfileView.where("viewed_at >= ? AND viewed_at < ?", start_date - 30.days, start_date + 1).count
-  end
-
-  def self.report_topics(report)
-    report.category_filtering = true
-    basic_report_about report, Topic, :listable_count_per_day, report.start_date, report.end_date, report.category_id
-    countable = Topic.listable_topics
-    countable = countable.in_category_and_subcategories(report.category_id) if report.category_id
-    add_counts report, countable, 'topics.created_at'
-  end
-
-  def self.report_posts(report)
-    report.modes = [:table, :chart]
-    report.category_filtering = true
-    basic_report_about report, Post, :public_posts_count_per_day, report.start_date, report.end_date, report.category_id
-    countable = Post.public_posts.where(post_type: Post.types[:regular])
-    if report.category_id
-      countable = countable.joins(:topic).merge(Topic.in_category_and_subcategories(report.category_id))
-    end
-    add_counts report, countable, 'posts.created_at'
-  end
-
-  def self.report_time_to_first_response(report)
-    report.category_filtering = true
-    report.icon = 'reply'
-    report.higher_is_better = false
-    report.data = []
-    Topic.time_to_first_response_per_day(report.start_date, report.end_date, category_id: report.category_id).each do |r|
-      report.data << { x: r["date"], y: r["hours"].to_f.round(2) }
-    end
-    report.total = Topic.time_to_first_response_total(category_id: report.category_id)
-    report.prev30Days = Topic.time_to_first_response_total(start_date: report.start_date - 30.days, end_date: report.start_date, category_id: report.category_id)
-  end
-
-  def self.report_topics_with_no_response(report)

[... diff too long, it was truncated ...]

GitHub sha: 961fb2c7

1 Like