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


Python Stats.update方法代码示例

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


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

示例1: Intelligence

# 需要导入模块: from stats import Stats [as 别名]
# 或者: from stats.Stats import update [as 别名]
class Intelligence(object):
    """
    Emotion Intelligence of an entity
    Based on Lövheim Cube of emotion:

    Shame/humiliation	Low	Low	Low
    Distress/anguish	Low	Low	High
    Fear/terror	Low	High	Low
    Anger/rage	Low	High	High
    Contempt/disgust	High	Low	Low
    Surprise	High	Low	High
    Enjoyment/Joy	High	High	Low
    Interest/excitement	High	High	High
    """

    def __init__(self, name, emotion_parser):
        self.name = name
        self.parser = emotion_parser
        self.threshold = 1.0
        self.stats = Stats()

    def update(self, text):
        """
        Update emotional state of an entity

        :param text: Emotionally charged text that entity produced
        :return: self
        """

        for emoji, power in self.parser.get_emojis(text):
            emoji_dir = np.array(emoji.dim)
            self.stats.update(power * emoji_dir / np.linalg.norm(emoji_dir))

        return self

    def emotions(self):
        emo = []

        emo_point = np.array(self.stats.mean)

        for k, emotion in self.parser.known_emotions.iteritems():
            emo_origin = np.array(emotion.dim)
            dist = np.linalg.norm(emo_point - emo_origin)
            if dist < self.threshold:
                emo.append((emotion,
                            dist))

        return emo
开发者ID:abbyssoul,项目名称:mood-prob,代码行数:50,代码来源:intelligence.py

示例2: run

# 需要导入模块: from stats import Stats [as 别名]
# 或者: from stats.Stats import update [as 别名]
    def run(self):
        """
        Runs the Gatling workload
        Iterates until a stopping condition has been raised.

        """
        cmd = self.command()
        users = self.users_start
        step = self.users_step

        stdout_parser = GatlingStdoutParser()

        runners = self.minions_with_role(self.config['gatling_role'])
        timeout = max(2 * self.duration, 360)

        while(True):
            env = self.env(users=users)
            kwargs = {
                'timeout': timeout,
                'arg': (cmd,),
                'kwarg': {
                    'env': env,
                    'runas': self.config['gatling_user']
                }
            }

            # Execution response (still have to make another request to
            # get the simulation.log file contents)
            retcodes = set([0, 2])
            exe_resp = self.client.cmd(runners[0].id_,
                                       'cmd.run_all',
                                       retcodes=retcodes,
                                       **kwargs)
            exe_resp = exe_resp.values()[0]
            retcode = exe_resp.get('retcode')
            stdout = exe_resp.get('stdout')
            stderr = exe_resp.get('stderr')
            stdout = cStringIO.StringIO(stdout)
            if stderr:
                # Do something with stderr if not empty or non none
                pass

            result = GatlingResult(users, self.duration, self.webheads)
            result.update({'retcode': retcode})
            result.update(stdout_parser.parse(stdout))
            print result

            # Push the simulation log file to the master
            kwargs = {
                'timeout': timeout,
                'arg': (result.simulation_log,)
            }
            log_resp = self.client.cmd(runners[0].id_, 'cp.push', **kwargs)
            log_resp = log_resp.values()[0]

            # Read the simulation log file
            filename = self.log_file_path(
                runners[0].id_,
                result.simulation_log
            )
            stats = Stats()
            with open(filename, 'r') as f:
                stats.update(f)

            # Attempt to get contents of simulation log
            #kwargs = {
            #    'timeout': timeout,
            #    'arg': ('cat %s' % result.simulation_log,)
            #}
            #log_resp = self.client.cmd(
            #    runners[0].id_,
            #    'cmd.run_all',
            #    **kwargs
            #)
            #log_resp = log_resp.values()[0]
            #stdout = cStringIO.StringIO(log_resp.get('stdout'))
            #stats = Stats()
            #stats.update(stdout)
            result.update({'stats': stats})
            self._results.append(result)
            if retcode not in [0, 2] or not result.success:
                break
            users += step
开发者ID:absalon-james,项目名称:cloud-workloads,代码行数:85,代码来源:workload.py


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