Skip to content

Commit

Permalink
Replace use of deprecated event_field message option in test templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjayVas committed Jul 6, 2023
1 parent 25faf09 commit 61dbb5e
Show file tree
Hide file tree
Showing 18 changed files with 137 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ path to the executable.
--measurement-ref-id=9999 \
--data-provider=dataProviders/1 \
--event-group=dataProviders/1/eventGroups/1 \
--event-filter="video_ad.age.value == 1" \
--event-filter="video_ad.age == 1" \
--event-start-time=2022-05-22T01:00:00.000Z \
--event-end-time=2022-05-24T05:00:00.000Z \
--event-group=dataProviders/1/eventGroups/2 \
--event-filter="video_ad.age.value == 2" \
--event-filter="video_ad.age == 2" \
--event-start-time=2022-05-22T01:22:32.250Z \
--event-end-time=2022-05-23T03:14:55.450Z \
--data-provider=dataProviders/2 \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ package org.wfanet.measurement.eventdataprovider.privacybudgetmanagement.testing
import com.google.protobuf.Message
import org.projectnessie.cel.Program
import org.wfanet.measurement.api.v2alpha.event_templates.testing.Person
import org.wfanet.measurement.api.v2alpha.event_templates.testing.PersonKt.ageGroupField
import org.wfanet.measurement.api.v2alpha.event_templates.testing.PersonKt.genderField
import org.wfanet.measurement.api.v2alpha.event_templates.testing.TestEvent
import org.wfanet.measurement.api.v2alpha.event_templates.testing.person
import org.wfanet.measurement.api.v2alpha.event_templates.testing.testEvent
Expand All @@ -37,7 +35,7 @@ class TestPrivacyBucketMapper : PrivacyBucketMapper {
compileProgram(
TestEvent.getDescriptor(),
filterExpression,
setOf("person.age_group.value", "person.gender.value")
setOf("person.age_group", "person.gender")
)
} catch (e: EventFilterValidationException) {
throw PrivacyBudgetManagerException(
Expand All @@ -49,21 +47,17 @@ class TestPrivacyBucketMapper : PrivacyBucketMapper {
override fun toEventMessage(privacyBucketGroup: PrivacyBucketGroup): Message {
return testEvent {
person = person {
ageGroup = ageGroupField {
value =
when (privacyBucketGroup.ageGroup) {
AgeGroup.RANGE_18_34 -> Person.AgeGroup.YEARS_18_TO_34
AgeGroup.RANGE_35_54 -> Person.AgeGroup.YEARS_35_TO_54
AgeGroup.ABOVE_54 -> Person.AgeGroup.YEARS_55_PLUS
}
}
gender = genderField {
value =
when (privacyBucketGroup.gender) {
Gender.MALE -> Person.Gender.MALE
Gender.FEMALE -> Person.Gender.FEMALE
}
}
ageGroup =
when (privacyBucketGroup.ageGroup) {
AgeGroup.RANGE_18_34 -> Person.AgeGroup.YEARS_18_TO_34
AgeGroup.RANGE_35_54 -> Person.AgeGroup.YEARS_35_TO_54
AgeGroup.ABOVE_54 -> Person.AgeGroup.YEARS_55_PLUS
}
gender =
when (privacyBucketGroup.gender) {
Gender.MALE -> Person.Gender.MALE
Gender.FEMALE -> Person.Gender.FEMALE
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ const val DUCHY_MILL_PARALLELISM = 3
*/
val EVENT_TEMPLATES_TO_FILTERS_MAP =
mapOf(
"$TEMPLATE_PREFIX.Video" to "video_ad.viewed_fraction.value > 0.25",
"$TEMPLATE_PREFIX.Person" to "person.gender.value == $TEMPLATE_PREFIX.Person.Gender.MALE"
"$TEMPLATE_PREFIX.Video" to "video_ad.viewed_fraction > 0.25",
"$TEMPLATE_PREFIX.Person" to "person.gender == $TEMPLATE_PREFIX.Person.Gender.MALE"
)
const val MC_DISPLAY_NAME = "mc"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object EventFilters {
val EVENT_TEMPLATES_TO_FILTERS_MAP =
mapOf(
"$TEMPLATE_PREFIX.Person" to
"person.age_group.value == $TEMPLATE_PREFIX.Person.AgeGroup.YEARS_18_TO_34"
"person.age_group == $TEMPLATE_PREFIX.Person.AgeGroup.YEARS_18_TO_34"
)

val VID_SAMPLER_HASH_FUNCTION: HashFunction = Hashing.farmHashFingerprint64()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ import java.util.UUID
import java.util.logging.Logger
import org.wfanet.measurement.api.v2alpha.RequisitionSpec.EventFilter
import org.wfanet.measurement.api.v2alpha.event_templates.testing.Person
import org.wfanet.measurement.api.v2alpha.event_templates.testing.PersonKt
import org.wfanet.measurement.api.v2alpha.event_templates.testing.TestEvent
import org.wfanet.measurement.api.v2alpha.event_templates.testing.VideoKt
import org.wfanet.measurement.api.v2alpha.event_templates.testing.person
import org.wfanet.measurement.api.v2alpha.event_templates.testing.testEvent
import org.wfanet.measurement.api.v2alpha.event_templates.testing.video
Expand Down Expand Up @@ -136,24 +134,21 @@ class BigQueryEventQuery(
person = person {
vid = get("vid").longValue
if (gender != null) {
this.gender = PersonKt.genderField { value = gender }
this.gender = gender
}
if (ageGroup != null) {
this.ageGroup = PersonKt.ageGroupField { value = ageGroup }
this.ageGroup = ageGroup
}
if (socialGradeGroup != null) {
socialGrade = PersonKt.socialGradeGroupField { value = socialGradeGroup }
this.socialGradeGroup = socialGradeGroup
}
}
videoAd = video {
viewedFraction =
VideoKt.viewedFractionField {
value =
if (complete) {
1.0
} else {
0.0
}
if (complete) {
1.0
} else {
0.0
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import java.time.format.DateTimeFormatter
import java.util.Locale
import java.util.logging.Logger
import org.wfanet.measurement.api.v2alpha.event_templates.testing.Person
import org.wfanet.measurement.api.v2alpha.event_templates.testing.PersonKt
import org.wfanet.measurement.api.v2alpha.event_templates.testing.TestEvent
import org.wfanet.measurement.api.v2alpha.event_templates.testing.VideoKt.viewedFractionField
import org.wfanet.measurement.api.v2alpha.event_templates.testing.person
import org.wfanet.measurement.api.v2alpha.event_templates.testing.testEvent
import org.wfanet.measurement.api.v2alpha.event_templates.testing.video
Expand Down Expand Up @@ -102,25 +100,23 @@ class CsvEventQuery(publisherId: Int, file: File) :
person = person {
this.vid = vid
if (gender != null) {
this.gender = PersonKt.genderField { value = gender }
this.gender = gender
}
if (ageGroup != null) {
this.ageGroup = PersonKt.ageGroupField { value = ageGroup }
this.ageGroup = ageGroup
}
if (socialGradeGroup != null) {
socialGrade = PersonKt.socialGradeGroupField { value = socialGradeGroup }
this.socialGradeGroup = socialGradeGroup
}
}
videoAd = video {
if (complete != null) {
viewedFraction = viewedFractionField {
value =
if (complete) {
1.0
} else {
0.0
}
}
viewedFraction =
if (complete) {
1.0
} else {
0.0
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Reporting \
--event-group=measurementConsumers/VCTqwV_vFXw/dataProviders/1/eventGroups/1 \
--event-group=measurementConsumers/VCTqwV_vFXw/dataProviders/1/eventGroups/2 \
--event-group=measurementConsumers/VCTqwV_vFXw/dataProviders/2/eventGroups/1 \
--filter='video_ad.age.value == 1' --display-name='test-reporting-set'
--filter='video_ad.age == 1' --display-name='test-reporting-set'
```

#### list
Expand Down Expand Up @@ -64,9 +64,9 @@ Reporting \
--idempotency-key="report001" \
--parent=measurementConsumers/777 \
--event-group-key=$EVENT_GROUP_NAME_1 \
--event-group-value="video_ad.age.value == 1" \
--event-group-value="video_ad.age == 1" \
--event-group-key=$EVENT_GROUP_NAME_2 \
--event-group-value="video_ad.age.value == 12" \
--event-group-value="video_ad.age == 12" \
--interval-start-time=2017-01-15T01:30:15.01Z \
--interval-end-time=2018-10-27T23:19:12.99Z \
--interval-start-time=2019-01-19T09:48:35.57Z \
Expand Down Expand Up @@ -126,6 +126,7 @@ Reporting \
### event-groups

#### list

```shell
Reporting \
--tls-cert-file=secretfiles/mc_tls.pem \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@ message Banner {
description: "A simple template for events related to a banner ad."
};

message ViewableField {
option (.wfa.measurement.api.v2alpha.event_field) = {
display_name: "Viewable"
};

bool value = 1;
}
// Whether the ad was shown for more than 2 seconds with at least 50% of the
// pixels on the screen. If not specified, viewability was not determined.
ViewableField viewable = 1;
bool viewable = 1 [(.wfa.measurement.api.v2alpha.template_field) = {
display_name: "Viewable"
description: "Whether the ad was shown for more than 2 seconds with at "
"least 50% of the pixels on the screen. If not specified, "
"viewability was not determined."
}];
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,48 +32,34 @@ message Person {
description: "Common fields about a person"
};

int64 vid = 1;

enum Gender {
GENDER_UNSPECIFIED = 0;
MALE = 1;
FEMALE = 2;
}
message GenderField {
option (.wfa.measurement.api.v2alpha.event_field) = {
display_name: "Gender"
};

Gender value = 1;
}
Gender gender = 2 [
(.wfa.measurement.api.v2alpha.template_field) = { display_name: "Gender" }
];

enum AgeGroup {
AGE_GROUP_UNSPECIFIED = 0;
YEARS_18_TO_34 = 1;
YEARS_35_TO_54 = 2;
YEARS_55_PLUS = 3;
}
message AgeGroupField {
option (.wfa.measurement.api.v2alpha.event_field) = {
display_name: "Age Group"
};

AgeGroup value = 1;
}
AgeGroup age_group = 3 [(.wfa.measurement.api.v2alpha.template_field) = {
display_name: "Age Group"
}];

enum SocialGradeGroup {
SOCIAL_GRADE_GROUP_UNSPECIFIED = 0;
A_B_C1 = 1;
C2_D_E = 2;
}
message SocialGradeGroupField {
option (.wfa.measurement.api.v2alpha.event_field) = {
display_name: "Social Grade"
};

SocialGradeGroup value = 1;
}

int64 vid = 1;
GenderField gender = 2;
AgeGroupField age_group = 3;
SocialGradeGroupField social_grade = 4;
SocialGradeGroup social_grade_group = 4
[(.wfa.measurement.api.v2alpha.template_field) = {
display_name: "Social Grade"
}];
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,13 @@ message Video {
description: "A simple template for events related to a video ad."
};

message LengthField {
option (.wfa.measurement.api.v2alpha.event_field) = {
display_name: "Video Length"
};

google.protobuf.Duration value = 1;
}
LengthField length = 1;

message ViewedFractionField {
option (.wfa.measurement.api.v2alpha.event_field) = {
display_name: "Viewed Fraction"
};

// In the range [0, 1] of what fraction of the video was viewed.
double value = 1;
}
// Fraction of video that was viewed.
ViewedFractionField viewed_fraction = 2;
google.protobuf.Duration length = 1
[(.wfa.measurement.api.v2alpha.template_field) = {
display_name: "Video Length"
}];

double viewed_fraction = 2 [(.wfa.measurement.api.v2alpha.template_field) = {
display_name: "Viewed Fraction"
description: "Fraction of the video that was viewed in the range [0, 1]"
}];
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.wfanet.measurement.api.v2alpha.event_templates.testing.Person
import org.wfanet.measurement.api.v2alpha.event_templates.testing.PersonKt
import org.wfanet.measurement.api.v2alpha.event_templates.testing.TestEvent
import org.wfanet.measurement.api.v2alpha.event_templates.testing.VideoKt.lengthField
import org.wfanet.measurement.api.v2alpha.event_templates.testing.person
import org.wfanet.measurement.api.v2alpha.event_templates.testing.testEvent
import org.wfanet.measurement.api.v2alpha.event_templates.testing.video
Expand All @@ -36,32 +34,28 @@ import org.wfanet.measurement.eventdataprovider.eventfiltration.validation.Event
class EventFiltersTest {
private fun exampleEventWithAge(): Message {
return testEvent {
person = person {
ageGroup = PersonKt.ageGroupField { value = Person.AgeGroup.YEARS_18_TO_34 }
}
videoAd = video {
length = lengthField { value = Duration.ofMinutes(5).withSeconds(11).toProtoDuration() }
}
person = person { ageGroup = Person.AgeGroup.YEARS_18_TO_34 }
videoAd = video { length = Duration.ofMinutes(5).withSeconds(11).toProtoDuration() }
}
}

@Test
fun `matches returns true when filter expression matches event`() {
val program = compileProgram(TestEvent.getDescriptor(), "person.age_group.value == 1")
val program = compileProgram(TestEvent.getDescriptor(), "person.age_group == 1")
val event = exampleEventWithAge()
assertThat(EventFilters.matches(event, program)).isTrue()
}

@Test
fun `matches returns false when filter expression does not match event`() {
val program = compileProgram(TestEvent.getDescriptor(), "person.age_group.value == 2")
val program = compileProgram(TestEvent.getDescriptor(), "person.age_group == 2")
val event = exampleEventWithAge()
assertThat(EventFilters.matches(event, program)).isFalse()
}

@Test
fun `matches returns true for default value when evaluated field is not set`() {
val program = compileProgram(TestEvent.getDescriptor(), "person.age_group.value == 0")
val program = compileProgram(TestEvent.getDescriptor(), "person.age_group == 0")
val event = TestEvent.getDefaultInstance()
assertThat(EventFilters.matches(event, program)).isTrue()
}
Expand All @@ -84,7 +78,7 @@ class EventFiltersTest {
fun `compileProgram throws error when expression is not a conditional`() {
val e =
assertFailsWith(EventFilterValidationException::class) {
compileProgram(TestEvent.getDescriptor(), "person.age_group.value")
compileProgram(TestEvent.getDescriptor(), "person.age_group")
}
assertThat(e.code).isEqualTo(EventFilterValidationException.Code.EXPRESSION_IS_NOT_CONDITIONAL)
}
Expand Down
Loading

0 comments on commit 61dbb5e

Please sign in to comment.