splango Package

splango Package

class splango.__init__.RequestExperimentManager(request)[source]
declare_and_enroll(exp_name, variants)[source]
enqueue(action, params)[source]
finish(response)[source]

Decide what to do if subject is human or not.

get_subject()[source]
log_goal(goal_name, extra=None)[source]
process_from_queue(action, params)[source]

middleware Module

class splango.middleware.ExperimentsMiddleware[source]
process_request(request)[source]

Assign the Experiment Manager to the request.

process_response(request, response)[source]

Retrieve the Experiment Manager from the request and assign it to the response.

models Module

class splango.models.Enrollment(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Identifies 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.Model

A 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 Enrollment object for subject.

Only if the object is to be created will variant be used. If variant is 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 subject

Return type:

Enrollment

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.Random generator is created in every call: using random.choice() used use the same generator every time because of it is not really a function but a method of a hidden instance of random.Random, defined in random. 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
get_variants()[source]
variants
variants_commasep()[source]
class splango.models.ExperimentReport(*args, **kwargs)[source]

Bases: django.db.models.base.Model

A report on the results of an experiment.

experiment
generate()[source]

Generate the report for experiment.

Generate the report of a experiment goals and variants.

Associate each variant with a goal, and associate the variant count too.

Returns:A dict with goals, variants and variants counts associated to each goal
get_funnel_goals()[source]
class splango.models.Goal(*args, **kwargs)[source]

Bases: django.db.models.base.Model

An 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 GoalRecord objects and percentage for each variant of experiment
Return 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.Model

Associate the goal reached by a subject with that subject.

static extract_request_info(request)[source]
get_next_by_created(*moreargs, **morekwargs)
get_previous_by_created(*moreargs, **morekwargs)
goal
classmethod record(subject, goal_name, request_info, extra=None)[source]
classmethod record_user_goal(user, goal_name)[source]
subject
class splango.models.Subject(*args, **kwargs)[source]

Bases: django.db.models.base.Model

An 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 both Variant and Subject.

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.User
Return type:bool
merge_into(other_subject)[source]

Move the enrollments and goal records associated with this subject into other_subject, preserving other_subject‘s enrollments in case of conflict.

registered_as
class splango.models.Variant(*args, **kwargs)[source]

Bases: django.db.models.base.Model

An 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 goal for 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 both Variant and Subject.

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 user in request is authenticated
  • if there is a HTTP_REFERER
  • if request‘s host matches the referer
Parameters:request (django.http.HttpRequest) – HTTP request
Returns:True if this request is the first one by request‘s visitor
Return type:bool
splango.utils.replace_insensitive(string, target, replacement)[source]

Similar to string.replace() but is case insensitive

Code borrowed from debug_toolbar and 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
splango.views.experiment_report(request, *args, **kwargs)[source]

Show the experiment report.

splango.views.experiments_overview(request, *args, **kwargs)[source]

Show experiments list.

splango.views.goal_report(request, *args, **kwargs)[source]

Goal results for all the variants.

Parameters:goal_name – The name of the goal
Returns: