chronaxis.results.rows
源码基线:8904c2f744951857659abd40aaa3535d57faf53c
1"""为当前平坦结果确定所属表和稳定排序键,不构造额外结果包装。23输入为已计算的冻结行;输出为固定表名和纯标量tuple,不读取来源或复制数值历史。4每个表按会话、业务对象和真实顺序排序,父ID明确关联事件或片段。5"""67from .summary import SummaryCalculationRow, SummaryCoverageCalculationRow, SummaryHostedCalculationRow, SummaryEventRow, SummarySequenceRow, SummarySegmentRow, SummaryContributionRow, SummaryInputRow, SummarySelectionRow, SUMMARY_MODELS89from .aggregation_row import SummaryAggregationRow10ResultRow = SummaryCalculationRow | SummaryEventRow | SummarySequenceRow | SummarySegmentRow | SummaryCoverageCalculationRow | SummaryContributionRow | SummaryInputRow | SummarySelectionRow | SummaryAggregationRow111213def row_table(row: ResultRow) -> str:14 """返回行所属表名,不依赖外部对象属性反射。1516 参数: row为已登记的结果行之一。返回: 当前固定表名。17 异常: TypeError为未注册类型。18 """19 # 精确类型防止子类增加未经编解码登记的字段。20 try:21 if type(row) in SUMMARY_MODELS:22 return SUMMARY_MODELS[type(row)][0]23 raise TypeError('未注册结果行类型')24 finally:25 # 返回名已先求值;原错误/TB只保位置,不替抵费后的借入行继续持有完整refs。26 row = None272829def row_sort_key(row: ResultRow) -> tuple:30 """给出session、规则、起点、序号为主的确定排序键。3132 参数: row为typed结果行。返回: 不含浮点值或可变对象的tuple。33 异常: TypeError为非法行;不在这里排序或重复原数据读取。34 """35 # 各表分别排序;序号为相同业务键提供稳定顺序。36 try:37 row_table(row)38 if type(row) is SummaryAggregationRow:39 return (row.session_id,row.aggregation_id,*row.group_values,row.sequence)40 if type(row) in SUMMARY_MODELS and SUMMARY_MODELS[type(row)][0]=='selections':41 return (row.session_id,row.calculation_id,row.scope,row.parent_id or '',row.time_ns,42 row.sequence,row.dataset_id,row.entity_id)43 if type(row) in SUMMARY_MODELS and SUMMARY_MODELS[type(row)][0]=='input_trace':44 return (row.session_id,row.source,row.original_sequence,row.sequence,row.dataset_id,row.entity_id)45 if type(row) in SUMMARY_MODELS and SUMMARY_MODELS[type(row)][0]=='contributions':46 return (row.session_id,row.calculation_id,row.evaluation_index,row.original_sequence,47 row.sequence,row.dataset_id,row.entity_id)48 if type(row) in SUMMARY_MODELS and SUMMARY_MODELS[type(row)][0]=='calculations':49 return (row.session_id, row.calculation_id, row.scope, row.parent_id or '',50 0, row.sequence, row.dataset_id, row.entity_id)51 if type(row) is SummarySegmentRow:52 return (row.session_id,row.window_id,row.start_ns if row.start_ns is not None else -(1<<63),53 row.sequence,row.dataset_id,row.entity_id)54 if type(row) in (SummaryEventRow, SummarySequenceRow):55 time = row.start_ns if type(row) is SummaryEventRow else row.decided_ns56 return (row.session_id,row.rule_id,time,row.sequence,row.dataset_id,row.entity_id)57 raise TypeError('未注册结果排序类型')58 finally:59 # 正常key元组不变;取消保原TB,但本层不再借持行、事件或片段的完整实体树。60 row = time = None61