Skip to content

Commit df23175

Browse files
committed
better basil stats
1 parent ff6b64c commit df23175

File tree

3 files changed

+34
-31
lines changed

3 files changed

+34
-31
lines changed

app/controllers/basil_controller.rb

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,10 @@ def about
211211
end
212212

213213
def stats
214-
@commissions = BasilCommission.all
214+
@commissions = BasilCommission.all.with_deleted
215215

216216
@queued = BasilCommission.where(completed_at: nil)
217-
@completed = BasilCommission.where.not(completed_at: nil)
217+
@completed = BasilCommission.where.not(completed_at: nil).with_deleted
218218

219219
@average_wait_time = @completed.where('completed_at > ?', 24.hours.ago)
220220
.average(:cached_seconds_taken)
@@ -275,22 +275,25 @@ def stats
275275
'painting2', 'painting3', 'anime'
276276
].flatten.compact.uniq
277277

278-
@total_score_per_style = BasilCommission.where(style: active_styles)
279-
.joins(:basil_feedbacks)
280-
.group(:style)
281-
.sum(:score_adjustment)
282-
.map { |style, average| [style, average.round(1)] }
283-
.sort_by(&:second)
284-
.reverse
285-
@average_score_per_style = BasilCommission.where(style: active_styles)
278+
@total_score_per_style = BasilCommission.with_deleted
279+
.where(style: active_styles)
280+
.joins(:basil_feedbacks)
281+
.group(:style)
282+
.sum(:score_adjustment)
283+
.map { |style, average| [style, average.round(1)] }
284+
.sort_by(&:second)
285+
.reverse
286+
@average_score_per_style = BasilCommission.with_deleted
287+
.where(style: active_styles)
286288
.joins(:basil_feedbacks)
287289
.group(:style)
288290
.average(:score_adjustment)
289291
.map { |style, average| [style, average.round(1)] }
290292
.sort_by(&:second)
291293
.reverse
292294

293-
@average_score_per_page_type = BasilCommission.where.not(completed_at: nil)
295+
@average_score_per_page_type = BasilCommission.with_deleted
296+
.where.not(completed_at: nil)
294297
.joins(:basil_feedbacks)
295298
.group(:entity_type)
296299
.average(:score_adjustment)
@@ -398,17 +401,17 @@ def commission
398401
return
399402
end
400403

401-
current_queue_size = current_user.basil_commissions.where(completed_at: nil).count
402-
if current_queue_size >= BasilService::MAX_JOB_QUEUE_SIZE
403-
redirect_back fallback_location: basil_path, notice: "You can only have #{BasilService::MAX_JOB_QUEUE_SIZE} commissions in progress at a time. Please wait for one to complete before requesting another."
404-
return
405-
end
406-
407404
# Fetch the related content
408405
@content = @current_user_content[commission_params.fetch(:entity_type)]
409406
.find { |c| c.id == commission_params.fetch(:entity_id).to_i }
410407
return raise "Invalid content commission params" if @content.nil?
411408

409+
current_queue_size = current_user.basil_commissions.where(completed_at: nil).where(entity: @content).count
410+
if current_queue_size >= BasilService::MAX_JOB_QUEUE_SIZE
411+
redirect_back fallback_location: basil_path, notice: "You can only have #{BasilService::MAX_JOB_QUEUE_SIZE} commissions per page in progress at a time. Please wait for one to complete before requesting another."
412+
return
413+
end
414+
412415
# Before creating the prompt, do a little config to tweak things to work well :)
413416
labels_to_omit_label_text = [
414417
"Name",

app/views/basil/content.html.erb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,33 +128,33 @@ function commission_basil(style) {
128128
<% end %>
129129
<% end %>
130130

131-
<% if !@can_request_another && @in_progress_commissions.any? %>
132-
<div class="card-panel purple white-text">
133-
Basil is working on your <%= pluralize @in_progress_commissions.count, 'requested commission' %>.
134-
<br /><br />
135-
As soon as he completes one, you'll be able to request another.
136-
</div>
137-
<% end %>
138-
139-
<% if !@can_request_another && @generated_images_count >= BasilService::FREE_IMAGE_LIMIT %>
131+
<% unless current_user.on_premium_plan? %>
140132
<div class="orange lighten-2 card-panel">
141133
<strong>
142134
Image generation is a Premium-only feature, but free accounts can still generate up
143135
to <%= pluralize BasilService::FREE_IMAGE_LIMIT, 'image' %> for free.
144136
</strong>
145137
<br /><br />
146138
You have generated <%= pluralize @generated_images_count, 'image' %>
147-
and have <%= pluralize [0, BasilService::FREE_IMAGE_LIMIT - @generated_images_count].max, 'image' %> remaining:
139+
and have <%= pluralize [0, BasilService::FREE_IMAGE_LIMIT - @generated_images_count].max, 'free image' %> remaining:
148140
<div class="progress white">
149141
<div class="determinate blue" style="width: <%= [@generated_images_count, BasilService::FREE_IMAGE_LIMIT].min %>%"></div>
150142
</div>
151143

152-
<% if @generated_images_count > BasilService::FREE_IMAGE_LIMIT %>
144+
<% if @generated_images_count >= BasilService::FREE_IMAGE_LIMIT %>
153145
<%= link_to 'Click here to manage your billing plan', subscription_path, class: 'blue-text text-darken-4' %>
154146
<% end %>
155147
</div>
156148
<% end %>
157149

150+
<% if !@can_request_another && @in_progress_commissions.any? %>
151+
<div class="card-panel purple white-text">
152+
Basil is working on your <%= pluralize @in_progress_commissions.count, 'requested commission' %>.
153+
<br /><br />
154+
As soon as he completes one, you'll be able to request another.
155+
</div>
156+
<% end %>
157+
158158
<% @commissions.each do |commission| %>
159159
<div>
160160
<% if commission.complete? %>

app/views/basil/index.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@
3939
</div>
4040
<div class="col s12 m8 l9">
4141

42-
<% if true %>
42+
<% unless current_user.on_premium_plan? %>
4343
<div class="orange lighten-2 card-panel">
4444
<strong>
4545
Image generation is a Premium-only feature, but free accounts can still generate up
4646
to <%= pluralize BasilService::FREE_IMAGE_LIMIT, 'image' %> for free.
4747
</strong>
4848
<br /><br />
4949
You have generated <%= pluralize @generated_images_count, 'image' %>
50-
and have <%= pluralize [0, BasilService::FREE_IMAGE_LIMIT - @generated_images_count].max, 'image' %> remaining:
50+
and have <%= pluralize [0, BasilService::FREE_IMAGE_LIMIT - @generated_images_count].max, 'free image' %> remaining:
5151
<div class="progress white">
5252
<div class="determinate blue" style="width: <%= [@generated_images_count, BasilService::FREE_IMAGE_LIMIT].min %>%"></div>
5353
</div>
5454

55-
<% if @generated_images_count > BasilService::FREE_IMAGE_LIMIT %>
55+
<% if @generated_images_count >= BasilService::FREE_IMAGE_LIMIT %>
5656
<%= link_to 'Click here to manage your billing plan', subscription_path, class: 'blue-text text-darken-4' %>
5757
<% end %>
5858
</div>

0 commit comments

Comments
 (0)