Example #1
0
        public char?GetNextBlockChar(PredictionRequest predictionRequest, BlockGenerationMode mode)
        {
            string developer = GetDeveloperName(predictionRequest);

            // MaxOccurrencesOfCharacterInBlock = 1 - random block generator.
            // MaxOccurrencesOfCharacterInBlock > 1 - alternating tratments design.
            const int MaxOccurrencesOfCharacterInBlock = 2;

            using (var databaseContext = this.CreateContext())
            {
                var lastRbgData = GetLastRbgDatas(databaseContext, developer, MaxOccurrencesOfCharacterInBlock);

                int experimentDay = CalculateCurrentExperimentDay(lastRbgData);

                // Do nothing if we have RBG data for current experiment day.
                if (lastRbgData.Any() && experimentDay == lastRbgData[0].ExperimentDay)
                {
                    return(lastRbgData[0].Mode[0]);
                }

                // Calculate for new day.
                char?nextCharacterInBlock = null;

                if (mode == BlockGenerationMode.RandomBlockGenerator)
                {
                    // [0] 2018-01-05 JOHN A
                    // [1] 2018-01-04 JOHN B
                    // [2] 2018-01-03 JOHN A
                    // [3] 2018-01-02 JOHN B
                    var block = lastRbgData
                                .Select(g => g.Mode[0])
                                .Reverse()
                                .ToArray();

                    var blockGenerator = RandomBlockGenerator.Create(new[] { 'A', 'B' });
                    blockGenerator.SetBlock(block);

                    // block = { 'B', 'A', 'B', 'A' }
                    nextCharacterInBlock = blockGenerator.Next(MaxOccurrencesOfCharacterInBlock);
                }
                else if (mode == BlockGenerationMode.ImposedParticipant)
                {
                    Participant participant = GetParticipant(developer, databaseContext);

                    if (participant != null)
                    {
                        var generator = new ImposedBlockGenerator();
                        generator.SetBlock(participant.Block.ToList());
                        generator.SetPosition(experimentDay);
                        nextCharacterInBlock = generator.GetForIndex(generator.Position);
                    }
                }

                AppendRbgData(databaseContext, developer, experimentDay, nextCharacterInBlock);

                return(nextCharacterInBlock);
            }
        }
        public void Test1()
        {
            var generator = RandomBlockGenerator.Create(new List <char> {
                'A', 'B'
            }, (min, max) => 0);

            generator.Next();
            generator.Next();
            generator.Next();
            generator.Next();
            Test("ABAB", generator);
        }
        public void Test3()
        {
            var generator = RandomBlockGenerator.Create(new List <char> {
                'A', 'B'
            });

            generator.SetBlock('A');
            generator.Next();
            generator.Next();
            generator.Next();
            generator.Next();
            Test("ABABA", generator);

            generator.SetBlock('B');
            generator.Next();
            generator.Next();
            generator.Next();
            generator.Next();
            Test("BABAB", generator);
        }
        public void Test5()
        {
            int[] randomIndexes = { 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1 };
            int   i             = 0;
            var   generator     = RandomBlockGenerator.Create(new List <char> {
                'A', 'B'
            }, (min, max) => randomIndexes[i++]);

            generator.SetBlock('A', 'A', 'A');
            generator.Next(3);
            generator.Next(3);
            generator.Next(3);
            generator.Next(3);
            generator.Next(3);
            generator.Next(3);
            generator.Next(3);
            generator.Next(3);
            generator.Next(3);
            generator.Next(3);
            generator.Next(3);

            Test("AAABAABAAABBBA", generator);
        }
Example #5
0
 public RbgService(IServiceConfiguration serviceConfiguration)
 {
     this.serviceConfiguration = serviceConfiguration;
     this.fileBlockGenerator   = RandomBlockGenerator.Create(new[] { 'A', 'B' });
 }