Class: Metric
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Metric
- Includes:
- RequiredUniqueName, Toggleable
- Defined in:
- app/models/metric.rb
Overview
Metric for component
Attributes:
biovision_component_id [BiovisionComponent]
created_at [DateTime]
default_period [integer]
incremental [boolean]
previous_value [integer]
show_on_dashboard [boolean]
start_with_zero [boolean]
name [string]
updated_at [DateTime]
value [integer]
Constant Summary collapse
- NAME_LIMIT =
255
- PERIOD_RANGE =
(1..366).freeze
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.[](name) ⇒ Object
29 30 31 |
# File 'app/models/metric.rb', line 29 def self.[](name) find_by(name: name) end |
Instance Method Details
#<<(input) ⇒ Object
38 39 40 41 42 |
# File 'app/models/metric.rb', line 38 def <<(input) metric_values.create(time: Time.now, quantity: input) update(value: incremental? ? quantity : input, previous_value: value) end |
#quantity ⇒ Object
33 34 35 |
# File 'app/models/metric.rb', line 33 def quantity metric_values.sum(:quantity) end |
#values(period = 7) ⇒ Object
45 46 47 48 49 50 51 |
# File 'app/models/metric.rb', line 45 def values(period = 7) current_value = 0 metric_values.since(period.days.ago).ordered_by_time.map do |v| current_value = incremental? ? current_value + v.quantity : v.quantity [v.time.strftime('%d.%m.%Y %H:%M'), current_value] end.to_h end |