示例#1
0
    def test_single_instance_with_same_name(self):
        """ 创建状态值如果name相同则单实例

        :return:
        """
        s1 = new_state("A", a=1, b=2)
        s2 = new_state("A", c=1, d=1)
        self.assertEqual(s1, s2)
示例#2
0
    def test_pick_up(self):
        """ 根据权重识别

        :return:
        """
        st = new_state("A", a=1, b=2, c=1)
        l = [st.pick_up() for _ in range(40000)]
        # assert is not accurate
        self.assertTrue(int(l.count("a") + l.count("c") - l.count("b")) < 200)
示例#3
0
    def test_get_rate_of_val(self):
        """ 获取状态值的概率

        :return:
        """
        st = new_state("Name", **{
            "a": 1,
            "b": 1,
            "c": 2,
        })
        self.assertEqual(st.get_rate_of_val("c"), float(2/4))
        self.assertEqual(st.get_rate_of_val("a"), float(1/4))
示例#4
0
    def test_set_rate_of_val(self):
        """ 设置状态值权重

        :return:
        """
        st = new_state("Name", **{
            "a": 1,
            "b": 1,
            "c": 2,
        })
        st["a"] = 0
        self.assertEqual(st.get_rate_of_val("a"), 0)
        self.assertEqual(st.get_rate_of_val("c"), float(2/3))
示例#5
0
from lib.base import new_state

stateWXServiceUserSources = new_state(
    "WXServiceUserSources",
    **{
        "0": 1,  # 代表其他合计
        "1": 1,  # 代表公众号搜索
        "17": 1,  # 代表名片分享
        "30": 1,  # 代表扫描二维码
        "43": 1,  # 代表图文页右上角菜单
        "51": 5,  # 代表支付后关注(在支付完成页
        "57": 1,  # 代表图文页内公众号名称
        "75": 1,  # 代表公众号文章广告
        "78": 1,  # 代表朋友圈广告
    })

stateWXServiceSubscribeScene = new_state(
    "WXServiceSubscribeScene",
    **{
        "ADD_SCENE_OTHERS": 1,  # 代表其他合计
        "ADD_SCENE_SEARCH": 1,  # 代表公众号搜索
        "ADD_SCENE_ACCOUNT_MIGRATION": 1,  # 公众号迁移
        "ADD_SCENE_PROFILE_CARD": 1,  # 代表名片分享
        "ADD_SCENE_QR_CODE": 1,  # 代表扫描二维码
        "ADD_SCENE_PROFILE_ITEM": 1,  # 代表图文页右上角菜单
        "ADD_SCENE_PAID": 5,  # 代表支付后关注(在支付完成页
        "ADD_SCENEPROFILE": 1,  # LINK 图文页内名称点击
    })

stateWXServiceSubscribe = new_state(
    "WXServiceSubscribe",