Browse Source

Merge remote-tracking branch 'origin/master'

Mr.wzp 5 months ago
parent
commit
054d45e6a3
4 changed files with 1291 additions and 8 deletions
  1. 400
    2
      Back/GS/GS.py
  2. 547
    2
      Back/GS/GScompute.py
  3. 344
    2
      Back/WD/WD.py
  4. 0
    2
      Back/WD/WDcompute.py

+ 400
- 2
Back/GS/GS.py View File

@@ -1,2 +1,400 @@
1
-def main_function(file_path, db_path):
2
-    print("这是GS")
1
+import openpyxl
2
+import xlrd
3
+import sqlite3
4
+import os
5
+from openpyxl import Workbook
6
+import tkinter as tk
7
+from tkinter import messagebox
8
+import math
9
+import numpy as np
10
+
11
+def to_utf8(text):
12
+    str1 = text.encode('utf-8')
13
+    return str1
14
+
15
+# 弹窗提示用户是否更新数据
16
+def ask_for_update(file_name):
17
+    root = tk.Tk()
18
+    root.withdraw()  # 隐藏主窗口
19
+    response = messagebox.askyesno("提示", f"检测到数据库中存在相同文件名 '{file_name}',是否更新数据?")
20
+    return response
21
+
22
+# 读取Excel文件并计算公式结果
23
+def load_and_calculate_excel(file_path,cell0):
24
+    # 加载Excel文件并计算单元格的公式结果。
25
+    workbook = openpyxl.load_workbook(file_path, data_only=True)
26
+    sheet = workbook.active
27
+    h1_value = sheet[cell0].value
28
+    return h1_value
29
+
30
+# 数据库插入函数
31
+def insert_into_database(database,pastname,newname,excelname,listname1,listpastx1,listpasty1,listcgcs1,listnewx1,listnewy1,pjbc,fxzwc,zrbzwc,points,zbs,zfxs,sf,pjbcs,pjfxs):
32
+    #先把输入的录入数据库
33
+    db = sqlite3.connect(database)
34
+    #获取游标
35
+    cursor = db.cursor()
36
+    #字符类的都需要转换成字节存进去
37
+    utf_pan = to_utf8(pastname)
38
+    utf_nn = to_utf8(newname)
39
+    utf_tn = to_utf8(excelname)
40
+    try:
41
+        # 查询是否已存在相同的记录
42
+        cursor.execute(
43
+            "SELECT * FROM GS_Input_Param WHERE TableName = ?",
44
+            (utf_tn,)
45
+        )
46
+        existing_record = cursor.fetchone()
47
+
48
+        if existing_record:
49
+            # 弹窗询问用户是否更新数据
50
+            if not ask_for_update(excelname):
51
+                print("用户选择不更新数据")
52
+                return
53
+
54
+            # 更新现有记录GS_Input_Param 
55
+            cursor.execute(
56
+                """
57
+                UPDATE GS_Input_Param 
58
+                SET Last_ResultName=?,New_ResultName=?,Avg_SL=?,Ms_Dir=?,Ms_WSL=?,Pt_Count=?,SL_Count=?,Dir_Count=?,Scale_Value=?,Avg_MSL=?,Avg_Dir=?
59
+                WHERE TableName = ?
60
+                """,
61
+                (utf_pan,utf_nn,pjbc,fxzwc,zrbzwc,points,zbs,zfxs,sf,pjbcs,pjfxs,utf_tn,)
62
+            )
63
+            # 更新现有记录GS_Input_Point 
64
+            #删了已有的数据,重新插入
65
+            cursor.execute(
66
+                """
67
+                DELETE FROM GS_Input_Point WHERE TableName = ?
68
+                """,
69
+                (utf_tn,)
70
+            )
71
+            rr = 0
72
+            while rr < len(listname1):
73
+                rr1 = listname1[rr]
74
+                rr2 = listpastx1[rr]
75
+                rr3 = listpasty1[rr]
76
+                rr4 = listcgcs1[rr]
77
+                rr5 = listnewx1[rr]
78
+                rr6 = listnewy1[rr]
79
+                utf_rr1 = to_utf8(rr1)
80
+                cursor.execute(
81
+                    """
82
+                    INSERT INTO GS_Input_Point(TableName,Last_ResultName,New_ResultName,Last_X,Last_Y,New_X,New_Y,PointName,cgcs) VALUES (?,?,?,?,?,?,?,?,?)
83
+                    """,
84
+                    (utf_tn,utf_pan,utf_nn,rr2,rr3,rr5,rr6,utf_rr1,rr4,)
85
+                )
86
+                rr = rr + 1
87
+            messagebox.showinfo("提示",
88
+                                f"文件 '{excelname}' 已成功更新到本地数据库中,点击确认以关闭此对话框。对话框关闭后,请点击“计算”以重新计算数据")
89
+        else:
90
+            # 插入新记录GS_Input_Param 
91
+            cursor.execute(
92
+                """
93
+                INSERT INTO GS_Input_Param (TableName,Last_ResultName,New_ResultName,Avg_SL,Ms_Dir,Ms_WSL,Pt_Count,SL_Count,Dir_Count,Scale_Value,Avg_MSL,Avg_Dir) 
94
+                VALUES (?,?,?,?,?,?,?,?,?,?,?,?)
95
+                """,
96
+                (utf_tn,utf_pan,utf_nn,pjbc,fxzwc,zrbzwc,points,zbs,zfxs,sf,pjbcs,pjfxs,)
97
+            )
98
+            # 插入新记录GS_Input_Point 
99
+            rr = 0
100
+            while rr < len(listname1):
101
+                rr1 = listname1[rr]
102
+                rr2 = listpastx1[rr]
103
+                rr3 = listpasty1[rr]
104
+                rr4 = listcgcs1[rr]
105
+                rr5 = listnewx1[rr]
106
+                rr6 = listnewy1[rr]
107
+                utf_rr1 = to_utf8(rr1)
108
+                cursor.execute(
109
+                    """
110
+                    INSERT INTO GS_Input_Point(TableName,Last_ResultName,New_ResultName,Last_X,Last_Y,New_X,New_Y,PointName,cgcs) VALUES (?,?,?,?,?,?,?,?,?)
111
+                    """,
112
+                    (utf_tn,utf_pan,utf_nn,rr2,rr3,rr5,rr6,utf_rr1,rr4,)
113
+                )
114
+                rr = rr + 1
115
+            messagebox.showinfo("提示",
116
+                                f"文件 '{excelname}' 已成功添加到本地数据库中,点击确认以关闭此对话框。对话框关闭后,请点击“计算”以计算数据")
117
+
118
+        db.commit()
119
+    except sqlite3.Error as e:
120
+        print(f"插入或更新文件名时发生错误: {e}")
121
+    except Exception as e:
122
+        print(f"处理文件时发生错误: {e}")
123
+    finally:
124
+        db.close()
125
+
126
+#读取xls
127
+def xlrd_read(excelpath,dbpath):
128
+    global gszbx
129
+    global gszby
130
+    listname1 = []
131
+    listnewx1 = []
132
+    listnewy1 = []
133
+    listpastx1 = []
134
+    listpasty1 = []
135
+    listcgcs1 = []
136
+
137
+    #excel表名就是表名
138
+    excelname = os.path.basename(excelpath)
139
+    # 读取excel
140
+    xlr = xlrd.open_workbook(excelpath)
141
+    tabler = xlr.sheets()[0]
142
+    # 从第3行开始,3A为点号,3B为最新x,3C为最新y,3D为往期x
143
+    # 3E为往期y
144
+    # 先看点数
145
+    rows = tabler.nrows
146
+    row = 2
147
+    points = rows - 2
148
+    # 收集每一列的数据,方便后期计算
149
+    listname = []
150
+    listnewx = []
151
+    listnewy = []
152
+    listpastx = []
153
+    listpasty = []
154
+    listcgcs = []
155
+    sumnewx = 0
156
+    sumnewy = 0
157
+    sumpastx = 0
158
+    sumpasty = 0
159
+    # 记录下最早的那几个开头
160
+    # excelpath是输入表格,outpath是输出路径,pjbc是平均边长
161
+    # fxzwc是方向中误差,zrbzwc是最弱边边长相对中误差,pjbcs是平均边数,pjfxs是平均方向数,sf是缩放值
162
+    # 新增总边数zbs,总方向数zfxs
163
+    # 先计算位移判断值
164
+    pjbc = float(tabler.cell(0, 6).value)
165
+    fxzwc = float(tabler.cell(1, 6).value)
166
+    str1 = str(tabler.cell(2, 6).value)
167
+    #判断下是哪种情况,转化为数值
168
+    if '.' in str1:
169
+        #直接float使用
170
+        zrbzwc = float(str1)
171
+    else:
172
+        #转化为分数
173
+        # 10的6次方
174
+        # ten_to_the_six = 10e6
175
+        fzstr = float(str1.split('/',-1)[0])
176
+        fmstr = float(str1.split('/',-1)[1])
177
+        zrbzwc = float(fzstr/fmstr)
178
+    zbs = float(tabler.cell(3, 6).value)
179
+    zfxs = float(tabler.cell(4, 6).value)
180
+    pjbcs = zbs / points
181
+    pjfxs = zfxs / points
182
+    sf = float(tabler.cell(5,6).value)
183
+    # 再拆细点
184
+    wy1 = pjbc / 1000
185
+    wy2 = wy1 * zrbzwc * 1e6
186
+    wypd1 = wy2 * wy2 / pjbcs
187
+    # 206.265是常数系数
188
+    wy3 = pjbc * fxzwc / 206.265
189
+    wypd2 = wy3 * wy3 / pjfxs
190
+    wypd3 = math.sqrt(wypd1 + wypd2)
191
+    wypd = round(wypd3 * 3, 4)
192
+    wypd0 = wypd
193
+    pastname = tabler.cell(0, 3).value
194
+    newname = tabler.cell(0, 1).value
195
+    #如果第二次测量或者首次测量为空,则判断为新建
196
+    while row < rows:
197
+        pname = tabler.cell(row, 0).value
198
+        pcgcs = 1
199
+        try:
200
+            pnewx = round(float(tabler.cell(row, 1).value),4)
201
+        except:
202
+            pnewx = 0
203
+            pcgcs = -2
204
+        try:
205
+            pnewy = round(float(tabler.cell(row, 2).value),4)
206
+        except:
207
+            pnewy = 0
208
+            pcgcs = -2
209
+        try:
210
+            ppastx = round(float(tabler.cell(row, 3).value),4)
211
+        except:
212
+            ppastx = 0
213
+            pcgcs = -2
214
+        try:
215
+            ppasty = round(float(tabler.cell(row, 4).value),4)
216
+        except:
217
+            ppasty = 0
218
+            pcgcs = -2
219
+        sumpastx = sumpastx + ppastx
220
+        sumnewy = sumnewy + pnewy
221
+        sumnewx = sumnewx + pnewx
222
+        sumpasty = sumpasty + ppasty
223
+        listname1.append(pname)
224
+        listnewx1.append(pnewx)
225
+        listnewy1.append(pnewy)
226
+        listpastx1.append(ppastx)
227
+        listpasty1.append(ppasty)
228
+        listcgcs1.append(pcgcs)
229
+        if pcgcs == -2:
230
+            points = points - 1
231
+        row = row + 1
232
+    #插入数据库
233
+    insert_into_database(dbpath,pastname,newname,excelname,listname1,listpastx1,listpasty1,listcgcs1,listnewx1,listnewy1,pjbc,fxzwc,zrbzwc,points,zbs,zfxs,sf,pjbcs,pjfxs)
234
+    #新建点不参与运算
235
+    rr=0
236
+    while rr < len(listname1):
237
+        rr1 = listname1[rr]
238
+        rr2 = listpastx1[rr]
239
+        rr3 = listpasty1[rr]
240
+        rr4 = listcgcs1[rr]
241
+        rr5 = listnewx1[rr]
242
+        rr6 = listnewy1[rr]
243
+        if rr4 == -2:
244
+            rr = rr + 1
245
+        else:
246
+            listname.append(rr1)
247
+            listpastx.append(rr2)
248
+            listpasty.append(rr3)
249
+            listcgcs.append(rr4)
250
+            listnewx.append(rr5)
251
+            listnewy.append(rr6)
252
+            rr = rr + 1
253
+
254
+#读取xlsx
255
+def openpyxl_read(excelpath,dbpath):
256
+    global gszbx
257
+    global gszby
258
+    listname1 = []
259
+    listnewx1 = []
260
+    listnewy1 = []
261
+    listpastx1 = []
262
+    listpasty1 = []
263
+    listcgcs1 = []
264
+
265
+    #excel表名就是表名
266
+    excelname = os.path.basename(excelpath)
267
+    # 读取excel
268
+    xlr = openpyxl.load_workbook(excelpath)
269
+    tabler = xlr.worksheets[0]
270
+    # 从第3行开始,3A为点号,3B为最新x,3C为最新y,3D为往期x
271
+    # 3E为往期y
272
+    # 先看点数
273
+    rows = tabler.max_row
274
+    row = 3
275
+    points = rows - 2
276
+    # 收集每一列的数据,方便后期计算
277
+    listname = []
278
+    listnewx = []
279
+    listnewy = []
280
+    listpastx = []
281
+    listpasty = []
282
+    listcgcs = []
283
+    sumnewx = 0
284
+    sumnewy = 0
285
+    sumpastx = 0
286
+    sumpasty = 0
287
+    # 记录下最早的那几个开头
288
+    # excelpath是输入表格,outpath是输出路径,pjbc是平均边长
289
+    # fxzwc是方向中误差,zrbzwc是最弱边边长相对中误差,pjbcs是平均边数,pjfxs是平均方向数,sf是缩放值
290
+    # 新增总边数zbs,总方向数zfxs
291
+    # 先计算位移判断值
292
+    pjbc = float(tabler['G1'].value)
293
+    fxzwc = float(tabler['G2'].value)
294
+    str1 = str(tabler['G3'].value)
295
+    #判断下是哪种情况,转化为数值
296
+    if '.' in str1:
297
+        #直接float使用
298
+        zrbzwc = float(str1)
299
+    else:
300
+        #转化为分数
301
+        # 10的6次方
302
+        # ten_to_the_six = 10e6
303
+        fzstr = float(str1.split('/',-1)[0])
304
+        fmstr = float(str1.split('/',-1)[1])
305
+        zrbzwc = float(fzstr/fmstr)
306
+    try:
307
+        zbs = float(tabler['G4'].value)
308
+    except:
309
+        zbs = load_and_calculate_excel(excelpath,'G4')
310
+    try:
311
+        zfxs = float(tabler['G5'].value)
312
+    except:
313
+        zfxs = load_and_calculate_excel(excelpath,'G5')
314
+    pjbcs = zbs / points
315
+    pjfxs = zfxs / points
316
+    sf = float(tabler['G6'].value)
317
+    # 再拆细点
318
+    wy1 = pjbc / 1000
319
+    wy2 = wy1 * zrbzwc * 1e6
320
+    wypd1 = wy2 * wy2 / pjbcs
321
+    # 206.265是常数系数
322
+    wy3 = pjbc * fxzwc / 206.265
323
+    wypd2 = wy3 * wy3 / pjfxs
324
+    wypd3 = math.sqrt(wypd1 + wypd2)
325
+    wypd = round(wypd3 * 3, 4)
326
+    wypd0 = wypd
327
+    pastname = tabler['D1'].value
328
+    newname = tabler['B1'].value
329
+    #如果第二次测量或者首次测量为空,则判断为新建
330
+    while row <= rows:
331
+        pname = tabler.cell(row, 1).value
332
+        pcgcs = 1
333
+        try:
334
+            pnewx = round(float(tabler.cell(row, 2).value),4)
335
+        except:
336
+            pnewx = 0
337
+            pcgcs = -2
338
+        try:
339
+            pnewy = round(float(tabler.cell(row, 3).value),4)
340
+        except:
341
+            pnewy = 0
342
+            pcgcs = -2
343
+        try:
344
+            ppastx = round(float(tabler.cell(row, 4).value),4)
345
+        except:
346
+            ppastx = 0
347
+            pcgcs = -2
348
+        try:
349
+            ppasty = round(float(tabler.cell(row, 5).value),4)
350
+        except:
351
+            ppasty = 0
352
+            pcgcs = -2
353
+        sumpastx = sumpastx + ppastx
354
+        sumnewy = sumnewy + pnewy
355
+        sumnewx = sumnewx + pnewx
356
+        sumpasty = sumpasty + ppasty
357
+        listname1.append(pname)
358
+        listnewx1.append(pnewx)
359
+        listnewy1.append(pnewy)
360
+        listpastx1.append(ppastx)
361
+        listpasty1.append(ppasty)
362
+        listcgcs1.append(pcgcs)
363
+        if pcgcs == -2:
364
+            points = points - 1
365
+        row = row + 1
366
+    #插入数据库
367
+    insert_into_database(dbpath,pastname,newname,excelname,listname1,listpastx1,listpasty1,listcgcs1,listnewx1,listnewy1,pjbc,fxzwc,zrbzwc,points,zbs,zfxs,sf,pjbcs,pjfxs)
368
+    #新建点不参与运算
369
+    rr=0
370
+    while rr < len(listname1):
371
+        rr1 = listname1[rr]
372
+        rr2 = listpastx1[rr]
373
+        rr3 = listpasty1[rr]
374
+        rr4 = listcgcs1[rr]
375
+        rr5 = listnewx1[rr]
376
+        rr6 = listnewy1[rr]
377
+        if rr4 == -2:
378
+            rr = rr + 1
379
+        else:
380
+            listname.append(rr1)
381
+            listpastx.append(rr2)
382
+            listpasty.append(rr3)
383
+            listcgcs.append(rr4)
384
+            listnewx.append(rr5)
385
+            listnewy.append(rr6)
386
+            rr = rr + 1
387
+
388
+# 主函数 读取excel文件
389
+def main_function(file_path,dbpath):
390
+    # 调用读取Excel文件的函数
391
+    file_name = os.path.basename(file_path)
392
+    #两种加载方式,对于不同的文件
393
+    if ".xlsx" in file_path:
394
+        #采用openpyxl
395
+        openpyxl_read(file_path,dbpath)
396
+    else:
397
+        #采用xlrd
398
+        xlrd_read(file_path,dbpath)
399
+    
400
+    

+ 547
- 2
Back/GS/GScompute.py View File

@@ -1,2 +1,547 @@
1
-def main_function(file_path, db_path):
2
-    print("GS")
1
+import sqlite3
2
+import os
3
+import tkinter as tk
4
+from tkinter import messagebox
5
+import math
6
+import numpy as np
7
+
8
+#region 各种方法
9
+
10
+def to_utf8(text):
11
+    str1 = text.encode('utf-8')
12
+    return str1
13
+
14
+def sfjs(gsx,listx,gsy,listy):
15
+    s1 = gsx[len(gsx) - 1] - gsx[0]
16
+    s2 = s1 * s1
17
+    s3 = gsy[len(gsy) - 1] - gsy[0]
18
+    s4 = s3 * s3
19
+    s5 = s2 + s4
20
+    s6 = math.sqrt(s5)
21
+    t1 = listx[len(listx) - 1] - listx[0]
22
+    t2 = t1 * t1
23
+    t3 = listy[len(listy) - 1] - listy[0]
24
+    t4 = t3 * t3
25
+    t5 = t2 + t4
26
+    t6 = math.sqrt(t5)
27
+    num1 = round(s6/t6,8)
28
+    return num1
29
+
30
+def mxjd(gs,nw):
31
+    ii = 0
32
+    sum1 = 0
33
+    while ii < len(gs):
34
+        s1 = gs[ii] - nw[ii]
35
+        s2 = s1 * s1
36
+        sum1 = sum1 + s2
37
+        ii = ii + 1
38
+    s3 = sum1 / 2 / len(gs)
39
+    s4 = math.sqrt(s3)
40
+    num1 = s4 * 1000
41
+    return num1
42
+
43
+def xzjs(gsx,listx,gsy,listy):
44
+    s1 = gsx[len(gsx) - 1] - gsx[0]
45
+    s2 = gsy[len(gsy) - 1] - gsy[0]
46
+    s3 = s2 / s1
47
+    s4 = math.atan(s3)
48
+    t1 = listx[len(listx) - 1] - listx[0]
49
+    t2 = listy[len(listy) - 1] - listy[0]
50
+    t3 = t2 / t1
51
+    t4 = math.atan(t3)
52
+    n1 = s4 - t4
53
+    num1 = n1 * 180 / math.pi * 3600
54
+    return num1
55
+
56
+def gsjs(x,y,nlist):
57
+    listgsx = []
58
+    xstr1 = nlist[0] * x
59
+    xstr2 = nlist[1] * y
60
+    xx = xstr1 + xstr2 + nlist[2]
61
+    ystr1 = nlist[3] * x
62
+    ystr2 = nlist[4] * y
63
+    yy = ystr1 + ystr2 + nlist[5]
64
+    listgsx.append(xx)
65
+    listgsx.append(yy)
66
+    return listgsx
67
+
68
+def jzys1(listy, zxzby, listx, zxzbx, sf):
69
+    rlist = []
70
+    listlen = len(listy)
71
+    ll = 0
72
+    while ll < listlen:
73
+        # 第一个的值
74
+        # num1 = round(((listx[ll] - zxzbx) / sf),0)
75
+        # num2 = round(((listy[ll] - zxzby) / sf),0)
76
+        num1 = (listx[ll] - zxzbx)
77
+        num2 = (listy[ll] - zxzby)
78
+        rlist.append(num1)
79
+        rlist.append(num2)
80
+        ll = ll + 1
81
+    return rlist
82
+
83
+def jzys2(listy, zxzby, listx, zxzbx, sf):
84
+    rlist = []
85
+    listlen = len(listy)
86
+    ll = 0
87
+    while ll < listlen:
88
+        # 第一个的值
89
+        num2 = (-1) * (listx[ll] - zxzbx) / sf
90
+        num1 = (listy[ll] - zxzby) / sf
91
+        rlist.append(num1)
92
+        rlist.append(num2)
93
+        ll = ll + 1
94
+    return rlist
95
+
96
+def jzys3(listy, aa, bb):
97
+    rlist = []
98
+    listlen = len(listy)
99
+    ll = 0
100
+    while ll < listlen:
101
+        # 第一个的值
102
+        num1 = aa
103
+        num2 = bb
104
+        rlist.append(num1)
105
+        rlist.append(num2)
106
+        ll = ll + 1
107
+    return rlist
108
+
109
+def jzys4(listpasty, zxzbpasty, listpastx, zxzbpastx, listnewy, zxzbnewy, listnewx, zxzbnewx, sf):
110
+    rlist = []
111
+    listlen = len(listnewx)
112
+    ll = 0
113
+    while ll < listlen:
114
+        num1 = (listpastx[ll] - listnewx[ll] - zxzbpastx + zxzbnewx) / sf
115
+        num2 = (listpasty[ll] - listnewy[ll] - zxzbpasty + zxzbnewy) / sf
116
+        rlist.append(round(num1,6))
117
+        rlist.append(round(num2,6))
118
+        ll = ll + 1
119
+    return rlist
120
+
121
+def jzys5(listp, zxzbp, sf):
122
+    rlist = []
123
+    listlen = len(listp)
124
+    ll = 0
125
+    while ll < listlen:
126
+        num1 = (listp[ll] - zxzbp) / sf
127
+        rlist.append(num1)
128
+        ll = ll + 1
129
+    return rlist
130
+
131
+def jzys6(listp, num):
132
+    rlist = []
133
+    listlen = len(listp)
134
+    ll = 0
135
+    while ll < listlen:
136
+        num1 = listp[ll] * num
137
+        rlist.append(num1)
138
+        ll = ll + 1
139
+    return rlist
140
+
141
+def cjh(listp):
142
+    rp = 0
143
+    listlen = len(listp)
144
+    ll = 0
145
+    while ll < listlen:
146
+        num1 = listp[ll] * listp[ll]
147
+        rp = rp + num1
148
+        ll = ll + 1
149
+    return rp
150
+
151
+def cjh2(lista, listb):
152
+    rp = 0
153
+    listlen = len(lista)
154
+    ll = 0
155
+    while ll < listlen:
156
+        num1 = lista[ll] * listb[ll]
157
+        rp = rp + num1
158
+        ll = ll + 1
159
+    return rp
160
+
161
+def gsys(listnewp, jxlist1, jylist1, lxlist, lylist, arrz, sf, zxzbnewp, zxzbpastp, ii):
162
+    # 新x+(矩阵[jx1 jy1 lx1 ly1]*矩阵z)*缩放-新重心坐标x+旧重心坐标x
163
+    rlist = []
164
+    listlen = len(listnewp)
165
+    ll = 0
166
+    while ll < listlen:
167
+        arr0 = np.array((jxlist1[ll], jylist1[ll],
168
+                        lxlist[2*ll+ii], lylist[2*ll+ii]))
169
+        arr1 = np.matmul(arr0, arrz)
170
+        arr3 = sf * arr1
171
+        newp = listnewp[ll] + arr3 - zxzbnewp + zxzbpastp
172
+        rlist.append(newp)
173
+        ll = ll + 1
174
+    return rlist
175
+
176
+def xcys(newlist, pastlist):
177
+    listlen = len(newlist)
178
+    ll = 0
179
+    rlist = []
180
+    while ll < listlen:
181
+        num1 =pastlist[ll] - newlist[ll]
182
+        num2 = num1 * 1000
183
+        rlist.append(num2)
184
+        ll = ll + 1
185
+    return rlist
186
+
187
+def takeFirst(elem):
188
+        return elem[0]
189
+
190
+#endregion
191
+
192
+def insert_into_database1(database,utf_tn,listname1,listname,gsx,gsy,listpastx1,listpasty1,listnewx1,listnewy1,nlist,utf_pan,utf_nn,wypd,sfxs,xzj,pycsx,pycsy,mxjdx,mxjdy,zxzbpastx,zxzbpasty,zxzbnewx,zxzbnewy,n1,n2,n3,n4,n5,n6):
193
+    #将结果输出到数据库
194
+    db1 = sqlite3.connect(database)
195
+    #获取游标
196
+    cursor1 = db1.cursor()
197
+    #先清除已有数据,用来更新
198
+    try:
199
+        sqlstr3 = 'delete from GS_Trans_Param WHERE TableName = ?'
200
+        sqlstr4 = 'delete from GS_Trans_Point WHERE TableName = ?'
201
+        sqlstr5 = 'delete from GS_Result_Point WHERE TableName = ?'
202
+        cursor1.execute(sqlstr3,(utf_tn,))
203
+        cursor1.execute(sqlstr4,(utf_tn,))
204
+        cursor1.execute(sqlstr5,(utf_tn,))
205
+    except:
206
+        pass
207
+    cursor1.execute('INSERT INTO GS_Trans_Param(TableName,Last_ResultName,New_ResultName,Dis_RefValue,Pt_CalCount,Scale_Factor,Rotate_Angle,Trans_X,Trans_Y,Model_AccX,Model_AccY,Last_GcX,Last_GcY,New_GcX,New_GcY,Formula_X1,Formula_X2,Formula_X3,Formula_Y1,Formula_Y2,Formula_Y3) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',(utf_tn,utf_pan,utf_nn,wypd,len(listname),sfxs,xzj,pycsx,pycsy,mxjdx,mxjdy,zxzbpastx,zxzbpasty,zxzbnewx,zxzbnewy,n1,n2,n3,n4,n5,n6,))
208
+    #Trans_Point和Result_Point一起存
209
+    for iname in listname1:
210
+        if iname in listname:
211
+            #属于没问题点的
212
+            #直接使用gsx,gsy
213
+            utf_pointname = to_utf8(str(iname))
214
+            wystr = to_utf8('稳定')
215
+            index1 = listname.index(iname)
216
+            numm1 = round(gsx[index1],4)
217
+            numm2 = round(gsy[index1],4)
218
+            #先找到首次的index
219
+            index2 = listname1.index(iname)
220
+            r1 = (listpastx1[index2] - gsx[index1])*1000
221
+            r2 = (listpasty1[index2] - gsy[index1])*1000
222
+            r3 = r1 * r1
223
+            r4 = r2 * r2
224
+            r5 = r3 + r4
225
+            r6 = round(math.sqrt(r5),1)
226
+            numn1 = listpastx1[index2]
227
+            numn2 = listnewx1[index2]
228
+            cursor1.execute('INSERT INTO GS_Trans_Point(TableName,Last_ResultName,New_ResultName,PointName,Last_X,Last_Y,New_X,New_Y) VALUES (?,?,?,?,?,?,?,?)',(utf_tn,utf_pan,utf_nn,utf_pointname,listpastx1[index2],listpasty1[index2],listnewx1[index2],listnewy1[index2],))
229
+            cursor1.execute('INSERT INTO GS_Result_Point(TableName,Last_ResultName,New_ResultName,PointName,Last_X,Last_Y,Result_X,Result_Y,Cal_X,Cal_Y,Last_ResultX,Last_ResultY,Last_ResultP,Last_CalX,Last_CalY,Last_CalP,Dis_Ass) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',(utf_tn,utf_pan,utf_nn,utf_pointname,listpastx1[index2],listpasty1[index2],listpastx1[index2],listpasty1[index2],numm1,numm2,0,0,0,r1,r2,r6,wystr,))
230
+        else:
231
+            index2 = listname1.index(iname)
232
+            utf_pointname = to_utf8(str(iname))
233
+            #首先判断有没有第一个点
234
+            if listnewx1[index2] != 0:
235
+                #有问题的点,使用公式跑
236
+                listxy = gsjs(listnewx1[index2],listnewy1[index2],nlist)   
237
+                #判断有没有第一次的数据,没有就不写
238
+                if listpastx1[index2] != 0:
239
+                    r1 = (listpastx1[index2] - listxy[0])*1000
240
+                    r2 = (listpasty1[index2] - listxy[1])*1000
241
+                    r3 = r1 * r1
242
+                    r4 = r2 * r2
243
+                    r5 = r3 + r4
244
+                    r6 = round(math.sqrt(r5),1)
245
+                    if r6 > 500:
246
+                        wystr = to_utf8('复建')
247
+                        cursor1.execute('INSERT INTO GS_Result_Point(TableName,Last_ResultName,New_ResultName,PointName,Last_X,Last_Y,Result_X,Result_Y,Cal_X,Cal_Y,Last_ResultX,Last_ResultY,Last_ResultP,Last_CalX,Last_CalY,Last_CalP,Dis_Ass) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',(utf_tn,utf_pan,utf_nn,utf_pointname,listpastx1[index2],listpasty1[index2],listxy[0],listxy[1],listxy[0],listxy[1],r1,r2,r6,r1,r2,r6,wystr,))
248
+                    else:
249
+                        wystr = to_utf8('位移')
250
+                        cursor1.execute('INSERT INTO GS_Result_Point(TableName,Last_ResultName,New_ResultName,PointName,Last_X,Last_Y,Result_X,Result_Y,Cal_X,Cal_Y,Last_ResultX,Last_ResultY,Last_ResultP,Last_CalX,Last_CalY,Last_CalP,Dis_Ass) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',(utf_tn,utf_pan,utf_nn,utf_pointname,listpastx1[index2],listpasty1[index2],listxy[0],listxy[1],listxy[0],listxy[1],r1,r2,r6,r1,r2,r6,wystr,))
251
+                else:
252
+                    wystr = to_utf8('新建')
253
+                    cursor1.execute('INSERT INTO GS_Result_Point(TableName,Last_ResultName,New_ResultName,PointName,Last_X,Last_Y,Result_X,Result_Y,Cal_X,Cal_Y,Last_ResultX,Last_ResultY,Last_ResultP,Last_CalX,Last_CalY,Last_CalP,Dis_Ass) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',(utf_tn,utf_pan,utf_nn,utf_pointname,listpastx1[index2],listpasty1[index2],listnewx1[index2],listnewy1[index2],listpastx1[index2],listpasty1[index2],0,0,0,0,0,0,wystr,))
254
+    #数据库执行
255
+    db1.commit()
256
+    #做完一切后,先关闭游标,再关闭数据库
257
+    cursor1.close()
258
+    db1.close()
259
+
260
+def tablein(outpath,str1):
261
+    listcgcs1 = []
262
+    listname1 = []
263
+    listpastx1 = []
264
+    listpasty1 = []
265
+    listname = []
266
+    listnewx = []
267
+    listnewy = []
268
+    listpastx = []
269
+    listpasty = []
270
+    listcgcs = []
271
+    listnewx1 = []
272
+    listnewy1 = []
273
+    points = 0
274
+    #查询,提取需要的数据
275
+    db2 = sqlite3.connect(outpath)
276
+    cursor2 = db2.cursor()
277
+    utfstr1 = to_utf8(str1)
278
+    sqlstr1 = 'SELECT * FROM GS_Input_Point WHERE TableName = ?'
279
+    cursor2.execute(sqlstr1,(utfstr1,))
280
+    all_da = cursor2.fetchall()
281
+    for da in all_da:
282
+        listpastx.append(da[3])
283
+        listpastx1.append(da[3])
284
+        listpasty.append(da[4])
285
+        listpasty1.append(da[4])
286
+        listnewx.append(da[5])
287
+        listnewx1.append(da[5])
288
+        listnewy.append(da[6])
289
+        listnewy1.append(da[6])
290
+        listname.append(da[7].decode('utf-8'))
291
+        listname1.append(da[7].decode('utf-8'))
292
+        listcgcs.append(da[8])
293
+        listcgcs1.append(da[8])
294
+        points = points + 1
295
+    sqlstr2 = 'SELECT * FROM GS_Input_Param WHERE TableName = ?'
296
+    cursor2.execute(sqlstr2,(utfstr1,))
297
+    all_par = cursor2.fetchall()
298
+    pastname = all_par[0][1].decode('utf-8')
299
+    newname = all_par[0][2].decode('utf-8')
300
+    # pjbc是平均边长
301
+    # fxzwc是方向中误差,zrbzwc是最弱边边长相对中误差,pjbcs是平均边数,pjfxs是平均方向数,sf是缩放值
302
+    # 新增总边数zbs,总方向数zfxs
303
+    # 先计算位移判断值
304
+    pjbc = all_par[0][3]
305
+    fxzwc = all_par[0][4]
306
+    zrbzwc = all_par[0][5]
307
+    zbs = all_par[0][7]
308
+    zfxs = all_par[0][8]
309
+    sf = all_par[0][9]
310
+    pjbcs = zbs / points
311
+    pjfxs = zfxs / points
312
+    # 再拆细点
313
+    wy1 = pjbc / 1000
314
+    wy2 = wy1 * zrbzwc * 1e6
315
+    wypd1 = wy2 * wy2 / pjbcs
316
+    # 206.265是常数系数
317
+    wy3 = pjbc * fxzwc / 206.265
318
+    wypd2 = wy3 * wy3 / pjfxs
319
+    wypd3 = math.sqrt(wypd1 + wypd2)
320
+    wypd = round(wypd3 * 3, 4)
321
+    wypd0 = wypd
322
+    #更新下数据库(参数部分)
323
+    sqlstr3 = 'update GS_Input_Param set Pt_Count=?,Avg_MSL=?,Avg_Dir=? WHERE TableName = ?'
324
+    cursor2.execute(sqlstr3,(points,pjbcs,pjfxs,utfstr1,))
325
+    #数据库执行
326
+    db2.commit()
327
+    #做完一切后,先关闭游标,再关闭数据库
328
+    cursor2.close()
329
+    db2.close()
330
+    js = 0
331
+    return listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx,listpasty, points, listcgcs,sf, newname, pastname, js,listnewx1,listnewy1
332
+
333
+def bhjs(dbpath,listcgcs1, listname1, listpastx1, listpasty1, wypd, listname, listnewx, listnewy, listpastx, listpasty, points, listcgcs,  sf, newname, pastname, js,listnewx1,listnewy1,excelname):
334
+    np.set_printoptions(suppress=False)
335
+    # pt用于给点数point计数
336
+    # point会随着回递函数而减少
337
+    pt = 0
338
+    sumnewx = 0
339
+    sumnewy = 0
340
+    sumpastx = 0
341
+    sumpasty = 0
342
+    gszbx = []
343
+    gszby = []
344
+    arrz = []
345
+    # #一个计数,把第一次改算坐标全部记下来
346
+    # 存的第一次的改算值和起限差
347
+    jslist = []
348
+    # 等同于listnewx/y1
349
+    jslist1 = []
350
+    # listnewx/y,listpastx/y,listcgcs都是要变的
351
+    # 带1的是原始的
352
+    while pt < points:
353
+        sumnewx = sumnewx + listnewx[pt]
354
+        sumnewy = sumnewy + listnewy[pt]
355
+        sumpastx = sumpastx + listpastx[pt]
356
+        sumpasty = sumpasty + listpasty[pt]
357
+        pt = pt + 1
358
+    # 计算4个重心坐标(最新一期和上一期的)
359
+    zxzbnewx = (sumnewx / points)
360
+    zxzbnewy = (sumnewy / points)
361
+    zxzbpastx = (sumpastx / points)
362
+    zxzbpasty = (sumpasty / points)
363
+    # 先计算平移参数
364
+    # pycsx = abs(zxzbnewx - zxzbpastx) * 1000
365
+    # pycsy = abs(zxzbnewy - zxzbpasty) * 1000
366
+    pycsx = round((zxzbpastx - zxzbnewx),4)
367
+    pycsy = round((zxzbpasty - zxzbnewy),4)
368
+    # 分别得k,sita的值
369
+    klist = jzys1(listnewy, zxzbnewy, listnewx, zxzbnewx, sf)
370
+    slist = jzys2(listnewy, zxzbnewy, listnewx, zxzbnewx, sf)
371
+    # 得dx,dy
372
+    dxlist = jzys3(listnewy, 1, 0)
373
+    dylist = jzys3(listnewy, 0, 1)
374
+    # 矩阵太难用了,还是手动计算
375
+    # 分别计算k、s、dx、dy的乘积和
376
+    k2 = cjh(klist)
377
+    s2 = cjh(slist)
378
+    dx2 = cjh(dxlist)
379
+    dy2 = cjh(dylist)
380
+    # 这里再创建矩阵1
381
+    arr1 = np.array(((k2, 0, 0, 0), (0, s2, 0, 0),
382
+                    (0, 0, dx2, 0), (0, 0, 0, dy2)))
383
+    # 矩阵1的逆矩阵矩阵2
384
+    arr2 = np.linalg.inv(arr1)
385
+    # 求矩阵l
386
+    llist = jzys4(listpasty, zxzbpasty, listpastx, zxzbpastx,
387
+                    listnewy, zxzbnewy, listnewx, zxzbnewx, sf)
388
+    # 得到数列e1,e2,e3,e4
389
+    e1 = cjh2(klist, llist)
390
+    e2 = cjh2(slist, llist)
391
+    e3 = cjh2(dxlist, llist)
392
+    e4 = cjh2(dylist, llist)
393
+    arrl = np.array(((e1), (e2), (e3), (e4)))
394
+    # 得到矩阵z
395
+    arrz = np.matmul(arr2, arrl)
396
+    # 求转换矩阵
397
+    jxlist1 = jzys5(listnewx, zxzbnewx, sf)
398
+    jylist1 = jzys5(listnewy, zxzbnewy, sf)
399
+    jxlist2 = jylist1
400
+    # jylist2 = jxlist1 * (-1)
401
+    jylist2 = jzys6(jxlist1, -1)
402
+    lxlist = jzys3(jylist1, 1, 0)
403
+    lylist = jzys3(jylist1, 0, 1)
404
+    # 求改算坐标
405
+    gsx = gsys(listnewx, jxlist1, jylist1, lxlist,
406
+                lylist, arrz, sf, zxzbnewx, zxzbpastx, 0)
407
+    gsy = gsys(listnewy, jxlist2, jylist2, lxlist,
408
+                lylist, arrz, sf, zxzbnewy, zxzbpasty, 1)
409
+    #缩放系数也是计算出来的sfxs
410
+    sfxs = sfjs(gsx,listnewx,gsy,listnewy)
411
+    #旋转角,模型精度
412
+    xzj = xzjs(gsx,listnewx,gsy,listnewy)
413
+    mxjdx = mxjd(gsx,listpastx)
414
+    mxjdy = mxjd(gsy,listpasty)
415
+    # 还是要先求较差
416
+    xcx = xcys(gsx, listpastx)
417
+    xcy = xcys(gsy, listpasty)
418
+    # 这里记录下第一次所有点的改算坐标
419
+    if js == 0:
420
+        lengs = len(gsx)
421
+        xx = 0
422
+        while xx < lengs:
423
+            gszbx.append(gsx[xx])
424
+            gszby.append(gsy[xx])
425
+            zblist1 = []
426
+            zblist1.append(gsx[xx])
427
+            zblist1.append(gsy[xx])
428
+            zblist1.append(xcx[xx])
429
+            zblist1.append(xcy[xx])
430
+            jslist.append(zblist1)
431
+            zblist2 = []
432
+            zblist2.append(listnewx[xx])
433
+            zblist2.append(listnewy[xx])
434
+            jslist1.append(zblist2)
435
+            xx = xx + 1
436
+        # 后面不需要经过这个if
437
+    # 判定方式是用差值平方和和位移对比
438
+    gxpd = 0
439
+    lenxc = len(xcx)
440
+    yy = 0
441
+    while yy < lenxc:
442
+        sumxcx = xcx[yy] * xcx[yy]
443
+        sumxcy = xcy[yy] * xcy[yy]
444
+        sumxc = sumxcx + sumxcy
445
+        xcpd = math.sqrt(sumxc)
446
+        if xcpd > wypd:
447
+            gxpd = -1
448
+            break
449
+        yy = yy + 1
450
+    if gxpd == 0:
451
+        # 输出之前把转换参数都算出来
452
+        # X=(z1+1)*x+z2*y+(旧重心坐标x-新重心坐标x-新重心坐标x*z1-新重心坐标y*z2+z3)
453
+        # Y=(-z2)*x+(z1+1)*y+(z1*新重心坐标y+新重心坐标x*z2+z4+旧重心坐标y-新重心坐标y)
454
+        n1 = float(arrz[0]) + 1
455
+        n2 = float(arrz[1])
456
+        s1 = zxzbnewx * float(arrz[0])
457
+        s2 = zxzbnewy * float(arrz[1])
458
+        n3 = zxzbpastx - zxzbnewx - s1 - s2 + float(arrz[2])
459
+        n4 = (-1) * float(arrz[1])
460
+        n5 = n1
461
+        s3 = (-1)*float(arrz[0])*zxzbnewy
462
+        s4 = float(arrz[1])*zxzbnewx
463
+        n6 = s3 + s4 + float(arrz[3])+zxzbpasty-zxzbnewy
464
+        sxylist = []
465
+        sxylist.append(n1)
466
+        sxylist.append(n2)
467
+        sxylist.append(n3)
468
+        sxylist.append(n4)
469
+        sxylist.append(n5)
470
+        sxylist.append(n6)
471
+        # 输出
472
+        relist1 = []
473
+        relist1.append(listname)
474
+        relist1.append(xcx)
475
+        relist1.append(xcy)
476
+        relist1.append(listcgcs)
477
+        relist1.append(gszbx)
478
+        relist1.append(gszby)
479
+        relist1.append(sxylist)
480
+        print(" Finish!")
481
+        # 输出的那个不是改算坐标,而是有计算的改算坐标
482
+        newgsx = []
483
+        newgsy = []
484
+        lengs1 = len(gszbx)
485
+        nlist = relist1[6]
486
+        # return relist
487
+        #中文再来一次
488
+        utf_pan = to_utf8(pastname)
489
+        utf_nn = to_utf8(newname)
490
+        utf_tn = to_utf8(excelname)
491
+        insert_into_database1(dbpath,utf_tn,listname1,listname,gsx,gsy,listpastx1,listpasty1,listnewx1,listnewy1,nlist,utf_pan,utf_nn,wypd,sfxs,xzj,pycsx,pycsy,mxjdx,mxjdy,zxzbpastx,zxzbpasty,zxzbnewx,zxzbnewy,n1,n2,n3,n4,n5,n6)
492
+
493
+    else:           
494
+        # 先把所有的合在一起,方便删除
495
+        lenlist1 = len(xcx)
496
+        ii = 0
497
+        relist1 = []
498
+        while ii < lenlist1:
499
+            smlist1 = []
500
+            nn2 = xcx[ii] * xcx[ii]
501
+            mm2 = xcy[ii] * xcy[ii]
502
+            nm2 = math.sqrt(nn2 + mm2)
503
+            smlist1.append(nm2)
504
+            smlist1.append(listname[ii])
505
+            smlist1.append(listnewx[ii])
506
+            smlist1.append(listnewy[ii])
507
+            smlist1.append(listpastx[ii])
508
+            smlist1.append(listpasty[ii])
509
+            relist1.append(smlist1)
510
+            ii = ii + 1
511
+        # 直接删除最大的那个
512
+        relist1.sort(key=takeFirst, reverse=True)
513
+        num1 = relist1[0]
514
+        # 获取name
515
+        num2 = num1[1]
516
+        ii2 = 0
517
+        mm2 = 0
518
+        while ii2 < lenlist1:
519
+            if listname[ii2] == num2:
520
+                del listname[ii2]
521
+                del listnewx[ii2]
522
+                del listnewy[ii2]
523
+                del listpastx[ii2]
524
+                del listpasty[ii2]
525
+                points = points - 1
526
+                break
527
+            else:
528
+                ii2 = ii2 + 1
529
+        while mm2 < len(listcgcs):
530
+            if listname1[mm2] == num2:
531
+                listcgcs[mm2] = -1
532
+                break
533
+            else:
534
+                mm2 = mm2 + 1
535
+        print(" Finish!")
536
+        js1 = 1
537
+        bhjs(dbpath,listcgcs1, listname1, listpastx1, listpasty1, wypd, listname, listnewx, listnewy, listpastx,
538
+                listpasty, points, listcgcs, sf, newname, pastname, js1,listnewx1,listnewy1,excelname)
539
+
540
+
541
+# 主函数 计算
542
+def main_function(dbpath,file_name):
543
+    #从数据库中调用
544
+    listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx,listpasty, points, listcgcs,sf, newname, pastname, js,listnewx1,listnewy1 = tablein(dbpath,file_name)
545
+    #计算
546
+    bhjs(dbpath,listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx,listpasty, points, listcgcs,sf, newname, pastname, js,listnewx1,listnewy1,file_name)
547
+    messagebox.showinfo("提示",f"文件 '{file_name}' 计算成功!")

+ 344
- 2
Back/WD/WD.py View File

@@ -1,2 +1,344 @@
1
-def main_function(file_path, db_path):
2
-    print("这是WD")
1
+import openpyxl
2
+import xlrd
3
+import sqlite3
4
+import os
5
+from openpyxl import Workbook
6
+import tkinter as tk
7
+from tkinter import messagebox
8
+import math
9
+import numpy as np
10
+
11
+def to_utf8(text):
12
+    str1 = text.encode('utf-8')
13
+    return str1
14
+
15
+# 弹窗提示用户是否更新数据
16
+def ask_for_update(file_name):
17
+    root = tk.Tk()
18
+    root.withdraw()  # 隐藏主窗口
19
+    response = messagebox.askyesno("提示", f"检测到数据库中存在相同文件名 '{file_name}',是否更新数据?")
20
+    return response
21
+
22
+# 读取Excel文件并计算公式结果
23
+def load_and_calculate_excel(file_path,cell0):
24
+    # 加载Excel文件并计算单元格的公式结果。
25
+    workbook = openpyxl.load_workbook(file_path, data_only=True)
26
+    sheet = workbook.active
27
+    h1_value = sheet[cell0].value
28
+    return h1_value
29
+
30
+# 数据库插入函数
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
+    #先把输入的录入数据库
33
+    db = sqlite3.connect(database)
34
+    #获取游标
35
+    cursor = db.cursor()
36
+    #字符类的都需要转换成字节存进去
37
+    utf_pan = to_utf8(pastname)
38
+    utf_nn = to_utf8(newname)
39
+    utf_bn = to_utf8(beforename)
40
+    utf_tn = to_utf8(excelname)
41
+    try:
42
+        # 查询是否已存在相同的记录
43
+        cursor.execute(
44
+            "SELECT * FROM WD_Input_Param WHERE TableName = ?",
45
+            (utf_tn,)
46
+        )
47
+        existing_record = cursor.fetchone()
48
+
49
+        if existing_record:
50
+            # 弹窗询问用户是否更新数据
51
+            if not ask_for_update(excelname):
52
+                print("用户选择不更新数据")
53
+                return
54
+
55
+            # 更新现有记录WD_Input_Param 
56
+            cursor.execute(
57
+                """
58
+                UPDATE WD_Input_Param 
59
+                SET First_ResultName = ?,Last_ResultName=?,New_ResultName=?,Avg_SL=?,Ms_Dir=?,Pt_Count=?,SL_Count=?,Dir_Count=?,Scale_Value=?,Avg_MSL=?,Avg_Dir=?
60
+                WHERE TableName = ?
61
+                """,
62
+                (utf_bn,utf_pan,utf_nn,pjbc,fxzwc,points,zbs,zfxs,sf,pjbcs,pjfxs,utf_tn,)
63
+            )
64
+            # 更新现有记录WD_Input_Point 
65
+            #删了已有的数据,重新插入
66
+            cursor.execute(
67
+                """
68
+                DELETE FROM WD_Input_Point WHERE TableName = ?
69
+                """,
70
+                (utf_tn,)
71
+            )
72
+            rr = 0
73
+            while rr < len(listname1):
74
+                rr1 = listname1[rr]
75
+                rr2 = listpastx1[rr]
76
+                rr3 = listpasty1[rr]
77
+                rr4 = listcgcs1[rr]
78
+                rr5 = listnewx[rr]
79
+                rr6 = listnewy[rr]
80
+                rr7 = listbex[rr]
81
+                rr8 = listbey[rr]
82
+                utf_rr1 = to_utf8(rr1)
83
+                cursor.execute(
84
+                    """
85
+                    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
+                    """,
87
+                    (utf_tn,utf_bn,utf_pan,utf_nn,rr2,rr3,rr5,rr6,utf_rr1,rr4,rr7,rr8,)
88
+                )
89
+                rr = rr + 1
90
+            messagebox.showinfo("提示",
91
+                                f"文件 '{excelname}' 已成功更新到本地数据库中,点击确认以关闭此对话框。对话框关闭后,请点击“计算”以重新计算数据")
92
+        else:
93
+            # 插入新记录WD_Input_Param 
94
+            cursor.execute(
95
+                """
96
+                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
+                VALUES (?,?,?,?,?,?,?,?,?,?,?,?)
98
+                """,
99
+                (utf_tn,utf_bn,utf_pan,utf_nn,pjbc,fxzwc,points,zbs,zfxs,sf,pjbcs,pjfxs,)
100
+            )
101
+            # 插入新记录WD_Input_Point 
102
+            rr = 0
103
+            while rr < len(listname1):
104
+                rr1 = listname1[rr]
105
+                rr2 = listpastx1[rr]
106
+                rr3 = listpasty1[rr]
107
+                rr4 = listcgcs1[rr]
108
+                rr5 = listnewx[rr]
109
+                rr6 = listnewy[rr]
110
+                rr7 = listbex[rr]
111
+                rr8 = listbey[rr]
112
+                utf_rr1 = to_utf8(rr1)
113
+                cursor.execute(
114
+                    """
115
+                    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
+                    """,
117
+                    (utf_tn,utf_bn,utf_pan,utf_nn,rr2,rr3,rr5,rr6,utf_rr1,rr4,rr7,rr8,)
118
+                )
119
+                rr = rr + 1
120
+            messagebox.showinfo("提示",
121
+                                f"文件 '{excelname}' 已成功添加到本地数据库中,点击确认以关闭此对话框。对话框关闭后,请点击“计算”以计算数据")
122
+
123
+        db.commit()
124
+    except sqlite3.Error as e:
125
+        print(f"插入或更新文件名时发生错误: {e}")
126
+    except Exception as e:
127
+        print(f"处理文件时发生错误: {e}")
128
+    finally:
129
+        db.close()
130
+
131
+#读取xls
132
+def xlrd_read(excelpath,dbpath):
133
+    global gszbx
134
+    global gszby
135
+    listname1 = []
136
+    listpastx1 = []
137
+    listpasty1 = []
138
+    listcgcs1 = []
139
+    #excel表名就是表名
140
+    excelname = os.path.basename(excelpath)
141
+    # 读取excel
142
+    xlr = xlrd.open_workbook(excelpath)
143
+    tabler = xlr.sheets()[0]
144
+    # 从第3行开始,3A为点号,3B为最新x,3C为最新y,3D为往期x
145
+    # 3E为往期y,3F为成果次数,3G为最早x,3H最早y
146
+    # 先看点数
147
+    rows = tabler.nrows
148
+    row = 2
149
+    points = rows - 2
150
+    # 收集每一列的数据,方便后期计算
151
+    listname = []
152
+    listnewx = []
153
+    listnewy = []
154
+    listpastx = []
155
+    listpasty = []
156
+    # 成果次数
157
+    listcgcs = []
158
+    # 最早的
159
+    listbex = []
160
+    listbey = []
161
+    sumnewx = 0
162
+    sumnewy = 0
163
+    sumpastx = 0
164
+    sumpasty = 0
165
+    # 记录下最早的那几个开头
166
+    # excelpath是输入表格,outpath是输出路径,pjbc是平均边长
167
+    # fxzwc是方向中误差,pjfxs是平均方向数,sf是缩放值
168
+    # 先计算位移判断值
169
+    pjbc = float(tabler.cell(0, 9).value)
170
+    fxzwc = float(tabler.cell(1, 9).value)
171
+    zbs = float(tabler.cell(2, 9).value)
172
+    zfxs = float(tabler.cell(3, 9).value)
173
+    pjbcs = zbs / points
174
+    pjfxs = zfxs / points
175
+    sf = float(tabler.cell(4, 9).value)
176
+    # 再拆细点
177
+    wy1 = pjbc / 1000
178
+    wy2 = wy1 + 1
179
+    wypd1 = wy2 * wy2 / pjbcs
180
+    # 好像206.265是常数系数
181
+    wy3 = pjbc * fxzwc / 206.265
182
+    wypd2 = wy3 * wy3 / pjfxs
183
+    wypd3 = math.sqrt(wypd1 + wypd2)
184
+    wypd = round((wypd3 * 2 * math.sqrt(2)), 9)
185
+    wypd0 = wypd
186
+    lastname = tabler.cell(0, 3).value
187
+    finalname = tabler.cell(0, 1).value
188
+    befname = tabler.cell(0, 6).value
189
+    utf_ln = to_utf8(lastname)
190
+    utf_fn = to_utf8(finalname)
191
+    utf_bn = to_utf8(befname)
192
+
193
+    while row < rows:
194
+        pname = tabler.cell(row, 0).value
195
+        pnewx = float(tabler.cell(row, 1).value)
196
+        sumnewx = sumnewx + pnewx
197
+        pnewy = float(tabler.cell(row, 2).value)
198
+        sumnewy = sumnewy + pnewy
199
+        ppastx = float(tabler.cell(row, 3).value)
200
+        sumpastx = sumpastx + ppastx
201
+        ppasty = float(tabler.cell(row, 4).value)
202
+        sumpasty = sumpasty + ppasty
203
+        pcgcs = float(tabler.cell(row, 5).value)
204
+        pbex = float(tabler.cell(row, 6).value)
205
+        pbey = float(tabler.cell(row, 7).value)
206
+        listname.append(pname)
207
+        listnewx.append(pnewx)
208
+        listnewy.append(pnewy)
209
+        listpastx.append(ppastx)
210
+        listpasty.append(ppasty)
211
+        listcgcs.append(pcgcs)
212
+        listbex.append(pbex)
213
+        listbey.append(pbey)
214
+        row = row + 1
215
+    # 最后返回这里输出
216
+    rr = 0
217
+    while rr < len(listname):
218
+        rr1 = listname[rr]
219
+        rr2 = listpastx[rr]
220
+        rr3 = listpasty[rr]
221
+        rr4 = listcgcs[rr]
222
+        listname1.append(rr1)
223
+        listpastx1.append(rr2)
224
+        listpasty1.append(rr3)
225
+        listcgcs1.append(rr4)
226
+        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)
229
+
230
+#读取xlsx
231
+def openpyxl_read(excelpath,dbpath):
232
+    global gszbx
233
+    global gszby
234
+    listname1 = []
235
+    listpastx1 = []
236
+    listpasty1 = []
237
+    listcgcs1 = []
238
+
239
+    #excel表名就是表名
240
+    excelname = os.path.basename(excelpath)
241
+    # 读取excel
242
+    xlr = openpyxl.load_workbook(excelpath)
243
+    tabler = xlr.worksheets[0]
244
+    # 从第3行开始,3A为点号,3B为最新x,3C为最新y,3D为往期x
245
+    # 3E为往期y
246
+    # 先看点数
247
+    rows = tabler.max_row
248
+    row = 3
249
+    points = rows - 2
250
+    # 收集每一列的数据,方便后期计算
251
+    listname = []
252
+    listnewx = []
253
+    listnewy = []
254
+    listpastx = []
255
+    listpasty = []
256
+    listcgcs = []
257
+    listbex=[]
258
+    listbey=[]
259
+    sumnewx = 0
260
+    sumnewy = 0
261
+    sumpastx = 0
262
+    sumpasty = 0
263
+    # 记录下最早的那几个开头
264
+    # excelpath是输入表格,outpath是输出路径,pjbc是平均边长
265
+    # fxzwc是方向中误差,zrbzwc是最弱边边长相对中误差,pjbcs是平均边数,pjfxs是平均方向数,sf是缩放值
266
+    # 新增总边数zbs,总方向数zfxs
267
+    # 先计算位移判断值
268
+    pjbc = float(tabler['J1'].value)
269
+    fxzwc = float(tabler['J2'].value)
270
+    try:
271
+        zbs = float(tabler['J3'].value)
272
+    except:
273
+        zbs = load_and_calculate_excel(excelpath,'J3')
274
+    try:
275
+        zfxs = float(tabler['J4'].value)
276
+    except:
277
+        zfxs = load_and_calculate_excel(excelpath,'J4')
278
+    pjbcs = zbs / points
279
+    pjfxs = zfxs / points
280
+    sf = float(tabler['J5'].value)
281
+    # 再拆细点
282
+    wy1 = pjbc / 1000
283
+    wy2 = wy1 + 1
284
+    wypd1 = wy2 * wy2 / pjbcs
285
+    # 好像206.265是常数系数
286
+    wy3 = pjbc * fxzwc / 206.265
287
+    wypd2 = wy3 * wy3 / pjfxs
288
+    wypd3 = math.sqrt(wypd1 + wypd2)
289
+    wypd = round((wypd3 * 2 * math.sqrt(2)), 9)
290
+    wypd0 = wypd
291
+    befname=tabler['G1'].value
292
+    lastname = tabler['D1'].value
293
+    finalname = tabler['B1'].value
294
+    while row <= rows:
295
+        try:
296
+            pname = tabler.cell(row, 1).value
297
+            pnewx = float(tabler.cell(row, 2).value)
298
+            sumnewx = sumnewx + pnewx
299
+            pnewy = float(tabler.cell(row, 3).value)
300
+            sumnewy = sumnewy + pnewy
301
+            ppastx = float(tabler.cell(row, 4).value)
302
+            sumpastx = sumpastx + ppastx
303
+            ppasty = float(tabler.cell(row, 5).value)
304
+            sumpasty = sumpasty + ppasty
305
+            pcgcs = float(tabler.cell(row, 6).value)
306
+            pbex = float(tabler.cell(row, 7).value)
307
+            pbey = float(tabler.cell(row, 8).value)
308
+            listname.append(pname)
309
+            listnewx.append(pnewx)
310
+            listnewy.append(pnewy)
311
+            listpastx.append(ppastx)
312
+            listpasty.append(ppasty)
313
+            listcgcs.append(pcgcs)
314
+            listbex.append(pbex)
315
+            listbey.append(pbey)
316
+            row = row + 1
317
+        except:
318
+            break
319
+    # 最后返回这里输出
320
+    rr = 0
321
+    while rr < len(listname):
322
+        rr1 = listname[rr]
323
+        rr2 = listpastx[rr]
324
+        rr3 = listpasty[rr]
325
+        rr4 = listcgcs[rr]
326
+        listname1.append(rr1)
327
+        listpastx1.append(rr2)
328
+        listpasty1.append(rr3)
329
+        listcgcs1.append(rr4)
330
+        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)
333
+
334
+# 主函数 读取excel文件
335
+def main_function(file_path,dbpath):
336
+    # 调用读取Excel文件的函数
337
+    file_name = os.path.basename(file_path)
338
+    #两种加载方式,对于不同的文件
339
+    if ".xlsx" in file_path:
340
+        #采用openpyxl
341
+        openpyxl_read(file_path,dbpath)
342
+    else:
343
+        #采用xlrd
344
+        xlrd_read(file_path,dbpath)

+ 0
- 2
Back/WD/WDcompute.py View File

@@ -1,2 +0,0 @@
1
-def main_function(file_path, db_path):
2
-    pass  # 添加计算的方法

Loading…
Cancel
Save