From 125a24dc26ddf46b3fb4fbc81215bd6fb6eae5af Mon Sep 17 00:00:00 2001 From: tanaydin Date: Thu, 14 Mar 2013 13:54:07 +0200 Subject: [PATCH] index sizes are now in human readable format. --- app/classes/BaseController.php | 32 ++++++++++++++++++++++++++++++++ app/controllers/collection.php | 6 +++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/classes/BaseController.php b/app/classes/BaseController.php index 6f75fa1..594c4fd 100644 --- a/app/classes/BaseController.php +++ b/app/classes/BaseController.php @@ -229,6 +229,38 @@ protected function _highlight($var, $format = "array", $label = false) { return $string; } + /** + * Export IndexSizes as string. + * + * @param mixed $var variable to be exported + * @return string + */ + protected function _highlightIndexSizes($var) { + $string = ""; + $c = 0; + foreach($var as $key => $value) { + if ($value < 1024) { + $formatted_size = $value . "b"; + } else if ($value < 1024 * 1024) { + $formatted_size = round($value/1024, 2) . " kb"; + } else if ($value < 1024 * 1024 * 1024) { + $formatted_size = round($value/1024/1024, 2) . " mb"; + } else if ($value < 1024 * 1024 * 1024 * 1024) { + $formatted_size = round($value/1024/1024/1024, 2) . " gb"; + } + if (($c%2) == 0) { + $bgc = "#fff"; + } else { + $bgc = "#eee"; + } + $string .= ""; + $string .= ""; + $c++; + } + $string .= "
" . $key . "" . $formatted_size . "
"; + return $string; + } + /** * format bytes to human size * diff --git a/app/controllers/collection.php b/app/controllers/collection.php index 3c454bd..33d59f6 100644 --- a/app/controllers/collection.php +++ b/app/controllers/collection.php @@ -785,7 +785,11 @@ public function doCollectionStats() { $this->stats = $ret; foreach ($this->stats as $index => $stat) { if (is_array($stat)) { - $this->stats[$index] = $this->_highlight($stat, "json"); + if ($index == "indexSizes") { + $this->stats[$index] = $this->_highlightIndexSizes($stat, "json"); + } else { + $this->stats[$index] = $this->_highlight($stat); + } } } }