Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffparnitzky committed May 9, 2017
2 parents af4da73 + aee7428 commit 4a5d58a
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 42 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Contao Extension "MonitoringCompression"
========================================

Version 1.1.0 (2017-05-09)
--------------------------
- added handling of response times
- moved `Contao Monitoring` to own backend group

Version 1.0.0 (2016-12-14)
--------------------------
- Initial version
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Install the extension via composer: [contao-monitoring/monitoring-compression](h

If you prefer to install it manually, download the latest release here: https://github.com/ContaoMonitoring/monitoring-compression/releases

After installation update the database and define Monitoring specific values in the system settings.


Tracker
-------
Expand All @@ -43,3 +45,4 @@ Dependency
This extension is dependent on the following extensions:

- [[contao-monitoring/monitoring]](https://packagist.org/packages/contao-monitoring/monitoring)
- [[menatwork/contao-multicolumnwizard]](https://packagist.org/packages/menatwork/contao-multicolumnwizard)
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"php":">=5.3",
"contao/core":">=3.2.0,<3.6",
"contao-community-alliance/composer-plugin":"~2.0",
"contao-monitoring/monitoring":"~1.7"
"contao-monitoring/monitoring":"~1.8",
"menatwork/contao-multicolumnwizard":"~3.3"
},
"extra":{
"contao":{
Expand All @@ -30,7 +31,7 @@
}
},
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "1.1.x-dev"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Contao Open Source CMS
* Copyright (C) 2005-2016 Leo Feyer
* Copyright (C) 2005-2017 Leo Feyer
*
* Formerly known as TYPOlight Open Source CMS.
*
Expand All @@ -21,7 +21,7 @@
* Software Foundation website at <http://www.gnu.org/licenses/>.
*
* PHP version 5
* @copyright Cliff Parnitzky 2016-2016
* @copyright Cliff Parnitzky 2016-2017
* @author Cliff Parnitzky
* @package MonitoringCompression
* @license LGPL
Expand All @@ -32,7 +32,6 @@
*/
namespace Monitoring;

use Contao\Database;
/**
* Class Monitoring
*
Expand All @@ -43,9 +42,13 @@
*/
class MonitoringCompressor extends \Backend
{
const COMPRESSION_NONE = '';
const COMPRESSION_DAY = 'DAY';
const COMPRESSION_IMPOSSIBLE = 'IMPOSSIBLE';
const COMPRESSION_NONE = '';
const COMPRESSION_DAY = 'DAY';
const COMPRESSION_IMPOSSIBLE = 'IMPOSSIBLE';

const RESPONSE_TIME_COMBINATION_AVERAGE = 'average';
const RESPONSE_TIME_COMBINATION_LOWEST = 'lowest';
const RESPONSE_TIME_COMBINATION_HIGHEST = 'highest';

/**
* Constructor
Expand Down Expand Up @@ -162,13 +165,13 @@ private function compressDay($tstampStartOfDay, $objMonitoringEntry=null, $blnIs
->execute($tstampStartOfDay, $this->addOneDay($tstampStartOfDay), MonitoringCompressor::COMPRESSION_NONE, $objMonitoringEntries->id);

$this->logDebugMsg('Found ' . $objTest->numRows . ' test results for day ' . date("d.m.Y", $tstampStartOfDay) . ' at entry with ID ' . $objMonitoringEntries->id, __METHOD__);
// TODO remove after testing
//log_message('Found ' . $objTest->numRows . ' test results for day ' . date("d.m.Y", $tstampStartOfDay) . ' at entry with ID ' . $objMonitoringEntries->id, 'monitoring_compression.log');

if ($objTest->numRows > 0)
{
$arrDeleteIds = array();
$arrComments = array();
$arrResponseTimes = array();
$arrResponseTimesForDb = array();
$blnEachStatusEqual = true;

// get the first entry
Expand All @@ -177,7 +180,12 @@ private function compressDay($tstampStartOfDay, $objMonitoringEntry=null, $blnIs
// remember data of the first entry
$intFirstId = $objTest->id;
$strFirstStatus = $objTest->status;
$arrComments[] = $objTest->comment;
if (!empty($objTest->comment))
{
$arrComments[] = $objTest->comment;
}
$arrResponseTimes[] = $objTest->response_time;
$arrResponseTimesForDb[] = array('date' => $objTest->date, 'responseTime' => $objTest->response_time);

while ($objTest->next())
{
Expand All @@ -186,13 +194,35 @@ private function compressDay($tstampStartOfDay, $objMonitoringEntry=null, $blnIs
$blnEachStatusEqual = false;
}
$arrDeleteIds[] = $objTest->id;
$arrComments[] = $objTest->comment;
if (!empty($objTest->comment))
{
$arrComments[] = $objTest->comment;
}
$arrResponseTimes[] = $objTest->response_time;
$arrResponseTimesForDb[] = array('date' => $objTest->date, 'responseTime' => $objTest->response_time);
}

if ($blnEachStatusEqual)
{
\Database::getInstance()->prepare("UPDATE tl_monitoring_test SET compression_type = ?, comment = ? WHERE id = ?")
->execute(MonitoringCompressor::COMPRESSION_DAY, implode("\n\n", $arrComments), $intFirstId);
$responseTime = 0;
$responseTimeCombination = \Config::get('monitoringCompressionResponseTimeCombination');
if (empty($responseTimeCombination))
{
$responseTimeCombination = MonitoringCompressor::RESPONSE_TIME_COMBINATION_AVERAGE;
}

if (!empty($arrResponseTimes))
{
switch ($responseTimeCombination)
{
case MonitoringCompressor::RESPONSE_TIME_COMBINATION_LOWEST : $responseTime = min($arrResponseTimes); break;
case MonitoringCompressor::RESPONSE_TIME_COMBINATION_HIGHEST : $responseTime = max($arrResponseTimes); break;
default : $responseTime = round(array_sum($arrResponseTimes) / count($arrResponseTimes), 3);
}
}

\Database::getInstance()->prepare("UPDATE tl_monitoring_test SET compression_type = ?, comment = ?, response_time = ?, response_time_combination = ?, response_times = ? WHERE id = ?")
->execute(MonitoringCompressor::COMPRESSION_DAY, implode("\n\n", $arrComments), $responseTime, $responseTimeCombination, serialize($arrResponseTimesForDb), $intFirstId);

if (!empty($arrDeleteIds))
{
Expand Down
8 changes: 4 additions & 4 deletions system/modules/MonitoringCompression/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Contao Open Source CMS
* Copyright (C) 2005-2016 Leo Feyer
* Copyright (C) 2005-2017 Leo Feyer
*
* Formerly known as TYPOlight Open Source CMS.
*
Expand All @@ -21,7 +21,7 @@
* Software Foundation website at <http://www.gnu.org/licenses/>.
*
* PHP version 5
* @copyright Cliff Parnitzky 2016-2016
* @copyright Cliff Parnitzky 2016-2017
* @author Cliff Parnitzky
* @package MonitoringCompression
* @license LGPL
Expand All @@ -30,8 +30,8 @@
/**
* Extend backend module (register new functions)
*/
$GLOBALS['BE_MOD']['system']['monitoring']['compressOne'] = array('MonitoringCompressor', 'compressOne');
$GLOBALS['BE_MOD']['system']['monitoring']['compressAll'] = array('MonitoringCompressor', 'compressAll');
$GLOBALS['BE_MOD']['ContaoMonitoring']['monitoring']['compressOne'] = array('MonitoringCompressor', 'compressOne');
$GLOBALS['BE_MOD']['ContaoMonitoring']['monitoring']['compressAll'] = array('MonitoringCompressor', 'compressAll');

/**
* Cron jobs for compression
Expand Down
81 changes: 80 additions & 1 deletion system/modules/MonitoringCompression/dca/tl_monitoring_test.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use Monitoring\MonitoringCompressor;
/**
* Contao Open Source CMS
* Copyright (C) 2005-2016 Leo Feyer
Expand Down Expand Up @@ -33,6 +32,11 @@
*/
$GLOBALS['TL_CSS'][] = 'system/modules/MonitoringCompression/assets/styles.css';

/**
* Add callback
*/
$GLOBALS['TL_DCA']['tl_monitoring_test']['config']['onload_callback'][] = array('tl_monitoring_test_MonitoringCompression', 'initPalettes');

/**
* Add global operations
*/
Expand All @@ -54,6 +58,44 @@
/**
* Add fields
*/
$GLOBALS['TL_DCA']['tl_monitoring_test']['fields']['response_time_combination'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_monitoring_test']['response_time_combination'],
'exclude' => true,
'inputType' => 'select',
'options' => array(MonitoringCompressor::RESPONSE_TIME_COMBINATION_AVERAGE, MonitoringCompressor::RESPONSE_TIME_COMBINATION_LOWEST, MonitoringCompressor::RESPONSE_TIME_COMBINATION_HIGHEST),
'reference' => &$GLOBALS['TL_LANG']['MSC']['monitoringCompressionResponseTimeCombinationOptions'],
'eval' => array('tl_class'=>'w50', 'readonly' => true, 'includeBlankOption'=>true),
'sql' => "varchar(16) NOT NULL default ''"
);

$GLOBALS['TL_DCA']['tl_monitoring_test']['fields']['response_times'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_monitoring_test']['response_times'],
'exclude' => true,
'inputType' => 'multiColumnWizard',
'eval' => array
(
'tl_class' => 'clr',
'buttons' => array('up' => false, 'down' => false, 'copy' => false, 'delete' => false),
'columnFields' => array
(
'date' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_monitoring_test']['response_times_date'],
'inputType' => 'text',
'eval' => array('rgxp' => 'datim', 'readonly' => true)
),
'responseTime' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_monitoring_test']['response_times_time'],
'inputType' => 'text',
'eval' => array('rgxp'=>'digit', 'readonly' => true)
)
)
),
'sql' => "blob NULL"
);
$GLOBALS['TL_DCA']['tl_monitoring_test']['fields']['compression_type'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_monitoring_test']['compression_type'],
Expand All @@ -68,4 +110,41 @@
'sql' => "varchar(16) NOT NULL default '" . MonitoringCompressor::COMPRESSION_NONE . "'"
);

/**
* Class tl_monitoring_test_MonitoringCompression
*
* Provide miscellaneous methods that are used by the data configuration array.
* PHP version 5
* @copyright Cliff Parnitzky 2017-2017
* @author Cliff Parnitzky
* @package Controller
*/
class tl_monitoring_test_MonitoringCompression extends Backend
{
/**
* Default constructor
*/
public function __construct()
{
parent::__construct();
}

/**
* Initialize the palettes when loading
* @param \DataContainer
*/
public function initPalettes()
{
if (\Input::get('act') == "edit")
{
$objMonitoringTest = \MonitoringTestModel::findByPk(\Input::get('id'));
if ($objMonitoringTest != null && $objMonitoringTest->compression_type == MonitoringCompressor::COMPRESSION_DAY)
{
$GLOBALS['TL_DCA']['tl_monitoring_test']['fields']['response_time']['eval']['tl_class'] = $GLOBALS['TL_DCA']['tl_monitoring_test']['fields']['response_time']['eval']['tl_class'] . " clr";
$GLOBALS['TL_DCA']['tl_monitoring_test']['palettes']['default'] = str_replace(",response_time,", ",response_time,response_time_combination,response_times,", $GLOBALS['TL_DCA']['tl_monitoring_test']['palettes']['default']);
}
}
}
}

?>
28 changes: 18 additions & 10 deletions system/modules/MonitoringCompression/dca/tl_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Contao Open Source CMS
* Copyright (C) 2005-2016 Leo Feyer
* Copyright (C) 2005-2017 Leo Feyer
*
* Formerly known as TYPOlight Open Source CMS.
*
Expand All @@ -21,7 +21,7 @@
* Software Foundation website at <http://www.gnu.org/licenses/>.
*
* PHP version 5
* @copyright Cliff Parnitzky 2016-2016
* @copyright Cliff Parnitzky 2016-2017
* @author Cliff Parnitzky
* @package MonitoringCompression
* @license LGPL
Expand All @@ -33,11 +33,11 @@
$arrDefaultPalletEntries = explode(";", $GLOBALS['TL_DCA']['tl_settings']['palettes']['default']);
foreach ($arrDefaultPalletEntries as $index=>$entry)
{
if (strpos($entry, "{monitoring_legend}") !== FALSE)
{
$entry .= ",monitoringAutoCompressionActive";
$arrDefaultPalletEntries[$index] = $entry;
}
if (strpos($entry, "{monitoring_legend}") !== FALSE)
{
$entry .= ",monitoringAutoCompressionActive,monitoringCompressionResponseTimeCombination";
$arrDefaultPalletEntries[$index] = $entry;
}
}
$GLOBALS['TL_DCA']['tl_settings']['palettes']['default'] = implode(";", $arrDefaultPalletEntries);

Expand All @@ -46,9 +46,17 @@
*/
$GLOBALS['TL_DCA']['tl_settings']['fields']['monitoringAutoCompressionActive'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_settings']['monitoringAutoCompressionActive'],
'inputType' => 'checkbox',
'eval' => array('tl_class'=>'clr w50')
'label' => &$GLOBALS['TL_LANG']['tl_settings']['monitoringAutoCompressionActive'],
'inputType' => 'checkbox',
'eval' => array('tl_class'=>'clr w50 m12')
);
$GLOBALS['TL_DCA']['tl_settings']['fields']['monitoringCompressionResponseTimeCombination'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_settings']['monitoringCompressionResponseTimeCombination'],
'inputType' => 'select',
'options' => array(MonitoringCompressor::RESPONSE_TIME_COMBINATION_AVERAGE, MonitoringCompressor::RESPONSE_TIME_COMBINATION_LOWEST, MonitoringCompressor::RESPONSE_TIME_COMBINATION_HIGHEST),
'reference' => &$GLOBALS['TL_LANG']['MSC']['monitoringCompressionResponseTimeCombinationOptions'],
'eval' => array('mandatory'=>true, 'tl_class'=>'w50', 'includeBlankOption'=>true)
);

?>
11 changes: 9 additions & 2 deletions system/modules/MonitoringCompression/languages/de/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Contao Open Source CMS
* Copyright (C) 2005-2016 Leo Feyer
* Copyright (C) 2005-2017 Leo Feyer
*
* Formerly known as TYPOlight Open Source CMS.
*
Expand All @@ -21,7 +21,7 @@
* Software Foundation website at <http://www.gnu.org/licenses/>.
*
* PHP version 5
* @copyright Cliff Parnitzky 2016-2016
* @copyright Cliff Parnitzky 2016-2017
* @author Cliff Parnitzky
* @package MonitoringCompression
* @license LGPL
Expand All @@ -33,4 +33,11 @@
$GLOBALS['TL_LANG']['MSC']['monitoringCompressedOne'] = 'Die Testergebnisse des Monitoring Eintrags mit der ID %s wurden komprimiert.';
$GLOBALS['TL_LANG']['MSC']['monitoringCompressedAll'] = 'Die Testergebnisse aller Monitoring Einträge wurden komprimiert.';

/**
* Options
*/
$GLOBALS['TL_LANG']['MSC']['monitoringCompressionResponseTimeCombinationOptions'][MonitoringCompressor::RESPONSE_TIME_COMBINATION_AVERAGE] = 'Durchschnittswert';
$GLOBALS['TL_LANG']['MSC']['monitoringCompressionResponseTimeCombinationOptions'][MonitoringCompressor::RESPONSE_TIME_COMBINATION_LOWEST] = 'Kleinster Wert';
$GLOBALS['TL_LANG']['MSC']['monitoringCompressionResponseTimeCombinationOptions'][MonitoringCompressor::RESPONSE_TIME_COMBINATION_HIGHEST] = 'Höchster Wert';

?>
Loading

0 comments on commit 4a5d58a

Please sign in to comment.