Class: LlmCostTracker::Dashboard::TimeSeries
- Inherits:
-
Object
- Object
- LlmCostTracker::Dashboard::TimeSeries
- Defined in:
- app/services/llm_cost_tracker/dashboard/time_series.rb
Constant Summary collapse
- DEFAULT_DAYS =
30
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(scope:, from:, to:) ⇒ TimeSeries
constructor
A new instance of TimeSeries.
- #points ⇒ Object
Constructor Details
#initialize(scope:, from:, to:) ⇒ TimeSeries
Returns a new instance of TimeSeries.
16 17 18 19 20 |
# File 'app/services/llm_cost_tracker/dashboard/time_series.rb', line 16 def initialize(scope:, from:, to:) @scope = scope @to = to.to_date @from = from ? from.to_date : (@to - (DEFAULT_DAYS - 1)) end |
Class Method Details
.call(scope: LlmCostTracker::LlmApiCall.all, from: nil, to: Date.current) ⇒ Object
11 12 13 |
# File 'app/services/llm_cost_tracker/dashboard/time_series.rb', line 11 def call(scope: LlmCostTracker::LlmApiCall.all, from: nil, to: Date.current) new(scope: scope, from: from, to: to).points end |
Instance Method Details
#points ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/services/llm_cost_tracker/dashboard/time_series.rb', line 22 def points costs = scoped_costs (from..to).map do |date| label = date.iso8601 { label: label, cost: costs.fetch(label, 0.0) } end end |