Просмотр исходного кода

完善了WD的计算和展示,GC的导出为excel文件,修复了未填写项目名直接点击新建没有弹窗提示的bug

wzp 4 месяцев назад
Родитель
Сommit
83c1a156cb
10 измененных файлов: 409 добавлений и 246 удалений
  1. 115
    0
      Back/GC/GCExport.py
  2. 6
    6
      Back/Program_Run/database_operations.py
  3. 51
    39
      Back/WD/WD.py
  4. 17
    14
      Back/WD/WDExport.py
  5. 142
    108
      Back/WD/WDcompute.py
  6. 39
    27
      Back/WD/WDshow.py
  7. 10
    2
      Front/main.py
  8. 28
    6
      Front/modules/ui_functions.py
  9. 1
    44
      Front/modules/ui_main.py
  10. Двоичные данные
      SQL/DataBase.db

+ 115
- 0
Back/GC/GCExport.py Просмотреть файл

@@ -0,0 +1,115 @@
1
+import time
2
+import pandas as pd
3
+import sqlite3
4
+import os
5
+from PySide6.QtWidgets import QMessageBox
6
+from openpyxl.styles import Font, NamedStyle
7
+from openpyxl.utils.dataframe import dataframe_to_rows
8
+
9
+
10
+def main_function(ui, file_path, utf_en, db_path):
11
+    export_folder = os.path.dirname(file_path)
12
+    if not os.path.exists(export_folder):
13
+        os.makedirs(export_folder)
14
+
15
+    # 连接数据库
16
+    conn = sqlite3.connect(db_path)
17
+
18
+    try:
19
+        # 查询数据库表为DataFrame,添加 TableName 条件
20
+        query = "SELECT * FROM GC_Output_Point WHERE TableName=?"
21
+        df = pd.read_sql_query(query, conn, params=(utf_en,))
22
+
23
+        # 检查是否有匹配的数据
24
+        if df.empty:
25
+            QMessageBox.warning(ui, '警告', '没有找到匹配的数据进行导出')
26
+            conn.close()
27
+            return
28
+
29
+        # 假设 TableName 字段是以字节序列存储的 UTF-8 编码字符串
30
+        if 'TableName' in df.columns:
31
+            try:
32
+                df['TableName'] = df['TableName'].apply(lambda x: x.decode('utf-8') if isinstance(x, bytes) else x)
33
+            except Exception as e:
34
+                QMessageBox.critical(ui, '错误', f'TableName 字段解码失败: {str(e)}')
35
+                conn.close()
36
+                return
37
+
38
+        # new HDiff 保留小数点后6位
39
+        if 'New_HDiff' in df.columns:
40
+            df['New_HDiff'] = df['New_HDiff'].round(6)
41
+        # New_RLen 保留小数点后6位
42
+        if 'New_RLen' in df.columns:
43
+            df['New_RLen'] = df['New_RLen'].round(6)
44
+        # Correct_Factor 保留小数点后2位
45
+        if 'Correct_Factor' in df.columns:
46
+            df['Correct_Factor'] = df['Correct_Factor'].round(2)
47
+        # Period_Diff 保留小数点后2位
48
+        if 'Period_Diff' in df.columns:
49
+            df['Period_Diff'] = df['Period_Diff'].round(2)
50
+
51
+        # 重命名指定的列
52
+        column_mapping = {
53
+            'TableName': '文件名',
54
+            'New_ID': '序号',
55
+            'New_ResultName': '结果期数',
56
+            'New_SPName': '起点',
57
+            'New_EPName': '终点',
58
+            'New_HDiff': '高差',
59
+            'New_RLen': '路线长',
60
+            'Correct_Factor': '修正数',
61
+            'Period_Diff': '期间差异',
62
+            'Dis_Ass': '变形判定'
63
+        }
64
+        df.rename(columns=column_mapping, inplace=True)
65
+
66
+        # 创建一个新的 Excel 工作簿
67
+        from openpyxl import Workbook
68
+        wb = Workbook()
69
+        ws = wb.active
70
+
71
+        # 将 DataFrame 写入工作表
72
+        for r in dataframe_to_rows(df, index=False, header=True):
73
+            ws.append(r)
74
+
75
+        # 定义自定义样式
76
+        style_0_000000 = NamedStyle(name="style_0_000000", number_format='0.000000')
77
+        style_0_00 = NamedStyle(name="style_0_00", number_format='0.00')
78
+
79
+        # 添加样式到工作簿
80
+        wb.add_named_style(style_0_000000)
81
+        wb.add_named_style(style_0_00)
82
+
83
+        # 应用样式到相应列
84
+        hdiff_col_index = df.columns.get_loc('高差') + 1  # 获取“高差”列的索引(+1 因为 Excel 列索引从 1 开始)
85
+        rlen_col_index = df.columns.get_loc('路线长') + 1  # 获取“路线长”列的索引
86
+        correct_factor_col_index = df.columns.get_loc('修正数') + 1  # 获取“修正数”列的索引
87
+        period_diff_col_index = df.columns.get_loc('期间差异') + 1  # 获取“期间差异”列的索引
88
+
89
+        for row in range(2, ws.max_row + 1):  # 从第二行开始,因为第一行为标题行
90
+            ws.cell(row=row, column=hdiff_col_index).style = style_0_000000
91
+            ws.cell(row=row, column=rlen_col_index).style = style_0_000000
92
+            ws.cell(row=row, column=correct_factor_col_index).style = style_0_00
93
+            ws.cell(row=row, column=period_diff_col_index).style = style_0_00
94
+
95
+        # 设置 Dis_Ass 列为“变形”的行的字体颜色为红色
96
+        red_font = Font(color="FF0000")
97
+        dis_ass_col_index = df.columns.get_loc('变形判定') + 1  # 获取“变形判定”列的索引
98
+
99
+        for row in range(2, ws.max_row + 1):  # 从第二行开始,因为第一行为标题行
100
+            cell_value = ws.cell(row=row, column=dis_ass_col_index).value
101
+            if cell_value == '变形':
102
+                for col in range(1, ws.max_column + 1):
103
+                    ws.cell(row=row, column=col).font = red_font
104
+
105
+        # 保存 Excel 文件
106
+        excel_filename = f"水准测段高差计算成果表{time.strftime('%Y%m%d_%H%M%S')}.xlsx"
107
+        excel_filepath = os.path.join(export_folder, excel_filename)
108
+        wb.save(excel_filepath)
109
+
110
+        QMessageBox.information(ui, '成功', f'数据库已成功导出到 {excel_filepath}')
111
+    except Exception as e:
112
+        QMessageBox.critical(ui, '错误', f'导出过程中发生错误: {str(e)}')
113
+    finally:
114
+        # 关闭数据库连接
115
+        conn.close()

+ 6
- 6
Back/Program_Run/database_operations.py Просмотреть файл

@@ -4,11 +4,11 @@ import os
4 4
 from PySide6.QtWidgets import QMessageBox
5 5
 
6 6
 
7
-def create_database_and_tables(self):
8
-    db_name = self.lineEdit.text().strip()
7
+def create_database_and_tables(main_window,ui):
8
+    db_name = main_window.ui.lineEdit.text().strip()
9 9
 
10 10
     if not db_name:
11
-        QMessageBox.warning(self, "警告", "请输入数据库名称")
11
+        QMessageBox.warning(main_window, "警告", "请输入数据库名称")
12 12
         return
13 13
     # 转换为UTF-8编码
14 14
     # db_name_utf8 = db_name.encode('utf-8')
@@ -28,7 +28,7 @@ def create_database_and_tables(self):
28 28
     # 读取现有的数据库结构
29 29
     existing_db_path = os.path.join(sql_folder, 'DataBase.db')
30 30
     if not os.path.exists(existing_db_path):
31
-        QMessageBox.critical(self.main_window, "错误", "找不到现有的数据库结构文件 DataBase.db")
31
+        QMessageBox.critical(main_window.main_window, "错误", "找不到现有的数据库结构文件 DataBase.db")
32 32
         return
33 33
     try:
34 34
         # 连接到现有的数据库以获取表结构
@@ -49,6 +49,6 @@ def create_database_and_tables(self):
49 49
 
50 50
                 new_conn.commit()
51 51
 
52
-        QMessageBox.information(self.main_window, "成功", f"项目{db_name}已成功创建")
52
+        QMessageBox.information(main_window, "成功", f"项目{db_name}已成功创建")
53 53
     except Exception as e:
54
-        QMessageBox.critical(self.main_window, "错误", f"创建项目时出错: {str(e)}")
54
+        QMessageBox.critical(main_window, "错误", f"创建项目时出错: {str(e)}")

+ 51
- 39
Back/WD/WD.py Просмотреть файл

@@ -2,38 +2,45 @@ import openpyxl
2 2
 import xlrd
3 3
 import sqlite3
4 4
 import os
5
+
6
+from PySide6.QtWidgets import QMessageBox
5 7
 from openpyxl import Workbook
6 8
 import tkinter as tk
7 9
 from tkinter import messagebox
8 10
 import math
9 11
 import numpy as np
10 12
 
13
+
11 14
 def to_utf8(text):
12 15
     str1 = text.encode('utf-8')
13 16
     return str1
14 17
 
18
+
15 19
 # 弹窗提示用户是否更新数据
16 20
 def ask_for_update(file_name):
17
-    root = tk.Tk()
18
-    root.withdraw()  # 隐藏主窗口
19
-    response = messagebox.askyesno("提示", f"检测到数据库中存在相同文件名 '{file_name}',是否更新数据?")
20
-    return response
21
+    response = QMessageBox.question(None, "提示", f"检测到数据库中存在相同文件 '{file_name}',是(Yes)否(No)更新数据?",
22
+                                    QMessageBox.Yes | QMessageBox.No)
23
+    return response == QMessageBox.Yes
24
+
21 25
 
22 26
 # 读取Excel文件并计算公式结果
23
-def load_and_calculate_excel(file_path,cell0):
27
+def load_and_calculate_excel(file_path, cell0):
24 28
     # 加载Excel文件并计算单元格的公式结果。
25 29
     workbook = openpyxl.load_workbook(file_path, data_only=True)
26 30
     sheet = workbook.active
27 31
     h1_value = sheet[cell0].value
28 32
     return h1_value
29 33
 
34
+
30 35
 # 数据库插入函数
31
-def insert_into_database(database,pastname,newname,beforename,excelname,listname1,listpastx1,listpasty1,listcgcs1,pjbc,fxzwc,points,zbs,zfxs,sf,pjbcs,pjfxs,listbex,listbey,listnewx,listnewy):
32
-    #先把输入的录入数据库
36
+def insert_into_database(database, pastname, newname, beforename, excelname, listname1, listpastx1, listpasty1,
37
+                         listcgcs1, pjbc, fxzwc, points, zbs, zfxs, sf, pjbcs, pjfxs, listbex, listbey, listnewx,
38
+                         listnewy):
39
+    # 先把输入的录入数据库
33 40
     db = sqlite3.connect(database)
34
-    #获取游标
41
+    # 获取游标
35 42
     cursor = db.cursor()
36
-    #字符类的都需要转换成字节存进去
43
+    # 字符类的都需要转换成字节存进去
37 44
     utf_pan = to_utf8(pastname)
38 45
     utf_nn = to_utf8(newname)
39 46
     utf_bn = to_utf8(beforename)
@@ -59,10 +66,10 @@ def insert_into_database(database,pastname,newname,beforename,excelname,listname
59 66
                 SET First_ResultName = ?,Last_ResultName=?,New_ResultName=?,Avg_SL=?,Ms_Dir=?,Pt_Count=?,SL_Count=?,Dir_Count=?,Scale_Value=?,Avg_MSL=?,Avg_Dir=?
60 67
                 WHERE TableName = ?
61 68
                 """,
62
-                (utf_bn,utf_pan,utf_nn,pjbc,fxzwc,points,zbs,zfxs,sf,pjbcs,pjfxs,utf_tn,)
69
+                (utf_bn, utf_pan, utf_nn, pjbc, fxzwc, points, zbs, zfxs, sf, pjbcs, pjfxs, utf_tn,)
63 70
             )
64 71
             # 更新现有记录WD_Input_Point 
65
-            #删了已有的数据,重新插入
72
+            # 删了已有的数据,重新插入
66 73
             cursor.execute(
67 74
                 """
68 75
                 DELETE FROM WD_Input_Point WHERE TableName = ?
@@ -84,11 +91,11 @@ def insert_into_database(database,pastname,newname,beforename,excelname,listname
84 91
                     """
85 92
                     INSERT INTO WD_Input_Point(TableName,First_ResultName,Last_ResultName,New_ResultName,Last_X,Last_Y,New_X,New_Y,PointName,Wight,First_X,First_Y) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)
86 93
                     """,
87
-                    (utf_tn,utf_bn,utf_pan,utf_nn,rr2,rr3,rr5,rr6,utf_rr1,rr4,rr7,rr8,)
94
+                    (utf_tn, utf_bn, utf_pan, utf_nn, rr2, rr3, rr5, rr6, utf_rr1, rr4, rr7, rr8,)
88 95
                 )
89 96
                 rr = rr + 1
90
-            messagebox.showinfo("提示",
91
-                                f"文件 '{excelname}' 已成功更新到本地数据库中,点击确认以关闭此对话框。对话框关闭后,请点击“计算”以重新计算数据")
97
+            QMessageBox.information(None, "提示",
98
+                                    f"文件 '{excelname}' 已成功更新到本地数据库中,点击'OK'以关闭此对话框。对话框关闭后,请点击“计算”以重新计算数据")
92 99
         else:
93 100
             # 插入新记录WD_Input_Param 
94 101
             cursor.execute(
@@ -96,7 +103,7 @@ def insert_into_database(database,pastname,newname,beforename,excelname,listname
96 103
                 INSERT INTO WD_Input_Param (TableName,First_ResultName,Last_ResultName,New_ResultName,Avg_SL,Ms_Dir,Pt_Count,SL_Count,Dir_Count,Scale_Value,Avg_MSL,Avg_Dir) 
97 104
                 VALUES (?,?,?,?,?,?,?,?,?,?,?,?)
98 105
                 """,
99
-                (utf_tn,utf_bn,utf_pan,utf_nn,pjbc,fxzwc,points,zbs,zfxs,sf,pjbcs,pjfxs,)
106
+                (utf_tn, utf_bn, utf_pan, utf_nn, pjbc, fxzwc, points, zbs, zfxs, sf, pjbcs, pjfxs,)
100 107
             )
101 108
             # 插入新记录WD_Input_Point 
102 109
             rr = 0
@@ -114,11 +121,11 @@ def insert_into_database(database,pastname,newname,beforename,excelname,listname
114 121
                     """
115 122
                     INSERT INTO WD_Input_Point(TableName,First_ResultName,Last_ResultName,New_ResultName,Last_X,Last_Y,New_X,New_Y,PointName,Wight,First_X,First_Y) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)
116 123
                     """,
117
-                    (utf_tn,utf_bn,utf_pan,utf_nn,rr2,rr3,rr5,rr6,utf_rr1,rr4,rr7,rr8,)
124
+                    (utf_tn, utf_bn, utf_pan, utf_nn, rr2, rr3, rr5, rr6, utf_rr1, rr4, rr7, rr8,)
118 125
                 )
119 126
                 rr = rr + 1
120
-            messagebox.showinfo("提示",
121
-                                f"文件 '{excelname}' 已成功添加到本地数据库中,点击确认以关闭此对话框。对话框关闭后,请点击“计算”以计算数据")
127
+            QMessageBox.information(None, "提示",
128
+                                    f"文件 '{excelname}' 已成功添加到本地数据库中,点击'OK'以关闭此对话框。对话框关闭后,请点击“计算”以计算数据")
122 129
 
123 130
         db.commit()
124 131
     except sqlite3.Error as e:
@@ -128,15 +135,16 @@ def insert_into_database(database,pastname,newname,beforename,excelname,listname
128 135
     finally:
129 136
         db.close()
130 137
 
131
-#读取xls
132
-def xlrd_read(excelpath,dbpath):
138
+
139
+# 读取xls
140
+def xlrd_read(excelpath, dbpath):
133 141
     global gszbx
134 142
     global gszby
135 143
     listname1 = []
136 144
     listpastx1 = []
137 145
     listpasty1 = []
138 146
     listcgcs1 = []
139
-    #excel表名就是表名
147
+    # excel表名就是表名
140 148
     excelname = os.path.basename(excelpath)
141 149
     # 读取excel
142 150
     xlr = xlrd.open_workbook(excelpath)
@@ -224,11 +232,13 @@ def xlrd_read(excelpath,dbpath):
224 232
         listpasty1.append(rr3)
225 233
         listcgcs1.append(rr4)
226 234
         rr = rr + 1
227
-    #存入数据库
228
-    insert_into_database(dbpath,lastname,finalname,befname,excelname,listname1,listpastx1,listpasty1,listcgcs1,pjbc,fxzwc,points,zbs,zfxs,sf,pjbcs,pjfxs,listbex,listbey,listnewx,listnewy)
235
+    # 存入数据库
236
+    insert_into_database(dbpath, lastname, finalname, befname, excelname, listname1, listpastx1, listpasty1, listcgcs1,
237
+                         pjbc, fxzwc, points, zbs, zfxs, sf, pjbcs, pjfxs, listbex, listbey, listnewx, listnewy)
238
+
229 239
 
230
-#读取xlsx
231
-def openpyxl_read(excelpath,dbpath):
240
+# 读取xlsx
241
+def openpyxl_read(excelpath, dbpath):
232 242
     global gszbx
233 243
     global gszby
234 244
     listname1 = []
@@ -236,7 +246,7 @@ def openpyxl_read(excelpath,dbpath):
236 246
     listpasty1 = []
237 247
     listcgcs1 = []
238 248
 
239
-    #excel表名就是表名
249
+    # excel表名就是表名
240 250
     excelname = os.path.basename(excelpath)
241 251
     # 读取excel
242 252
     xlr = openpyxl.load_workbook(excelpath)
@@ -254,8 +264,8 @@ def openpyxl_read(excelpath,dbpath):
254 264
     listpastx = []
255 265
     listpasty = []
256 266
     listcgcs = []
257
-    listbex=[]
258
-    listbey=[]
267
+    listbex = []
268
+    listbey = []
259 269
     sumnewx = 0
260 270
     sumnewy = 0
261 271
     sumpastx = 0
@@ -270,11 +280,11 @@ def openpyxl_read(excelpath,dbpath):
270 280
     try:
271 281
         zbs = float(tabler['J3'].value)
272 282
     except:
273
-        zbs = load_and_calculate_excel(excelpath,'J3')
283
+        zbs = load_and_calculate_excel(excelpath, 'J3')
274 284
     try:
275 285
         zfxs = float(tabler['J4'].value)
276 286
     except:
277
-        zfxs = load_and_calculate_excel(excelpath,'J4')
287
+        zfxs = load_and_calculate_excel(excelpath, 'J4')
278 288
     pjbcs = zbs / points
279 289
     pjfxs = zfxs / points
280 290
     sf = float(tabler['J5'].value)
@@ -288,7 +298,7 @@ def openpyxl_read(excelpath,dbpath):
288 298
     wypd3 = math.sqrt(wypd1 + wypd2)
289 299
     wypd = round((wypd3 * 2 * math.sqrt(2)), 9)
290 300
     wypd0 = wypd
291
-    befname=tabler['G1'].value
301
+    befname = tabler['G1'].value
292 302
     lastname = tabler['D1'].value
293 303
     finalname = tabler['B1'].value
294 304
     while row <= rows:
@@ -328,17 +338,19 @@ def openpyxl_read(excelpath,dbpath):
328 338
         listpasty1.append(rr3)
329 339
         listcgcs1.append(rr4)
330 340
         rr = rr + 1
331
-    #存入数据库
332
-    insert_into_database(dbpath,lastname,finalname,befname,excelname,listname1,listpastx1,listpasty1,listcgcs1,pjbc,fxzwc,points,zbs,zfxs,sf,pjbcs,pjfxs,listbex,listbey,listnewx,listnewy)
341
+    # 存入数据库
342
+    insert_into_database(dbpath, lastname, finalname, befname, excelname, listname1, listpastx1, listpasty1, listcgcs1,
343
+                         pjbc, fxzwc, points, zbs, zfxs, sf, pjbcs, pjfxs, listbex, listbey, listnewx, listnewy)
344
+
333 345
 
334 346
 # 主函数 读取excel文件
335
-def main_function(file_path,dbpath):
347
+def main_function(file_path, dbpath):
336 348
     # 调用读取Excel文件的函数
337 349
     file_name = os.path.basename(file_path)
338
-    #两种加载方式,对于不同的文件
350
+    # 两种加载方式,对于不同的文件
339 351
     if ".xlsx" in file_path:
340
-        #采用openpyxl
341
-        openpyxl_read(file_path,dbpath)
352
+        # 采用openpyxl
353
+        openpyxl_read(file_path, dbpath)
342 354
     else:
343
-        #采用xlrd
344
-        xlrd_read(file_path,dbpath)
355
+        # 采用xlrd
356
+        xlrd_read(file_path, dbpath)

+ 17
- 14
Back/WD/WDExport.py Просмотреть файл

@@ -185,17 +185,20 @@ def openpyxl_write(outpath,dbpath,filename):
185 185
     wb.save(outpath)
186 186
 
187 187
 
188
-# # 主函数 写入excel文件
189
-# def main_function(outpath,dbpath,file_path):
190
-#     dbpath = r"D:\4work_now\20240819GS\ControlNetwork\ControlNetwork\UI\SQL\DataBase.db"
191
-#     outpath = r'D:\4work_now\20240819GS\JPG\WD成果表.xlsx'
192
-#     file_path = r'D:\4work_now\20240819GS\test_wd.xls'
193
-#     file_name = os.path.basename(file_path)
194
-#     # outpath为包含输出excel名字的全路径
195
-#     openpyxl_write(outpath,dbpath,file_name)
196
-dbpath = r"D:\4work_now\20240819GS\ControlNetwork\ControlNetwork\UI\SQL\DataBase.db"
197
-outpath = r'D:\4work_now\20240819GS\JPG\WD成果表.xlsx'
198
-file_path = r'D:\4work_now\20240819GS\test_wd.xls'
199
-file_name = os.path.basename(file_path)
200
-# outpath为包含输出excel名字的全路径
201
-openpyxl_write(outpath,dbpath,file_name)
188
+# 主函数 写入excel文件
189
+def main_function(outpath,dbpath,file_path):
190
+    dbpath = r"D:\4work_now\20240819GS\ControlNetwork\ControlNetwork\UI\SQL\DataBase.db"
191
+    outpath = r'D:\4work_now\20240819GS\JPG\WD成果表.xlsx'
192
+    file_path = r'D:\4work_now\20240819GS\test_wd.xls'
193
+    file_name = os.path.basename(file_path)
194
+    # outpath为包含输出excel名字的全路径
195
+    openpyxl_write(outpath,dbpath,file_name)
196
+
197
+
198
+# dbpath = r"D:\4work_now\20240819GS\ControlNetwork\ControlNetwork\UI\SQL\DataBase.db"
199
+# # dbpath = r"D:/Code/ControlNetwork/UI/SQL/DataBase.db"
200
+# outpath = r'D:\4work_now\20240819GS\JPG\WD成果表.xlsx'
201
+# file_path = r'D:\4work_now\20240819GS\test_wd.xls'
202
+# file_name = os.path.basename(file_path)
203
+# # outpath为包含输出excel名字的全路径
204
+# openpyxl_write(outpath,dbpath,file_name)

+ 142
- 108
Back/WD/WDcompute.py Просмотреть файл

@@ -10,11 +10,15 @@ import numpy as np
10 10
 from tkinter import messagebox
11 11
 from tkinter import *
12 12
 
13
-#region 各种方法
13
+from PySide6.QtWidgets import QMessageBox
14
+
15
+
16
+# region 各种方法
14 17
 def to_utf8(text):
15 18
     str1 = text.encode('utf-8')
16 19
     return str1
17 20
 
21
+
18 22
 def jzys1(listy, zxzby, listx, zxzbx, sf):
19 23
     rlist = []
20 24
     listlen = len(listy)
@@ -30,6 +34,7 @@ def jzys1(listy, zxzby, listx, zxzbx, sf):
30 34
         ll = ll + 1
31 35
     return rlist
32 36
 
37
+
33 38
 def jzys2(listy, zxzby, listx, zxzbx, sf):
34 39
     rlist = []
35 40
     listlen = len(listy)
@@ -43,6 +48,7 @@ def jzys2(listy, zxzby, listx, zxzbx, sf):
43 48
         ll = ll + 1
44 49
     return rlist
45 50
 
51
+
46 52
 def jzys3(listy, aa, bb):
47 53
     rlist = []
48 54
     listlen = len(listy)
@@ -56,6 +62,7 @@ def jzys3(listy, aa, bb):
56 62
         ll = ll + 1
57 63
     return rlist
58 64
 
65
+
59 66
 def jzys4(listpasty, zxzbpasty, listpastx, zxzbpastx, listnewy, zxzbnewy, listnewx, zxzbnewx, sf):
60 67
     rlist = []
61 68
     listlen = len(listnewx)
@@ -68,6 +75,7 @@ def jzys4(listpasty, zxzbpasty, listpastx, zxzbpastx, listnewy, zxzbnewy, listne
68 75
         ll = ll + 1
69 76
     return rlist
70 77
 
78
+
71 79
 def jzys5(listp, zxzbp, sf):
72 80
     rlist = []
73 81
     listlen = len(listp)
@@ -78,6 +86,7 @@ def jzys5(listp, zxzbp, sf):
78 86
         ll = ll + 1
79 87
     return rlist
80 88
 
89
+
81 90
 def jzys6(listp, num):
82 91
     rlist = []
83 92
     listlen = len(listp)
@@ -88,6 +97,7 @@ def jzys6(listp, num):
88 97
         ll = ll + 1
89 98
     return rlist
90 99
 
100
+
91 101
 def cjh(listp):
92 102
     rp = 0
93 103
     listlen = len(listp)
@@ -98,6 +108,7 @@ def cjh(listp):
98 108
         ll = ll + 1
99 109
     return rp
100 110
 
111
+
101 112
 def cjh2(lista, listb):
102 113
     rp = 0
103 114
     listlen = len(lista)
@@ -108,6 +119,7 @@ def cjh2(lista, listb):
108 119
         ll = ll + 1
109 120
     return rp
110 121
 
122
+
111 123
 def gsys(listnewp, jxlist1, jylist1, lxlist, lylist, arrz, sf, zxzbnewp, zxzbpastp, ii):
112 124
     # 新x+(矩阵[jx1 jy1 lx1 ly1]*矩阵z)*缩放-新重心坐标x+旧重心坐标x
113 125
     rlist = []
@@ -115,7 +127,7 @@ def gsys(listnewp, jxlist1, jylist1, lxlist, lylist, arrz, sf, zxzbnewp, zxzbpas
115 127
     ll = 0
116 128
     while ll < listlen:
117 129
         arr0 = np.array((jxlist1[ll], jylist1[ll],
118
-                        lxlist[2*ll+ii], lylist[2*ll+ii]))
130
+                         lxlist[2 * ll + ii], lylist[2 * ll + ii]))
119 131
         arr1 = np.matmul(arr0, arrz)
120 132
         arr3 = sf * arr1
121 133
         newp = listnewp[ll] + arr3 - zxzbnewp + zxzbpastp
@@ -123,6 +135,7 @@ def gsys(listnewp, jxlist1, jylist1, lxlist, lylist, arrz, sf, zxzbnewp, zxzbpas
123 135
         ll = ll + 1
124 136
     return rlist
125 137
 
138
+
126 139
 def xcys(newlist, pastlist):
127 140
     listlen = len(newlist)
128 141
     ll = 0
@@ -134,40 +147,46 @@ def xcys(newlist, pastlist):
134 147
         ll = ll + 1
135 148
     return rlist
136 149
 
150
+
137 151
 def takeFirst(elem):
138 152
     return elem[0]
139
-#endregion
140 153
 
141
-def insert_into_database1(database,pastname,newname,beforename,excelname,listname1,listpastx1,listpasty1,listcgcs1,listbex,listbey,sxylist,wypd,gsx,gsy,listcgcs):
142
-    #转换下汉字
154
+
155
+# endregion
156
+
157
+def insert_into_database1(database, pastname, newname, beforename, excelname, listname1, listpastx1, listpasty1,
158
+                          listcgcs1, listbex, listbey, sxylist, wypd, gsx, gsy, listcgcs):
159
+    # 转换下汉字
143 160
     utf_tn = to_utf8(excelname)
144 161
     utf_nn = to_utf8(newname)
145 162
     utf_pn = to_utf8(pastname)
146 163
     utf_bn = to_utf8(beforename)
147 164
     utf_bx = to_utf8('变形')
148 165
     utf_wd = to_utf8('稳定')
149
-    #将结果输出到数据库
166
+    # 将结果输出到数据库
150 167
     db1 = sqlite3.connect(database)
151
-    #获取游标
168
+    # 获取游标
152 169
     cursor1 = db1.cursor()
153
-    #先清除已有数据,用来更新
170
+    # 先清除已有数据,用来更新
154 171
     try:
155 172
         sqlstr3 = 'delete from WD_Result_Param WHERE TableName = ?'
156 173
         sqlstr4 = 'delete from WD_Result_Point WHERE TableName = ?'
157
-        cursor1.execute(sqlstr3,(utf_tn,))
158
-        cursor1.execute(sqlstr4,(utf_tn,))
174
+        cursor1.execute(sqlstr3, (utf_tn,))
175
+        cursor1.execute(sqlstr4, (utf_tn,))
159 176
     except:
160 177
         pass
161
-    cursor1.execute('INSERT INTO WD_Result_Param(TableName,Last_ResultName,New_ResultName,Formula_X1,Formula_X2,Formula_X3,Formula_Y1,Formula_Y2,Formula_Y3) VALUES(?,?,?,?,?,?,?,?,?)',(utf_tn,utf_pn,utf_nn,sxylist[0],sxylist[1],sxylist[2],sxylist[3],sxylist[4],sxylist[5],))
162
-    #WD_Result_Point的输入
178
+    cursor1.execute(
179
+        'INSERT INTO WD_Result_Param(TableName,Last_ResultName,New_ResultName,Formula_X1,Formula_X2,Formula_X3,Formula_Y1,Formula_Y2,Formula_Y3) VALUES(?,?,?,?,?,?,?,?,?)',
180
+        (utf_tn, utf_pn, utf_nn, sxylist[0], sxylist[1], sxylist[2], sxylist[3], sxylist[4], sxylist[5],))
181
+    # WD_Result_Point的输入
163 182
     kk = -1
164 183
     kk1 = -1
165 184
     if (-1) in listcgcs:
166 185
         kk = 1
167
-    #记位移点个数
186
+    # 记位移点个数
168 187
     wyd = 0
169 188
     for lname in listname1:
170
-        #获取对应索引号
189
+        # 获取对应索引号
171 190
         index1 = listname1.index(lname)
172 191
         PointName = lname
173 192
         First_X = listbex[index1]
@@ -176,38 +195,38 @@ def insert_into_database1(database,pastname,newname,beforename,excelname,listnam
176 195
         Last_Y = listpasty1[index1]
177 196
         Last_Wight = listcgcs1[index1]
178 197
         New_Wight = listcgcs[index1]
179
-        #位移点
198
+        # 位移点
180 199
         if New_Wight == -1:
181 200
             # 获取他原本的坐标和初始改算值进行对比
182 201
             for smx in jslist:
183 202
                 if First_X == smx[0] and First_Y == smx[1]:
184 203
                     numa3 = sxylist[0] * jslist1[index1][0]
185 204
                     numa4 = sxylist[1] * jslist1[index1][1]
186
-                    numa5 = numa3 + numa4+ sxylist[2]
205
+                    numa5 = numa3 + numa4 + sxylist[2]
187 206
                     numa6 = sxylist[3] * jslist1[index1][0]
188 207
                     numa7 = sxylist[4] * jslist1[index1][1]
189
-                    numa8 = numa6 + numa7+sxylist[5]
208
+                    numa8 = numa6 + numa7 + sxylist[5]
190 209
                     Result_X = numa5
191 210
                     Result_Y = numa8
192 211
                     New_Wight = 1
193 212
                     numb1 = (numa5 - First_X) * 1000
194 213
                     numb2 = (numa8 - First_Y) * 1000
195
-                    numb3 = numb1 *numb1
196
-                    numb4 = numb2 *numb2
214
+                    numb3 = numb1 * numb1
215
+                    numb4 = numb2 * numb2
197 216
                     numb5 = math.sqrt(numb3 + numb4)
198 217
                     New_FirstX = numb1
199 218
                     New_FirstY = numb2
200 219
                     New_FirstP = numb5
201
-                    #新-首有个位移判定
220
+                    # 新-首有个位移判定
202 221
                     if numb5 > wypd:
203 222
                         NFDis_Ass = utf_bx
204 223
                     else:
205 224
                         NFDis_Ass = utf_wd
206
-                    
225
+
207 226
                     numc1 = (numa5 - Last_X) * 1000
208 227
                     numc2 = (numa8 - Last_Y) * 1000
209
-                    numc3 = numc1 *numc1
210
-                    numc4 = numc2 *numc2
228
+                    numc3 = numc1 * numc1
229
+                    numc4 = numc2 * numc2
211 230
                     numc5 = math.sqrt(numc3 + numc4)
212 231
                     New_LastX = numc1
213 232
                     New_LastY = numc2
@@ -216,9 +235,9 @@ def insert_into_database1(database,pastname,newname,beforename,excelname,listnam
216 235
                     kk1 = 1
217 236
                     wyd = wyd + 1
218 237
                     break
219
-        #不是位移点
238
+        # 不是位移点
220 239
         else:
221
-            #全部都是稳定点
240
+            # 全部都是稳定点
222 241
             if kk == -1:
223 242
                 num3 = Last_X * Last_Wight
224 243
                 num4 = num3 + gsx[index1]
@@ -238,21 +257,21 @@ def insert_into_database1(database,pastname,newname,beforename,excelname,listnam
238 257
                 New_FirstX = numd1
239 258
                 New_FirstY = numd2
240 259
                 New_FirstP = numd5
241
-                #新-首有个位移判定
260
+                # 新-首有个位移判定
242 261
                 if numd5 > wypd:
243 262
                     NFDis_Ass = utf_bx
244 263
                 else:
245 264
                     NFDis_Ass = utf_wd
246 265
                 nume1 = (num6 - Last_X) * 1000
247 266
                 nume2 = (num10 - Last_Y) * 1000
248
-                nume3 = nume1 *nume1
249
-                nume4 = nume2 *nume2
267
+                nume3 = nume1 * nume1
268
+                nume4 = nume2 * nume2
250 269
                 nume5 = math.sqrt(nume3 + nume4)
251 270
                 New_LastX = nume1
252 271
                 New_LastY = nume2
253 272
                 New_LastP = nume5
254 273
                 NLDis_Ass = utf_wd
255
-            #有位移点,且已经走过了
274
+            # 有位移点,且已经走过了
256 275
             if kk == 1 and kk1 == 1:
257 276
                 num3 = Last_X * Last_Wight
258 277
                 num4 = num3 + gsx[index1 - wyd]
@@ -272,21 +291,21 @@ def insert_into_database1(database,pastname,newname,beforename,excelname,listnam
272 291
                 New_FirstX = numd1
273 292
                 New_FirstY = numd2
274 293
                 New_FirstP = numd5
275
-                #新-首有个位移判定
294
+                # 新-首有个位移判定
276 295
                 if numd5 > wypd:
277 296
                     NFDis_Ass = utf_bx
278 297
                 else:
279 298
                     NFDis_Ass = utf_wd
280 299
                 nume1 = (num6 - Last_X) * 1000
281 300
                 nume2 = (num10 - Last_Y) * 1000
282
-                nume3 = nume1 *nume1
283
-                nume4 = nume2 *nume2
301
+                nume3 = nume1 * nume1
302
+                nume4 = nume2 * nume2
284 303
                 nume5 = math.sqrt(nume3 + nume4)
285 304
                 New_LastX = nume1
286 305
                 New_LastY = nume2
287 306
                 New_LastP = nume5
288 307
                 NLDis_Ass = utf_wd
289
-            #有位移点,但没有走过
308
+            # 有位移点,但没有走过
290 309
             if kk == 1 and kk1 == -1:
291 310
                 num3 = Last_X * Last_Wight
292 311
                 num4 = num3 + gsx[index1]
@@ -306,25 +325,30 @@ def insert_into_database1(database,pastname,newname,beforename,excelname,listnam
306 325
                 New_FirstX = numd1
307 326
                 New_FirstY = numd2
308 327
                 New_FirstP = numd5
309
-                #新-首有个位移判定
328
+                # 新-首有个位移判定
310 329
                 if numd5 > wypd:
311 330
                     NFDis_Ass = utf_bx
312 331
                 else:
313 332
                     NFDis_Ass = utf_wd
314 333
                 nume1 = (num6 - Last_X) * 1000
315 334
                 nume2 = (num10 - Last_Y) * 1000
316
-                nume3 = nume1 *nume1
317
-                nume4 = nume2 *nume2
335
+                nume3 = nume1 * nume1
336
+                nume4 = nume2 * nume2
318 337
                 nume5 = math.sqrt(nume3 + nume4)
319 338
                 New_LastX = nume1
320 339
                 New_LastY = nume2
321 340
                 New_LastP = nume5
322 341
                 NLDis_Ass = utf_wd
323
-        #在这里整体输出
324
-        cursor1.execute('INSERT INTO WD_Result_Point(TableName,First_ResultName,Last_ResultName,New_ResultName,First_X,First_Y,Last_X,Last_Y,Result_X,Result_Y,Last_Wight,New_Wight,New_FirstX,New_FirstY,New_FirstP,NFDis_Ass,New_LastX,New_LastY,New_LastP,NLDis_Ass,PointName) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',(utf_tn,utf_bn,utf_pn,utf_nn,First_X,First_Y,Last_X,Last_Y,Result_X,Result_Y,Last_Wight,New_Wight,New_FirstX,New_FirstY,New_FirstP,NFDis_Ass,New_LastX,New_LastY,New_LastP,NLDis_Ass,PointName,))
325
-    #数据库执行
342
+        # 在这里整体输出
343
+        cursor1.execute(
344
+            'INSERT INTO WD_Result_Point(TableName,First_ResultName,Last_ResultName,New_ResultName,First_X,First_Y,Last_X,Last_Y,Result_X,Result_Y,Last_Wight,New_Wight,New_FirstX,New_FirstY,New_FirstP,NFDis_Ass,New_LastX,New_LastY,New_LastP,NLDis_Ass,PointName) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
345
+            (
346
+                utf_tn, utf_bn, utf_pn, utf_nn, First_X, First_Y, Last_X, Last_Y, Result_X, Result_Y, Last_Wight,
347
+                New_Wight,
348
+                New_FirstX, New_FirstY, New_FirstP, NFDis_Ass, New_LastX, New_LastY, New_LastP, NLDis_Ass, PointName,))
349
+    # 数据库执行
326 350
     db1.commit()
327
-    #做完一切后,先关闭游标,再关闭数据库
351
+    # 做完一切后,先关闭游标,再关闭数据库
328 352
     cursor1.close()
329 353
     db1.close()
330 354
 
@@ -333,7 +357,10 @@ gszbx = []
333 357
 gszby = []
334 358
 jslist = []
335 359
 jslist1 = []
336
-def bhjs(listcgcs1, listname1, listpastx1, listpasty1, wypd, listname, listnewx, listnewy, listpastx, listpasty, points, listcgcs, listbex, listbey, sf, dbpath, befname, finalname, lastname, js,file_name):
360
+
361
+
362
+def bhjs(listcgcs1, listname1, listpastx1, listpasty1, wypd, listname, listnewx, listnewy, listpastx, listpasty, points,
363
+         listcgcs, listbex, listbey, sf, dbpath, befname, finalname, lastname, js, file_name):
337 364
     np.set_printoptions(suppress=False)
338 365
     # pt用于给点数point计数
339 366
     # point会随着回递函数而减少
@@ -372,12 +399,12 @@ def bhjs(listcgcs1, listname1, listpastx1, listpasty1, wypd, listname, listnewx,
372 399
     dy2 = cjh(dylist)
373 400
     # 这里再创建矩阵1
374 401
     arr1 = np.array(((k2, 0, 0, 0), (0, s2, 0, 0),
375
-                    (0, 0, dx2, 0), (0, 0, 0, dy2)))
402
+                     (0, 0, dx2, 0), (0, 0, 0, dy2)))
376 403
     # 矩阵1的逆矩阵矩阵2
377 404
     arr2 = np.linalg.inv(arr1)
378 405
     # 求矩阵l
379 406
     llist = jzys4(listpasty, zxzbpasty, listpastx, zxzbpastx,
380
-                    listnewy, zxzbnewy, listnewx, zxzbnewx, sf)
407
+                  listnewy, zxzbnewy, listnewx, zxzbnewx, sf)
381 408
     # 得到数列e1,e2,e3,e4
382 409
     e1 = cjh2(klist, llist)
383 410
     e2 = cjh2(slist, llist)
@@ -396,9 +423,9 @@ def bhjs(listcgcs1, listname1, listpastx1, listpasty1, wypd, listname, listnewx,
396 423
     lylist = jzys3(jylist1, 0, 1)
397 424
     # 求改算坐标
398 425
     gsx = gsys(listnewx, jxlist1, jylist1, lxlist,
399
-                lylist, arrz, sf, zxzbnewx, zxzbpastx, 0)
426
+               lylist, arrz, sf, zxzbnewx, zxzbpastx, 0)
400 427
     gsy = gsys(listnewy, jxlist2, jylist2, lxlist,
401
-                lylist, arrz, sf, zxzbnewy, zxzbpasty, 1)
428
+               lylist, arrz, sf, zxzbnewy, zxzbpasty, 1)
402 429
     # 还是要先求较差
403 430
     xcx = xcys(gsx, listpastx)
404 431
     xcy = xcys(gsy, listpasty)
@@ -447,9 +474,9 @@ def bhjs(listcgcs1, listname1, listpastx1, listpasty1, wypd, listname, listnewx,
447 474
         n3 = zxzbpastx - zxzbnewx - s1 - s2 + float(arrz[2])
448 475
         n4 = (-1) * float(arrz[1])
449 476
         n5 = n1
450
-        s3 = (-1)*float(arrz[0])*zxzbnewy
451
-        s4 = float(arrz[1])*zxzbnewx
452
-        n6 = s3 + s4 + float(arrz[3])+zxzbpasty-zxzbnewy
477
+        s3 = (-1) * float(arrz[0]) * zxzbnewy
478
+        s4 = float(arrz[1]) * zxzbnewx
479
+        n6 = s3 + s4 + float(arrz[3]) + zxzbpasty - zxzbnewy
453 480
         sxylist = []
454 481
         sxylist.append(n1)
455 482
         sxylist.append(n2)
@@ -466,56 +493,58 @@ def bhjs(listcgcs1, listname1, listpastx1, listpasty1, wypd, listname, listnewx,
466 493
         relist1.append(gszbx)
467 494
         relist1.append(gszby)
468 495
         relist1.append(sxylist)
469
-        #存入数据库
470
-        insert_into_database1(dbpath,lastname,finalname,befname,file_name,listname1,listpastx1,listpasty1,listcgcs1,listbex,listbey,sxylist,wypd,gsx,gsy,listcgcs)
496
+        # 存入数据库
497
+        insert_into_database1(dbpath, lastname, finalname, befname, file_name, listname1, listpastx1, listpasty1,
498
+                              listcgcs1, listbex, listbey, sxylist, wypd, gsx, gsy, listcgcs)
471 499
     else:
472
-            # 先把所有的合在一起,方便删除
473
-            lenlist1 = len(xcx)
474
-            ii = 0
475
-            relist1 = []
476
-            while ii < lenlist1:
477
-                smlist1 = []
478
-                nn2 = xcx[ii] * xcx[ii]
479
-                mm2 = xcy[ii] * xcy[ii]
480
-                nm2 = math.sqrt(nn2 + mm2)
481
-                smlist1.append(nm2)
482
-                smlist1.append(listname[ii])
483
-                smlist1.append(listnewx[ii])
484
-                smlist1.append(listnewy[ii])
485
-                smlist1.append(listpastx[ii])
486
-                smlist1.append(listpasty[ii])
487
-                relist1.append(smlist1)
488
-                ii = ii + 1
489
-            # 直接删除最大的那个
490
-            relist1.sort(key=takeFirst, reverse=True)
491
-            num1 = relist1[0]
492
-            # 获取name
493
-            num2 = num1[1]
494
-            ii2 = 0
495
-            mm2 = 0
496
-            while ii2 < lenlist1:
497
-                if listname[ii2] == num2:
498
-                    del listname[ii2]
499
-                    del listnewx[ii2]
500
-                    del listnewy[ii2]
501
-                    del listpastx[ii2]
502
-                    del listpasty[ii2]
503
-                    points = points - 1
504
-                    break
505
-                else:
506
-                    ii2 = ii2 + 1
507
-            while mm2 < len(listcgcs):
508
-                if listname1[mm2] == num2:
509
-                    listcgcs[mm2] = -1
510
-                    break
511
-                else:
512
-                    mm2 = mm2 + 1
513
-            print(" Finish!")
514
-            js1 = 1
515
-            bhjs(listcgcs1, listname1, listpastx1, listpasty1, wypd, listname, listnewx, listnewy, listpastx,
516
-                 listpasty, points, listcgcs, listbex, listbey, sf, dbpath, befname, finalname, lastname, js1,file_name)
500
+        # 先把所有的合在一起,方便删除
501
+        lenlist1 = len(xcx)
502
+        ii = 0
503
+        relist1 = []
504
+        while ii < lenlist1:
505
+            smlist1 = []
506
+            nn2 = xcx[ii] * xcx[ii]
507
+            mm2 = xcy[ii] * xcy[ii]
508
+            nm2 = math.sqrt(nn2 + mm2)
509
+            smlist1.append(nm2)
510
+            smlist1.append(listname[ii])
511
+            smlist1.append(listnewx[ii])
512
+            smlist1.append(listnewy[ii])
513
+            smlist1.append(listpastx[ii])
514
+            smlist1.append(listpasty[ii])
515
+            relist1.append(smlist1)
516
+            ii = ii + 1
517
+        # 直接删除最大的那个
518
+        relist1.sort(key=takeFirst, reverse=True)
519
+        num1 = relist1[0]
520
+        # 获取name
521
+        num2 = num1[1]
522
+        ii2 = 0
523
+        mm2 = 0
524
+        while ii2 < lenlist1:
525
+            if listname[ii2] == num2:
526
+                del listname[ii2]
527
+                del listnewx[ii2]
528
+                del listnewy[ii2]
529
+                del listpastx[ii2]
530
+                del listpasty[ii2]
531
+                points = points - 1
532
+                break
533
+            else:
534
+                ii2 = ii2 + 1
535
+        while mm2 < len(listcgcs):
536
+            if listname1[mm2] == num2:
537
+                listcgcs[mm2] = -1
538
+                break
539
+            else:
540
+                mm2 = mm2 + 1
541
+        print(" Finish!")
542
+        js1 = 1
543
+        bhjs(listcgcs1, listname1, listpastx1, listpasty1, wypd, listname, listnewx, listnewy, listpastx,
544
+             listpasty, points, listcgcs, listbex, listbey, sf, dbpath, befname, finalname, lastname, js1, file_name)
545
+
517 546
 
518
-def tablein(dbpath,file_name):
547
+def tablein(dbpath, file_name):
519 548
     # 收集每一列的数据,方便后期计算
520 549
     listname1 = []
521 550
     listpastx1 = []
@@ -532,12 +561,12 @@ def tablein(dbpath,file_name):
532 561
     listbex = []
533 562
     listbey = []
534 563
     points = 0
535
-    #查询,提取需要的数据
564
+    # 查询,提取需要的数据
536 565
     db2 = sqlite3.connect(dbpath)
537 566
     cursor2 = db2.cursor()
538 567
     utfstr1 = to_utf8(file_name)
539 568
     sqlstr1 = 'SELECT * FROM WD_Input_Point WHERE TableName = ?'
540
-    cursor2.execute(sqlstr1,(utfstr1,))
569
+    cursor2.execute(sqlstr1, (utfstr1,))
541 570
     all_da = cursor2.fetchall()
542 571
     for da in all_da:
543 572
         listbex.append(da[4])
@@ -554,11 +583,11 @@ def tablein(dbpath,file_name):
554 583
         listname.append(da[11])
555 584
         listname1.append(da[11])
556 585
     sqlstr2 = 'SELECT * FROM WD_Input_Param WHERE TableName = ?'
557
-    cursor2.execute(sqlstr2,(utfstr1,))
586
+    cursor2.execute(sqlstr2, (utfstr1,))
558 587
     all_par = cursor2.fetchall()
559 588
     befname = all_par[0][0].decode('utf-8')
560 589
     lastname = all_par[0][1].decode('utf-8')
561
-    finalname = all_par[0][2].decode('utf-8')    
590
+    finalname = all_par[0][2].decode('utf-8')
562 591
     # pjbc是平均边长
563 592
     # fxzwc是方向中误差,zrbzwc是最弱边边长相对中误差,pjbcs是平均边数,pjfxs是平均方向数,sf是缩放值
564 593
     # 新增总边数zbs,总方向数zfxs
@@ -580,14 +609,19 @@ def tablein(dbpath,file_name):
580 609
     wypd3 = math.sqrt(wypd1 + wypd2)
581 610
     wypd = round((wypd3 * 2 * math.sqrt(2)), 9)
582 611
     wypd0 = wypd
583
-    js=0
584
-    return listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx,listpasty, points, listcgcs, listbex, listbey, sf, befname, finalname, lastname, js
612
+    js = 0
613
+    return listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx, listpasty, points, listcgcs, listbex, listbey, sf, befname, finalname, lastname, js
585 614
 
586 615
 
587 616
 # 主函数 计算
588
-def main_function(dbpath,file_name):
589
-    #从数据库中调用
590
-    listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx,listpasty, points, listcgcs, listbex, listbey, sf, befname, finalname, lastname, js = tablein(dbpath,file_name)
591
-    #计算
592
-    bhjs(listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx,listpasty, points, listcgcs, listbex, listbey, sf, dbpath, befname, finalname, lastname, js,file_name)
593
-    messagebox.showinfo("提示",f"文件 '{file_name}' 计算成功!")
617
+def main_function(file_name, dbpath):
618
+    try:
619
+        # 从数据库中调用
620
+        listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx, listpasty, points, listcgcs, listbex, listbey, sf, befname, finalname, lastname, js = tablein(
621
+            dbpath, file_name)
622
+        # 计算
623
+        bhjs(listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx, listpasty,
624
+             points, listcgcs, listbex, listbey, sf, dbpath, befname, finalname, lastname, js, file_name)
625
+        QMessageBox.information(None, "提示", f"文件 '{file_name}' 计算成功!")
626
+    except Exception as e:
627
+        QMessageBox.critical(None, "错误", f"文件 '{file_name}' 计算失败!错误信息: {str(e)}")

+ 39
- 27
Back/WD/WDshow.py Просмотреть файл

@@ -3,42 +3,48 @@ import sqlite3
3 3
 
4 4
 from PySide6.QtGui import QStandardItemModel
5 5
 
6
+
6 7
 def main_function(ui, db_path, utf_en):
7
-    #只显示头两个tab
8
-    ui.tabWidget.setTabVisible(0,True)
9
-    ui.tabWidget.setTabVisible(1,True)
10
-    ui.tabWidget.setTabVisible(2,False)
11
-    #重新设置文字名称
12
-    ui.tabWidget.setTabText(0,'稳定性分析成果表')
13
-    ui.tabWidget.setTabText(1,'自由网成果归算模型')
14
-    #链接数据库并显示
8
+    # 只显示头两个tab
9
+    ui.tabWidget.setTabVisible(0, True)
10
+    ui.tabWidget.setTabVisible(1, True)
11
+    ui.tabWidget.setTabVisible(2, False)
12
+    # 重新设置文字名称
13
+    ui.tabWidget.setTabText(0, '稳定性分析成果表')
14
+    ui.tabWidget.setTabText(1, '自由网成果归算模型')
15
+    # 链接数据库并显示
15 16
     # 连接到数据库
16
-    #将结果输出到数据库
17
+    # 将结果输出到数据库
17 18
     db1 = sqlite3.connect(db_path)
18
-    #获取游标
19
+    # 获取游标
19 20
     cursor1 = db1.cursor()
20
-    #查询表内符合的所有数据
21
+    # 查询表内符合的所有数据
21 22
     sqlstr1 = 'select PointName,First_X,First_Y,Last_X,Last_Y,Last_Wight,Result_X,Result_Y,New_Wight,New_FirstX,New_FirstY,New_FirstP,NFDis_Ass,New_LastX,New_LastY,New_LastP,NLDis_Ass from WD_Result_Point WHERE TableName = ?'
22
-    cursor1.execute(sqlstr1,(utf_en,))
23
-    #获取结果集
23
+    cursor1.execute(sqlstr1, (utf_en,))
24
+    # 获取结果集
24 25
     result = cursor1.fetchall()
25
-    #对结果集进行处理,把汉字转换过来,添加表头部分
26
-    nlist,plist = Arrange_Data(result)
26
+    # 对结果集进行处理,把汉字转换过来,添加表头部分
27
+    nlist, plist = Arrange_Data(result)
27 28
     # 创建一个数据模型
28 29
     model = QStandardItemModel()
29
-    #把数据放进去
30
+    # 把数据放进去
30 31
     model1 = Data_in_Cell(plist)
31
-    #设置表头
32
-    model1.setHorizontalHeaderLabels(['点名', '首期X','首期Y','上期X', '上期Y','权','本期X','本期Y','权','本期-首期X','本期-首期Y','本期-首期P','位移判定', '本期-上期X','本期-上期Y','本期-上期P','位移判定'])
32
+    # 设置表头
33
+    model1.setHorizontalHeaderLabels(
34
+        ['点名', '首期X', '首期Y', '上期X', '上期Y', '权', '本期X', '本期Y', '权', '本期-首期X', '本期-首期Y',
35
+         '本期-首期P', '位移判定', '本期-上期X', '本期-上期Y', '本期-上期P', '位移判定'])
33 36
     model1.setVerticalHeaderLabels(nlist)
34
-    #QTableView并将数据模型与之关联
37
+
38
+    # QTableView并将数据模型与之关联
35 39
     ui.resultTableView.setModel(model1)
36 40
     ui.resultTableView.show()
37 41
 
38
-    #富文本的html
42
+    # 隐藏 QLabel(默认提示语言)
43
+    ui.default_remind.hide()
44
+    # 富文本的html
39 45
     sqlstr2 = 'select Last_ResultName,New_ResultName,Formula_X1,Formula_X2,Formula_X3,Formula_Y1,Formula_Y2,Formula_Y3 from WD_Result_Param WHERE TableName = ?'
40
-    cursor1.execute(sqlstr2,(utf_en,))
41
-    #获取结果集
46
+    cursor1.execute(sqlstr2, (utf_en,))
47
+    # 获取结果集
42 48
     result1 = cursor1.fetchall()
43 49
     str1 = result1[0][0].decode('utf-8')
44 50
     str2 = result1[0][1].decode('utf-8')
@@ -55,9 +61,15 @@ hr { height: 1px; border-width: 0; }
55 61
 li.unchecked::marker { content: "\2610"; }
56 62
 li.checked::marker { content: "\2612"; }
57 63
 </style></head><body style=" font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;">
58
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; color:#000000;">"""+str2+"""--"""+str1+"""</span><span style=" font-size:14pt;">已知系统转换公式:</span></p>
59
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:700;">X</span><span style=" font-size:14pt;">=(</span><span style=" font-size:14pt; color:#aa0000;">"""+str(n1)+"""</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">x</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00aa00;">"""+str(n2)+"""</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">y</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00007f;">"""+str(n3)+"""</span><span style=" font-size:14pt;">)</span></p>
60
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:700;">Y</span><span style=" font-size:14pt;">=(</span><span style=" font-size:14pt; color:#aa0000;">"""+str(n4)+"""</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">x</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00aa00;">"""+str(n5)+"""</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">y</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00007f;">"""+str(n6)+"""</span><span style=" font-size:14pt;">)</span></p>
61
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">式中:</span><span style=" font-size:14pt; font-weight:700; color:#000000;">x、y</span><span style=" font-size:14pt;">为</span><span style=" font-size:14pt; color:#000000;">"""+str2+"""</span><span style=" font-size:14pt;">坐标;</span></p>
62
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">          </span><span style=" font-size:14pt; font-weight:700;">X、Y</span><span style=" font-size:14pt;">为"""+str1+"""已知系统的"""+str2+"""归算坐标。</span></p></body></html>"""
64
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; color:#000000;">""" + str2 + """--""" + str1 + """</span><span style=" font-size:14pt;">已知系统转换公式:</span></p>
65
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:700;">X</span><span style=" font-size:14pt;">=(</span><span style=" font-size:14pt; color:#aa0000;">""" + str(
66
+        n1) + """</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">x</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00aa00;">""" + str(
67
+        n2) + """</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">y</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00007f;">""" + str(
68
+        n3) + """</span><span style=" font-size:14pt;">)</span></p>
69
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:700;">Y</span><span style=" font-size:14pt;">=(</span><span style=" font-size:14pt; color:#aa0000;">""" + str(
70
+        n4) + """</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">x</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00aa00;">""" + str(
71
+        n5) + """</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">y</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00007f;">""" + str(
72
+        n6) + """</span><span style=" font-size:14pt;">)</span></p>
73
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">式中:</span><span style=" font-size:14pt; font-weight:700; color:#000000;">x、y</span><span style=" font-size:14pt;">为</span><span style=" font-size:14pt; color:#000000;">""" + str2 + """</span><span style=" font-size:14pt;">坐标;</span></p>
74
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">          </span><span style=" font-size:14pt; font-weight:700;">X、Y</span><span style=" font-size:14pt;">为""" + str1 + """已知系统的""" + str2 + """归算坐标。</span></p></body></html>"""
63 75
     ui.printTableView.setHtml(str0)

+ 10
- 2
Front/main.py Просмотреть файл

@@ -67,7 +67,9 @@ class MainWindow(QMainWindow):
67 67
         # ///////////////////////////////////////////////////////////////
68 68
         self.ui = Ui_MainWindow()
69 69
         self.ui.setupUi(self)
70
+        # 连接信号与槽函数,实现点击操作
70 71
         self.ui.createFile.clicked.connect(self.on_create_file_clicked)
72
+        self.ui.export_2.clicked.connect(self.on_export_2_clicked)
71 73
         # self.comboBox_2 = QComboBox(self)
72 74
         # ...此处为省略代码...
73 75
         global widgets
@@ -247,10 +249,16 @@ class MainWindow(QMainWindow):
247 249
             # 触发按钮点击事件
248 250
             btn.click()
249 251
 
250
-
251 252
     # 新增槽函数来调用 create_database_and_tables
252 253
     def on_create_file_clicked(self):
253
-        Back.Program_Run.database_operations.create_database_and_tables(self.ui)
254
+        Back.Program_Run.database_operations.create_database_and_tables(self, self.ui)
255
+
256
+    # 定义导出数据库的槽函数
257
+    def on_export_2_clicked(self):
258
+        if self.file_path:
259
+            UIFunctions.export_database_to_excel(self, self.file_path)
260
+        else:
261
+            QMessageBox.warning(self, '警告', '请先选择项目并上传文件')
254 262
 
255 263
     # RESIZE EVENTS
256 264
     # ///////////////////////////////////////////////////////////////

+ 28
- 6
Front/modules/ui_functions.py Просмотреть файл

@@ -13,16 +13,16 @@
13 13
 # https://doc.qt.io/qtforpython/licenses.html
14 14
 #
15 15
 # ///////////////////////////////////////////////////////////////
16
-
16
+from PySide6.QtWidgets import QMessageBox
17 17
 # MAIN FILE
18 18
 # ///////////////////////////////////////////////////////////////
19 19
 
20 20
 
21 21
 from main import *
22 22
 import importlib
23
-from Back.GC import GC
24
-from Back.GS import GS
25
-from Back.WD import WD
23
+from Back.GC import GC, GCExport
24
+from Back.GS import GS, GSExport
25
+from Back.WD import WD, WDExport
26 26
 from Back.GC import GCcompute
27 27
 from Back.GS import GScompute
28 28
 from Back.WD import WDcompute
@@ -320,7 +320,6 @@ class UIFunctions(MainWindow):
320 320
     # 计算与展示文件的方法
321 321
     def compute_show_process_excel_file(self, file_path):
322 322
         current_text = self.ui.comboBox_2.currentText()
323
-        # db_path = r"D:/Code/ControlNetwork/UI/SQL/DataBase.db"
324 323
         # 获取当前脚本所在的目录
325 324
         current_dir = os.path.dirname(os.path.abspath(__file__))
326 325
         # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹)
@@ -338,6 +337,29 @@ class UIFunctions(MainWindow):
338 337
             GScompute.main_function(excelname, db_path)
339 338
             GSshow.main_function(self.ui, db_path, utf_en)
340 339
         elif current_text == "平面控制网稳定性计算":
341
-            WDcompute.main_function(file_path, db_path)
340
+            WDcompute.main_function(excelname, db_path)
342 341
             WDshow.main_function(self.ui, db_path, utf_en)
342
+
343
+    # 文件导出的方法
344
+    def export_database_to_excel(self, file_path):
345
+        current_text = self.ui.comboBox_2.currentText()
346
+        # 获取当前脚本所在的目录
347
+        current_dir = os.path.dirname(os.path.abspath(__file__))
348
+        # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹)
349
+        sql_folder = os.path.join(current_dir, '..', '..', 'SQL')
350
+        # 将相对路径转换为绝对路径
351
+        sql_folder = os.path.abspath(sql_folder)
352
+        db_path = os.path.join(sql_folder, f"{self.ui.comboBox.currentText()}.db")
353
+        # 转换为utf-8
354
+        excelname = os.path.basename(file_path)  # 文件名
355
+        utf_en = excelname.encode('utf-8')  # 转换文件名为utf-8编码形式
356
+        if current_text == "水准测段高差稳定计算":
357
+            GCExport.main_function(self, file_path, utf_en, db_path)
358
+        elif current_text == "控制网复测平面基准计算":
359
+            GSExport.main_function(self, db_path, file_path)
360
+        elif current_text == "平面控制网稳定性计算":
361
+            # WDExport.main_function(self, file_path)
362
+            pass
363
+        else:
364
+            QMessageBox.warning(self, '警告', '请选择有效的计算类型')
343 365
     # END - GUI DEFINITIONS

+ 1
- 44
Front/modules/ui_main.py Просмотреть файл

@@ -33,49 +33,6 @@ from watchdog.observers import Observer
33 33
 from .resources_rc import *
34 34
 
35 35
 
36
-
37
-# class ComboBoxUpdater(FileSystemEventHandler):
38
-#     def __init__(self, comboBox, sql_folder):
39
-#         super().__init__()
40
-#         self.comboBox = comboBox
41
-#         self.sql_folder = sql_folder
42
-#
43
-#     def on_modified(self, event):
44
-#         if event.is_directory:
45
-#             return
46
-#         if event.src_path.endswith('.db'):
47
-#             self.update_combo_box()
48
-#
49
-#     def on_created(self, event):
50
-#         if event.is_directory:
51
-#             return
52
-#         if event.src_path.endswith('.db'):
53
-#             self.update_combo_box()
54
-#
55
-#     def on_deleted(self, event):
56
-#         if event.is_directory:
57
-#             return
58
-#         if event.src_path.endswith('.db'):
59
-#             self.update_combo_box()
60
-#
61
-#     def update_combo_box(self):
62
-#         # 清空现有的 comboBox 内容
63
-#         self.comboBox.clear()
64
-#
65
-#         # 列出 SQL 文件夹中的所有 .db 文件
66
-#         db_files = [f for f in os.listdir(self.sql_folder) if f.endswith('.db')]
67
-#
68
-#         # 将数据库文件名添加到 comboBox 中
69
-#         for db_file in db_files:
70
-#             self.comboBox.addItem(QCoreApplication.translate("MainWindow", db_file, None))
71
-#
72
-#         # 如果没有找到任何数据库文件,显示提示信息
73
-#         if not db_files:
74
-#             self.comboBox.addItem(QCoreApplication.translate("MainWindow", "未找到数据库文件", None))
75
-
76
-
77
-
78
-
79 36
 class Ui_MainWindow(object):
80 37
     # UI界面
81 38
     def setupUi(self, MainWindow):
@@ -1359,7 +1316,7 @@ class Ui_MainWindow(object):
1359 1316
 
1360 1317
         # 确保 SQL 文件夹存在
1361 1318
         if not os.path.exists(sql_folder):
1362
-            QMessageBox.critical(MainWindow, "错误", "SQL 文件夹不存在")
1319
+            QMessageBox.critical(MainWindow, "错误", "项目文件夹不存在")
1363 1320
             return
1364 1321
         # 初始化 ComboBoxUpdater
1365 1322
         self.updater = ComboBoxUpdater(self.comboBox, sql_folder)

Двоичные данные
SQL/DataBase.db Просмотреть файл


Загрузка…
Отмена
Сохранить