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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -9,20 +9,18 @@
|
||||
<% if mode == :table %>
|
||||
<table class="striped autofit" width="100%">
|
||||
<thead>
|
||||
<th>Date</th>
|
||||
|
||||
<% 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 %>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% results.each do |row| %>
|
||||
<% dataframe.each_row do |row| %>
|
||||
<tr>
|
||||
<td><%= row["date"].to_date %></td>
|
||||
|
||||
<% columns.each do |column| %>
|
||||
<td><%= row[column.to_s] %></td>
|
||||
<% dataframe.types.keys.each do |column| %>
|
||||
<td>
|
||||
<%= row[column] %>
|
||||
</td>
|
||||
<% end %>
|
||||
<tr>
|
||||
<% end %>
|
||||
@@ -32,8 +30,8 @@
|
||||
<div class="line-chart" style="width: 100%; height: 80vh;"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var data = <%= raw results.to_a.to_json %>;
|
||||
var columns = <%= raw columns.to_json %>;
|
||||
var data = <%= raw dataframe.each_row.map(&:values).to_json %>;
|
||||
var columns = <%= raw dataframe.types.keys.without("date").to_json %>;
|
||||
var chart = new Danbooru.TimeSeriesComponent({
|
||||
container: $(".line-chart").get(0),
|
||||
data: data,
|
||||
|
||||
Reference in New Issue
Block a user