@@ -47,8 +47,6 @@ class DefaultDecisionService: OPTDecisionService {
47
47
experiment: Experiment ,
48
48
user: OptimizelyUserContext ,
49
49
options: [ OptimizelyDecideOption ] ? = nil ) -> DecisionResponse < Variation > {
50
- // let reasons = DecisionReasons(options: options)
51
-
52
50
let userId = user. userId
53
51
let ignoreUPS = ( options ?? [ ] ) . contains ( . ignoreUserProfileService)
54
52
var profileTracker : UserProfileTracker ?
@@ -71,8 +69,7 @@ class DefaultDecisionService: OPTDecisionService {
71
69
user: OptimizelyUserContext ,
72
70
options: [ OptimizelyDecideOption ] ? = nil ,
73
71
userProfileTracker: UserProfileTracker ? ) -> DecisionResponse < Variation > {
74
- // var decisionReasons = reasons
75
- var decisionReasons = DecisionReasons ( options: options)
72
+ let reasons = DecisionReasons ( options: options)
76
73
let userId = user. userId
77
74
let attributes = user. attributes
78
75
let experimentId = experiment. id
@@ -84,33 +81,33 @@ class DefaultDecisionService: OPTDecisionService {
84
81
if !experiment. isActivated {
85
82
let info = LogMessage . experimentNotRunning ( experiment. key)
86
83
logger. i ( info)
87
- decisionReasons . addInfo ( info)
88
- return DecisionResponse ( result: nil , reasons: decisionReasons )
84
+ reasons . addInfo ( info)
85
+ return DecisionResponse ( result: nil , reasons: reasons )
89
86
}
90
87
91
88
// ---- check if the user is forced into a variation ----
92
89
let decisionResponse = config. getForcedVariation ( experimentKey: experiment. key, userId: userId)
93
90
94
- decisionReasons . merge ( decisionResponse. reasons)
91
+ reasons . merge ( decisionResponse. reasons)
95
92
96
93
if let variationId = decisionResponse. result? . id,
97
94
let variation = experiment. getVariation ( id: variationId) {
98
- return DecisionResponse ( result: variation, reasons: decisionReasons )
95
+ return DecisionResponse ( result: variation, reasons: reasons )
99
96
}
100
97
101
98
// ---- check to see if user is white-listed for a certain variation ----
102
99
if let variationKey = experiment. forcedVariations [ userId] {
103
100
if let variation = experiment. getVariation ( key: variationKey) {
104
101
let info = LogMessage . forcedVariationFound ( variationKey, userId)
105
102
logger. i ( info)
106
- decisionReasons . addInfo ( info)
107
- return DecisionResponse ( result: variation, reasons: decisionReasons )
103
+ reasons . addInfo ( info)
104
+ return DecisionResponse ( result: variation, reasons: reasons )
108
105
}
109
106
110
107
// mapped to invalid variation - ignore and continue for other deciesions
111
108
let info = LogMessage . forcedVariationFoundButInvalid ( variationKey, userId)
112
109
logger. e ( info)
113
- decisionReasons . addInfo ( info)
110
+ reasons . addInfo ( info)
114
111
}
115
112
116
113
/// Load variation from tracker
@@ -120,44 +117,44 @@ class DefaultDecisionService: OPTDecisionService {
120
117
121
118
let info = LogMessage . gotVariationFromUserProfile ( variation. key, experiment. key, userId)
122
119
logger. i ( info)
123
- decisionReasons . addInfo ( info)
124
- return DecisionResponse ( result: variation, reasons: decisionReasons )
120
+ reasons . addInfo ( info)
121
+ return DecisionResponse ( result: variation, reasons: reasons )
125
122
}
126
123
127
124
var bucketedVariation : Variation ?
128
125
// ---- check if the user passes audience targeting before bucketing ----
129
126
let audienceResponse = doesMeetAudienceConditions ( config: config,
130
127
experiment: experiment,
131
128
user: user)
132
- decisionReasons . merge ( audienceResponse. reasons)
129
+ reasons . merge ( audienceResponse. reasons)
133
130
134
131
if audienceResponse. result ?? false {
135
132
// bucket user into a variation
136
133
let decisionResponse = bucketer. bucketExperiment ( config: config,
137
134
experiment: experiment,
138
135
bucketingId: bucketingId)
139
- decisionReasons . merge ( decisionResponse. reasons)
136
+ reasons . merge ( decisionResponse. reasons)
140
137
141
138
bucketedVariation = decisionResponse. result
142
139
143
140
if let variation = bucketedVariation {
144
141
let info = LogMessage . userBucketedIntoVariationInExperiment ( userId, experiment. key, variation. key)
145
142
logger. i ( info)
146
- decisionReasons . addInfo ( info)
143
+ reasons . addInfo ( info)
147
144
userProfileTracker? . updateProfile ( experiment: experiment, variation: variation)
148
145
} else {
149
146
let info = LogMessage . userNotBucketedIntoVariation ( userId)
150
147
logger. i ( info)
151
- decisionReasons . addInfo ( info)
148
+ reasons . addInfo ( info)
152
149
}
153
150
154
151
} else {
155
152
let info = LogMessage . userNotInExperiment ( userId, experiment. key)
156
153
logger. i ( info)
157
- decisionReasons . addInfo ( info)
154
+ reasons . addInfo ( info)
158
155
}
159
156
160
- return DecisionResponse ( result: bucketedVariation, reasons: decisionReasons )
157
+ return DecisionResponse ( result: bucketedVariation, reasons: reasons )
161
158
}
162
159
163
160
func doesMeetAudienceConditions( config: ProjectConfig ,
@@ -261,7 +258,7 @@ class DefaultDecisionService: OPTDecisionService {
261
258
user: OptimizelyUserContext ,
262
259
options: [ OptimizelyDecideOption ] ? = nil ) -> [ DecisionResponse < FeatureDecision > ] {
263
260
264
- var reasons = DecisionReasons ( options: options)
261
+ let reasons = DecisionReasons ( options: options)
265
262
let userId = user. userId
266
263
let ignoreUPS = ( options ?? [ ] ) . contains ( . ignoreUserProfileService)
267
264
var profileTracker : UserProfileTracker ?
@@ -395,7 +392,7 @@ class DefaultDecisionService: OPTDecisionService {
395
392
user: OptimizelyUserContext ,
396
393
userProfileTracker: UserProfileTracker ? ,
397
394
options: [ OptimizelyDecideOption ] ? = nil ) -> DecisionResponse < Variation > {
398
- var reasons = DecisionReasons ( options: options)
395
+ let reasons = DecisionReasons ( options: options)
399
396
// check forced-decision first
400
397
let forcedDecisionResponse = findValidatedForcedDecision ( config: config,
401
398
user: user,
0 commit comments