Esempio n. 1
0
def get_ab_test_properties(user):
    return {
        "a_b_test_variable_1": "A" if deterministic_random(user.username + "a_b_test_variable_1") > 0.5 else "B",
        "a_b_test_variable_first_submission": "A"
        if deterministic_random(user.username + "a_b_test_variable_first_submission") > 0.5
        else "B",
    }
Esempio n. 2
0
def get_ab_test_properties(user):
    return {
        'a_b_test_variable_1':
            'A' if deterministic_random(user.username + 'a_b_test_variable_1') > 0.5 else 'B',
        'a_b_test_variable_first_submission':
            'A' if deterministic_random(user.username + 'a_b_test_variable_first_submission') > 0.5 else 'B',
    }
Esempio n. 3
0
def get_ab_test_properties(user):
    return {
        'a_b_test_variable_1':
            'A' if deterministic_random(user.username + 'a_b_test_variable_1') > 0.5 else 'B',
        'a_b_test_variable_first_submission':
            'A' if deterministic_random(user.username + 'a_b_test_variable_first_submission') > 0.5 else 'B',
    }
Esempio n. 4
0
 def test_consistency(self):
     seen = set()
     for seed in self._random_strings(100):
         converted_rand = deterministic_random(seed)
         self.assertTrue(0 <= converted_rand < 1)
         self.assertEqual(converted_rand, deterministic_random(seed))
         self.assertTrue(converted_rand not in seen)
         seen.add(converted_rand)
Esempio n. 5
0
 def test_consistency(self):
     seen = set()
     for seed in self._random_strings(100):
         converted_rand = deterministic_random(seed)
         self.assertTrue(0 <= converted_rand < 1)
         self.assertEqual(converted_rand, deterministic_random(seed))
         self.assertTrue(converted_rand not in seen)
         seen.add(converted_rand)
Esempio n. 6
0
def track_clicked_deploy_on_hubspot(webuser_id, hubspot_cookie, meta):
    webuser = WebUser.get_by_user_id(webuser_id)
    num = deterministic_random(webuser.username + 'a_b_variable_deploy')
    ab = {'a_b_variable_deploy': 'A' if num > 0.5 else 'B'}
    _send_form_to_hubspot(HUBSPOT_CLICKED_DEPLOY_FORM_ID,
                          webuser,
                          hubspot_cookie,
                          meta,
                          extra_fields=ab)
Esempio n. 7
0
def track_clicked_signup_on_hubspot(email, cookies, meta):
    data = {"lifecyclestage": "subscriber"}
    number = deterministic_random(email + "a_b_test_variable_newsletter")
    if number < 0.33:
        data["a_b_test_variable_newsletter"] = "A"
    elif number < 0.67:
        data["a_b_test_variable_newsletter"] = "B"
    else:
        data["a_b_test_variable_newsletter"] = "C"
    if email:
        _send_form_to_hubspot(HUBSPOT_CLICKED_SIGNUP_FORM, None, cookies, meta, extra_fields=data, email=email)
Esempio n. 8
0
def track_clicked_signup_on_hubspot(email, cookies, meta):
    data = {'lifecyclestage': 'subscriber'}
    number = deterministic_random(email + 'a_b_test_variable_newsletter')
    if number < 0.33:
        data['a_b_test_variable_newsletter'] = 'A'
    elif number < 0.67:
        data['a_b_test_variable_newsletter'] = 'B'
    else:
        data['a_b_test_variable_newsletter'] = 'C'
    if email:
        _send_form_to_hubspot(HUBSPOT_CLICKED_SIGNUP_FORM, None, cookies, meta, extra_fields=data, email=email)
Esempio n. 9
0
def track_clicked_deploy_on_hubspot(webuser, cookies, meta):
    ab = {
        'a_b_variable_deploy':
        'A' if deterministic_random(webuser.username +
                                    'a_b_variable_deploy') > 0.5 else 'B',
    }
    _send_form_to_hubspot(HUBSPOT_CLICKED_DEPLOY_FORM_ID,
                          webuser,
                          cookies,
                          meta,
                          extra_fields=ab)
Esempio n. 10
0
def track_clicked_signup_on_hubspot(email, cookies, meta):
    data = {'lifecyclestage': 'subscriber'}
    number = deterministic_random(email + 'a_b_test_variable_newsletter')
    if number < 0.33:
        data['a_b_test_variable_newsletter'] = 'A'
    elif number < 0.67:
        data['a_b_test_variable_newsletter'] = 'B'
    else:
        data['a_b_test_variable_newsletter'] = 'C'
    if email:
        _send_form_to_hubspot(HUBSPOT_CLICKED_SIGNUP_FORM, None, cookies, meta, extra_fields=data, email=email)
Esempio n. 11
0
    def test_randomness(self):
        buckets = defaultdict(lambda: 0)
        for i in range(10000):
            # use similar looking strings to make sure randomness is in the called function.
            # note that this also makes this (statistically-determined) test deterministic which is nice
            seed = 'test-string-{}'.format(i)
            converted_rand = deterministic_random(seed)
            self.assertTrue(0 <= converted_rand < 1)
            first_decimal = int("{:.1f}".format(converted_rand)[-1])
            buckets[first_decimal] += 1

        self.assertEqual(10, len(buckets))
        for i in range(10):
            # we expect about 1000 in each bucket and the sample is big enough that
            # these constraints are fine.
            self.assertTrue(900 < buckets[i] < 1100)
Esempio n. 12
0
    def test_randomness(self):
        buckets = defaultdict(lambda: 0)
        for i in range(10000):
            # use similar looking strings to make sure randomness is in the called function.
            # note that this also makes this (statistically-determined) test deterministic which is nice
            seed = 'test-string-{}'.format(i)
            converted_rand = deterministic_random(seed)
            self.assertTrue(0 <= converted_rand < 1)
            first_decimal = int("{:.1f}".format(converted_rand)[-1])
            buckets[first_decimal] += 1

        self.assertEqual(10, len(buckets))
        for i in range(10):
            # we expect about 1000 in each bucket and the sample is big enough that
            # these constraints are fine.
            self.assertTrue(900 < buckets[i] < 1100)
Esempio n. 13
0
 def test_unicode(self):
     unicode_string = u'टूटना{}'.format(self._random_string())
     value = deterministic_random(unicode_string)
     self.assertEqual(value, deterministic_random(unicode_string))
Esempio n. 14
0
 def test_unicode(self):
     unicode_string = 'टूटना{}'.format(self._random_string())
     value = deterministic_random(unicode_string)
     self.assertEqual(value, deterministic_random(unicode_string))
Esempio n. 15
0
def track_clicked_deploy_on_hubspot(webuser, cookies, meta):
    ab = {
        'a_b_variable_deploy': 'A' if deterministic_random(webuser.username + 'a_b_variable_deploy') > 0.5 else 'B',
    }
    _send_form_to_hubspot(HUBSPOT_CLICKED_DEPLOY_FORM_ID, webuser, cookies, meta, extra_fields=ab)
Esempio n. 16
0
 def test_deterministic(self):
     self.assertEqual(
         deterministic_random("[None, 'domain']:test_toggle:diana"),
         0.5358778226236243
     )
Esempio n. 17
0
 def test_deterministic(self):
     self.assertEqual(
         deterministic_random("[None, 'domain']:test_toggle:diana"),
         0.5358778226236243)