Ejemplo n.º 1
0
        /// <summary>
        /// Create a new test, or load an existing one.
        /// </summary>
        /// <param name="testName"></param>
        /// <param name="alternatives"></param>
        /// <returns></returns>
        public ABTest GetOrCreateTest(string testName, params string[] alternatives)
        {
            ABTest test;
            if (Tests.ContainsKey(testName))
            {
                test = Tests[testName];
            }
            else
            {
                test = new ABTest(testName, alternatives);
                Tests.Add(testName, test);
            }

            return test;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a new test, or load an existing one.
        /// </summary>
        /// <param name="testName"></param>
        /// <param name="altCount"></param>
        /// <returns></returns>
        public ABTest GetOrCreateTest(string testName, int altCount)
        {
            ABTest test;
            if (Tests.ContainsKey(testName))
            {
                test = Tests[testName];
            }
            else
            {
                string[] alternatives = new string[altCount];
                for (int a = 0; a < altCount; a++)
                {
                    alternatives[a] = "Alternative " + (a + 1);
                }
                test = new ABTest(testName, alternatives);
                Tests.Add(testName, test);
            }

            return test;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// For the specified test, pick an alternative to always show this user, and return that alternative.
        /// </summary>
        /// <param name="test"></param>
        /// <returns></returns>
        public ABAlternative GetUserAlternative(ABTest test)
        {
            ABUser user = IdentifyUser();
            ABAlternative choice = test.GetUserAlternative(user.ID);

            if (!user.Tests.Contains(test.TestName) && !IsBotRequest())
            {
                choice.ScoreParticipation();

                // NOTE: If this runs into concurrency issues in high traffic, we'll probably want to move it out to a timer of some form.
                // For now though, it's probably safe here for most sites, since it's balling up changes and saving infrequently.
                Save();

                user.Tests.Add(test.TestName);
                user.SaveToCookie();
            }

            return choice;
        }