Class: AgentC::Costs::Data
- Inherits:
-
Object
- Object
- AgentC::Costs::Data
- Defined in:
- lib/agent_c/costs/data.rb
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#run ⇒ Object
readonly
Returns the value of attribute run.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(project:, run:) ⇒ Data
constructor
A new instance of Data.
Constructor Details
#initialize(project:, run:) ⇒ Data
Returns a new instance of Data.
8 9 10 11 |
# File 'lib/agent_c/costs/data.rb', line 8 def initialize(project:, run:) @project = project @run = run end |
Instance Attribute Details
#project ⇒ Object (readonly)
Returns the value of attribute project.
6 7 8 |
# File 'lib/agent_c/costs/data.rb', line 6 def project @project end |
#run ⇒ Object (readonly)
Returns the value of attribute run.
6 7 8 |
# File 'lib/agent_c/costs/data.rb', line 6 def run @run end |
Class Method Details
.calculate(agent_store:, project:, run_id: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/agent_c/costs/data.rb', line 13 def self.calculate(agent_store:, project:, run_id: nil) calculator = Report::Calculator.new # Calculate project-level cost = agent_store. .joins(:chat) .where(chats: { project: project }) .includes(:model, :chat) project_stats = calculator.calculate() project_cost = project_stats[:total_cost] # Calculate run-level cost run_cost = 0.0 if run_id = agent_store. .joins(:chat) .where(chats: { project: project, run_id: run_id }) .includes(:model, :chat) run_stats = calculator.calculate() run_cost = run_stats[:total_cost] end new(project: project_cost, run: run_cost) end |