import glob
import os
import pandas as pd
import numpy as np
def KK(Q_out,Z,fg,zx,Qan):
qmax=Q_out.max()
qmin=Q_out.min()
T=len(Q_out)
sum0=0
for Q in Q_out:
kk=((Q-qmin)/(qmax-qmin))**2
sum0+=kk
k1=sum0/T
print('出流最大值', qmax)
print('出流最小值', qmin)
print('洪水时间不长', T)
print('k1', k1)
print('=======================')
Z_tt=Z.iloc[-1]
Z_t=Z.iloc[-2]
Zp=(Z_t+Z_tt)/2
zk2=(fg-Zp)/(fg-zx)
alph=10000
k2=zk2-abs(1-zk2)*alph
print('末1', Z_tt)
print('末2', Z_t)
print('末pin', Zp)
print('防洪限制水位', fg)
print('归一化结果zk2', zk2)
print('目标水位', zx)
print('k2', k2)
print('===================')
Zmax=Z.max()
zk3=(Zmax-zx)/(fg-zx)
if zk3<0.5:
k3=1-0.2*zk3
elif zk3>0.9:
k3=5*(1-zk3)
else:
k3 = 1.4 - zk3
print('汛限水位', zx)
print('最高水位', Zmax)
print('浮动防限水位',fg )
print('zka,归一结果',zk3 )
print('k3', k3)
print('========================')
k40=0
t=0
for q in Q_out:
if q>Qan:
k40+=(q-Qan)
t+=1
else:
k40+=0
if t==0:
k4=0
else:
k4=k40/t
print('下端安全流量', Qan)
print('流量的时段个数', t)
print('k4',k4)
print('===================')
sum1 = 0
for i, q in enumerate(Q_out):
if i < T-1:
sum1 += (Q_out[i] - Q_out[i + 1]) ** 2
Q_pin = np.mean(Q_out)
k5 = sum1 / Q_pin
print('下游防洪控制断面过流量方差', sum1)
print('下游防洪控制断面过流量均值', Q_pin)
print('k5', k5)
if __name__ == "__main__":
folder_path = r'C:\Users\fanfu\Desktop\联合调度'
excel_files = glob.glob(os.path.join(folder_path, '*.xls'))
for excel_file in excel_files:
print(excel_file)
df = pd.read_excel(excel_file)
Q_out=df['出流']
Z=df['水位']
fg=df['防洪高水位'][2]
zx=df['汛限水位'][2]
substring1 = "水库"
substring2 = "水库"
substring3 = "岭水库"
substring4 = "水库"
substring5 = "水库"
if substring1 in excel_file:
Qan = 3400
if substring2 in excel_file:
Qan = 900
if substring3 in excel_file:
Qan = 4435
if substring4 in excel_file:
Qan = 1617
if substring5 in excel_file:
Qan = 1820
KK(Q_out, Z, fg, zx, Qan)
print('-')
print('-')
print('-')
print('-')