Files
ai-agent-admin/backend-fastapi/online_dev/report_manager/engine/convert.py
T

62 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
报表渲染引擎(Phase 3
- 参数单元格替换
- dataSource 单格填充
- dataSource 列表向下扩展(list / down
"""
from typing import Any, Dict, List, Optional
from online_dev.report_manager.engine.column_layout import apply_column_layout
from online_dev.report_manager.engine.code_cells import apply_code_cells
from online_dev.report_manager.engine.expression_eval import apply_expression_cells
from online_dev.report_manager.engine.merge_recalc import apply_merge_recalc_after_expand
from online_dev.report_manager.engine.preview_mvp import (
apply_parameter_cells,
apply_snapshot_placeholders,
)
def _apply_data_source_cells(
snapshot: Dict[str, Any],
cells_meta: Dict[str, Any],
datasets: Dict[str, List[Any]],
) -> tuple[Dict[str, Any], list[tuple[str, int, int, int]]]:
from online_dev.report_manager.engine.data_expand import apply_data_source_cells
return apply_data_source_cells(snapshot, cells_meta, datasets)
def transform(
snapshot: Dict[str, Any],
cells: Dict[str, Any],
datasets: Dict[str, List[Any]],
params: Optional[Dict[str, Any]] = None,
column_list: Optional[List[Any]] = None,
fence_list: Optional[List[Any]] = None,
) -> Dict[str, Any]:
"""
将数据集填充到 Univer snapshot。
"""
if not snapshot:
return snapshot or {}
cells_meta = cells or {}
params = params or {}
layout_list = fence_list if fence_list else column_list
original = snapshot
filled = apply_parameter_cells(snapshot, cells_meta, params)
filled = apply_snapshot_placeholders(filled, params)
filled = apply_code_cells(filled, params)
filled, pending_group_merges = _apply_data_source_cells(filled, cells_meta, datasets)
filled = apply_merge_recalc_after_expand(original, filled)
if pending_group_merges:
from online_dev.report_manager.engine.data_expand import apply_pending_group_merges
filled = apply_pending_group_merges(filled, pending_group_merges)
filled = apply_expression_cells(filled, cells_meta, datasets, params)
if layout_list:
filled = apply_column_layout(filled, layout_list)
return filled