Skip to content

Commit

Permalink
Merge pull request #88 from visenze/feature/ab_test
Browse files Browse the repository at this point in the history
[ES-4362] A/B test experiment response, add vs_attrs_to_get and vs_config request params
  • Loading branch information
thehung111 authored Apr 29, 2022
2 parents 55ecf8b + 97a7e02 commit 667711a
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 22 deletions.
4 changes: 2 additions & 2 deletions doc/ProductSearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ With the release of ViSenze's Catalog system, ViSearch Android SDK will now incl
- Aggregate search results on a product level instead of image level
- Consistent data type in API response with Catalog’s schema

> Current stable version: 2.1.5
> Current stable version: 2.2.0
> Minimum Android SDK Version: API 9, Android 2.3
Expand Down Expand Up @@ -64,7 +64,7 @@ allprojects {
include the dependency in your project using gradle:
```gradle
implementation 'com.github.visenze:visenze-tracking-android:0.2.1'
implementation 'com.github.visenze:visearch-sdk-android:2.1.5'
implementation 'com.github.visenze:visearch-sdk-android:2.2.0'
```

### 1.3 Add User Permissions
Expand Down
4 changes: 2 additions & 2 deletions doc/ViSearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ViSearch is an API that provides accurate, reliable and scalable image search. V

The ViSearch Android SDK is an open source software to provide easy integration of ViSearch Search API with your Android mobile applications. It provides three search methods based on the ViSearch Search API - pre-indexed search, color search and upload search. For source code and references, please visit the [Github Repository](https://github.com/visenze/visearch-sdk-android).

>Current stable version: 2.1.0
>Current stable version: 2.2.0
>Minimum Android SDK Version: API 9, Android 2.3
Expand Down Expand Up @@ -80,7 +80,7 @@ allprojects {
include the dependency in your project using gradle:
```gradle
implementation 'com.github.visenze:visenze-tracking-android:0.2.1'
implementation 'com.github.visenze:visearch-sdk-android:2.0.1'
implementation 'com.github.visenze:visearch-sdk-android:2.2.0'
```

### 1.3 Add User Permissions
Expand Down
6 changes: 3 additions & 3 deletions visearch-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ plugins {
}

def versionMajor = 2
def versionMinor = 1
def versionPatch = 5
version = '2.1.5'
def versionMinor = 2
def versionPatch = 0
version = '2.2.0'

android {
compileSdkVersion 29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,21 +397,23 @@ public void setVaS2(String vaS2) {
@Expose(deserialize = false, serialize = false)
private List<String> attrsToGet;

@SerializedName("vs_attrs_to_get")
@Expose(deserialize = false, serialize = false)
private List<String> vsAttrsToGet;

@Expose(deserialize = false, serialize = false)
private Map<String, String> filters;

@Expose(deserialize = false, serialize = false)
private Map<String, String> textFilters;


@Expose(deserialize = false, serialize = false)
private Map<String, String> vsConfig;

@SerializedName("custom_map")
@Expose(deserialize = false, serialize = false)
private Map<String, String> customParams;



public Map<String, String> getFilters() {
return filters;
}
Expand All @@ -428,6 +430,14 @@ public void setTextFilters(Map<String, String> textFilters) {
this.textFilters = textFilters;
}

public Map<String, String> getVsConfig() {
return vsConfig;
}

public void setVsConfig(Map<String, String> vsConfig) {
this.vsConfig = vsConfig;
}

public List<String> getAttrsToGet() {
return attrsToGet;
}
Expand All @@ -436,6 +446,14 @@ public void setAttrsToGet(List<String> attrsToGet) {
this.attrsToGet = attrsToGet;
}

public List<String> getVsAttrsToGet() {
return vsAttrsToGet;
}

public void setVsAttrsToGet(List<String> vsAttrsToGet) {
this.vsAttrsToGet = vsAttrsToGet;
}

public List<String> getFacets() {
return facets;
}
Expand Down Expand Up @@ -481,16 +499,6 @@ public RetrofitQueryMap getQueryMap() {
}
}

if(customParams != null) {
Set<Map.Entry<String, String>> set = customParams.entrySet();
for(Map.Entry<String, String> entry : set) {
String key = entry.getKey();
String val = entry.getValue();
ret.put(key, val);
}
}


if(filters != null) {
List<String> list = formatToList(filters);
ret.put("filters", list);
Expand All @@ -501,6 +509,20 @@ public RetrofitQueryMap getQueryMap() {
ret.put("text_filters", list);
}

if (vsConfig != null) {
List<String> list = formatToList(vsConfig);
ret.put("vs_config", list);
}

if(customParams != null) {
Set<Map.Entry<String, String>> set = customParams.entrySet();
for(Map.Entry<String, String> entry : set) {
String key = entry.getKey();
String val = entry.getValue();
ret.put(key, val);
}
}

return ret;
}

Expand All @@ -510,7 +532,7 @@ private List<String> formatToList(Map<String, String> params) {
for(Map.Entry<String, String>entry : set) {
String key = entry.getKey();
String val = entry.getValue();
ret.add(key+":"+val);
ret.add(key + ":" + val);
}
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public class ProductSearchByIdParams extends BaseProductSearchParams {
@SerializedName("alt_limit")
private Integer altLimit;

@SerializedName("strategy_id")
private Integer strategyId;

public String getProductId() {
return productId;
}
Expand All @@ -23,6 +26,18 @@ public void setAltLimit(Integer altLimit) {
this.altLimit = altLimit;
}

public void setProductId(String productId) {
this.productId = productId;
}

public Integer getStrategyId() {
return strategyId;
}

public void setStrategyId(Integer strategyId) {
this.strategyId = strategyId;
}

public ProductSearchByIdParams(String productId) {
this.productId = productId;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.visenze.visearch.android.model;

import com.google.gson.annotations.SerializedName;

public class Experiment {

@SerializedName("experiment_id")
private int experimentId;

@SerializedName("variant_id")
private int variantId;

@SerializedName("variant_name")
private String variantName;

@SerializedName("strategy_id")
private Integer strategyId;

@SerializedName("experiment_no_recommendation")
private boolean expNoRecommendation;

public int getExperimentId() {
return experimentId;
}

public void setExperimentId(int experimentId) {
this.experimentId = experimentId;
}

public int getVariantId() {
return variantId;
}

public void setVariantId(int variantId) {
this.variantId = variantId;
}

public String getVariantName() {
return variantName;
}

public void setVariantName(String variantName) {
this.variantName = variantName;
}

public Integer getStrategyId() {
return strategyId;
}

public void setStrategyId(Integer strategyId) {
this.strategyId = strategyId;
}

public boolean isExpNoRecommendation() {
return expNoRecommendation;
}

public void setExpNoRecommendation(boolean expNoRecommendation) {
this.expNoRecommendation = expNoRecommendation;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class Product {
@SerializedName("data")
private Map<String, Object> data;

@SerializedName("vs_data")
private Map<String, Object> vsData;

@SerializedName("score")
private Float score;

Expand Down Expand Up @@ -66,6 +69,14 @@ public void setData(Map<String, Object> data) {
this.data = data;
}

public Map<String, Object> getVsData() {
return vsData;
}

public void setVsData(Map<String, Object> vsData) {
this.vsData = vsData;
}

public Float getScore() {
return score;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class ProductResponse {
@SerializedName("strategy")
private Strategy strategy;

@SerializedName("experiment")
private Experiment experiment;

public String getStatus() {
return status;
}
Expand Down Expand Up @@ -96,7 +99,7 @@ public List<Product> getProducts() {
return products;
}

public void setImageResults(List<Product> products) {
public void setProducts(List<Product> products) {
this.products = products;
}

Expand Down Expand Up @@ -171,4 +174,20 @@ public Strategy getStrategy() {
public void setStrategy(Strategy strategy) {
this.strategy = strategy;
}

public Experiment getExperiment() {
return experiment;
}

public void setExperiment(Experiment experiment) {
this.experiment = experiment;
}

/**
*
* @return whether the results are empty due to A/B test setting of returning no recommendations
*/
public boolean experimentNoRecommendation() {
return (experiment != null && experiment.isExpNoRecommendation());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.visenze.visearch.android.model.ErrorData;
import com.visenze.visearch.android.model.Experiment;
import com.visenze.visearch.android.model.ImageResult;
import com.visenze.visearch.android.model.ObjectResult;
import com.visenze.visearch.android.model.ProductObject;
Expand All @@ -23,7 +24,9 @@
import java.util.HashMap;
import java.util.Map;

import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;

@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP, manifest = Config.NONE)
Expand Down Expand Up @@ -470,4 +473,61 @@ public void onSearchResult(ProductResponse response, ErrorData error) {

}

@Test
public void testExperimentResponse() {
String json =
"{\n" +
" \"reqid\": \"01806a667776c6f8a31c28105fd99b\",\n" +
" \"status\": \"OK\",\n" +
" \"method\": \"product/recommendations\",\n" +
" \"page\": 1,\n" +
" \"limit\": 10,\n" +
" \"total\": 2,\n" +
" \"product_types\": [],\n" +
" \"result\": [\n" +
" ],\n" +
" \"strategy\": {\n" +
" \"id\": 3,\n" +
" \"name\": \"test\",\n" +
" \"algorithm\": \"VSR\"\n" +
" },\n" +
" \"experiment\": {\n" +
" \"experiment_id\": 522,\n" +
" \"variant_id\": 2019,\n" +
" \"strategy_id\": 3,\n" +
" \"experiment_no_recommendation\": false,\n" +
" \"debug\": {\n" +
" \"experimentDebugLogs\": [\n" +
" {\n" +
" \"experimentID\": 522,\n" +
" \"msg\": \"matched all constraints. rollout yes. {BucketNum:260 DistributionArray:{VariantIDs:[2019 2020] PercentsAccumulated:[500 1000]} VariantID:2019 RolloutPercent:100}\"\n" +
" }\n" +
" ]\n" +
" }\n" +
" }," +
" \"alt_limit\": 15\n" +
"}";
ProductResponse response = gson.fromJson(json, ProductResponse.class);
searchService.handleResponse(response, new ProductSearch.ResultListener() {
@Override
public void onSearchResult(ProductResponse response, ErrorData error) {
assertNull(error);

assertEquals(15, response.getAltLimit().intValue());
assertEquals(3, response.getStrategy().getId().intValue());
assertEquals("test", response.getStrategy().getName());
assertEquals("VSR", response.getStrategy().getAlgorithm());
assertEquals(0, response.getProducts().size());

Experiment experiment = response.getExperiment();
assertEquals(522, experiment.getExperimentId());
assertEquals(2019, experiment.getVariantId());
assertFalse(experiment.isExpNoRecommendation());
assertTrue(3 == experiment.getStrategyId());

}
});

}

}

0 comments on commit 667711a

Please sign in to comment.