From 1afb7abef4d542250d1ccd4635ddc2ccf4a03fab Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Sun, 5 Mar 2023 15:59:57 -0800 Subject: [PATCH] basil stats page improvements --- app/controllers/basil_controller.rb | 15 +++++++++------ app/views/basil/stats.html.erb | 15 ++++++++++----- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/controllers/basil_controller.rb b/app/controllers/basil_controller.rb index 5deebd24..388be1ca 100644 --- a/app/controllers/basil_controller.rb +++ b/app/controllers/basil_controller.rb @@ -1,5 +1,5 @@ class BasilController < ApplicationController - before_action :authenticate_user!, except: [:complete_commission] + before_action :authenticate_user!, except: [:complete_commission, :about, :stats] before_action :require_admin_access, only: [:review], unless: -> { Rails.env.development? } @@ -54,7 +54,7 @@ class BasilController < ApplicationController @average_wait_time = @completed.where('completed_at > ?', 24.hours.ago) .average(:cached_seconds_taken) @seconds_over_time = @completed.where('completed_at > ?', 24.hours.ago) - .group_by { |c| (c.cached_seconds_taken / 60).round } + .group_by { |c| ((c.cached_seconds_taken || 0) / 60).round } .map { |minutes, list| [minutes, list.count] } # Projected date, at our current rate, to reach 1,000,000 images @@ -68,6 +68,7 @@ class BasilController < ApplicationController .order(:score_adjustment) .group(:score_adjustment) .count + total = @feedback_today.values.sum @emoji_counts_today = @feedback_today.map do |score, count| emoji = case score when -2 then "Very Bad :'(" @@ -77,17 +78,19 @@ class BasilController < ApplicationController when 2 then "Very Good :D" when 3 then "Lovely! <3" end - [emoji, count] + [emoji, (count / total.to_f * 100).round(1)] end # Feedback all time - @feedback_all_time = BasilFeedback.order(:score_adjustment) + @feedback_before_today = BasilFeedback.where('updated_at < ?', 24.hours.ago) + .order(:score_adjustment) .group(:score_adjustment) .count days_since_start = (Date.current - BasilFeedback.minimum(:updated_at).to_date) days_since_start = 1 if days_since_start.zero? # no dividing by 0 lol - @emoji_counts_all_time = @feedback_all_time.map do |score, count| + total = @feedback_before_today.values.sum + @emoji_counts_all_time = @feedback_before_today.map do |score, count| emoji = case score when -2 then "Very Bad :'(" when -1 then "Bad :(" @@ -97,7 +100,7 @@ class BasilController < ApplicationController when 3 then "Lovely! <3" end - [emoji, count / days_since_start] + [emoji, (count / total.to_f * 100).round(1)] end active_styles = %w(realistic painting sketch digital anime abstract painting2 horror watercolor) diff --git a/app/views/basil/stats.html.erb b/app/views/basil/stats.html.erb index e3647bc1..318dd76f 100644 --- a/app/views/basil/stats.html.erb +++ b/app/views/basil/stats.html.erb @@ -28,7 +28,8 @@ bar_chart @seconds_over_time, colors: ['#EF6C00'], label: 'Images that took this long', - title: 'Wait times today (in minutes)' %> + title: 'Wait times today (in minutes)' + %>

@@ -36,11 +37,13 @@

<%= number_with_delimiter @commissions.count %>

total images created
-
+
<%= area_chart @commissions.group_by_day(:created_at).map { |date, count| [date.to_date, count] }, colors: ['#9C27B0', '#2196F3'], - title: 'Images created per day' + title: 'Images created per day', + library: { backgroundColor: "#fff" }, + suffix: ' images' %>
@@ -59,7 +62,8 @@ { name: "Today", data: @emoji_counts_today, } ], colors: ['#2196F3', '#C88ED2'], - title: "Quality: #{number_with_delimiter @feedback_all_time.values.sum} #{'image'.pluralize @feedback_all_time.values.sum} rated" + title: "Quality: #{number_with_delimiter @feedback_today.values.sum + @feedback_before_today.values.sum} #{'image'.pluralize @feedback_before_today.values.sum} rated", + suffix: '%' %>
@@ -68,7 +72,8 @@ colors: ['#B71C1C', '#D95151', '#757575' '#1B5E20', '#236428', '#43A047', '#2196F3'], legend: 'right', donut: true, - title: "Today's quality ratings" + title: "Today's quality ratings", + suffix: '%' %>