<commit_before><?php
/*

Copyright (C) 2010-2016 by the FusionInventory Development Team.
Copyright (C) 2016 Teclib'

This file is part of Armadito Plugin for GLPI.

Armadito Plugin for GLPI is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Armadito Plugin for GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with Armadito Plugin for GLPI. If not, see <http://www.gnu.org/licenses/>.

**/

if (!defined('GLPI_ROOT')) {
    die("Sorry. You can't access directly to this file");
}

class PluginArmaditoAlertBoard extends PluginArmaditoBoard
{

    function __construct()
    {
    }

    function displayBoard()
    {
        $restrict_entity = getEntitiesRestrictRequest(" AND", 'comp');

        echo "<table align='center'>";
        echo "<tr height='420'>";

        $this->addAlertsByVirusNameChart($restrict_entity);
        $this->addLastAlertsChart($restrict_entity);
        $this->addAlertsByAntivirusChart($restrict_entity);

        echo "</tr>";
        echo "</table>";
    }

    function addLastAlertsChart($restrict_entity)
    {
        $data = PluginArmaditoLastAlertStat::getLastHours();

        $bchart = new PluginArmaditoChartBar();
        $bchart->init('lastalerts', __('Alerts of last hours', 'armadito'), $data);

        echo "<td width='400'>";
        $bchart->showChart();
        echo "</td>";
    }

    function addAlertsByVirusNameChart($restrict_entity)
    {
        $data = $this->getAlertsByVirusNameChartData();

        $hchart = new PluginArmaditoChartHalfDonut();
        $hchart->init('alerts_by_virusnames', __('Alerts by names', 'armadito'), $data, 370);

        echo "<td width='380'>";
        $hchart->showChart();
        echo "</td>";
    }

    function addAlertsByAntivirusChart($restrict_entity)
    {
        $data = $this->getAlertsByAntivirusChartData();

        $hchart = new PluginArmaditoChartHalfDonut();
        $hchart->init('alerts_by_antiviruses', __('Alerts by antiviruses', 'armadito'), $data, 370);

        echo "<td width='380'>";
        $hchart->showChart();
        echo "</td>";
    }

    function countAlertsForAV($AV_id)
    {
        return countElementsInTableForMyEntities('glpi_plugin_armadito_alerts', "`plugin_armadito_antiviruses_id`='" . $AV_id . "'");
    }

    function getAlertsByAntivirusChartData()
    {
        $AVs       = PluginArmaditoAntivirus::getAntivirusList();
        $colortbox = new PluginArmaditoColorToolbox();
        $palette   = $colortbox->getPalette(sizeof($AVs));

        $data = array();
        $i    = 0;
        foreach ($AVs as $id => $name) {
            $n_AVs  = $this->countAlertsForAV($id);
            if($n_AVs > 0){
                $data[] = array(
                    'key' => __($name, 'armadito') . ' : ' . $n_AVs,
                    'value' => $n_AVs,
                    'color' => $palette[$i]
                );
                $i++;
            }
        }

        return $data;
    }

    function getAlertsByVirusNameChartData()
    {
        $VirusNames = PluginArmaditoAlert::getVirusNamesList(5);
        $colortbox  = new PluginArmaditoColorToolbox();
        $palette    = $colortbox->getPalette(sizeof($VirusNames));

        $data = array();
        $i    = 0;
        foreach ($VirusNames as $name => $counter) {<commit_msg>Rm label value printed<commit_after><?php
/*

Copyright (C) 2010-2016 by the FusionInventory Development Team.
Copyright (C) 2016 Teclib'

This file is part of Armadito Plugin for GLPI.

Armadito Plugin for GLPI is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Armadito Plugin for GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with Armadito Plugin for GLPI. If not, see <http://www.gnu.org/licenses/>.

**/

if (!defined('GLPI_ROOT')) {
    die("Sorry. You can't access directly to this file");
}

class PluginArmaditoAlertBoard extends PluginArmaditoBoard
{

    function __construct()
    {
    }

    function displayBoard()
    {
        $restrict_entity = getEntitiesRestrictRequest(" AND", 'comp');

        echo "<table align='center'>";
        echo "<tr height='420'>";

        $this->addAlertsByVirusNameChart($restrict_entity);
        $this->addLastAlertsChart($restrict_entity);
        $this->addAlertsByAntivirusChart($restrict_entity);

        echo "</tr>";
        echo "</table>";
    }

    function addLastAlertsChart($restrict_entity)
    {
        $data = PluginArmaditoLastAlertStat::getLastHours();

        $bchart = new PluginArmaditoChartBar();
        $bchart->init('lastalerts', __('Alerts of last hours', 'armadito'), $data);

        echo "<td width='400'>";
        $bchart->showChart();
        echo "</td>";
    }

    function addAlertsByVirusNameChart($restrict_entity)
    {
        $data = $this->getAlertsByVirusNameChartData();

        $hchart = new PluginArmaditoChartHalfDonut();
        $hchart->init('alerts_by_virusnames', __('Alerts by names', 'armadito'), $data, 370);

        echo "<td width='380'>";
        $hchart->showChart();
        echo "</td>";
    }

    function addAlertsByAntivirusChart($restrict_entity)
    {
        $data = $this->getAlertsByAntivirusChartData();

        $hchart = new PluginArmaditoChartHalfDonut();
        $hchart->init('alerts_by_antiviruses', __('Alerts by antiviruses', 'armadito'), $data, 370);

        echo "<td width='380'>";
        $hchart->showChart();
        echo "</td>";
    }

    function countAlertsForAV($AV_id)
    {
        return countElementsInTableForMyEntities('glpi_plugin_armadito_alerts', "`plugin_armadito_antiviruses_id`='" . $AV_id . "'");
    }

    function getAlertsByAntivirusChartData()
    {
        $AVs       = PluginArmaditoAntivirus::getAntivirusList();
        $colortbox = new PluginArmaditoColorToolbox();
        $palette   = $colortbox->getPalette(sizeof($AVs));

        $data = array();
        $i    = 0;
        foreach ($AVs as $id => $name) {
            $n_AVs  = $this->countAlertsForAV($id);
            if($n_AVs > 0){
                $data[] = array(
                    'key' => __($name, 'armadito'),
                    'value' => $n_AVs,
                    'color' => $palette[$i]
                );
                $i++;
            }
        }

        return $data;
    }

    function getAlertsByVirusNameChartData()
    {
        $VirusNames = PluginArmaditoAlert::getVirusNamesList(5);
        $colortbox  = new PluginArmaditoColorToolbox();
        $palette    = $colortbox->getPalette(sizeof($VirusNames));

        $data = array();
        $i    = 0;
        foreach ($VirusNames as $name => $counter) {
{'fraction_non_alphanumeric': 0.1234866828087167, 'fraction_numerical': 0.009416195856873822, 'mean_word_length': 2.736180904522613, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '481510', 'n_tokens_mistral': 2382, 'n_tokens_neox': 2215, 'n_words': 570}