|
@@ -4,15 +4,17 @@
|
|
|
@time: 2024/12/5
|
|
|
@desc:
|
|
|
"""
|
|
|
+import json
|
|
|
import os
|
|
|
import shutil
|
|
|
+import time
|
|
|
from typing import List
|
|
|
|
|
|
import gradio as gr
|
|
|
import pandas as pd
|
|
|
|
|
|
+from commom import f_read_file
|
|
|
from config import BaseConfig
|
|
|
-from strategy_parse import StrategyParse
|
|
|
from .manager import engine
|
|
|
|
|
|
DATA_SUB_DIR = "data"
|
|
@@ -60,6 +62,16 @@ def _get_upload_data(data) -> pd.ExcelFile:
|
|
|
return excel
|
|
|
|
|
|
|
|
|
+def _get_node_func_dict(data) -> dict:
|
|
|
+ node_func_dict_path = _get_save_path(data, BaseConfig.node_map_name)
|
|
|
+ if not os.path.exists(node_func_dict_path):
|
|
|
+ return None
|
|
|
+ with open(node_func_dict_path, mode="r", encoding="utf8") as f:
|
|
|
+ node_func_dict = f.read()
|
|
|
+ node_func_dict = json.loads(node_func_dict)
|
|
|
+ return node_func_dict
|
|
|
+
|
|
|
+
|
|
|
def f_project_is_exist(data):
|
|
|
project_name = engine.get(data, "project_name")
|
|
|
if project_name is None or len(project_name) == 0:
|
|
@@ -88,7 +100,7 @@ def f_data_upload(data):
|
|
|
data_path = _get_save_path(data, file_data.name, DATA_SUB_DIR, UPLOAD_DATA_PREFIX)
|
|
|
shutil.copy(file_data.name, data_path)
|
|
|
excel = _get_upload_data(data)
|
|
|
- df = excel.parse(sheet_name="流程")
|
|
|
+ df = excel.parse(sheet_name=BaseConfig.flow_sheet_name)
|
|
|
columns = excel.sheet_names
|
|
|
excel.close()
|
|
|
return {
|
|
@@ -102,13 +114,22 @@ def f_get_sheet_data(data):
|
|
|
excel = _get_upload_data(data)
|
|
|
df = excel.parse(sheet_name=sheet_name)
|
|
|
excel.close()
|
|
|
+
|
|
|
+ node_func_dict = _get_node_func_dict(data)
|
|
|
+ if node_func_dict is not None:
|
|
|
+ code = f_read_file(_get_save_path(data, node_func_dict[sheet_name]))
|
|
|
+ return {
|
|
|
+ engine.get_elem_by_id("data_upload"): gr.update(value=df),
|
|
|
+ engine.get_elem_by_id("code_view"): gr.update(value=code),
|
|
|
+ }
|
|
|
+
|
|
|
return {
|
|
|
- engine.get_elem_by_id("data_upload"): gr.update(value=df, visible=True)
|
|
|
+ engine.get_elem_by_id("data_upload"): gr.update(value=df)
|
|
|
}
|
|
|
|
|
|
|
|
|
def f_download_code(data):
|
|
|
- file_path = _get_save_path(data, "code.zip")
|
|
|
+ file_path = _get_save_path(data, BaseConfig.code_zip_name)
|
|
|
if os.path.exists(file_path):
|
|
|
return {engine.get_elem_by_id("download_code"): gr.update(value=file_path)}
|
|
|
else:
|
|
@@ -119,8 +140,8 @@ def f_verify_param(data):
|
|
|
excel = _get_upload_data(data)
|
|
|
columns = excel.sheet_names
|
|
|
excel.close()
|
|
|
- if "流程" not in columns:
|
|
|
- raise gr.Error(message=f'【流程】sheet不能为空', duration=5)
|
|
|
+ if BaseConfig.flow_sheet_name not in columns:
|
|
|
+ raise gr.Error(message=f'【{BaseConfig.flow_sheet_name}】sheet不能为空', duration=5)
|
|
|
return True
|
|
|
|
|
|
|
|
@@ -135,7 +156,7 @@ def f_code_generate(data, progress=gr.Progress(track_tqdm=True)):
|
|
|
all_param = engine.get_all(data)
|
|
|
|
|
|
# 清空储存目录
|
|
|
- _clean_base_dir(data)
|
|
|
+ # _clean_base_dir(data)
|
|
|
# 校验参数
|
|
|
if not f_verify_param(data):
|
|
|
yield _reset_component_state()
|
|
@@ -143,16 +164,31 @@ def f_code_generate(data, progress=gr.Progress(track_tqdm=True)):
|
|
|
yield _reset_component_state()
|
|
|
|
|
|
progress(0.01)
|
|
|
- excel = _get_upload_data(data)
|
|
|
|
|
|
- strategy_parse = StrategyParse(**all_param)
|
|
|
- strategy_parse.f_parse_strategy(excel, progress)
|
|
|
+ time.sleep(2)
|
|
|
+ excel = None
|
|
|
+ try:
|
|
|
+ excel = _get_upload_data(data)
|
|
|
|
|
|
- excel.close()
|
|
|
+ # strategy_parse = StrategyParse(**all_param)
|
|
|
+ # strategy_parse.f_parse_strategy(excel, progress)
|
|
|
+
|
|
|
+ excel.close()
|
|
|
+ except Exception as msg:
|
|
|
+ if excel is not None:
|
|
|
+ excel.close()
|
|
|
+ yield _reset_component_state()
|
|
|
+ raise gr.Error(message=f"系统错误【{msg}】", duration=5)
|
|
|
+
|
|
|
+ code_zip_file_path = _get_save_path(data, BaseConfig.code_zip_name)
|
|
|
+
|
|
|
+ node_func_dict = _get_node_func_dict(data)
|
|
|
|
|
|
- code_file_path = _get_save_path(data, "code.zip")
|
|
|
+ flow_code = f_read_file(_get_save_path(data, node_func_dict[BaseConfig.flow_sheet_name]))
|
|
|
|
|
|
progress(1)
|
|
|
|
|
|
yield {engine.get_elem_by_id("generate_progress"): gr.update(value="生成完成"),
|
|
|
- engine.get_elem_by_id("download_code"): gr.update(value=code_file_path, visible=True)}
|
|
|
+ engine.get_elem_by_id("download_code"): gr.update(value=code_zip_file_path, visible=True),
|
|
|
+ engine.get_elem_by_id("code_view"): gr.update(value=flow_code, visible=True),
|
|
|
+ }
|