Skip to content

Commit

Permalink
added targeting preset values fixes mozilla#3124 (mozilla#3129)
Browse files Browse the repository at this point in the history
* added targeting preset values fixes mozilla#3124

* formatting

* formatting

Co-authored-by: Jared Lockhart <119884+jaredlockhart@users.noreply.github.com>
  • Loading branch information
tiftran and jaredlockhart authored Jul 27, 2020
1 parent 6c750a3 commit 13a39a4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
27 changes: 26 additions & 1 deletion app/experimenter/experiments/api/v4/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,29 @@ def get_filter_expression(self, obj):
].format(minFirefoxVersion=obj.firefox_min_version)

def get_targeting(self, obj):
return NIMBUS_DATA["Audiences"][obj.audience]["targeting"]
if ExperimentBucketRange.objects.filter(experiment=obj).exists():
bucket_range = ExperimentBucketRange.objects.get(experiment=obj)
bucket_namespace = bucket_range.namespace.name
bucket_start = bucket_range.start

bucket_config = NIMBUS_DATA["ExperimentDesignPresets"]["empty_aa"]["preset"][
"arguments"
]["bucketConfig"]

randomization_unit = bucket_config["randomizationUnit"]
bucket_count = bucket_config["count"]
bucket_total = bucket_config["total"]
audience_targeting = NIMBUS_DATA["Audiences"][obj.audience]["targeting"]

targeting_string = NIMBUS_DATA["ExperimentDesignPresets"]["empty_aa"][
"preset"
]["targeting"]

return targeting_string.format(
bucketNamespace=bucket_namespace,
bucketStart=bucket_start,
randomizationUnit=randomization_unit,
bucketCount=bucket_count,
bucketTotal=bucket_total,
audienceTargeting=audience_targeting,
)
9 changes: 5 additions & 4 deletions app/experimenter/experiments/tests/api/v4/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ def test_serializer_outputs_expected_schema(self):
{
"id": normandy_slug,
"filter_expression": "env.version|versionCompare('80.0') >= 0",
"targeting": "localeLanguageCode == 'en' && region == 'US'"
" && browserSettings.update.channel == 'release'",
"targeting": None,
"enabled": True,
},
)
Expand Down Expand Up @@ -116,8 +115,10 @@ def test_serializer_outputs_expected_schema_with_nameSpace_bucket(self):
{
"id": normandy_slug,
"filter_expression": "env.version|versionCompare('80.0') >= 0",
"targeting": "localeLanguageCode == 'en' && region == 'US'"
" && browserSettings.update.channel == 'release'",
"targeting": '[userId, "experimenter-normandy-slug"]'
"|bucketSample(0, 100, 10000) "
"&& localeLanguageCode == 'en' && region == 'US' "
"&& browserSettings.update.channel == 'release'",
"enabled": True,
},
)
Expand Down

0 comments on commit 13a39a4

Please sign in to comment.