瀏覽代碼

Merge branch 'master' of bn.git:plabudda/se

Piotr Labudda 9 年之前
父節點
當前提交
98dfc2a003
共有 2 個文件被更改,包括 17 次插入13 次删除
  1. 13 9
      SE/dev/php-cli/biale_plamy_class.php
  2. 4 4
      SE/dev/php-cli/biale_plamy_class_usage.php

+ 13 - 9
SE/dev/php-cli/biale_plamy_class.php

@@ -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']}`";

+ 4 - 4
SE/dev/php-cli/biale_plamy_class_usage.php

@@ -4,7 +4,7 @@ require("biale_plamy_class.php");
 
 $test = new bialePlamy(array("pointsTable"=>"Rozdzielcza_test2_bzyk_punkty_adresowe", "origWaysTable"=>"Rozdzielcza_test2_bzyk_drogi"));
 $test->enableShowProgress();
-$test->loadCache();
+$test->loadCache("dupa");
 
 
 //$test->generateWays();
@@ -14,9 +14,9 @@ $test->loadCache();
 //$test->generateWaysLenghts();
 $test->generateLongWays();
 
-$test->saveCache();
-$test->saveXML();
-$test->saveArrays();
+//$test->saveCache();
+//$test->saveXML();
+//$test->saveArrays();
 
 
 //echo $test->printArray('joins2ways');