Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat (audiences): Audience combinations #150

Merged
merged 28 commits into from
Dec 19, 2018

Conversation

oakbani
Copy link
Contributor

@oakbani oakbani commented Dec 4, 2018

Summary

This adds support for audience combinations on experiments. If experiment.audienceConditions is present, it will be used as a condition tree where the leaf conditions are audience Ids.

  • The audience evaluator uses the condition tree evaluator on both the experiment audience conditions and the individual audience conditions.
  • The audience evaluator treats conditions trees and flat lists of audience ids (the old format) the same way, because a flat list of audience ids is a valid condition tree with an implicit OR condition.
  • Added a new method to Experiment entity that returns audienceConditions if not None, otherwise returns audience Ids

Test plan

  • test_optimizely - Added unit tests for APIs that pass/fail using various complex audiences with different match types.
  • test_audience - Added new unit tests for calling condition tree and custom attribute evaluators.
  • Ran complex audiences test cases in compatibility test suite.

Issues

oakbani and others added 25 commits October 25, 2018 14:35
… oakbani/audience-match-types-project-config
… oakbani/audience-match-types-project-config
… oakbani/audience-match-types-project-config
… oakbani/audience-match-types-project-config
… oakbani/audience-match-types-project-config
Co-Authored-By: oakbani <owais.akbani92@gmail.com>
… oakbani/audience-match-types-project-config
@@ -50,17 +29,34 @@ def is_user_in_experiment(config, experiment, attributes):
"""

# Return True in case there are no audiences
if not experiment.audienceIds:
audience_conditions = experiment.getAudienceConditionsOrIds()
if not audience_conditions:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: it'd be safer to perform an explicit check

if audience_conditions is None or audience_conditions == []:

especially since the condition tree may be a single leaf node (an audience ID) and that leaf node could (theoretically) be ('').


eval_result = condition_tree_evaluator.evaluate(
audience_conditions,
lambda audienceId: evaluate_audience(audienceId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lambda audienceId: evaluate_audience(audienceId)
evaluate_audience

optimizely/helpers/audience.py Show resolved Hide resolved
Copy link
Contributor

@nchilada nchilada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating! I haven't looked very closely at the unit tests; will rely on the compatibility suite to catch any issues with correctness.


self.assertStrictFalse(audience.is_user_in_experiment(self.project_config, experiment, user_attributes))

def test_is_user_in_experiment__evaluates_audience_Ids(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe delete the underscore in audience_Ids?

@msohailhussain msohailhussain changed the base branch from oakbani/audience-match-types-project-config to master December 18, 2018 20:07
@oakbani oakbani changed the base branch from master to oakbani/audience-match-types-project-config December 19, 2018 04:35
@oakbani oakbani changed the base branch from oakbani/audience-match-types-project-config to master December 19, 2018 04:39
@aliabbasrizvi aliabbasrizvi merged commit a59b08d into master Dec 19, 2018
@aliabbasrizvi aliabbasrizvi deleted the oakbani/audience-combinations-2 branch December 19, 2018 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants