Browse Source

Signed-off-by: caner <5658514@qq.com>

caner 3 years ago
parent
commit
602eee86e5
3 changed files with 34 additions and 21 deletions
  1. BIN
      3744.xls
  2. BIN
      3745.xls
  3. 34 21
      main.py

BIN
3744.xls


BIN
3745.xls


+ 34 - 21
main.py

@@ -22,12 +22,15 @@ def R123(r):
         R1 = float(r[0])
         R2 = float(r[1])
         R3 = float(r[2])
-        V = float(0.3)
+        Er = float(r[3])
+        V = float(r[4])
         return [
             # 2*弹性模量(E)*机械比能-R1*R1-R2*R2-R3*R3+2*v*(R1*R2+R1*R3+R2*R3)
-            2*e*K-R1*R1-R2*R2-R3*R3+2*V*(R1*R2+R1*R3+R2*R3),
-            2*e1*K1-R1*R1-R2*R2-R3*R3+2*V*(R1*R2+R1*R3+R2*R3),
-            2*e2*K2-R1*R1-R2*R2-R3*R3+2*V*(R1*R2+R1*R3+R2*R3)
+            2*Er*K-R1*R1-R2*R2-R3*R3+2*V*(R1*R2+R1*R3+R2*R3),
+            2*Er*K1-R1*R1-R2*R2-R3*R3+2*V*(R1*R2+R1*R3+R2*R3),
+            2*Er*K2-R1*R1-R2*R2-R3*R3+2*V*(R1*R2+R1*R3+R2*R3),
+            2*Er*K3-R1*R1-R2*R2-R3*R3+2*V*(R1*R2+R1*R3+R2*R3),
+            2*Er*K4-R1*R1-R2*R2-R3*R3+2*V*(R1*R2+R1*R3+R2*R3)
         ]
     except:
         return ['null', 'null', 'null']
@@ -47,12 +50,12 @@ def nullData(arr):
 
 
 if __name__ == "__main__":
-    path = 'C:\\Users\\caner\\Desktop\\test'
+    path = 'C:\\Users\\caner\\Desktop\\countExcel'
     colTitle = '机械比能'
     try:
         files = glob.glob(os.path.join(path, "*.xls"))
         for file in files:
-            array = pd.read_excel(file) #读取excel数据
+            array = pd.read_excel(file)  # 读取excel数据
             col = array[colTitle]  # 某列
             colLen = len(col)  # 一列的长度
             rowLen = len(array.iloc[1])  # 一行的长度
@@ -76,31 +79,37 @@ if __name__ == "__main__":
                     E[i] = math.fabs(e)
                     E[i+1] = math.fabs(e)
 
-            # 单独对数据为null的进行平均值计算
+                # 单独对数据为null的进行平均值计算
             nullData(RC)
             nullData(E)
 
             # 三行计算R123
             for j in range(colLen):
-                if (j+2) < len(col):
+                if (j+4) < len(col):
                     K = col[j]
                     K1 = col[j+1]
                     K2 = col[j+2]
-                    e = E[j]
-                    e1 = E[j+1]
-                    e2 = E[j+2]
-                    rea = fsolve(R123, [1, 1, 1])  # 其它参数直接用
+                    K3 = col[j+3]
+                    K4 = col[j+4]
+                    rea = fsolve(R123, [1, 1, 1, 100, 1])  # 其它参数直接用
                     rea = R123(rea)
-                    arr = sorted(rea, reverse=True) #倒叙
+                    arr = sorted(rea, reverse=True)  # 倒叙
+                    print(arr)
                     RK1[j] = math.fabs(arr[0])
                     RK1[j+1] = math.fabs(arr[0])
                     RK1[j+2] = math.fabs(arr[0])
+                    RK1[j+3] = math.fabs(arr[0])
+                    RK1[j+4] = math.fabs(arr[0])
                     RK2[j] = math.fabs(arr[1])
                     RK2[j+1] = math.fabs(arr[1])
                     RK2[j+2] = math.fabs(arr[1])
+                    RK2[j+3] = math.fabs(arr[1])
+                    RK2[j+4] = math.fabs(arr[1])
                     RK3[j] = math.fabs(arr[2])
                     RK3[j+1] = math.fabs(arr[2])
                     RK3[j+2] = math.fabs(arr[2])
+                    RK3[j+3] = math.fabs(arr[2])
+                    RK3[j+4] = math.fabs(arr[2])
 
             # 单独对数据为null的进行平均值计算
             nullData(RK1)
@@ -109,20 +118,24 @@ if __name__ == "__main__":
 
             # 计算强度
             for z in range(colLen):
-                GRA[z] = RC[z] / RK1[z]
-
-            # 对整体数据进行倍数计算↓
-            # .......
+                try:
+                    GRA[z] = RC[z] / RK1[z]
+                except:
+                    GRA[z] = 'null'
+                    
+            # 单独对数据为null的进行平均值计算                    
+            nullData(GRA)
 
-            # 保存excel
+                # 保存excel
             array.insert(rowLen, '单轴抗压强度', RC)
             array.insert(rowLen+1, '弹性模量', E)
             array.insert(rowLen+2, '第一主应力', RK1)
             array.insert(rowLen+3, '第二主应力', RK2)
             array.insert(rowLen+4, '第三主应力', RK3)
             array.insert(rowLen+5, '岩石强度应力比', GRA)
-            pd.DataFrame(array).to_excel(file, sheet_name='Sheet1', index=False, header=True)
+            pd.DataFrame(array).to_excel(
+                file, sheet_name='Sheet1', index=False, header=True)
             print('保存完毕')
 
-    except:
-        print('计算错误')
+    except ZeroDivisionError as err:
+        print('计算错误', err)