N°1350 - Configurable error tolerance for report color of audit categories

This commit is contained in:
Lars Kaltefleiter
2022-08-11 10:55:56 +02:00
committed by Molkobain
parent 9b47ee12e7
commit 4a54b2f8ff
4 changed files with 38 additions and 18 deletions

View File

@@ -48,13 +48,38 @@ class AuditCategory extends cmdbAbstractObject
MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeOQL("definition_set", array("allowed_values"=>null, "sql"=>"definition_set", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeLinkedSet("rules_list", array("linked_class"=>"AuditRule", "ext_key_to_me"=>"category_id", "allowed_values"=>null, "count_min"=>0, "count_max"=>0, "depends_on"=>array(), "edit_mode" => LINKSET_EDITMODE_INPLACE, "tracking_level" => LINKSET_TRACKING_ALL)));
MetaModel::Init_AddAttribute(new AttributeInteger("ok_error_tolerance", array("allowed_values"=>null, "sql"=>"ok_error_tolerance", "default_value"=>5, "is_null_allowed"=>true, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeInteger("warning_error_tolerance", array("allowed_values"=>null, "sql"=>"warning_error_tolerance", "default_value"=>25, "is_null_allowed"=>true, "depends_on"=>array())));
// Display lists
MetaModel::Init_SetZListItems('details', array('name', 'description', 'definition_set', 'rules_list')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('details', array('name', 'description', 'definition_set', 'ok_error_tolerance', 'warning_error_tolerance', 'rules_list')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('list', array('description', )); // Attributes to be displayed for a list
// Search criteria
MetaModel::Init_SetZListItems('standard_search', array('description', 'definition_set')); // Criteria of the std search form
MetaModel::Init_SetZListItems('default_search', array('name', 'description')); // Criteria of the default search form
}
/**
* @param int $iTotal
* @param int $iErrors
*
* @return string A semantic color name (eg. red, green, orange, success, failure, ... {@see css/backoffice/utils/variables/colors/_semantic-palette.scss}) to use for this category depending on its error count and tolerance
* @throws \CoreException
*
* @since 3.1.0
*/
public function GetReportColor($iTotal, $iErrors)
{
$sResult = 'red';
if ( ($iTotal == 0) || ($iErrors / $iTotal) <= ($this->Get('ok_error_tolerance') / 100) )
{
$sResult = 'green';
}
else if ( ($iErrors / $iTotal) <= ($this->Get('warning_error_tolerance') / 100) )
{
$sResult = 'orange';
}
return $sResult;
}
}
?>

View File

@@ -14,6 +14,10 @@ Dict::Add('DE DE', 'German', 'Deutsch', array(
'Class:AuditCategory/Attribute:definition_set+' => 'OQL-Ausdrücke, die den Umfang der zu auditierenden Objekte festlegen',
'Class:AuditCategory/Attribute:rules_list' => 'Audit-Regeln',
'Class:AuditCategory/Attribute:rules_list+' => 'Audit-Regeln für diese Kategorie',
'Class:AuditCategory/Attribute:ok_error_tolerance' => 'Fehlertoleranz (OK)',
'Class:AuditCategory/Attribute:ok_error_tolerance+' => 'Erlaubter prozentualer Anteil ungültiger Objekte, bei dem das Ergebnis noch als in Ordnung (grün) dargestellt wird',
'Class:AuditCategory/Attribute:warning_error_tolerance' => 'Fehlertoleranz (Warnung)',
'Class:AuditCategory/Attribute:warning_error_tolerance+' => 'Erlaubter prozentualer Anteil ungültiger Objekte, bei dem das Ergebnis noch als Warnung (orange) dargestellt wir.',
));
//

View File

@@ -30,6 +30,10 @@ Dict::Add('EN US', 'English', 'English', array(
'Class:AuditCategory/Attribute:definition_set+' => 'OQL expression defining the set of objects to audit',
'Class:AuditCategory/Attribute:rules_list' => 'Audit Rules',
'Class:AuditCategory/Attribute:rules_list+' => 'Audit rules for this category',
'Class:AuditCategory/Attribute:ok_error_tolerance' => 'Error tolerance (OK)',
'Class:AuditCategory/Attribute:ok_error_tolerance+' => 'Allowed percentage of invalid objects at which the result is still displayed as OK (green)',
'Class:AuditCategory/Attribute:warning_error_tolerance' => 'Error tolerance (warning)',
'Class:AuditCategory/Attribute:warning_error_tolerance+' => 'Allowed percentage of invalid objects at which the result is still displayed as a warning (orange)',
));
//

View File

@@ -139,20 +139,6 @@ function GetRuleResultFilter($iRuleId, $oDefinitionFilter, $oAppContext)
return $oFilter;
}
function GetReportColor($iTotal, $iErrors)
{
$sResult = 'red';
if ( ($iTotal == 0) || ($iErrors / $iTotal) <= 0.05 )
{
$sResult = 'green';
}
else if ( ($iErrors / $iTotal) <= 0.25 )
{
$sResult = 'orange';
}
return $sResult;
}
try
{
require_once('../approot.inc.php');
@@ -306,6 +292,7 @@ try
$oCategoriesSet = new DBObjectSet($oAuditFilter);
$aAuditCategoryPanels = [];
/** @var AuditCategory $oAuditCategory */
while($oAuditCategory = $oCategoriesSet->fetch())
{
$oAuditCategoryPanelBlock = new Panel($oAuditCategory->GetName());
@@ -340,7 +327,7 @@ try
// nothing to check, really !
$aRow['nb_errors'] = "<a href=\"audit.php?operation=errors&category=".$oAuditCategory->GetKey()."&rule=".$oAuditRule->GetKey()."\">0</a>";
$aRow['percent_ok'] = '100.00';
$aRow['class'] = GetReportColor($iCount, 0);
$aRow['class'] = $oAuditCategory->GetReportColor($iCount, 0);
}
else
{
@@ -355,7 +342,7 @@ try
}
$aRow['nb_errors'] = ($iErrorsCount == 0) ? '0' : "<a href=\"?operation=errors&category=".$oAuditCategory->GetKey()."&rule=".$oAuditRule->GetKey()."&".$oAppContext->GetForLink()."\">$iErrorsCount</a> <a href=\"?operation=csv&category=".$oAuditCategory->GetKey()."&rule=".$oAuditRule->GetKey()."&".$oAppContext->GetForLink()."\"><img src=\"../images/icons/icons8-export-csv.svg\" class=\"ibo-audit--audit-line--csv-download\"></a>";
$aRow['percent_ok'] = sprintf('%.2f', 100.0 * (($iCount - $iErrorsCount) / $iCount));
$aRow['class'] = GetReportColor($iCount, $iErrorsCount);
$aRow['class'] = $oAuditCategory->GetReportColor($iCount, $iErrorsCount);
}
catch(Exception $e)
{
@@ -373,7 +360,7 @@ try
}
$iTotalErrors = count($aObjectsWithErrors);
$sOverallPercentOk = ($iCount == 0) ? '100.00' : sprintf('%.2f', 100.0 * (($iCount - $iTotalErrors) / $iCount));
$sClass = GetReportColor($iCount, $iTotalErrors);
$sClass = $oAuditCategory->GetReportColor($iCount, $iTotalErrors);
$oTotalBlock->SetCount((int)$oTotalBlock->GetCount() + ($iCount));
$oErrorBlock->SetCount((int)$oErrorBlock->GetCount() + $iTotalErrors);