Skip to content

Commit

Permalink
Add mock progress during initial log load
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Dec 12, 2023
1 parent 6b90ad3 commit 7ce110b
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/hub/dataSources/HistoricalDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class HistoricalDataSource {
};

private paths: string[] = [];
private mockProgress: number = 0;
private status: HistoricalDataSourceStatus = HistoricalDataSourceStatus.Waiting;
private statusCallback: ((status: HistoricalDataSourceStatus) => void) | null = null;
private progressCallback: ((progress: number) => void) | null = null;
Expand Down Expand Up @@ -47,7 +48,7 @@ export class HistoricalDataSource {
content:
"Hoot log files must be opened on Windows. CTRE provides no method of decoding log files on macOS or Linux."
});
this.setStatus(HistoricalDataSourceStatus.Stopped);
this.stop();
return;
}
if (!this.paths.includes(newPath)) {
Expand All @@ -56,6 +57,20 @@ export class HistoricalDataSource {
}
this.setStatus(HistoricalDataSourceStatus.Reading);
window.sendMainMessage("historical-start", this.paths);

// Start mock progress updates
let startTime = new Date().getTime();
let sendMockProgress = () => {
let time = (new Date().getTime() - startTime) / 1000;
this.mockProgress = HistoricalDataSource.calcMockProgress(time);
if (this.progressCallback !== null) {
this.progressCallback(this.mockProgress);
}
if (this.status === HistoricalDataSourceStatus.Reading) {
window.requestAnimationFrame(sendMockProgress);
}
};
window.requestAnimationFrame(sendMockProgress);
}

/** Cancels the read operation. */
Expand Down Expand Up @@ -98,7 +113,8 @@ export class HistoricalDataSource {
WorkerManager.request("../bundles/" + selectedWorkerName, contents, (progress) => {
progressValues[i] = progress;
if (this.progressCallback && this.status === HistoricalDataSourceStatus.Decoding) {
let totalProgress = progressValues.reduce((a, b) => a + b, 0) / progressValues.length;
let decodeProgress = progressValues.reduce((a, b) => a + b, 0) / progressValues.length;
let totalProgress = this.mockProgress + decodeProgress * (1 - this.mockProgress);
this.progressCallback(totalProgress);
}
})
Expand Down Expand Up @@ -133,6 +149,12 @@ export class HistoricalDataSource {
if (this.statusCallback !== null) this.statusCallback(status);
}
}

/** Calculates a mock progress value for the initial load time. */
private static calcMockProgress(time: number): number {
// https://www.desmos.com/calculator/86u4rnu8ob
return 0.5 - 0.5 / (0.1 * time + 1);
}
}

export enum HistoricalDataSourceStatus {
Expand Down

0 comments on commit 7ce110b

Please sign in to comment.