分桶方法decide

云眼About 7 min

分桶方法decide

本主题概述了 Python SDK 的判定方法,这些方法可用于在云眼灰度发布(特性标帜)AB实验中为用户返回标帜判定。

使用 Decide 方法返回用户的标帜决策。标帜决策包括标帜启用/禁用状态和标帜变体。

本页介绍以下决策方法:

有关可以为 Determined 方法设置的选项的详细信息,请参阅:

决定

版本

SDK 3.7 及更高版本

描述

返回用户的标帜键的决策结果。决策结果在 EyeofcloudDecision 对象中返回,并包含传递标帜规则所需的所有数据。

Decide 是 UserContext 对象的一种方法。有关详细信息,请参阅 EyeofcloudUserContext

有关返回的决策对象的详细信息,请参阅 EyeofcloudDecision

参数

下表描述了 Decide 方法的参数:

参数

类型

描述

flag_key

字符串

灰度发布(特性标帜)的键

选项(可选)

数组

Array of EyeofcloudDecideOption enums.请参阅下表。

返回

方法返回一个云眼决策对象。有关更多信息,请参阅云眼决策

如果该方法遇到严重错误(SDK 未就绪、标帜键无效等),则它会返回带有空变体键字段的决策,并使用错误消息填充“原因”字段(无论“包括原因”选项如何)。

示例决策

下面是调用 Decide 方法并访问返回的 EyeofcloudDecision 对象的示例:

Python

# create the user and decide which flag rule & variation they bucket into user = eyeofcloud.create_user_context("user123", {"logged_in":True}) decision = user.decide("product_sort") # Did the decision fail with a critical error? try: variation_key = decision.variation_key except: print("{} error: {}".format(decision, decision.reasons) # flag enabled state: enabled = decision.enabled # variable value: value1 = decision.variables["sort_method"] # all variable values all_var_values = decision.variables # variation. if null, decision fail with a critical error variation_key = decision.variation_key # flag decision reasons reasons = decision.reasons # user for which the decision was made user_context = decision.user_context

Side Effects

Invokes the notification listener if this listener is enabled.DECISION

EyeofcloudDecideOption

The following example shows how you can set options individually on any Decide method, or as global defaults when you instantiate the Eyeofcloud client.

Python

from eyeofcloud import eyeofcloud from eyeofcloud.decision.eyeofcloud_decide_option import EyeofcloudDecideOption # set global default decide options when initializing the client eyeofcloud_client = eyeofcloud.Eyeofcloud( sdk_key = "<YOUR_SDK_KEY>", options = [EyeofcloudDecideOption.DISABLE_DECISION_EVENT]) # set additional options in a decide call user = eyeofcloud.create_user_context("user123") decision = user.decide_all( options = [EyeofcloudDecideOption.ENABLED_FLAGS_ONLY, EyeofcloudDecideOption.IGNORE_USER_PROFILE_SERVICE])

The following table shows details for the options you can set on Decide methods.

EyeofcloudDecideOption enum

If set:

DecideOption.DISABLE_DECISION_EVENT

Prevents the visitor from firing an impressionopen in new window while still being served the variation, which disables displaying results of the Decide method on the Results pageopen in new window.

This setting can be why the Decision Event Dispatched enum is false in the returned EyeofcloudDecisionopen in new window object or the DECIDE notification listener payload.

DecideOption.ENABLED_FLAGS_ONLY

Return decisions for enabled flags only. This is a valid option only for methods that decide multiple flags, like the Decide All method. This option is ignored if it is invalid. When this option is not set, the SDK returns all decisions regardless of whether the flag is enabled or not.

DecideOption.IGNORE_USER_PROFILE_SERVICE

When set, the SDK bypasses UPS (both lookup and save) for the decision.

When this option is not set, UPS overrides audience targeting, traffic allocation, and experiment mutual exclusion groups.

DecideOption.INCLUDE_REASONS

Return log messages in the Reasons field of EyeofcloudDecision object. Note that unlike info or debug messages, critical error messages are always returned, regardless of this setting.

DecideOption.EXCLUDE_VARIABLES

Exclude flag variable values from the decision result. Use this option to minimize the returned decision by skipping large JSON variables.

Decide All

Returns decisions for all active (unarchived) flags for a user.

See EyeofcloudDecision for details.

Version

SDK v3.7 and higher

Description

Use the Decide All method to return a map of flag decisions for a user.

Parameters

The following table describes parameters for the Decide All method:

Parameter

Type

Description

options (optional)

Array

Array of EyeofcloudDecideOption enums. See Decide Parameters.

Returns

The Decide All method returns a map of EyeofcloudDecisions. For more information, see EyeofcloudDecision.

If the method fails for all flags (for example, the SDK isn't ready or the user context is invalid), then it returns an empty map. If the method detects an error for a specific flag, it returns error messages in the Reasons field of the decision for that flag.

Examples

The following is an example of getting flags for the user with the Decide All call:

Python

from eyeofcloud.decision.eyeofcloud_decide_option import EyeofcloudDecideOption # make decisions for all active (unarchived) flags in the project for a user decisions = user.decide_all() # or only for enabled flags decisions = user.decide_all([EyeofcloudDecideOption.ENABLED_FLAGS_ONLY]) flag_keys = decisions.keys flag_decisions = decisions.values decision_for_flag_1 = decisions["flag_1"]

Invokes the notification listener for each decision if this listener is enabled. DECISION

Decide For Keys

The Decide For Keys method makes decisions for a user for specified flag keys.

Version

SDK v3.7 and higher

Description

Get a map of flag decisions for specific flag keys.

Parameters

The following table describes parameters for the Decide For Keys method:

Parameter

Type

Description

keys

Array

Array of string flag keys.

options (optional)

Array

Array of EyeofcloudDecideOption enums. See EyeofcloudDecideOption.

Returns

Returns a map of EyeofcloudDecisions. For more information, see EyeofcloudDecision.

If the method fails for all flags (for example, the SDK isn't ready or the user context is invalid), then it returns an empty map. If the method detects an error for a specific flag, it returns error messages in the Reasons field of the decision for that flag.

Example

The following is an example of getting specified flags for the user:

Python

from eyeofcloud.decision.eyeofcloud_decide_option import EyeofcloudDecideOption # make a decisions for specific flags if enabled decisions = user.decide_for_keys(["flag_1", "flag_2"], [EyeofcloudDecideOption.ENABLED_FLAGS_ONLY]) decision_for_flag_1 = decisions["flag_1"] decision_for_flag_2 = decisions["flag_2"]

Side effects

Invokes the notification listener for each decision if this listener is enabled. DECISION

Source files

The language/platform source files containing the implementation for Python is eyeofcloud.pyopen in new window.

Updated 2 months ago


[

Create User Context

](/experimentation/v4.0.0-full-stack/docs/create-user-context-python)[

Track Event

](/experimentation/v4.0.0-full-stack/docs/track-event-python)

Did this page help you?

Yes

No

创建用户上下文

介绍创建用户上下文方法,该方法为云眼灰度发布(特性标帜)AB实验中的标帜决策和事件创建用户上下文。

此方法的目的是创建用户并设置用户上下文一次,因此不必在每次做出标帜决策或跟踪事件时都指定用户。可以定义多个用户上下文。系统将用户上下文作为运行时对象返回,否则不会持久化。

版本

1.0.0-beta 或更高版本

描述

此调用为标帜决策和事件创建用户上下文。可以在 Eyeofcloud 客户端实例上成功调用此方法,甚至在完全配置实例之前也是如此。

参数

下表列出了必需参数和可选参数:

参数

类型

描述

(必选)用户 ID

字符串

用户的 ID。

属性
可选

Map

自定义键值字符串对的映射,指定系统用户用于受众群体定位的用户的属性。有关更多详细信息,请参阅以下部分。

受众群体属性

为用户设置自定义受众群体属性,可以使用这些属性来定位受众群体。可以将字符串、数字、布尔值和 nil 作为自定义用户属性值传递。如果要根据他们使用的应用程序变体定位访问群体,还可以传入格式为语义变体的open in new window字符串,然后在 Eyeofcloud 应用中定义受众条件。version

🚧 重要

在访问群体评估期间,如果没有为给定的访问群体条件传递有效的属性值(例如,如果在受众群体条件需要布尔值时传递字符串,或者忘记传递值),则系统会跳过该条件。发生这种情况时,SDK 日志会包含警告。

返回

返回一个 EyeofcloudUserContext 对象。有关详细信息,请参阅云眼用户上下文

Dart

// option 1: create a user, then set attributes var user = await flutterSDK.createUserContext("user123"); var attributes = <String, dynamic>{}; attributes["is_logged_in"] = false; attributes["app_version"] = "1.3.2"; user!.setAttributes(attributes); // option 2: pass attributes when creating the user var attributes = <String, dynamic>{}; attributes["is_logged_in"] = false; attributes["app_version"] = "1.3.2"; var eyeofcloudUserContext = await eyeofcloudClient.createUserContext("user123", attributes);

参见

云眼用户上下文

源文件

包含 Flutter SDK for Android Eyeofcloudopen in new window 和 Swift 实现的语言/平台源文件.java为 EyeofcloudClient.swiftopen in new window

Last update:
Contributors: “zhangweixue”