bug fix
This commit is contained in:
parent
43e9db62d8
commit
bdd2c5124b
|
@ -28,16 +28,16 @@ POST
|
||||||
{
|
{
|
||||||
"province": "山东省",
|
"province": "山东省",
|
||||||
"city": "青岛市",
|
"city": "青岛市",
|
||||||
"capacity": 200MW, # 装机容量
|
"capacity": 200, # 装机容量,单位为kW
|
||||||
"angle": 38, # 用户设置倾角
|
"angle": 38, # 用户设置倾角
|
||||||
"dhi": [100.0, 123.1,..., 210.2] # 未来120小时的辐照
|
"dhi": [100.0, 123.1,..., 210.2] # 未来120小时的辐照,单位 W/m**-2
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
### 输出
|
### 输出
|
||||||
```
|
```
|
||||||
{
|
{
|
||||||
"code": 200,
|
"code": 200,
|
||||||
"data": [7.5, 8.6, ..., 7.2] # 未来120h的每小时发电量
|
"data": [7.5, 8.6, ..., 7.2] # 未来120h的每小时出力,单位为kW
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
## 未来光伏出力数据(复杂版)
|
## 未来光伏出力数据(复杂版)
|
||||||
|
@ -50,7 +50,7 @@ POST
|
||||||
{
|
{
|
||||||
"province": "山东省",
|
"province": "山东省",
|
||||||
"city": "青岛市",
|
"city": "青岛市",
|
||||||
"capacity": 200MW, # 装机容量(kW)
|
"capacity": 200, # 装机容量(kW)
|
||||||
"angle": 38, # 用户设置倾角
|
"angle": 38, # 用户设置倾角
|
||||||
"dhi": [100.0, 123.1,..., 210.2], # 未来120小时的辐照(数仓取数)
|
"dhi": [100.0, 123.1,..., 210.2], # 未来120小时的辐照(数仓取数)
|
||||||
"tmp": [27, 29, ..., 32], 未来120h气温(数仓取数)
|
"tmp": [27, 29, ..., 32], 未来120h气温(数仓取数)
|
||||||
|
|
38
run.py
38
run.py
|
@ -8,12 +8,11 @@ from logzero import logger
|
||||||
current_path = os.path.dirname(os.path.abspath(__file__)) # for local
|
current_path = os.path.dirname(os.path.abspath(__file__)) # for local
|
||||||
# current_path = "/app" # for docker
|
# current_path = "/app" # for docker
|
||||||
logger.info(f"{current_path}")
|
logger.info(f"{current_path}")
|
||||||
from tools import cal_generation, cal_angle, load_config
|
from tools import cal_generation, cal_angle, load_config, cal_complex_gen
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
angle_config = load_config(f"{current_path}/config/angle.json")
|
angle_config = load_config(f"{current_path}/config/angle.json")
|
||||||
|
|
||||||
|
|
||||||
@app.route('/angle/', methods=["POST"])
|
@app.route('/angle/', methods=["POST"])
|
||||||
def get_angle_info():
|
def get_angle_info():
|
||||||
resp_info = dict()
|
resp_info = dict()
|
||||||
|
@ -22,7 +21,7 @@ def get_angle_info():
|
||||||
city = request.json.get('city')
|
city = request.json.get('city')
|
||||||
logger.info(f"{prov}-{city}")
|
logger.info(f"{prov}-{city}")
|
||||||
try:
|
try:
|
||||||
best_angle = cal_angle(prov, city)
|
best_angle = cal_angle(prov, city, angle_config)
|
||||||
resp_info["code"] = 200
|
resp_info["code"] = 200
|
||||||
resp_info["data"] = best_angle
|
resp_info["data"] = best_angle
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -34,6 +33,30 @@ def get_angle_info():
|
||||||
|
|
||||||
@app.route('/power/', methods=["POST"])
|
@app.route('/power/', methods=["POST"])
|
||||||
def get_power():
|
def get_power():
|
||||||
|
resp_info = dict()
|
||||||
|
if request.method == "POST":
|
||||||
|
prov = request.json.get('province')
|
||||||
|
city = request.json.get('city')
|
||||||
|
cap = float(request.json.get('capacity'))
|
||||||
|
angle = float(request.json.get('angle'))
|
||||||
|
dhi_list = request.json.get('dhi')
|
||||||
|
dhi_list = [float(x) for x in dhi_list]
|
||||||
|
logger.info(dhi_list)
|
||||||
|
try:
|
||||||
|
best_angle = cal_angle(prov, city, angle_config)[0]
|
||||||
|
power_trend = cal_generation(cap, angle, best_angle, dhi_list)
|
||||||
|
resp_info["code"] = 200
|
||||||
|
resp_info["data"] = power_trend
|
||||||
|
except Exception as e:
|
||||||
|
logger.info(e)
|
||||||
|
resp_info["code"] = 406
|
||||||
|
resp_info["data"] = str(e)
|
||||||
|
resp = make_response(json.dumps(resp_info))
|
||||||
|
resp.status_code = 200
|
||||||
|
return resp
|
||||||
|
|
||||||
|
@app.route('/power_custom/', methods=["POST"])
|
||||||
|
def get_power_custom():
|
||||||
resp_info = dict()
|
resp_info = dict()
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
prov = request.json.get('province')
|
prov = request.json.get('province')
|
||||||
|
@ -41,9 +64,14 @@ def get_power():
|
||||||
cap = request.json.get('capacity')
|
cap = request.json.get('capacity')
|
||||||
angle = request.json.get('angle')
|
angle = request.json.get('angle')
|
||||||
dhi_list = request.json.get('dhi')
|
dhi_list = request.json.get('dhi')
|
||||||
|
tmp_list = request.json.get("tmp")
|
||||||
|
materials = request.json.get("materials")
|
||||||
|
sigma = request.json.get("sigma")
|
||||||
|
t_noct = request.json.get("t_noct")
|
||||||
try:
|
try:
|
||||||
best_angle = cal_angle(prov, city)
|
best_angle = cal_angle(prov, city)
|
||||||
power_trend = cal_generation(cap, angle, best_angle, dhi_list)
|
power_trend = cal_complex_gen(cap, angle, best_angle, dhi_list,
|
||||||
|
tmp_list, materials, sigma, t_noct)
|
||||||
resp_info["code"] = 200
|
resp_info["code"] = 200
|
||||||
resp_info["data"] = power_trend
|
resp_info["data"] = power_trend
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -55,4 +83,4 @@ def get_power():
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(port=9515, host="0.0.0.0", debug=False)
|
app.run(port=9515, host="0.0.0.0", debug=True)
|
||||||
|
|
25
tools.py
25
tools.py
|
@ -2,6 +2,7 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import json
|
import json
|
||||||
import math
|
import math
|
||||||
|
from logzero import logger
|
||||||
|
|
||||||
def load_config(path):
|
def load_config(path):
|
||||||
with open(path, 'r', encoding='utf-8') as fr:
|
with open(path, 'r', encoding='utf-8') as fr:
|
||||||
|
@ -29,17 +30,19 @@ def cal_angle(prov:str, city:str, angle_config:dict):
|
||||||
values = city_values
|
values = city_values
|
||||||
return values
|
return values
|
||||||
|
|
||||||
def cal_generation(cap: [int, float], angle, best_angle, dhi_list):
|
def cal_generation(cap:float, angle, best_angle, dhi_list):
|
||||||
"""_summary_
|
"""_summary_
|
||||||
G = Y * cos(|x - y|)* 0.9 * GHI
|
G = Y * cos(|x - y|)* 0.9 * GHI
|
||||||
"""
|
"""
|
||||||
dhi_list = np.asarray(dhi_list)
|
dhi_list = np.asarray(dhi_list)
|
||||||
return list(cap * math.cos(math.radians(abs(angle - best_angle))) * dhi_list)
|
logger.info(dhi_list)
|
||||||
|
index = math.cos(math.radians(abs(angle - best_angle)))
|
||||||
|
return list(cap * index * 0.9 * dhi_list / 1000)
|
||||||
|
|
||||||
|
|
||||||
def cal_complex_gen(cap:float, angle:float, best_angle:float,
|
def cal_complex_gen(cap:float, angle:float, best_angle:float,
|
||||||
dhi_list:list, t_list:list, materials:str, sigma:float=None,
|
dhi_list:list, t_list:list, materials:str, sigma:float=None,
|
||||||
t_noct:[float, int]=45, t_a_noct:[float, int]=20, g_noct:[float, int]=800, ita:float=0.083/0.9)->list:
|
t_noct:[float, int]=45)->list:
|
||||||
"""复杂的计算出力的方式
|
"""复杂的计算出力的方式
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -47,17 +50,17 @@ def cal_complex_gen(cap:float, angle:float, best_angle:float,
|
||||||
angle (float): _光伏安装倾角(°).
|
angle (float): _光伏安装倾角(°).
|
||||||
best_angle (float): _当地最佳安装倾角
|
best_angle (float): _当地最佳安装倾角
|
||||||
dhi_list (list): _未来120h辐照预测值,W/m2
|
dhi_list (list): _未来120h辐照预测值,W/m2
|
||||||
t_list (list): _未来120气温预测值,℃
|
t_list (list): _未来120h气温预测值,℃
|
||||||
materials (str): _晶体材料
|
materials (str): _晶体材料
|
||||||
sigma (float, optional): _温度系数(%/℃)取值一般为[-0.45 ~ -0.33],当该值不为None时,不通过晶体材料计算sigma. Defaults to None.
|
sigma (float, optional): _温度系数(%/℃)取值一般为[-0.45 ~ -0.33],当该值不为None时,不通过晶体材料计算sigma. Defaults to None.
|
||||||
t_noct (int, optional): _电池片结温. Defaults to 45.
|
t_noct (int, optional): _电池片结温. Defaults to 45.
|
||||||
t_a_noct (int, optional): _NOCT下的环境温度. Defaults to 20.
|
|
||||||
g_noct (int, optional): _NOCT下的辐照(W/m2). Defaults to 800.
|
|
||||||
ita (_type_, optional): _常数系数. Defaults to 0.083/0.9=0.0922
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
power_list(list[float]): 未来120h的小时出力,KW
|
power_list(list[float]): 未来120h的小时出力,KW
|
||||||
"""
|
"""
|
||||||
|
t_a_noct = 20
|
||||||
|
g_noct = 800
|
||||||
|
ita = 0.083 / 0.9
|
||||||
sigma_dict = {
|
sigma_dict = {
|
||||||
"N型单晶": -0.38,
|
"N型单晶": -0.38,
|
||||||
"P型单晶": -0.42,
|
"P型单晶": -0.42,
|
||||||
|
@ -65,8 +68,14 @@ def cal_complex_gen(cap:float, angle:float, best_angle:float,
|
||||||
}
|
}
|
||||||
t_list = np.asarray(t_list)
|
t_list = np.asarray(t_list)
|
||||||
dhi_list = np.asarray(dhi_list)
|
dhi_list = np.asarray(dhi_list)
|
||||||
t_cell = t_list + (t_noct - t_a_noct)*(dhi_list / g_noct)*(1-ita)
|
t_cell = t_list + (float(t_noct) - t_a_noct)*(dhi_list / g_noct)*(1-ita)
|
||||||
if sigma is None:
|
if sigma is None:
|
||||||
sigma = sigma_dict.get(materials, -0.42)
|
sigma = sigma_dict.get(materials, -0.42)
|
||||||
|
else:
|
||||||
|
sigma = float(sigma)
|
||||||
K = 1 + sigma / 100 * (t_cell - t_a_noct)
|
K = 1 + sigma / 100 * (t_cell - t_a_noct)
|
||||||
return list(cap * math.cos(math.radians(abs(angle - best_angle))) * dhi_list) * K
|
return list(cap * math.cos(math.radians(abs(angle - best_angle))) * dhi_list) * K
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print(cal_generation(200., 32, 33, [15., 21., 33., 94.]))
|
Loading…
Reference in New Issue