feat: 新增电价参数配置功能

- 在Excel模板中新增电价参数项(默认0.4元/kWh)
- GUI界面显示电价参数,支持从Excel读取
- 核心计算逻辑集成电价参数,为后续经济性分析做准备
- 支持自定义电价或使用默认值
This commit is contained in:
dmy
2026-01-06 11:43:41 +08:00
parent 86e0e21b58
commit c54ad369a4
3 changed files with 27 additions and 2 deletions

View File

@@ -53,7 +53,8 @@ def create_template(output_file='windfarm_template.xlsx'):
# Create System Parameters data # Create System Parameters data
param_data = [ param_data = [
{'Parameter': 'Voltage (kV) / 电压 (kV)', 'Value': 66}, {'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) df_params = pd.DataFrame(param_data)

15
gui.py
View File

@@ -128,6 +128,21 @@ def index():
pf_str += " (默认)" pf_str += " (默认)"
params_text.append(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: for p in params_text:
ui.chip(p, icon="bolt").props("outline color=primary") ui.chip(p, icon="bolt").props("outline color=primary")

11
main.py
View File

@@ -18,6 +18,7 @@ plt.rcParams['axes.unicode_minus'] = False
# 常量定义 # 常量定义
VOLTAGE_LEVEL = 66000 # 66kV VOLTAGE_LEVEL = 66000 # 66kV
POWER_FACTOR = 0.95 POWER_FACTOR = 0.95
ELECTRICITY_PRICE = 0.4 # 元/kWh
# 1. 生成风电场数据(实际应用中替换为真实坐标) # 1. 生成风电场数据(实际应用中替换为真实坐标)
def generate_wind_farm_data(n_turbines=30, seed=42, layout='random', spacing=800): 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 system_params['voltage'] = val
elif 'factor' in key or '功率因数' in key: elif 'factor' in key or '功率因数' in key:
system_params['power_factor'] = val system_params['power_factor'] = val
elif 'price' in key or '电价' in key:
system_params['electricity_price'] = val
except ValueError: except ValueError:
pass pass
# 设置默认电价(如果参数表中未提供)
if 'electricity_price' not in system_params:
system_params['electricity_price'] = ELECTRICITY_PRICE
if system_params: if system_params:
print(f"成功加载系统参数: {system_params}") print(f"成功加载系统参数: {system_params}")
except Exception as e: 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) voltage = system_params.get('voltage', VOLTAGE_LEVEL)
power_factor = system_params.get('power_factor', POWER_FACTOR) 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) # 原始 specs 是 5 元素元组: (section, capacity, resistance, cost, is_optional)