Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@keptn/pitometer-grader-threshold

Package Overview
Dependencies
Maintainers
4
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@keptn/pitometer-grader-threshold - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

8

dist/classes/Grader.d.ts

@@ -16,13 +16,15 @@ /**

*/
import * as pitometer from 'pitometer';
import * as pitometer from '../../../pitometer';
export declare class Grader implements pitometer.IGrader {
private context;
private individualResults;
setOptions(options: pitometer.IOptions): void;
getContext(): string;
private evaluate;
grade(id: string, results: pitometer.ISourceResult[], { thresholds, metricScore, ignoreEmpty }: {
grade(id: string, results: pitometer.ISourceResult[], { thresholds, metricScore, ignoreEmpty, metadata, }: {
thresholds: any;
metricScore: any;
ignoreEmpty: any;
}): pitometer.IGradingResult;
metadata: any;
}, compareResult: any): pitometer.IGradingResult;
}

@@ -21,2 +21,3 @@ "use strict";

this.context = options.context;
this.individualResults = options.individualResults ? options.individualResults : false;
}

@@ -26,11 +27,27 @@ getContext() {

}
evaluate(result, { thresholds, metricScore, ignoreEmpty }) {
evaluate(result, { thresholds, metricScore, ignoreEmpty, metadata }, individualCompareResult) {
let score = metricScore;
const violations = [];
const value = result.value;
if (thresholds.lowerSevere && value <= thresholds.lowerSevere) {
const individualResult = { value: result.value, key: result.key };
// lets see if we have been passed an individual grading result
if (individualCompareResult) {
// console.log("we have something to compare: " + JSON.stringify(individualCompareResult));
// If we have a comparison dataset the Threshold Grader support specifying upperSeverePerc, upperWarningPerc, lowerWarningPerc, lowerSeverePerc
// if those are specified we calculate them based on the previous run data
if (thresholds.upperSeverePerc)
thresholds.upperSevere = individualCompareResult.value * (100 + thresholds.upperSeverePerc) / 100;
if (thresholds.upperWarningPerc)
thresholds.upperWarning = individualCompareResult.value * (100 + thresholds.upperWarningPerc) / 100;
if (thresholds.lowerWarningPerc)
thresholds.lowerWarning = individualCompareResult.value * (100 - thresholds.lowerWarningPerc) / 100;
if (thresholds.lowerSeverePerc)
thresholds.lowerSevere = individualCompareResult.value * (100 - thresholds.lowerSeverePerc) / 100;
console.log("Actual Thresholds: " + JSON.stringify(thresholds));
}
if (thresholds.lowerSevere && individualResult.value <= thresholds.lowerSevere) {
score = 0;
violations.push({
value,
key: result.key,
metadata,
value: individualResult.value,
key: individualResult.key,
breach: 'lowerSevere',

@@ -40,7 +57,8 @@ threshold: thresholds.lowerSevere,

}
else if (thresholds.lowerWarning && value <= thresholds.lowerWarning) {
else if (thresholds.lowerWarning && individualResult.value <= thresholds.lowerWarning) {
score /= 2;
violations.push({
value,
key: result.key,
metadata,
value: individualResult.value,
key: individualResult.key,
breach: 'lowerWarning',

@@ -50,7 +68,8 @@ threshold: thresholds.lowerWarning,

}
if (thresholds.upperSevere && value >= thresholds.upperSevere) {
if (thresholds.upperSevere && individualResult.value >= thresholds.upperSevere) {
score = 0;
violations.push({
value,
key: result.key,
metadata,
value: individualResult.value,
key: individualResult.key,
breach: 'upperSevere',

@@ -60,7 +79,8 @@ threshold: thresholds.upperSevere,

}
else if (thresholds.upperWarning && value >= thresholds.upperWarning) {
else if (thresholds.upperWarning && individualResult.value >= thresholds.upperWarning) {
score /= 2;
violations.push({
value,
key: result.key,
metadata,
value: individualResult.value,
key: individualResult.key,
breach: 'upperWarning',

@@ -70,12 +90,38 @@ threshold: thresholds.upperWarning,

}
if (this.individualResults) {
if (thresholds.lowerSevere)
individualResult.lowerSevere = thresholds.lowerSevere;
if (thresholds.lowerWarning)
individualResult.lowerWarning = thresholds.lowerWarning;
if (thresholds.upperSevere)
individualResult.upperSevere = thresholds.upperSevere;
if (thresholds.upperWarning)
individualResult.upperWarning = thresholds.upperWarning;
return { score, violations, individualResult };
}
return {
score,
violations,
violations
};
}
grade(id, results, { thresholds, metricScore, ignoreEmpty }) {
grade(id, results, { thresholds, metricScore, ignoreEmpty, metadata, }, compareResult) {
const grades = [];
const violations = [];
const individualResults = [];
results.forEach((result) => {
const grade = this.evaluate(result, { thresholds, metricScore, ignoreEmpty });
// lets see if we have an individual compare result for that source key
var individualResult = null;
if (compareResult && compareResult.individualResults) {
for (var i = 0; i < compareResult.individualResults.length; i++) {
if (compareResult.individualResults[i].key == result.key)
individualResult = compareResult.individualResults[i];
break;
}
}
const grade = this.evaluate(result, {
thresholds,
metricScore,
ignoreEmpty,
metadata,
}, individualResult);
violations.push(...grade.violations);

@@ -89,2 +135,4 @@ grades.push({

});
if (this.individualResults)
individualResults.push(grade.individualResult);
});

@@ -104,5 +152,8 @@ const reduced = grades.reduce((acc, elm) => {

violations.push({
metadata,
breach: 'The indicator returned no values',
});
}
if (this.individualResults)
return { id, violations, score, individualResults };
return { id, violations, score };

@@ -109,0 +160,0 @@ }

{
"name": "@keptn/pitometer-grader-threshold",
"version": "1.0.1",
"version": "1.1.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc