答题结果处理器
(options: {
// doWork 的返回值结果
results: WorkResult<E>[];
// 提交类型
type: WorkUploadType;
/**
* 是否上传处理器
*
* @param uploadable 是否可以上传
* @param finishedRate 完成率
*/
callback: (finishedRate: number, uploadable: boolean) => void | Promise<void>;
})
| 330 | |
| 331 | /** 答题结果处理器 */ |
| 332 | uploadHandler(options: { |
| 333 | // doWork 的返回值结果 |
| 334 | results: WorkResult<E>[]; |
| 335 | // 提交类型 |
| 336 | type: WorkUploadType; |
| 337 | /** |
| 338 | * 是否上传处理器 |
| 339 | * |
| 340 | * @param uploadable 是否可以上传 |
| 341 | * @param finishedRate 完成率 |
| 342 | */ |
| 343 | callback: (finishedRate: number, uploadable: boolean) => void | Promise<void>; |
| 344 | }) { |
| 345 | const { results, type, callback } = options; |
| 346 | if (type !== 'nomove') { |
| 347 | let finished = 0; |
| 348 | for (const result of results) { |
| 349 | if (result.result?.finish) { |
| 350 | finished++; |
| 351 | } |
| 352 | } |
| 353 | const rate = results.length === 0 ? 0 : (finished / results.length) * 100; |
| 354 | if (type === 'force') { |
| 355 | return callback(rate, true); |
| 356 | } else { |
| 357 | return callback(rate, type === 'save' ? false : rate >= parseFloat(type.toString())); |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | export class CustomOCSWorker extends CommonEventEmitter<WorkerEvents> { |
no test coverage detected