Import Tachymeter fertig
This commit is contained in:
BIN
Campusnetz.db
BIN
Campusnetz.db
Binary file not shown.
@@ -6,8 +6,8 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": true,
|
"collapsed": true,
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2025-12-10T17:56:08.191585Z",
|
"end_time": "2025-12-11T12:48:02.991066Z",
|
||||||
"start_time": "2025-12-10T17:56:07.832678Z"
|
"start_time": "2025-12-11T12:48:02.590922Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"source": [
|
"source": [
|
||||||
@@ -16,7 +16,8 @@
|
|||||||
"import Import\n",
|
"import Import\n",
|
||||||
"import importlib\n",
|
"import importlib\n",
|
||||||
"import Koordinatentransformationen\n",
|
"import Koordinatentransformationen\n",
|
||||||
"import sqlite3"
|
"import sqlite3\n",
|
||||||
|
"from pathlib import Path"
|
||||||
],
|
],
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"execution_count": 1
|
"execution_count": 1
|
||||||
@@ -24,8 +25,8 @@
|
|||||||
{
|
{
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2025-12-10T17:56:08.274538Z",
|
"end_time": "2025-12-11T12:48:03.094896Z",
|
||||||
"start_time": "2025-12-10T17:56:08.235850Z"
|
"start_time": "2025-12-11T12:48:03.010452Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
@@ -47,8 +48,8 @@
|
|||||||
{
|
{
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2025-12-10T17:56:08.297943Z",
|
"end_time": "2025-12-11T12:48:03.117333Z",
|
||||||
"start_time": "2025-12-10T17:56:08.279765Z"
|
"start_time": "2025-12-11T12:48:03.099737Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
@@ -72,8 +73,8 @@
|
|||||||
{
|
{
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2025-12-10T17:56:08.314677Z",
|
"end_time": "2025-12-11T12:48:03.133119Z",
|
||||||
"start_time": "2025-12-10T17:56:08.304360Z"
|
"start_time": "2025-12-11T12:48:03.123298Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
@@ -275,8 +276,8 @@
|
|||||||
{
|
{
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2025-12-10T17:56:08.325087Z",
|
"end_time": "2025-12-11T12:48:03.144627Z",
|
||||||
"start_time": "2025-12-10T17:56:08.319929Z"
|
"start_time": "2025-12-11T12:48:03.140303Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
@@ -301,8 +302,8 @@
|
|||||||
{
|
{
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2025-12-10T17:56:08.355544Z",
|
"end_time": "2025-12-11T12:48:03.173134Z",
|
||||||
"start_time": "2025-12-10T17:56:08.333320Z"
|
"start_time": "2025-12-11T12:48:03.154035Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
@@ -362,8 +363,8 @@
|
|||||||
{
|
{
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2025-12-10T17:56:10.662819Z",
|
"end_time": "2025-12-11T12:48:05.283580Z",
|
||||||
"start_time": "2025-12-10T17:56:08.361074Z"
|
"start_time": "2025-12-11T12:48:03.178151Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
@@ -535,8 +536,8 @@
|
|||||||
{
|
{
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2025-12-10T17:56:10.844846Z",
|
"end_time": "2025-12-11T12:48:05.460533Z",
|
||||||
"start_time": "2025-12-10T17:56:10.809175Z"
|
"start_time": "2025-12-11T12:48:05.427340Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
@@ -727,8 +728,8 @@
|
|||||||
{
|
{
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2025-12-10T17:56:10.872837Z",
|
"end_time": "2025-12-11T12:48:05.493950Z",
|
||||||
"start_time": "2025-12-10T17:56:10.853910Z"
|
"start_time": "2025-12-11T12:48:05.476525Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
@@ -745,8 +746,8 @@
|
|||||||
{
|
{
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"ExecuteTime": {
|
"ExecuteTime": {
|
||||||
"end_time": "2025-12-10T17:56:10.904556Z",
|
"end_time": "2025-12-11T12:48:05.525108Z",
|
||||||
"start_time": "2025-12-10T17:56:10.882418Z"
|
"start_time": "2025-12-11T12:48:05.503651Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
@@ -780,6 +781,35 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"execution_count": 10
|
"execution_count": 10
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"metadata": {
|
||||||
|
"ExecuteTime": {
|
||||||
|
"end_time": "2025-12-11T12:48:09.112399Z",
|
||||||
|
"start_time": "2025-12-11T12:48:09.106481Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cell_type": "code",
|
||||||
|
"source": [
|
||||||
|
"# Importieren der tachymetrischen Beobachtungen\n",
|
||||||
|
"importlib.reload(Import)\n",
|
||||||
|
"imp = Import.Import(pfad_datenbank)\n",
|
||||||
|
"\n",
|
||||||
|
"pfad_datei_tachymeterbeobachtungen = r\"Daten\\campsnetz_beobachtungen_bereinigt.csv\"\n",
|
||||||
|
"\n",
|
||||||
|
"imp.import_beobachtungen_tachymeter(pfad_datei_tachymeterbeobachtungen, 1)"
|
||||||
|
],
|
||||||
|
"id": "509e462917e98145",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Der Import wurde abgebrochen, weil die Beobachtungen aus der Datei Daten\\campsnetz_beobachtungen_bereinigt.csv bereits in der Datenbank vorhanden sind.\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"execution_count": 12
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
|
|||||||
166
Import.py
166
Import.py
@@ -1,5 +1,6 @@
|
|||||||
import csv
|
import csv
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
class Import:
|
class Import:
|
||||||
def __init__(self, pfad_datenbank):
|
def __init__(self, pfad_datenbank):
|
||||||
@@ -10,6 +11,10 @@ class Import:
|
|||||||
zahl = zahl.replace(',', '.')
|
zahl = zahl.replace(',', '.')
|
||||||
return float(zahl)
|
return float(zahl)
|
||||||
|
|
||||||
|
def string_to_decimal(self, zahl):
|
||||||
|
zahl = zahl.replace(',', '.')
|
||||||
|
return Decimal(zahl)
|
||||||
|
|
||||||
def import_koordinaten_lh_tachymeter(self, pfad_datei):
|
def import_koordinaten_lh_tachymeter(self, pfad_datei):
|
||||||
liste_punktnummern = []
|
liste_punktnummern = []
|
||||||
liste_punktnummern_vorher = []
|
liste_punktnummern_vorher = []
|
||||||
@@ -54,4 +59,163 @@ class Import:
|
|||||||
con.commit()
|
con.commit()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
con.close()
|
con.close()
|
||||||
print("Der Import der Näherungskoordinaten wurde erfolgreich abgeschlossen")
|
print("Der Import der Näherungskoordinaten wurde erfolgreich abgeschlossen")
|
||||||
|
|
||||||
|
def import_beobachtungen_tachymeter(self, pfad_datei, instrumentenID):
|
||||||
|
# Prüfen, ob Bereits Daten aus der Datei in der Datenbank vorhanden sind
|
||||||
|
con = sqlite3.connect(self.pfad_datenbank)
|
||||||
|
cursor = con.cursor()
|
||||||
|
liste_dateinamen_in_db = [r[0] for r in cursor.execute(
|
||||||
|
"SELECT DISTINCT dateiname FROM Beobachtungen"
|
||||||
|
).fetchall()]
|
||||||
|
liste_beobachtungsgruppeID = [r[0] for r in cursor.execute("""SELECT DISTINCT beobachtungsgruppeID
|
||||||
|
FROM Beobachtungen""").fetchall()]
|
||||||
|
liste_instrumentenid = [r[0] for r in cursor.execute("SELECT instrumenteID FROM Instrumente").fetchall()]
|
||||||
|
|
||||||
|
con.close()
|
||||||
|
cursor.close
|
||||||
|
|
||||||
|
Import_fortsetzen = True
|
||||||
|
|
||||||
|
if pfad_datei in liste_dateinamen_in_db:
|
||||||
|
Import_fortsetzen = False
|
||||||
|
|
||||||
|
if Import_fortsetzen:
|
||||||
|
nummer_zielpunkt = 0
|
||||||
|
try:
|
||||||
|
nummer_beobachtungsgruppeID = max(liste_beobachtungsgruppeID)
|
||||||
|
except:
|
||||||
|
nummer_beobachtungsgruppeID = 0
|
||||||
|
|
||||||
|
with (open(pfad_datei, "r", encoding="utf-8") as f):
|
||||||
|
liste_fehlerhafte_zeile = []
|
||||||
|
liste_beobachtungen_vorbereitung = []
|
||||||
|
|
||||||
|
for i, zeile in enumerate(f):
|
||||||
|
if i < 3:
|
||||||
|
continue
|
||||||
|
zeile = zeile.strip().split(";")
|
||||||
|
if zeile[1] == "" and zeile[2] == "" and zeile[3] == "":
|
||||||
|
nummer_beobachtungsgruppeID += 1
|
||||||
|
# print("Standpunkt: ",nummer_beobachtungsgruppeID ,zeile[0])
|
||||||
|
standpunkt = zeile[0]
|
||||||
|
|
||||||
|
if nummer_zielpunkt % 6 != 0:
|
||||||
|
liste_fehlerhafte_zeile.append(i)
|
||||||
|
|
||||||
|
nummer_zielpunkt = 0
|
||||||
|
liste_zielpunkte_hs = []
|
||||||
|
liste_zielpunkte_vs2 = []
|
||||||
|
liste_zielpunkte_vs3 = []
|
||||||
|
else:
|
||||||
|
nummer_zielpunkt += 1
|
||||||
|
if zeile[0] not in liste_zielpunkte_hs:
|
||||||
|
liste_zielpunkte_hs.append(zeile[0])
|
||||||
|
if zeile[0] in liste_zielpunkte_vs3:
|
||||||
|
# print(f"{nummer_zielpunkt} VS3 HS1 {zeile}")
|
||||||
|
liste_beobachtungen_vorbereitung.append(
|
||||||
|
[nummer_beobachtungsgruppeID, "VS3", "HS1", standpunkt, zeile[0], zeile[1],
|
||||||
|
zeile[2], zeile[3]])
|
||||||
|
elif zeile[0] in liste_zielpunkte_vs2:
|
||||||
|
# print(f"{nummer_zielpunkt} VS2 HS1 {zeile}")
|
||||||
|
liste_beobachtungen_vorbereitung.append(
|
||||||
|
[nummer_beobachtungsgruppeID, "VS2", "HS1", standpunkt, zeile[0], zeile[1],
|
||||||
|
zeile[2], zeile[3]])
|
||||||
|
else:
|
||||||
|
# print(f"{nummer_zielpunkt} VS1 HS1 {zeile}")
|
||||||
|
liste_beobachtungen_vorbereitung.append(
|
||||||
|
[nummer_beobachtungsgruppeID, "VS1", "HS1", standpunkt, zeile[0], zeile[1],
|
||||||
|
zeile[2],
|
||||||
|
zeile[3]])
|
||||||
|
|
||||||
|
else:
|
||||||
|
liste_zielpunkte_hs.remove(zeile[0])
|
||||||
|
if zeile[0] in liste_zielpunkte_vs3:
|
||||||
|
# print(f"{nummer_zielpunkt} VS3 HS2 {zeile}")
|
||||||
|
liste_beobachtungen_vorbereitung.append(
|
||||||
|
[nummer_beobachtungsgruppeID, "VS3", "HS2", standpunkt, zeile[0], zeile[1],
|
||||||
|
zeile[2],
|
||||||
|
zeile[3]])
|
||||||
|
|
||||||
|
elif zeile[0] in liste_zielpunkte_vs2:
|
||||||
|
if zeile[0] not in liste_zielpunkte_vs3:
|
||||||
|
liste_zielpunkte_vs3.append(zeile[0])
|
||||||
|
# print(f"{nummer_zielpunkt} VS2 HS2 {zeile}")
|
||||||
|
liste_beobachtungen_vorbereitung.append(
|
||||||
|
[nummer_beobachtungsgruppeID, "VS2", "HS2", standpunkt, zeile[0], zeile[1],
|
||||||
|
zeile[2],
|
||||||
|
zeile[3]])
|
||||||
|
else:
|
||||||
|
if zeile[0] not in liste_zielpunkte_vs2:
|
||||||
|
liste_zielpunkte_vs2.append(zeile[0])
|
||||||
|
# print(f"{nummer_zielpunkt} VS1 HS2 {zeile}")
|
||||||
|
liste_beobachtungen_vorbereitung.append(
|
||||||
|
[nummer_beobachtungsgruppeID, "VS1", "HS2", standpunkt, zeile[0], zeile[1],
|
||||||
|
zeile[2],
|
||||||
|
zeile[3]])
|
||||||
|
|
||||||
|
if liste_fehlerhafte_zeile == []:
|
||||||
|
# print(f"Einlesen der Datei {pfad_datei} erfolgreich beendet.")
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
f"Das Einlesen der Datei {pfad_datei} wurde abgebrochen.\nBitte bearbeiten Sie die Zeilen rund um: {", ".join(map(str, liste_fehlerhafte_zeile))} in der csv-Datei und wiederholen Sie den Import.")
|
||||||
|
Import_fortsetzen = False
|
||||||
|
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
f"Der Import wurde abgebrochen, weil die Beobachtungen aus der Datei {pfad_datei} bereits in der Datenbank vorhanden sind.")
|
||||||
|
|
||||||
|
if Import_fortsetzen:
|
||||||
|
liste_beobachtungen_import = []
|
||||||
|
|
||||||
|
while len(liste_beobachtungen_vorbereitung) > 0:
|
||||||
|
liste_aktueller_zielpunkt = liste_beobachtungen_vorbereitung[0]
|
||||||
|
aktueller_zielpunkt = liste_aktueller_zielpunkt[4]
|
||||||
|
# print(liste_beobachtungen_vorbereitung[0])
|
||||||
|
|
||||||
|
for index in range(1, len(liste_beobachtungen_vorbereitung)):
|
||||||
|
liste = liste_beobachtungen_vorbereitung[index]
|
||||||
|
|
||||||
|
if liste[4] == aktueller_zielpunkt:
|
||||||
|
# print(liste)
|
||||||
|
richtung1 = self.string_to_decimal(liste_aktueller_zielpunkt[5])
|
||||||
|
richtung2 = self.string_to_decimal(liste[5]) - Decimal(200)
|
||||||
|
zenitwinkel_vollsatz = (self.string_to_decimal(liste_aktueller_zielpunkt[6]) - self.string_to_decimal(
|
||||||
|
liste[6]) + 400) / 2
|
||||||
|
distanz_vollsatz = (self.string_to_decimal(liste_aktueller_zielpunkt[7]) + self.string_to_decimal(
|
||||||
|
liste[7])) / 2
|
||||||
|
if richtung2 < 0:
|
||||||
|
richtung2 += Decimal(400)
|
||||||
|
elif richtung2 > 400:
|
||||||
|
richtung2 -= Decimal(400)
|
||||||
|
richtung_vollsatz = (richtung1 + richtung2) / 2
|
||||||
|
|
||||||
|
# print(richtung_vollsatz)
|
||||||
|
# print(zenitwinkel_vollsatz)
|
||||||
|
# print(distanz_vollsatz)
|
||||||
|
liste_beobachtungen_import.append(
|
||||||
|
[liste[0], liste[3], liste[4], richtung_vollsatz, zenitwinkel_vollsatz, distanz_vollsatz])
|
||||||
|
|
||||||
|
del liste_beobachtungen_vorbereitung[index]
|
||||||
|
del liste_beobachtungen_vorbereitung[0]
|
||||||
|
break
|
||||||
|
|
||||||
|
if instrumentenID not in liste_instrumentenid:
|
||||||
|
Import_fortsetzen = False
|
||||||
|
print(
|
||||||
|
"Der Import wurde abgebrochen. Bitte eine gültige InstrumentenID eingeben. Bei Bedarf ist das Instrument neu anzulegen.")
|
||||||
|
|
||||||
|
if Import_fortsetzen:
|
||||||
|
con = sqlite3.connect(self.pfad_datenbank)
|
||||||
|
cursor = con.cursor()
|
||||||
|
for beobachtung_import in liste_beobachtungen_import:
|
||||||
|
cursor.execute(
|
||||||
|
"INSERT INTO Beobachtungen (punktnummer_sp, punktnummer_zp, instrumenteID, beobachtungsgruppeID, tachymeter_richtung, tachymeter_zenitwinkel, tachymeter_distanz, dateiname) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
|
(beobachtung_import[1], beobachtung_import[2], instrumentenID, beobachtung_import[0],
|
||||||
|
float(beobachtung_import[3]), float(beobachtung_import[4]), float(beobachtung_import[5]),
|
||||||
|
pfad_datei))
|
||||||
|
con.commit()
|
||||||
|
cursor.close()
|
||||||
|
con.close()
|
||||||
|
print(f"Der Import der Datei {pfad_datei} wurde erfolgreich abgeschlossen.")
|
||||||
Reference in New Issue
Block a user