27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/optimizely/audience.rb', line 27
def user_meets_audience_conditions?(config, experiment, user_context, logger, logging_hash = nil, logging_key = nil)
decide_reasons = []
logging_hash ||= 'EXPERIMENT_AUDIENCE_EVALUATION_LOGS'
logging_key ||= experiment['key']
logs_hash = Object.const_get "Optimizely::Helpers::Constants::#{logging_hash}"
audience_conditions = experiment['audienceConditions'] || experiment['audienceIds']
message = format(logs_hash['EVALUATING_AUDIENCES_COMBINED'], logging_key, audience_conditions)
logger.log(Logger::DEBUG, message)
if audience_conditions.empty?
message = format(logs_hash['AUDIENCE_EVALUATION_RESULT_COMBINED'], logging_key, 'TRUE')
logger.log(Logger::INFO, message)
decide_reasons.push(message)
return true, decide_reasons
end
user_condition_evaluator = UserConditionEvaluator.new(user_context, logger)
evaluate_user_conditions = lambda do |condition|
user_condition_evaluator.evaluate(condition)
end
evaluate_audience = lambda do |audience_id|
audience = config.get_audience_from_id(audience_id)
return nil unless audience
audience_conditions = audience['conditions']
message = format(logs_hash['EVALUATING_AUDIENCE'], audience_id, audience_conditions)
logger.log(Logger::DEBUG, message)
decide_reasons.push(message)
audience_conditions = JSON.parse(audience_conditions) if audience_conditions.is_a?(String)
result = ConditionTreeEvaluator.evaluate(audience_conditions, evaluate_user_conditions)
result_str = result.nil? ? 'UNKNOWN' : result.to_s.upcase
message = format(logs_hash['AUDIENCE_EVALUATION_RESULT'], audience_id, result_str)
logger.log(Logger::DEBUG, message)
decide_reasons.push(message)
result
end
eval_result = ConditionTreeEvaluator.evaluate(audience_conditions, evaluate_audience)
eval_result ||= false
message = format(logs_hash['AUDIENCE_EVALUATION_RESULT_COMBINED'], logging_key, eval_result.to_s.upcase)
logger.log(Logger::INFO, message)
decide_reasons.push(message)
[eval_result, decide_reasons]
end
|