Class: Ask::Monitoring::Metrics::Cost

Inherits:
Base
  • Object
show all
Defined in:
lib/ask/monitoring/metrics/cost.rb

Overview

Computes cost-over-time chart data from Ask::Event records.

Groups events by time period and sums the cost column. Requires groupdate for time-series grouping.

Instance Attribute Summary

Attributes inherited from Base

#scope

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Ask::Monitoring::Metrics::Base

Instance Method Details

#as_chart_dataArray<Hash>

Returns Chart data points [Time, value: Float].

Returns:

  • (Array<Hash>)

    Chart data points [Time, value: Float]



10
11
12
13
14
15
# File 'lib/ask/monitoring/metrics/cost.rb', line 10

def as_chart_data
  scope
    .group_by_period(:hour, :created_at)
    .sum(:cost)
    .map { |date, value| { date: date, value: value.to_f } }
end