@@ -47,8 +47,6 @@ class DefaultDecisionService: OPTDecisionService {
4747 experiment: Experiment ,
4848 user: OptimizelyUserContext ,
4949 options: [ OptimizelyDecideOption ] ? = nil ) -> DecisionResponse < Variation > {
50- // let reasons = DecisionReasons(options: options)
51-
5250 let userId = user. userId
5351 let ignoreUPS = ( options ?? [ ] ) . contains ( . ignoreUserProfileService)
5452 var profileTracker : UserProfileTracker ?
@@ -71,8 +69,7 @@ class DefaultDecisionService: OPTDecisionService {
7169 user: OptimizelyUserContext ,
7270 options: [ OptimizelyDecideOption ] ? = nil ,
7371 userProfileTracker: UserProfileTracker ? ) -> DecisionResponse < Variation > {
74- // var decisionReasons = reasons
75- var decisionReasons = DecisionReasons ( options: options)
72+ let reasons = DecisionReasons ( options: options)
7673 let userId = user. userId
7774 let attributes = user. attributes
7875 let experimentId = experiment. id
@@ -84,33 +81,33 @@ class DefaultDecisionService: OPTDecisionService {
8481 if !experiment. isActivated {
8582 let info = LogMessage . experimentNotRunning ( experiment. key)
8683 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 )
8986 }
9087
9188 // ---- check if the user is forced into a variation ----
9289 let decisionResponse = config. getForcedVariation ( experimentKey: experiment. key, userId: userId)
9390
94- decisionReasons . merge ( decisionResponse. reasons)
91+ reasons . merge ( decisionResponse. reasons)
9592
9693 if let variationId = decisionResponse. result? . id,
9794 let variation = experiment. getVariation ( id: variationId) {
98- return DecisionResponse ( result: variation, reasons: decisionReasons )
95+ return DecisionResponse ( result: variation, reasons: reasons )
9996 }
10097
10198 // ---- check to see if user is white-listed for a certain variation ----
10299 if let variationKey = experiment. forcedVariations [ userId] {
103100 if let variation = experiment. getVariation ( key: variationKey) {
104101 let info = LogMessage . forcedVariationFound ( variationKey, userId)
105102 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 )
108105 }
109106
110107 // mapped to invalid variation - ignore and continue for other deciesions
111108 let info = LogMessage . forcedVariationFoundButInvalid ( variationKey, userId)
112109 logger. e ( info)
113- decisionReasons . addInfo ( info)
110+ reasons . addInfo ( info)
114111 }
115112
116113 /// Load variation from tracker
@@ -120,44 +117,44 @@ class DefaultDecisionService: OPTDecisionService {
120117
121118 let info = LogMessage . gotVariationFromUserProfile ( variation. key, experiment. key, userId)
122119 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 )
125122 }
126123
127124 var bucketedVariation : Variation ?
128125 // ---- check if the user passes audience targeting before bucketing ----
129126 let audienceResponse = doesMeetAudienceConditions ( config: config,
130127 experiment: experiment,
131128 user: user)
132- decisionReasons . merge ( audienceResponse. reasons)
129+ reasons . merge ( audienceResponse. reasons)
133130
134131 if audienceResponse. result ?? false {
135132 // bucket user into a variation
136133 let decisionResponse = bucketer. bucketExperiment ( config: config,
137134 experiment: experiment,
138135 bucketingId: bucketingId)
139- decisionReasons . merge ( decisionResponse. reasons)
136+ reasons . merge ( decisionResponse. reasons)
140137
141138 bucketedVariation = decisionResponse. result
142139
143140 if let variation = bucketedVariation {
144141 let info = LogMessage . userBucketedIntoVariationInExperiment ( userId, experiment. key, variation. key)
145142 logger. i ( info)
146- decisionReasons . addInfo ( info)
143+ reasons . addInfo ( info)
147144 userProfileTracker? . updateProfile ( experiment: experiment, variation: variation)
148145 } else {
149146 let info = LogMessage . userNotBucketedIntoVariation ( userId)
150147 logger. i ( info)
151- decisionReasons . addInfo ( info)
148+ reasons . addInfo ( info)
152149 }
153150
154151 } else {
155152 let info = LogMessage . userNotInExperiment ( userId, experiment. key)
156153 logger. i ( info)
157- decisionReasons . addInfo ( info)
154+ reasons . addInfo ( info)
158155 }
159156
160- return DecisionResponse ( result: bucketedVariation, reasons: decisionReasons )
157+ return DecisionResponse ( result: bucketedVariation, reasons: reasons )
161158 }
162159
163160 func doesMeetAudienceConditions( config: ProjectConfig ,
@@ -261,7 +258,7 @@ class DefaultDecisionService: OPTDecisionService {
261258 user: OptimizelyUserContext ,
262259 options: [ OptimizelyDecideOption ] ? = nil ) -> [ DecisionResponse < FeatureDecision > ] {
263260
264- var reasons = DecisionReasons ( options: options)
261+ let reasons = DecisionReasons ( options: options)
265262 let userId = user. userId
266263 let ignoreUPS = ( options ?? [ ] ) . contains ( . ignoreUserProfileService)
267264 var profileTracker : UserProfileTracker ?
@@ -395,7 +392,7 @@ class DefaultDecisionService: OPTDecisionService {
395392 user: OptimizelyUserContext ,
396393 userProfileTracker: UserProfileTracker ? ,
397394 options: [ OptimizelyDecideOption ] ? = nil ) -> DecisionResponse < Variation > {
398- var reasons = DecisionReasons ( options: options)
395+ let reasons = DecisionReasons ( options: options)
399396 // check forced-decision first
400397 let forcedDecisionResponse = findValidatedForcedDecision ( config: config,
401398 user: user,
0 commit comments