Chronaxis用户手册English
本页目录

chronaxis.batch.templates

源码基线:8904c2f744951857659abd40aaa3535d57faf53c

1"""把一个分析模板应用于明确输入集合,每个文件形成独立任务,不读取日志。23路径按模板目录解释;输入目录按批量配置目录解释。复用已有自然序和4096文件限制,4来源有多个候选时要求source,绝不把连续会话自动拆开。本入口由用户显式选择。5"""6from copy import deepcopy7from pathlib import Path89from ..configuration import load_configuration10from ..configuration.imports import expand_document_imports11from ..planning.checks import PlanValidationError, text_at12from ..planning.input_paths import expand_source_files131415def template_jobs(raw, base):16    """参数为批量对象和路径基准;返回独立BatchJob列表。配置错误抛PlanValidationError,不写文件。"""17    from .models import BatchJob18    from ..planning.plan import AnalysisPlan19    path=base/Path(text_at(raw['template'],'$.template'))20    path=path.absolute()21    template=expand_document_imports(load_configuration(path)).data22    sources=template.get('sources',[]) if type(template) is dict else []23    if type(sources) is not list or any(type(source) is not dict for source in sources):24        raise PlanValidationError('$.template','模板sources必须为来源对象数组')25    selector=raw.get('source')26    if selector is not None:selector=text_at(selector,'$.source',identifier=True)27    candidates=[i for i,s in enumerate(sources) if selector is None or s.get('name',f'source_{i+1}')==selector]28    if len(candidates)!=1:29        raise PlanValidationError('$.source','模板必须能唯一确定要替换文件的来源;多来源时填写source')30    index=candidates[0]31    selected=sources[index]32    if selected.get('source_type')=='memory':33        raise PlanValidationError('$.source','目录批量模板不能替换内存来源')34    files,shifts=expand_source_files(dict(paths=raw['inputs'],source_type=selected.get('source_type')),base,'$.inputs')35    jobs=[]36    for number,file in enumerate(files,1):37        config=deepcopy(template);source=config['sources'][index]38        for key in ('path','paths','offsets'):source.pop(key,None)39        source['path']=str(file)40        if shifts is not None:source['paths']=[dict(path=source.pop('path'),offset=shifts[number-1])]41        jobs.append(BatchJob(f'job_{number}',AnalysisPlan.from_dict(config,base_dir=path.parent)))42    return jobs43
Chronaxis 用户手册 · 离线阅读