|
|
@@ -14,7 +14,7 @@ class showProgress {
|
|
|
|
|
|
private $startTime;
|
|
|
private $i = 0, $l = 0, $left = 0, $diff = 0, $n, $msg;
|
|
|
- private $strlen = 40;
|
|
|
+ private $strlen = 50;
|
|
|
|
|
|
public function __construct($msg, $n = null) {
|
|
|
$this->msg = str_pad($msg, $this->strlen);
|
|
|
@@ -39,7 +39,7 @@ class showProgress {
|
|
|
$this->left = $left;
|
|
|
if ($left > 59) $left = floor($left / 60) . "m " . ($left % 60);
|
|
|
if ($diff > 59) $diff = floor($diff / 60) . "m " . ($diff % 60);
|
|
|
- echo "\r".str_pad("", $this->strlen+60);
|
|
|
+ echo "\r".str_pad("", $this->strlen+70);
|
|
|
echo "\r{$this->msg}: {$p}% (elapsed {$diff}s, estimated remaining {$left}s)";
|
|
|
}
|
|
|
}
|
|
|
@@ -51,7 +51,7 @@ class showProgress {
|
|
|
$diff = $curTime - $this->startTime;
|
|
|
$diff = floor($diff);
|
|
|
if ($diff > 59) $diff = floor($diff / 60) . "m " . ($diff % 60);
|
|
|
- echo "\r".str_pad("", $this->strlen+60);
|
|
|
+ echo "\r".str_pad("", $this->strlen+70);
|
|
|
echo "\r{$this->msg}: OK (done in {$diff}s)\n";
|
|
|
}
|
|
|
}
|
|
|
@@ -91,10 +91,12 @@ class bialePlamy {
|
|
|
private $dataArrays = array('drogi_asText', 'joins_asText', 'ways_asText', 'xpoints_asText', 'points_asText', 'przylacza_asText', 'waysLengths', 'longWays_asText',
|
|
|
'ways2drogi', 'drogi2ways', 'ways2joins', 'joins2ways', 'points2xpoints', 'xpoints2points', 'przylacza2joins', 'przylacza2points', 'points2joins');
|
|
|
|
|
|
- public function saveCache() {
|
|
|
+ public function saveCache($prefix = '') {
|
|
|
+ if (!preg_match("/^[[:alnum:]]*$/", $prefix)) throw new Exception("saveCache() :: prefix error");
|
|
|
+ if ($prefix) $prefix .= "_";
|
|
|
foreach ($this->dataArrays as $array) if ($this->$array) {
|
|
|
if ($this->showProgress) $progress = new showProgress("Saving {$array}");
|
|
|
- file_put_contents('/tmp/save_'.$array.'.txt', serialize($this->$array));
|
|
|
+ file_put_contents('/tmp/save_'.$prefix.$array.'.txt', serialize($this->$array));
|
|
|
if ($this->showProgress) $progress->stop();
|
|
|
}
|
|
|
}
|
|
|
@@ -138,11 +140,13 @@ class bialePlamy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function loadCache() {
|
|
|
+ public function loadCache($prefix = '') {
|
|
|
try {
|
|
|
- foreach ($this->dataArrays as $array) if (file_exists('/tmp/save_'.$array.'.txt')) {
|
|
|
+ if (!preg_match("/^[[:alnum:]]*$/", $prefix)) throw new Exception("saveCache() :: prefix error");
|
|
|
+ if ($prefix) $prefix .= "_";
|
|
|
+ foreach ($this->dataArrays as $array) if (file_exists('/tmp/save_'.$prefix.$array.'.txt')) {
|
|
|
if ($this->showProgress) $progress = new showProgress("Loading {$array}");
|
|
|
- $this->$array = unserialize(file_get_contents('/tmp/save_'.$array.'.txt'));
|
|
|
+ $this->$array = unserialize(file_get_contents('/tmp/save_'.$prefix.$array.'.txt'));
|
|
|
if ($this->showProgress) $progress->stop();
|
|
|
}
|
|
|
} catch (Exception $e) {
|
|
|
@@ -152,7 +156,7 @@ class bialePlamy {
|
|
|
|
|
|
private function saveDB($src, $dst) {
|
|
|
try {
|
|
|
- if ($this->showProgress) $progress = new showProgress("Saving points table");
|
|
|
+ if ($this->showProgress) $progress = new showProgress("Saving table {$dst}");
|
|
|
DB::getPDO()->query("truncate table `{$dst}`");
|
|
|
$result = DB::getPDO()->fetchall("show fields from `{$src}`");
|
|
|
foreach ($result as $col) $cols[] = "`{$col['Field']}`";
|