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 #147

Conversation

rashidsp
Copy link
Contributor

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.

  • Experiments can now be evaluated on behalf of either complex audienceConditions or simple audienceIds
  • Audience conditions can either be a string defining array of conditions or simply a string of audience id which is then converted to an OR condition.
  • Priority will be given to audienceConditions if both audienceIds and audienceConditions are present.

Test plan

  • test_optimizely - Added unit tests for APIs that pass/fail using various complex audiences with different match types.
  • Ran complex audiences test cases in compatibility test suite.

Issues

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 305be7e on rashid/audience-combinations into 80569a1 on rashid/audience-match-type-project-config.

@coveralls
Copy link

coveralls commented Dec 24, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 2b250d3 on rashid/audience-combinations into 80569a1 on rashid/audience-match-type-project-config.

@rashidsp rashidsp requested review from mikeproeng37 and msohailhussain and removed request for mikeproeng37 December 24, 2018 14:54
@rashidsp rashidsp added the WIP Work in progress label Dec 24, 2018
Copy link
Contributor

@oakbani oakbani left a comment

Choose a reason for hiding this comment

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

Overall looks good. Minor feedback.

@@ -33,25 +33,29 @@ def user_in_experiment?(config, experiment, attributes)
#
# Returns boolean representing if user satisfies audience conditions for any of the audiences or not.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. Update doc. 'any' isn't necessarily true anymore since now we have audiences ANDed as well.

custom_attribute_condition_evaluator = CustomAttributeConditionEvaluator.new(attributes)
return custom_attribute_condition_evaluator.evaluate(condition)
evaluate_custom_attr = lambda do |condition|
custom_attr_condition_evaluator = CustomAttributeConditionEvaluator.new(attributes)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you declare this once outside and reuse it here?

audience = config.get_audience_from_id(audience_id)
return nil unless audience

audience_conditions = audience['conditions']
audience_conditions = JSON.parse(audience_conditions) if audience_conditions.is_a?(String)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then we will have to update parser tests; would be an irrelevant change.
Leaving it for separate PR.

it 'should return nil when complex audience conditions do not match' do
user_attributes = {'house' => 'Hufflepuff', 'lasers' => 45.5}
variation_to_return = @project_typed_audience_instance.config.get_variation_from_id('audience_combinations_experiment', '1423767504')
allow(@project_typed_audience_instance.decision_service.bucketer).to receive(:bucket).and_return(variation_to_return)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. Can remove the return part

}, {
entity_id: Optimizely::Helpers::Constants::CONTROL_ATTRIBUTES['BOT_FILTERING'],
key: Optimizely::Helpers::Constants::CONTROL_ATTRIBUTES['BOT_FILTERING'],
type: 'custom', value: false
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. value on new line

expect(Optimizely::Audience.user_in_experiment?(@project_instance.config,
experiment,
nil)).to be false
expect(Optimizely::CustomAttributeConditionEvaluator).to have_received(:new).with({}).twice
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. Add a comment that this asserts nil attributes default to {}

@rashidsp rashidsp removed the WIP Work in progress label Dec 27, 2018
@aliabbasrizvi aliabbasrizvi requested a review from a team December 28, 2018 00:30
Copy link
Contributor

@mikeproeng37 mikeproeng37 left a comment

Choose a reason for hiding this comment

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

Nice, thanks for updating the license headers as well. It is a bit confusing that we are merging into this branch: audience-match-type-project-config as I see project config as a part of audience-match-types. Anyway, we can follow up offline about which branch to run the integration tests on.

@mikeproeng37 mikeproeng37 merged commit 0c6c795 into rashid/audience-match-type-project-config Jan 2, 2019
@rashidsp rashidsp deleted the rashid/audience-combinations branch January 9, 2019 15:03
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