控制网复测平面基准归算程序(包含控制网复测平面基准计算,平面控制网稳定性计算,水准测段高差稳定计算三个程序功能)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GCshow.py 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. import itertools
  2. import sqlite3
  3. from PySide6.QtGui import QStandardItemModel, QStandardItem
  4. from PySide6.QtCore import QItemSelectionModel
  5. def process_utf_en(utf_en):
  6. # 确保 utf_en 是字节字符串
  7. if not isinstance(utf_en, bytes):
  8. utf_en = utf_en.encode('utf-8')
  9. # 将字节字符串解码为普通字符串
  10. file_name = utf_en.decode('utf-8')
  11. # 检查文件后缀名并进行相应处理
  12. if file_name.endswith('.xls'):
  13. # 去掉 .xls 后缀并添加 .xlsx 后缀
  14. file_name = file_name[:-4] + '.xlsx'
  15. # 将处理后的字符串重新编码为字节字符串
  16. utf_en = file_name.encode('utf-8')
  17. return utf_en
  18. def main_function(ui, db_path, utf_en):
  19. # 处理 utf_en
  20. utf_en = process_utf_en(utf_en)
  21. # 设置 QTabWidget 的可见性和标签文本
  22. tabs_to_show = [(0, '水准测段高差计算成果表')]
  23. for index in range(ui.tabWidget.count()):
  24. visible = index in [t[0] for t in tabs_to_show]
  25. ui.tabWidget.setTabVisible(index, visible)
  26. for index, text in tabs_to_show:
  27. ui.tabWidget.setTabText(index, text)
  28. # 连接到数据库并执行查询
  29. db1 = sqlite3.connect(db_path)
  30. db1.text_factory = lambda x: str(x, 'utf-8')
  31. cursor1 = db1.cursor()
  32. # 查询 GC_Output_Point 表中的数据
  33. query = """
  34. SELECT New_ID, New_ResultName, New_SPName, New_EPName, New_HDiff, New_RLen, Correct_Factor, Period_Diff, Dis_Ass
  35. FROM GC_Output_Point
  36. WHERE TableName = ?
  37. """
  38. cursor1.execute(query, (utf_en,))
  39. output_result = cursor1.fetchall()
  40. # 查询 GC_Input_Param 表中的 Correct_Factor 字段
  41. param_query_correct_factor = """
  42. SELECT Correct_Factor
  43. FROM GC_Input_Param
  44. WHERE TableName = ?
  45. """
  46. cursor1.execute(param_query_correct_factor, (utf_en,))
  47. correct_factor_result = cursor1.fetchall()
  48. cursor1.close()
  49. db1.close()
  50. # 创建 QStandardItemModel 实例
  51. model = QStandardItemModel()
  52. model.setColumnCount(len(output_result[0]) + 1) # 增加一列
  53. # 设置表头
  54. headers = ['序号', '结果期数', '起点', '终点', '高差', '路线长', '修正数', '期间差异', '变形判定', '修正系数']
  55. model.setHorizontalHeaderLabels(headers)
  56. # 使用 itertools.zip_longest 处理长度不一致的情况
  57. for row_data, correct_factor_data in itertools.zip_longest(output_result, correct_factor_result,
  58. fillvalue=(None, None)):
  59. items = []
  60. for i, item in enumerate(row_data):
  61. if item is None:
  62. item = "" # 如果是 None,显示空字符串
  63. else:
  64. if i == 4 or i == 5: # 索引4(高差)和索引5(路线长)
  65. item = f"{item:.6f}" # 格式化为6位小数
  66. elif i == 6: # 索引 6(修正数)
  67. item = f"{item:.2f}"
  68. elif i == 7: # 假设 Period_Diff 在索引 7
  69. if item is not None and isinstance(item, (int, float)):
  70. item = f"{item:.2f}" # 格式化为2位小数
  71. else:
  72. item = "" # 如果是 None 或非数字类型,显示空字符串
  73. elif i == 8: # 假设 Dis_Ass 在索引 8
  74. if item is not None and isinstance(item, str):
  75. item = item # 显示字符串内容
  76. else:
  77. item = "" # 如果是 None,显示空字符串
  78. items.append(QStandardItem(str(item)))
  79. # 添加修正系数列数据
  80. if correct_factor_data is not None and correct_factor_data[0] is not None:
  81. correct_factor = f"{correct_factor_data[0]:.10f}" # 格式化为10位小数
  82. else:
  83. correct_factor = ""
  84. items.append(QStandardItem(str(correct_factor)))
  85. model.appendRow(items)
  86. # 设置并展示表格
  87. ui.resultTableView.setModel(model)
  88. ui.resultTableView.show()
  89. # 隐藏 QLabel
  90. ui.default_remind.hide()
  91. def search_show_function(ui, db_path, utf_en):
  92. # 确保 utf_en 是字节字符串
  93. if not isinstance(utf_en, bytes):
  94. utf_en = utf_en.encode('utf-8')
  95. tabs_to_show = [(0, '输入数据'), (1, '水准测段高差计算成果表')]
  96. for index in range(ui.View.count()):
  97. visible = index in [t[0] for t in tabs_to_show]
  98. ui.View.setTabVisible(index, visible)
  99. for index, text in tabs_to_show:
  100. ui.View.setTabText(index, text)
  101. # 连接到数据库并执行查询
  102. db1 = sqlite3.connect(db_path)
  103. db1.text_factory = lambda x: str(x, 'utf-8')
  104. cursor1 = db1.cursor()
  105. # 查询 GC_Input_Point 表中的数据
  106. input_query = """
  107. SELECT New_ID, Last_ResultName, Last_SPName, Last_EPName, Last_HDiff, Last_RLen, New_ResultName, New_SPName, New_EPName, New_HDiff, New_RLen
  108. FROM GC_Input_Point
  109. WHERE TableName = ?
  110. """
  111. cursor1.execute(input_query, (utf_en,))
  112. input_result = cursor1.fetchall()
  113. # 查询 GC_Input_Param 表中的数据
  114. param_query = """
  115. SELECT ObservationLevel, Ms_Station, Last_StationCount, Last_SumHDiff, Last_SumRLen, New_StationCount, New_SumHDiff, New_SumRLen, Correct_Factor
  116. FROM GC_Input_Param
  117. WHERE TableName = ?
  118. """
  119. cursor1.execute(param_query, (utf_en,))
  120. param_result = cursor1.fetchall()
  121. # 创建 QStandardItemModel 实例
  122. input_model = QStandardItemModel()
  123. input_model.setColumnCount(len(input_result[0]) + 8) # 增加八列(2 + 6)
  124. # 设置表头
  125. input_headers = [
  126. '序号', '上期成果名', '上期测段起点', '上期测段终点', '上期高差', '上期路线长', '本期成果名',
  127. '本期测段起点', '本期测段终点',
  128. '本期高差', '本期路线长', '观测等级', '测站全中误差',
  129. '上次总测段数', '上期高差合计', '上期路线长合计', '本期总测段数', '本期高差合计', '本期路线长合计'
  130. ]
  131. input_model.setHorizontalHeaderLabels(input_headers)
  132. # 使用 itertools.zip_longest 处理长度不一致的情况
  133. for row_data, param_data in itertools.zip_longest(input_result, param_result,
  134. fillvalue=(None, None, None, None, None, None, None, None, None)):
  135. items = []
  136. for i, item in enumerate(row_data):
  137. if item is None:
  138. item = "" # 如果是 None,显示空字符串
  139. else:
  140. if i in [4, 5, 10, 11]: # 索引4,5,10,11(高差和路线长)
  141. item = f"{item:.6f}" # 格式化为6位小数
  142. items.append(QStandardItem(str(item)))
  143. # 添加新的列数据
  144. if param_data is not None:
  145. 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
  146. else:
  147. observation_level, ms_station, last_station_count, last_sum_hdiff, last_sum_rlen, new_station_count, new_sum_hdiff, new_sum_rlen, correct_factor = "", "", "", "", "", "", "", "", ""
  148. # 确保 observation_level 和 ms_station 是字符串
  149. if observation_level is None:
  150. observation_level = ""
  151. if ms_station is None:
  152. ms_station = ""
  153. # 确保其他字段是字符串或格式化后的字符串
  154. if last_station_count is None:
  155. last_station_count = ""
  156. if last_sum_hdiff is None:
  157. last_sum_hdiff = ""
  158. else:
  159. last_sum_hdiff = f"{last_sum_hdiff:.6f}"
  160. if last_sum_rlen is None:
  161. last_sum_rlen = ""
  162. else:
  163. last_sum_rlen = f"{last_sum_rlen:.6f}"
  164. if new_station_count is None:
  165. new_station_count = ""
  166. if new_sum_hdiff is None:
  167. new_sum_hdiff = ""
  168. else:
  169. new_sum_hdiff = f"{new_sum_hdiff:.6f}"
  170. if new_sum_rlen is None:
  171. new_sum_rlen = ""
  172. else:
  173. new_sum_rlen = f"{new_sum_rlen:.6f}"
  174. if correct_factor is None:
  175. correct_factor = ""
  176. items.append(QStandardItem(str(observation_level)))
  177. items.append(QStandardItem(f"{ms_station:.2f}" if isinstance(ms_station, (int, float)) else ""))
  178. items.append(QStandardItem(str(last_station_count)))
  179. items.append(QStandardItem(str(last_sum_hdiff)))
  180. items.append(QStandardItem(str(last_sum_rlen)))
  181. items.append(QStandardItem(str(new_station_count)))
  182. items.append(QStandardItem(str(new_sum_hdiff)))
  183. items.append(QStandardItem(str(new_sum_rlen)))
  184. input_model.appendRow(items)
  185. # 设置并展示输入数据表格
  186. ui.View.setTabText(0, '输入数据')
  187. ui.resultTableView1.setModel(input_model)
  188. ui.resultTableView1.show()
  189. # 隐藏 QLabel
  190. ui.default_remind1.hide()
  191. # 查询 GC_Output_Point 表中的数据
  192. output_query = """
  193. SELECT New_ID, New_ResultName, New_SPName, New_EPName, New_HDiff, New_RLen, Correct_Factor, Period_Diff, Dis_Ass
  194. FROM GC_Output_Point
  195. WHERE TableName = ?
  196. """
  197. cursor1.execute(output_query, (utf_en,))
  198. output_result = cursor1.fetchall()
  199. # 查询 GC_Input_Param 表中的 Correct_Factor 字段
  200. param_query_correct_factor = """
  201. SELECT Correct_Factor
  202. FROM GC_Input_Param
  203. WHERE TableName = ?
  204. """
  205. cursor1.execute(param_query_correct_factor, (utf_en,))
  206. correct_factor_result = cursor1.fetchall()
  207. # 创建 QStandardItemModel 实例
  208. output_model = QStandardItemModel()
  209. output_model.setColumnCount(len(output_result[0]) + 1) # 增加一列
  210. # 设置表头
  211. output_headers = [
  212. '序号', '结果期数', '起点', '终点', '高差', '路线长', '修正数', '期间差异', '变形判定', '修正系数'
  213. ]
  214. output_model.setHorizontalHeaderLabels(output_headers)
  215. # 使用 itertools.zip_longest 处理长度不一致的情况
  216. for row_data, correct_factor_data in itertools.zip_longest(output_result, correct_factor_result,
  217. fillvalue=(None, None)):
  218. items = []
  219. for i, item in enumerate(row_data):
  220. if item is None:
  221. item = "" # 如果是 None,显示空字符串
  222. else:
  223. if i == 4 or i == 5: # 索引4(高差)和索引5(路线长)
  224. item = f"{item:.6f}" # 格式化为6位小数
  225. elif i == 6: # 索引 6(修正数)
  226. item = f"{item:.2f}"
  227. elif i == 7: # 假设 Period_Diff 在索引 7
  228. if item is not None and isinstance(item, (int, float)):
  229. item = f"{item:.2f}" # 格式化为2位小数
  230. else:
  231. item = "" # 如果是 None 或非数字类型,显示空字符串
  232. elif i == 8: # 假设 Dis_Ass 在索引 8
  233. if item is not None and isinstance(item, str):
  234. item = item # 显示字符串内容
  235. else:
  236. item = "" # 如果是 None,显示空字符串
  237. items.append(QStandardItem(str(item)))
  238. # 添加修正系数列数据
  239. if correct_factor_data is not None and correct_factor_data[0] is not None:
  240. correct_factor = f"{correct_factor_data[0]:.10f}" # 格式化为6位小数
  241. else:
  242. correct_factor = ""
  243. items.append(QStandardItem(str(correct_factor)))
  244. output_model.appendRow(items)
  245. # 设置并展示输出数据表格
  246. ui.View.setTabText(1, '水准测段高差计算成果表')
  247. ui.reconTableView1.setModel(output_model)
  248. ui.reconTableView1.show()
  249. # 返回一个选择模型
  250. selectionModel = QItemSelectionModel(input_model) # Item选择模型
  251. ui.resultTableView1.setSelectionModel(selectionModel)
  252. return selectionModel
  253. # 关闭数据库连接
  254. cursor1.close()
  255. db1.close()
  256. # 隐藏 QLabel
  257. ui.default_remind1.hide()