@@ -61,7 +61,7 @@ - (instancetype)initWithConfig:(OPTLYProjectConfig *)config {
61
61
}
62
62
63
63
- (OPTLYVariation *)bucketExperiment : (OPTLYExperiment *)experiment
64
- withUserId : (NSString *)userId {
64
+ withBucketingId : (NSString *)bucketingId {
65
65
BOOL ok = YES ;
66
66
// check for mutex
67
67
NSString *groupId = experiment.groupId ;
@@ -74,7 +74,7 @@ - (OPTLYVariation *)bucketExperiment:(OPTLYExperiment *)experiment
74
74
// do nothing if it is overlapping policy
75
75
}
76
76
else if ([group.policy isEqualToString: OPTLYBucketerMutexPolicy]) {
77
- OPTLYExperiment *mutexExperiment = [self bucketToExperiment: group withUserId: userId ];
77
+ OPTLYExperiment *mutexExperiment = [self bucketToExperiment: group withBucketingId: bucketingId ];
78
78
if (mutexExperiment != experiment) { // check to see if the experiment the user should fall into is the same experiment we are bucketing
79
79
ok = NO ;
80
80
}
@@ -86,20 +86,20 @@ - (OPTLYVariation *)bucketExperiment:(OPTLYExperiment *)experiment
86
86
87
87
// bucket to variation only if experiment passes Mutex check
88
88
if (ok) {
89
- OPTLYVariation *variation = [self bucketToVariation: experiment withUserId: userId ];
89
+ OPTLYVariation *variation = [self bucketToVariation: experiment withBucketingId: bucketingId ];
90
90
return variation;
91
91
}
92
92
else {
93
93
// log message if the user is mutually excluded
94
- NSString *logMessage = [NSString stringWithFormat: OPTLYLoggerMessagesUserMutuallyExcluded, userId , experiment.experimentKey, groupId];
94
+ NSString *logMessage = [NSString stringWithFormat: OPTLYLoggerMessagesUserMutuallyExcluded, bucketingId , experiment.experimentKey, groupId];
95
95
[self .config.logger logMessage: logMessage withLevel: OptimizelyLogLevelInfo];
96
96
return nil ;
97
97
}
98
98
}
99
99
100
- - (OPTLYExperiment *)bucketToExperiment : (OPTLYGroup *)group withUserId : (NSString *)userId {
101
- NSString *bucketingId = [self makeBucketingIdFromUserId: userId andEntityId: group.groupId];
102
- int bucketValue = [self generateBucketValue: bucketingId ];
100
+ - (OPTLYExperiment *)bucketToExperiment : (OPTLYGroup *)group withBucketingId : (NSString *)bucketingId {
101
+ NSString *hashId = [self makeHashIdFromBucketingId: bucketingId andEntityId: group.groupId];
102
+ int bucketValue = [self generateBucketValue: hashId ];
103
103
104
104
if ([group.trafficAllocations count ] == 0 ) {
105
105
// log error if there are no traffic allocation values
@@ -121,7 +121,7 @@ - (OPTLYExperiment *)bucketToExperiment:(OPTLYGroup *)group withUserId:(NSString
121
121
code: OPTLYErrorTypesDataUnknown
122
122
description: NSLocalizedString(OPTLYErrorHandlerMessagesExperimentUnknown, experimentId)];
123
123
124
- NSString *logMessage = [NSString stringWithFormat: OPTLYLoggerMessagesForcedBucketingFailed, experimentId, userId ];
124
+ NSString *logMessage = [NSString stringWithFormat: OPTLYLoggerMessagesForcedBucketingFailed, experimentId, bucketingId ];
125
125
[self .config.logger logMessage: logMessage withLevel: OptimizelyLogLevelError];
126
126
}
127
127
return experiment;
@@ -136,9 +136,9 @@ - (OPTLYExperiment *)bucketToExperiment:(OPTLYGroup *)group withUserId:(NSString
136
136
return nil ;
137
137
}
138
138
139
- - (OPTLYVariation *)bucketToVariation : (OPTLYExperiment *)experiment withUserId : (NSString *)userId {
140
- NSString *bucketingId = [self makeBucketingIdFromUserId: userId andEntityId: experiment.experimentId];
141
- int bucketValue = [self generateBucketValue: bucketingId ];
139
+ - (OPTLYVariation *)bucketToVariation : (OPTLYExperiment *)experiment withBucketingId : (NSString *)bucketingId {
140
+ NSString *hashId = [self makeHashIdFromBucketingId: bucketingId andEntityId: experiment.experimentId];
141
+ int bucketValue = [self generateBucketValue: hashId ];
142
142
143
143
if ([experiment.trafficAllocations count ] == 0 ) {
144
144
// log error if there are no traffic allocation values
@@ -162,11 +162,11 @@ - (OPTLYVariation *)bucketToVariation:(OPTLYExperiment *)experiment withUserId:
162
162
code: OPTLYErrorTypesDataUnknown
163
163
description: NSLocalizedString(OPTLYErrorHandlerMessagesVariationUnknown, variationId)];
164
164
165
- NSString *variationUnknownMessage = [NSString stringWithFormat: OPTLYLoggerMessagesForcedBucketingFailed, variationId, userId ];
165
+ NSString *variationUnknownMessage = [NSString stringWithFormat: OPTLYLoggerMessagesForcedBucketingFailed, variationId, bucketingId ];
166
166
[self .config.logger logMessage: variationUnknownMessage withLevel: OptimizelyLogLevelError];
167
167
}
168
168
else {
169
- NSString *logMessage = [NSString stringWithFormat: OPTLYLoggerMessagesBucketAssigned, variation.variationKey, userId ];
169
+ NSString *logMessage = [NSString stringWithFormat: OPTLYLoggerMessagesBucketAssigned, variation.variationKey, bucketingId ];
170
170
[self .config.logger logMessage: logMessage withLevel: OptimizelyLogLevelDebug];
171
171
}
172
172
return variation;
@@ -181,21 +181,21 @@ - (OPTLYVariation *)bucketToVariation:(OPTLYExperiment *)experiment withUserId:
181
181
return nil ;
182
182
}
183
183
184
- - (int )generateBucketValue : (NSString *)bucketingId {
185
- double ratio = ((double ) [self generateUnsignedHashCode32Bit: bucketingId ] / (double ) MAX_HASH_VALUE);
184
+ - (int )generateBucketValue : (NSString *)hashId {
185
+ double ratio = ((double ) [self generateUnsignedHashCode32Bit: hashId ] / (double ) MAX_HASH_VALUE);
186
186
return ratio * MAX_TRAFFIC_VALUE;
187
187
}
188
188
189
- - (uint32_t )generateUnsignedHashCode32Bit : (NSString *)bucketingId {
190
- const char *str = [bucketingId UTF8String ];
191
- int len = (int )[bucketingId length ];
189
+ - (uint32_t )generateUnsignedHashCode32Bit : (NSString *)hashId {
190
+ const char *str = [hashId UTF8String ];
191
+ int len = (int )[hashId length ];
192
192
uint32_t result = 0 ;
193
193
MurmurHash3_x86_32 (str, len, self.bucket_seed , &result);
194
194
return result;
195
195
}
196
196
197
- - (NSString *)makeBucketingIdFromUserId : (NSString *)userId andEntityId : (NSString *)entityId {
198
- return [NSString stringWithFormat: BUCKETING_ID_TEMPLATE, userId , entityId];
197
+ - (NSString *)makeHashIdFromBucketingId : (NSString *)bucketingId andEntityId : (NSString *)entityId {
198
+ return [NSString stringWithFormat: BUCKETING_ID_TEMPLATE, bucketingId , entityId];
199
199
}
200
200
201
201
@end
0 commit comments