Class: Raif::Admin::Stats::TasksController

Inherits:
ApplicationController show all
Defined in:
app/controllers/raif/admin/stats/tasks_controller.rb

Instance Method Summary collapse

Methods inherited from Raif::ApplicationController

#raif_current_user

Instance Method Details

#indexObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/raif/admin/stats/tasks_controller.rb', line 7

def index
  @selected_period = params[:period] || "day"
  @time_range = get_time_range(@selected_period)

  @task_count = Raif::Task.where(created_at: @time_range).count

  @task_stats_by_type = Raif::Task.joins(:raif_model_completion)
    .where(created_at: @time_range)
    .group(:type)
    .pluck(
      "raif_tasks.type",
      "COUNT(raif_tasks.id)",
      "SUM(raif_model_completions.prompt_token_cost)",
      "SUM(raif_model_completions.output_token_cost)",
      "SUM(raif_model_completions.total_cost)"
    ).map do |type, count, input_cost, output_cost, total_cost|
      Raif::Admin::TaskStat.new(type, count, input_cost, output_cost, total_cost)
    end
end