当前位置: 首页>>代码示例>>Python>>正文


Python Experiment.find_or_create方法代码示例

本文整理汇总了Python中models.Experiment.find_or_create方法的典型用法代码示例。如果您正苦于以下问题:Python Experiment.find_or_create方法的具体用法?Python Experiment.find_or_create怎么用?Python Experiment.find_or_create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Experiment的用法示例。


在下文中一共展示了Experiment.find_or_create方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: participate

# 需要导入模块: from models import Experiment [as 别名]
# 或者: from models.Experiment import find_or_create [as 别名]
def participate(experiment, alternatives, client_id,
    force=None,
    record_force=False,
    traffic_fraction=None,
    prefetch=False,
    datetime=None,
    redis=None):

    exp = Experiment.find_or_create(experiment, alternatives, traffic_fraction=traffic_fraction, redis=redis)

    alt = None
    if force and force in alternatives:
        alt = Alternative(force, exp, redis=redis)

        if record_force:
            client = Client(client_id, redis=redis)
            alt.record_participation(client, datetime)

    elif not cfg.get('enabled', True):
        alt = exp.control
    elif exp.winner is not None:
        alt = exp.winner
    else:
        client = Client(client_id, redis=redis)
        alt = exp.get_alternative(client, dt=datetime, prefetch=prefetch)

    return alt
开发者ID:seatgeek,项目名称:sixpack,代码行数:29,代码来源:api.py

示例2: on_participate

# 需要导入模块: from models import Experiment [as 别名]
# 或者: from models.Experiment import find_or_create [as 别名]
    def on_participate(self, request):
        opts = {}
        alts = request.args.getlist('alternatives')
        experiment_name = request.args.get('experiment')
        force = request.args.get('force')
        client_id = request.args.get('client_id')
        distribution = request.args.get('traffic_dist')

        if client_id is None or experiment_name is None or alts is None:
            return json_error({'message': 'missing arguments'}, request, 400)

        if distribution:
            opts['distribution'] = distribution

        try:
            experiment = Experiment.find_or_create(experiment_name, alts, self.redis, opts)
        except ValueError as e:
            return json_error({'message': str(e)}, request, 400)

        alternative = None
        if force and force in alts:
            alternative = force
        elif not cfg.get('enabled', True):
            alternative = alts[0]
        elif experiment.winner is not None:
            alternative = experiment.winner
        elif should_exclude_visitor(request):
            alternative = alts[0]
        else:
            dt = None
            if request.args.get("datetime"):
                dt = dateutil.parser.parse(request.args.get("datetime"))
            client = Client(client_id, self.redis)
            alternative = experiment.get_alternative(client, dt=dt).name

        resp = {
            'alternative': {
                'name': alternative
            },
            'experiment': {
                'name': experiment.name,
            },
            'client_id': client_id,
            'status': 'ok'
        }

        return json_success(resp, request)
开发者ID:Onasusweb,项目名称:sixpack,代码行数:49,代码来源:server.py


注:本文中的models.Experiment.find_or_create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。