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


Python Builder.timelist方法代码示例

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


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

示例1: update_cache

# 需要导入模块: from builder import Builder [as 别名]
# 或者: from builder.Builder import timelist [as 别名]
def update_cache(cx, suite, prefix, when, rows):
    # Sort everything into separate modes.
    modes = { }
    for row in rows:
        modeid = int(row[4])
        if not modeid in cx.modemap:
            continue

        if modeid in modes:
            line = modes[modeid]
        else:
            line = []
            modes[modeid] = line

        line.append(row)

    # Build our actual datasets.
    lines = [ ]
    builder = Builder()
    for modeid in modes:
        rows = modes[modeid]
        points = []
        for row in rows:
            score = float(row[3])
            if score:
                cset = row[2]
            else:
                cset = None
            builder.addPoint(points,
                             int(row[1]),
                             cset,
                             None,
                             score,
                             row[5],
                             row[6])
        line = { 'modeid': modeid,
                 'data': points
               }
        lines.append(line)
    builder.prune()
    builder.finish(lines)

    # Open the old cache.
    cache = open_cache(suite, prefix)

    # Build a reverse mode mapping for the cache.
    cache_modes = { }
    for i, oldline in enumerate(cache['lines']):
        cache_modes[int(oldline['modeid'])] = oldline

    # Updating fails if there are items before the last time in the cache.
    if len(cache['timelist']) and len(builder.timelist):
        last_time = cache['timelist'][-1]
        i = 0
        while i < len(builder.timelist) and builder.timelist[i] < last_time:
            return False
        if i:
            builder.timelist = builder.timelist[i:]
            for line in lines:
                line['data'] = line['data'][i:]


    # For any of our lines that are not in the cache, prepend null points so
    # the line width matches the existing lines.
    for line in lines:
        if line['modeid'] in cache_modes:
            continue

        data = { 'data': [None] * len(cache['timelist']),
                 'modeid': line['modeid']
               }
        cache['lines'].append(data)
        cache_modes[line['modeid']] = data

    # Now we can merge our data into the existing graph.
    for line in lines:
        oldline = cache_modes[line['modeid']]
        oldline['data'].extend(line['data'])

    # For any lines which are in the cache, but not in our pulled data, extend
    # them to have null datapoints for our timelist.
    for oldline in cache['lines']:
        modeid = int(oldline['modeid'])
        if modeid in modes:
            continue
        oldline['data'].extend([None] * len(builder.timelist))

    # Finally we can extend the cache timelist.
    cache['timelist'].extend(builder.timelist)

    # Sanity check.
    for line in cache['lines']:
        if len(line['data']) != len(cache['timelist']):
            print(str(len(line['data'])) + ' != ' + str(len(cache['timelist'])))
            raise Exception('computed datapoints wrong')

    # Now save the results.
    save_cache(prefix, cache)
    return True
开发者ID:,项目名称:,代码行数:101,代码来源:


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