Class: AsyncExperiments::ExperimentResult
- Inherits:
-
Object
- Object
- AsyncExperiments::ExperimentResult
- Defined in:
- lib/async_experiments/experiment_result.rb
Instance Attribute Summary collapse
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#run_output ⇒ Object
readonly
Returns the value of attribute run_output.
Instance Method Summary collapse
- #available? ⇒ Boolean
- #candidate? ⇒ Boolean
- #control? ⇒ Boolean
-
#initialize(name, id, type, redis, statsd, run_output = nil, duration = nil) ⇒ ExperimentResult
constructor
A new instance of ExperimentResult.
- #process_run_output(candidate) ⇒ Object
- #store_run_output ⇒ Object
Constructor Details
#initialize(name, id, type, redis, statsd, run_output = nil, duration = nil) ⇒ ExperimentResult
Returns a new instance of ExperimentResult.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/async_experiments/experiment_result.rb', line 7 def initialize(name, id, type, redis, statsd, run_output = nil, duration = nil) @name = name @key = "#{name}:#{id}" @redis = redis @statsd = statsd @type = type @run_output = run_output @duration = duration if Util.blank?(run_output) || Util.blank?(duration) redis_data = data_from_redis if redis_data @run_output ||= redis_data.fetch(:run_output) @duration ||= redis_data.fetch(:duration) end end end |
Instance Attribute Details
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
26 27 28 |
# File 'lib/async_experiments/experiment_result.rb', line 26 def duration @duration end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
26 27 28 |
# File 'lib/async_experiments/experiment_result.rb', line 26 def key @key end |
#run_output ⇒ Object (readonly)
Returns the value of attribute run_output.
26 27 28 |
# File 'lib/async_experiments/experiment_result.rb', line 26 def run_output @run_output end |
Instance Method Details
#available? ⇒ Boolean
49 50 51 |
# File 'lib/async_experiments/experiment_result.rb', line 49 def available? Util.present?(run_output) && Util.present?(duration) end |
#candidate? ⇒ Boolean
45 46 47 |
# File 'lib/async_experiments/experiment_result.rb', line 45 def candidate? type == :candidate end |
#control? ⇒ Boolean
41 42 43 |
# File 'lib/async_experiments/experiment_result.rb', line 41 def control? type == :control end |
#process_run_output(candidate) ⇒ Object
35 36 37 38 39 |
# File 'lib/async_experiments/experiment_result.rb', line 35 def process_run_output(candidate) variation = HashDiff.diff(sort(self.run_output), sort(candidate.run_output)) report_data(variation, candidate) redis.del("experiments:#{key}:candidate") end |
#store_run_output ⇒ Object
28 29 30 31 32 33 |
# File 'lib/async_experiments/experiment_result.rb', line 28 def store_run_output redis.set("experiments:#{key}:#{type}", { run_output: run_output, duration: duration, }.to_json) end |