Class: AsyncExperiments::ExperimentResult

Inherits:
Object
  • Object
show all
Defined in:
lib/async_experiments/experiment_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#durationObject (readonly)

Returns the value of attribute duration.



26
27
28
# File 'lib/async_experiments/experiment_result.rb', line 26

def duration
  @duration
end

#keyObject (readonly)

Returns the value of attribute key.



26
27
28
# File 'lib/async_experiments/experiment_result.rb', line 26

def key
  @key
end

#run_outputObject (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

Returns:

  • (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

Returns:

  • (Boolean)


45
46
47
# File 'lib/async_experiments/experiment_result.rb', line 45

def candidate?
  type == :candidate
end

#control?Boolean

Returns:

  • (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_outputObject



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