From c54ad369a4376d6d39a6a3306489b29704a1ced7 Mon Sep 17 00:00:00 2001 From: dmy Date: Tue, 6 Jan 2026 11:43:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E7=94=B5=E4=BB=B7?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E9=85=8D=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在Excel模板中新增电价参数项(默认0.4元/kWh) - GUI界面显示电价参数,支持从Excel读取 - 核心计算逻辑集成电价参数,为后续经济性分析做准备 - 支持自定义电价或使用默认值 --- generate_template.py | 3 ++- gui.py | 15 +++++++++++++++ main.py | 11 ++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/generate_template.py b/generate_template.py index 16a8f82..02ccc37 100644 --- a/generate_template.py +++ b/generate_template.py @@ -53,7 +53,8 @@ def create_template(output_file='windfarm_template.xlsx'): # Create System Parameters data param_data = [ {'Parameter': 'Voltage (kV) / 电压 (kV)', 'Value': 66}, - {'Parameter': 'Power Factor / 功率因数', 'Value': 0.95} + {'Parameter': 'Power Factor / 功率因数', 'Value': 0.95}, + {'Parameter': 'Electricity Price (元/kWh) / 电价 (元/kWh)', 'Value': 0.4} ] df_params = pd.DataFrame(param_data) diff --git a/gui.py b/gui.py index b7e61d5..6bbae31 100644 --- a/gui.py +++ b/gui.py @@ -128,6 +128,21 @@ def index(): pf_str += " (默认)" params_text.append(pf_str) + # 获取电价 + ep = 0.4 # Default + is_default_ep = True + if ( + state.get("system_params") + and "electricity_price" in state["system_params"] + ): + ep = state["system_params"]["electricity_price"] + is_default_ep = False + + ep_str = f"电价: {ep} 元/kWh" + if is_default_ep: + ep_str += " (默认)" + params_text.append(ep_str) + for p in params_text: ui.chip(p, icon="bolt").props("outline color=primary") diff --git a/main.py b/main.py index c12a736..f97157a 100644 --- a/main.py +++ b/main.py @@ -18,6 +18,7 @@ plt.rcParams['axes.unicode_minus'] = False # 常量定义 VOLTAGE_LEVEL = 66000 # 66kV POWER_FACTOR = 0.95 +ELECTRICITY_PRICE = 0.4 # 元/kWh # 1. 生成风电场数据(实际应用中替换为真实坐标) def generate_wind_farm_data(n_turbines=30, seed=42, layout='random', spacing=800): @@ -224,8 +225,15 @@ def load_data_from_excel(file_path): system_params['voltage'] = val elif 'factor' in key or '功率因数' in key: system_params['power_factor'] = val + elif 'price' in key or '电价' in key: + system_params['electricity_price'] = val except ValueError: pass + + # 设置默认电价(如果参数表中未提供) + if 'electricity_price' not in system_params: + system_params['electricity_price'] = ELECTRICITY_PRICE + if system_params: print(f"成功加载系统参数: {system_params}") except Exception as e: @@ -1107,7 +1115,8 @@ def compare_design_methods(excel_path=None, n_clusters_override=None, interactiv voltage = system_params.get('voltage', VOLTAGE_LEVEL) power_factor = system_params.get('power_factor', POWER_FACTOR) - print(f"使用的系统参数: 电压={voltage} V, 功率因数={power_factor}") + electricity_price = system_params.get('electricity_price', ELECTRICITY_PRICE) + print(f"使用的系统参数: 电压={voltage} V, 功率因数={power_factor}, 电价={electricity_price} 元/kWh") # 准备三种电缆方案 # 原始 specs 是 5 元素元组: (section, capacity, resistance, cost, is_optional)