日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

A/B實(shí)驗(yàn)Java SDK

更新時(shí)間:

本文為您介紹如何使用A/B實(shí)驗(yàn)的Java SDK進(jìn)行實(shí)驗(yàn)分流,并獲取實(shí)驗(yàn)相關(guān)的參數(shù)配置信息。

前提條件

添加依賴項(xiàng)

使用Java編寫(xiě)客戶端代碼時(shí),在Maven工程中使用A/B實(shí)驗(yàn)SDK,必須在pom.xml文件<dependencies>中添加如下依賴,示例如下所示:

  • pai-abtest-sdk

    <dependency>
      <groupId>com.aliyun.openservices.aiservice</groupId>
      <artifactId>pai-abtest-sdk</artifactId>
      <version>1.0.0</version>
    </dependency>
  • okhttp

    <dependency>
        <groupId>com.squareup.okhttp3</groupId>
        <artifactId>okhttp</artifactId>
        <version>4.12.0</version>
    </dependency>

使用示例

package com.aliyun.openservices.paiabtest;

import com.aliyun.openservices.paiabtest.api.ApiClient;
import com.aliyun.openservices.paiabtest.api.Configuration;
import com.aliyun.openservices.paiabtest.model.ExperimentContext;
import com.aliyun.openservices.paiabtest.model.ExperimentResult;

import java.util.HashMap;
import java.util.Map;

public class ExperimentTest {
    static ExperimentClient experimentClient;

    public static void main(String[] args) throws Exception {
        // set up experiment client
        String regionId = "cn-beijing";
        String accessId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
        String accessKey = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
        Configuration configuration = new Configuration(regionId, accessId, accessKey);
        ApiClient apiClient = new ApiClient(configuration);
        experimentClient = new ExperimentClient(apiClient);

        // init load experiment data
        experimentClient.init();

        // set up experiment context
        ExperimentContext experimentContext = new ExperimentContext();
        experimentContext.setRequestId("<req_id>");
        // set uid
        experimentContext.setUid("<uid>");
        // set filter params for condition filter match
        Map<String, Object> filterParams = new HashMap<>();
        filterParams.put("sex", "male");
        experimentContext.setFilterParams(filterParams);

        // match experiment
        ExperimentResult experimentResult =  experimentClient.matchExperiment("<DefaultProject>", experimentContext);

        // print experiment info
        System.out.println(experimentResult.info());
        // print exp id
        System.out.println(experimentResult.getExpId());
        // print exp params
        System.out.println(experimentResult.getExperimentParams().get("recall_v", "not exist"));
        System.out.println(experimentResult.getExperimentParams().get("rank_v", "not exist"));
        System.out.println(experimentResult.getExperimentParams().get("male_v", "not exist"));
    }
}

其中:

  • regionId:地域ID,例如華東1(杭州)配置為cn-hangzhou。

  • <req_id>:自定義配置請(qǐng)求ID。

  • <uid>:實(shí)驗(yàn)分流ID標(biāo)識(shí)。可以是用戶側(cè)的UserID,也可以是設(shè)備ID等。

  • filterParams.put("sex", "male"):其中sexmale為實(shí)驗(yàn)分流參數(shù),請(qǐng)根據(jù)實(shí)際情況進(jìn)行修改。

  • <DefaultProject>:A/B實(shí)驗(yàn)項(xiàng)目名稱。請(qǐng)前往A/B實(shí)驗(yàn)的項(xiàng)目管理 > 實(shí)現(xiàn)項(xiàng)目頁(yè)面,查看項(xiàng)目名稱。具體操作,請(qǐng)參見(jiàn)新建實(shí)驗(yàn)項(xiàng)目