From 1ae38ab34bcbdff622c7623119ee54bad419f4ed Mon Sep 17 00:00:00 2001
From: zmk <496160012@qq.com>
Date: 星期三, 28 八月 2024 16:11:08 +0800
Subject: [PATCH] 提交代码

---
 CalHead.py |  908 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 754 insertions(+), 154 deletions(-)

diff --git a/CalHead.py b/CalHead.py
index 55ecad8..162383f 100644
--- a/CalHead.py
+++ b/CalHead.py
@@ -5,78 +5,129 @@
 @author: ZMK
 """
 
-import flopy
 import flopy.utils.binaryfile as bf
 import csv
 import Base as base
 import os
 import json
+import subprocess
+import re
 import ModelPeriod
 import numpy as np
+import AchiveReport
 
-
+#娣诲姞modle
+def addModelJson(model_name,start_time,end_time,remark):
+  
+      context=""
+      prediction_path = base.prefix + "\\model_list.json"
+      with open(prediction_path,encoding='utf-8') as f:
+             context = json.load(f)   
+      array=[]
+      for item in context:
+             array.append(item) 
+             
+      dicts={"model_name":model_name,
+              "start_time":start_time,"end_time":end_time,"remark":remark} 
+      array.append(dicts)
+      
+      with open(prediction_path, "w",encoding='utf-8') as outfile:
+          json.dump(array, outfile,ensure_ascii=False)
+      return "淇濆瓨瀹屾瘯锛�"; 
+    
+#鍒犻櫎model
+def removeModelJson(model_name):
+      context=""
+      prediction_path = base.prefix + "\\model_list.json"
+      with open(prediction_path,encoding='utf-8') as f:
+             context = json.load(f)   
+      array=[]
+      for item in context:
+          if item["model_name"] != model_name:
+              array.append(item) 
+              
+      with open(prediction_path, "w",encoding='utf-8') as outfile:
+          json.dump(array, outfile,ensure_ascii=False)
+          
+      return "鍒犻櫎妯″瀷瀹屾瘯锛�"; 
+    
 
 def get_model_json(model_name):
       period_json=""
       prediction_path = base.model_dir + model_name +"\\prediction.json"
       with open(prediction_path,encoding='utf-8') as f:
-             period_json = json.load(f)  
-     
+             period_json = json.load(f)    
       return period_json; 
   
 def get_model_period(model_name):
-     period_json=""
-     prediction_path = base.model_dir + model_name +"\\prediction.json"
-     with open(prediction_path,encoding='utf-8') as f:
-             period_json = json.load(f)  
-     
+     period_json= get_model_json(model_name)     
      start_time = period_json["start_time"]
-     end_time = period_json["end_time"]
-      
+     end_time = period_json["end_time"]    
      months = ModelPeriod.get_months_in_range_ym(start_time, end_time)
      return months; 
     
+def is_cloned_model(model_name):
+    paths = base.model_dir + model_name + "\\water_bal.txt"
+    if os.path.exists(paths):
+        return False
+    return True
+    
 
 #瑙傛祴浜昪hart
-def obsChartdata(model_name, row, column):
+def obsChartdata(wellId,model_name, row, column):
     
       row = int(row)-1
       column = int(column)-1
-      dir = base.model_dir + model_name + "\\modflow.head"
-
-      head = bf.HeadFile(dir)
-      alldata = head.get_alldata()
-      period = len(alldata)
-
-      layer = 3
-
-      xdata = []
-      ydata = []
-      result = {}
-      for per in range(period):
-           for lay in range(layer):
-               if per % 3 == 0 and lay == 0:
-                   md = (int)(lay / 3 + 1)
-                   per_array = alldata[per][lay]
-
-                   cell_data = (float)(per_array[row][column])
-                   ydata.append(cell_data)
-    
-      period_json= get_model_json(model_name)
-      
+      dir=""    
+      period_json= get_model_json(model_name)    
       start_time = period_json["start_time"]
       end_time = period_json["end_time"]
+      xmonths = ModelPeriod.get_months_in_range_ym(start_time, end_time)
       
-      months = ModelPeriod.get_months_in_range_ym(start_time, end_time)
-
-      result = {"y_data": ydata, "x_data": months}
+      if model_name == base.not_allowed_model:
+          dir = base.baseModel2  + "\\modflow.head"
+      else:
+          dir = base.model_dir + model_name + "\\modflow.head"
+          cloned = is_cloned_model(model_name)
+          if cloned ==True:
+              return  {"y_data": [],"y_data2":[],"x_data":xmonths }
+          
+      head = bf.HeadFile(dir)
+      alldata = head.get_alldata()
+      
+      #鍛ㄦ湡鏁�
+      months = int(len(alldata)/3)
+      ydata= []
+      result = {}
+      for month in range(months):
+          z1= alldata[int(month+1)*3-1,0,:,:]
+          cell_data = float(z1[row][column])
+          ydata.append(round(cell_data,2))
+    
+      y_data2=[]
+      if model_name == base.not_allowed_model:
+          array_data =  np.loadtxt(base.obswell_data_path, dtype=str,encoding='utf-8')
+          y_data2= getObsData(wellId,array_data)
+          
+      result = {"y_data": ydata,"y_data2":y_data2,"x_data": xmonths}
       return result
 
-def getRowCloumnById(index_id):
-    row = 104
-    column =114
-    count=0
+def getObsData(wellId,array_data):
+    result =[]
+    new_list =[]
+    for item in array_data:
+        if item[0]==wellId:
+            result.append(item[3])
+    for i in range(0,len(result),3):
+        data =( float(result[i]) +float(result[i+1])+float(result[i+2]))/3
+        data = round(data,2)
+        new_list.append(data)
+        
+    return new_list;
     
+    
+def getRowCloumnById(index_id):
+    row,column,count = 104,114,0
     for  i in range(row):
         for j in range(column):
             if index_id == count:
@@ -89,116 +140,39 @@
 #鍦颁笅姘翠俊鎭�
 def earthWaterChart(model_name, index_id):
     
-      row_column =  getRowCloumnById(index_id)
-      
+      row_column =  getRowCloumnById(index_id)  
       row = row_column[0]
       column = row_column[1]
-      dir = base.model_dir + model_name + "\\modflow.head"
-
-      head = bf.HeadFile(dir)
-      alldata = head.get_alldata()
-      period = len(alldata)
-
-      layer = 3
-
-      ydata = []
-      result = {}
-      for per in range(period):
-           for lay in range(layer):
-               if per % 3 == 0 and lay == 0:
-                  
-                   per_array = alldata[per][lay]
-
-                   cell_data = (float)(per_array[row][column])
-                   ydata.append(cell_data)
-    
-      period_json= get_model_json(model_name)
       
+      period_json= get_model_json(model_name)    
       start_time = period_json["start_time"]
       end_time = period_json["end_time"]
+      xmonths = ModelPeriod.get_months_in_range_ym(start_time, end_time)
+      dir = ""
+      if model_name == base.not_allowed_model:
+          dir = base.baseModel2  + "\\modflow.head"
+      else:
+          dir = base.model_dir + model_name + "\\modflow.head"
+          cloned = is_cloned_model(model_name)
+          if cloned ==True:
+              return  {"y_data": [],"x_data":xmonths }
       
-      months = ModelPeriod.get_months_in_range_ym(start_time, end_time)
+      head = bf.HeadFile(dir)
+      alldata = head.get_alldata()
+      
+      #鍛ㄦ湡鏁�
+      months = int(len(alldata)/3)
+      ydata= []
+      result = {}
+      for month in range(months):
+          z1= alldata[int(month+1)*3-1,0,:,:]
+          cell_data = float(z1[row][column])
+          ydata.append(round(cell_data,2))
 
-      result = {"y_data": ydata, "x_data": months}
+      result = {"y_data": ydata, "x_data": xmonths}
       return result
-
-def heatmapdata(model_name,period):
-    dir = base.model_dir + model_name + "\\modflow.head"
-      
-    head = bf.HeadFile(dir)
-
-    alldata = head.get_alldata()
+   
     
-    index = int(period)*3
-    return alldata[index][0]
-
-
-#姘村潎琛¤绠�
-def waterEqu(model_name):
-    if model_name == '202001_202212':  
-        water_equ_path = base.prefix + "\\water_equ.json"
-        with open(water_equ_path,encoding='utf-8') as f:
-             data = json.load(f)
-             return data       
-    else:
-        year = model_name[0:4]
-        title =[year]
-        dict ={"title":title}
-        
-        celldata = np.array(base.water_equ2022).tolist()
-      
-        predict_json= get_model_json(model_name)
-        
-        a1=float(celldata[0])
-        a2=float(celldata[1])
-        a3=float(celldata[2])
-        a4=float(celldata[3])
-        
-        b1=float(celldata[4])
-        b2=float(celldata[5])
-        b3=float(celldata[6])
-        
-        if predict_json["rain"]:
-            a1= float(predict_json["rain"]["ratio"]) * float(celldata[0])  
-            a3= float(predict_json["rain"]["ratio"]) * float(celldata[2]) 
-            a4= float(predict_json["rain"]["ratio"]) * float(celldata[3])        
-            b2= float(predict_json["rain"]["ratio"]) * float(celldata[5]) 
-            b3= float(predict_json["rain"]["ratio"]) * float(celldata[6])     
-        if predict_json["river"]:
-            a2=  float(predict_json["river"]["ratio"]) * float(celldata[1])
-            
-        if predict_json["mine"]:
-            b1=  b1    
-        
-        in_data= a1+a2+a3+a4
-        out_data= b1 +b2 + b3
-        float_data=[a1,a2,a3,a4,in_data,b1,b2,b3,out_data,in_data-out_data]
-        
-        inarray=[]
-        inarray.append({"name":"闄嶆按鍏ユ笚閲�","value":a1})
-        inarray.append({"name":"娌虫祦鍏ユ笚閲�","value":a2})
-        inarray.append({"name":"L1渚у悜琛ョ粰閲�","value":a3})
-        inarray.append({"name":"L3渚у悜琛ョ粰閲�","value":a4})
-        outarray=[]
-        outarray.append({"name":"浜哄伐寮�閲囬噺","value":b1})
-        outarray.append({"name":"L1渚у悜娴佸嚭閲�","value":b2})
-        outarray.append({"name":"L3渚у悜娴佸嚭閲�","value":b3})
-        pie1={str(year):inarray}
-        pie2={str(year):outarray}
-        
-        dict["pie1"]=pie1
-        dict["pie2"]=pie2
-        
-        array2d=[]
-        array2d.append([str(year)])
-        for i in range(len(float_data)):
-            tmp=[]
-            tmp.append(str(float_data[i]))
-            array2d.append(tmp)
-        dict["data"]=array2d
-        return dict
-        
-
 #瀵煎嚭csv鏂囦欢
 def exportCsV(model_name):
     
@@ -207,26 +181,652 @@
     if not os.path.exists(out_path):
          os.mkdir(out_path)  
     
-    head = bf.HeadFile(dir)
-
+    # z1= alldata[int(per1)*3,0,:,:]
+    head = bf.HeadFile(dir) 
     alldata = head.get_alldata()
-    month = len(alldata)
-    layer = 3
-
-    for i in range(month):
-       for j in range(layer):
-          if i % 3 == 0:
-            md = (int)(i / 3 + 1)
-            filename = out_path + str(md) + '-' + str(j+1) + '.csv'
+    months = int(len(alldata)/3)  
+    layers = 3
+    #渚嬪 0-36鏈�
+    for month in range(months):
+        for layer in range (layers):
+            z_last= alldata[(month+1)*3-1,layer,:,:]
+            
+            filename = out_path + str(month+1) + '-' + str(layer+1) + '.csv'
             f = open(filename, 'w', newline='')
             writer = csv.writer(f)
-            for p in alldata[i][j]:
+           
+            for p in z_last:
                writer.writerow(p)
             f.close()
-
+            
     return out_path
  
+    
+#姘村潎琛¤绠�
+def waterEqu(model_name):
+    if model_name == base.not_allowed_model:  
+        water_equ_path = base.prefix + "\\water_equ.json"
+        with open(water_equ_path,encoding='utf-8') as f:
+             data = json.load(f)
+             return data       
+    else:
+        year = model_name
+        title =[year]
+        dict ={"title":title}
+        
+        jx = get_model_json(model_name)
+        dict["start_time"]=jx["start_time"]
+        dict["end_time"]=jx["end_time"]
+        
+        paths=base.model_dir + model_name +"\\water_bal.txt"
+        wat = water_balance(model_name, paths)
+        
+        in_data= round(wat[0]+ wat[1]+ wat[2]+ wat[3] , 4)
+        out_data= round(wat[4] + wat[5] +  wat[6], 4)
+        inout = round(in_data-out_data, 4)
+        float_data=[wat[0],wat[1],wat[2],wat[3],in_data,
+                     wat[4],wat[5], wat[6],out_data,inout]
+        
+        inarray=[]
+        inarray.append({"name":"闄嶆按鍏ユ笚閲�","value":wat[0]})
+        inarray.append({"name":"娌虫祦鍏ユ笚閲�","value":wat[1]})
+        inarray.append({"name":"涓�灞備晶鍚戣ˉ缁欓噺","value":wat[2]})
+        inarray.append({"name":"涓夊眰渚у悜琛ョ粰閲�","value":wat[3]})
+        outarray=[]
+        outarray.append({"name":"浜哄伐寮�閲囬噺","value":wat[4]})
+        outarray.append({"name":"涓�灞備晶鍚戞祦鍑洪噺","value":wat[5]})
+        outarray.append({"name":"涓夊眰渚у悜娴佸嚭閲�","value":wat[6]})
+        pie1={str(year):inarray}
+        pie2={str(year):outarray}
+        
+        dict["pie1"]=pie1
+        dict["pie2"]=pie2
+        
+        array2d=[]
+        array2d.append(["鏁版嵁锛堜嚎绔嬫柟绫筹級"])
+        for i in range(len(float_data)):
+            tmp=[]
+            tmp.append(str(float_data[i]))
+            array2d.append(tmp)
+        dict["data"]=array2d
+        return dict        
 
 
 
+def run_zonebudget_bal(model_name):
+    # 瀹氫箟exe鏂囦欢鐨勮矾寰勫拰鍙傛暟  
+    exe_path = base.ZoneBudget64Exe
+    txt_path = base.model_dir + model_name + "\\water_bal.txt\n"
+    cell_path = base.model_dir + model_name + "\\modflow.flow\n"
+    process = subprocess.Popen([exe_path], stdin=subprocess.PIPE,shell = True) 
+    process.stdin.write(txt_path.encode())  # 杈撳叆鍙傛暟1  
+    process.stdin.write(cell_path.encode()) 
+    process.stdin.write(b"title\n") 
+    process.stdin.write(base.water_bal_zones.encode()) 
+    process.stdin.write(b"A\n")
+    output, _ = process.communicate()
+    print(output)
+
+
+def run_zonebudget_res(model_name):
+    # 瀹氫箟exe鏂囦欢鐨勮矾寰勫拰鍙傛暟  
+    exe_path = base.ZoneBudget64Exe
+    txt_path = base.model_dir + model_name + "\\water_res.txt\n"
+    cell_path = base.model_dir + model_name + "\\modflow.flow\n"
+    process = subprocess.Popen([exe_path], stdin=subprocess.PIPE,shell = True) 
+    process.stdin.write(txt_path.encode())  # 杈撳叆鍙傛暟1  
+    process.stdin.write(cell_path.encode()) 
+    process.stdin.write(b"title\n") 
+    process.stdin.write(base.water_res_zones.encode()) 
+    process.stdin.write(b"A\n")
+    output, _ = process.communicate()
+    print(output)
+
+def reg_find_int(text):
+    numbers = re.findall(r'\d+', text)
+    return numbers
+
+
+def read_txt(path):
+    data =[]
+    with open(path, 'r') as file:
+        lines = file.readlines()   
+        for line in lines:
+           data.append(line)
+    return data  
    
+#瑙f瀽姘村潎琛℃暟鎹� 
+def water_balance(model_name,paths):
+    data= read_txt(paths)  
+    lens = len(data) 
+    index = 0 
+    segment=[]
+    dicts={}
+    flag = 0
+    title=""
+    while index < lens:
+        strs = data[index].strip()
+        if strs.startswith("Flow Budget for Zone"):
+            segment=[]
+            flag = 1
+            title=strs
+        if strs.startswith("Percent Discrepancy"):
+            segment.append(strs) 
+            numbers = reg_find_int(title)
+            key = ','.join(numbers)
+            dicts[key]=segment
+            flag = 0       
+        if flag ==1 :
+            segment.append(strs)
+        index=index+1
+        
+    recharge = 0  
+    for key in dicts:
+        array = dicts[key]
+        temp=[]
+        for item in array:
+            if item.startswith("RECHARGE") :
+                strs = item.replace(" ", "").replace("RECHARGE=", "")
+                temp.append(float(strs))
+                
+        recharge += (temp[0]-temp[1])
+    
+    #娌虫祦鍏ユ笚閲忥紙姝o級	鎵�鏈夊簲鍔涙湡锛宖or Zone 3鐨刉ELLS椤圭浉鍔�
+    zone3 = 0
+    for key in dicts:
+        if key.startswith("3,"):
+            array = dicts[key]
+            temp=[]
+            for item in array:
+                 if item.startswith("WELLS") :
+                     strs = item.replace(" ", "").replace("WELLS=", "")
+                     temp.append(float(strs))
+       
+            zone3 += (temp[0]-temp[1])
+             
+    #L1渚у悜琛ョ粰閲忥紙姝o級	鎵�鏈夊簲鍔涙湡锛宖or Zone 4鐨処N-WELLS椤圭浉鍔�
+    Zone4_in_well=0
+    for key in dicts:
+        if key.startswith("4,"):
+            array = dicts[key]
+            for item in array:
+                 if item.startswith("WELLS") :
+                     strs = item.replace(" ", "").replace("WELLS=", "")
+                     data = float(strs)
+                     Zone4_in_well +=data
+                     break
+    
+    #L3渚у悜琛ョ粰閲忥紙姝o級	鎵�鏈夊簲鍔涙湡锛宖or Zone 8鐨処N-WELLS椤圭浉鍔�
+    Zone8_in_well =0 
+    for key in dicts:
+        if key.startswith("8,"):
+            array = dicts[key]
+            for item in array:
+                 if item.startswith("WELLS") :
+                     strs = item.replace(" ", "").replace("WELLS=", "")
+                     data = float(strs)
+                     Zone8_in_well +=data
+                     break   
+    
+    #浜哄伐寮�閲囬噺锛堣礋锛�	鎵�鏈夊簲鍔涙湡锛宖or Zone 5鐨凮UT-WELLS椤圭浉鍔�
+    zone5out =0
+    for key in dicts:
+        if key.startswith("5,"):
+            array = dicts[key]
+            for item in array:
+                 if item.startswith("WELLS") :
+                     strs = item.replace(" ", "").replace("WELLS=", "")
+                     data = float(strs)
+                     zone5out +=data 
+     
+      #L1渚у悜娴佸嚭閲忥紙璐燂級	鎵�鏈夊簲鍔涙湡锛宖or Zone 4鐨凮UT-WELLS椤圭浉鍔�  
+    Zone4_out_well=0  
+    for key in dicts:
+        if key.startswith("4,"):
+            array = dicts[key]
+            for item in array:
+                 if item.startswith("WELLS") :
+                     strs = item.replace(" ", "").replace("WELLS=", "")
+                     data = float(strs)
+                     Zone4_out_well +=data
+     
+    # L3=L3渚у悜娴佸嚭閲忥紙璐燂級
+    L3=0.0
+    result =[recharge,zone3,Zone4_in_well,Zone8_in_well,zone5out,Zone4_out_well,L3]
+    for i in range(len(result)):
+        # 姣忚鏁版嵁瀹為檯涓婅绠� 鐨勬槸 涓�涓猻tep , 1涓猻tep =10澶�
+        result[i]= round(result[i]/100000000*10, 4)
+    
+    return result
+
+
+#瑙f瀽姘磋祫婧愰噺鏁版嵁 
+def water_res(model_name,paths):
+    data= read_txt(paths) 
+    lens = len(data)
+    index = 0
+    segment=[]
+    dicts={}
+    flag = 0
+    title=""
+    while index < lens:
+        strs = data[index].strip()
+        if strs.startswith("Flow Budget for Zone"):
+            segment=[]
+            flag = 1
+            title=strs
+        if strs.startswith("Percent Discrepancy"):
+            segment.append(strs) 
+            numbers = reg_find_int(title)
+            key = ','.join(numbers)
+            dicts[key]=segment
+            flag = 0       
+        if flag ==1 :
+            segment.append(strs)
+        index=index+1
+        
+    # 澶ф皵闄嶆按	for zone1閲屾墍鏈夌殑recharge椤圭浉鍔狅紙鍖呮嫭in鍜宱ut锛�
+    zone1_rechage = 0
+    
+    for key in dicts:
+       if key.startswith("1,"):
+          array = dicts[key]
+          temp=[]
+          for item in array:
+              if item.startswith("RECHARGE") :
+                  strs = item.replace(" ", "").replace("RECHARGE=", "")
+                  temp.append(float(strs))
+                
+          zone1_rechage += (temp[0]-temp[1])
+    
+    #姘稿畾娌虫笚婕�	for zone1閲屾墍鏈夌殑zone2椤圭浉鍔狅紙鍖呮嫭in鍜宱ut锛�
+    zone1_well = 0
+    for key in dicts:
+        if key.startswith("1,"):
+            array = dicts[key]
+            indata,outdata= 0,0
+            for item in array:
+                 if item.startswith("Zone   2 to   1") :
+                     strs = item.replace(" ", "").replace("Zone2to1=", "")
+                     indata = float(strs)
+                     
+                 if item.startswith("Zone   1 to   2") :
+                     strs = item.replace(" ", "").replace("Zone1to2=", "")
+                     outdata = float(strs)
+       
+            zone1_well += (indata-outdata)
+           
+    #渚у悜娴佸叆	For zone7 閲屾墍鏈夌殑zone8椤圭浉鍔狅紙鍖呮嫭in鍜宱ut锛�
+    zone7=0
+    for key in dicts:
+        if key.startswith("7,"):
+            array = dicts[key]
+            indata,outdata= 0,0
+            for item in array:
+                 if item.startswith("Zone   8 to   7") :
+                     strs = item.replace(" ", "").replace("Zone8to7=", "")
+                     indata = float(strs)
+                   
+                 if item.startswith("Zone   7 to   8") :
+                     strs = item.replace(" ", "").replace("Zone7to8=", "")
+                     outdata = float(strs)
+                    
+            zone7 += (indata-outdata)
+    
+    #瓒婃祦鎺掓硠	For zone6 閲屾墍鏈夌殑zone7椤圭浉鍔狅紙鍖呮嫭in鍜宱ut锛�
+    zone6 =0 
+    for key in dicts:
+        if key.startswith("6,"):
+            array = dicts[key]
+            indata,outdata= 0,0
+            for item in array:
+                 if item.startswith("Zone   7 to   6") :
+                     strs = item.replace(" ", "").replace("Zone7to6=", "")
+                     indata = float(strs)
+                     
+                 if item.startswith("Zone   6 to   7") :
+                     strs = item.replace(" ", "").replace("Zone6to7=", "")
+                     outdata = float(strs)
+            zone6 += (indata-outdata)
+    
+    result =[zone1_rechage,zone1_well,zone7,zone6]
+    for i in range(len(result)):
+        result[i]= round(result[i]/100000000*10,4)
+    return result
+
+
+ #瑙f瀽姘磋祫婧愰噺鏁版嵁 
+def water_res_month(model_name,paths,per):
+    data= read_txt(paths) 
+    lens = len(data)
+    index = 0
+    segment=[]
+    dicts={}
+    flag = 0
+    title=""
+    while index < lens:
+        strs = data[index].strip()
+        if strs.startswith("Flow Budget for Zone"):
+            segment=[]
+            flag = 1
+            title=strs
+        if strs.startswith("Percent Discrepancy"):
+            segment.append(strs) 
+            numbers = reg_find_int(title)
+            key = ','.join(numbers)
+            dicts[key]=segment
+            flag = 0       
+        if flag ==1 :
+            segment.append(strs)
+        index=index+1
+        
+    # 澶ф皵闄嶆按	for zone1閲屾墍鏈夌殑recharge椤圭浉鍔狅紙鍖呮嫭in鍜宱ut锛�
+    zone1_rechage = 0
+    zone1_keys=[ "1,1,"+str(per+1),"1,2,"+str(per+1),"1,3,"+str(per+1)]
+    for key in zone1_keys:
+          array = dicts[key]
+          temp=[]
+          for item in array:
+              if item.startswith("RECHARGE") :
+                  strs = item.replace(" ", "").replace("RECHARGE=", "")
+                  temp.append(float(strs))   
+          zone1_rechage += (temp[0]-temp[1])
+          
+    #姘稿畾娌虫笚婕�	for zone1閲屾墍鏈夌殑zone2椤圭浉鍔狅紙鍖呮嫭in鍜宱ut锛�
+    zone1_well = 0
+    zone1_well_keys=["1,1,"+str(per+1),"1,2,"+str(per+1),"1,3,"+str(per+1)]
+    for key in zone1_well_keys:
+            array = dicts[key]
+            indata,outdata= 0,0
+            for item in array:
+                 if item.startswith("Zone   2 to   1") :
+                     strs = item.replace(" ", "").replace("Zone2to1=", "")
+                     indata = float(strs)
+                     
+                 if item.startswith("Zone   1 to   2") :
+                     strs = item.replace(" ", "").replace("Zone1to2=", "")
+                     outdata = float(strs)
+       
+            zone1_well += (indata-outdata)
+           
+    #渚у悜娴佸叆	For zone7 閲屾墍鏈夌殑zone8椤圭浉鍔狅紙鍖呮嫭in鍜宱ut锛�
+    zone7=0
+    zone7_keys=["7,1,"+str(per+1),"7,2,"+str(per+1),"7,3,"+str(per+1)]
+    for key in zone7_keys:
+            array = dicts[key]
+            indata,outdata= 0,0
+            for item in array:
+                 if item.startswith("Zone   8 to   7") :
+                     strs = item.replace(" ", "").replace("Zone8to7=", "")
+                     indata = float(strs)
+                     
+                 if item.startswith("Zone   7 to   8") :
+                     strs = item.replace(" ", "").replace("Zone7to8=", "")
+                     outdata = float(strs)
+            zone7 += (indata-outdata)
+  
+    #瓒婃祦鎺掓硠	For zone6 閲屾墍鏈夌殑zone7椤圭浉鍔狅紙鍖呮嫭in鍜宱ut锛�
+    zone6 =0 
+    zone6_keys=["6,1,"+str(per+1),"6,2,"+str(per+1),"6,3,"+str(per+1)]
+    for key in zone6_keys:
+            array = dicts[key]
+            indata,outdata= 0,0
+            for item in array:
+                 if item.startswith("Zone   7 to   6") :
+                     strs = item.replace(" ", "").replace("Zone7to6=", "")
+                     indata = float(strs)
+                     
+                 if item.startswith("Zone   6 to   7") :
+                     strs = item.replace(" ", "").replace("Zone6to7=", "")
+                     outdata = float(strs)
+            zone6 += (indata-outdata)
+ 
+    result =[zone1_rechage,zone1_well,zone7,zone6]
+    for i in range(len(result)):
+        result[i]= round(result[i]/100000000*10, 4)
+    
+    return result  
+
+#澶氭ā鍨嬬殑姘翠綅
+def water_depth(model_name):
+    name_array = model_name.split(",")
+    
+    yhyMatrix = np.loadtxt(base.water_yhy_path, dtype=str,encoding='utf-8')
+    lshMatrix  = np.loadtxt(base.water_lsh_path, dtype=str,encoding='utf-8')
+    dbwMatrix =  np.loadtxt(base.water_dbw_path, dtype=str,encoding='utf-8')
+    
+    res ={} 
+    #棰愬拰鍥紝鑾茬煶婀栵紝涓滃寳鏃虹殑姘村钩绾垮拰澶氭ā鍨嬬殑澶氭姌绾垮�� 
+    yhydata=[]
+    base1={"name":"鍦拌〃楂樼▼","data":[52]*12}
+    yhydata.append(base1)
+    
+    lshdata=[]
+    base2={"name":"鍦拌〃楂樼▼","data":[80]*12}
+    lshdata.append(base2)
+    
+    dbwdata=[]
+    base3={"name":"鍦拌〃楂樼▼","data":[49]*12}
+    dbwdata.append(base3)
+    
+    months = ModelPeriod.get_months_in_range_ym("2023-01","2023-12")
+    
+    for i in range(len(name_array)):
+        if name_array[i] != '':
+ 
+             index = muiltyModelIndex(name_array[i])
+             array1 = get_column(yhyMatrix,index)
+             array2 = get_column(lshMatrix,index)
+             array3 = get_column(dbwMatrix,index)
+                
+             yhydata.append({"name":name_array[i],"data":convertColumnData(array1)})
+             lshdata.append({"name":name_array[i],"data":convertColumnData(array2)})
+             dbwdata.append({"name":name_array[i],"data":convertColumnData(array3)})
+            
+    rchMatrix = np.loadtxt(base.prefix + "base_water.ini", dtype=str,encoding='utf-8')
+    riverMatrix = np.loadtxt(base.prefix + "base_river.ini", dtype=str,encoding='utf-8')
+    pumpMatrix = np.loadtxt(base.prefix + "base_mining.ini", dtype=str,encoding='utf-8')
+    
+    rchdata=[]
+    rch_base1 = rchMatrix[1]
+    rch_base1_float =[]
+    for i in range (0,len(rch_base1)):
+         float_data =  round(float(rch_base1[i])/9,2)
+         rch_base1_float.append(float_data)
+    
+    rchdata.append({"name":"鍩哄噯鍊�","data":rch_base1_float})
+    
+    riverdata=[]
+    riverdata.append({"name":"鍩哄噯鍊�","data":riverMatrix.astype(float).tolist()})
+    
+    pumpdata=[]
+    pumpX=pumpMatrix[1]
+    pump_float=[]
+    for i in range (0,len(pumpX)):
+         float_data =  round(float(pumpX[i]),2)
+         pump_float.append(float_data)
+    
+    pumpdata.append({"name":"鍩哄噯鍊�","data":pump_float})     
+       
+    res["xAxis"]  = months
+    res["yhy_line"]  = yhydata
+    res["lsh_line"]  = lshdata
+    res["dbw_line"]  = dbwdata
+    
+    
+    for i in range(len(name_array)):
+        if name_array[i] != '':
+            rchdata.append(rchBaseResult(rchMatrix,name_array[i]))
+            riverdata.append(riverBaseResult(riverMatrix, name_array[i]))
+            pumpdata.append(pumpBaseResult(pumpMatrix, name_array[i]))
+            
+    res["rch_line"]  = rchdata
+    res["river_line"]  = riverdata
+    res["pump_line"]  = pumpdata     
+    
+    yqsdata=[]
+    pyqdata=[]
+    sqdata=[]
+    for i in range(len(name_array)):
+         if name_array[i] != '':
+             paths = base.muiltyModel + name_array[i] + "\\modflow.head"
+             resdata = AchiveReport.getXs3LineChart(paths)    
+             pyqdata.append({"name":name_array[i],"data":resdata["pyq"]})
+             sqdata.append({"name":name_array[i],"data":resdata["sq"]})
+             yqsdata.append({"name":name_array[i],"data":resdata["yqs"]})
+             
+    res["yqs_line"]  = yqsdata  
+    res["sq_line"]  = sqdata 
+    res["pyq_line"]  = pyqdata            
+
+    return res 
+
+#灏忓満鏅按浣� 鍜屽彉骞�
+def xs_depth(model_name):
+    res={}
+    line1,line2=[],[]
+    paths = base.model_dir + model_name + "\\modflow.head"
+    if model_name == base.not_allowed_model:
+        paths = base.baseModel2 + "\\modflow.head"
+    
+    resdata = AchiveReport.getXs3LineChart(paths)    
+    line1.append({"name":"骞冲師鍖�","data":roundArray(resdata["pyq"])})
+    line1.append({"name":"灞卞尯","data":roundArray(resdata["sq"])})
+    line1.append({"name":"鐜夋硥灞卞湴鍖�","data":roundArray(resdata["yqs"])})
+    res["depth"]  = line1  
+    
+    line2.append({"name":"骞冲師鍖�","data":xs_bf(resdata["pyq"])})
+    line2.append({"name":"灞卞尯","data":xs_bf(resdata["sq"])})
+    line2.append({"name":"鐜夋硥灞卞湴鍖�","data":xs_bf(resdata["yqs"])})
+    res["bf"]  = line2          
+    return res 
+
+def xs_bf(array):
+    newlist=[]
+    newlist.append(0)
+    lens = len(array)-1
+    for i in range(0,lens):
+        x = array[i+1]-array[i]
+        newlist.append(round(x,2))
+    return newlist
+
+def roundArray(array):
+    newlist=[]
+    for item in array:
+        item = round(item,2)
+        newlist.append(item)
+    return newlist
+
+#rch 鍩哄噯鏁版嵁
+def rchBaseResult(rchMatrix,sp):
+    rchDict ={}   
+    rch_base1 = rchMatrix[1]
+    rch_base2 = rchMatrix[2]
+    rch_base3 = rchMatrix[3]    
+    trump = getmuiltyModelparam(sp)
+    
+    types = trump[0]
+    rch_x = trump[1]
+    
+    if types ==1:
+        temp = muiltyArray(rch_base1,rch_x)
+        for i in range(0,len(temp)):
+            temp[i] =round(temp[i]/9,2)    
+        rchDict={"name":sp,"data":temp}
+    if types ==2:
+        temp = muiltyArray(rch_base2,rch_x)
+        for i in range(0,len(temp)):
+            temp[i] =round(temp[i]/9,2) 
+        rchDict={"name":sp,"data":temp}    
+    if types ==3:
+        temp = muiltyArray(rch_base3,rch_x)
+        for i in range(0,len(temp)):
+            temp[i] =round(temp[i]/9,2) 
+        rchDict={"name":sp,"data":temp}
+    
+    return rchDict
+
+#娌虫祦鍩哄噯 鏁版嵁
+def riverBaseResult(riverMatrix,sp):   
+    trump = getmuiltyModelparam(sp)  
+    river_x = trump[2]
+    riverDict={"name":sp,"data":muiltyArray(riverMatrix,river_x)}
+    return riverDict
+
+
+#鎶芥按浜曞熀鍑嗘暟鎹�
+def pumpBaseResult(pumpMatrix,sp):
+    trump = getmuiltyModelparam(sp)
+    pump_x =trump[3]
+    pumpDict={"name":sp,"data":muiltyArray(pumpMatrix[1],pump_x)}
+    return pumpDict
+    
+
+def muiltyArray(array,scale):
+    result =[]
+    for item in array:
+        x= round(float(item) * scale,2)
+        result.append(x)
+    return result
+
+
+def convertColumnData(array):
+    result =[]
+    new_list=[]
+    for i in range(len(array)):
+        if i!= 0:         
+             data =  transToNum(array[i])
+             result.append(data) 
+    for index in range(len(result)):
+        if index % 3 == 0:
+            new_list.append(result[index])     
+    return new_list   
+
+def transToNum(str):
+    data = 0
+    try:
+        data=  round(float(str),2) 
+        return data
+    except ValueError():
+        return 0    
+  
+     
+ #鑾峰彇棰勬祴鍦烘櫙鐨勪笅鏍囧�硷紝 闇�瑕佷粠ini 鏂囦欢涓寜鐓у垪杩涜璇诲彇
+def muiltyModelIndex(name):
+    models= muiltyModelList()
+    indexs = models.index(name)
+    return indexs
+
+#棰勬祴妯″瀷鍒楄〃
+def  muiltyModelList():
+    models=["SP0-0","SP1-1","SP1-2","SP1-3","SP2-1","SP2-2","SP2-3","SP3-1",
+            "SP3-2","SP3-4","SP3-5","SP3-6","SP3-7","SP4-1","SP4-7"]
+    return models
+    
+   
+
+#Np鑾峰彇鏌愪竴鍒楃殑鍊�
+def get_column(matrix, column_number):
+    column = matrix[:, column_number]
+    return column
+
+#鍏冪粍涓� 1=闄嶉洦绫诲瀷  2=鍊嶆暟 3,娌虫祦鍊嶆暟 4,鎶芥按浜曞�嶆暟
+def getmuiltyModelparam(sp):
+    dicts={
+        "SP0-0":(1,1,1,1),
+        "SP1-1":(2,1,1,1),
+        "SP1-2":(3,1,1,1),
+        "SP1-3":(3,1.2,1,1),     
+        "SP2-1":(1,1,2,1),
+        "SP2-2":(1,1,5,1),
+        "SP2-3":(1,1,10,1),     
+        "SP3-1":(1,1,1,0.25),
+        "SP3-2":(1,1,1,0.5),
+        "SP3-4":(1,1,1,0),    
+        "SP3-5":(1,1,1,0.4),
+        "SP3-6":(1,1,1,0.3),
+        "SP3-7":(1,1,1,0.6),
+        
+        "SP4-1":(1,1,2,0.5),
+        "SP4-7":(3,1.2,10,0)}
+    return dicts[sp]

--
Gitblit v1.9.1