splango Package¶
middleware Module¶
models Module¶
-
class
splango.models.Enrollment(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelIdentifies which variant a subject is assigned to in a given experiment.
-
experiment¶
-
get_next_by_created(*moreargs, **morekwargs)¶
-
get_previous_by_created(*moreargs, **morekwargs)¶
-
subject¶
-
variant¶
-
-
class
splango.models.Experiment(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelA named experiment.
An experiment has a lot of variants, and a variant belongs to only one experiment.
-
classmethod
declare(name, variants_names)[source]¶ create or update an experiment and its variants (variant names given).
-
enrollment_set¶
-
experimentreport_set¶
-
get_next_by_created(*moreargs, **morekwargs)¶
-
get_or_create_enrollment(subject, variant=None)[source]¶ Get or create an
Enrollmentobject forsubject.Only if the object is to be created will
variantbe used. Ifvariantis None, a random variant will be assigned.Parameters: - subject (
Subject) – the subject of the enrollment - variant (str or None) – when creating the object, it is the variant to use;
if None, a random variant will be used
created, this will be the value for
Enrollment.variant
Returns: the enrollment for
subjectReturn type: - subject (
-
get_previous_by_created(*moreargs, **morekwargs)¶
-
get_random_variant()[source]¶ Return one of the object’s variants chosen in a random way.
Warning
There is a reason why a
random.Randomgenerator is created in every call: usingrandom.choice()used use the same generator every time because of it is not really a function but a method of a hidden instance ofrandom.Random, defined inrandom. Debugging we could see that the instance’s internal state was always the same, thus the output will not be random!Also,
random.Random.jumpahead()seemed to be the solution but it is not recommended and was removed in Python 3.Returns: variant Return type: basestring
-
variants¶
-
classmethod
-
class
splango.models.ExperimentReport(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelA report on the results of an experiment.
-
experiment¶
-
-
class
splango.models.Goal(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelAn experiment goal, that is what we are waiting to happen.
-
get_next_by_created(*moreargs, **morekwargs)¶
-
get_previous_by_created(*moreargs, **morekwargs)¶
-
get_records_count_per_variant(experiment)[source]¶ Get the goal records count and the respective percentage per variant.
>> goal.get_records_count_per_variant(experiment) {8: (1, 25.0), 1: (2, 50.0), 2: (0, 0.0), 6: (1, 25.0), 9: (0, 0.0)}Parameters: experiment ( Experiment) –Returns: count of GoalRecordobjects and percentage for each variant ofexperimentReturn type: dict
-
get_records_total(experiment)[source]¶ Get the goal records total for an experiment, including all its variants
-
goalrecord_set¶
-
subject_set¶
-
-
class
splango.models.GoalRecord(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelAssociate the goal reached by a subject with that subject.
-
get_next_by_created(*moreargs, **morekwargs)¶
-
get_previous_by_created(*moreargs, **morekwargs)¶
-
goal¶
-
subject¶
-
-
class
splango.models.Subject(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelAn experimental subject, possibly also a registered user (at creation or later on.
-
enrollment_set¶
-
get_next_by_created(*moreargs, **morekwargs)¶
-
get_previous_by_created(*moreargs, **morekwargs)¶
-
get_variants()[source]¶ Return all the variants shown to this subject.
The relationship is established through
Enrollment, which has foreign keys to bothVariantandSubject.See also
See analogous method
Variant.get_subjects().Returns: the variants Return type: queryset of Variant
-
goalrecord_set¶
-
goals¶
-
is_registered_user()[source]¶ Is this subject associated to a registered user?
Returns: True if subject is a registered user i.e. associated to a django.contrib.auth.models.UserReturn type: bool
-
merge_into(other_subject)[source]¶ Move the enrollments and goal records associated with this subject into
other_subject, preservingother_subject‘s enrollments in case of conflict.
-
registered_as¶
-
-
class
splango.models.Variant(*args, **kwargs)[source]¶ Bases:
django.db.models.base.ModelAn Experiment Variant, with optional weight
(The weight is not considered at the moment)
-
enrollment_set¶
-
experiment¶
-
get_goal_records(goal)[source]¶ Return all the records of
goalfor this variant.Parameters: goal ( Goal) –Returns: the goal records Return type: queryset of GoalRecord
-
get_subjects()[source]¶ Return all the subjects to whom this variant was shown.
The relationship is established through
Enrollment, which has foreign keys to bothVariantandSubject.See also
See analogous method
Subject.get_variants().Returns: the subjects Return type: queryset of Subject
-
utils Module¶
Utilities for project Splango.
-
splango.utils.is_first_visit(request)[source]¶ Tell whether it is the first visit by
request‘s visitor.Current algorithm is very basic. It performs the following nested checks:
- if
userinrequestis authenticated - if there is a HTTP_REFERER
- if
request‘s host matches the referer
Parameters: request ( django.http.HttpRequest) – HTTP requestReturns: True if this requestis the first one byrequest‘s visitorReturn type: bool - if
-
splango.utils.replace_insensitive(string, target, replacement)[source]¶ Similar to string.replace() but is case insensitive
Code borrowed from
debug_toolbarand http://forums.devshed.com/python-programming-11/case-insensitive-string-replace-490921.html
views Module¶
-
splango.views.experiment_detail(request, *args, **kwargs)[source]¶ Show the experiment and its reports.
-
splango.views.experiment_goal_report(request, *args, **kwargs)[source]¶ Goal results for all the variants in a experiment.
Parameters: - request –
- exp_name – The name of the experiment
- goal_name – The name of the goal
Returns:
-
splango.views.experiment_log(request, *args, **kwargs)[source]¶ Show an enrollment, that dentifies which variant a subject is assigned to in a given experiment.
In the response, it returns the experiment itself; the activities, that shows what goals reached by the subject, with the given variant, and the title, that shows the activity in string format.
Returns: The experiment log response