basil stats page improvements

This commit is contained in:
Andrew Brown 2023-03-05 15:59:57 -08:00
parent 4ff897795a
commit 1afb7abef4
2 changed files with 19 additions and 11 deletions

View File

@ -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)

View File

@ -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)'
%>
<br /><br />
</div>
@ -36,11 +37,13 @@
<h1 class="center purple-text" style="margin-bottom: 0; margin-top: 1.6em"><%= number_with_delimiter @commissions.count %></h1>
<div class="center grey-text text-darken-3"><strong>total images created</strong></div>
</div>
<div class="col s12 m8 l9">
<div class="col s12 m8 l9 grey lighten-3">
<%=
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'
%>
</div>
@ -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: '%'
%>
</div>
<div class="col s12 m4 l5">
@ -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: '%'
%>
<br /><br /><br />
</div>