8

Add method to randomise matching sessions into the segment

This commit is contained in:
Kaitlyn Crawford
2018-02-05 12:18:22 +02:00
parent ecb4f928fb
commit 6f97c76958

View File

@@ -1,4 +1,5 @@
from __future__ import absolute_import, unicode_literals
import random
from django import forms
from django.conf import settings
@@ -182,6 +183,19 @@ class Segment(ClusterableModel):
if save:
self.save()
def randomise_into_segment(self):
""" Returns True if randomisation_percent is not set or it generates
a random number less than the randomisation_percent
This is so there is some randomisation in which users are added to the
segment
"""
if self.randomisation_percent is None:
return True
if random.randint(1, 100) <= self.randomisation_percent:
return True
return False
class PersonalisablePageMetadata(ClusterableModel):
"""The personalisable page model. Allows creation of variants with linked