Module: LlmCostTracker::Storage::ActiveRecordPeriods
- Defined in:
- lib/llm_cost_tracker/storage/active_record_periods.rb
Constant Summary collapse
- PERIODS =
{ monthly: "month", daily: "day" }.freeze
Class Method Summary collapse
Class Method Details
.bucket(period, time) ⇒ Object
26 27 28 |
# File 'lib/llm_cost_tracker/storage/active_record_periods.rb', line 26 def bucket(period, time) range_start(period, time).to_date end |
.range_start(period, time) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/llm_cost_tracker/storage/active_record_periods.rb', line 17 def range_start(period, time) utc_time = time.to_time.utc case period when :monthly then utc_time.beginning_of_month when :daily then utc_time.beginning_of_day end end |
.valid_keys(periods) ⇒ Object
13 14 15 |
# File 'lib/llm_cost_tracker/storage/active_record_periods.rb', line 13 def valid_keys(periods) periods.map(&:to_sym).select { |period| PERIODS.key?(period) } end |