Commit 86787903 authored by ZZH's avatar ZZH

fix inv eval 2024-12-31 15:34

parent ab0bf15a
...@@ -54,12 +54,12 @@ class EnergyModel: ...@@ -54,12 +54,12 @@ class EnergyModel:
if m.status == GRB.OPTIMAL: if m.status == GRB.OPTIMAL:
IOR = IOR.x IOR = IOR.x
irr = calculate_irr(revenue_year, Investment_Cost.getValue(), irr = calculate_irr(revenue_year, Investment_Cost.getValue(),
max_invest_year) self.max_invest_year)
if IOR > self.max_invest_year: if IOR > self.max_invest_year:
return {"Error": f"当前区域的投资回报比(IOR = {IOR:.2f})高于" return {"Error": f"当前区域的投资回报比(IOR = {IOR:.2f})高于"
f"设置的投资上限,建议不要投资。"} f"设置的投资上限,建议不要投资。"}
else: else:
result = { return {
'pv': 0, 'pv': 0,
'es_p': P_ES.x, 'es_cap': P_ES.x * 2, 'es_p': P_ES.x, 'es_cap': P_ES.x * 2,
'cg': P_CG.x, 'cg': P_CG.x,
...@@ -69,7 +69,6 @@ class EnergyModel: ...@@ -69,7 +69,6 @@ class EnergyModel:
'cost_kWh': round(cost_kWh, 2), 'cost_kWh': round(cost_kWh, 2),
'irr': irr 'irr': irr
} }
return result
else: else:
return {"Error": "当前限制条件不合理"} return {"Error": "当前限制条件不合理"}
...@@ -128,12 +127,13 @@ class EnergyModel: ...@@ -128,12 +127,13 @@ class EnergyModel:
if m.status == GRB.OPTIMAL: if m.status == GRB.OPTIMAL:
IOR = IOR.x IOR = IOR.x
irr = calculate_irr(revenue_year.getValue(), irr = calculate_irr(revenue_year.getValue(),
Investment_Cost.getValue(), max_invest_year) Investment_Cost.getValue(),
self.max_invest_year)
if IOR > self.max_invest_year: if IOR > self.max_invest_year:
return {"Error": f"当前区域的投资回报比(IOR = {IOR:.2f})高于" return {"Error": f"当前区域的投资回报比(IOR = {IOR:.2f})高于"
f"设置的投资上限,建议不要投资。"} f"设置的投资上限,建议不要投资。"}
else: else:
result = { return {
'pv': P_PV.x, 'pv': P_PV.x,
'es_p': P_ES.x, 'es_cap': P_ES.x * 2, 'es_p': P_ES.x, 'es_cap': P_ES.x * 2,
'cg': P_CG.x, 'cg': P_CG.x,
...@@ -143,7 +143,6 @@ class EnergyModel: ...@@ -143,7 +143,6 @@ class EnergyModel:
'cost_kWh': round(cost_kWh, 2), 'cost_kWh': round(cost_kWh, 2),
'irr': irr 'irr': irr
} }
return result
else: else:
return {"Error": "当前限制条件不合理"} return {"Error": "当前限制条件不合理"}
...@@ -210,11 +209,10 @@ class EnergyModel: ...@@ -210,11 +209,10 @@ class EnergyModel:
Investment_Cost.getValue(), Investment_Cost.getValue(),
max_invest_year) max_invest_year)
if IOR > self.max_invest_year: if IOR > self.max_invest_year:
return { return {"Error": f"当前区域的投资回报比(IOR = {IOR:.2f})"
"Error": f"当前区域的投资回报比(IOR = {IOR:.2f})高于" f"高于设置的投资上限,建议不要投资。"}
f"设置的投资上限,建议不要投资。"}
else: else:
result = { return {
'pv': P_PV.x, 'pv': P_PV.x,
'es_p': P_ES.x, 'es_cap': P_ES.x * 2, 'es_p': P_ES.x, 'es_cap': P_ES.x * 2,
'cg': P_CG.x, 'cg': P_CG.x,
...@@ -224,16 +222,14 @@ class EnergyModel: ...@@ -224,16 +222,14 @@ class EnergyModel:
'cost_kWh': round(cost_kWh, 2), 'cost_kWh': round(cost_kWh, 2),
'irr': irr 'irr': irr
} }
return result
except: except:
rlt_all = ems_model.all_calculate(dict(pv_cost=pv_cost, return self.all_calculate(dict(pv_cost=pv_cost,
sun_hrs_year=sun_hrs_year, sun_hrs_year=sun_hrs_year,
max_load=max_load, max_load=max_load,
min_load=min_load, min_load=min_load,
pv_eff=pv_eff, pv_eff=pv_eff,
pv_area=pv_area, pv_area=pv_area,
pv_limit=pv_limit)) pv_limit=pv_limit))
return rlt_all
def com_strategy(self, d_params): def com_strategy(self, d_params):
pv_cost = d_params["pv_cost"] pv_cost = d_params["pv_cost"]
...@@ -292,12 +288,13 @@ class EnergyModel: ...@@ -292,12 +288,13 @@ class EnergyModel:
if m.status == GRB.OPTIMAL: if m.status == GRB.OPTIMAL:
IOR = Investment_Cost.getValue() / revenue_year.getValue() IOR = Investment_Cost.getValue() / revenue_year.getValue()
irr = calculate_irr(revenue_year.getValue(), irr = calculate_irr(revenue_year.getValue(),
Investment_Cost.getValue(), max_invest_year) Investment_Cost.getValue(),
self.max_invest_year)
if IOR > self.max_invest_year: if IOR > self.max_invest_year:
return {"Error": f"当前区域的投资回报比(IOR = {IOR:.2f})高于" return {"Error": f"当前区域的投资回报比(IOR = {IOR:.2f})高于"
f"设置的投资上限,建议不要投资。"} f"设置的投资上限,建议不要投资。"}
else: else:
result = { return {
'pv': P_PV.x, 'pv': P_PV.x,
'es_p': P_ES.x, 'es_p': P_ES.x,
'es_cap': P_ES.x * 2, 'es_cap': P_ES.x * 2,
...@@ -308,7 +305,6 @@ class EnergyModel: ...@@ -308,7 +305,6 @@ class EnergyModel:
'cost_kWh': round(cost_kWh, 2), 'cost_kWh': round(cost_kWh, 2),
'irr': irr 'irr': irr
} }
return result
else: else:
return {"Error": "当前限制条件不合理"} return {"Error": "当前限制条件不合理"}
......
...@@ -15,7 +15,8 @@ class EmsInvEvalReq(Model): ...@@ -15,7 +15,8 @@ class EmsInvEvalReq(Model):
es_cost: float = Opt(Float("储能成本 元/kw").eg(1500)) es_cost: float = Opt(Float("储能成本 元/kw").eg(1500))
pv_cost: float = Opt(Float("年均负荷(kw)").eg(800)) pv_cost: float = Opt(Float("年均负荷(kw)").eg(800))
ele_price: float = Opt(Float("电价").eg(1.4)) ele_price: float = Opt(Float("电价").eg(1.4))
cg_cost: float = Opt(Float("煤制气成本加上燃料成本 元/kw").eg(8000)) cg_cost: float = Opt(Float("煤制气设备成本").eg(8000))
cg_fuel_cost: float = Opt(Float("煤制气燃料成本").eg(8000))
sale_price: float = Opt(Float("售电价格").eg(1000)) sale_price: float = Opt(Float("售电价格").eg(1000))
sale_cost: float = Opt(Float("售电成本价格").eg(0.5)) sale_cost: float = Opt(Float("售电成本价格").eg(0.5))
work_hours_year: float = Opt(Float("每年的工作时长").eg(2000)) work_hours_year: float = Opt(Float("每年的工作时长").eg(2000))
...@@ -29,6 +30,8 @@ class EmsInvEvalReq(Model): ...@@ -29,6 +30,8 @@ class EmsInvEvalReq(Model):
sale_limit: float = Opt(Float("售电限制kw*h").eg(100000)) sale_limit: float = Opt(Float("售电限制kw*h").eg(100000))
cg_eff: float = Opt(Float("煤制气效率").eg(0.8)) cg_eff: float = Opt(Float("煤制气效率").eg(0.8))
es_eff: float = Opt(Float("充电效率").eg(0.8)) es_eff: float = Opt(Float("充电效率").eg(0.8))
pv_deg_rate: float = Opt(Float("光伏衰减率").eg(0.8))
es_deg_rate: float = Opt(Float("储能衰减率").eg(0.8))
goal: int = Int("1保重要负荷2保所有负荷3可联网售电4综合成本最优").eg(1) goal: int = Int("1保重要负荷2保所有负荷3可联网售电4综合成本最优").eg(1)
......
...@@ -26,16 +26,22 @@ async def inv_eval(d_params): ...@@ -26,16 +26,22 @@ async def inv_eval(d_params):
sale_price = d_params["sale_price"] sale_price = d_params["sale_price"]
sale_limit = d_params["sale_limit"] sale_limit = d_params["sale_limit"]
sale_cost = d_params["sale_cost"] sale_cost = d_params["sale_cost"]
cg_fuel_cost = d_params["cg_fuel_cost"]
pv_deg_rate = d_params["pv_deg_rate"]
es_deg_rate = d_params["es_deg_rate"]
goal = d_params["goal"] goal = d_params["goal"]
rlt_cfg = {} rlt_cfg = {}
ems_model = EnergyModel(dict(load_year=load_year, ems_model = EnergyModel(dict(load_year=load_year,
imp_load_year=imp_load_year, imp_load_year=imp_load_year,
es_cost=es_cost, ele_price=ele_price, es_cost=es_cost, ele_price=ele_price,
cg_cost=cg_cost, cg_cost=cg_cost, cg_fuel_cost=cg_fuel_cost,
work_hours_year=work_hours_year, work_hours_year=work_hours_year,
max_invest_year=max_invest_year, max_invest_year=max_invest_year,
cg_eff=cg_eff, es_eff=es_eff)) cg_eff=cg_eff, es_eff=es_eff,
pv_deg_rate=pv_deg_rate,
es_deg_rate=es_deg_rate
))
if goal == 1: if goal == 1:
rlt_cfg = ems_model.cri_calculate() rlt_cfg = ems_model.cri_calculate()
......
...@@ -4,6 +4,7 @@ DATE:2024/12/30 10:15 ...@@ -4,6 +4,7 @@ DATE:2024/12/30 10:15
""" """
from pot_libs.sanic_api import summary from pot_libs.sanic_api import summary
from pot_libs.logger import log
from unify_api.modules.inv_eval.service.ems_srv import inv_eval from unify_api.modules.inv_eval.service.ems_srv import inv_eval
from unify_api.modules.inv_eval.components.ems_cps import ( from unify_api.modules.inv_eval.components.ems_cps import (
EmsInvEvalReq, EmsInvEvalRsp EmsInvEvalReq, EmsInvEvalRsp
...@@ -19,6 +20,7 @@ async def post_inv_eval(req, body: EmsInvEvalReq) -> EmsInvEvalRsp: ...@@ -19,6 +20,7 @@ async def post_inv_eval(req, body: EmsInvEvalReq) -> EmsInvEvalRsp:
pv_cost = body.pv_cost or 0 pv_cost = body.pv_cost or 0
ele_price = body.ele_price or 0 ele_price = body.ele_price or 0
cg_cost = body.cg_cost or 0 cg_cost = body.cg_cost or 0
cg_fuel_cost = body.cg_fuel_cost or 0
sale_price = body.sale_price or 0 sale_price = body.sale_price or 0
sale_cost = body.sale_cost or 0 sale_cost = body.sale_cost or 0
work_hours_year = body.work_hours_year or 0 work_hours_year = body.work_hours_year or 0
...@@ -32,16 +34,20 @@ async def post_inv_eval(req, body: EmsInvEvalReq) -> EmsInvEvalRsp: ...@@ -32,16 +34,20 @@ async def post_inv_eval(req, body: EmsInvEvalReq) -> EmsInvEvalRsp:
sale_limit = body.sale_limit or 0 sale_limit = body.sale_limit or 0
cg_eff = body.cg_eff or 0.8 cg_eff = body.cg_eff or 0.8
es_eff = body.es_eff or 0.8 es_eff = body.es_eff or 0.8
pv_deg_rate = body.pv_deg_rate or 0.6
es_deg_rate = body.es_deg_rate or 2.1
goal = body.goal goal = body.goal
d_params = dict(load_year=load_year, imp_load_year=imp_load_year, d_params = dict(load_year=load_year, imp_load_year=imp_load_year,
es_cost=es_cost, pv_cost=pv_cost, ele_price=ele_price, es_cost=es_cost, pv_cost=pv_cost, ele_price=ele_price,
cg_cost=cg_cost, work_hours_year=work_hours_year, cg_cost=cg_cost, cg_fuel_cost=cg_fuel_cost,
work_hours_year=work_hours_year,
max_invest_year=max_invest_year, max_invest_year=max_invest_year,
cg_eff=cg_eff, es_eff=es_eff, cg_eff=cg_eff, es_eff=es_eff,
sun_hrs_year=sun_hrs_year, sun_hrs_year=sun_hrs_year,
max_load=max_load, min_load=min_load, max_load=max_load, min_load=min_load,
pv_eff=pv_eff, pv_area=pv_area, pv_limit=pv_limit, pv_eff=pv_eff, pv_area=pv_area, pv_limit=pv_limit,
sale_price=sale_price, sale_limit=sale_limit, sale_price=sale_price, sale_limit=sale_limit,
pv_deg_rate=pv_deg_rate, es_deg_rate=es_deg_rate,
sale_cost=sale_cost, goal=goal) sale_cost=sale_cost, goal=goal)
cfg = await inv_eval(d_params) cfg = await inv_eval(d_params)
if "Error" in cfg: if "Error" in cfg:
...@@ -55,5 +61,50 @@ async def post_inv_eval(req, body: EmsInvEvalReq) -> EmsInvEvalRsp: ...@@ -55,5 +61,50 @@ async def post_inv_eval(req, body: EmsInvEvalReq) -> EmsInvEvalRsp:
irr=cfg.get("irr", 0), ior=cfg.get("ior", 0), irr=cfg.get("irr", 0), ior=cfg.get("ior", 0),
cost_kWh=cfg.get("cost_kWh", 0), ) cost_kWh=cfg.get("cost_kWh", 0), )
except Exception as e: except Exception as e:
log.error(f"cal ems inv eval error, e:{e}")
return EmsInvEvalRsp(pv=0, es_p=0, es_cap=0, cg=0, income_year=0, return EmsInvEvalRsp(pv=0, es_p=0, es_cap=0, cg=0, income_year=0,
total_inv_cost=0, irr=0, ior=0, cost_kWh=0) total_inv_cost=0, irr=0, ior=0, cost_kWh=0)
#
# async def main():
# load_year = 2500 # 年均负荷(kw)
# imp_load_year = 1500 # 年均重要负荷(kw)
# es_cost = 1500 # 储能成本 元/kw
# pv_cost = 800 # 光伏成本 元/kw
# ele_price = 1.4 # 电价
# cg_cost = 6000 # 煤制气设备成本元/kw
# cg_fuel_cost = 100 # 煤制气燃料成本元/kw
# sale_price = 50 # 售电价格元
# sale_cost = 0.5 # 售电价格元
# work_hours_year = 2000 # 每年的工作时长为2000小时
# sun_hrs_year = 1300 # 每年的光照时长为1300小时
# max_load = 6000 # kw
# min_load = 1000 # kw
# pv_area = 5000000 # 当前场地的光伏建设面积最大面积平方米
# pv_eff = 0.8 # 光伏效率
# max_invest_year = 5 # 当前投资收益最大限制
# pv_limit = 7000 # 光伏最大限制
# sale_limit = 2400000 # 售电限制kw*h
# pv_deg_rate = 0.6
# es_deg_rate = 2.1
# goal = 4
# d_params = dict(load_year=load_year, imp_load_year=imp_load_year,
# es_cost=es_cost, pv_cost=pv_cost, ele_price=ele_price,
# cg_cost=cg_cost, cg_fuel_cost=cg_fuel_cost,
# work_hours_year=work_hours_year,
# max_invest_year=max_invest_year,
# cg_eff=0.8, es_eff=0.8,
# sun_hrs_year=sun_hrs_year,
# max_load=max_load, min_load=min_load,
# pv_eff=pv_eff, pv_area=pv_area, pv_limit=pv_limit,
# sale_price=sale_price, sale_limit=sale_limit,
# pv_deg_rate=pv_deg_rate, es_deg_rate=es_deg_rate,
# sale_cost=sale_cost, goal=goal)
# cfg = await inv_eval(d_params)
# print(cfg)
#
#
# if __name__ == '__main__':
# import asyncio
#
# asyncio.run(main())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment