[icinga-checkins] icinga.org: icingaweb2/feature/translation-msgfmt-statistics-7052: Add StatisticsCommand class

git at icinga.org git at icinga.org
Wed Jan 4 14:03:40 CET 2017


Module: icingaweb2
Branch: feature/translation-msgfmt-statistics-7052
Commit: 3decc2f5af1ea233c9cb1a3ba18f5e1dd9b8f159
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=3decc2f5af1ea233c9cb1a3ba18f5e1dd9b8f159

Author: Jennifer Mourek <jennifer.mourek at netways.de>
Date:   Wed Jan  4 14:00:46 2017 +0100

Add StatisticsCommand class

---

 .../application/clicommands/StatisticsCommand.php  |  140 ++++++++++++++++++++
 1 file changed, 140 insertions(+)

diff --git a/modules/translation/application/clicommands/StatisticsCommand.php b/modules/translation/application/clicommands/StatisticsCommand.php
new file mode 100644
index 0000000..eb04f29
--- /dev/null
+++ b/modules/translation/application/clicommands/StatisticsCommand.php
@@ -0,0 +1,140 @@
+<?php
+/* Icinga Web 2 | (c) 2016 Icinga Development Team | GPLv2+ */
+
+namespace Icinga\Module\Translation\Clicommands;
+
+use Icinga\Module\Translation\Statistics\Statistics;
+use Icinga\Module\Translation\Cli\TranslationCommand;
+
+class StatisticsCommand extends TranslationCommand
+{
+    /**
+     * The statistics to be displayed
+     *
+     * @var Statistics
+     */
+    protected $statistics;
+
+    /**
+     * The percentages of the statistics to be displayed
+     *
+     * @var array
+     */
+    protected $percentages;
+
+    public function getPercentage($number)
+    {
+        $percentage = $number / $this->statistics->countEntries() * 100;
+        if ($percentage != 0 && $percentage < 1) {
+            $percentage = 1;
+        }
+
+        return round($percentage);
+    }
+
+    /**
+     * Calculates the percentages from the statistics
+     */
+    public function calculatePercentages()
+    {
+        $this->percentages = array();
+        $this->percentages['untranslated'] = $this->getPercentage($this->statistics->countUntranslatedEntries());
+        $this->percentages['translated'] = $this->getPercentage($this->statistics->countTranslatedEntries());
+        $this->percentages['fuzzy'] = $this->getPercentage($this->statistics->countFuzzyEntries());
+        $this->percentages['faulty'] = $this->getPercentage($this->statistics->countFaultyEntries());
+
+        $percentageSum = array_sum($this->percentages);
+        if ($percentageSum != 100) {
+            $difference = 100 - $percentageSum;
+
+            $toAdapt = array_search(max($this->percentages), $this->percentages);
+            $this->percentages[$toAdapt] += $difference;
+        }
+    }
+
+    public function graphsAction()
+    {
+        if (!$this->params->getAllStandalone()) {
+            //todo display manual
+            return;
+        }
+
+        foreach ($this->params->getAllStandalone() as $path) {
+            $this->statistics = new Statistics($path);
+
+            $this->calculatePercentages();
+
+            echo PHP_EOL;
+
+            foreach ($this->percentages as $key => $value) {
+                $color = '';
+                switch ($key) {
+                    case 'untranslated':
+                        $color = 'blue';
+                        break;
+                    case 'translated':
+                        $color = 'red';
+                        break;
+                    case 'fuzzy':
+                        $color = 'green';
+                        break;
+                    case 'faulty':
+                        $color = 'purple';
+                        break;
+                }
+                for ($i = 0; $i < $value; $i++) {
+                    echo $this->screen->colorize('█', $color);
+                }
+            }
+
+
+            $pathParts = explode('/', $this->statistics->getPath());
+
+            echo PHP_EOL
+                . '⤷ '
+                . $pathParts[count($pathParts) - 3]
+                . ': '
+                . $pathParts[count($pathParts) - 1]
+                . ' ('
+                . $this->statistics->countEntries()
+                . ' entries)'
+                . PHP_EOL . PHP_EOL;
+
+            echo "\t"
+                . $this->screen->colorize('Untranslated', 'blue')
+                . ': '
+                . $this->percentages['untranslated']
+                . '% ('
+                . $this->statistics->countUntranslatedEntries()
+                . ' messages)'
+                . PHP_EOL;
+
+            echo "\t"
+                . $this->screen->colorize('Translated', 'red')
+                . ': '
+                . $this->percentages['translated']
+                . '% ('
+                . $this->statistics->countTranslatedEntries()
+                . ' messages)'
+                . PHP_EOL;
+
+            echo "\t"
+                . $this->screen->colorize('Fuzzy', 'green')
+                . ': '
+                . $this->percentages['fuzzy']
+                . '% ('
+                . $this->statistics->countFuzzyEntries()
+                . ' messages)'
+                . PHP_EOL;
+
+            echo "\t"
+                . $this->screen->colorize('Faulty', 'purple')
+                . ': '
+                . $this->percentages['faulty']
+                . '% ('
+                . $this->statistics->countFaultyEntries()
+                . ' messages)'
+                . PHP_EOL . PHP_EOL;
+        }
+    }
+}
\ No newline at end of file



More information about the icinga-checkins mailing list