强制决策方法
强制决策方法
本主题介绍强制决策方法,这些方法可用于强制用户进入云眼特性标帜(Feature Flag)AB实验中的特定变体。
这些方法将通过强制用户进入特定变体来帮助测试和调试客户端应用程序的各种流。
云眼特性标帜(Feature Flag)AB实验 Python SDK 将在做出任何决策之前检查强制决策。如果找到请求标帜的匹配项,Python SDK 会在做出正常决策之前立即返回强制决策(忽略受众条件和流量分配):
下面介绍了 Python SDK 将遵循的具体场景:
标记到决策
- SDK 将在给定标帜的任何决策调用开始时查找。如果为该标帜找到匹配的标帜到决策强制决策,它将返回该决定。
从实验规则到决策
- SDK 将在决策开始时查找给定实验规则(标帜键)。如果为标帜找到匹配的实验规则到决策强制决策,它将返回决策。
从交付规则到决策
- SDK 将在决策开始时查找给定的传递规则(标帜键)。如果找到匹配的传递规则到决策强制决策,它将返回该决策。
❗️
警告
在调用任何强制决策方法之前,必须将变体关联到标帜规则。
对于强制决策,SDK 会像其他正常决策一样触发展示事件和通知(除非被 DISABLE_DECISION_EVENT 选项禁用)。
📘 注意
这些强制决策不是永久性的,将在重新初始化 EyeofcloudUserContext 时清除。
有关每种方法的更多信息,请单击下面的方法名称:
云眼分桶结果 EyeofcloudDecision上下文
Python
class EyeofcloudDecisionContext(object):
def __init__(self, flag_key, rule_key):
云眼强制决策
Python
class EyeofcloudForcedDecision(object):
def __init__(self, variation_key):
设置强制决策方法 - set_forced_decision()
版本
4.0.0
描述
为给定的EyeofcloudDecisionContext
设置强制决策(variation_key
)。
参数
This table lists the required and optional parameters for the Python SDK.
Parameter
Type
Description
context
required
Class
An instance of with the required and optional for the forced decision you want to set. EyeofcloudDecisionContext``flag_key``rule_key
decision
required
Class
An instance of with the required for the forced decision you want to set.EyeofcloudForcedDecision``variation_key
Returns
A boolean value that indicates if setting the forced decision () was completed successfully.variation_key
Example
See the full Python SDK example here.
Get Forced Decision Method - get_forced_decision()
Version
4.0.0
Description
Returns the forced decision () for a given . Returns the null if there is no matching item.variation_key``EyeofcloudDecisionContext
Parameters
This table lists the required and optional parameters for the Python SDK.
Parameter
Type
Description
context
required
Class
An instance of with the required and optional for the forced decision you want to get. EyeofcloudDecisionContext``flag_key``rule_key
Returns
A forced decision instance for the context or nil if there is no matching item.EyeofcloudForcedDecision
Example
See the full Python SDK example here.
Remove Forced Decision Method - remove_forced_decision()
Version
4.0.0
Description
删除给定 的强制决策 ()。variation_key``EyeofcloudDecisionContext
参数
下表列出了 Python SDK 的必需参数和可选参数。
参数
类型
描述
所需的上下文
类
的实例,具有要删除的强制决策的必需和可选。EyeofcloudDecisionContext``flag_key``rule_key
返回
删除强制决策 () 时的成功/失败布尔状态。 variation_key
例
在此处查看完整的 Python SDK 示例。
删除所有强制决策方法 - remove_all_forced_decisions()
变体
4.0.0
描述
删除用户上下文的所有强制决策 ()。variation_key
参数
下表列出了 Python SDK 的必需参数和可选参数。
参数
类型
描述
没有
不适用
不适用
返回
成功/失败布尔状态。
例
在此处查看完整的 Python SDK 示例。
完整代码示例
Python
from eyeofcloud import eyeofcloud, eyeofcloud_user_context eyeofcloud = eyeofcloud.Eyeofcloud(sdk_key="sdk_key") user = eyeofcloud.create_user_context("test_user", attributes) flag_context = eyeofcloud_user_context.EyeofcloudUserContext.EyeofcloudDecisionContext("flag-1",None) flag_and_ab_test_context = eyeofcloud_user_context.EyeofcloudUserContext.EyeofcloudDecisionContext("flag-1","ab-test-1") flag_and_delivery_rule_context = eyeofcloud_user_context.EyeofcloudUserContext.EyeofcloudDecisionContext("flag-1","delivery-1") variation_a_forced_decision = eyeofcloud_user_context.EyeofcloudUserContext.EyeofcloudForcedDecision("variation-a") variation_b_forced_decision = eyeofcloud_user_context.EyeofcloudUserContext.EyeofcloudForcedDecision("variation-b") variation_on_forced_decision = eyeofcloud_user_context.EyeofcloudUserContext.EyeofcloudForcedDecision("on") # set a forced decision for a flag success = user.set_forced_decision(flag_context, variation_a_forced_decision) decision = user.decide("flag-1") # set a forced decision for an ab-test rule success = user.set_forced_decision(flag_and_ab_test_context, variation_b_forced_decision) decision = user.decide("flag-1") # set a forced variation for a delivery rule success = user.set_forced_decision(flag_and_delivery_rule_context, variation_on_forced_decision) decision = user.decide("flag-1") # get forced variations forced_decision = user.get_forced_decision(flag_context) print(f"[ForcedDecision] variation_key = {forced_decision}") # remove forced variations success = user.remove_forced_decision(flag_and_ab_test_context) success = user.remove_all_forced_decision()
参见
Source Files