Ver código fonte

Merge branch 'master' of http://oa.sccehui.com:6101/cmc-coding2/ControlNetwork

rmy 5 meses atrás
pai
commit
409ca9c318
4 arquivos alterados com 170 adições e 47 exclusões
  1. 32
    2
      Back/GC/GC.py
  2. 20
    0
      Back/GC/GCExport.py
  3. 7
    0
      Back/GC/GCcompute.py
  4. 111
    45
      Back/GC/GCshow.py

+ 32
- 2
Back/GC/GC.py Ver arquivo

1
 import openpyxl
1
 import openpyxl
2
 import sqlite3
2
 import sqlite3
3
 import os
3
 import os
4
+import pandas as pd
4
 from openpyxl import Workbook
5
 from openpyxl import Workbook
5
 from PySide6.QtWidgets import QApplication, QMessageBox
6
 from PySide6.QtWidgets import QApplication, QMessageBox
6
 
7
 
7
 
8
 
9
+# 添加文件转换函数
10
+def convert_xls_to_xlsx(file_path):
11
+    # 使用 pandas 读取 .xls 文件
12
+    df = pd.read_excel(file_path, engine='xlrd')
13
+    # 创建一个新的 .xlsx 文件路径
14
+    xlsx_file_path = file_path.replace('.xls', '.xlsx')
15
+    # 将数据保存为 .xlsx 文件
16
+    df.to_excel(xlsx_file_path, index=False)
17
+    return xlsx_file_path
18
+
19
+
20
+# 弹窗提示用户 .xls 文件将转换为 .xlsx 文件
21
+def confirm_xls_to_xlsx_conversion(file_name):
22
+    response = QMessageBox.question(None, "确认转换",
23
+                                    f".xls文件将默认转换为.xlsx文件进行计算,系统会重新生成一个.xlsx文件副本用以计算,不会删除您本来的.xls文件,点击“OK”开始上传文件,点击“Cancel”取消上传文件",
24
+                                    QMessageBox.Ok | QMessageBox.Cancel)
25
+    return response == QMessageBox.Ok
26
+
27
+
8
 # 读取指定单元格的数据
28
 # 读取指定单元格的数据
9
 def read_cells_from_excel(cells, sheet):
29
 def read_cells_from_excel(cells, sheet):
10
     """
30
     """
106
                 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
126
                 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
107
                 """,
127
                 """,
108
                 (
128
                 (
109
-                file_name_utf8, cell_values['D1'], cell_values['C1'], cell_values['I1'], ms_station, last_station_count,
110
-                new_station_count, last_sum_hdiff, new_sum_hdiff, last_sum_rlen, new_sum_rlen)
129
+                    file_name_utf8, cell_values['D1'], cell_values['C1'], cell_values['I1'], ms_station,
130
+                    last_station_count,
131
+                    new_station_count, last_sum_hdiff, new_sum_hdiff, last_sum_rlen, new_sum_rlen)
111
             )
132
             )
112
             QMessageBox.information(None, "提示",
133
             QMessageBox.information(None, "提示",
113
                                     f"文件 '{file_name}' 已成功添加到本地数据库中,点击'OK'以关闭此对话框。对话框关闭后,请点击“计算”以计算数据")
134
                                     f"文件 '{file_name}' 已成功添加到本地数据库中,点击'OK'以关闭此对话框。对话框关闭后,请点击“计算”以计算数据")
243
 
264
 
244
 # 主函数 读取excel文件
265
 # 主函数 读取excel文件
245
 def main_function(file_path, db_path):
266
 def main_function(file_path, db_path):
267
+    # 检查文件扩展名
268
+    if file_path.endswith('.xls'):
269
+        # 弹窗提示用户 .xls 文件将转换为 .xlsx 文件
270
+        if not confirm_xls_to_xlsx_conversion(os.path.basename(file_path)):
271
+            print("用户取消了转换操作")
272
+            return
273
+
274
+        # 转换 .xls 文件为 .xlsx 文件
275
+        file_path = convert_xls_to_xlsx(file_path)
246
     # 调用读取Excel文件的函数
276
     # 调用读取Excel文件的函数
247
     file_name = os.path.basename(file_path)
277
     file_name = os.path.basename(file_path)
248
     file_name_utf8 = file_name.encode('utf-8')
278
     file_name_utf8 = file_name.encode('utf-8')

+ 20
- 0
Back/GC/GCExport.py Ver arquivo

272
         else:
272
         else:
273
             QMessageBox.critical(ui, '错误', f'导出初始数据过程中发生错误: {str(e)}')
273
             QMessageBox.critical(ui, '错误', f'导出初始数据过程中发生错误: {str(e)}')
274
 
274
 
275
+def process_utf_en(utf_en):
276
+    # 确保 utf_en 是字节字符串
277
+    if not isinstance(utf_en, bytes):
278
+        utf_en = utf_en.encode('utf-8')
279
+
280
+    # 将字节字符串解码为普通字符串
281
+    file_name = utf_en.decode('utf-8')
282
+
283
+    # 检查文件后缀名并进行相应处理
284
+    if file_name.endswith('.xls'):
285
+        # 去掉 .xls 后缀并添加 .xlsx 后缀
286
+        file_name = file_name[:-4] + '.xlsx'
287
+
288
+    # 将处理后的字符串重新编码为字节字符串
289
+    utf_en = file_name.encode('utf-8')
290
+
291
+    return utf_en
275
 
292
 
276
 def main_function_initial(ui, utf_en, db_path):
293
 def main_function_initial(ui, utf_en, db_path):
294
+
277
     # 获取应用的安装目录
295
     # 获取应用的安装目录
278
     app_install_dir = os.path.dirname(os.path.abspath(__file__))  # 假设脚本文件位于应用的安装目录下
296
     app_install_dir = os.path.dirname(os.path.abspath(__file__))  # 假设脚本文件位于应用的安装目录下
279
     export_folder = os.path.join(app_install_dir, 'Export')
297
     export_folder = os.path.join(app_install_dir, 'Export')
287
 
305
 
288
 
306
 
289
 def main_function_result(ui, utf_en, db_path):
307
 def main_function_result(ui, utf_en, db_path):
308
+    # 处理 utf_en
309
+    utf_en = process_utf_en(utf_en)
290
     # 获取应用的安装目录
310
     # 获取应用的安装目录
291
     app_install_dir = os.path.dirname(os.path.abspath(__file__))  # 假设脚本文件位于应用的安装目录下
311
     app_install_dir = os.path.dirname(os.path.abspath(__file__))  # 假设脚本文件位于应用的安装目录下
292
     export_folder = os.path.join(app_install_dir, 'Export')
312
     export_folder = os.path.join(app_install_dir, 'Export')

+ 7
- 0
Back/GC/GCcompute.py Ver arquivo

278
         file_name = os.path.basename(file_path)
278
         file_name = os.path.basename(file_path)
279
         file_name_utf8 = file_name.encode('utf-8')
279
         file_name_utf8 = file_name.encode('utf-8')
280
 
280
 
281
+        # 检查文件后缀名
282
+        if file_name.endswith('.xls'):
283
+            # 去掉 .xls 后缀并添加 .xlsx 后缀
284
+            file_name = file_name[:-4] + '.xlsx'
285
+            file_name_utf8 = file_name.encode('utf-8')
286
+
281
         # 处理查询结果
287
         # 处理查询结果
282
         abs_last_hdiffs = calculate_absolute_height_differences(db_path, file_name_utf8, "Last_HDiff")
288
         abs_last_hdiffs = calculate_absolute_height_differences(db_path, file_name_utf8, "Last_HDiff")
283
         abs_new_hdiffs = calculate_absolute_height_differences(db_path, file_name_utf8, "New_HDiff")
289
         abs_new_hdiffs = calculate_absolute_height_differences(db_path, file_name_utf8, "New_HDiff")
359
 
365
 
360
     except Exception as e:
366
     except Exception as e:
361
         QMessageBox.critical(None, "错误", f"文件 '{file_name}' 计算失败!错误信息: {str(e)}")
367
         QMessageBox.critical(None, "错误", f"文件 '{file_name}' 计算失败!错误信息: {str(e)}")
368
+        print(f"文件 '{file_name}' 计算失败!错误信息: {str(e)}")

+ 111
- 45
Back/GC/GCshow.py Ver arquivo

5
 from PySide6.QtCore import QItemSelectionModel
5
 from PySide6.QtCore import QItemSelectionModel
6
 
6
 
7
 
7
 
8
-def main_function(ui, db_path, utf_en):
8
+def process_utf_en(utf_en):
9
     # 确保 utf_en 是字节字符串
9
     # 确保 utf_en 是字节字符串
10
     if not isinstance(utf_en, bytes):
10
     if not isinstance(utf_en, bytes):
11
         utf_en = utf_en.encode('utf-8')
11
         utf_en = utf_en.encode('utf-8')
12
 
12
 
13
+    # 将字节字符串解码为普通字符串
14
+    file_name = utf_en.decode('utf-8')
15
+
16
+    # 检查文件后缀名并进行相应处理
17
+    if file_name.endswith('.xls'):
18
+        # 去掉 .xls 后缀并添加 .xlsx 后缀
19
+        file_name = file_name[:-4] + '.xlsx'
20
+
21
+    # 将处理后的字符串重新编码为字节字符串
22
+    utf_en = file_name.encode('utf-8')
23
+
24
+    return utf_en
25
+
26
+
27
+def main_function(ui, db_path, utf_en):
28
+    # 处理 utf_en
29
+    utf_en = process_utf_en(utf_en)
30
+
13
     # 设置 QTabWidget 的可见性和标签文本
31
     # 设置 QTabWidget 的可见性和标签文本
14
     tabs_to_show = [(0, '水准测段高差计算成果表')]
32
     tabs_to_show = [(0, '水准测段高差计算成果表')]
15
     for index in range(ui.tabWidget.count()):
33
     for index in range(ui.tabWidget.count()):
23
     db1.text_factory = lambda x: str(x, 'utf-8')
41
     db1.text_factory = lambda x: str(x, 'utf-8')
24
     cursor1 = db1.cursor()
42
     cursor1 = db1.cursor()
25
 
43
 
26
-    # 查询 GC_Output_Point 表中的 TableName 字段
27
-    query_table_names = "SELECT DISTINCT TableName FROM GC_Output_Point"
28
-    cursor1.execute(query_table_names)
29
-
44
+    # 查询 GC_Output_Point 表中的数据
30
     query = """
45
     query = """
31
     SELECT New_ID, New_ResultName, New_SPName, New_EPName, New_HDiff, New_RLen, Correct_Factor, Period_Diff, Dis_Ass
46
     SELECT New_ID, New_ResultName, New_SPName, New_EPName, New_HDiff, New_RLen, Correct_Factor, Period_Diff, Dis_Ass
32
     FROM GC_Output_Point
47
     FROM GC_Output_Point
33
     WHERE TableName = ?
48
     WHERE TableName = ?
34
     """
49
     """
35
     cursor1.execute(query, (utf_en,))
50
     cursor1.execute(query, (utf_en,))
36
-    result = cursor1.fetchall()
51
+    output_result = cursor1.fetchall()
52
+
53
+    # 查询 GC_Input_Param 表中的 Correct_Factor 字段
54
+    param_query_correct_factor = """
55
+    SELECT Correct_Factor
56
+    FROM GC_Input_Param
57
+    WHERE TableName = ?
58
+    """
59
+    cursor1.execute(param_query_correct_factor, (utf_en,))
60
+    correct_factor_result = cursor1.fetchall()
61
+
37
     cursor1.close()
62
     cursor1.close()
38
     db1.close()
63
     db1.close()
39
 
64
 
40
     # 创建 QStandardItemModel 实例
65
     # 创建 QStandardItemModel 实例
41
     model = QStandardItemModel()
66
     model = QStandardItemModel()
42
-    model.setColumnCount(len(result[0]))
67
+    model.setColumnCount(len(output_result[0]) + 1)  # 增加一列
43
 
68
 
44
     # 设置表头
69
     # 设置表头
45
-    headers = ['序号', '结果期数', '起点', '终点', '高差', '路线长', '修正数', '期间差异', '变形判定']
70
+    headers = ['序号', '结果期数', '起点', '终点', '高差', '路线长', '修正数', '期间差异', '变形判定', '修正系数']
46
     model.setHorizontalHeaderLabels(headers)
71
     model.setHorizontalHeaderLabels(headers)
47
 
72
 
48
-    for row_data in result:
73
+    # 使用 itertools.zip_longest 处理长度不一致的情况
74
+    for row_data, correct_factor_data in itertools.zip_longest(output_result, correct_factor_result,
75
+                                                               fillvalue=(None, None)):
49
         items = []
76
         items = []
50
         for i, item in enumerate(row_data):
77
         for i, item in enumerate(row_data):
51
-            if i == 4 or i == 5:  # 索引4(高差)
52
-                item = f"{item:.6f}"  # 格式化为6位小数
53
-            elif i == 6:  # 索引 6(修正数)
54
-                item = f"{item:.2f}"
55
-            elif i == 7:  # 假设 Period_Diff 在索引 7
56
-                if item is not None and isinstance(item, (int, float)):
57
-                    item = f"{item:.2f}"  # 格式化为2位小数
58
-                else:
59
-                    item = ""  # 如果是 None 或非数字类型,显示空字符串
60
-            elif i == 8:  # 假设 Dis_Ass 在索引 8
61
-                if item is not None and isinstance(item, str):
62
-                    item = item  # 显示字符串内容
63
-                else:
64
-                    item = ""  # 如果是 None,显示空字符串
78
+            if item is None:
79
+                item = ""  # 如果是 None,显示空字符串
80
+            else:
81
+                if i == 4 or i == 5:  # 索引4(高差)和索引5(路线长)
82
+                    item = f"{item:.6f}"  # 格式化为6位小数
83
+                elif i == 6:  # 索引 6(修正数)
84
+                    item = f"{item:.2f}"
85
+                elif i == 7:  # 假设 Period_Diff 在索引 7
86
+                    if item is not None and isinstance(item, (int, float)):
87
+                        item = f"{item:.2f}"  # 格式化为2位小数
88
+                    else:
89
+                        item = ""  # 如果是 None 或非数字类型,显示空字符串
90
+                elif i == 8:  # 假设 Dis_Ass 在索引 8
91
+                    if item is not None and isinstance(item, str):
92
+                        item = item  # 显示字符串内容
93
+                    else:
94
+                        item = ""  # 如果是 None,显示空字符串
65
             items.append(QStandardItem(str(item)))
95
             items.append(QStandardItem(str(item)))
96
+
97
+        # 添加修正系数列数据
98
+        if correct_factor_data is not None and correct_factor_data[0] is not None:
99
+            correct_factor = f"{correct_factor_data[0]:.10f}"  # 格式化为10位小数
100
+        else:
101
+            correct_factor = ""
102
+
103
+        items.append(QStandardItem(str(correct_factor)))
104
+
66
         model.appendRow(items)
105
         model.appendRow(items)
67
 
106
 
68
     # 设置并展示表格
107
     # 设置并展示表格
101
 
140
 
102
     # 查询 GC_Input_Param 表中的数据
141
     # 查询 GC_Input_Param 表中的数据
103
     param_query = """
142
     param_query = """
104
-    SELECT ObservationLevel, Ms_Station, Last_StationCount, Last_SumHDiff, Last_SumRLen, New_StationCount, New_SumHDiff, New_SumRLen
143
+    SELECT ObservationLevel, Ms_Station, Last_StationCount, Last_SumHDiff, Last_SumRLen, New_StationCount, New_SumHDiff, New_SumRLen, Correct_Factor
105
     FROM GC_Input_Param
144
     FROM GC_Input_Param
106
     WHERE TableName = ?
145
     WHERE TableName = ?
107
     """
146
     """
122
     input_model.setHorizontalHeaderLabels(input_headers)
161
     input_model.setHorizontalHeaderLabels(input_headers)
123
 
162
 
124
     # 使用 itertools.zip_longest 处理长度不一致的情况
163
     # 使用 itertools.zip_longest 处理长度不一致的情况
125
-    for row_data, param_data in itertools.zip_longest(input_result, param_result, fillvalue=(None, None, None, None, None, None, None, None)):
164
+    for row_data, param_data in itertools.zip_longest(input_result, param_result,
165
+                                                      fillvalue=(None, None, None, None, None, None, None, None, None)):
126
         items = []
166
         items = []
127
         for i, item in enumerate(row_data):
167
         for i, item in enumerate(row_data):
128
             if item is None:
168
             if item is None:
134
 
174
 
135
         # 添加新的列数据
175
         # 添加新的列数据
136
         if param_data is not None:
176
         if param_data is not None:
137
-            observation_level, ms_station, last_station_count, last_sum_hdiff, last_sum_rlen, new_station_count, new_sum_hdiff, new_sum_rlen = param_data
177
+            observation_level, ms_station, last_station_count, last_sum_hdiff, last_sum_rlen, new_station_count, new_sum_hdiff, new_sum_rlen, correct_factor = param_data
138
         else:
178
         else:
139
-            observation_level, ms_station, last_station_count, last_sum_hdiff, last_sum_rlen, new_station_count, new_sum_hdiff, new_sum_rlen = "", "", "", "", "", "", "", ""
179
+            observation_level, ms_station, last_station_count, last_sum_hdiff, last_sum_rlen, new_station_count, new_sum_hdiff, new_sum_rlen, correct_factor = "", "", "", "", "", "", "", "", ""
140
 
180
 
141
         # 确保 observation_level 和 ms_station 是字符串
181
         # 确保 observation_level 和 ms_station 是字符串
142
         if observation_level is None:
182
         if observation_level is None:
165
             new_sum_rlen = ""
205
             new_sum_rlen = ""
166
         else:
206
         else:
167
             new_sum_rlen = f"{new_sum_rlen:.6f}"
207
             new_sum_rlen = f"{new_sum_rlen:.6f}"
208
+        if correct_factor is None:
209
+            correct_factor = ""
168
 
210
 
169
         items.append(QStandardItem(str(observation_level)))
211
         items.append(QStandardItem(str(observation_level)))
170
         items.append(QStandardItem(f"{ms_station:.2f}" if isinstance(ms_station, (int, float)) else ""))
212
         items.append(QStandardItem(f"{ms_station:.2f}" if isinstance(ms_station, (int, float)) else ""))
193
     cursor1.execute(output_query, (utf_en,))
235
     cursor1.execute(output_query, (utf_en,))
194
     output_result = cursor1.fetchall()
236
     output_result = cursor1.fetchall()
195
 
237
 
238
+    # 查询 GC_Input_Param 表中的 Correct_Factor 字段
239
+    param_query_correct_factor = """
240
+    SELECT Correct_Factor
241
+    FROM GC_Input_Param
242
+    WHERE TableName = ?
243
+    """
244
+    cursor1.execute(param_query_correct_factor, (utf_en,))
245
+    correct_factor_result = cursor1.fetchall()
246
+
196
     # 创建 QStandardItemModel 实例
247
     # 创建 QStandardItemModel 实例
197
     output_model = QStandardItemModel()
248
     output_model = QStandardItemModel()
198
-    output_model.setColumnCount(len(output_result[0]))
249
+    output_model.setColumnCount(len(output_result[0]) + 1)  # 增加一列
199
 
250
 
200
     # 设置表头
251
     # 设置表头
201
-    output_headers = ['序号', '结果期数', '起点', '终点', '高差', '路线长', '修正数', '期间差异', '变形判定']
252
+    output_headers = [
253
+        '序号', '结果期数', '起点', '终点', '高差', '路线长', '修正数', '期间差异', '变形判定', '修正系数'
254
+    ]
202
     output_model.setHorizontalHeaderLabels(output_headers)
255
     output_model.setHorizontalHeaderLabels(output_headers)
203
 
256
 
204
-    for row_data in output_result:
257
+    # 使用 itertools.zip_longest 处理长度不一致的情况
258
+    for row_data, correct_factor_data in itertools.zip_longest(output_result, correct_factor_result,
259
+                                                               fillvalue=(None, None)):
205
         items = []
260
         items = []
206
         for i, item in enumerate(row_data):
261
         for i, item in enumerate(row_data):
207
-            if i == 4 or i == 5:  # 索引4(高差)和索引5(路线长)
208
-                item = f"{item:.6f}"  # 格式化为6位小数
209
-            elif i == 6:  # 索引 6(修正数)
210
-                item = f"{item:.2f}"
211
-            elif i == 7:  # 假设 Period_Diff 在索引 7
212
-                if item is not None and isinstance(item, (int, float)):
213
-                    item = f"{item:.2f}"  # 格式化为2位小数
214
-                else:
215
-                    item = ""  # 如果是 None 或非数字类型,显示空字符串
216
-            elif i == 8:  # 假设 Dis_Ass 在索引 8
217
-                if item is not None and isinstance(item, str):
218
-                    item = item  # 显示字符串内容
219
-                else:
220
-                    item = ""  # 如果是 None,显示空字符串
262
+            if item is None:
263
+                item = ""  # 如果是 None,显示空字符串
264
+            else:
265
+                if i == 4 or i == 5:  # 索引4(高差)和索引5(路线长)
266
+                    item = f"{item:.6f}"  # 格式化为6位小数
267
+                elif i == 6:  # 索引 6(修正数)
268
+                    item = f"{item:.2f}"
269
+                elif i == 7:  # 假设 Period_Diff 在索引 7
270
+                    if item is not None and isinstance(item, (int, float)):
271
+                        item = f"{item:.2f}"  # 格式化为2位小数
272
+                    else:
273
+                        item = ""  # 如果是 None 或非数字类型,显示空字符串
274
+                elif i == 8:  # 假设 Dis_Ass 在索引 8
275
+                    if item is not None and isinstance(item, str):
276
+                        item = item  # 显示字符串内容
277
+                    else:
278
+                        item = ""  # 如果是 None,显示空字符串
221
             items.append(QStandardItem(str(item)))
279
             items.append(QStandardItem(str(item)))
280
+
281
+        # 添加修正系数列数据
282
+        if correct_factor_data is not None and correct_factor_data[0] is not None:
283
+            correct_factor = f"{correct_factor_data[0]:.10f}"  # 格式化为6位小数
284
+        else:
285
+            correct_factor = ""
286
+
287
+        items.append(QStandardItem(str(correct_factor)))
288
+
222
         output_model.appendRow(items)
289
         output_model.appendRow(items)
223
 
290
 
224
     # 设置并展示输出数据表格
291
     # 设置并展示输出数据表格
237
 
304
 
238
     # 隐藏 QLabel
305
     # 隐藏 QLabel
239
     ui.default_remind1.hide()
306
     ui.default_remind1.hide()
240
-

Carregando…
Cancelar
Salvar