mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-17 23:47:33 +00:00
feat(renderer): add progress tracking and ETA estimation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
725d9e71b1
commit
18d6a3e9e2
@@ -0,0 +1,24 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { ProgressTracker } from "./progress.js";
|
||||
|
||||
describe("ProgressTracker", () => {
|
||||
it("estimates time remaining based on rate", () => {
|
||||
const tracker = new ProgressTracker(100);
|
||||
tracker.recordFrame(10, 1000);
|
||||
const eta = tracker.estimateTimeRemaining();
|
||||
expect(eta).toBeGreaterThan(8000);
|
||||
expect(eta).toBeLessThan(10000);
|
||||
});
|
||||
|
||||
it("returns capture rate", () => {
|
||||
const tracker = new ProgressTracker(100);
|
||||
tracker.recordFrame(20, 2000);
|
||||
expect(tracker.captureRate()).toBeCloseTo(10, 0);
|
||||
});
|
||||
|
||||
it("handles zero frames gracefully", () => {
|
||||
const tracker = new ProgressTracker(100);
|
||||
expect(tracker.estimateTimeRemaining()).toBeUndefined();
|
||||
expect(tracker.captureRate()).toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Progress tracking and ETA estimation.
|
||||
*/
|
||||
|
||||
export class ProgressTracker {
|
||||
private totalFrames: number;
|
||||
private framesCaptured = 0;
|
||||
private elapsedMs = 0;
|
||||
|
||||
constructor(totalFrames: number) {
|
||||
this.totalFrames = totalFrames;
|
||||
}
|
||||
|
||||
recordFrame(framesCaptured: number, elapsedMs: number): void {
|
||||
this.framesCaptured = framesCaptured;
|
||||
this.elapsedMs = elapsedMs;
|
||||
}
|
||||
|
||||
captureRate(): number {
|
||||
if (this.elapsedMs <= 0) return 0;
|
||||
return this.framesCaptured / (this.elapsedMs / 1000);
|
||||
}
|
||||
|
||||
estimateTimeRemaining(): number | undefined {
|
||||
const rate = this.captureRate();
|
||||
if (rate <= 0) return undefined;
|
||||
const remaining = this.totalFrames - this.framesCaptured;
|
||||
return (remaining / rate) * 1000;
|
||||
}
|
||||
|
||||
progress(): number {
|
||||
if (this.totalFrames <= 0) return 0;
|
||||
return this.framesCaptured / this.totalFrames;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user