@nitin15j/plugin-dora-frontend
Version:
Welcome to the dora-frontend plugin!
70 lines (67 loc) • 2.34 kB
JavaScript
import { MetricType } from '../types/metrics.esm.js';
import { determineTrend, calculateTrendChange, calculateTrendChangeSimple, getMetricPerformance } from './calculations.esm.js';
const createMetricData = (metricType, currentValue, previousValue, useRoundedCalculation = true) => {
const calculateChange = useRoundedCalculation ? calculateTrendChange : calculateTrendChangeSimple;
return {
metricName: metricType,
value: getMetricPerformance(metricType, currentValue),
rawValue: currentValue,
previousValue: getMetricPerformance(metricType, previousValue),
percentageChange: calculateChange(currentValue, previousValue),
trend: determineTrend(currentValue, previousValue, metricType)
};
};
const processMetricsResponse = (response, useRoundedCalculation = true) => {
const { currentRange, previousRange } = response;
return [
createMetricData(
MetricType.Frequency,
currentRange.numOfDeploysPerDay,
previousRange.numOfDeploysPerDay,
useRoundedCalculation
),
createMetricData(
MetricType.LeadTime,
currentRange.avgLeadTimeInSec,
previousRange.avgLeadTimeInSec,
useRoundedCalculation
),
createMetricData(
MetricType.FailureRate,
currentRange.failureRatePercent,
previousRange.failureRatePercent,
useRoundedCalculation
),
createMetricData(
MetricType.Mttr,
currentRange.avgMttrDurationInSec,
previousRange.avgMttrDurationInSec,
useRoundedCalculation
)
];
};
const mapMetricType = (insightMetricType) => {
switch (insightMetricType) {
case "DEPLOYING":
case "FREQUENCY":
return "Frequency";
case "MTTR":
return "Mttr";
case "FAILURE_RATE":
return "FailureRate";
default:
return insightMetricType;
}
};
const processInsights = (insights) => {
return insights.filter((insight) => insight.__typename === "MetricOffsetFromAverageInsightType").map((insight) => ({
message: insight.message,
icon: insight.icon,
isPositive: insight.isPositive,
metricType: mapMetricType(insight.insightMetricType),
status: insight.isPositive ? "good" : "warning",
summary: insight.message
}));
};
export { createMetricData, mapMetricType, processInsights, processMetricsResponse };
//# sourceMappingURL=processors.esm.js.map