Skip to content

Commit be2130d

Browse files
authored
Ingest categorical coefficients as an object (Map) (#56)
* ingest categorial coefficients as object * bump version
1 parent 4eca261 commit be2130d

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>cloud.eppo</groupId>
88
<artifactId>eppo-server-sdk</artifactId>
9-
<version>2.4.4</version>
9+
<version>2.4.5</version>
1010

1111
<name>${project.groupId}:${project.artifactId}</name>
1212
<description>Eppo Server-Side SDK for Java</description>

src/main/java/com/eppo/sdk/deserializer/BanditsDeserializer.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,13 @@ private Map<String, BanditCategoricalAttributeCoefficients> parseCategoricalAttr
112112
categoricalAttributeCoefficientsArrayNode.iterator().forEachRemaining(categoricalAttributeCoefficientsNode -> {
113113
String attributeKey = categoricalAttributeCoefficientsNode.get("attributeKey").asText();
114114
Double missingValueCoefficient = categoricalAttributeCoefficientsNode.get("missingValueCoefficient").asDouble();
115+
115116
Map<String, Double> valueCoefficients = new HashMap<>();
116-
JsonNode valuesNode = categoricalAttributeCoefficientsNode.get("values");
117-
valuesNode.iterator().forEachRemaining(valueNode -> {
118-
String value = valueNode.get("value").asText();
119-
Double coefficient = valueNode.get("coefficient").asDouble();
117+
JsonNode valuesNode = categoricalAttributeCoefficientsNode.get("valueCoefficients");
118+
Iterator<Map.Entry<String, JsonNode>> coefficientIterator = valuesNode.fields();
119+
coefficientIterator.forEachRemaining(field -> {
120+
String value = field.getKey();
121+
Double coefficient = field.getValue().asDouble();
120122
valueCoefficients.put(value, coefficient);
121123
});
122124

src/test/resources/bandits/bandits-parameters-1.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
"actionCategoricalCoefficients": [
2525
{
2626
"attributeKey": "loyalty_tier",
27-
"values": [
28-
{ "value": "gold", "coefficient": 4.5 },
29-
{ "value": "silver", "coefficient": 3.2 },
30-
{ "value": "bronze", "coefficient": 1.9 }
31-
],
27+
"valueCoefficients": {
28+
"gold": 4.5,
29+
"silver": 3.2,
30+
"bronze": 1.9
31+
},
3232
"missingValueCoefficient": 0.0
3333
}
3434
],
@@ -42,10 +42,10 @@
4242
"subjectCategoricalCoefficients": [
4343
{
4444
"attributeKey": "gender_identity",
45-
"values": [
46-
{ "value": "female", "coefficient": 0.5 },
47-
{ "value": "male", "coefficient": -0.5 }
48-
],
45+
"valueCoefficients": {
46+
"female": 0.5,
47+
"male": -0.5
48+
},
4949
"missingValueCoefficient": 2.3
5050
}
5151
]
@@ -63,21 +63,21 @@
6363
"actionCategoricalCoefficients": [
6464
{
6565
"attributeKey": "purchased_last_30_days",
66-
"values": [
67-
{ "value": "true", "coefficient": 9.0 },
68-
{ "value": "false", "coefficient": 0.0 }
69-
],
66+
"valueCoefficients": {
67+
"true": 9.0,
68+
"false": 0.0
69+
},
7070
"missingValueCoefficient": 0.0
7171
}
7272
],
7373
"subjectNumericCoefficients": [],
7474
"subjectCategoricalCoefficients": [
7575
{
7676
"attributeKey": "gender_identity",
77-
"values": [
78-
{ "value": "female", "coefficient": 0.0 },
79-
{ "value": "male", "coefficient": 0.3 }
80-
],
77+
"valueCoefficients": {
78+
"female": 0.0,
79+
"male": 0.3
80+
},
8181
"missingValueCoefficient": 0.45
8282
}
8383
]

0 commit comments

Comments
 (0)