@choiceform/os-client-core 3.6.39 → 3.6.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +747 -0
- package/dist/infer.js +1 -1
- package/dist/web-core.js +1 -1
- package/package.json +20 -17
package/dist/infer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const inferCommander={accumulated:[],consumingStarted:!1,ended:!1,postingCount:0,queryObj:null,iframeCount:0,startTime:0,messageDiv:null,errorDiv:null,workersDiv:null,typeColorMap:{error:"red",skip:"orange"},successCount:0,skipCount:0,errorCount:0,tryCount:0,rejectCount:0,requireCount:0,timeLog:null,start(){this.queryObj=this.queryToObj(),this.iframeCount=this.queryObj.thread||10,this.startTime=Date.now(),this.progressDiv=document.getElementById("message"),this.errorDiv=document.getElementById("error"),this.workersDiv=document.getElementById("workers"),this.timeLog=document.querySelector("#time-log tbody"),window.addEventListener("message",(t=>{const{name:e,id:s,progress:r,round:i}=t.data;"infer_worker"===e?this.accumulate(t.data):"infer_progress"===e&&this.updateWorkerStatus(r,s,i)})),this.requireCount=Number(this.queryObj.count),this.iframeCount=Math.min(this.requireCount,this.iframeCount),this.workersDiv.innerHTML=`<div>使用${this.iframeCount}个工人执行任务</div>`,this.iframes=[];const t=Object.keys(this.queryObj).reduce(((t,e)=>{let s=e;if(["time_range","status","collector_id"].includes(e))s="infer_"+e;else{if(!s.startsWith("$$_"))return t;s=s.substring(3)}return t+`&${s}=${this.queryObj[e]}`}),"");for(let e=0;e<this.iframeCount;e++){const s=document.createElement("iframe");let r=`../infer-worker.html?sid=${this.queryObj.sid}&infer_id=${e}${t}`;s.src=r,s.style.display="none",this.iframes.push(s),document.body.appendChild(s);const i=`<span>工人${e+1}:</span>\n <span class='worker_status'>准备中...</span>\n <span class='worker_progress'></span>`,n=document.createElement("div");n.setAttribute("id","infer_id_"+e),n.innerHTML=i,this.workersDiv.appendChild(n)}},enableImmediateNextTask(){return this.postingCount<this.requireCount-this.successCount},accumulate(t){this.accumulated.push(t),this.consumingStarted||(this.consumingStarted=!0,this.consume())},consume(){if(this.ended)return;if(!this.enableImmediateNextTask())return void(this.consumingStarted=!1);const t=this.accumulated.shift();if(t){this.tryCount++;const{type:e,message:s}=t;if("END"===e)if(this.queryObj.dry){this.successCount++,this.handleProgress("success");const e=t.data.result.answers.length,s=t.data.result.time_consuming,r=Math.round(s/e);console.info(s,e,r);const i=document.createElement("tr");i.innerHTML=`<td>${this.successCount}</td>\n <td>${s}</td><td>${e}</td><td>${r}</td>`,this.timeLog.appendChild(i)}else this.postData(t.data).then((()=>{this.successCount++,this.handleProgress("success")})).catch((t=>{"rejected"===t?(this.rejectCount++,this.handleProgress("reject")):(this.errorCount++,this.handleProgress("error",s))})),this.consume();else"ERROR"===e||"NEXT_FAIL"===e||"TIMEOUT"===e||"ABANDON"===e?(this.errorCount++,this.handleProgress("error",s)):"CHECK_END"===e&&(this.skipCount++,this.handleProgress("skip",s))}else this.consumingStarted=!1},postData(t){return this.postingCount++,new Promise(((e,s)=>{const r=new XMLHttpRequest;return r.onload=()=>{this.postingCount--,r.status>=200&&r.status<300?e():s()},r.onerror=()=>{this.postingCount--,s()},r.open("POST",t.url),r.setRequestHeader("content-type","application/json"),r.setRequestHeader("Authorization","
|
|
1
|
+
const inferCommander={accumulated:[],consumingStarted:!1,ended:!1,postingCount:0,queryObj:null,iframeCount:0,startTime:0,messageDiv:null,errorDiv:null,workersDiv:null,typeColorMap:{error:"red",skip:"orange"},successCount:0,skipCount:0,errorCount:0,tryCount:0,rejectCount:0,requireCount:0,timeLog:null,start(){this.queryObj=this.queryToObj(),this.iframeCount=this.queryObj.thread||10,this.startTime=Date.now(),this.progressDiv=document.getElementById("message"),this.errorDiv=document.getElementById("error"),this.workersDiv=document.getElementById("workers"),this.timeLog=document.querySelector("#time-log tbody"),window.addEventListener("message",(t=>{const{name:e,id:s,progress:r,round:i}=t.data;"infer_worker"===e?this.accumulate(t.data):"infer_progress"===e&&this.updateWorkerStatus(r,s,i)})),this.requireCount=Number(this.queryObj.count),this.iframeCount=Math.min(this.requireCount,this.iframeCount),this.workersDiv.innerHTML=`<div>使用${this.iframeCount}个工人执行任务</div>`,this.iframes=[];const t=Object.keys(this.queryObj).reduce(((t,e)=>{let s=e;if(["time_range","status","collector_id"].includes(e))s="infer_"+e;else{if(!s.startsWith("$$_"))return t;s=s.substring(3)}return t+`&${s}=${this.queryObj[e]}`}),"");for(let e=0;e<this.iframeCount;e++){const s=document.createElement("iframe");let r=`../infer-worker.html?sid=${this.queryObj.sid}&infer_id=${e}${t}`;s.src=r,s.style.display="none",this.iframes.push(s),document.body.appendChild(s);const i=`<span>工人${e+1}:</span>\n <span class='worker_status'>准备中...</span>\n <span class='worker_progress'></span>`,n=document.createElement("div");n.setAttribute("id","infer_id_"+e),n.innerHTML=i,this.workersDiv.appendChild(n)}},enableImmediateNextTask(){return this.postingCount<this.requireCount-this.successCount},accumulate(t){this.accumulated.push(t),this.consumingStarted||(this.consumingStarted=!0,this.consume())},consume(){if(this.ended)return;if(!this.enableImmediateNextTask())return void(this.consumingStarted=!1);const t=this.accumulated.shift();if(t){this.tryCount++;const{type:e,message:s}=t;if("END"===e)if(this.queryObj.dry){this.successCount++,this.handleProgress("success");const e=t.data.result.answers.length,s=t.data.result.time_consuming,r=Math.round(s/e);console.info(s,e,r);const i=document.createElement("tr");i.innerHTML=`<td>${this.successCount}</td>\n <td>${s}</td><td>${e}</td><td>${r}</td>`,this.timeLog.appendChild(i)}else this.postData(t.data).then((()=>{this.successCount++,this.handleProgress("success")})).catch((t=>{"rejected"===t?(this.rejectCount++,this.handleProgress("reject")):(this.errorCount++,this.handleProgress("error",s))})),this.consume();else"ERROR"===e||"NEXT_FAIL"===e||"TIMEOUT"===e||"ABANDON"===e?(this.errorCount++,this.handleProgress("error",s)):"CHECK_END"===e&&(this.skipCount++,this.handleProgress("skip",s))}else this.consumingStarted=!1},postData(t){return this.postingCount++,new Promise(((e,s)=>{const r=new XMLHttpRequest;return r.onload=()=>{this.postingCount--,r.status>=200&&r.status<300?e():s()},r.onerror=()=>{this.postingCount--,s()},r.open("POST",t.url),r.setRequestHeader("content-type","application/json"),r.setRequestHeader("Authorization","Bearer "+t.jwt),r.send(JSON.stringify(t.result)),r}))},queryToObj(){const t=location.href.split("?")[1].split("&"),e={};return t.forEach((t=>{const s=t.split("=");e[s[0]]=s[1]})),e},shouldEnd(){if(this.successCount>=this.requireCount||this.rejectCount)return!0;const{max_error_count:t,max_try_count:e,max_skip_count:s}=this.queryObj;return!!(e&&this.tryCount>=e)||!!(t&&this.errorCount>=t)||!!(s&&this.skipCount>=s)},updateWorkerStatus(t,e,s){if(!this.ended&&window.parent===window){const{percent:r,fullLength:i,index:n}=t,o=this.workersDiv.querySelector("#infer_id_"+e);o.querySelector(".worker_status").textContent=`轮次: ${s} `,o.querySelector(".worker_progress").textContent=`进度: ${n}/${i} ${r}%`}},handleProgress(t,e){if(this.shouldEnd()){this.ended=!0;let t=this.iframes.pop();for(;t;)document.body.removeChild(t),t=this.iframes.pop();const e=this.workersDiv.querySelectorAll(".worker_status"),s=this.workersDiv.querySelectorAll(".worker_progress");e.forEach((t=>t.innerHTML="收工")),s.forEach((t=>t.innerHTML=""))}if(window.parent!==window)window.parent.postMessage({name:"infer_result",requireCount:this.requireCount,successCount:this.successCount,skipCount:this.skipCount,errorCount:this.errorCount,tryCount:this.tryCount,rejectCount:this.rejectCount,ended:this.ended,cost:this.ended?Date.now()-this.startTime:void 0,type:t,message:e},"*");else if(this.progressDiv.innerHTML=[this.ended?`<div>已结束,耗时: ${(Date.now()-this.startTime)/1e3}s</div>`:"<div>运行中...</div>",`<div>要求总数量:${this.requireCount}</div>`,`<div>已尝试次数:${this.tryCount}</div>`,`<div style='color: green'>已成功次数:${this.successCount}</div>`,`<div style='color: red'>出错误次数:${this.errorCount}</div>`,`<div style='color: orange'>被甄别次数:${this.skipCount}</div>`,`<div style='color: tomato'>被拒绝次数:${this.rejectCount}</div>`].join("\n"),e){const s=`<div style='color: ${this.typeColorMap[t]}'>${e}</div>`;this.errorDiv.innerHTML+=s}this.ended||this.consume()}};inferCommander.start();
|