From f73d2e39562d3a3781a68c5ff0a6ec86f045e3d7 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 22 Oct 2022 03:17:30 -0500 Subject: [PATCH] reports: add ability to group reports by column. Add ability to group reports by various columns. For example, you can see the posts by the top 10 uploaders over time, or posts grouped by rating over time. --- Gemfile | 1 + Gemfile.lock | 4 + app/components/time_series_component.rb | 8 +- .../time_series_component.html.erb | 20 ++-- app/controllers/reports_controller.rb | 62 ++++++++---- .../src/javascripts/time_series_component.js | 9 +- app/logical/concerns/aggregatable.rb | 96 ++++++++++++------- app/logical/danbooru/data_frame.rb | 47 +++++++++ app/views/reports/show.html.erb | 3 +- 9 files changed, 176 insertions(+), 74 deletions(-) create mode 100644 app/logical/danbooru/data_frame.rb diff --git a/Gemfile b/Gemfile index 867f5f803..d97d929a0 100644 --- a/Gemfile +++ b/Gemfile @@ -58,6 +58,7 @@ gem "debug" gem "ffaker" gem "composite_primary_keys" gem "resolv" +gem "rover-df" group :development do gem 'rubocop', require: false diff --git a/Gemfile.lock b/Gemfile.lock index cfdd274b9..8cb65a690 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -315,6 +315,7 @@ GEM nokogiri (1.13.9) mini_portile2 (~> 2.8.0) racc (~> 1.4) + numo-narray (0.9.2.1) oauth2 (2.0.9) faraday (>= 0.17.3, < 3.0) jwt (>= 1.0, < 3.0) @@ -407,6 +408,8 @@ GEM reverse_markdown (2.1.1) nokogiri rexml (3.2.5) + rover-df (0.3.4) + numo-narray (>= 0.9.1.9) rubocop (1.36.0) json (~> 2.3) parallel (~> 1.10) @@ -582,6 +585,7 @@ DEPENDENCIES redis resolv responders + rover-df rubocop rubocop-rails ruby-vips diff --git a/app/components/time_series_component.rb b/app/components/time_series_component.rb index 651ad6129..064117a1e 100644 --- a/app/components/time_series_component.rb +++ b/app/components/time_series_component.rb @@ -3,11 +3,11 @@ class TimeSeriesComponent < ApplicationComponent delegate :current_page_path, :search_params, to: :helpers - attr_reader :results, :columns, :mode + attr_reader :dataframe, :group, :mode - def initialize(results, columns, mode: :table) - @results = results - @columns = columns + def initialize(dataframe, group: nil, mode: :table) + @dataframe = dataframe + @group = group @mode = mode.to_sym end end diff --git a/app/components/time_series_component/time_series_component.html.erb b/app/components/time_series_component/time_series_component.html.erb index e0c10f399..447d5c0aa 100644 --- a/app/components/time_series_component/time_series_component.html.erb +++ b/app/components/time_series_component/time_series_component.html.erb @@ -9,20 +9,18 @@ <% if mode == :table %> - - - <% columns.each do |column| %> - <%= tag.th(column.to_s.capitalize, class: ("col-expand" if column == columns.last)) %> + <% dataframe.types.keys.each do |column| %> + <%= tag.th(column.to_s.titleize, class: ("col-expand" if column == dataframe.types.keys.last)) %> <% end %> - <% results.each do |row| %> + <% dataframe.each_row do |row| %> - - - <% columns.each do |column| %> - + <% dataframe.types.keys.each do |column| %> + <% end %> <% end %> @@ -32,8 +30,8 @@
Date
<%= row["date"].to_date %><%= row[column.to_s] %> + <%= row[column] %> +