从旧变体更新使用情况

云眼About 1 min

从旧变体更新使用情况

本主题介绍如何从旧变体的云眼全栈 Python SDK 进行更新。

代码示例

本节提供了代码示例,说明我们建议如何利用新的决策和事件跟踪 API。所有现有方法和实现仍包含在内并受支持,并且只有在弃用标记和未来主要变体后才会删除。

我们建议采用新的“决定”、“全部决定”和“跟踪事件”方法,作为当前在实现中使用 isFeatureEnabled、getFeatureVariable、getAllFeatures或Track 调用的更灵活、更易于使用的替代方法。

有关早期方法,请参阅 SDK 参考指南的早期变体open in new window

下面是如何将旧方法迁移到较新方法的一些示例。

Python

from eyeofcloud import eyeofcloud from eyeofcloud.decision.eyeofcloud_decide_option import EyeofcloudDecideOption # ------------------------------- # Prereq for new methods: create a user # ------------------------------ attributes = {"is_logged_in": True} user = eyeofcloud.create_user_context("user_123", attributes) # ------------------------------- # Is Feature Enabled # ------------------------------ # old method enabled = eyeofcloud.is_feature_enabled("flag_1","user_123", attributes) # new method decision = user.decide("flag_1") enabled = decision.enabled # ------------------------------- # Activate & Get Variation # ------------------------------ # old method variation_key = eyeofcloud.activate('experiment_key', 'user_123', attributes) # new method variation_key = decision.variation_key # ------------------------------- # Get All Feature Variables # ------------------------------ # old method all_var_values = eyeofcloud.get_all_feature_variables('my_feature_key', 'user_123', attributes) # new method all_var_values = decision.variables # ------------------------------- # Get Enabled Features # ------------------------------ # old method enabled_features = eyeofcloud.get_enabled_features("user_123") # new method decisions = user.decide_all([EyeofcloudDecideOption.ENABLED_FLAGS_ONLY]) enabled_flags = decisions.keys # ------------------------------- # Track # ------------------------------ # old method eyeofcloud.track('my_purchase_event_key', 'user_123', attributes, {"purchase_count": 2}) # new method user.track_event('my_purchase_event_key', {"purchase_count": 2})

激活方法和A / B测试

与现有的“已启用功能”方法一样,“决定”方法基于灰度发布(特性标帜)键,不支持独立的 A/B 测试或多臂 Bandit。我们正在努力长期统一应用程序的数据模型和接口,以减少维护多种不同访问方法的需求。同时,仍然可以在旧项目中使用“激活”和“获取变体”方法以及“决定”方法进行独立的 A/B 测试。

Last update:
Contributors: “zhangweixue”,zhangweixue