agentic-qe
Version:
Agentic Quality Engineering Fleet System - AI-driven quality management platform
167 lines • 7.76 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MonitorCompare = void 0;
const fs = __importStar(require("fs/promises"));
class MonitorCompare {
constructor(dataDir) {
this.dataDir = dataDir;
}
async initialize() {
await fs.mkdir(this.dataDir, { recursive: true });
}
async compare(baseline, current, options) {
const threshold = options?.threshold ?? 10;
const result = {};
// Get common metrics
const metrics = Object.keys(baseline).filter(key => key in current);
for (const metric of metrics) {
const baselineAvg = this.average(baseline[metric]);
const currentAvg = this.average(current[metric]);
const change = currentAvg - baselineAvg;
const percentChange = (change / baselineAvg) * 100;
const significant = Math.abs(percentChange) >= threshold;
result[metric] = {
baseline: baselineAvg,
current: currentAvg,
change,
percentChange,
significant,
};
}
return result;
}
async visualize(baseline, current) {
const comparison = await this.compare(baseline, current);
const lines = [];
lines.push('╔════════════════════════════════════════════════════╗');
lines.push('║ METRIC COMPARISON REPORT ║');
lines.push('╠════════════════════════════════════════════════════╣');
for (const [metric, data] of Object.entries(comparison)) {
lines.push(`║ ${metric.toUpperCase().padEnd(48)} ║`);
lines.push('╟────────────────────────────────────────────────────╢');
// Baseline bar
const baselineBar = this.createBar(data.baseline, 100, 30, '█');
lines.push(`║ Baseline: ${baselineBar} ${data.baseline.toFixed(1).padStart(6)} ║`);
// Current bar
const currentBar = this.createBar(data.current, 100, 30, '█');
lines.push(`║ Current: ${currentBar} ${data.current.toFixed(1).padStart(6)} ║`);
// Change indicator
const changeSign = data.change >= 0 ? '+' : '';
const changeIndicator = data.significant ? ' ⚠️ ' : ' ';
lines.push(`║ Change: ${changeSign}${data.change.toFixed(1).padStart(5)} (${changeSign}${data.percentChange.toFixed(1)}%)${changeIndicator} ║`);
lines.push('╟────────────────────────────────────────────────────╢');
}
lines.push('╚════════════════════════════════════════════════════╝');
return lines.join('\n');
}
async compareMultiple(periods) {
if (periods.length < 2) {
throw new Error('At least 2 periods required for comparison');
}
const result = {
trend: 'stable',
periods: [],
overallChange: {},
};
// Calculate averages for each period
for (const period of periods) {
const averages = {};
for (const [metric, values] of Object.entries(period.metrics)) {
if (Array.isArray(values)) {
averages[metric] = this.average(values);
}
}
result.periods.push({
name: period.name,
average: averages,
});
}
// Determine overall trend
const firstPeriod = result.periods[0];
const lastPeriod = result.periods[result.periods.length - 1];
// Calculate overall change for each metric
for (const metric of Object.keys(firstPeriod.average)) {
const first = firstPeriod.average[metric];
const last = lastPeriod.average[metric];
result.overallChange[metric] = ((last - first) / first) * 100;
}
// Determine predominant trend
const avgChange = Object.values(result.overallChange).reduce((a, b) => a + b, 0) /
Object.values(result.overallChange).length;
if (avgChange > 5) {
result.trend = 'increasing';
}
else if (avgChange < -5) {
result.trend = 'decreasing';
}
else {
result.trend = 'stable';
}
return result;
}
average(values) {
return values.reduce((a, b) => a + b, 0) / values.length;
}
createBar(value, max, width, char) {
const filled = Math.round((value / max) * width);
const empty = width - filled;
return char.repeat(filled) + '░'.repeat(empty);
}
async compareWithThreshold(baseline, current, thresholds) {
const comparison = await this.compare(baseline, current);
const results = {};
for (const [metric, data] of Object.entries(comparison)) {
const threshold = thresholds[metric] ?? 10;
results[metric] = Math.abs(data.percentChange) < threshold;
}
return results;
}
async generateComparisonReport(baseline, current) {
const comparison = await this.compare(baseline, current);
const visualization = await this.visualize(baseline, current);
const summary = [
'# Monitoring Comparison Report',
'',
'## Summary',
'',
];
for (const [metric, data] of Object.entries(comparison)) {
const status = data.significant ? '⚠️ SIGNIFICANT CHANGE' : '✓ Normal';
summary.push(`- **${metric}**: ${status}`);
summary.push(` - Baseline: ${data.baseline.toFixed(2)}`);
summary.push(` - Current: ${data.current.toFixed(2)}`);
summary.push(` - Change: ${data.change >= 0 ? '+' : ''}${data.change.toFixed(2)} (${data.percentChange >= 0 ? '+' : ''}${data.percentChange.toFixed(1)}%)`);
summary.push('');
}
summary.push('## Visualization');
summary.push('```');
summary.push(visualization);
summary.push('```');
return summary.join('\n');
}
}
exports.MonitorCompare = MonitorCompare;
//# sourceMappingURL=compare.js.map