about summary refs log tree commit diff
path: root/app/lib/admin/metrics/measure/tag_accounts_measure.rb
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-11-25 23:49:17 +0100
committerClaire <claire.github-309c@sitedethib.com>2021-11-25 23:50:35 +0100
commit443ec4f8ba3d9f78acc1b89e2b29ad364cd5e956 (patch)
tree6c83fa75cc4f699503546be0a68409fffa11080f /app/lib/admin/metrics/measure/tag_accounts_measure.rb
parent8c2fe2a846dd14914f7faa4bf71be21058249a93 (diff)
parentb1fd6d44901a13450d22884b02eb6e9ae4fc1248 (diff)
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts:
- `app/views/admin/tags/index.html.haml`:
  Removed upstream while it had changes in glitch-soc to accomodate for the
  theming system.

Additional changes to accomodate for the theming system:
- `app/views/admin/trends/links/preview_card_providers/index.html.haml`
- `app/views/admin/trends/links/index.html.haml`
- `app/views/admin/trends/tags/index.html.haml`
- `app/views/admin/tags/show.html.haml`
Diffstat (limited to 'app/lib/admin/metrics/measure/tag_accounts_measure.rb')
-rw-r--r--app/lib/admin/metrics/measure/tag_accounts_measure.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/app/lib/admin/metrics/measure/tag_accounts_measure.rb b/app/lib/admin/metrics/measure/tag_accounts_measure.rb
new file mode 100644
index 000000000..ef773081b
--- /dev/null
+++ b/app/lib/admin/metrics/measure/tag_accounts_measure.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+class Admin::Metrics::Measure::TagAccountsMeasure < Admin::Metrics::Measure::BaseMeasure
+  def self.with_params?
+    true
+  end
+
+  def key
+    'tag_accounts'
+  end
+
+  def total
+    tag.history.aggregate(time_period).accounts
+  end
+
+  def previous_total
+    tag.history.aggregate(previous_time_period).accounts
+  end
+
+  def data
+    time_period.map { |date| { date: date.to_time(:utc).iso8601, value: tag.history.get(date).accounts.to_s } }
+  end
+
+  protected
+
+  def tag
+    @tag ||= Tag.find(params[:id])
+  end
+
+  def time_period
+    (@start_at.to_date..@end_at.to_date)
+  end
+
+  def previous_time_period
+    ((@start_at.to_date - length_of_period)..(@end_at.to_date - length_of_period))
+  end
+
+  def params
+    @params.permit(:id)
+  end
+end