added new tool type field

This commit is contained in:
Luca Haid
2025-05-27 14:04:36 +02:00
parent 5a8fef9611
commit ece7dcf806
9 changed files with 207 additions and 14 deletions

View File

@@ -134,16 +134,42 @@
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="hausnummer">Hausnummer *</label>
<div class="col-lg-10">
<?php if(is_array($save_data) && array_key_exists("hausnummer", $save_data)): ?>
<input type="text" class="form-control" name="hausnummer" id="hausnummer" value="<?=$save_data['hausnummer']?>">
<?php else: ?>
<input type="text" class="form-control" name="hausnummer" id="hausnummer" value="<?=$address->hausnummer?>">
<?php endif; ?>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="hausnummer">Hausnummer *</label>
<div class="col-lg-10">
<?php if(is_array($save_data) && array_key_exists("hausnummer", $save_data)): ?>
<input type="text" class="form-control" name="hausnummer" id="hausnummer" value="<?=$save_data['hausnummer']?>">
<?php else: ?>
<input type="text" class="form-control" name="hausnummer" id="hausnummer" value="<?=$address->hausnummer?>">
<?php endif; ?>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="tool_building_type">Gebäudetyp</label>
<div class="col-lg-10">
<select name="tool_building_type" id="tool_building_type" class="form-control">
<option value="">Alle</option>
<option value="0" <?=($address->tool_building_type == "0") ? "selected='selected'" : ""?>>Unbekannt</option>
<option value="1" <?=($address->tool_building_type == "1") ? "selected='selected'" : ""?>>EFH</option>
<option value="2" <?=($address->tool_building_type == "2") ? "selected='selected'" : ""?>>MFH</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="tool_building_type_override">Gebäudetyp überschreiben</label>
<div class="col-lg-10" style="padding-left: 40px">
<?php
$isChecked = false;
if ($address->tool_building_type_override == 1) {
$isChecked = true;
}
?>
<input type="hidden" name="tool_building_type_override" value="0">
<input type="checkbox" class="form-check-input" name="tool_building_type_override" id="tool_building_type_override" value="1" <?= $isChecked ? "checked" : "" ?>>
</div>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="hausnummer">Stiege</label>

View File

@@ -153,10 +153,19 @@
<div class="row mt-1">
<div class="col-2">
<label class="form-label" for="filter_rimo_id">Rimo External ID</label>
<input type="text" class="form-control" name="filter[rimo_id]" id="filter_rimo_id" value="<?=(array_key_exists("rimo_id", $filter)) ? $filter['rimo_id'] : ""?>" />
</div>
<label class="form-label" for="filter_rimo_id">Rimo External ID</label>
<input type="text" class="form-control" name="filter[rimo_id]" id="filter_rimo_id" value="<?=(array_key_exists("rimo_id", $filter)) ? $filter['rimo_id'] : ""?>" />
</div>
<div class="col-2">
<label class="form-label" for="filter_tool_building_type">Gebäude Typ</label>
<select name="filter[tool_building_type]" id="filter_tool_building_type" class="form-control">
<option value="">Alle</option>
<option value="0" <?=(array_key_exists("tool_building_type", $filter) && $filter['tool_building_type'] == "0") ? "selected='selected'" : ""?>>Unbekannt</option>
<option value="1" <?=(array_key_exists("tool_building_type", $filter) && $filter['tool_building_type'] == "1") ? "selected='selected'" : ""?>>EFH</option>
<option value="2" <?=(array_key_exists("tool_building_type", $filter) && $filter['tool_building_type'] == "2") ? "selected='selected'" : ""?>>MFH</option>
</select>
</div>
</div>
<div class="row mt-2">

View File

@@ -57,6 +57,9 @@
<th>Wohneinheiten</th>
<td><?=count($address->wohneinheiten)?></td>
</tr><tr>
<th>Tool-Gebäudetyp</th>
<td><?= $address->tool_building_type == 0 ? "Unbekannt" : ($address->tool_building_type == 1 ? "EFH" : "MFH") ?></td>
</tr><tr>
<th>GPS Koordinaten</th>
<td>
<?php if($address->gps_lat && $address->gps_long): ?>

View File

@@ -238,6 +238,17 @@ class ADBHausnummerModel {
}
}
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%']);
if($oaid) {

View File

@@ -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;

View File

@@ -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");

View File

@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class AdbHausnummerAddToolType extends AbstractMigration
{
public function up(): void
{
if($this->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();
}
}
}

View File

@@ -0,0 +1,64 @@
<?php
class ProgressLogger {
private $totalItems;
private $startTime;
private $processedCount;
private $lastOutputTime;
private $outputInterval; // in seconds
public function __construct($totalItems, $outputInterval = 1) {
$this->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";
}
}
?>

View File

@@ -0,0 +1,49 @@
#!/usr/bin/php
<?php
require("../../config/config.php");
define('FRONKDB_SQLDEBUG',false);
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED));
require_once(LIBDIR."/mvcfronk/mfRouter/mfRouter.php");
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseModel.php");
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php");
$me = new User(1);
define("INTERNAL_USER_ID", $me->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");
?>