Added scripts to update units and split preorders with connection_count

> 1
This commit is contained in:
Frank Schubert
2023-04-19 17:20:36 +02:00
parent df088b56eb
commit c5a9e3e9d7
7 changed files with 244 additions and 3 deletions
+111
View File
@@ -0,0 +1,111 @@
#!/usr/bin/php
<?php
//require 'vendor/autoload.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);
$ignore_preorders = [];
$campaign_prem_nord = 5;
$same_unit_count = 0;
$missing_units = [];
$missing_doors = [];
$total = 0;
$c = 0;
foreach(PreorderModel::search(["deleted" => 0, "preordercampaign_id" => $campaign_prem_nord, "connection_count" => 2]) as $preorder) {
// check if we have enough units with extref
$wohneinheiten = ADBWohneinheitModel::search(["hausnummer_id" => $preorder->adb_hausnummer_id]);
$unit_count = count($wohneinheiten);
if($unit_count < $preorder->connection_count) {
$mu = [];
$mu['preorder'] = $preorder;
$mu['unit_count'] = $unit_count;
$missing_units[] = $mu;
//echo "Nicht genug Wohneinheiten - Preorder id ".$preorder->id.": ".count($wohneinheiten)." - need ".$preorder->connection_count."\n";
continue;
}
$available_units = [];
foreach($wohneinheiten as $unit) {
if(!PreorderModel::getFirst(["adb_wohneinheit_id" => $unit->id])) {
if($unit->tuer || preg_match('/^Top\s+\d+$/', $unit->zusatz)) {
$available_units[] = $unit;
}
}
}
if($preorder->connection_count > count($available_units)) {
$md = [];
$md["unit_count"] = $unit_count;
$md["door_count"] = count($available_units);
$md["preorder"] = $preorder;
$missing_doors[] = $md;
//echo "Not enough units with tuer (hausnummer id ".$preorder->adb_hausnummer_id.") units total: ".count($wohneinheiten)."; units with tuer: ".count($available_units)."; preorder connection count: ".$preorder->connection_count."\n";
continue;
}
// create new Preorders with available units
// then set original Preorder deleted
echo "Creating ".$preorder->connection_count." new preorders\n";
for($i = 0; $i < $preorder->connection_count; $i++) {
if(!$available_units[$i]->oaid) {
$available_units[$i]->oaid = $available_units[$i]->getNewOAID();
$available_units[$i]->save();
}
$new_preorder = clone($preorder);
$new_preorder->ucode = $preorder->ucode.".".($i+1);
$new_preorder->connection_count = 1;
$new_preorder->adb_wohneinheit_id = $available_units[$i]->id;
$new_preorder->oaid = $available_units[$i]->oaid;
//var_dump($new_preorder);exit;
$new_preorder->save();
}
$preorder->deleted = 1;
$preorder->delete_reason = "connection_split";
$preorder->save();
$i++;
}
echo "Adresse;Bestellte Anschlüsse;Vorhandene Wohneinheiten;Vorhanden Wohneinheiten mit Tür/Top Nummer\n";
foreach($missing_units as $mu) {
$preorder = $mu['preorder'];
/*echo "Adresse: ".$preorder->adb_hausnummer->strasse->name." ".$preorder->adb_hausnummer->hausnummer;
echo " | Bestellte Anschlüsse: ".$preorder->connection_count;
echo " | Vorhandene Wohneinheiten: ".$mu['unit_count'];*/
echo '"'.$preorder->adb_hausnummer->strasse->name.'";';
echo $preorder->connection_count.';';
echo $mu['unit_count'].';';
echo ';';
echo "\n";
}
foreach($missing_doors as $md) {
$preorder = $md['preorder'];
/*echo "Adresse: ".$preorder->adb_hausnummer->strasse->name." ".$preorder->adb_hausnummer->hausnummer;
echo " | Bestellte Anschlüsse: ".$preorder->connection_count;
echo " | Vorhandene Wohneinheiten: ".$md['unit_count'];
echo " | Vorhandene Tür/Top Nummern: ".$md["door_count"];*/
echo '"'.$preorder->adb_hausnummer->strasse->name.'";';
echo $preorder->connection_count.';';
echo $md["unit_count"].';';
echo $md["door_count"].';';
echo "\n";
}
echo "Processed $total, created $c preorders\n";
+88
View File
@@ -0,0 +1,88 @@
#!/usr/bin/php
<?php
//require 'vendor/autoload.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);
$ignore_preorders = [];
$campaign_prem_nord = 5;
$same_unit_count = 0;
$i = 0;
foreach(PreorderModel::search(['preordercampaign_id' => $campaign_prem_nord, 'adb_wohneinheit_id' => null, 'connection_count' => 1, "connection_type" => "single-dwelling", "deleted" => 0]) as $preorder) {
if(in_array($preorder->id, $ignore_preorders)) continue;
//if($preorder->connection_type != "single-dwelling") continue;
if($preorder->adb_wohneinheit_id) {
echo "hat eh a unit\n";
continue;
}
if(!$preorder->adb_hausnummer_id) {
echo "missing hausnummer Preorder ".$preorder->id."\n";
continue;
}
$wohneinheiten = ADBWohneinheitModel::search(['hausnummer_id' => $preorder->adb_hausnummer_id]);
if(!count($wohneinheiten)) {
echo "Keine Wohneinheit gefunden. Preorder ".$preorder->id."\n";
}
$unit_count = count($wohneinheiten);
//echo "$unit_count\n";
if($unit_count === 1) {
$same_unit_count++;
$unit = $wohneinheiten[0];
$preorder->adb_wohneinheit_id = $unit->id;
$preorder->save();
continue;
}
if($unit_count > 1 && $unit_count <= 4) {
// assume its single-dwelling with erroneously high door count
$unit_candidates = [];
foreach($wohneinheiten as $unit) {
if(!$unit->tuer) continue;
if($unit->tuer > 1) {
$unit_candidates[$unit->tuer] = $unit;
}
}
/*if(!count($unit_candidates)) {
foreach($wohneinheiten as $unit) {
if(!$unit->zusatz) continue;
if(preg_match('/Top\s+\d+/i',$unit->zusatz)) {
$unit_candidates[$unit->zusatz] = $unit;
}
}
}*/
if(count($unit_candidates)) {
ksort($unit_candidates, SORT_NUMERIC);
$new_unit = array_shift($unit_candidates);
$preorder->adb_wohneinheit_id = $new_unit->id;
$preorder->save();
echo "$i Wohneinheit saved\n";
continue;
}
}
$i++;
}
echo "Same unit count: $same_unit_count (".$i - $same_unit_count." with different unit count)\n";
echo "Processed $i Preorders\n";