示例#1
0
        public async Task <bool> IsInVariantAsync(int experimentId, int userId, bool recordParticipation = true)
        {
            var experiment = await _experimentRepository.GetExperimentAsync(experimentId);

            if (!experiment.IsActive)
            {
                return(false);
            }

            var user = await _userRepository.GetUserAsync(userId);

            // Do some bit fiddling to make sure we always return the same value
            // Use experiment.SplitType to calculate it based on the userId or the teamId
            int differentiator;

            switch (experiment.SplitType)
            {
            case GroupSplitType.User:
                differentiator = user.UserId;
                break;

            case GroupSplitType.Team:
                differentiator = user.TeamId;
                break;

            case GroupSplitType.None:
            default:
                throw new ArgumentOutOfRangeException();
            }

            var hash    = GetParticipationHash(experiment.ExperimentId, differentiator);
            var variant = (int)(hash % experiment.Variants.Length);

            if (recordParticipation)
            {
                await _experimentRepository.RecordParticipationAsync(experimentId, userId, variant);
            }

            // 0 is always control
            return(variant > 0);
        }
示例#2
0
        public async Task <Significance> GetSignificanceAsync(int experimentId)
        {
            var experiment = await _experimentRepository.GetExperimentAsync(experimentId);

            IAnalysisStrategy evaluationStrategy = null;

            switch (experiment.EvaluationType)
            {
            case Testify.Models.EvaluationType.VideoImpressions:
                evaluationStrategy = new VideoImpressionAnalysisStrategy();
                break;

            case Testify.Models.EvaluationType.VideosInteracted:
                break;

            case Testify.Models.EvaluationType.None:
            default:
                break;
            }

            var analyticsData = await evaluationStrategy.GetStrategyResultAsync(experiment);

            return(GetSignificance(analyticsData));
        }