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


Python Cache.write_analyzer_xml方法代码示例

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


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

示例1: TelemetaPreprocessImport

# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import write_analyzer_xml [as 别名]
class TelemetaPreprocessImport(object):

    def __init__(self, media_dir, dest_dir,  log_file):
        self.root_dir = media_dir
        self.dest_dir = dest_dir
        self.threads = 1
        self.logger = Logger(log_file)
        self.counter = 0
        self.force = 0
        self.cache = Cache(self.dest_dir)

        self.scheme = GrapherScheme()
        self.width = self.scheme.width
        self.height = self.scheme.height
        self.bg_color = self.scheme.bg_color
        self.color_scheme = self.scheme.color_scheme
        self.force = self.scheme.force
        self.threads = self.scheme.threads
        self.logger = Logger(log_file)
        self.counter = 0        
        
        self.analyzers = timeside.core.processors(timeside.api.IAnalyzer)
        self.grapher = timeside.grapher.WaveformAwdio(width=self.width, 
                                                         height=self.height, 
                                                         bg_color=self.bg_color, 
                                                         color_scheme=self.color_scheme)
        
        self.media_list = self.get_media_list()
        if not os.path.exists(self.dest_dir):
            os.makedirs(self.dest_dir)
                                   
    def get_media_list(self):
        media_list = []
        for root, dirs, files in os.walk(self.root_dir):
            if root:
                for file in files:
                    if file[0] != '.':
                        ext = file.split('.')[-1]
                        media_list.append(root+os.sep+file)
        return media_list

    def process(self):          
        for media in self.media_list:
            filename = media.split(os.sep)[-1]
            name, ext = os.path.splitext(filename)
            size = str(self.width) + '_' + str(self.height)
            image = self.dest_dir + os.sep + name + '.' + self.scheme.id + '.' + size + '.png'
            xml = name + '.xml'
            
            if not self.cache.exists(image) or not self.cache.exists(xml):
                mess = 'Processing ' + media
                self.logger.write_info(mess)
                decoder  = timeside.decoder.FileDecoder(media)
                pipe = decoder | self.grapher
                analyzers = []
                analyzers_sub = []
                for analyzer in self.analyzers:
                    subpipe = analyzer()
                    analyzers_sub.append(subpipe)
                    pipe = pipe | subpipe
                pipe.run()
                
                mess = 'Rendering ' + image
                self.logger.write_info(mess)
                self.grapher.render(output=image)
                
                mess = 'Frames / Pixel = ' + str(self.grapher.graph.samples_per_pixel)
                self.logger.write_info(mess)
                
                for analyzer in analyzers_sub:
                    value = analyzer.result()
                    if analyzer.id() == 'duration':
                        value = datetime.timedelta(0,value)
                    analyzers.append({'name':analyzer.name(),
                              'id':analyzer.id(),
                              'unit':analyzer.unit(),
                              'value':str(value)})
                
                self.cache.write_analyzer_xml(analyzers, xml)		    

            filename = name
            data = name.split('.')
            date = data[0]
            collection_name = data[1]
            other = ''
            if len(data) > 2:
                other = '.'.join(data[2:])
                
            item = telemeta.models.media.MediaItem.objects.filter(code=filename)
            collections = telemeta.models.media.MediaCollection.objects.filter(code=collection_name)
            
            if not collections:
                c = telemeta.models.media.MediaCollection(code=collection_name)
                c.title = collection_name
                c.save()
                msg = 'added'
                self.logger.write_info(collection_name, msg)
                collection = c
            else:
                collection = collections[0]
#.........这里部分代码省略.........
开发者ID:MechanisM,项目名称:TimeSide,代码行数:103,代码来源:telemeta_preprocess_batch.py


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