Spaces:
Configuration error
Configuration error
File size: 2,383 Bytes
03b405b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | const { getDb } = require('../config/db');
/**
* Audit system performance benchmarks based on completed job ratios
*/
function getBenchmarksReport() {
const db = getDb();
const jobs = db.prepare("SELECT mode, result FROM jobs WHERE status = 'completed'").all();
const benchmarkStats = {};
for (const job of jobs) {
try {
const res = JSON.parse(job.result);
if (!res || !res.inputSize || !res.outputSize || !res.duration) continue;
const preset = job.mode;
if (!benchmarkStats[preset]) {
benchmarkStats[preset] = {
count: 0,
totalInputSize: 0,
totalOutputSize: 0,
totalCompressionTimeSecs: 0,
totalVideoDurationSecs: 0,
vmafScores: [],
ssimScores: []
};
}
const stats = benchmarkStats[preset];
stats.count++;
stats.totalInputSize += res.inputSize;
stats.totalOutputSize += res.outputSize;
stats.totalCompressionTimeSecs += res.compressionTimeMs ? res.compressionTimeMs / 1000 : 0;
stats.totalVideoDurationSecs += res.duration;
if (res.quality && res.quality.ssim) stats.ssimScores.push(res.quality.ssim);
if (res.quality && res.quality.vmaf) stats.vmafScores.push(res.quality.vmaf);
} catch { /* skip malformed result */ }
}
// Calculate averages per preset
const report = [];
for (const [preset, stats] of Object.entries(benchmarkStats)) {
const avgSaving = stats.totalInputSize > 0
? ((stats.totalInputSize - stats.totalOutputSize) / stats.totalInputSize) * 100
: 0;
const avgProcessingFactor = stats.totalVideoDurationSecs > 0
? stats.totalCompressionTimeSecs / stats.totalVideoDurationSecs
: 0;
const avgSsim = stats.ssimScores.length > 0
? stats.ssimScores.reduce((a, b) => a + b, 0) / stats.ssimScores.length
: 0.95;
const avgVmaf = stats.vmafScores.length > 0
? stats.vmafScores.reduce((a, b) => a + b, 0) / stats.vmafScores.length
: 85;
report.push({
preset,
sampleCount: stats.count,
averageSavingPercent: Math.round(avgSaving),
speedFactor: parseFloat(avgProcessingFactor.toFixed(2)),
qualityMetric: {
ssim: parseFloat(avgSsim.toFixed(4)),
vmaf: Math.round(avgVmaf)
}
});
}
return report;
}
module.exports = { getBenchmarksReport };
|