def vypocet(self): # vezme cisla bodu print("*******************************************") print("Delka a smernik") self.stanovisko = self.textEdit.toPlainText() # stanovisko self.cil = self.textEdit_2.toPlainText() # cil print("Z bodu: {}".format(self.cil)) print("Na bod: {}".format(self.stanovisko)) query1 = 'select Y, X from gps_sour where CB is {}{}{}{}{} '.format( '"', ' ', str(self.stanovisko), ' ', '"') query2 = 'select Y, X from gps_sour where CB is {}{}{}{}{} '.format( '"', ' ', str(self.cil), ' ', '"') bod1 = Databaze.sql_query(self.cesta, query1) bod2 = Databaze.sql_query(self.cesta, query2) try: #vypocet smerniku a delky self.delka = vypocty.delka(bod1, bod2) self.delka = vypocty.zaokrouhleni(self.delka, 3) self.smernik = vypocty.smernik(bod1, bod2) self.smernik = vypocty.zaokrouhleni(self.smernik, 4) # posle delku a smernik do oken self.textEdit_4.setText(str(self.delka)) self.textEdit_3.setText(str(self.smernik)) except IndexError: print("Body nejsou v seznamu souradnic!!")
def ulozeni_stanoviska(self): # ulozi vysledne souradnice do projektu query_pridani = 'insert into gps_sour (CB, X ,Y ) values (" {} ",{},{})'.format( self.stan, self.X, self.Y) Databaze.pridani_bodu(self.cesta, query_pridani) print("Bod ulozen!!")
def ulozeni_rajonu(self): # ulozi souradnice spocitaneho rajonu try: query='insert into gps_sour (CB, Y, X, kod) values (" {} ", {}, {}," {} ")'.format(self.bod, self.souradniceY, self.souradniceX, self.bod_data[0][6]) Databaze.pridani_bodu(self.cesta, query) print("Bod ulozen!!") except IndexError: print("Bod neni spocitan!!")
def uloz_bod(self): # ulozeni vypocteneho bodu do seznamu souradnic try: query='insert into gps_sour (CB, Y, X) values (" {} ", {}, {})'.format(self.cb, self.Y, self.X) Databaze.pridani_bodu(self.cesta, query) print("Bod ulozen") except sql.OperationalError: print("Neni spocitan bod nebo neni vyplneno cislo bodu!!")
def exportSouradnic(self): # export senamu souradnic cesta_export = QFileDialog.getSaveFileUrl() cesta_export = cesta_export[0].toString() cesta_export = cesta_export[8:] Databaze.export2txt(self.cesta_projektu[0], cesta_export) print("Seznam souradnic ulozen!!")
def vypocet(self): # vypocet volneho stanoviska # cisla bodu z grafickeho rozhrani self.ori1 = self.orientace1.toPlainText() self.ori2 = self.orientace2.toPlainText() self.stan = self.CB.toPlainText() # priprava sql prikazu query1 = 'select X, Y from gps_sour where CB is " {} "'.format( str(self.ori1)) query2 = 'select X, Y from gps_sour where CB is " {} "'.format( str(self.ori2)) query_stan1 = 'select Delka, Zenitka, Smer from mereni where Stanovisko is " {} " and Orientace is " {} "'.format( str(self.stan), str(self.ori1)) query_stan2 = 'select Delka, Zenitka, Smer from mereni where Stanovisko is " {} " and Orientace is " {} "'.format( str(self.stan), str(self.ori2)) #tahani dat z databaze ori1_sour = Databaze.sql_query(self.cesta, query1) ori2_sour = Databaze.sql_query(self.cesta, query2) ori1_mer = Databaze.sql_query(self.cesta, query_stan1) ori2_mer = Databaze.sql_query(self.cesta, query_stan2) try: # vypocet volneho stanoviska data = { 503: { 'x': ori1_sour[0][0], 'y': ori1_sour[0][1], 'delka': ori1_mer[0][0] * math.sin(ori1_mer[0][1]), 'smer': ori1_mer[0][2] }, 504: { 'x': ori2_sour[0][0], 'y': ori2_sour[0][1], 'delka': ori2_mer[0][0] * math.sin(ori2_mer[0][1]), 'smer': ori2_mer[0][2] } } stanovisko = vypocty.vyp_stanovisko(data) self.X = vypocty.zaokrouhleni(stanovisko['X'], 3) self.Y = vypocty.zaokrouhleni(stanovisko['Y'], 3) # ukazani vyslednych souradnic do graf. rozhrani self.Xova.setText(str(self.X)) self.Yova.setText(str(self.Y)) except IndexError: print("Data nejsou soucasti projektu!!")
def __init__(self, cesta_projekt): super().__init__() self.setWindowIcon(QtGui.QIcon('foto.jpg')) _translate = QtCore.QCoreApplication.translate self.setWindowTitle(_translate("Dialog", "Grafika")) self._main = QtWidgets.QWidget() self.cesta = cesta_projekt self.setCentralWidget(self._main) layout = QtWidgets.QVBoxLayout(self._main) static_canvas = FigureCanvas(Figure(figsize=(20, 20))) layout.addWidget(static_canvas) self.addToolBar(NavigationToolbar(static_canvas, self)) self._static_ax = static_canvas.figure.subplots() query = "select Y, X, CB from gps_sour" sour = Databaze.sql_query(self.cesta, query) y = [] x = [] for i in range(0, len(sour)): Y = -sour[i][0] X = -sour[i][1] CB = sour[i][2] y.append(Y) x.append(X) self._static_ax.text(Y, X, CB) self._static_ax.plot(y, x, "+") self._static_ax.axis('equal') self.show()
def info_projekt(self): # vypise info o zalozenem projektu #ziskani informaci z databaze try: info = Databaze.sql_query(self.cesta_projektu[0], 'select * from projekt') pocet_stanovisek = Databaze.sql_query( self.cesta_projektu[0], 'SELECT count(distinct Stanovisko) from mereni group by Stanovisko' ) # vypis infa do terminalu print("*******************************************") print("Aktivni projekt: {}".format(self.cesta_projektu[0])) print("Pocet bodu z GPS: {}".format(info[0][2])) print("Pocet bodu v zapisniku: {}".format(info[0][3])) print("Pocet stanovisek: {}".format(pocet_stanovisek[0][0])) except AttributeError: print("Neni aktivni projekt!!")
def vypocet(self): # vypocte souradnice bodu urceneho protinanim # nacteni hodnot z okna self.bod1_=self.bod1.toPlainText() self.bod2_=self.bod1_2.toPlainText() self.del1=self.delka1.toPlainText() self.del2=self.delka2.toPlainText() self.cb=self.CB.toPlainText() # ziskani souradnic z databaze # cesta_databaze=path.ziskej_cestu() bod1_sour=Databaze.sql_query(self.cesta,'select X, Y from gps_sour where CB = " {} "'.format(self.bod1_)) bod2_sour=Databaze.sql_query(self.cesta,'select X, Y from gps_sour where CB = " {} "'.format(self.bod2_)) # vypocet protinani try: bod1v=[bod1_sour[0][0], bod1_sour[0][1]] bod2v=[bod2_sour[0][0], bod2_sour[0][1]]\ bod=vypocty.prot_delek(bod1v,bod2v,float(self.del1),float(self.del2)) # zaokrouhleni souradnic self.X=vypocty.zaokrouhleni(bod[0],3) self.Y=vypocty.zaokrouhleni(bod[1],3) # vypsani souradnic do okna self.Xova.setText(str(self.X)) self.Yova.setText(str(self.Y)) print("Bod vypocten!!") except ValueError: print("Nedodrzena trojuhelnikova nerovnost") except IndexError: print("Body nejsou v seznamu souradnic!!")
def vypocet_rajonu(self): # vypocet rajonu print("*******************************************") print("Vypocet rajonu") # vezme hodnoty z textEdit self.stan = self.stanovisko.toPlainText() self.ori = self.orientace.toPlainText() self.bod = self.merenybod.toPlainText() #tahani dat z databaze query_stanovisko = 'select * from gps_sour where CB is " {} "'.format(self.stan) query_orientace = 'select * from gps_sour where CB is " {} "'.format(self.ori) query_bod = 'select * from mereni where Orientace is " {} " and Stanovisko is " {} "'.format(self.bod,self.stan) query_mereni_orientace = 'select * from mereni where Orientace is " {} " and Stanovisko is " {} "'.format(self.ori,self.stan) self.stanovisko_data = Databaze.sql_query(self.cesta,query_stanovisko) self.orientace_data = Databaze.sql_query(self.cesta,query_orientace) self.bod_data = Databaze.sql_query(self.cesta,query_bod) self.mereni_orientace = Databaze.sql_query(self.cesta,query_mereni_orientace) try: # priprava slovniku pro vypocet rajonu b_ori={5001:{'x': self.orientace_data[0][3], 'y': self.orientace_data[0][2], 'smer': self.mereni_orientace[0][5]}} b_sta={'X': self.stanovisko_data[0][3], 'Y': self.stanovisko_data[0][2]} b_mer={5003:{'delka': self.bod_data[0][3]*math.sin(self.bod_data[0][4]*math.pi/200), 'smer': self.bod_data[0][5]}} # vypocet rajonu rajon=vypocty.rajon(b_ori,b_sta,b_mer) # vypsani souradnic rajonu self.souradniceX=vypocty.zaokrouhleni(rajon[5003]['x'],3) self.souradniceY=vypocty.zaokrouhleni(rajon[5003]['y'],3) self.X.setText(str(self.souradniceX)) self.Y.setText(str(self.souradniceY)) except IndexError: print("Data nejsou soucasti projektu!!")
def davka(cesta, stanovisko,orientace): # vypocet rajonu hromadne xy_orientace = {} mereni_body = {} try: # zsiakni souradnic orientace query='select CB, X, Y from gps_sour where CB is " {} "'.format(str(orientace)) orientace_sour=Databaze.sql_query(cesta,query) CB=int(orientace_sour[0][0]) xy_orientace[CB] = {} xy_orientace[CB]['x'] = orientace_sour[0][1] xy_orientace[CB]['y'] = orientace_sour[0][2] # ziskani mereni ze stanoviska query='select Orientace, Delka, Zenitka, Smer,kod from mereni where Stanovisko is " {} "'.format(str(stanovisko)) body_sour=Databaze.sql_query(cesta,query) for i in range(0,len(body_sour)): CB=int(body_sour[i][0]) delka=body_sour[i][1]*sin(body_sour[i][2]*pi/200) smer=body_sour[i][3] mereni_body[CB] = {} mereni_body[CB]['delka'] = delka mereni_body[CB]['smer'] = smer if CB==int(orientace): xy_orientace[CB]['delka']=body_sour[i][1]*sin(body_sour[i][2]) xy_orientace[CB]['smer']=smer # ziskani souradnic stanoviska query='select X,Y from gps_sour where CB is " {} "'.format(str(stanovisko)) stan_sour=Databaze.sql_query(cesta,query) stanovisko = {'X': 0, 'Y': 0} stanovisko['X'] = stan_sour[0][0] stanovisko['Y'] = stan_sour[0][1] # vypocet souradnic rajonu body = vypocty.rajon(xy_orientace, stanovisko, mereni_body) # zapsani souradnic podrobnych bodu do databaze con=sql.connect(cesta) c=con.cursor() for i in range(0,len(body)): CB=body_sour[i][0] X=vypocty.zaokrouhleni(body[CB]['x'],3) Y=vypocty.zaokrouhleni(body[CB]['y'],3) kod=body_sour[i][4] if CB<4000: query='insert into gps_sour (CB, X, Y, kod) values (" {} ", {}, {}, " {} ") '.format(CB, str(X) ,str(Y), kod) c.execute(query) con.commit() con.close() return i except IndexError: print('Data nejsou soucasti projektu!!')
# systemove knihovny import os # vlastni knihovny from data import Databaze from config import DB_CONFIG, DATA_CONFIG # import konfigurace databaze a dat databaze = Databaze() databaze.vytvoreni(DB_CONFIG["nazev_projektu"]) databaze.vytvor_tabulku(DB_CONFIG["tabulka_souradnic"], DB_CONFIG["schema_tabulky_souradnic"]) databaze.vytvor_tabulku(DB_CONFIG["tabulka_mereni"], DB_CONFIG["schema_tabulky_mereni"]) # databaze.smazat(DB_CONFIG["tabulka_souradnic"], '') # databaze.smazat(DB_CONFIG["tabulka_mereni"], '') databaze.importuj_sour(DATA_CONFIG['cesta_sour']) databaze.importuj_mereni(DATA_CONFIG['cesta_mereni']) # data=Databaze.sql_query(projekt,'select * from gps_sour') # print(data[0][:])
def accept(self): # kdyz se klikne na OK print("*******************************************") print("Projekt zalozen") nazev=self.textEdit.toPlainText() # vezme nazev souboru print(nazev) cesta=self.cesta_souradnice[0] cesta_inv=cesta[::-1] pozice=cesta_inv.find('/') cesta_konecna=cesta[0:len(cesta)-pozice] #======================================================================# #zalozeni databaze databaze = Databaze() databaze.vytvoreni(nazev,cesta_konecna) databaze.vytvor_tabulku(DB_CONFIG["tabulka_souradnic"], DB_CONFIG["schema_tabulky_souradnic"]) databaze.vytvor_tabulku(DB_CONFIG["tabulka_mereni"], DB_CONFIG["schema_tabulky_mereni"]) databaze.vytvor_tabulku(DB_CONFIG["tabulka_projekt"], DB_CONFIG["schema_projekt"]) databaze.importuj_sour(str(self.cesta_souradnice[0])) databaze.importuj_mereni(str(self.cesta_mereni[0])) databaze.zapis_info(self.cesta_souradnice[0]) f=str(cesta_konecna+nazev+'.db') print('Projekt ulozen do: '+cesta_konecna+nazev+'.db') self.global_cesta.append(f) self.close()