123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598 |
- import sqlite3
- import os
- import math
- import numpy as np
- from PySide6.QtWidgets import QMessageBox
-
-
- # region 各种方法
-
- def to_utf8(text):
- str1 = text.encode('utf-8')
- return str1
-
-
- def sfjs(gsx, listx, gsy, listy):
- s1 = gsx[len(gsx) - 1] - gsx[0]
- s2 = s1 * s1
- s3 = gsy[len(gsy) - 1] - gsy[0]
- s4 = s3 * s3
- s5 = s2 + s4
- s6 = math.sqrt(s5)
- t1 = listx[len(listx) - 1] - listx[0]
- t2 = t1 * t1
- t3 = listy[len(listy) - 1] - listy[0]
- t4 = t3 * t3
- t5 = t2 + t4
- t6 = math.sqrt(t5)
- num1 = round(s6 / t6, 8)
- return num1
-
-
- def mxjd(gs, nw):
- ii = 0
- sum1 = 0
- while ii < len(gs):
- s1 = gs[ii] - nw[ii]
- s2 = s1 * s1
- sum1 = sum1 + s2
- ii = ii + 1
- s3 = sum1 / 2 / len(gs)
- s4 = math.sqrt(s3)
- num1 = s4 * 1000
- return num1
-
-
- def xzjs(gsx, listx, gsy, listy):
- s1 = gsx[len(gsx) - 1] - gsx[0]
- s2 = gsy[len(gsy) - 1] - gsy[0]
- s3 = s2 / s1
- s4 = math.atan(s3)
- t1 = listx[len(listx) - 1] - listx[0]
- t2 = listy[len(listy) - 1] - listy[0]
- t3 = t2 / t1
- t4 = math.atan(t3)
- n1 = s4 - t4
- num1 = n1 * 180 / math.pi * 3600
- return num1
-
-
- def gsjs(x, y, nlist):
- listgsx = []
- xstr1 = nlist[0] * x
- xstr2 = nlist[1] * y
- xx = xstr1 + xstr2 + nlist[2]
- ystr1 = nlist[3] * x
- ystr2 = nlist[4] * y
- yy = ystr1 + ystr2 + nlist[5]
- listgsx.append(xx)
- listgsx.append(yy)
- return listgsx
-
-
- def jzys1(listy, zxzby, listx, zxzbx, sf):
- rlist = []
- listlen = len(listy)
- ll = 0
- while ll < listlen:
- # 第一个的值
- # num1 = round(((listx[ll] - zxzbx) / sf),0)
- # num2 = round(((listy[ll] - zxzby) / sf),0)
- num1 = (listx[ll] - zxzbx)
- num2 = (listy[ll] - zxzby)
- rlist.append(num1)
- rlist.append(num2)
- ll = ll + 1
- return rlist
-
-
- def jzys2(listy, zxzby, listx, zxzbx, sf):
- rlist = []
- listlen = len(listy)
- ll = 0
- while ll < listlen:
- # 第一个的值
- num2 = (-1) * (listx[ll] - zxzbx) / sf
- num1 = (listy[ll] - zxzby) / sf
- rlist.append(num1)
- rlist.append(num2)
- ll = ll + 1
- return rlist
-
-
- def jzys3(listy, aa, bb):
- rlist = []
- listlen = len(listy)
- ll = 0
- while ll < listlen:
- # 第一个的值
- num1 = aa
- num2 = bb
- rlist.append(num1)
- rlist.append(num2)
- ll = ll + 1
- return rlist
-
-
- def jzys4(listpasty, zxzbpasty, listpastx, zxzbpastx, listnewy, zxzbnewy, listnewx, zxzbnewx, sf):
- rlist = []
- listlen = len(listnewx)
- ll = 0
- while ll < listlen:
- num1 = (listpastx[ll] - listnewx[ll] - zxzbpastx + zxzbnewx) / sf
- num2 = (listpasty[ll] - listnewy[ll] - zxzbpasty + zxzbnewy) / sf
- rlist.append(round(num1, 6))
- rlist.append(round(num2, 6))
- ll = ll + 1
- return rlist
-
-
- def jzys5(listp, zxzbp, sf):
- rlist = []
- listlen = len(listp)
- ll = 0
- while ll < listlen:
- num1 = (listp[ll] - zxzbp) / sf
- rlist.append(num1)
- ll = ll + 1
- return rlist
-
-
- def jzys6(listp, num):
- rlist = []
- listlen = len(listp)
- ll = 0
- while ll < listlen:
- num1 = listp[ll] * num
- rlist.append(num1)
- ll = ll + 1
- return rlist
-
-
- def cjh(listp):
- rp = 0
- listlen = len(listp)
- ll = 0
- while ll < listlen:
- num1 = listp[ll] * listp[ll]
- rp = rp + num1
- ll = ll + 1
- return rp
-
-
- def cjh2(lista, listb):
- rp = 0
- listlen = len(lista)
- ll = 0
- while ll < listlen:
- num1 = lista[ll] * listb[ll]
- rp = rp + num1
- ll = ll + 1
- return rp
-
-
- def gsys(listnewp, jxlist1, jylist1, lxlist, lylist, arrz, sf, zxzbnewp, zxzbpastp, ii):
- # 新x+(矩阵[jx1 jy1 lx1 ly1]*矩阵z)*缩放-新重心坐标x+旧重心坐标x
- rlist = []
- listlen = len(listnewp)
- ll = 0
- while ll < listlen:
- arr0 = np.array((jxlist1[ll], jylist1[ll],
- lxlist[2 * ll + ii], lylist[2 * ll + ii]))
- arr1 = np.matmul(arr0, arrz)
- arr3 = sf * arr1
- newp = listnewp[ll] + arr3 - zxzbnewp + zxzbpastp
- rlist.append(newp)
- ll = ll + 1
- return rlist
-
-
- def xcys(newlist, pastlist):
- listlen = len(newlist)
- ll = 0
- rlist = []
- while ll < listlen:
- num1 = pastlist[ll] - newlist[ll]
- num2 = num1 * 1000
- rlist.append(num2)
- ll = ll + 1
- return rlist
-
-
- def takeFirst(elem):
- return elem[0]
-
-
- # endregion
-
- 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):
- # 将结果输出到数据库
- db1 = sqlite3.connect(database)
- # 获取游标
- cursor1 = db1.cursor()
- # 先清除已有数据,用来更新
- try:
- sqlstr3 = 'delete from GS_Trans_Param WHERE TableName = ?'
- sqlstr4 = 'delete from GS_Trans_Point WHERE TableName = ?'
- sqlstr5 = 'delete from GS_Result_Point WHERE TableName = ?'
- cursor1.execute(sqlstr3, (utf_tn,))
- cursor1.execute(sqlstr4, (utf_tn,))
- cursor1.execute(sqlstr5, (utf_tn,))
- except:
- pass
- 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,))
- # Trans_Point和Result_Point一起存
- for iname in listname1:
- if iname in listname:
- # 属于没问题点的
- # 直接使用gsx,gsy
- utf_pointname = to_utf8(str(iname))
- wystr = to_utf8('稳定')
- index1 = listname.index(iname)
- numm1 = round(gsx[index1], 4)
- numm2 = round(gsy[index1], 4)
- # 先找到首次的index
- index2 = listname1.index(iname)
- r1 = (listpastx1[index2] - gsx[index1]) * 1000
- r2 = (listpasty1[index2] - gsy[index1]) * 1000
- r3 = r1 * r1
- r4 = r2 * r2
- r5 = r3 + r4
- r6 = round(math.sqrt(r5), 1)
- numn1 = listpastx1[index2]
- numn2 = listnewx1[index2]
- 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],))
- 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,))
- else:
- index2 = listname1.index(iname)
- utf_pointname = to_utf8(str(iname))
- # 首先判断有没有第一个点
- if listnewx1[index2] != 0:
- # 有问题的点,使用公式跑
- listxy = gsjs(listnewx1[index2], listnewy1[index2], nlist)
- # 判断有没有第一次的数据,没有就不写
- if listpastx1[index2] != 0:
- r1 = (listpastx1[index2] - listxy[0]) * 1000
- r2 = (listpasty1[index2] - listxy[1]) * 1000
- r3 = r1 * r1
- r4 = r2 * r2
- r5 = r3 + r4
- r6 = round(math.sqrt(r5), 1)
- if r6 > 500:
- wystr = to_utf8('复建')
- 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,))
- else:
- wystr = to_utf8('位移')
- 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,))
- else:
- wystr = to_utf8('新建')
- 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,))
- # 数据库执行
- db1.commit()
- # 做完一切后,先关闭游标,再关闭数据库
- cursor1.close()
- db1.close()
-
-
- def tablein(outpath, str1):
- print(f"Connecting to database at path: {outpath}")
- listcgcs1 = []
- listname1 = []
- listpastx1 = []
- listpasty1 = []
- listname = []
- listnewx = []
- listnewy = []
- listpastx = []
- listpasty = []
- listcgcs = []
- listnewx1 = []
- listnewy1 = []
- points = 0
- # 查询,提取需要的数据
- db2 = sqlite3.connect(outpath)
- cursor2 = db2.cursor()
- utfstr1 = to_utf8(str1)
- sqlstr1 = 'SELECT * FROM GS_Input_Point WHERE TableName = ?'
- cursor2.execute(sqlstr1, (utfstr1,))
- all_da = cursor2.fetchall()
- for da in all_da:
- listpastx.append(da[3])
- listpastx1.append(da[3])
- listpasty.append(da[4])
- listpasty1.append(da[4])
- listnewx.append(da[5])
- listnewx1.append(da[5])
- listnewy.append(da[6])
- listnewy1.append(da[6])
- listname.append(da[7].decode('utf-8'))
- listname1.append(da[7].decode('utf-8'))
- listcgcs.append(da[8])
- listcgcs1.append(da[8])
- points = points + 1
- sqlstr2 = 'SELECT * FROM GS_Input_Param WHERE TableName = ?'
- cursor2.execute(sqlstr2, (utfstr1,))
- all_par = cursor2.fetchall()
- if not all_par:
- raise ValueError(f"No data found in GS_Input_Param for TableName: {str1}")
- pastname = all_par[0][1].decode('utf-8')
- newname = all_par[0][2].decode('utf-8')
- # pjbc是平均边长
- # fxzwc是方向中误差,zrbzwc是最弱边边长相对中误差,pjbcs是平均边数,pjfxs是平均方向数,sf是缩放值
- # 新增总边数zbs,总方向数zfxs
- # 先计算位移判断值
- pjbc = all_par[0][3]
- fxzwc = all_par[0][4]
- zrbzwc = all_par[0][5]
- zbs = all_par[0][7]
- zfxs = all_par[0][8]
- sf = all_par[0][9]
- pjbcs = zbs / points
- pjfxs = zfxs / points
- # 再拆细点
- wy1 = pjbc / 1000
- wy2 = wy1 * zrbzwc * 1e6
- wypd1 = wy2 * wy2 / pjbcs
- # 206.265是常数系数
- wy3 = pjbc * fxzwc / 206.265
- wypd2 = wy3 * wy3 / pjfxs
- wypd3 = math.sqrt(wypd1 + wypd2)
- wypd = round(wypd3 * 3, 4)
- wypd0 = wypd
- # 更新下数据库(参数部分)
- sqlstr3 = 'update GS_Input_Param set Pt_Count=?,Avg_MSL=?,Avg_Dir=? WHERE TableName = ?'
- cursor2.execute(sqlstr3, (points, pjbcs, pjfxs, utfstr1,))
- # 数据库执行
- db2.commit()
- # 做完一切后,先关闭游标,再关闭数据库
- cursor2.close()
- db2.close()
- js = 0
- return listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx, listpasty, points, listcgcs, sf, newname, pastname, js, listnewx1, listnewy1
-
-
- def bhjs(dbpath, listcgcs1, listname1, listpastx1, listpasty1, wypd, listname, listnewx, listnewy, listpastx, listpasty,
- points, listcgcs, sf, newname, pastname, js, listnewx1, listnewy1, excelname):
- np.set_printoptions(suppress=False)
- # pt用于给点数point计数
- # point会随着回递函数而减少
- pt = 0
- sumnewx = 0
- sumnewy = 0
- sumpastx = 0
- sumpasty = 0
- gszbx = []
- gszby = []
- arrz = []
- # #一个计数,把第一次改算坐标全部记下来
- # 存的第一次的改算值和起限差
- jslist = []
- # 等同于listnewx/y1
- jslist1 = []
- # listnewx/y,listpastx/y,listcgcs都是要变的
- # 带1的是原始的
- while pt < points:
- sumnewx = sumnewx + listnewx[pt]
- sumnewy = sumnewy + listnewy[pt]
- sumpastx = sumpastx + listpastx[pt]
- sumpasty = sumpasty + listpasty[pt]
- pt = pt + 1
- # 计算4个重心坐标(最新一期和上一期的)
- zxzbnewx = (sumnewx / points)
- zxzbnewy = (sumnewy / points)
- zxzbpastx = (sumpastx / points)
- zxzbpasty = (sumpasty / points)
- # 先计算平移参数
- # pycsx = abs(zxzbnewx - zxzbpastx) * 1000
- # pycsy = abs(zxzbnewy - zxzbpasty) * 1000
- pycsx = round((zxzbpastx - zxzbnewx), 4)
- pycsy = round((zxzbpasty - zxzbnewy), 4)
- # 分别得k,sita的值
- klist = jzys1(listnewy, zxzbnewy, listnewx, zxzbnewx, sf)
- slist = jzys2(listnewy, zxzbnewy, listnewx, zxzbnewx, sf)
- # 得dx,dy
- dxlist = jzys3(listnewy, 1, 0)
- dylist = jzys3(listnewy, 0, 1)
- # 矩阵太难用了,还是手动计算
- # 分别计算k、s、dx、dy的乘积和
- k2 = cjh(klist)
- s2 = cjh(slist)
- dx2 = cjh(dxlist)
- dy2 = cjh(dylist)
- # 这里再创建矩阵1
- arr1 = np.array(((k2, 0, 0, 0), (0, s2, 0, 0),
- (0, 0, dx2, 0), (0, 0, 0, dy2)))
- # 矩阵1的逆矩阵矩阵2
- arr2 = np.linalg.inv(arr1)
- # 求矩阵l
- llist = jzys4(listpasty, zxzbpasty, listpastx, zxzbpastx,
- listnewy, zxzbnewy, listnewx, zxzbnewx, sf)
- # 得到数列e1,e2,e3,e4
- e1 = cjh2(klist, llist)
- e2 = cjh2(slist, llist)
- e3 = cjh2(dxlist, llist)
- e4 = cjh2(dylist, llist)
- arrl = np.array(((e1), (e2), (e3), (e4)))
- # 得到矩阵z
- arrz = np.matmul(arr2, arrl)
- # 求转换矩阵
- jxlist1 = jzys5(listnewx, zxzbnewx, sf)
- jylist1 = jzys5(listnewy, zxzbnewy, sf)
- jxlist2 = jylist1
- # jylist2 = jxlist1 * (-1)
- jylist2 = jzys6(jxlist1, -1)
- lxlist = jzys3(jylist1, 1, 0)
- lylist = jzys3(jylist1, 0, 1)
- # 求改算坐标
- gsx = gsys(listnewx, jxlist1, jylist1, lxlist,
- lylist, arrz, sf, zxzbnewx, zxzbpastx, 0)
- gsy = gsys(listnewy, jxlist2, jylist2, lxlist,
- lylist, arrz, sf, zxzbnewy, zxzbpasty, 1)
- # 缩放系数也是计算出来的sfxs
- sfxs = sfjs(gsx, listnewx, gsy, listnewy)
- # 旋转角,模型精度
- xzj = xzjs(gsx, listnewx, gsy, listnewy)
- mxjdx = mxjd(gsx, listpastx)
- mxjdy = mxjd(gsy, listpasty)
- # 还是要先求较差
- xcx = xcys(gsx, listpastx)
- xcy = xcys(gsy, listpasty)
- # 这里记录下第一次所有点的改算坐标
- if js == 0:
- lengs = len(gsx)
- xx = 0
- while xx < lengs:
- gszbx.append(gsx[xx])
- gszby.append(gsy[xx])
- zblist1 = []
- zblist1.append(gsx[xx])
- zblist1.append(gsy[xx])
- zblist1.append(xcx[xx])
- zblist1.append(xcy[xx])
- jslist.append(zblist1)
- zblist2 = []
- zblist2.append(listnewx[xx])
- zblist2.append(listnewy[xx])
- jslist1.append(zblist2)
- xx = xx + 1
- # 后面不需要经过这个if
- # 判定方式是用差值平方和和位移对比
- gxpd = 0
- lenxc = len(xcx)
- yy = 0
- while yy < lenxc:
- sumxcx = xcx[yy] * xcx[yy]
- sumxcy = xcy[yy] * xcy[yy]
- sumxc = sumxcx + sumxcy
- xcpd = math.sqrt(sumxc)
- if xcpd > wypd:
- gxpd = -1
- break
- yy = yy + 1
- if gxpd == 0:
- # 输出之前把转换参数都算出来
- # X=(z1+1)*x+z2*y+(旧重心坐标x-新重心坐标x-新重心坐标x*z1-新重心坐标y*z2+z3)
- # Y=(-z2)*x+(z1+1)*y+(z1*新重心坐标y+新重心坐标x*z2+z4+旧重心坐标y-新重心坐标y)
- n1 = float(arrz[0]) + 1
- n2 = float(arrz[1])
- s1 = zxzbnewx * float(arrz[0])
- s2 = zxzbnewy * float(arrz[1])
- n3 = zxzbpastx - zxzbnewx - s1 - s2 + float(arrz[2])
- n4 = (-1) * float(arrz[1])
- n5 = n1
- s3 = (-1) * float(arrz[0]) * zxzbnewy
- s4 = float(arrz[1]) * zxzbnewx
- n6 = s3 + s4 + float(arrz[3]) + zxzbpasty - zxzbnewy
- sxylist = []
- sxylist.append(n1)
- sxylist.append(n2)
- sxylist.append(n3)
- sxylist.append(n4)
- sxylist.append(n5)
- sxylist.append(n6)
- # 输出
- relist1 = []
- relist1.append(listname)
- relist1.append(xcx)
- relist1.append(xcy)
- relist1.append(listcgcs)
- relist1.append(gszbx)
- relist1.append(gszby)
- relist1.append(sxylist)
- print(" Finish!")
- # 输出的那个不是改算坐标,而是有计算的改算坐标
- newgsx = []
- newgsy = []
- lengs1 = len(gszbx)
- nlist = relist1[6]
- # return relist
- # 中文再来一次
- utf_pan = to_utf8(pastname)
- utf_nn = to_utf8(newname)
- utf_tn = to_utf8(excelname)
- 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)
-
- else:
- # 先把所有的合在一起,方便删除
- lenlist1 = len(xcx)
- ii = 0
- relist1 = []
- while ii < lenlist1:
- smlist1 = []
- nn2 = xcx[ii] * xcx[ii]
- mm2 = xcy[ii] * xcy[ii]
- nm2 = math.sqrt(nn2 + mm2)
- smlist1.append(nm2)
- smlist1.append(listname[ii])
- smlist1.append(listnewx[ii])
- smlist1.append(listnewy[ii])
- smlist1.append(listpastx[ii])
- smlist1.append(listpasty[ii])
- relist1.append(smlist1)
- ii = ii + 1
- # 直接删除最大的那个
- relist1.sort(key=takeFirst, reverse=True)
- num1 = relist1[0]
- # 获取name
- num2 = num1[1]
- ii2 = 0
- mm2 = 0
- while ii2 < lenlist1:
- if listname[ii2] == num2:
- del listname[ii2]
- del listnewx[ii2]
- del listnewy[ii2]
- del listpastx[ii2]
- del listpasty[ii2]
- points = points - 1
- break
- else:
- ii2 = ii2 + 1
- while mm2 < len(listcgcs):
- if listname1[mm2] == num2:
- listcgcs[mm2] = -1
- break
- else:
- mm2 = mm2 + 1
- print(" Finish!")
- js1 = 1
- bhjs(dbpath, listcgcs1, listname1, listpastx1, listpasty1, wypd, listname, listnewx, listnewy, listpastx,
- listpasty, points, listcgcs, sf, newname, pastname, js1, listnewx1, listnewy1, excelname)
-
-
- # 主函数 计算
- def main_function(file_name, dbpath):
- try:
- print(f"File name: {file_name}")
- # 从数据库中调用
- listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx, listpasty, points, listcgcs, sf, newname, pastname, js, listnewx1, listnewy1 = tablein(
- dbpath, file_name)
- # 计算
- bhjs(dbpath, listcgcs1, listname1, listpastx1, listpasty1, wypd0, listname, listnewx, listnewy, listpastx,
- listpasty, points, listcgcs, sf, newname, pastname, js, listnewx1, listnewy1, file_name)
- QMessageBox.information(None, "提示", f"文件 '{file_name}' 计算成功!")
- except Exception as e:
- QMessageBox.critical(None, "错误", f"文件 '{file_name}' 计算失败!错误信息: {str(e)}")
|