Beispiel #1
0
 internal Rollout(RolloutKind kind, int?seed, IEnumerable <WeightedVariation> variations, UserAttribute?bucketBy)
 {
     Kind       = kind;
     Seed       = seed;
     Variations = variations ?? Enumerable.Empty <WeightedVariation>();
     BucketBy   = bucketBy;
 }
Beispiel #2
0
        private static Rollout BuildRollout(RolloutKind kind, bool untrackedVariations)
        {
            var variations = new List <WeightedVariation>()
            {
                new WeightedVariation(0, 10000, untrackedVariations),
                new WeightedVariation(1, 20000, untrackedVariations),
                new WeightedVariation(0, 70000, true)
            };

            return(new Rollout(kind, seed, variations, UserAttribute.Key));
        }
        private static Rollout BuildRollout(RolloutKind kind, bool untrackedVariations)
        {
            var variations = new List <WeightedVariation>()
            {
                new WeightedVariation(1, 50000, untrackedVariations),
                new WeightedVariation(2, 20000, untrackedVariations)
            };
            const int seed = 123;

            return(new Rollout(kind, seed, variations, UserAttribute.Key));
        }
Beispiel #4
0
        internal static Rollout?ReadRollout(ref JReader r)
        {
            ImmutableList <WeightedVariation> variations = null;
            UserAttribute?bucketBy = null;
            RolloutKind   kind     = RolloutKind.Rollout;
            int?          seed     = null;
            var           obj      = r.ObjectOrNull();

            if (!obj.IsDefined)
            {
                return(null);
            }
            while (obj.Next(ref r))
            {
                switch (obj.Name)
                {
                case var n when n == "variations":
                    var listBuilder = ImmutableList.CreateBuilder <WeightedVariation>();
                    for (var arr = r.ArrayOrNull(); arr.Next(ref r);)
                    {
                        int  variation = 0, weight = 0;
                        bool untracked = false;
                        for (var wvObj = r.Object(); wvObj.Next(ref r);)
                        {
                            switch (wvObj.Name)
                            {
                            case var nn when nn == "variation":
                                variation = r.Int();
                                break;

                            case var nn when nn == "weight":
                                weight = r.Int();
                                break;

                            case var nn when nn == "untracked":
                                untracked = r.Bool();
                                break;
                            }
                        }
                        listBuilder.Add(new WeightedVariation(variation, weight, untracked));
                    }
                    variations = listBuilder.ToImmutable();
                    break;

                case var n when n == "bucketBy":
                    var s = r.StringOrNull();
                    bucketBy = s is null ? (UserAttribute?)null : UserAttribute.ForName(s);
                    break;

                case var n when n == "kind":
                    var kindStr = r.StringOrNull();
                    kind = "experiment".Equals(kindStr) ? RolloutKind.Experiment : RolloutKind.Rollout;
                    break;

                case var n when n == "seed":
                    seed = r.IntOrNull();
                    break;
                }
            }
            return(new Rollout(kind, seed, variations, bucketBy));
        }