fix: print stats when error(fix #12)
parent
878731e473
commit
82c82bed94
59
src/app.ts
59
src/app.ts
|
|
@ -43,6 +43,16 @@ type Progress = {
|
||||||
total: number;
|
total: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function printStats(stats: Record<string, number>) {
|
||||||
|
console.log(
|
||||||
|
`Exported ${
|
||||||
|
Object.entries(stats)
|
||||||
|
.map(([name, count]) => `${name}: ${count}`)
|
||||||
|
.join(", ")
|
||||||
|
}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export class App {
|
export class App {
|
||||||
state: State = DEFAULT_STATE;
|
state: State = DEFAULT_STATE;
|
||||||
stateBackend: StateBackend;
|
stateBackend: StateBackend;
|
||||||
|
|
@ -118,8 +128,29 @@ export class App {
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
exportOnce() {
|
async exportOnce() {
|
||||||
return retryRecoverableError(() => this._exportOnce(), this.recoveryToken);
|
const exporters = await this.getExporters();
|
||||||
|
const stats: Record<string, number> = Object.fromEntries(
|
||||||
|
exporters.map((e) => [e.name, 0]),
|
||||||
|
);
|
||||||
|
|
||||||
|
await retryRecoverableError(() =>
|
||||||
|
this._exportOnce({
|
||||||
|
stats,
|
||||||
|
}), {
|
||||||
|
...this.recoveryToken,
|
||||||
|
recovery: () => {
|
||||||
|
if (Object.values(stats).some((i) => i > 0)) {
|
||||||
|
printStats(stats);
|
||||||
|
for (const key of Object.keys(stats)) {
|
||||||
|
stats[key] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.recoveryToken.recovery();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
printStats(stats);
|
||||||
}
|
}
|
||||||
exporterProgress(title: string) {
|
exporterProgress(title: string) {
|
||||||
const bar = !this.opts.noProgress
|
const bar = !this.opts.noProgress
|
||||||
|
|
@ -150,12 +181,13 @@ export class App {
|
||||||
|
|
||||||
return { redraw, endBar };
|
return { redraw, endBar };
|
||||||
}
|
}
|
||||||
async _exportOnce() {
|
private async _exportOnce(
|
||||||
|
{ stats }: {
|
||||||
|
stats: Record<string, number>;
|
||||||
|
},
|
||||||
|
) {
|
||||||
const exporters = await this.getExporters();
|
const exporters = await this.getExporters();
|
||||||
const skipMode = this.getSkipMode();
|
const skipMode = this.getSkipMode();
|
||||||
const stats: Record<string, number> = Object.fromEntries(
|
|
||||||
exporters.map((e) => [e.name, 0]),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (skipMode.includes("vs")) {
|
if (skipMode.includes("vs")) {
|
||||||
console.log("Skip exporting VS games.");
|
console.log("Skip exporting VS games.");
|
||||||
|
|
@ -201,7 +233,9 @@ export class App {
|
||||||
endBar();
|
endBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skipMode.includes("coop")) {
|
// TODO: remove this filter when stat.ink support coop export
|
||||||
|
const coopExporter = exporters.filter((e) => e.name !== "stat.ink");
|
||||||
|
if (skipMode.includes("coop") || coopExporter.length === 0) {
|
||||||
console.log("Skip exporting Coop games.");
|
console.log("Skip exporting Coop games.");
|
||||||
} else {
|
} else {
|
||||||
console.log("Fetching coop battle list...");
|
console.log("Fetching coop battle list...");
|
||||||
|
|
@ -217,8 +251,7 @@ export class App {
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
// TODO: remove this filter when stat.ink support coop export
|
coopExporter.map((e) =>
|
||||||
exporters.filter((e) => e.name !== "stat.ink").map((e) =>
|
|
||||||
showError(
|
showError(
|
||||||
this.exportGameList({
|
this.exportGameList({
|
||||||
type: "CoopInfo",
|
type: "CoopInfo",
|
||||||
|
|
@ -239,14 +272,6 @@ export class App {
|
||||||
|
|
||||||
endBar();
|
endBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
|
||||||
`Exported ${
|
|
||||||
Object.entries(stats)
|
|
||||||
.map(([name, count]) => `${name}: ${count}`)
|
|
||||||
.join(", ")
|
|
||||||
}`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
async monitor() {
|
async monitor() {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue