126 lines
5.5 KiB
Python
126 lines
5.5 KiB
Python
import os
|
|
import sqlite3
|
|
import sympy as sp
|
|
|
|
|
|
class Datenbank_anlegen:
|
|
def __init__(self, pfad_datenbank):
|
|
self.pfad_datenbank = pfad_datenbank
|
|
self.db_anlegen()
|
|
|
|
def db_anlegen(self):
|
|
# pfad = r"C:\Users\fabia\OneDrive\Jade HS\Master\MGW2\Masterprojekt_allgemein\Masterprojekt\Programmierung\Campusnetz\Campusnetz.db"
|
|
if not os.path.exists(self.pfad_datenbank):
|
|
con = sqlite3.connect(self.pfad_datenbank)
|
|
cursor = con.cursor()
|
|
cursor.executescript("""CREATE TABLE Netzpunkte (
|
|
punktnummer TEXT(10),
|
|
naeherungx_lh NUMERIC(9,3),
|
|
naeherungy_lh NUMERIC(7,3),
|
|
naeherungz_lh NUMERIC(8,3),
|
|
naeherungx_us NUMERIC(9,3),
|
|
naeherungy_us NUMERIC(7,3),
|
|
naeherungz_us NUMERIC(8,3),
|
|
CONSTRAINT pk_Netzpunkte PRIMARY KEY (punktnummer)
|
|
);
|
|
""");
|
|
cursor.executescript("""CREATE TABLE Beobachtungen(
|
|
beobachtungenID INTEGER,
|
|
beobachtungsgruppeID INTEGER,
|
|
punktnummer_sp TEXT(10),
|
|
punktnummer_zp TEXT(10),
|
|
instrumenteID INTEGER,
|
|
tachymeter_richtung NUMERIC(8, 6),
|
|
tachymeter_zenitwinkel NUMERIC(8, 6),
|
|
tachymeter_distanz NUMERIC(8, 4),
|
|
dateiname TEXT(200),
|
|
CONSTRAINT pk_Beobachtunen PRIMARY KEY (beobachtungenID)
|
|
);
|
|
""");
|
|
cursor.executescript("""CREATE TABLE Instrumente(
|
|
instrumenteID INTEGER,
|
|
typ TEXT(200),
|
|
name TEXT(200),
|
|
CONSTRAINT pk_Instrumente PRIMARY KEY (instrumenteID)
|
|
);
|
|
""")
|
|
con.commit()
|
|
cursor.close()
|
|
con.close()
|
|
|
|
class Datenbankzugriff:
|
|
def __init__(self, pfad_datenbank):
|
|
self.pfad_datenbank = pfad_datenbank
|
|
|
|
def get_koordinaten(self, koordinatenart, ausgabeart = "Dict"):
|
|
con = sqlite3.connect(self.pfad_datenbank)
|
|
cursor = con.cursor()
|
|
if koordinatenart == "naeherung_lh":
|
|
values = "punktnummer, naeherungx_lh, naeherungy_lh, naeherungz_lh"
|
|
elif koordinatenart == "naeherung_us":
|
|
values = "punktnummer, naeherungx_us, naeherungy_us, naeherungz_us"
|
|
|
|
liste_koordinaten = cursor.execute(f"""
|
|
SELECT {values} FROM Netzpunkte;
|
|
""").fetchall()
|
|
cursor.close()
|
|
con.close()
|
|
|
|
liste_koordinaten = [
|
|
koordinate for koordinate in liste_koordinaten
|
|
if koordinate[1] is not None and koordinate[2] is not None and koordinate[3] is not None
|
|
]
|
|
if ausgabeart == "Dict":
|
|
return {koordinate[0]: sp.Matrix([float(koordinate[1]), float(koordinate[2]), float(koordinate[3])]) for koordinate in liste_koordinaten}
|
|
|
|
def set_koordinaten(self, dict_koordinaten, koordinatenart):
|
|
con = sqlite3.connect(self.pfad_datenbank)
|
|
cursor = con.cursor()
|
|
|
|
daten = []
|
|
|
|
for punktnummer, wert in dict_koordinaten.items():
|
|
daten.append((
|
|
float(wert[0]),
|
|
float(wert[1]),
|
|
float(wert[2]),
|
|
str(punktnummer)
|
|
))
|
|
|
|
if koordinatenart == "naeherung_lh":
|
|
pass
|
|
elif koordinatenart == "naeherung_us":
|
|
cursor.executemany(f"""UPDATE Netzpunkte SET naeherungx_us = ?, naeherungy_us = ?, naeherungz_us = ? WHERE punktnummer = ? AND naeherungx_us IS NULL AND naeherungy_us IS NULL AND naeherungz_us IS NULL""", daten)
|
|
|
|
|
|
con.commit()
|
|
cursor.close()
|
|
con.close()
|
|
|
|
def set_instrument(self, typ, name):
|
|
con = sqlite3.connect(self.pfad_datenbank)
|
|
cursor = con.cursor()
|
|
liste_instrumente = cursor.execute("SELECT * FROM Instrumente WHERE typ = ? AND name =?", (typ, name)).fetchall()
|
|
if liste_instrumente == []:
|
|
cursor.execute(
|
|
"INSERT INTO Instrumente (typ, name) VALUES (?, ?)", (typ, name)
|
|
)
|
|
print(f"Das Instrument {name} wurde erfolgreich hinzugefügt.")
|
|
else:
|
|
id_instrument = cursor.execute(
|
|
"SELECT instrumenteID FROM Instrumente WHERE typ = ? AND name =?", (typ, name))
|
|
print(f"Das Instrument {name} ist bereits in der Datenbank vorhanden.\nEs hat die ID {id_instrument.fetchone()[0]}")
|
|
con.commit()
|
|
cursor.close()
|
|
con.close()
|
|
|
|
def get_instrument(self, typ):
|
|
con = sqlite3.connect(self.pfad_datenbank)
|
|
cursor = con.cursor()
|
|
liste_instrumente = cursor.execute("SELECT * FROM Instrumente WHERE typ = ?", (typ,)).fetchall()
|
|
liste_typen = cursor.execute("SELECT DISTINCT typ FROM Instrumente").fetchall()
|
|
cursor.close()
|
|
con.close()
|
|
if liste_instrumente == []:
|
|
liste_instrumente = f"Kein Instrument vom Typ {typ} gefunden. Folgende Typen stehen aktuell zur Auswahl: {liste_typen}"
|
|
return liste_instrumente |