| GPS Koordinaten |
gps_lat && $address->gps_long): ?>
diff --git a/application/ADBHausnummer/ADBHausnummerModel.php b/application/ADBHausnummer/ADBHausnummerModel.php
index 30b3deae2..835cdd033 100644
--- a/application/ADBHausnummer/ADBHausnummerModel.php
+++ b/application/ADBHausnummer/ADBHausnummerModel.php
@@ -237,6 +237,17 @@ class ADBHausnummerModel {
$where .= " AND Hausnummer.`oaid` = '$oaid'";
}
}
+
+ if(array_key_exists("tool_building_type", $filter)) {
+ $tool_building_type = $filter['tool_building_type'];
+ if(is_numeric($tool_building_type)) {
+ $where .= " AND Hausnummer.tool_building_type=$tool_building_type";
+ } elseif(is_array($tool_building_type) && count($tool_building_type)) {
+ $where .= " AND Hausnummer.tool_building_type IN (". implode(",", $tool_building_type).")";
+ } elseif($tool_building_type === null) {
+ $where .= " AND Hausnummer.tool_building_type IS NULL";
+ }
+ }
if(array_key_exists("oaid%", $filter)) {
$oaid = FronkDB::singleton()->escape($filter['oaid%']);
diff --git a/application/AddressDB/AddressDB.php b/application/AddressDB/AddressDB.php
index 163c20c3d..a19c8567d 100644
--- a/application/AddressDB/AddressDB.php
+++ b/application/AddressDB/AddressDB.php
@@ -470,6 +470,8 @@ class AddressDB {
$hausnummer_data['grund_nr'] = $data['grund_nr'];
$hausnummer_data['gdaeigenschaft'] = $data['gdaeigenschaft'];
$hausnummer_data['meridian'] = $data['meridian'];
+ $hausnummer_data['tool_building_type'] = $data['tool_building_type'] ?? '0';
+ $hausnummer_data['tool_building_type_override'] = $data['tool_building_type_override'] ?? '0';
$hausnummer_data['rw'] = ($data['rw']) ? str_replace(",",".", $data['rw']) : null;
$hausnummer_data['hw'] = ($data['hw']) ? str_replace(",",".", $data['hw']) : null;
diff --git a/application/AddressDB/AddressDBController.php b/application/AddressDB/AddressDBController.php
index 2d5d8fe62..92b7cedcc 100644
--- a/application/AddressDB/AddressDBController.php
+++ b/application/AddressDB/AddressDBController.php
@@ -294,7 +294,7 @@ class AddressDBController extends mfBaseController {
if(!$this->me->is("Admin")) {
$required[] = "netzgebiet_id";
}
- foreach(['adrcd','extref','rimo_id','netzgebiet_id','strasse','hausnummer','stiege','plz','ortschaft','gemeinde','grund_nr','gdaeigenschaft','meridian','rw','hw','gps_lat','gps_long','unit_count','visibility'] as $field) {
+ foreach(['adrcd','extref','rimo_id','netzgebiet_id','strasse','hausnummer','stiege','plz','ortschaft','gemeinde','grund_nr','gdaeigenschaft','meridian','rw','hw','gps_lat','gps_long','unit_count','visibility','tool_building_type', 'tool_building_type_override'] as $field) {
if(in_array($field, $required)) {
if(!trim($r->$field)) {
$this->layout()->setFlash("'".ucfirst($field)."' darf nicht leer sein!", "error");
diff --git a/db/migrations/20250527123000_adb_hausnummer_add_tool_type.php b/db/migrations/20250527123000_adb_hausnummer_add_tool_type.php
new file mode 100644
index 000000000..e418d7856
--- /dev/null
+++ b/db/migrations/20250527123000_adb_hausnummer_add_tool_type.php
@@ -0,0 +1,29 @@
+getEnvironment() == "addressdb") {
+ $Hausnummer = $this->table("Hausnummer");
+ $Hausnummer->addColumn("tool_building_type", "integer", ["default" => 0, "null" => false])
+ ->addColumn("tool_building_type_override", "boolean", ["default" => 0, "null" => false]);
+
+ $Hausnummer->update();
+ }
+ }
+
+ public function down(): void
+ {
+ if($this->getEnvironment() == "addressdb") {
+ $Hausnummer = $this->table("Hausnummer");
+ if($Hausnummer->hasColumn("tool_building_type")) $Hausnummer->removeColumn("tool_building_type");
+ if($Hausnummer->hasColumn("tool_building_type_override")) $Hausnummer->removeColumn("tool_building_type_override");
+
+ $Hausnummer->update();
+ }
+ }
+}
\ No newline at end of file
diff --git a/lib/ProgressLogger/ProgressLogger.php b/lib/ProgressLogger/ProgressLogger.php
new file mode 100644
index 000000000..d51fb366c
--- /dev/null
+++ b/lib/ProgressLogger/ProgressLogger.php
@@ -0,0 +1,64 @@
+totalItems = $totalItems;
+ $this->processedCount = 0;
+ $this->startTime = microtime(true);
+ $this->lastOutputTime = 0;
+ $this->outputInterval = $outputInterval;
+ }
+
+ public function incrementAndLog() {
+ $this->processedCount++;
+ $currentTime = microtime(true);
+
+ // Only update the console if enough time has passed or it's the last item
+ if (($currentTime - $this->lastOutputTime > $this->outputInterval) || ($this->processedCount === $this->totalItems)) {
+ $this->logProgress();
+ $this->lastOutputTime = $currentTime;
+ }
+ }
+
+ private function logProgress() {
+ $elapsedTime = microtime(true) - $this->startTime;
+ $itemsPerSecond = ($this->processedCount > 0) ? ($this->processedCount / $elapsedTime) : 0;
+ $remainingItems = $this->totalItems - $this->processedCount;
+ $estimatedTimeRemaining = ($itemsPerSecond > 0) ? ($remainingItems / $itemsPerSecond) : 0;
+
+ $hours = floor($estimatedTimeRemaining / 3600);
+ $minutes = floor(($estimatedTimeRemaining % 3600) / 60);
+ $seconds = floor($estimatedTimeRemaining % 60);
+
+ printf("\rProcessing: %d/%d (%.2f%%) | Elapsed: %s | Remaining: %02d:%02d:%02d",
+ $this->processedCount,
+ $this->totalItems,
+ ($this->processedCount / $this->totalItems) * 100,
+ gmdate("H:i:s", $elapsedTime),
+ $hours,
+ $minutes,
+ $seconds
+ );
+
+ // If all items are processed, add a newline
+ if ($this->processedCount === $this->totalItems) {
+ echo "\n";
+ }
+ }
+
+ public function startMessage() {
+ echo "Starting update for {$this->totalItems} items...\n";
+ }
+
+ public function finishMessage($type = 'items') {
+ echo "Finished! Updated {$this->processedCount} $type.\n";
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/scripts/addressdb/update_hausnummer_tool_type.php b/scripts/addressdb/update_hausnummer_tool_type.php
new file mode 100644
index 000000000..14c8fbef5
--- /dev/null
+++ b/scripts/addressdb/update_hausnummer_tool_type.php
@@ -0,0 +1,49 @@
+#!/usr/bin/php
+id);
+define("INTERNAL_USER_USERNAME", $me->username);
+define("MFBASE_BYPASS_LOGIN", true);
+
+$logger = new ProgressLogger(ADBHausnummerModel::count(["netzgebiet_id" => true]));
+$logger->startMessage();
+
+$network_owner_id_map = array_reduce(NetworkModel::getAll(), function($carry, $network) {
+ $carry[$network->adb_netzgebiet_id] = $network->owner_id;
+ return $carry;
+}, []);
+
+foreach(ADBHausnummerModel::search(["netzgebiet_id" => true], 1) as $hausnummer) {
+ $logger->incrementAndLog();
+
+ $unit_count = ADBWohneinheitModel::count(['hausnummer_id' => $hausnummer->id]);
+ if ($hausnummer->id === 1597668) echo "Processing hausnummer ID: {$hausnummer->id}, Unit Count: {$unit_count}\n"; // New line for each hausnummer
+ if($hausnummer->tool_building_type_override == 1) continue;
+
+ $hausnummer->tool_building_type = 0; // Unknown
+ if (isset($network_owner_id_map[$hausnummer->netzgebiet_id]) && $network_owner_id_map[$hausnummer->netzgebiet_id] == 4807) {
+ if($unit_count > 2) $hausnummer->tool_building_type = 2;
+ else if ($unit_count > 0) $hausnummer->tool_building_type = 1;
+ } else {
+ if ($unit_count > 3) $hausnummer->tool_building_type = 2;
+ else if ($unit_count > 0) $hausnummer->tool_building_type = 1;
+ }
+
+ if(!$hausnummer->save()) {
+ echo "\nError saving hausnummer ".$hausnummer->id."\n"; // New line for errors
+ }
+}
+
+$logger->finishMessage("Hausnummern");
+
+?>
\ No newline at end of file
|