public Variation TargettedVariation(string userId, List <Variation> whiteListedVariations) { int whiteListedVariationsLength = whiteListedVariations.Count; RangeBucket <Variation> whiteListedVariationsList = new RangeBucket <Variation>(); Variation targettedVariation; if (whiteListedVariationsLength == 0) { return(null); } else if (whiteListedVariationsLength == 1) { targettedVariation = whiteListedVariations[0]; } else { whiteListedVariations = ScaleVariations(whiteListedVariations); whiteListedVariationsList = GetVariationAllocationRanges(whiteListedVariations); double maxVal = Constants.Variation.MAX_TRAFFIC_VALUE; double multiplier = 1; var bucketValue = this._userHasher.ComputeBucketValue(userId, Constants.Campaign.MAX_TRAFFIC_PERCENT, multiplier); targettedVariation = whiteListedVariationsList.Find(bucketValue); } return(targettedVariation); }
private RangeBucket <Variation> Bucket(IReadOnlyList <Variation> variations, string campaignKey) { RangeBucket <Variation> bucket = new RangeBucket <Variation>(Constants.Variation.MAX_TRAFFIC_VALUE); foreach (var variation in variations) { bucket.Add(variation.Weight, variation, out double start, out double end); LogInfoMessage.VariationRangeAllocation(file, campaignKey, variation.Name, variation.Weight, start, end); } return(bucket); }
public RangeBucket <Variation> GetVariationAllocationRanges(List <Variation> variations) { int currentAllocation = 0; RangeBucket <Variation> bucket = new RangeBucket <Variation>(Constants.Variation.MAX_TRAFFIC_VALUE); foreach (var variation in variations) { int stepFactor = GetVariationBucketingRange(variation.Weight); if (stepFactor != 0) { bucket.AddNew(variation, currentAllocation + 1, currentAllocation + stepFactor); currentAllocation += stepFactor; } else { bucket.AddNew(variation, -1, -1); } } return(bucket); }