Class: Presenters::QcThresholdPresenter::Threshold
- Inherits:
-
Object
- Object
- Presenters::QcThresholdPresenter::Threshold
- Defined in:
- app/models/presenters/qc_threshold_presenter.rb
Overview
A threshold is a single QC attribute, and the configuration for the default range, the units used, and whether there are any defaults
Constant Summary collapse
- RANGE_EXPANSION =
The range slider, unless otherwise configured, will set its range based on the maximum and minimum values observed. It will expand the range by the percentage indicated here to ensure the maximum and minimum values don’t butt right up against the range limits
5
- DEFAULT_DECIMAL_PLACES =
2
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
-
#default ⇒ Float, Integer
The default position for the slider.
-
#enabled? ⇒ Boolean
Indicates if the field should be enabled.
-
#error ⇒ String
UI ready text to display to the user if the field is not enabled.
-
#initialize(key, results, configuration) ⇒ Threshold
constructor
A new instance of Threshold.
-
#max ⇒ Float
The maximum value for the slider.
-
#min ⇒ Float
The minimum value for the slider.
- #options {|configured_default, "#{configured_default} #{units}"| ... } ⇒ Object
- #step ⇒ Object
-
#units ⇒ String
The units to use for the threshold.
- #value_for(qc_result) ⇒ Object
Constructor Details
#initialize(key, results, configuration) ⇒ Threshold
Returns a new instance of Threshold.
19 20 21 22 23 24 |
# File 'app/models/presenters/qc_threshold_presenter.rb', line 19 def initialize(key, results, configuration) @key = key @name = configuration.fetch(:name, key) @results = results @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
17 18 19 |
# File 'app/models/presenters/qc_threshold_presenter.rb', line 17 def configuration @configuration end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
17 18 19 |
# File 'app/models/presenters/qc_threshold_presenter.rb', line 17 def key @key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'app/models/presenters/qc_threshold_presenter.rb', line 17 def name @name end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
17 18 19 |
# File 'app/models/presenters/qc_threshold_presenter.rb', line 17 def results @results end |
Instance Method Details
#default ⇒ Float, Integer
The default position for the slider. If not set in the thresholds section of the purpose configuration is set to zero.
67 68 69 |
# File 'app/models/presenters/qc_threshold_presenter.rb', line 67 def default configuration.fetch(:default_threshold, 0) end |
#enabled? ⇒ Boolean
Indicates if the field should be enabled. Returns false if there are no QC results for thresholds to work with or the units used for the wells can’t be directly converted.
78 79 80 |
# File 'app/models/presenters/qc_threshold_presenter.rb', line 78 def enabled? results? && compatible_units? end |
#error ⇒ String
UI ready text to display to the user if the field is not enabled.
87 88 89 90 91 92 93 |
# File 'app/models/presenters/qc_threshold_presenter.rb', line 87 def error return 'There are no QC results of this type to apply a threshold.' unless results? return if compatible_units? units = unique_units.map(&:units).join(', ') "Incompatible units #{units}. Automatic thresholds disabled." end |
#max ⇒ Float
The maximum value for the slider. If not set in the thresholds section of the purpose configuration is calibrated based on the maximum observed value. (Or 100 if it’s a percentage)
33 34 35 |
# File 'app/models/presenters/qc_threshold_presenter.rb', line 33 def max @max ||= configuration.fetch(:max) { percentage? ? 100 : max_result + range_buffer }.ceil(decimal_places) end |
#min ⇒ Float
The minimum value for the slider. If not set in the thresholds section of the purpose configuration is calibrated based on the minimum observed value. (Or 0 if it’s a percentage)
44 45 46 |
# File 'app/models/presenters/qc_threshold_presenter.rb', line 44 def min @min ||= configuration.fetch(:min) { percentage? ? 0 : min_result - range_buffer }.floor(decimal_places) end |
#options {|configured_default, "#{configured_default} #{units}"| ... } ⇒ Object
101 102 103 104 105 106 |
# File 'app/models/presenters/qc_threshold_presenter.rb', line 101 def configured_default = configuration[:default_threshold] return unless configured_default yield configured_default, "#{configured_default} #{units}" end |
#step ⇒ Object
108 109 110 |
# File 'app/models/presenters/qc_threshold_presenter.rb', line 108 def step (10**-decimal_places).to_f end |
#units ⇒ String
The units to use for the threshold. If not set in the thresholds section of the purpose configuration is calibrated based on the most sensitive observed units
55 56 57 58 59 |
# File 'app/models/presenters/qc_threshold_presenter.rb', line 55 def units @units ||= configuration.fetch(:units) { unique_units.min.units } rescue ArgumentError unique_units.first end |
#value_for(qc_result) ⇒ Object
95 96 97 98 99 |
# File 'app/models/presenters/qc_threshold_presenter.rb', line 95 def value_for(qc_result) qc_result.unit_value.convert_to(units).scalar.to_f rescue ArgumentError nil end |