fix: use raw intensity to find visual heatmap bumps

This commit is contained in:
Kilo Code Cloud
2026-01-14 20:11:43 +00:00
parent 9ea4d4ab33
commit 49bc42f4c9

View File

@@ -23,7 +23,6 @@ interface ProcessedSegment {
start: number; start: number;
end: number; end: number;
intensity: number; intensity: number;
integralJump: number;
} }
interface VideoInfo { interface VideoInfo {
@@ -143,7 +142,7 @@ function getIntensity(segment: RawHeatmapSegment): number {
return segment.intensity ?? segment.heat ?? segment.value ?? 0; return segment.intensity ?? segment.heat ?? segment.value ?? 0;
} }
function getTopSegmentsByIntegral( function getTopSegmentsByIntensity(
segments: RawHeatmapSegment[], segments: RawHeatmapSegment[],
topN: number topN: number
): ProcessedSegment[] { ): ProcessedSegment[] {
@@ -166,19 +165,9 @@ function getTopSegmentsByIntegral(
return []; return [];
} }
// Calculate integral for each segment and sort by highest // Sort by raw intensity (highest first) - this matches visual "bumps" in heatmap
const withIntegral = validSegments.map(seg => { validSegments.sort((a, b) => b.intensity - a.intensity);
const segmentDuration = seg.end - seg.start; return validSegments.slice(0, topN);
const integralJump = seg.intensity * segmentDuration;
return {
...seg,
integralJump,
};
});
// Sort by integral jump (highest first) and return top N
withIntegral.sort((a, b) => b.integralJump - a.integralJump);
return withIntegral.slice(0, topN);
} }
export async function downloadMostWatchedSegment(options: DownloadOptions): Promise<void> { export async function downloadMostWatchedSegment(options: DownloadOptions): Promise<void> {
@@ -208,10 +197,10 @@ export async function downloadMostWatchedSegment(options: DownloadOptions): Prom
} }
console.log(`\nHeatmap data found: ${info.heatmap.length} segments`); console.log(`\nHeatmap data found: ${info.heatmap.length} segments`);
console.log(`\nTop ${topN} segments by integral jump:\n`); console.log(`\nTop ${topN} segments by intensity (visual heatmap bumps):\n`);
// Get top segments // Get top segments by raw intensity
const topSegments = getTopSegmentsByIntegral(info.heatmap, topN); const topSegments = getTopSegmentsByIntensity(info.heatmap, topN);
if (topSegments.length === 0) { if (topSegments.length === 0) {
console.log("No valid segments found. Downloading full video..."); console.log("No valid segments found. Downloading full video...");
@@ -224,7 +213,7 @@ export async function downloadMostWatchedSegment(options: DownloadOptions): Prom
for (let i = 0; i < topSegments.length; i++) { for (let i = 0; i < topSegments.length; i++) {
const seg = topSegments[i]; const seg = topSegments[i];
const duration = seg.end - seg.start; const duration = seg.end - seg.start;
console.log(`${i + 1}. ${formatTime(seg.start)} - ${formatTime(seg.end)} | Duration: ${formatTime(duration)} | Integral: ${seg.integralJump.toFixed(4)}`); console.log(`${i + 1}. ${formatTime(seg.start)} - ${formatTime(seg.end)} | Duration: ${formatTime(duration)} | Intensity: ${(seg.intensity * 100).toFixed(1)}%`);
} }
console.log(""); console.log("");
@@ -239,14 +228,13 @@ export async function downloadMostWatchedSegment(options: DownloadOptions): Prom
// Save segment info // Save segment info
const segmentInfoPath = join(outputDir, `${safeTitle}_top_segments.txt`); const segmentInfoPath = join(outputDir, `${safeTitle}_top_segments.txt`);
let segmentInfo = `# ${info.title}\n\n`; let segmentInfo = `# ${info.title}\n\n`;
segmentInfo += `Top ${topN} segments by integral jump:\n\n`; segmentInfo += `Top ${topN} segments by intensity (highest re-watch rate):\n\n`;
for (let i = 0; i < topSegments.length; i++) { for (let i = 0; i < topSegments.length; i++) {
const seg = topSegments[i]; const seg = topSegments[i];
const duration = seg.end - seg.start; const duration = seg.end - seg.start;
segmentInfo += `${i + 1}. ${formatTime(seg.start)} - ${formatTime(seg.end)}\n`; segmentInfo += `${i + 1}. ${formatTime(seg.start)} - ${formatTime(seg.end)}\n`;
segmentInfo += ` Duration: ${formatTime(duration)}\n`; segmentInfo += ` Duration: ${formatTime(duration)}\n`;
segmentInfo += ` Integral: ${seg.integralJump.toFixed(4)}\n`;
segmentInfo += ` Intensity: ${(seg.intensity * 100).toFixed(1)}%\n\n`; segmentInfo += ` Intensity: ${(seg.intensity * 100).toFixed(1)}%\n\n`;
} }