108 lines
2.4 KiB
PHP
108 lines
2.4 KiB
PHP
#!/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);
|
|
|
|
$bundeslaender = [
|
|
"Burgenland",
|
|
"Kaernten",
|
|
"Niederoesterreich",
|
|
"Oberoesterreich",
|
|
"Salzburg",
|
|
"Steiermark",
|
|
"Tirol",
|
|
"Vorarlberg",
|
|
"Wien"
|
|
];
|
|
|
|
$db = FronkDB::singleton();
|
|
$log = mfLoghandler::singleton();
|
|
|
|
$start = date("U");
|
|
$last_ts = $start;
|
|
echo "Begin: ".date("Y-m-d H:i:s")."\n";
|
|
|
|
$c = 0;
|
|
|
|
$queries = [];
|
|
$insert_values = [];
|
|
|
|
foreach($bundeslaender as $bland) {
|
|
$filename = __DIR__ . "/csv/StatistikAustria_100mRaster_Anschlusspotential2022_$bland.csv";
|
|
|
|
if(!file_exists($filename)) {
|
|
die("File $filename not found!\n");
|
|
}
|
|
|
|
echo "$bland\n";
|
|
|
|
$input = fopen($filename, "r");
|
|
|
|
$bom = "\xef\xbb\xbf";
|
|
if(fgets($input, 4) !== $bom) {
|
|
// BOM not found - rewind pointer to start of file.
|
|
rewind($input);
|
|
|
|
}
|
|
|
|
$headers = [];
|
|
|
|
$i = 0;
|
|
while($csv = fgetcsv($input, 0, ";")) {
|
|
$i++;
|
|
|
|
if($i == 1) {
|
|
foreach($csv as $key => $name) {
|
|
$headers[$name] = $key;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
if(!trim($csv[0])) {
|
|
continue;
|
|
}
|
|
|
|
$raster = trim($csv[$headers["rasterid"]]);
|
|
$unit_count = trim($csv[$headers["anschlusspotential"]]);
|
|
|
|
$sql = "INSERT INTO `Rtr100mRaster` (`raster`,`unit_count`,`create_by`,`edit_by`,`create`,`edit`) VALUES";
|
|
$insert_values[] = "('$raster',$unit_count,1,1,1733431100,1733431100)";
|
|
|
|
$c++;
|
|
|
|
|
|
if($c % 100000 == 0) {
|
|
runQuery($sql.implode(",", $insert_values), $c);
|
|
$insert_values = [];
|
|
}
|
|
}
|
|
if(count($insert_values)) {
|
|
runQuery($sql . implode(",", $insert_values), $c);
|
|
$insert_values = [];
|
|
$c = 0;
|
|
}
|
|
echo "\n";
|
|
}
|
|
|
|
function runQuery($sql, $c) {
|
|
global $db;
|
|
global $last_ts;
|
|
|
|
mysqli_query($db->link, $sql);
|
|
|
|
$now = date("U");
|
|
echo "$c: ".date("Y-m-d H:i:s")." - delta ".($now - $last_ts)."\n";
|
|
$last_ts = $now;
|
|
} |