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


Python OrderedDict.itervalues方法代码示例

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


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

示例1: JobTracker

# 需要导入模块: from odict import OrderedDict [as 别名]
# 或者: from odict.OrderedDict import itervalues [as 别名]
class JobTracker(object):
    def __init__(self, name, trackers, cls=Monitor):
        self.name = name
        self.count = 0
        self.trackers = OrderedDict()
        for n, getter in trackers:
            mon = cls("%s: %s" % (name, n))
            self.trackers[n] = (mon, getter)

    def __getattr__(self, attr):
        if attr in self.trackers:
            return self.trackers[attr][0]
        else:
            raise AttributeError

    def record(self, agent, job):
        for mon, getter in self.trackers.itervalues():
            mon.observe(getter(agent, job))
        self.count += 1

    def report(self):
        for mon, _ in self.trackers.itervalues():
            print self._report(mon)
    
    def _report(self, tally):
        s = "mean %s: %.2f (%.2f)"
        if tally.count():
            vars = (tally.name, tally.mean(), math.sqrt(tally.var()))
        else:
            vars = (tally.name, 0, 0)
        return s % vars
开发者ID:bloodearnest,项目名称:deal,代码行数:33,代码来源:util.py

示例2: FLA

# 需要导入模块: from odict import OrderedDict [as 别名]
# 或者: from odict.OrderedDict import itervalues [as 别名]

#.........这里部分代码省略.........
                try:
                    fla.symbols[name] = Symbol(symbol.attrib, fla.symbols,
                                               fla.directory)
                except IOError:
                    # In some scenarios, there is referenced symbols that 
                    # doesn't exists on directory.
                    continue

        return fla

    def __str__(self):
        # Visualization candy
        return "<FLA '%s' symbols=%d folders=%d>" % \
                (self.name, len(self.symbols), len(self.folders))
    
    def _replace_template(self, tpl, values):
        # Replace into given template (string) some dinamic values 
        for k, v in values.iteritems():
            if isinstance(v, unicode):
                v = v.encode('utf-8')

            if isinstance(v, str):
                tpl = tpl.replace("{{ %s }}" % k, v)

        return tpl

    def save(self, filepath):
        """
        Read our not_saved record, craft xml, zip and save into given filepath
        """
        self.name = os.path.basename(filepath).split('.')[0]

        xmlfolders = u'\n'.join(_tag_from_dict('DOMFolderItem', f)\
                for f in self.folders.itervalues())
        
        # Sort Items, to avoid some Flash Crashes (!!!)
        symbols = self.symbols.values()
        symbols.sort(key=lambda x: x.attrs['href'])
        xmlsymbols = u'\n'.join(s.to_xml() for s in symbols)

        xdom = self._replace_template(self.xdom, 
                {'folders_xml': xmlfolders, 'symbols_xml': xmlsymbols})
        xconf = self._replace_template(self.xconf, 
                dict((k, getattr(self, k)) for k in dir(self) if k[0] != '_'))

        open('%s/mimetype' % self.directory, 'w').write(self.mimetype)
        open('%s/DOMDocument.xml' % self.directory, 'w').write(xdom)
        open('%s/PublishSettings.xml' % self.directory, 'w').write(xconf)
        open('%s/%s.xfl' % (self.directory, self.name), 'w').write('PROXY-CS5')

        # Make FLA file (Just a regular zip file)
        fzip(filepath, self.directory)

    @classmethod
    def from_symbols(klass, symbols, fladirectory=None, flainstance=None):
        paths = lambda n: [] \
            if n == os.path.dirname(n) else paths(os.path.dirname(n)) + [n]

        newfla = flainstance or FLA(name='dynamic')
        newfla.symbols = symbols
        if fladirectory:
            newfla.directory = fladirectory

        for ohref, symbol in symbols.items():
            href = os.path.dirname(symbol.attrs['href'])
开发者ID:Reflejo,项目名称:pyfla,代码行数:69,代码来源:FLA.py

示例3: GridModel

# 需要导入模块: from odict import OrderedDict [as 别名]
# 或者: from odict.OrderedDict import itervalues [as 别名]
class GridModel(Model):
    "Basic model of the Grid"
    def __init__(self,
                 size=100,
                 load=1.0,
                 regions=(4,4),
                 coords=(100,100),
                 run_times=6,
                 arrival_dist = dists.expon,
                 resource_sizes = dists.gamma(100, 10),
                 job_sizes = dists.gamma(20, 4),
                 job_durations = dists.gamma(100, 10),
                 service_means = dists.normal(0.1),
                 service_dist = dists.shaped_gamma(0.1),
                 latency_means = dists.normal(0.1),
                 latency_dist = dists.shaped_gamma(0.1),
                 regional_latency = dists.gamma(0.2, 0.1),
                 global_latency = dists.gamma(0.4, 0.1)
                 ):


        # calculated results
        self.runtime = run_times * job_durations.mean
        total_capacity = size * resource_sizes.mean;
        max_jobs = total_capacity / float(job_sizes.mean);
        arrival_mean = job_durations.mean / float(max_jobs);

        self.inter_arrival_time = arrival_dist(arrival_mean / load)
        self.job_sizes = job_sizes
        self.job_durations = job_durations
        
        # store for stats
        self.size = size
        self.load = load

        # generate network
        self.graph = network.Network(
                coords,
                regions,
                latency_means,
                regional_latency,
                global_latency,
                latency_dist)
        
        # generate nodes, but no topology
        network.generate_nodes(self.graph, size)
 
        self.service_dist = service_dist
        self.service_means = service_means
        for node in self.graph.nodes_iter():
            node.server = Server(node, service_dist(service_means()))
            node.resource = GridResource(node, int(resource_sizes()))

        self.mons = OrderedDict()
        self.mons["grid_util"] = Monitor("grid_util")
        self.mons["server_util"] = Monitor("server_util")
        self.mons["server_queue"] = Monitor("server_queue")

    @property
    def nodes(self):
        return self.graph.nodes()

    def random_node(self):
        return random.choice(self.nodes)

    def random_region_node(self, region):
        return random.choice([n for n in self.graph.nodes_iter()
                              if n.region == region])

    def new_job(self):
        return Job(self.job_sizes(), self.job_durations())

    def collect_stats(self, tlast):
        self.mons["grid_util"].observe(stats.current_grid_util(self, tlast))
        self.mons["server_util"].observe(stats.current_server_util(self, tlast))
        self.mons["server_queue"].observe(stats.current_server_queue(self, tlast))

    def get_series_mons(self):
        for mon in self.mons.itervalues():
            yield mon
开发者ID:bloodearnest,项目名称:deal,代码行数:82,代码来源:models.py


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