@idm-plugin/vessel 3.7.5 → 3.7.6

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/dist/index.js CHANGED
@@ -916,7 +916,7 @@ class H {
916
916
  static waveHeightFactor(e, t, a = 10) {
917
917
  e = e < 3 ? e * 0.7 : e, e = e < 0 ? 0.2 : e, e = e > 6 ? e - 0.9 * (e - 6) : e, e = e > 9 ? 9 : e;
918
918
  let o;
919
- return t > 30 && t <= 60 ? o = -0.6 : t > 60 && t <= 90 ? o = -0.5 : t > 90 && t <= 120 ? o = e < 4 ? 0.4 : -0.15 : t > 120 && t <= 150 ? o = e < 4 ? 0.5 : -0.12 : t > 150 && t <= 180 ? o = e < 4 ? 0.6 : -0.1 : o = -0.7, Math.round(o * (0.144 * Math.pow(e, 2) + 0.378 * e) * 1e4) / 1e4;
919
+ return t > 30 && t <= 60 ? o = -0.6 : t > 60 && t <= 90 ? o = -0.5 : t > 90 && t <= 120 ? o = e < 4 ? 0.4 : -0.4 : t > 120 && t <= 150 ? o = e < 4 ? 0.5 : -0.5 : t > 150 && t <= 180 ? o = e < 4 ? 0.6 : -0.6 : o = -0.7, Math.round(o * (0.144 * Math.pow(e, 2) + 0.378 * e) * 1e4) / 1e4;
920
920
  }
921
921
  /**
922
922
  * 组装船舶运行参数
@@ -1094,7 +1094,7 @@ class H {
1094
1094
  let d = l * r * h / 100 * (e.speed - n);
1095
1095
  d = Math.round(d * 1.943844 * 1e4) / 1e4 * -1, e.tag === "tugs" && Math.abs(d) > 1 && (d = d / (Math.abs(Math.round(d)) + 1)), S == null || S.info("[%s] calculate wind wx factor: %d", o.requestId, d), u = R.includedAngle(e.bearing, (v = (p = t == null ? void 0 : t.wave) == null ? void 0 : p.sig) == null ? void 0 : v.degree);
1096
1096
  const I = H.waveHeightFactor(((c = (m = t == null ? void 0 : t.wave) == null ? void 0 : m.sig) == null ? void 0 : c.height) ?? 1, u, e.draught);
1097
- return S == null || S.info("[%s] calculate wave wx factor: %d", I), d = Math.abs(d) > Math.abs(I) ? d : 0.7 * d + 0.9 * I, S == null || S.info("[%s] calculate finial weather factor: %d (0.7 * wf) + (0.9 * hf)", o.requestId, d), Math.round((d || 0) * 100) / 100;
1097
+ return S == null || S.info("[%s] calculate wave wx factor: %d", o.requestId, I), d = Math.abs(d) > Math.abs(I) ? d : 0.7 * d + 0.9 * I, S == null || S.info("[%s] calculate finial weather factor: %d (0.7 * wf) + (0.9 * hf)", o.requestId, d), Math.round((d || 0) * 100) / 100;
1098
1098
  }
1099
1099
  /**
1100
1100
  * 以12小时级别去掉重复的days
@@ -1 +1 @@
1
- (function(P,x){typeof exports=="object"&&typeof module<"u"?x(exports,require("got"),require("@log4js-node/log4js-api"),require("moment"),require("@idm-plugin/geo2"),require("@idm-plugin/meteo2"),require("@idm-plugin/meteo")):typeof define=="function"&&define.amd?define(["exports","got","@log4js-node/log4js-api","moment","@idm-plugin/geo2","@idm-plugin/meteo2","@idm-plugin/meteo"],x):(P=typeof globalThis<"u"?globalThis:P||self,x(P["idm-plugin-vessel"]={},P.got,P["@log4js-node/log4js-api"],P.moment,P["@idm-plugin/geo2"],P["@idm-plugin/meteo2"],P["@idm-plugin/meteo"]))})(this,function(P,x,K,w,E,pt,it){"use strict";var St=Object.defineProperty;var Ct=(P,x,K)=>x in P?St(P,x,{enumerable:!0,configurable:!0,writable:!0,value:K}):P[x]=K;var U=(P,x,K)=>(Ct(P,typeof x!="symbol"?x+"":x,K),K);let M;try{M=K.getLogger("vessel")}catch{}finally{}class G{parseStatus(e){let t,a;switch(e){case 0:t="在航(主机推动)",a="Underway Using Engine";break;case 1:t="锚泊",a="Anchored";break;case 2:t="失控",a="Not under command";break;case 3:t="操纵受限",a="Limited airworthiness";break;case 4:t="吃水受限",a="Limited by ship's draft";break;case 5:t="靠泊",a="Mooring";break;case 6:t="搁浅",a="Stranded";break;case 7:t="捕捞作业",a="Engaged in fishing";break;case 8:t="靠帆船提供动力",a="Sailing";break;default:t="未定义",a="Undefined"}return{labelCn:t,labelEn:a}}}class Mt extends G{constructor(t,a){super();U(this,"clientId");U(this,"clientSecret");U(this,"token");this.clientId=t,this.clientSecret=a}async authToken(t={}){const a="https://svc.data.myvessel.cn/ada/oauth/token",o={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},i=await x.post(a,o).json();M==null||M.info("[%s] fetch access token from: %s - %j",t.requestId,a,i),i.error||(this.token={accessToken:i.access_token,tokenType:i.token_type,expiresIn:i.expires_in,scope:i.scope,jti:i.jti,issuedAt:w().utc().format()})}async checkToken(t={}){var a;return(!this.token||w().diff(w(this.token.issuedAt),"seconds")>(((a=this.token)==null?void 0:a.expiresIn)||0)-300)&&await this.authToken(t),this.token}async suggest(t,a={}){var s,r;await this.checkToken(a);const o="https://market.myvessel.cn/sdc/v1/mkt/vessels/fuzzy",i={headers:{Authorization:`${(s=this.token)==null?void 0:s.tokenType} ${(r=this.token)==null?void 0:r.accessToken}`},json:{kw:t,recordNum:a.ps||10}};M==null||M.info("[%s] fetch suggest vessels from: %s - %j",a.requestId,o,i);const n=await x.post(o,i).json();return n.status!==200?(M==null||M.warn("[%s] fetch suggest vessels failed: %j",a.requestId,{message:n.message,status:n.status,code:n.code}),[]):(n.data||[]).map(l=>({mmsi:l.mmsi,name:l.nameEn,nameCn:l.nameCn,imo:Number.isNaN(l.imo)?null:Number(l.imo),callSign:l.callsign,type:l.vesselTypeNameEn,flagName:l.flagCtry,vendor:"myvessel",raw:l}))}async search(t,a={}){var u,l;await this.checkToken(a);const o=/^\d{7}$/.test(t.toString()),i=o?"https://market.myvessel.cn/sdc/v1/mkt/vessels/detail/imo":"https://market.myvessel.cn/sdc/v1/mkt/vessels/detail/mmsi",n=o?{imo:t}:{mmsi:t},s={headers:{Authorization:`${(u=this.token)==null?void 0:u.tokenType} ${(l=this.token)==null?void 0:l.accessToken}`},searchParams:n};M==null||M.info("[%s] fetch vessel from: %s - %j",a.requestId,i,s);const r=await x.get(i,s).json();if(r.status!==200)return M==null||M.warn("[%s] fetch suggest vessels failed: %j",a.requestId,{message:r.message,status:r.status,code:r.code}),{};{const h=r.data;if(h)return{mmsi:h.mmsi,imo:Number.isNaN(h.imo)?null:Number(h.imo),callSign:h.callsign,name:h.nameEn,nameCn:h.nameCn,type:h.vesselTypeNameEn,flagName:h.flagCtry,clasz:h.classSociety,dateOfBuild:h.buildYearMonth,deadweight:h.dwt,grossTonnage:h.grt,netTonnage:h.net,teu:h.teu,length:h.length,breadth:h.width,height:h.height,draught:h.draught,speed:h.speed,passengerCapacity:h.passengercapacity,vendor:"myvessel",raw:h}}return{}}async archives(t,a={}){var s,r;await this.checkToken(a);const o="https://svc.data.myvessel.cn/sdc/v1/ship/info/batch",i={headers:{Authorization:`${(s=this.token)==null?void 0:s.tokenType} ${(r=this.token)==null?void 0:r.accessToken}`},json:{mmsiList:typeof t=="number"?[t]:t}};M==null||M.info("[%s] fetch vessel archive from: %s - %j",a.requestId,o,i);const n=await x.post(o,i).json();return n.status!==200?(M==null||M.warn("[%s] fetch vessel archive failed: %j",a.requestId,{message:n.message,status:n.status,code:n.code}),{}):n.data}async realTimePosition(t,a={}){var r,u;await this.checkToken(a);const o="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",i={headers:{Authorization:`${(r=this.token)==null?void 0:r.tokenType} ${(u=this.token)==null?void 0:u.accessToken}`},searchParams:{mmsi:t}};M==null||M.info("[%s] fetch realtime position from: %s - %j",a.requestId,o,i);const n=await x.get(o,i).json();if(n.code)return M==null||M.warn("[%s] fetch realtime position failed: %j",a.requestId,{message:n.message,status:n.status,code:n.code}),n;const s=n.data;for(const l in s)!isNaN(s[l])&&Number(s[l])!==1/0&&(s[l]=Number(s[l]));if(s){const l=w(`${s.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:s.mmsi,name:s.vesselName||s.aisVesselName,imo:s.imo,callSign:s.callsign||s.aisCallSign,lat:s.lat,lng:s.lon,length:s.length,width:s.width,draught:s.currDraught,sog:s.sog,cog:s.cog,hdg:s.hdg,rot:s.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta)?w.utc(s.eta).format():void 0,destination:s.dest,positionTime:l.unix(),status:s.status,labelCn:s.statusNameCn,labelEn:s.statusNameEn,vesselType:s.vesselTypeNameEn,flag:s.flagCtryNameEn,clasz:s.classSociety,build:s.buildYear,dwt:s.dwt,grt:s.grt,net:s.net,method:"position",vendor:"myVessel",utc:l.utc().format()}}else return{}}async calculateRoute(t,a,o,i,n,s={}){var I,v,T;const r=w();await this.checkToken(s);const u="https://market.myvessel.cn/sdc/v1/mkt/routes/plan",l={maxDraught:s.draught||10,useAIModel:s.useAIModel??!0,withECA:s.withECA||!1,withSpecialRegion:s.withSpecial||!1};t.code&&(l.startPortCode=t.code),t.lng!==void 0&&t.lat!==void 0&&(l.startPoint={lon:t.lng,lat:t.lat}),a.code&&(l.endPortCode=a.code),a.lng!==void 0&&a.lat!==void 0&&(l.endPoint={lon:a.lng,lat:a.lat}),o!=null&&o.length&&(l.crossMonthList=o),i!=null&&i.length&&(l.excludeNodes=i),n!=null&&n.length&&(l.excludeSeaAreas=n);const h={headers:{Authorization:`${(I=this.token)==null?void 0:I.tokenType} ${(v=this.token)==null?void 0:v.accessToken}`},json:l};M==null||M.info("[%s] fetch route from: %s - %j",s.requestId,u,h);const d=await x.post(u,h).json();if(d.status!==200)return M==null||M.warn("[%s] fetch route failed: %j",s.requestId,{message:d.message,status:d.status,code:d.code}),{};{const k={status:"Success",nodes:[],seas:[],regions:[],waypoints:[],route:[],distance:0,memo:""},{nodes:g,seas:b,tracks:f,specialRegions:c,ecaLength:m}=d.data;k.nodes=g==null?void 0:g.map(p=>({code:p.nodeCode,nameEn:p.nameEn,nameCn:p.nameCn,center:{lat:Math.round(p.lat*1e6)/1e6,lng:Math.round(p.lon*1e6)/1e6},start:{lat:Math.round(p.startLat*1e6)/1e6,lng:Math.round(p.startLon*1e6)/1e6},end:{lat:Math.round(p.endLat*1e6)/1e6,lng:Math.round(p.endLat*1e6)/1e6},isKey:p.isKeyNode,isHub:p.isHubNode})),k.seas=b==null?void 0:b.map(p=>({code:p.mrgidSea,nameEn:p.nameEn,nameCn:p.nameCn,center:{lat:Math.round(p.centerLat*1e6)/1e6,lng:Math.round(p.centerLon*1e6)/1e6},min:{lat:Math.round(p.minLat*1e6)/1e6,lng:Math.round(p.minLon*1e6)/1e6},max:{lat:Math.round(p.maxLat*1e6)/1e6,lng:Math.round(p.maxLon*1e6)/1e6},level:p.mapLevel})),c==null||c.map(p=>{p.regionLength&&k.regions.push({type:p.regionType,distance:p.regionLength,rows:p.regions.map(L=>({code:L.regionCode,nameCn:L.nameCn,nameEn:L.nameEn,type:L.regionType,distance:L.length}))})}),k.waypoints=f==null?void 0:f.map(p=>({lat:Math.round(p.lat*1e5)/1e5,lng:Math.round(p.lon*1e5)/1e5})),(T=k.waypoints)!=null&&T.length&&(k.waypoints=E.LaneHelper.simplifyCoordinates(k.waypoints),k.route=E.LaneHelper.divideAccordingToLng(k.waypoints),k.distance=E.LaneHelper.calculateRouteDistance(k.route),k.distanceInECA=m);const F=w().diff(r,"second");return k.memo=`time cost: ${F}s`,M.info("[%s] calculate route cost: %d seconds",s.requestId,F),k}}async trajectory(t,a,o,i,n=!0,s={}){await this.checkToken(s);const r=await this.realTimePosition(t,s),u=w(a),l=w(o),h=[];for(;l.diff(u,"day",!0)>30;)await this.trajectoryIn30Day(t,u,u.clone().add(30,"day"),r,i,h,s),u.add(30,"day");return await this.trajectoryIn30Day(t,u,l,r,i,h,s),h}async trajectoryIn30Day(t,a,o,i,n,s,r={}){var v,T,k,g,b;const u="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",l={headers:{Authorization:`${(v=this.token)==null?void 0:v.tokenType} ${(T=this.token)==null?void 0:T.accessToken}`},json:{mmsi:t,startTime:a.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:o.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};M==null||M.info("[%s] fetch trajectory from: %s - %j",r.requestId,u,l);const h=await x.post(u,l).json();if(h.code)return M==null||M.warn("[%s] fetch trajectory failed: %j",r.requestId,u,{message:h.message,status:h.status,code:h.code}),h;let d=-1;const I=w(`${(g=(k=h.data)==null?void 0:k[0])==null?void 0:g.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(b=h.data)==null||b.forEach(f=>{for(const H in f)!isNaN(f[H])&&Number(f[H])!==1/0&&(f[H]=Number(f[H]));const c=w(`${f.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),m=f.status,{labelCn:y,labelEn:F}=this.parseStatus(m),p={mmsi:f.mmsi,imo:i==null?void 0:i.imo,lat:f.lat,lng:f.lon,sog:f.sog,cog:f.cog,hdg:f.hdg,draught:f.draught,status:m,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(f.eta)?w(`${f.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").utc().format():void 0,destination:f.dest,positionTime:c.unix(),labelCn:y,labelEn:F,method:"trajectory",vendor:"myVessel",utc:c.utc().format()},L=Math.floor(c.diff(I,"minute",!0)/(n||1));L!==d&&(d=L,s.push(p))}),s}}class vt extends G{constructor(t){super();U(this,"token");this.token=t}async realTimePosition(t,a={}){const o="https://api.hifleet.com/position/position/get/token",i={searchParams:{mmsi:t,usertoken:this.token}},n=await x.post(o,i).json();M==null||M.info("[%s] fetch realtime position from: %s - %j",a.requestId,o,i);const s=n==null?void 0:n.list;if(!s)return M==null||M.warn("[%s] fetch realtime position failed: %j",a.requestId,o,n),n;for(const I in s)!isNaN(s[I])&&Number(s[I])!==1/0&&(s[I]=Number(s[I]));s.status=s.sp>3?0:1;const r=s.status,{labelCn:u,labelEn:l}=this.parseStatus(r),h=w(`${s.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:s.m,name:s.n,imo:s.imonumber,callSign:s.callsign,lat:Math.round(s.la/60*1e5)/1e5,lng:Math.round(s.lo/60*1e5)/1e5,length:s.l,width:s.w,draught:s.draught,sog:s.sp,cog:s.co,hdg:s.h,rot:isNaN(s.rot)?0:s.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta)?w.utc(s.eta).format():void 0,destination:s.destination,vesselType:s.type,dwt:s.dwt,build:s.buildyear,flag:s.fn,positionTime:h.unix(),utc:h.utc().format(),status:r,labelCn:u,labelEn:l,method:"position",vendor:"hifleet"}}async search(t,a={}){let o="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const i={searchParams:{keyword:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let n=await x.post(o,i).json();M==null||M.info("[%s] fetch vessel props from: %s - %j",a.requestId,o,i),n instanceof Array&&(n=n[0]);for(const r in n)!isNaN(n[r])&&Number(n[r])!==1/0&&(n[r]=Number(n[r]));const s={mmsi:n.m,name:n.n,imo:n.i,callSign:n.c,length:n.l,breadth:n.b,draught:n.dr,type:n.t};return o="https://www.hifleet.com/hifleetapi/sameShipSearch.do",n=await x.post(o,i).json(),M==null||M.info("[%s] search vessel dead weight from: %s - %j",a.requestId,o,i),n instanceof Array&&(n=n[0]),n&&(s.deadweight=Number(n.dwt)),s}async suggest(t,a={}){const o="https://www.hifleet.com/hifleetapi/getShipSuggest.do",i={searchParams:{q:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}},n=await x.post(o,i).json();M==null||M.info("[%s] suggest vessel props from: %s - %j",a.requestId,o,i);const s=[];for(const r of n)s.push({mmsi:!r.mmsi||isNaN(r.mmsi)?null:Number(r.mmsi),name:r.name,callSign:r.callsign,imo:!r.imo||isNaN(r.imo)?null:Number(r.imo),score:r._score});return s.sort((r,u)=>u.score-r.score),s}async trajectory(t,a,o,i,n=!0,s={}){var f,c,m;const r=await this.realTimePosition(t,s);let u=w(a);const l=w(o),h=w();if(n){let y=l.diff(u,"d",!0);y<0?u=l.clone().subtract(40,"d"):y<30?u.subtract(10,"d"):y<60?u.subtract(5,"d"):u=l.clone().subtract(80,"d"),y=h.diff(l,"d",!0),l.add(y>10?240:y*24,"h")}const d={searchParams:{endtime:l.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),starttime:u.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),mmsi:t,usertoken:this.token}},I="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",v=await x.get(I,d).json();M==null||M.info("[%s] fetch trajectory from: %s - %j",s.requestId,I,d);let T;v&&(T=((c=(f=v.ships)==null?void 0:f.offors)==null?void 0:c.ship)||[],T.length||M==null||M.warn("[%s] fetch trajectory failed: %j",s.requestId,v));const k=[];let g=-1;const b=w(`${(m=T==null?void 0:T[0])==null?void 0:m.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const y of T){for(const W in y)!isNaN(y[W])&&Number(y[W])!==1/0&&(y[W]=Number(y[W]));const F=w(`${y.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");y.status=y.sp>4?0:1;const{labelEn:p,labelCn:L}=this.parseStatus(y.status),H={mmsi:y.m,name:y.n,imo:r==null?void 0:r.imo,lat:y.la,lng:y.lo,draught:y.draught,sog:y.sp,cog:y.co,hdg:y.hdg,positionTime:F.unix(),utc:F.utc().format(),status:y.status,labelCn:L,labelEn:p,method:"trajectory",vendor:"hifleet"},N=Math.floor(F.diff(b,"minute",!0)/(i||1));N!==g&&(g=N,k.push(H))}return k}}class bt extends G{constructor(t){super();U(this,"token");this.token=t}async realTimePosition(t,a={}){const o={searchParams:{id:t,k:this.token,enc:1}},i="https://api.shipxy.com/apicall/GetSingleShip",n=await x.get(i,o).json();if(M==null||M.info("[%s] fetch realtime position from: %s - %j",a.requestId,i,o),(n==null?void 0:n.status)!==0)return n;const s=n.data[0];for(const d in s)!isNaN(s[d])&&Number(s[d])!==1/0&&(s[d]=Number(s[d]));const{labelCn:r,labelEn:u}=await this.parseStatus(s.navistat),l=w.unix(s.lasttime);return{mmsi:s.ShipID,name:s.name,imo:s.imo,callSign:s.callsign,lat:Math.round(s.lat/1e6*1e5)/1e5,lng:Math.round(s.lon/1e6*1e5)/1e5,length:Math.round(s.length/10*100)/100,width:Math.round(s.width/10*100)/100,draught:Math.round(s.draught/1e3*100)/100,sog:Math.round(s.sog*3600/1e3/1852*100)/100,cog:Math.round(s.cog/100*100)/100,hdg:Math.round(s.hdg/100*100)/100,rot:Math.round(s.rot/100*100)/100,positionTime:s.lasttime,utc:l.utc().format(),status:s.navistat,labelEn:u,labelCn:r,method:"position",vendor:"shipxy"}}async trajectory(t,a,o,i,n=!0,s={}){var b;const r=await this.realTimePosition(t,s),u=w(a),l=w(o),h="https://api.shipxy.com/apicall/GetShipTrack",d={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:u.unix(),etm:l.unix()}},I=await x.get(h,d).json();if(M==null||M.info("[%s] fetch trajectory from: %s - %j",s.requestId,h,d),(I==null?void 0:I.status)!==0)return I;const v=I==null?void 0:I.points,T=[],k=w.unix((b=v[0])==null?void 0:b.utc);let g=-1;for(const f of v){const c=w.unix(f.utc),m={imo:r==null?void 0:r.imo,mmsi:t,sog:Math.round(f.sog*3600/1e3/1852*100)/100,cog:Math.round(f.cog/100*100)/100,lat:Math.round(f.lat/1e6*1e5)/1e5,lng:Math.round(f.lon/1e6*1e5)/1e5,positionTime:c.unix(),utc:c.utc().format(),method:"trajectory",vendor:"shipxy"},y=Math.floor(c.diff(k,"minute",!0)/(i||1));y!==g&&(g=y,T.push(m))}return T}}class gt extends G{constructor(t){super();U(this,"token");this.token=t}async getShipId(t,a={}){const o={headers:{appKey:this.token},json:{mmsiList:t}},i="https://api3.myships.com/sp/ships/getShipIdByMMSI",n=await x.post(i,o).json();return M==null||M.info("[%s] fetch ship id from: %s - %j",a.requestId,i,o),n.code!=="0"?n:n.data[0].shipId}async getShipInfo(t,a={}){const o={headers:{appKey:this.token},json:{shipId:t}},i="https://api3.myships.com/sp/ships/aissta",n=await x.post(i,o).json();if(M==null||M.info("[%s] fetch ship info from: %s - %j",a.requestId,i,o),n.code!=="0")return n;const s=n.data;let r=s.imo;return t==="407170"&&(r="9198379",M==null||M.warn("[%s] ship(%s) imo error: %s, should be %s",a.requestId,t,s.imo,r)),{mmsi:s.mmsi,name:s.shipnameEn,imo:r,callSign:s.callSign,length:s.length,width:s.breadth,draught:(s.draught||100)/10}}async realTimePosition(t,a={}){const o=await this.getShipId(t,a),i=await this.getShipInfo(o,a),n={headers:{appKey:this.token},json:{shipId:o}},s="https://api3.myships.com/sp/ships/position/latest",r=await x.post(s,n).json();M==null||M.info("[%s] fetch realtime position from: %s - %j",a.requestId,s,n);const u=r.data[0];for(const v in u)!isNaN(u[v])&&Number(u[v])!==1/0&&(u[v]=Number(u[v]));const{labelCn:l,labelEn:h}=await this.parseStatus(u.aisNavStatus),d=w.unix(u.posTime);return{...i,mmsi:t,lat:Math.round(u.lat/1e4/60*1e5)/1e5,lng:Math.round(u.lon/1e4/60*1e5)/1e5,sog:Math.round(u.sog/10*100)/100,cog:Math.round(u.cog/10*100)/100,hdg:Math.round(u.heading*100)/100,rot:Math.round(u.rot*100)/100,positionTime:u.posTime,utc:d.utc().format(),status:u.aisNavStatus,labelEn:h,labelCn:l,method:"position",vendor:"myship"}}async trajectory(t,a,o,i,n=!0,s={}){const r=w(a),u=w(o),l=await this.getShipId(t),h=await this.getShipInfo(l),d=[];for(;u.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(l,r.unix(),r.add(30,"day").unix(),h,t,i,d);return await this.trajectoryIn30Day(l,r.unix(),u.unix(),h,t,i,d),d}async trajectoryIn30Day(t,a,o,i,n,s,r,u={}){var k;const l={headers:{appKey:this.token},json:{shipId:t,startTime:a,endTime:o}},h="https://api3.myships.com/sp/ships/position/history",d=await x.post(h,l).json();if(M==null||M.info("[%s] fetch trajectory from: %s - %j",u.requestId,h,l),d.code!=="0")return M==null||M.warn("[%s] invoke myship trajectory failed: %j",u.requestId,d),d;const I=d.data;for(const g in I)!isNaN(I[g])&&Number(I[g])!==1/0&&(I[g]=Number(I[g]));const v=w.unix((k=I[0])==null?void 0:k.posTime);let T=-1;for(const g of I){const b=w.unix(g.posTime),f={imo:i==null?void 0:i.imo,mmsi:n,lat:Math.round(g.lat/1e4/60*1e5)/1e5,lng:Math.round(g.lon/1e4/60*1e5)/1e5,sog:Math.round(g.sog/10*100)/100,cog:Math.round(g.cog/10*100)/100,hdg:Math.round(g.heading*100)/100,rot:Math.round(g.rot*100)/100,positionTime:b.unix(),utc:b.utc().format(),method:"trajectory",vendor:"myship"},c=Math.floor(b.diff(v,"minute",!0)/(s||1));c!==T&&(T=c,r.push(f))}return r}}let _;try{_=K.getLogger("vessel")}catch{}finally{}var lt=(A=>(A.NOTICE="NOTICE",A.WARN="WARN",A.HEAVY="HEAVY",A.SEVERE="SEVERE",A.ERROR="ERROR",A.FATAL="FATAL",A))(lt||{});class ht{parsePrinciple(e,t={}){var s,r,u;_==null||_.debug("[%s] parse rule: %s",t.requestId,e);const a=new RegExp("(?<=\\[)(.+)(?=])","g"),o=e.match(a)?(s=e.match(a))==null?void 0:s[0]:void 0,i=o==null?void 0:o.split(";");if(!i)return;const n={};for(let l=0;l<(i==null?void 0:i.length);l++){const h=(u=(r=i[l].match(a))==null?void 0:r[0])==null?void 0:u.split("],");if(l===0&&!h)n.scope=i[0];else if(h)for(let d=0,I=h.length;d<I;d++){const v=this.parseRule(h[d]);v&&(n[v.level]?v.key?n[v.level][v==null?void 0:v.key]=v:n[v.level]=v:v.key?n[v.level]={[v==null?void 0:v.key]:v}:n[v.level]=v)}}return n}parseRule(e,t={}){var n;_==null||_.debug("[%s] parse rule: %s",t.requestId,e),e=e.startsWith("[")?e:`[${e}`,e=e.endsWith("]")?e:`${e}]`;const a=new RegExp("(?<=\\[)(.+?)(?=])","g"),o=(n=e==null?void 0:e.match(a))==null?void 0:n[0],i=o==null?void 0:o.split(",");if(i){let s=i[3]==="Number.MAX_VALUE"?100:Number(i[3]);return s=isNaN(s)?1:s,{operator:i[0],number:Number.isNaN(Number(i[1]))?i[1]:Number(i[1]),level:i[2],time:s,key:i[4]}}}checkWeather(e,t,a={}){var v,T,k,g,b,f,c,m,y,F,p,L,H,N,W;let o=0,i=0,n=0,s=0;const r=Math.round(((T=(v=t==null?void 0:t.SEVERE)==null?void 0:v.sigWave)==null?void 0:T.number)*1.6*100)/100,u=(g=(k=t==null?void 0:t.SEVERE)==null?void 0:k.sigWave)==null?void 0:g.number,l=(f=(b=t==null?void 0:t.HEAVY)==null?void 0:b.sigWave)==null?void 0:f.number,h=Math.round((((m=(c=t==null?void 0:t.SEVERE)==null?void 0:c.wind)==null?void 0:m.number)+2)*100)/100,d=(F=(y=t==null?void 0:t.SEVERE)==null?void 0:y.wind)==null?void 0:F.number,I=(L=(p=t==null?void 0:t.HEAVY)==null?void 0:p.wind)==null?void 0:L.number;for(let B=0;B<(e==null?void 0:e.length);B++){const S=e[B],R=(N=(H=S==null?void 0:S.meteo)==null?void 0:H.wave)==null?void 0:N.sig,D=(W=S==null?void 0:S.meteo)==null?void 0:W.wind,z=B?w(S.eta).diff(w(e[B-1].eta),"hour",!0):0;s=z>s?z:s,_==null||_.debug("[%s] check sig.wave: %j",a.requestId,{...R,dgThd4Wv:r,svThd4Wv:u,hvThd4Wv:l}),(R==null?void 0:R.height)>=r?S.isDangerous=!0:(R==null?void 0:R.height)>=u?S.isSevere=!0:(R==null?void 0:R.height)>=l&&(S.isHeavy=!0),_==null||_.debug("[%s] check wind: %j",a.requestId,{...D,dgThd4Wd:h,svThd4Wd:d,hvThd4Wd:I}),(D==null?void 0:D.scale)>=h?(S.isDangerous=!0,delete S.isSevere,delete S.isHeavy):(D==null?void 0:D.scale)>d?(S.isDangerous||(S.isSevere=!0),delete S.isHeavy):(D==null?void 0:D.scale)===I&&!S.isDangerous&&!S.isSevere&&(S.isHeavy=!0),o+=S.isDangerous?z:0,i+=S.isSevere?z:0,n+=S.isHeavy?z:0}return o=Math.round(o*100)/100,i=Math.round(i*100)/100,n=Math.round(n*100)/100,s=Math.round(s),{sample:e,dangerous:o,severe:i,heavy:n,step:s<3?3:s,wind:{dgThd4Wd:h,svThd4Wd:d,hvThd4Wd:I},sig:{dgThd4Wv:r,svThd4Wv:u,hvThd4Wv:l}}}}const wt=new ht;let C;try{C=K.getLogger("vessel")}catch{}finally{}const It=new pt.MeteoHelper2("",!0);var ft=(A=>(A.common="common",A.container="container",A.tugs="tugs",A))(ft||{}),mt=(A=>(A.Ballast="Ballast",A.Laden="Laden",A))(mt||{}),yt=(A=>(A.Cp="CP",A.Perf="Basis",A.Instruct="Other",A))(yt||{});class O{static blockCoefficient(e,t,a,o){let i=Math.round(e/(t*a*o)*100)/100;i=i<.55?.55:i>.85?.85:i;const n=[.55,.6,.65,.7,.75,.8,.85],s=n.map(r=>Math.abs(r-i));return n[s.indexOf(Math.min(...s))]}static froudeNumber(e,t,a=9.8){let o=Math.round(Math.sqrt(e*e/(a*t))*100)/100;return o=o<.05?.05:o>.3?.3:o,o}static amendFactor(e,t,a){const o={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.4,-10.6,-9.5],.8:[2.6,-13.1,-15.1],.85:[3.1,-18.7,28]};let n={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.6,-12.5,-13.5],.8:[3,-16.3,-21.6],.85:[3.4,-20.9,31.8]}[e];return a==="Laden"&&(n=o[e]),n[0]+n[1]*t+n[2]*Math.pow(t,2)}static directionFactor(e,t=0){let a;return e>30&&e<=60?a=(1.7-.03*Math.pow(t-4,2))/2:e>60&&e<=150?a=(.9-.06*Math.pow(t-6,2))/2:e>150&&e<=180?a=(.4-.03*Math.pow(t-8,2))/2:a=1,Math.round(a*1e5)/1e5}static vesselTagFactor(e,t,a,o){let i;return a==="container"?i=.7*o/2+Math.pow(o,3)/(22*Math.pow(e,2/3)):t==="Ballast"?i=.7*o/2+Math.pow(o,3)/(2.7*Math.pow(e,2/3)):i=.5*o/2+Math.pow(o,3)/(2.7*Math.pow(e,2/3)),i}static waveHeightFactor(e,t,a=10){e=e<3?e*.7:e,e=e<0?.2:e,e=e>6?e-.9*(e-6):e,e=e>9?9:e;let o;return t>30&&t<=60?o=-.6:t>60&&t<=90?o=-.5:t>90&&t<=120?o=e<4?.4:-.15:t>120&&t<=150?o=e<4?.5:-.12:t>150&&t<=180?o=e<4?.6:-.1:o=-.7,Math.round(o*(.144*Math.pow(e,2)+.378*e)*1e4)/1e4}static assembleProperties(e,t,a,o){var d;const i=e.lbp??e.length??e.lengthOverall??198.9642,n=e.draught??8,s=e.breadthMoulded??e.breadth??e.breadthExtreme??32.4572,r=e.deadweight??67035.7773,u=((d=e==null?void 0:e.type)==null?void 0:d.toLowerCase())||"common";return{tag:u.indexOf("container")>-1?"container":u.indexOf("tugs")>-1?"tugs":"common",lbp:i,loadCondition:t,draught:n,breadthMoulded:s,displacement:Math.round((r/1.025+n*s*i*.7)*1e4)/1e4,speed:Math.round((a??14.1382)*1852/3600*1e4)/1e4,bearing:o||90}}static async speedLoseAt(e,t,a,o="",i=2,n=!0,s=!1,r={}){let u;if(t.velocity&&s&&(e.speed=E.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),n){let l;try{o=(o==null?void 0:o.toUpperCase())==="CMEMS"?"ECMWF":o,o=(o==null?void 0:o.toUpperCase())==="METEO2"?"best_match":o;const{weatherModels:k,marineModels:g}=await it.Meteo2Assist.autoPickMeteoModel(o),b=a.utc().format(),f=await It.spotForecast(t.lat,t.lng,b,!1,!1,!0,{...r,pastDays:1,forecastDays:2,weatherModels:k,marineModels:g}),[c]=it.Meteo2Assist.pickHourly(f,a);l=it.Meteo2Assist.toLegacy(c)}catch(k){C.warn("[%s] meteo2 spot(%j) forecast failed: %s",r.requestId,{...t,eta:a.utc().format(),source:o},k)}let h=O.currentFactor(e.bearing,l==null?void 0:l.current,i,r),d=O.weatherFactor(e,l,h,r);const I=e.speed*1.943844;I+h+d<=0&&(C.warn("[%s] v0(%d) is less then factor(%d) = wxFactor(%d) + cFactor(%d), scale factor with 0.6",r.requestId,I,d+h,d,h),h=Math.round(h*.6*1e3)/1e3,d=Math.round(d*.6*1e3)/1e3);const v=d<=(r.minV0Factor||-1)?Math.max(r.maxV0Factor||-3,-1*d*(d/1.2)):0;C==null||C.info("[%s] calculate speed lose with v0Factor(%d), cFactor(%d) and wxFactor(%d)",r.requestId,v,h,d),d+=v;let T=Math.round((I+h+d)*100)/100;T=T<=0?1:T,u={meteo:{...l},wxFactor:d,v0Factor:v,cFactor:h,speed:t.velocity&&s?t.velocity:T,eta:a.utc().format(),etd:a.utc().format()}}else u={wxFactor:0,v0Factor:0,cFactor:0,speed:t.velocity&&s?t.velocity:Math.round(e.speed*1.943844*100)/100,eta:a.utc().format(),etd:a.utc().format()};return delete t.meteo,delete t.wxFactor,delete t.cFactor,delete t.speed,delete t.etd,{...u,...t}}static async speedLoseInHoursStep(e,t,a,o,i,n,s="",r=!0,u=!1,l={}){t.utc();const h=t.clone().add(14,"days"),d=[],I=[],v=[];let T=0,k=0,g,b;for(let f=0;f<n.length-1;f++){let c=n[f];c.distanceFromStart=Math.round((i+k)*1e3)/1e3;const m=n[f+1];if(e.bearing=E.LaneHelper.calculateBearing(c,m,!m.gcToPrevious),c.bearing=e.bearing,c.suspend&&u){c.eta=c.eta||t.utc().format(),c.elapsed=c.elapsed??0;const p=c.suspend-c.elapsed;if(o-T>p)o=o-T-p,t.add(p,"hour"),c.elapsed=c.suspend;else{const L=o-T;c.elapsed+=L,t.add(L,"hour"),o=0}if(C==null||C.info(`[%s] suspend ${c.elapsed} hours at %j, and remain ${o} hours need to go...`,l.requestId,c),o===0)return c.distanceFromPrevious=k,{etd:t,from:b||c,to:c,next:n.filter(L=>L),wps:d,days:I,all:v}}else c.suspend=0;r=t.isAfter(h)?!1:r,c=await O.speedLoseAt(e,c,t,s,0,r,u,l),v.push(c),b=b||c,c.important&&d.push(c),t.isSameOrAfter(a)&&(I.push(c),a.add(24,"hour"));const y=E.LaneHelper.calculateDistance(c,m,!m.gcToPrevious);let F=Math.round(y/b.speed*1e5)/1e5;if(T+F<o){if(T+=F,t.add(F,"hour"),delete n[f],C==null||C.debug(`[%s] go to %j from %j with ${y}nm, and cost ${F} hours`,l.requestId,{lat:m.lat,lng:m.lng},{lat:b.lat,lng:b.lng,etd:b.etd}),k+=y,n.filter(p=>p).length<=1){g=m,g.eta=t.utc().format(),g.distanceFromPrevious=y,g.distanceFromStart=Math.round((i+k)*1e4)/1e4,d.push(g),v.push(g),delete n[f+1];break}}else{F=o-T,t.add(F,"hour");const p=E.LngLatHelper.roundPrecision(b.speed*F,5);g=E.LaneHelper.calculateCoordinate(c,e.bearing,p,"nauticalmiles",!m.gcToPrevious),g.eta=t.utc().format(),n[f]=g,C==null||C.debug(`[%s] go to %j from %j with ${p}nm, and cost ${F} hours`,l.requestId,{lat:g.lat,lng:g.lng},{lat:c.lat,lng:c.lng,etd:c.etd}),k+=p,g.distanceFromPrevious=Math.round(k*1e4)/1e4,g.distanceFromStart=Math.round((i+k)*1e4)/1e4;break}}return{etd:t,from:b,to:g,next:n.filter(f=>f),wps:d,days:I,all:v}}static currentFactor(e,t,a=0,o={}){const i=E.LaneHelper.includedAngle(e,(t==null?void 0:t.degree)||0)/180*Math.PI;let n;return Math.abs(i)===Math.PI/2&&(n=0),n=((t==null?void 0:t.kts)||0)*Math.cos(i),a&2?n=Math.ceil(n*100)/100:a&1?n=Math.floor(n*100)/100:n=Math.round(n*100)/100,C==null||C.info("[%s] calculate current factor with %j",o.requestId,{beta:i,current:t,factor:n,role:a}),Math.abs(n)>5?0:n}static weatherFactor(e,t,a=0,o={}){var v,T,k,g,b,f,c;C==null||C.info("[%s] calculate weather factor via: %j",o.requestId,{...e,...t});const i=O.blockCoefficient(e.displacement,e.lbp,e.breadthMoulded,e.draught),n=E.LngLatHelper.roundPrecision(a*1852/3600,6),s=O.froudeNumber(e.speed-n,e.lbp),r=O.amendFactor(i,s,e.loadCondition);let u=E.LaneHelper.includedAngle(e.bearing,(v=t==null?void 0:t.wind)==null?void 0:v.degree);const l=O.directionFactor(u,(T=t==null?void 0:t.wind)==null?void 0:T.scale),h=O.vesselTagFactor(e.displacement,e.loadCondition,e.tag,(k=t==null?void 0:t.wind)==null?void 0:k.kts);let d=l*r*h/100*(e.speed-n);d=Math.round(d*1.943844*1e4)/1e4*-1,e.tag==="tugs"&&Math.abs(d)>1&&(d=d/(Math.abs(Math.round(d))+1)),C==null||C.info("[%s] calculate wind wx factor: %d",o.requestId,d),u=E.LaneHelper.includedAngle(e.bearing,(b=(g=t==null?void 0:t.wave)==null?void 0:g.sig)==null?void 0:b.degree);const I=O.waveHeightFactor(((c=(f=t==null?void 0:t.wave)==null?void 0:f.sig)==null?void 0:c.height)??1,u,e.draught);return C==null||C.info("[%s] calculate wave wx factor: %d",I),d=Math.abs(d)>Math.abs(I)?d:.7*d+.9*I,C==null||C.info("[%s] calculate finial weather factor: %d (0.7 * wf) + (0.9 * hf)",o.requestId,d),Math.round((d||0)*100)/100}static async reduceDays(e,t=12*60*60){return e=e==null?void 0:e.reduce((a,o)=>(o.positionTime||(o.positionTime=w.utc(o.etd||o.eta).unix()),a.some(i=>Math.floor(i.positionTime/t)===Math.floor(o.positionTime/t))||a.push(o),a),[]),e}static async reduceWPS(e,t=60){return e=e==null?void 0:e.reduce((a,o)=>(a.some(i=>Math.floor(w(i.etd).unix()/t)===Math.floor(w(o.etd).unix()/t))||a.push(o),a),[]),e}static async analyseInstant(e,t,a,o,i,n="",s=0,r=!0,u=!1,l={}){var X,Q,Z,$,tt,et;const h=w().valueOf();e.lng=E.LngLatHelper.convertToStdLng(e.lng);const{route:d,waypoints:I}=i.points,v=E.LaneHelper.calculateSubRoute(e,d);if(((X=v[0])==null?void 0:X.length)<=1)return;const{v0:T,label:k}=e.sog?{v0:e.sog,label:e.label||"Other"}:{v0:o.speed,label:"CP"},g=O.assembleProperties(a,o.loadCondition,T,0),b=I.length?E.LaneHelper.calculateSubWaypoints(e,I):[];b.forEach(q=>q.important=!0);const f={from:{...e},route:v,waypoints:b,v0:T,label:k},c={hours:[],days:[],wps:[],all:[]};s||(E.LaneHelper.calculateRouteDistance(v)/o.speed<=72?s=3:s=6);let m=E.LaneHelper.simplifyRouteToCoordinates(v,b,0),y=0,F=0,p=0,L=0;t=w(t).utc();const H=t.clone();for(;m.length>0;){const q=s-t.hour()%s,J=Math.ceil(t.clone().add(q,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,j=await O.speedLoseInHoursStep(g,t,H,J,y,m,n,r,u,l);if(c.all.push(...j.all),(Q=j.from)!=null&&Q.speed&&(c.hours.push(j.from),c.wps.push(...j.wps),c.days.push(...j.days)),m=j==null?void 0:j.next,!m.length){const V=await O.speedLoseAt(g,j.to,w(j.to.eta),n,0,r,u,l);V.bearing=g.bearing,c.hours.push(V),c.all.push(V)}y+=Math.round((((Z=j==null?void 0:j.to)==null?void 0:Z.distanceFromPrevious)??0)*1e4)/1e4}const N=c.hours;for(let q=0;q<N.length-1;q++){const J=w(N[q+1].eta).diff(N[q].etd,"hour",!0)||1;F+=(N[q].wxFactor||0)*J,p+=(N[q].cFactor||0)*J,L+=J}const W=N.reduce((q,J)=>q+(J.suspend||0),0);($=c.wps)==null||$.forEach((q,J)=>{q.positionTime=w.utc(q.etd||q.eta).unix();const j=c.wps[J-1];if(j){const V=q.distanceFromStart-j.distanceFromStart,Y=w(q.eta||q.etd).diff(w(j.etd||j.eta),"h",!0);q.avgSpd=Math.round(V/Y*100)/100;const ot=E.LaneHelper.calculateBearing(j,q);q.avgBearing=ot,j.bearing=ot}}),c.wps=await O.reduceWPS(c.wps),c.days=await O.reduceDays(c.days),c.all=(tt=c.all)==null?void 0:tt.reduce((q,J)=>(J.positionTime=w.utc(J.etd||J.eta).unix(),q.some(j=>Math.round(j.positionTime/60)===Math.round(J.positionTime/60))||q.push(J),q),[]),f.sample=c;const B=c.hours.at(0),S=c.hours.at(-1);f.distance=Math.round(S.distanceFromStart*1e3)/1e3,f.etd=w(B.eta).utc().format(),f.eta=w(S.eta).utc().format(),f.wxFactor=Math.round(F/L*1e3)/1e3,f.cFactor=Math.round(p/L*1e3)/1e3,f.avgSpeed=Math.round(S.distanceFromStart/L*1e3)/1e3,f.totalHrs=Math.round(L*1e3)/1e3,f.suspend=Math.round(W*1e3)/1e3;const R=E.LngLatHelper.roundPrecision(o.dgo/24*W,3),{distanceInECA:D,hoursInECA:z,totalDgoConsInECA:rt,eca:st}=await this.calculateECA(f,o,l),at=E.LngLatHelper.roundPrecision(o.fo/24*(L-z),3),ct=E.LngLatHelper.roundPrecision(o.dgo/24*L+R,3);f.extend={eca:st,distanceInECA:D,hoursInECA:z,totalDgoConsInECA:rt,totalDgoConsInSuspend:R},f.totalFoCons=at<0?0:at,f.totalDgoCons=ct;const nt=w().valueOf()-h,ut=((et=c==null?void 0:c.hours)==null?void 0:et.length)||1;return C==null||C.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",l==null?void 0:l.requestId,nt,ut,Math.round(nt/ut*1e3)/1e3),f}static async analyseInstantWithThreshed(e,t,a,o,i,n,s,r="",u=3,l=!0,h=!1,d={}){var Z,$,tt,et,q,J;const I=w().valueOf();e.lng=E.LngLatHelper.convertToStdLng(e.lng);const{v0:v,label:T}=e.sog?{v0:e.sog,label:e.label||"Other"}:{v0:i.speed,label:"CP"},k=O.assembleProperties(o,i.loadCondition,v,0),g=E.LaneHelper.calculateSubRoute(e,n);if(((Z=g[0])==null?void 0:Z.length)<=1)return;const b=s.length?E.LaneHelper.calculateSubWaypoints(e,s):[];b.forEach(j=>j.important=!0);let f=E.LaneHelper.simplifyRouteToCoordinates(g,b,0),c=0,m=0,y=0,F=0;const p={hours:[],wps:[],days:[],all:[]};t=w(t).utc();const L=t.clone();for(;f.length>0;){const j=u-t.hour()%u;let V=Math.ceil(t.clone().add(j,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;V=t.clone().add(V,"h").isSameOrAfter(a)?a.diff(t,"h",!0)*1e4/1e4:V;const Y=await O.speedLoseInHoursStep(k,t,L,V,c,f,r,l,h,d);if(p.all.push(...Y.all),($=Y.from)!=null&&$.speed&&(p.hours.push(Y.from),Y!=null&&Y.wps&&p.wps.push(...Y.wps),p.days.push(...Y.days)),f=Y==null?void 0:Y.next,f.length||p.hours.push(Y==null?void 0:Y.to),c+=Math.round((((tt=Y==null?void 0:Y.to)==null?void 0:tt.distanceFromPrevious)??0)*1e4)/1e4,!V)break}p.wps=await O.reduceWPS(p.wps),p.days=await O.reduceDays(p.days),p.all=(et=p.all)==null?void 0:et.reduce((j,V)=>(V.positionTime=w.utc(V.etd||V.eta).unix(),j.some(Y=>Math.round(w(Y.etd).unix()/60)===Math.round(w(V.etd).unix()/60))||j.push(V),j),[]),(q=p.wps)==null||q.forEach((j,V)=>{const Y=p.wps[V-1];if(Y){const ot=j.distanceFromStart-Y.distanceFromStart,kt=w(j.eta||j.etd).diff(w(Y.etd||Y.eta),"h",!0);Y.bearing=E.LaneHelper.calculateBearing(Y,j),j.avgSpd=Math.round(ot/kt*100)/100}});const H=p.hours;for(let j=0;j<H.length-1;j++){const V=w(H[j+1].eta).diff(H[j].etd,"hour",!0);m+=H[j].wxFactor*V,y+=H[j].cFactor*V,F+=V}const N=H.reduce((j,V)=>j+(V.suspend||0),0),W=p.hours.at(0),B=p.hours.at(-1),S=await E.LaneHelper.calculateRangeRoute(W,B,g),R=await E.LaneHelper.calculateRangeWaypoints(W,B,g,b),D={sample:p,distance:Math.round(((B==null?void 0:B.distanceFromStart)||0)*1e4)/1e4,etd:w(W.eta).utc().format(),eta:w(B==null?void 0:B.eta).utc().format(),wxFactor:Math.round(m/F*1e3)/1e3,cFactor:Math.round(y/F*1e3)/1e3,avgSpeed:Math.round(((B==null?void 0:B.distanceFromStart)||0)/F*1e3)/1e3,totalHrs:Math.round(F*1e3)/1e3,suspend:Math.round(N*1e3)/1e3,from:W,to:B,route:S,waypoints:R,v0:v,label:T},z=E.LngLatHelper.roundPrecision(i.dgo/24*N,3),{distanceInECA:rt,hoursInECA:st,totalDgoConsInECA:at,eca:ct}=await this.calculateECA(D,i,d),dt=E.LngLatHelper.roundPrecision(i.fo/24*(F-st),3),nt=E.LngLatHelper.roundPrecision(i.dgo/24*F+z,3);D.extend={eca:ct,distanceInECA:rt,hoursInECA:st,totalDgoConsInECA:at,totalDgoConsInSuspend:z},D.totalDgoCons=nt,D.totalFoCons=dt<0?0:dt;const X=w().valueOf()-I,Q=((J=p==null?void 0:p.hours)==null?void 0:J.length)||1;return C==null||C.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",d==null?void 0:d.requestId,X,Q,Math.round(X/Q*1e3)/1e3),D}static async analyseCost(e,t,a,o,i={}){var g,b;const n=w().valueOf(),s=[];e.speedStep=e.speedStep||3,e.alterStep=e.alterStep??1;const r=E.LaneHelper.calculateRouteDistance(o.route);let u=0;a.forEach(f=>{const c=Math.ceil(r/f.speed/24);u=u<c?c:u}),u=u*1.3;const l=w.utc(e.etd).add(u??14,"day");let h=1;for(const f of a){const c=JSON.parse(JSON.stringify(o.route)),m=JSON.parse(JSON.stringify(o.waypoints)),y=await O.analyseInstantWithThreshed({lat:e.lat,lng:e.lng},e.etd,l,t,f,c,m,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,i);y&&(await O.calculateCost(y,f,e,i),s.push(y),C==null||C.info("[%s][L%d-%d] analyse from %s to %s cost: %j",i.requestId,1,h,e.etd,l.format(),{cost:y.cost.total,hire:y.cost.hire,bunker:y.cost.bunker,distance:y.distance,hours:y.totalHrs,cp:`${f.speed}/${f.fo}/${f.dgo}`})),h++}s.sort((f,c)=>f.cost.total-c.cost.total);const d=s.at(0),I=s.at(1),v=[];if(v.push({combined:!1,speeds:[d],cost:(g=d.cost)==null?void 0:g.total}),I){const f=d.cost.cp,c=I.cost.cp,m=w(d.eta),y=w(d.etd),F=m.diff(y,"days",!0);let p=Math.ceil(F/2);p=p>7?7:p<e.alterStep?e.alterStep:p;let L=2,H={combined:!1,speeds:[I],cost:(b=I.cost)==null?void 0:b.total},N;for(;p>=e.alterStep;){const W=await O.combinedAnalyse(e,t,l,[f,c],o,p,{...i,level:L});if(H.cost>W.cost?N?(N==null?void 0:N.cost)>W.cost&&(N=W):(N=H,H=W):(!N||(N==null?void 0:N.cost)>W.cost)&&(N=W),p<=e.alterStep)break;p=Math.ceil(p/2),L+=1}v.push(H),N&&v.push(N)}const k=w().valueOf()-n;return C==null||C.info("[%s] analyse elapsed: %d ms",i==null?void 0:i.requestId,k),v.sort((f,c)=>f.cost-c.cost)}static async combinedAnalyse(e,t,a,o,i,n,s={}){s.counter=1,C==null||C.info("[%s][L%d] analyse with alternate cp in every %d days",s.requestId,s.level,n);const r=await O.alternateAnalyse(e,t,a,o,0,i,n,s),u=r.reduce((c,m)=>c+m.cost.total,0),l=r.reduce((c,m)=>c+m.cost.hire,0),h=r.reduce((c,m)=>c+m.cost.bunker,0),d=r.reduce((c,m)=>c+m.distance,0),I=r.reduce((c,m)=>c+m.totalHrs,0);C==null||C.info("[%s][L%d] cost with cpa/cpb turn: %j",s.requestId,s.level,{cost:u,hire:l,bunker:h,distance:d,hours:I});const v=await O.alternateAnalyse(e,t,a,o,1,i,n,s),T=v.reduce((c,m)=>c+m.cost.total,0),k=v.reduce((c,m)=>c+m.cost.hire,0),g=v.reduce((c,m)=>c+m.cost.bunker,0),b=v.reduce((c,m)=>c+m.distance,0),f=v.reduce((c,m)=>c+m.totalHrs,0);return C==null||C.info("[%s][L%d] cost with cpb/cpa turn: %j",s.requestId,s.level,{cost:T,hire:k,bunker:g,distance:b,hours:f}),u<T?{combined:!0,cost:Math.round(u*1e3)/1e3,speeds:r,step:n}:{combined:!0,cost:Math.round(T*1e3)/1e3,speeds:v,step:n}}static async alternateAnalyse(e,t,a,o,i,n,s,r={}){var d,I;let u=w.utc(e.etd);const l={lat:e.lat,lng:e.lng},h=[];for(;u.isBefore(a);){const v=u.clone().utc().add(s,"day"),T=JSON.parse(JSON.stringify(n.route)),k=JSON.parse(JSON.stringify(n.waypoints)),g=o[i],b=await O.analyseInstantWithThreshed(l,u.utc().format(),v,t,g,T,k,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,r);b&&(await O.calculateCost(b,g,e,r),C==null||C.info("[%s][L%d-%d] analyse from %s to %s cost: %j",r.requestId,r.level,r.counter,u.utc().format(),v.utc().format(),{cost:b.cost.total,hire:b.cost.hire,bunker:b.cost.bunker,distance:b.distance,hours:b.totalHrs,cp:`${g.speed}/${g.fo}/${g.dgo}`})),r.counter=r.counter+1;const f=(I=(d=b==null?void 0:b.sample)==null?void 0:d.hours)==null?void 0:I.at(-1);if(f)l.lat=f.lat,l.lng=f.lng,u=w(f.eta),h.push(b),i=i?0:1;else break}return h}static async calculateCost(e,t,a,o={}){var i;if(e){const n=(a.addComm||0)>=1?(a.addComm||0)/100:a.addComm||0,s=Math.round((a.dailyHire||0)*(e.suspend||0)/24*1e3)/1e3,r=Math.round(e.totalHrs/24*(a.dailyHire||0)*(1-n)*1e3)/1e3+s,u=Math.round(e.totalFoCons*(a.priceFO||0)*1e3)/1e3,l=Math.round((e.totalDgoCons+(((i=e.extend)==null?void 0:i.totalDgoConsInECA)||0))*(a.priceDGO||0)*1e3)/1e3;e.cost={total:Math.round((r+u+l)*1e3)/1e3,hire:Math.round(r*1e3)/1e3,suspendHire:s,bunker:Math.round((u+l)*1e3)/1e3,cp:t}}return e}static async calculateECA(e,t,a={}){var r,u,l,h;const o=await E.LaneHelper.intersectInECA((e==null?void 0:e.route)||[]);let i=0,n=0,s=0;(u=(r=e==null?void 0:e.sample)==null?void 0:r.wps)==null||u.forEach(d=>{d.positionTime=w.utc(d.etd||d.eta).unix()});for(const d of o){i+=d.distance;const I=await E.LaneHelper.deadReckoningTime((l=d.waypoints)==null?void 0:l.at(0),e.sample.all||e.sample.wps),v=await E.LaneHelper.deadReckoningTime((h=d.waypoints)==null?void 0:h.at(-1),e.sample.all||e.sample.wps);d.in=I,d.out=v,d.totalHrs=E.LngLatHelper.roundPrecision((v.positionTime-I.positionTime)/3600,3),d.totalDgoCons=E.LngLatHelper.roundPrecision(t.fo/24*d.totalHrs,3),n+=d.totalHrs,s+=d.totalDgoCons}return i=E.LngLatHelper.roundPrecision(i,3),n=E.LngLatHelper.roundPrecision(n,3),s=E.LngLatHelper.roundPrecision(s,3),{distanceInECA:i,hoursInECA:n,totalDgoConsInECA:s,eca:o}}static async mergeSpeeds(e,t={}){var f,c;const a={hours:[],wps:[],days:[],all:[]},o=e.reduce((m,y)=>m+y.distance,0),i=e.reduce((m,y)=>{var F;return m+(((F=y.extend)==null?void 0:F.distanceInECA)||0)},0),n=e.reduce((m,y)=>m+y.totalHrs,0),s=e.reduce((m,y)=>{var F;return m+(((F=y.extend)==null?void 0:F.hoursInECA)||0)},0),r=e.reduce((m,y)=>{var F;return m+(((F=y.extend)==null?void 0:F.totalDgoConsInECA)||0)},0),u=e.reduce((m,y)=>m+y.wxFactor*y.totalHrs/n,0),l=e.reduce((m,y)=>m+y.cFactor*y.totalHrs/n,0),h=e.reduce((m,y)=>m+y.totalFoCons,0),d=e.reduce((m,y)=>m+y.totalDgoCons,0),I=e.reduce((m,y)=>m+y.cost.total,0),v=e.reduce((m,y)=>m+y.cost.hire,0),T=e.reduce((m,y)=>m+y.cost.bunker,0),k=[],g=[];let b;for(const m of e){g.push(...((f=m.extend)==null?void 0:f.eca)||[]);const y=m.sample.hours,F=m.sample.all,p=m.sample.wps,L=m.sample.days,H=y.at(0);b&&(H.distanceFromPrevious=b.distanceFromPrevious,H.distanceFromStart=b.distanceFromStart,y.forEach((S,R)=>{R&&(S.distanceFromStart=S.distanceFromStart+b.distanceFromStart)}),F.at(0).distanceFromPrevious=b.distanceFromPrevious,F.at(0).distanceFromStart=b.distanceFromStart,F.forEach((S,R)=>{R&&(S.distanceFromStart=S.distanceFromStart+b.distanceFromStart)}),p.at(0).distanceFromPrevious=b.distanceFromPrevious,p.at(0).distanceFromStart=b.distanceFromStart,p.forEach((S,R)=>{R&&(S.distanceFromStart=S.distanceFromStart+b.distanceFromStart)}),L.at(0).distanceFromPrevious=b.distanceFromPrevious,L.at(0).distanceFromStart=b.distanceFromStart,L.forEach((S,R)=>{R&&(S.distanceFromStart=S.distanceFromStart+b.distanceFromStart)})),H.cp=m.cost.cp;const N=[m.etd,m.eta],W=k.findIndex(S=>S.id===H.cp.id);W===-1?(H.cp.segment=[N],k.push(H.cp)):k[W].segment.push(N),y.forEach(S=>{var D;((D=a.hours)==null?void 0:D.findIndex(z=>z.eta===S.eta))===-1&&a.hours.push(S)}),F.forEach(S=>{var D;((D=a.all)==null?void 0:D.findIndex(z=>z.eta===S.eta))===-1&&a.all.push(S)}),p.forEach(S=>{var D;((D=a.wps)==null?void 0:D.findIndex(z=>z.eta===S.eta))===-1&&a.wps.push(S)}),L.forEach(S=>{var D;((D=a==null?void 0:a.days)==null?void 0:D.findIndex(z=>z.eta===S.eta))===-1&&a.days.push(S)});const B=(c=a.wps)==null?void 0:c.findIndex(S=>S.eta===H.eta);B===-1?a.wps.push(H):a.wps[B]=H,b=y.at(-1)}return a.wps.sort((m,y)=>w(m.etd).unix()-w(y.etd).unix()),a.wps.forEach((m,y)=>{const F=a.wps[y-1];if(F){const p=m.distanceFromStart-(F.distanceFromStart||0),L=w(m.eta||m.etd).diff(w(F.etd||F.eta),"hour",!0),H=Math.round(p/L*100)/100;m.avgSpd=H;const N=E.LaneHelper.calculateBearing(F,m);F.bearing=N}}),{sample:a,etd:e.at(0).etd,eta:e.at(-1).eta,from:e.at(0).from,to:e.at(-1).to,v0:e.at(0).v0,label:"Combined",distance:Math.round(o*1e3)/1e3,totalHrs:Math.round(n*1e3)/1e3,avgSpeed:Math.round(o/n*1e3)/1e3,wxFactor:Math.round(u*1e3)/1e3,cFactor:Math.round(l*1e3)/1e3,totalFoCons:Math.round(h*1e3)/1e3,totalDgoCons:Math.round(d*1e3)/1e3,cost:{total:Math.round(I*1e3)/1e3,hire:Math.round(v*1e3)/1e3,bunker:Math.round(T*1e3)/1e3},extend:{cps:k,eca:g,distanceInECA:Math.round(i*1e3)/1e3,hoursInECA:Math.round(s*1e3)/1e3,totalDgoConsInECA:Math.round(r*1e3)/1e3,speeds:e}}}}P.AISImpl=G,P.AlertHelper=ht,P.AlertLevel=lt,P.HifleetImpl=vt,P.LoadCondition=mt,P.MyShipImpl=gt,P.MyVesselImpl=Mt,P.ShipxyImpl=bt,P.SpeedHelper=O,P.SpeedLabel=yt,P.VesselTag=ft,P.alertHelper=wt,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})});
1
+ (function(P,x){typeof exports=="object"&&typeof module<"u"?x(exports,require("got"),require("@log4js-node/log4js-api"),require("moment"),require("@idm-plugin/geo2"),require("@idm-plugin/meteo2"),require("@idm-plugin/meteo")):typeof define=="function"&&define.amd?define(["exports","got","@log4js-node/log4js-api","moment","@idm-plugin/geo2","@idm-plugin/meteo2","@idm-plugin/meteo"],x):(P=typeof globalThis<"u"?globalThis:P||self,x(P["idm-plugin-vessel"]={},P.got,P["@log4js-node/log4js-api"],P.moment,P["@idm-plugin/geo2"],P["@idm-plugin/meteo2"],P["@idm-plugin/meteo"]))})(this,function(P,x,K,w,E,pt,it){"use strict";var St=Object.defineProperty;var Ct=(P,x,K)=>x in P?St(P,x,{enumerable:!0,configurable:!0,writable:!0,value:K}):P[x]=K;var U=(P,x,K)=>(Ct(P,typeof x!="symbol"?x+"":x,K),K);let M;try{M=K.getLogger("vessel")}catch{}finally{}class G{parseStatus(e){let t,a;switch(e){case 0:t="在航(主机推动)",a="Underway Using Engine";break;case 1:t="锚泊",a="Anchored";break;case 2:t="失控",a="Not under command";break;case 3:t="操纵受限",a="Limited airworthiness";break;case 4:t="吃水受限",a="Limited by ship's draft";break;case 5:t="靠泊",a="Mooring";break;case 6:t="搁浅",a="Stranded";break;case 7:t="捕捞作业",a="Engaged in fishing";break;case 8:t="靠帆船提供动力",a="Sailing";break;default:t="未定义",a="Undefined"}return{labelCn:t,labelEn:a}}}class Mt extends G{constructor(t,a){super();U(this,"clientId");U(this,"clientSecret");U(this,"token");this.clientId=t,this.clientSecret=a}async authToken(t={}){const a="https://svc.data.myvessel.cn/ada/oauth/token",o={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},i=await x.post(a,o).json();M==null||M.info("[%s] fetch access token from: %s - %j",t.requestId,a,i),i.error||(this.token={accessToken:i.access_token,tokenType:i.token_type,expiresIn:i.expires_in,scope:i.scope,jti:i.jti,issuedAt:w().utc().format()})}async checkToken(t={}){var a;return(!this.token||w().diff(w(this.token.issuedAt),"seconds")>(((a=this.token)==null?void 0:a.expiresIn)||0)-300)&&await this.authToken(t),this.token}async suggest(t,a={}){var s,r;await this.checkToken(a);const o="https://market.myvessel.cn/sdc/v1/mkt/vessels/fuzzy",i={headers:{Authorization:`${(s=this.token)==null?void 0:s.tokenType} ${(r=this.token)==null?void 0:r.accessToken}`},json:{kw:t,recordNum:a.ps||10}};M==null||M.info("[%s] fetch suggest vessels from: %s - %j",a.requestId,o,i);const n=await x.post(o,i).json();return n.status!==200?(M==null||M.warn("[%s] fetch suggest vessels failed: %j",a.requestId,{message:n.message,status:n.status,code:n.code}),[]):(n.data||[]).map(l=>({mmsi:l.mmsi,name:l.nameEn,nameCn:l.nameCn,imo:Number.isNaN(l.imo)?null:Number(l.imo),callSign:l.callsign,type:l.vesselTypeNameEn,flagName:l.flagCtry,vendor:"myvessel",raw:l}))}async search(t,a={}){var u,l;await this.checkToken(a);const o=/^\d{7}$/.test(t.toString()),i=o?"https://market.myvessel.cn/sdc/v1/mkt/vessels/detail/imo":"https://market.myvessel.cn/sdc/v1/mkt/vessels/detail/mmsi",n=o?{imo:t}:{mmsi:t},s={headers:{Authorization:`${(u=this.token)==null?void 0:u.tokenType} ${(l=this.token)==null?void 0:l.accessToken}`},searchParams:n};M==null||M.info("[%s] fetch vessel from: %s - %j",a.requestId,i,s);const r=await x.get(i,s).json();if(r.status!==200)return M==null||M.warn("[%s] fetch suggest vessels failed: %j",a.requestId,{message:r.message,status:r.status,code:r.code}),{};{const h=r.data;if(h)return{mmsi:h.mmsi,imo:Number.isNaN(h.imo)?null:Number(h.imo),callSign:h.callsign,name:h.nameEn,nameCn:h.nameCn,type:h.vesselTypeNameEn,flagName:h.flagCtry,clasz:h.classSociety,dateOfBuild:h.buildYearMonth,deadweight:h.dwt,grossTonnage:h.grt,netTonnage:h.net,teu:h.teu,length:h.length,breadth:h.width,height:h.height,draught:h.draught,speed:h.speed,passengerCapacity:h.passengercapacity,vendor:"myvessel",raw:h}}return{}}async archives(t,a={}){var s,r;await this.checkToken(a);const o="https://svc.data.myvessel.cn/sdc/v1/ship/info/batch",i={headers:{Authorization:`${(s=this.token)==null?void 0:s.tokenType} ${(r=this.token)==null?void 0:r.accessToken}`},json:{mmsiList:typeof t=="number"?[t]:t}};M==null||M.info("[%s] fetch vessel archive from: %s - %j",a.requestId,o,i);const n=await x.post(o,i).json();return n.status!==200?(M==null||M.warn("[%s] fetch vessel archive failed: %j",a.requestId,{message:n.message,status:n.status,code:n.code}),{}):n.data}async realTimePosition(t,a={}){var r,u;await this.checkToken(a);const o="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",i={headers:{Authorization:`${(r=this.token)==null?void 0:r.tokenType} ${(u=this.token)==null?void 0:u.accessToken}`},searchParams:{mmsi:t}};M==null||M.info("[%s] fetch realtime position from: %s - %j",a.requestId,o,i);const n=await x.get(o,i).json();if(n.code)return M==null||M.warn("[%s] fetch realtime position failed: %j",a.requestId,{message:n.message,status:n.status,code:n.code}),n;const s=n.data;for(const l in s)!isNaN(s[l])&&Number(s[l])!==1/0&&(s[l]=Number(s[l]));if(s){const l=w(`${s.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:s.mmsi,name:s.vesselName||s.aisVesselName,imo:s.imo,callSign:s.callsign||s.aisCallSign,lat:s.lat,lng:s.lon,length:s.length,width:s.width,draught:s.currDraught,sog:s.sog,cog:s.cog,hdg:s.hdg,rot:s.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta)?w.utc(s.eta).format():void 0,destination:s.dest,positionTime:l.unix(),status:s.status,labelCn:s.statusNameCn,labelEn:s.statusNameEn,vesselType:s.vesselTypeNameEn,flag:s.flagCtryNameEn,clasz:s.classSociety,build:s.buildYear,dwt:s.dwt,grt:s.grt,net:s.net,method:"position",vendor:"myVessel",utc:l.utc().format()}}else return{}}async calculateRoute(t,a,o,i,n,s={}){var I,v,T;const r=w();await this.checkToken(s);const u="https://market.myvessel.cn/sdc/v1/mkt/routes/plan",l={maxDraught:s.draught||10,useAIModel:s.useAIModel??!0,withECA:s.withECA||!1,withSpecialRegion:s.withSpecial||!1};t.code&&(l.startPortCode=t.code),t.lng!==void 0&&t.lat!==void 0&&(l.startPoint={lon:t.lng,lat:t.lat}),a.code&&(l.endPortCode=a.code),a.lng!==void 0&&a.lat!==void 0&&(l.endPoint={lon:a.lng,lat:a.lat}),o!=null&&o.length&&(l.crossMonthList=o),i!=null&&i.length&&(l.excludeNodes=i),n!=null&&n.length&&(l.excludeSeaAreas=n);const h={headers:{Authorization:`${(I=this.token)==null?void 0:I.tokenType} ${(v=this.token)==null?void 0:v.accessToken}`},json:l};M==null||M.info("[%s] fetch route from: %s - %j",s.requestId,u,h);const d=await x.post(u,h).json();if(d.status!==200)return M==null||M.warn("[%s] fetch route failed: %j",s.requestId,{message:d.message,status:d.status,code:d.code}),{};{const k={status:"Success",nodes:[],seas:[],regions:[],waypoints:[],route:[],distance:0,memo:""},{nodes:g,seas:b,tracks:f,specialRegions:c,ecaLength:m}=d.data;k.nodes=g==null?void 0:g.map(p=>({code:p.nodeCode,nameEn:p.nameEn,nameCn:p.nameCn,center:{lat:Math.round(p.lat*1e6)/1e6,lng:Math.round(p.lon*1e6)/1e6},start:{lat:Math.round(p.startLat*1e6)/1e6,lng:Math.round(p.startLon*1e6)/1e6},end:{lat:Math.round(p.endLat*1e6)/1e6,lng:Math.round(p.endLat*1e6)/1e6},isKey:p.isKeyNode,isHub:p.isHubNode})),k.seas=b==null?void 0:b.map(p=>({code:p.mrgidSea,nameEn:p.nameEn,nameCn:p.nameCn,center:{lat:Math.round(p.centerLat*1e6)/1e6,lng:Math.round(p.centerLon*1e6)/1e6},min:{lat:Math.round(p.minLat*1e6)/1e6,lng:Math.round(p.minLon*1e6)/1e6},max:{lat:Math.round(p.maxLat*1e6)/1e6,lng:Math.round(p.maxLon*1e6)/1e6},level:p.mapLevel})),c==null||c.map(p=>{p.regionLength&&k.regions.push({type:p.regionType,distance:p.regionLength,rows:p.regions.map(L=>({code:L.regionCode,nameCn:L.nameCn,nameEn:L.nameEn,type:L.regionType,distance:L.length}))})}),k.waypoints=f==null?void 0:f.map(p=>({lat:Math.round(p.lat*1e5)/1e5,lng:Math.round(p.lon*1e5)/1e5})),(T=k.waypoints)!=null&&T.length&&(k.waypoints=E.LaneHelper.simplifyCoordinates(k.waypoints),k.route=E.LaneHelper.divideAccordingToLng(k.waypoints),k.distance=E.LaneHelper.calculateRouteDistance(k.route),k.distanceInECA=m);const F=w().diff(r,"second");return k.memo=`time cost: ${F}s`,M.info("[%s] calculate route cost: %d seconds",s.requestId,F),k}}async trajectory(t,a,o,i,n=!0,s={}){await this.checkToken(s);const r=await this.realTimePosition(t,s),u=w(a),l=w(o),h=[];for(;l.diff(u,"day",!0)>30;)await this.trajectoryIn30Day(t,u,u.clone().add(30,"day"),r,i,h,s),u.add(30,"day");return await this.trajectoryIn30Day(t,u,l,r,i,h,s),h}async trajectoryIn30Day(t,a,o,i,n,s,r={}){var v,T,k,g,b;const u="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",l={headers:{Authorization:`${(v=this.token)==null?void 0:v.tokenType} ${(T=this.token)==null?void 0:T.accessToken}`},json:{mmsi:t,startTime:a.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:o.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};M==null||M.info("[%s] fetch trajectory from: %s - %j",r.requestId,u,l);const h=await x.post(u,l).json();if(h.code)return M==null||M.warn("[%s] fetch trajectory failed: %j",r.requestId,u,{message:h.message,status:h.status,code:h.code}),h;let d=-1;const I=w(`${(g=(k=h.data)==null?void 0:k[0])==null?void 0:g.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(b=h.data)==null||b.forEach(f=>{for(const H in f)!isNaN(f[H])&&Number(f[H])!==1/0&&(f[H]=Number(f[H]));const c=w(`${f.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),m=f.status,{labelCn:y,labelEn:F}=this.parseStatus(m),p={mmsi:f.mmsi,imo:i==null?void 0:i.imo,lat:f.lat,lng:f.lon,sog:f.sog,cog:f.cog,hdg:f.hdg,draught:f.draught,status:m,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(f.eta)?w(`${f.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").utc().format():void 0,destination:f.dest,positionTime:c.unix(),labelCn:y,labelEn:F,method:"trajectory",vendor:"myVessel",utc:c.utc().format()},L=Math.floor(c.diff(I,"minute",!0)/(n||1));L!==d&&(d=L,s.push(p))}),s}}class vt extends G{constructor(t){super();U(this,"token");this.token=t}async realTimePosition(t,a={}){const o="https://api.hifleet.com/position/position/get/token",i={searchParams:{mmsi:t,usertoken:this.token}},n=await x.post(o,i).json();M==null||M.info("[%s] fetch realtime position from: %s - %j",a.requestId,o,i);const s=n==null?void 0:n.list;if(!s)return M==null||M.warn("[%s] fetch realtime position failed: %j",a.requestId,o,n),n;for(const I in s)!isNaN(s[I])&&Number(s[I])!==1/0&&(s[I]=Number(s[I]));s.status=s.sp>3?0:1;const r=s.status,{labelCn:u,labelEn:l}=this.parseStatus(r),h=w(`${s.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:s.m,name:s.n,imo:s.imonumber,callSign:s.callsign,lat:Math.round(s.la/60*1e5)/1e5,lng:Math.round(s.lo/60*1e5)/1e5,length:s.l,width:s.w,draught:s.draught,sog:s.sp,cog:s.co,hdg:s.h,rot:isNaN(s.rot)?0:s.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta)?w.utc(s.eta).format():void 0,destination:s.destination,vesselType:s.type,dwt:s.dwt,build:s.buildyear,flag:s.fn,positionTime:h.unix(),utc:h.utc().format(),status:r,labelCn:u,labelEn:l,method:"position",vendor:"hifleet"}}async search(t,a={}){let o="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const i={searchParams:{keyword:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let n=await x.post(o,i).json();M==null||M.info("[%s] fetch vessel props from: %s - %j",a.requestId,o,i),n instanceof Array&&(n=n[0]);for(const r in n)!isNaN(n[r])&&Number(n[r])!==1/0&&(n[r]=Number(n[r]));const s={mmsi:n.m,name:n.n,imo:n.i,callSign:n.c,length:n.l,breadth:n.b,draught:n.dr,type:n.t};return o="https://www.hifleet.com/hifleetapi/sameShipSearch.do",n=await x.post(o,i).json(),M==null||M.info("[%s] search vessel dead weight from: %s - %j",a.requestId,o,i),n instanceof Array&&(n=n[0]),n&&(s.deadweight=Number(n.dwt)),s}async suggest(t,a={}){const o="https://www.hifleet.com/hifleetapi/getShipSuggest.do",i={searchParams:{q:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}},n=await x.post(o,i).json();M==null||M.info("[%s] suggest vessel props from: %s - %j",a.requestId,o,i);const s=[];for(const r of n)s.push({mmsi:!r.mmsi||isNaN(r.mmsi)?null:Number(r.mmsi),name:r.name,callSign:r.callsign,imo:!r.imo||isNaN(r.imo)?null:Number(r.imo),score:r._score});return s.sort((r,u)=>u.score-r.score),s}async trajectory(t,a,o,i,n=!0,s={}){var f,c,m;const r=await this.realTimePosition(t,s);let u=w(a);const l=w(o),h=w();if(n){let y=l.diff(u,"d",!0);y<0?u=l.clone().subtract(40,"d"):y<30?u.subtract(10,"d"):y<60?u.subtract(5,"d"):u=l.clone().subtract(80,"d"),y=h.diff(l,"d",!0),l.add(y>10?240:y*24,"h")}const d={searchParams:{endtime:l.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),starttime:u.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),mmsi:t,usertoken:this.token}},I="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",v=await x.get(I,d).json();M==null||M.info("[%s] fetch trajectory from: %s - %j",s.requestId,I,d);let T;v&&(T=((c=(f=v.ships)==null?void 0:f.offors)==null?void 0:c.ship)||[],T.length||M==null||M.warn("[%s] fetch trajectory failed: %j",s.requestId,v));const k=[];let g=-1;const b=w(`${(m=T==null?void 0:T[0])==null?void 0:m.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const y of T){for(const W in y)!isNaN(y[W])&&Number(y[W])!==1/0&&(y[W]=Number(y[W]));const F=w(`${y.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");y.status=y.sp>4?0:1;const{labelEn:p,labelCn:L}=this.parseStatus(y.status),H={mmsi:y.m,name:y.n,imo:r==null?void 0:r.imo,lat:y.la,lng:y.lo,draught:y.draught,sog:y.sp,cog:y.co,hdg:y.hdg,positionTime:F.unix(),utc:F.utc().format(),status:y.status,labelCn:L,labelEn:p,method:"trajectory",vendor:"hifleet"},N=Math.floor(F.diff(b,"minute",!0)/(i||1));N!==g&&(g=N,k.push(H))}return k}}class bt extends G{constructor(t){super();U(this,"token");this.token=t}async realTimePosition(t,a={}){const o={searchParams:{id:t,k:this.token,enc:1}},i="https://api.shipxy.com/apicall/GetSingleShip",n=await x.get(i,o).json();if(M==null||M.info("[%s] fetch realtime position from: %s - %j",a.requestId,i,o),(n==null?void 0:n.status)!==0)return n;const s=n.data[0];for(const d in s)!isNaN(s[d])&&Number(s[d])!==1/0&&(s[d]=Number(s[d]));const{labelCn:r,labelEn:u}=await this.parseStatus(s.navistat),l=w.unix(s.lasttime);return{mmsi:s.ShipID,name:s.name,imo:s.imo,callSign:s.callsign,lat:Math.round(s.lat/1e6*1e5)/1e5,lng:Math.round(s.lon/1e6*1e5)/1e5,length:Math.round(s.length/10*100)/100,width:Math.round(s.width/10*100)/100,draught:Math.round(s.draught/1e3*100)/100,sog:Math.round(s.sog*3600/1e3/1852*100)/100,cog:Math.round(s.cog/100*100)/100,hdg:Math.round(s.hdg/100*100)/100,rot:Math.round(s.rot/100*100)/100,positionTime:s.lasttime,utc:l.utc().format(),status:s.navistat,labelEn:u,labelCn:r,method:"position",vendor:"shipxy"}}async trajectory(t,a,o,i,n=!0,s={}){var b;const r=await this.realTimePosition(t,s),u=w(a),l=w(o),h="https://api.shipxy.com/apicall/GetShipTrack",d={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:u.unix(),etm:l.unix()}},I=await x.get(h,d).json();if(M==null||M.info("[%s] fetch trajectory from: %s - %j",s.requestId,h,d),(I==null?void 0:I.status)!==0)return I;const v=I==null?void 0:I.points,T=[],k=w.unix((b=v[0])==null?void 0:b.utc);let g=-1;for(const f of v){const c=w.unix(f.utc),m={imo:r==null?void 0:r.imo,mmsi:t,sog:Math.round(f.sog*3600/1e3/1852*100)/100,cog:Math.round(f.cog/100*100)/100,lat:Math.round(f.lat/1e6*1e5)/1e5,lng:Math.round(f.lon/1e6*1e5)/1e5,positionTime:c.unix(),utc:c.utc().format(),method:"trajectory",vendor:"shipxy"},y=Math.floor(c.diff(k,"minute",!0)/(i||1));y!==g&&(g=y,T.push(m))}return T}}class gt extends G{constructor(t){super();U(this,"token");this.token=t}async getShipId(t,a={}){const o={headers:{appKey:this.token},json:{mmsiList:t}},i="https://api3.myships.com/sp/ships/getShipIdByMMSI",n=await x.post(i,o).json();return M==null||M.info("[%s] fetch ship id from: %s - %j",a.requestId,i,o),n.code!=="0"?n:n.data[0].shipId}async getShipInfo(t,a={}){const o={headers:{appKey:this.token},json:{shipId:t}},i="https://api3.myships.com/sp/ships/aissta",n=await x.post(i,o).json();if(M==null||M.info("[%s] fetch ship info from: %s - %j",a.requestId,i,o),n.code!=="0")return n;const s=n.data;let r=s.imo;return t==="407170"&&(r="9198379",M==null||M.warn("[%s] ship(%s) imo error: %s, should be %s",a.requestId,t,s.imo,r)),{mmsi:s.mmsi,name:s.shipnameEn,imo:r,callSign:s.callSign,length:s.length,width:s.breadth,draught:(s.draught||100)/10}}async realTimePosition(t,a={}){const o=await this.getShipId(t,a),i=await this.getShipInfo(o,a),n={headers:{appKey:this.token},json:{shipId:o}},s="https://api3.myships.com/sp/ships/position/latest",r=await x.post(s,n).json();M==null||M.info("[%s] fetch realtime position from: %s - %j",a.requestId,s,n);const u=r.data[0];for(const v in u)!isNaN(u[v])&&Number(u[v])!==1/0&&(u[v]=Number(u[v]));const{labelCn:l,labelEn:h}=await this.parseStatus(u.aisNavStatus),d=w.unix(u.posTime);return{...i,mmsi:t,lat:Math.round(u.lat/1e4/60*1e5)/1e5,lng:Math.round(u.lon/1e4/60*1e5)/1e5,sog:Math.round(u.sog/10*100)/100,cog:Math.round(u.cog/10*100)/100,hdg:Math.round(u.heading*100)/100,rot:Math.round(u.rot*100)/100,positionTime:u.posTime,utc:d.utc().format(),status:u.aisNavStatus,labelEn:h,labelCn:l,method:"position",vendor:"myship"}}async trajectory(t,a,o,i,n=!0,s={}){const r=w(a),u=w(o),l=await this.getShipId(t),h=await this.getShipInfo(l),d=[];for(;u.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(l,r.unix(),r.add(30,"day").unix(),h,t,i,d);return await this.trajectoryIn30Day(l,r.unix(),u.unix(),h,t,i,d),d}async trajectoryIn30Day(t,a,o,i,n,s,r,u={}){var k;const l={headers:{appKey:this.token},json:{shipId:t,startTime:a,endTime:o}},h="https://api3.myships.com/sp/ships/position/history",d=await x.post(h,l).json();if(M==null||M.info("[%s] fetch trajectory from: %s - %j",u.requestId,h,l),d.code!=="0")return M==null||M.warn("[%s] invoke myship trajectory failed: %j",u.requestId,d),d;const I=d.data;for(const g in I)!isNaN(I[g])&&Number(I[g])!==1/0&&(I[g]=Number(I[g]));const v=w.unix((k=I[0])==null?void 0:k.posTime);let T=-1;for(const g of I){const b=w.unix(g.posTime),f={imo:i==null?void 0:i.imo,mmsi:n,lat:Math.round(g.lat/1e4/60*1e5)/1e5,lng:Math.round(g.lon/1e4/60*1e5)/1e5,sog:Math.round(g.sog/10*100)/100,cog:Math.round(g.cog/10*100)/100,hdg:Math.round(g.heading*100)/100,rot:Math.round(g.rot*100)/100,positionTime:b.unix(),utc:b.utc().format(),method:"trajectory",vendor:"myship"},c=Math.floor(b.diff(v,"minute",!0)/(s||1));c!==T&&(T=c,r.push(f))}return r}}let _;try{_=K.getLogger("vessel")}catch{}finally{}var lt=(A=>(A.NOTICE="NOTICE",A.WARN="WARN",A.HEAVY="HEAVY",A.SEVERE="SEVERE",A.ERROR="ERROR",A.FATAL="FATAL",A))(lt||{});class ht{parsePrinciple(e,t={}){var s,r,u;_==null||_.debug("[%s] parse rule: %s",t.requestId,e);const a=new RegExp("(?<=\\[)(.+)(?=])","g"),o=e.match(a)?(s=e.match(a))==null?void 0:s[0]:void 0,i=o==null?void 0:o.split(";");if(!i)return;const n={};for(let l=0;l<(i==null?void 0:i.length);l++){const h=(u=(r=i[l].match(a))==null?void 0:r[0])==null?void 0:u.split("],");if(l===0&&!h)n.scope=i[0];else if(h)for(let d=0,I=h.length;d<I;d++){const v=this.parseRule(h[d]);v&&(n[v.level]?v.key?n[v.level][v==null?void 0:v.key]=v:n[v.level]=v:v.key?n[v.level]={[v==null?void 0:v.key]:v}:n[v.level]=v)}}return n}parseRule(e,t={}){var n;_==null||_.debug("[%s] parse rule: %s",t.requestId,e),e=e.startsWith("[")?e:`[${e}`,e=e.endsWith("]")?e:`${e}]`;const a=new RegExp("(?<=\\[)(.+?)(?=])","g"),o=(n=e==null?void 0:e.match(a))==null?void 0:n[0],i=o==null?void 0:o.split(",");if(i){let s=i[3]==="Number.MAX_VALUE"?100:Number(i[3]);return s=isNaN(s)?1:s,{operator:i[0],number:Number.isNaN(Number(i[1]))?i[1]:Number(i[1]),level:i[2],time:s,key:i[4]}}}checkWeather(e,t,a={}){var v,T,k,g,b,f,c,m,y,F,p,L,H,N,W;let o=0,i=0,n=0,s=0;const r=Math.round(((T=(v=t==null?void 0:t.SEVERE)==null?void 0:v.sigWave)==null?void 0:T.number)*1.6*100)/100,u=(g=(k=t==null?void 0:t.SEVERE)==null?void 0:k.sigWave)==null?void 0:g.number,l=(f=(b=t==null?void 0:t.HEAVY)==null?void 0:b.sigWave)==null?void 0:f.number,h=Math.round((((m=(c=t==null?void 0:t.SEVERE)==null?void 0:c.wind)==null?void 0:m.number)+2)*100)/100,d=(F=(y=t==null?void 0:t.SEVERE)==null?void 0:y.wind)==null?void 0:F.number,I=(L=(p=t==null?void 0:t.HEAVY)==null?void 0:p.wind)==null?void 0:L.number;for(let B=0;B<(e==null?void 0:e.length);B++){const S=e[B],R=(N=(H=S==null?void 0:S.meteo)==null?void 0:H.wave)==null?void 0:N.sig,q=(W=S==null?void 0:S.meteo)==null?void 0:W.wind,z=B?w(S.eta).diff(w(e[B-1].eta),"hour",!0):0;s=z>s?z:s,_==null||_.debug("[%s] check sig.wave: %j",a.requestId,{...R,dgThd4Wv:r,svThd4Wv:u,hvThd4Wv:l}),(R==null?void 0:R.height)>=r?S.isDangerous=!0:(R==null?void 0:R.height)>=u?S.isSevere=!0:(R==null?void 0:R.height)>=l&&(S.isHeavy=!0),_==null||_.debug("[%s] check wind: %j",a.requestId,{...q,dgThd4Wd:h,svThd4Wd:d,hvThd4Wd:I}),(q==null?void 0:q.scale)>=h?(S.isDangerous=!0,delete S.isSevere,delete S.isHeavy):(q==null?void 0:q.scale)>d?(S.isDangerous||(S.isSevere=!0),delete S.isHeavy):(q==null?void 0:q.scale)===I&&!S.isDangerous&&!S.isSevere&&(S.isHeavy=!0),o+=S.isDangerous?z:0,i+=S.isSevere?z:0,n+=S.isHeavy?z:0}return o=Math.round(o*100)/100,i=Math.round(i*100)/100,n=Math.round(n*100)/100,s=Math.round(s),{sample:e,dangerous:o,severe:i,heavy:n,step:s<3?3:s,wind:{dgThd4Wd:h,svThd4Wd:d,hvThd4Wd:I},sig:{dgThd4Wv:r,svThd4Wv:u,hvThd4Wv:l}}}}const wt=new ht;let C;try{C=K.getLogger("vessel")}catch{}finally{}const It=new pt.MeteoHelper2("",!0);var ft=(A=>(A.common="common",A.container="container",A.tugs="tugs",A))(ft||{}),mt=(A=>(A.Ballast="Ballast",A.Laden="Laden",A))(mt||{}),yt=(A=>(A.Cp="CP",A.Perf="Basis",A.Instruct="Other",A))(yt||{});class O{static blockCoefficient(e,t,a,o){let i=Math.round(e/(t*a*o)*100)/100;i=i<.55?.55:i>.85?.85:i;const n=[.55,.6,.65,.7,.75,.8,.85],s=n.map(r=>Math.abs(r-i));return n[s.indexOf(Math.min(...s))]}static froudeNumber(e,t,a=9.8){let o=Math.round(Math.sqrt(e*e/(a*t))*100)/100;return o=o<.05?.05:o>.3?.3:o,o}static amendFactor(e,t,a){const o={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.4,-10.6,-9.5],.8:[2.6,-13.1,-15.1],.85:[3.1,-18.7,28]};let n={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.6,-12.5,-13.5],.8:[3,-16.3,-21.6],.85:[3.4,-20.9,31.8]}[e];return a==="Laden"&&(n=o[e]),n[0]+n[1]*t+n[2]*Math.pow(t,2)}static directionFactor(e,t=0){let a;return e>30&&e<=60?a=(1.7-.03*Math.pow(t-4,2))/2:e>60&&e<=150?a=(.9-.06*Math.pow(t-6,2))/2:e>150&&e<=180?a=(.4-.03*Math.pow(t-8,2))/2:a=1,Math.round(a*1e5)/1e5}static vesselTagFactor(e,t,a,o){let i;return a==="container"?i=.7*o/2+Math.pow(o,3)/(22*Math.pow(e,2/3)):t==="Ballast"?i=.7*o/2+Math.pow(o,3)/(2.7*Math.pow(e,2/3)):i=.5*o/2+Math.pow(o,3)/(2.7*Math.pow(e,2/3)),i}static waveHeightFactor(e,t,a=10){e=e<3?e*.7:e,e=e<0?.2:e,e=e>6?e-.9*(e-6):e,e=e>9?9:e;let o;return t>30&&t<=60?o=-.6:t>60&&t<=90?o=-.5:t>90&&t<=120?o=e<4?.4:-.4:t>120&&t<=150?o=e<4?.5:-.5:t>150&&t<=180?o=e<4?.6:-.6:o=-.7,Math.round(o*(.144*Math.pow(e,2)+.378*e)*1e4)/1e4}static assembleProperties(e,t,a,o){var d;const i=e.lbp??e.length??e.lengthOverall??198.9642,n=e.draught??8,s=e.breadthMoulded??e.breadth??e.breadthExtreme??32.4572,r=e.deadweight??67035.7773,u=((d=e==null?void 0:e.type)==null?void 0:d.toLowerCase())||"common";return{tag:u.indexOf("container")>-1?"container":u.indexOf("tugs")>-1?"tugs":"common",lbp:i,loadCondition:t,draught:n,breadthMoulded:s,displacement:Math.round((r/1.025+n*s*i*.7)*1e4)/1e4,speed:Math.round((a??14.1382)*1852/3600*1e4)/1e4,bearing:o||90}}static async speedLoseAt(e,t,a,o="",i=2,n=!0,s=!1,r={}){let u;if(t.velocity&&s&&(e.speed=E.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),n){let l;try{o=(o==null?void 0:o.toUpperCase())==="CMEMS"?"ECMWF":o,o=(o==null?void 0:o.toUpperCase())==="METEO2"?"best_match":o;const{weatherModels:k,marineModels:g}=await it.Meteo2Assist.autoPickMeteoModel(o),b=a.utc().format(),f=await It.spotForecast(t.lat,t.lng,b,!1,!1,!0,{...r,pastDays:1,forecastDays:2,weatherModels:k,marineModels:g}),[c]=it.Meteo2Assist.pickHourly(f,a);l=it.Meteo2Assist.toLegacy(c)}catch(k){C.warn("[%s] meteo2 spot(%j) forecast failed: %s",r.requestId,{...t,eta:a.utc().format(),source:o},k)}let h=O.currentFactor(e.bearing,l==null?void 0:l.current,i,r),d=O.weatherFactor(e,l,h,r);const I=e.speed*1.943844;I+h+d<=0&&(C.warn("[%s] v0(%d) is less then factor(%d) = wxFactor(%d) + cFactor(%d), scale factor with 0.6",r.requestId,I,d+h,d,h),h=Math.round(h*.6*1e3)/1e3,d=Math.round(d*.6*1e3)/1e3);const v=d<=(r.minV0Factor||-1)?Math.max(r.maxV0Factor||-3,-1*d*(d/1.2)):0;C==null||C.info("[%s] calculate speed lose with v0Factor(%d), cFactor(%d) and wxFactor(%d)",r.requestId,v,h,d),d+=v;let T=Math.round((I+h+d)*100)/100;T=T<=0?1:T,u={meteo:{...l},wxFactor:d,v0Factor:v,cFactor:h,speed:t.velocity&&s?t.velocity:T,eta:a.utc().format(),etd:a.utc().format()}}else u={wxFactor:0,v0Factor:0,cFactor:0,speed:t.velocity&&s?t.velocity:Math.round(e.speed*1.943844*100)/100,eta:a.utc().format(),etd:a.utc().format()};return delete t.meteo,delete t.wxFactor,delete t.cFactor,delete t.speed,delete t.etd,{...u,...t}}static async speedLoseInHoursStep(e,t,a,o,i,n,s="",r=!0,u=!1,l={}){t.utc();const h=t.clone().add(14,"days"),d=[],I=[],v=[];let T=0,k=0,g,b;for(let f=0;f<n.length-1;f++){let c=n[f];c.distanceFromStart=Math.round((i+k)*1e3)/1e3;const m=n[f+1];if(e.bearing=E.LaneHelper.calculateBearing(c,m,!m.gcToPrevious),c.bearing=e.bearing,c.suspend&&u){c.eta=c.eta||t.utc().format(),c.elapsed=c.elapsed??0;const p=c.suspend-c.elapsed;if(o-T>p)o=o-T-p,t.add(p,"hour"),c.elapsed=c.suspend;else{const L=o-T;c.elapsed+=L,t.add(L,"hour"),o=0}if(C==null||C.info(`[%s] suspend ${c.elapsed} hours at %j, and remain ${o} hours need to go...`,l.requestId,c),o===0)return c.distanceFromPrevious=k,{etd:t,from:b||c,to:c,next:n.filter(L=>L),wps:d,days:I,all:v}}else c.suspend=0;r=t.isAfter(h)?!1:r,c=await O.speedLoseAt(e,c,t,s,0,r,u,l),v.push(c),b=b||c,c.important&&d.push(c),t.isSameOrAfter(a)&&(I.push(c),a.add(24,"hour"));const y=E.LaneHelper.calculateDistance(c,m,!m.gcToPrevious);let F=Math.round(y/b.speed*1e5)/1e5;if(T+F<o){if(T+=F,t.add(F,"hour"),delete n[f],C==null||C.debug(`[%s] go to %j from %j with ${y}nm, and cost ${F} hours`,l.requestId,{lat:m.lat,lng:m.lng},{lat:b.lat,lng:b.lng,etd:b.etd}),k+=y,n.filter(p=>p).length<=1){g=m,g.eta=t.utc().format(),g.distanceFromPrevious=y,g.distanceFromStart=Math.round((i+k)*1e4)/1e4,d.push(g),v.push(g),delete n[f+1];break}}else{F=o-T,t.add(F,"hour");const p=E.LngLatHelper.roundPrecision(b.speed*F,5);g=E.LaneHelper.calculateCoordinate(c,e.bearing,p,"nauticalmiles",!m.gcToPrevious),g.eta=t.utc().format(),n[f]=g,C==null||C.debug(`[%s] go to %j from %j with ${p}nm, and cost ${F} hours`,l.requestId,{lat:g.lat,lng:g.lng},{lat:c.lat,lng:c.lng,etd:c.etd}),k+=p,g.distanceFromPrevious=Math.round(k*1e4)/1e4,g.distanceFromStart=Math.round((i+k)*1e4)/1e4;break}}return{etd:t,from:b,to:g,next:n.filter(f=>f),wps:d,days:I,all:v}}static currentFactor(e,t,a=0,o={}){const i=E.LaneHelper.includedAngle(e,(t==null?void 0:t.degree)||0)/180*Math.PI;let n;return Math.abs(i)===Math.PI/2&&(n=0),n=((t==null?void 0:t.kts)||0)*Math.cos(i),a&2?n=Math.ceil(n*100)/100:a&1?n=Math.floor(n*100)/100:n=Math.round(n*100)/100,C==null||C.info("[%s] calculate current factor with %j",o.requestId,{beta:i,current:t,factor:n,role:a}),Math.abs(n)>5?0:n}static weatherFactor(e,t,a=0,o={}){var v,T,k,g,b,f,c;C==null||C.info("[%s] calculate weather factor via: %j",o.requestId,{...e,...t});const i=O.blockCoefficient(e.displacement,e.lbp,e.breadthMoulded,e.draught),n=E.LngLatHelper.roundPrecision(a*1852/3600,6),s=O.froudeNumber(e.speed-n,e.lbp),r=O.amendFactor(i,s,e.loadCondition);let u=E.LaneHelper.includedAngle(e.bearing,(v=t==null?void 0:t.wind)==null?void 0:v.degree);const l=O.directionFactor(u,(T=t==null?void 0:t.wind)==null?void 0:T.scale),h=O.vesselTagFactor(e.displacement,e.loadCondition,e.tag,(k=t==null?void 0:t.wind)==null?void 0:k.kts);let d=l*r*h/100*(e.speed-n);d=Math.round(d*1.943844*1e4)/1e4*-1,e.tag==="tugs"&&Math.abs(d)>1&&(d=d/(Math.abs(Math.round(d))+1)),C==null||C.info("[%s] calculate wind wx factor: %d",o.requestId,d),u=E.LaneHelper.includedAngle(e.bearing,(b=(g=t==null?void 0:t.wave)==null?void 0:g.sig)==null?void 0:b.degree);const I=O.waveHeightFactor(((c=(f=t==null?void 0:t.wave)==null?void 0:f.sig)==null?void 0:c.height)??1,u,e.draught);return C==null||C.info("[%s] calculate wave wx factor: %d",o.requestId,I),d=Math.abs(d)>Math.abs(I)?d:.7*d+.9*I,C==null||C.info("[%s] calculate finial weather factor: %d (0.7 * wf) + (0.9 * hf)",o.requestId,d),Math.round((d||0)*100)/100}static async reduceDays(e,t=12*60*60){return e=e==null?void 0:e.reduce((a,o)=>(o.positionTime||(o.positionTime=w.utc(o.etd||o.eta).unix()),a.some(i=>Math.floor(i.positionTime/t)===Math.floor(o.positionTime/t))||a.push(o),a),[]),e}static async reduceWPS(e,t=60){return e=e==null?void 0:e.reduce((a,o)=>(a.some(i=>Math.floor(w(i.etd).unix()/t)===Math.floor(w(o.etd).unix()/t))||a.push(o),a),[]),e}static async analyseInstant(e,t,a,o,i,n="",s=0,r=!0,u=!1,l={}){var X,Q,Z,$,tt,et;const h=w().valueOf();e.lng=E.LngLatHelper.convertToStdLng(e.lng);const{route:d,waypoints:I}=i.points,v=E.LaneHelper.calculateSubRoute(e,d);if(((X=v[0])==null?void 0:X.length)<=1)return;const{v0:T,label:k}=e.sog?{v0:e.sog,label:e.label||"Other"}:{v0:o.speed,label:"CP"},g=O.assembleProperties(a,o.loadCondition,T,0),b=I.length?E.LaneHelper.calculateSubWaypoints(e,I):[];b.forEach(D=>D.important=!0);const f={from:{...e},route:v,waypoints:b,v0:T,label:k},c={hours:[],days:[],wps:[],all:[]};s||(E.LaneHelper.calculateRouteDistance(v)/o.speed<=72?s=3:s=6);let m=E.LaneHelper.simplifyRouteToCoordinates(v,b,0),y=0,F=0,p=0,L=0;t=w(t).utc();const H=t.clone();for(;m.length>0;){const D=s-t.hour()%s,J=Math.ceil(t.clone().add(D,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,j=await O.speedLoseInHoursStep(g,t,H,J,y,m,n,r,u,l);if(c.all.push(...j.all),(Q=j.from)!=null&&Q.speed&&(c.hours.push(j.from),c.wps.push(...j.wps),c.days.push(...j.days)),m=j==null?void 0:j.next,!m.length){const V=await O.speedLoseAt(g,j.to,w(j.to.eta),n,0,r,u,l);V.bearing=g.bearing,c.hours.push(V),c.all.push(V)}y+=Math.round((((Z=j==null?void 0:j.to)==null?void 0:Z.distanceFromPrevious)??0)*1e4)/1e4}const N=c.hours;for(let D=0;D<N.length-1;D++){const J=w(N[D+1].eta).diff(N[D].etd,"hour",!0)||1;F+=(N[D].wxFactor||0)*J,p+=(N[D].cFactor||0)*J,L+=J}const W=N.reduce((D,J)=>D+(J.suspend||0),0);($=c.wps)==null||$.forEach((D,J)=>{D.positionTime=w.utc(D.etd||D.eta).unix();const j=c.wps[J-1];if(j){const V=D.distanceFromStart-j.distanceFromStart,Y=w(D.eta||D.etd).diff(w(j.etd||j.eta),"h",!0);D.avgSpd=Math.round(V/Y*100)/100;const ot=E.LaneHelper.calculateBearing(j,D);D.avgBearing=ot,j.bearing=ot}}),c.wps=await O.reduceWPS(c.wps),c.days=await O.reduceDays(c.days),c.all=(tt=c.all)==null?void 0:tt.reduce((D,J)=>(J.positionTime=w.utc(J.etd||J.eta).unix(),D.some(j=>Math.round(j.positionTime/60)===Math.round(J.positionTime/60))||D.push(J),D),[]),f.sample=c;const B=c.hours.at(0),S=c.hours.at(-1);f.distance=Math.round(S.distanceFromStart*1e3)/1e3,f.etd=w(B.eta).utc().format(),f.eta=w(S.eta).utc().format(),f.wxFactor=Math.round(F/L*1e3)/1e3,f.cFactor=Math.round(p/L*1e3)/1e3,f.avgSpeed=Math.round(S.distanceFromStart/L*1e3)/1e3,f.totalHrs=Math.round(L*1e3)/1e3,f.suspend=Math.round(W*1e3)/1e3;const R=E.LngLatHelper.roundPrecision(o.dgo/24*W,3),{distanceInECA:q,hoursInECA:z,totalDgoConsInECA:rt,eca:st}=await this.calculateECA(f,o,l),at=E.LngLatHelper.roundPrecision(o.fo/24*(L-z),3),ct=E.LngLatHelper.roundPrecision(o.dgo/24*L+R,3);f.extend={eca:st,distanceInECA:q,hoursInECA:z,totalDgoConsInECA:rt,totalDgoConsInSuspend:R},f.totalFoCons=at<0?0:at,f.totalDgoCons=ct;const nt=w().valueOf()-h,ut=((et=c==null?void 0:c.hours)==null?void 0:et.length)||1;return C==null||C.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",l==null?void 0:l.requestId,nt,ut,Math.round(nt/ut*1e3)/1e3),f}static async analyseInstantWithThreshed(e,t,a,o,i,n,s,r="",u=3,l=!0,h=!1,d={}){var Z,$,tt,et,D,J;const I=w().valueOf();e.lng=E.LngLatHelper.convertToStdLng(e.lng);const{v0:v,label:T}=e.sog?{v0:e.sog,label:e.label||"Other"}:{v0:i.speed,label:"CP"},k=O.assembleProperties(o,i.loadCondition,v,0),g=E.LaneHelper.calculateSubRoute(e,n);if(((Z=g[0])==null?void 0:Z.length)<=1)return;const b=s.length?E.LaneHelper.calculateSubWaypoints(e,s):[];b.forEach(j=>j.important=!0);let f=E.LaneHelper.simplifyRouteToCoordinates(g,b,0),c=0,m=0,y=0,F=0;const p={hours:[],wps:[],days:[],all:[]};t=w(t).utc();const L=t.clone();for(;f.length>0;){const j=u-t.hour()%u;let V=Math.ceil(t.clone().add(j,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;V=t.clone().add(V,"h").isSameOrAfter(a)?a.diff(t,"h",!0)*1e4/1e4:V;const Y=await O.speedLoseInHoursStep(k,t,L,V,c,f,r,l,h,d);if(p.all.push(...Y.all),($=Y.from)!=null&&$.speed&&(p.hours.push(Y.from),Y!=null&&Y.wps&&p.wps.push(...Y.wps),p.days.push(...Y.days)),f=Y==null?void 0:Y.next,f.length||p.hours.push(Y==null?void 0:Y.to),c+=Math.round((((tt=Y==null?void 0:Y.to)==null?void 0:tt.distanceFromPrevious)??0)*1e4)/1e4,!V)break}p.wps=await O.reduceWPS(p.wps),p.days=await O.reduceDays(p.days),p.all=(et=p.all)==null?void 0:et.reduce((j,V)=>(V.positionTime=w.utc(V.etd||V.eta).unix(),j.some(Y=>Math.round(w(Y.etd).unix()/60)===Math.round(w(V.etd).unix()/60))||j.push(V),j),[]),(D=p.wps)==null||D.forEach((j,V)=>{const Y=p.wps[V-1];if(Y){const ot=j.distanceFromStart-Y.distanceFromStart,kt=w(j.eta||j.etd).diff(w(Y.etd||Y.eta),"h",!0);Y.bearing=E.LaneHelper.calculateBearing(Y,j),j.avgSpd=Math.round(ot/kt*100)/100}});const H=p.hours;for(let j=0;j<H.length-1;j++){const V=w(H[j+1].eta).diff(H[j].etd,"hour",!0);m+=H[j].wxFactor*V,y+=H[j].cFactor*V,F+=V}const N=H.reduce((j,V)=>j+(V.suspend||0),0),W=p.hours.at(0),B=p.hours.at(-1),S=await E.LaneHelper.calculateRangeRoute(W,B,g),R=await E.LaneHelper.calculateRangeWaypoints(W,B,g,b),q={sample:p,distance:Math.round(((B==null?void 0:B.distanceFromStart)||0)*1e4)/1e4,etd:w(W.eta).utc().format(),eta:w(B==null?void 0:B.eta).utc().format(),wxFactor:Math.round(m/F*1e3)/1e3,cFactor:Math.round(y/F*1e3)/1e3,avgSpeed:Math.round(((B==null?void 0:B.distanceFromStart)||0)/F*1e3)/1e3,totalHrs:Math.round(F*1e3)/1e3,suspend:Math.round(N*1e3)/1e3,from:W,to:B,route:S,waypoints:R,v0:v,label:T},z=E.LngLatHelper.roundPrecision(i.dgo/24*N,3),{distanceInECA:rt,hoursInECA:st,totalDgoConsInECA:at,eca:ct}=await this.calculateECA(q,i,d),dt=E.LngLatHelper.roundPrecision(i.fo/24*(F-st),3),nt=E.LngLatHelper.roundPrecision(i.dgo/24*F+z,3);q.extend={eca:ct,distanceInECA:rt,hoursInECA:st,totalDgoConsInECA:at,totalDgoConsInSuspend:z},q.totalDgoCons=nt,q.totalFoCons=dt<0?0:dt;const X=w().valueOf()-I,Q=((J=p==null?void 0:p.hours)==null?void 0:J.length)||1;return C==null||C.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",d==null?void 0:d.requestId,X,Q,Math.round(X/Q*1e3)/1e3),q}static async analyseCost(e,t,a,o,i={}){var g,b;const n=w().valueOf(),s=[];e.speedStep=e.speedStep||3,e.alterStep=e.alterStep??1;const r=E.LaneHelper.calculateRouteDistance(o.route);let u=0;a.forEach(f=>{const c=Math.ceil(r/f.speed/24);u=u<c?c:u}),u=u*1.3;const l=w.utc(e.etd).add(u??14,"day");let h=1;for(const f of a){const c=JSON.parse(JSON.stringify(o.route)),m=JSON.parse(JSON.stringify(o.waypoints)),y=await O.analyseInstantWithThreshed({lat:e.lat,lng:e.lng},e.etd,l,t,f,c,m,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,i);y&&(await O.calculateCost(y,f,e,i),s.push(y),C==null||C.info("[%s][L%d-%d] analyse from %s to %s cost: %j",i.requestId,1,h,e.etd,l.format(),{cost:y.cost.total,hire:y.cost.hire,bunker:y.cost.bunker,distance:y.distance,hours:y.totalHrs,cp:`${f.speed}/${f.fo}/${f.dgo}`})),h++}s.sort((f,c)=>f.cost.total-c.cost.total);const d=s.at(0),I=s.at(1),v=[];if(v.push({combined:!1,speeds:[d],cost:(g=d.cost)==null?void 0:g.total}),I){const f=d.cost.cp,c=I.cost.cp,m=w(d.eta),y=w(d.etd),F=m.diff(y,"days",!0);let p=Math.ceil(F/2);p=p>7?7:p<e.alterStep?e.alterStep:p;let L=2,H={combined:!1,speeds:[I],cost:(b=I.cost)==null?void 0:b.total},N;for(;p>=e.alterStep;){const W=await O.combinedAnalyse(e,t,l,[f,c],o,p,{...i,level:L});if(H.cost>W.cost?N?(N==null?void 0:N.cost)>W.cost&&(N=W):(N=H,H=W):(!N||(N==null?void 0:N.cost)>W.cost)&&(N=W),p<=e.alterStep)break;p=Math.ceil(p/2),L+=1}v.push(H),N&&v.push(N)}const k=w().valueOf()-n;return C==null||C.info("[%s] analyse elapsed: %d ms",i==null?void 0:i.requestId,k),v.sort((f,c)=>f.cost-c.cost)}static async combinedAnalyse(e,t,a,o,i,n,s={}){s.counter=1,C==null||C.info("[%s][L%d] analyse with alternate cp in every %d days",s.requestId,s.level,n);const r=await O.alternateAnalyse(e,t,a,o,0,i,n,s),u=r.reduce((c,m)=>c+m.cost.total,0),l=r.reduce((c,m)=>c+m.cost.hire,0),h=r.reduce((c,m)=>c+m.cost.bunker,0),d=r.reduce((c,m)=>c+m.distance,0),I=r.reduce((c,m)=>c+m.totalHrs,0);C==null||C.info("[%s][L%d] cost with cpa/cpb turn: %j",s.requestId,s.level,{cost:u,hire:l,bunker:h,distance:d,hours:I});const v=await O.alternateAnalyse(e,t,a,o,1,i,n,s),T=v.reduce((c,m)=>c+m.cost.total,0),k=v.reduce((c,m)=>c+m.cost.hire,0),g=v.reduce((c,m)=>c+m.cost.bunker,0),b=v.reduce((c,m)=>c+m.distance,0),f=v.reduce((c,m)=>c+m.totalHrs,0);return C==null||C.info("[%s][L%d] cost with cpb/cpa turn: %j",s.requestId,s.level,{cost:T,hire:k,bunker:g,distance:b,hours:f}),u<T?{combined:!0,cost:Math.round(u*1e3)/1e3,speeds:r,step:n}:{combined:!0,cost:Math.round(T*1e3)/1e3,speeds:v,step:n}}static async alternateAnalyse(e,t,a,o,i,n,s,r={}){var d,I;let u=w.utc(e.etd);const l={lat:e.lat,lng:e.lng},h=[];for(;u.isBefore(a);){const v=u.clone().utc().add(s,"day"),T=JSON.parse(JSON.stringify(n.route)),k=JSON.parse(JSON.stringify(n.waypoints)),g=o[i],b=await O.analyseInstantWithThreshed(l,u.utc().format(),v,t,g,T,k,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,r);b&&(await O.calculateCost(b,g,e,r),C==null||C.info("[%s][L%d-%d] analyse from %s to %s cost: %j",r.requestId,r.level,r.counter,u.utc().format(),v.utc().format(),{cost:b.cost.total,hire:b.cost.hire,bunker:b.cost.bunker,distance:b.distance,hours:b.totalHrs,cp:`${g.speed}/${g.fo}/${g.dgo}`})),r.counter=r.counter+1;const f=(I=(d=b==null?void 0:b.sample)==null?void 0:d.hours)==null?void 0:I.at(-1);if(f)l.lat=f.lat,l.lng=f.lng,u=w(f.eta),h.push(b),i=i?0:1;else break}return h}static async calculateCost(e,t,a,o={}){var i;if(e){const n=(a.addComm||0)>=1?(a.addComm||0)/100:a.addComm||0,s=Math.round((a.dailyHire||0)*(e.suspend||0)/24*1e3)/1e3,r=Math.round(e.totalHrs/24*(a.dailyHire||0)*(1-n)*1e3)/1e3+s,u=Math.round(e.totalFoCons*(a.priceFO||0)*1e3)/1e3,l=Math.round((e.totalDgoCons+(((i=e.extend)==null?void 0:i.totalDgoConsInECA)||0))*(a.priceDGO||0)*1e3)/1e3;e.cost={total:Math.round((r+u+l)*1e3)/1e3,hire:Math.round(r*1e3)/1e3,suspendHire:s,bunker:Math.round((u+l)*1e3)/1e3,cp:t}}return e}static async calculateECA(e,t,a={}){var r,u,l,h;const o=await E.LaneHelper.intersectInECA((e==null?void 0:e.route)||[]);let i=0,n=0,s=0;(u=(r=e==null?void 0:e.sample)==null?void 0:r.wps)==null||u.forEach(d=>{d.positionTime=w.utc(d.etd||d.eta).unix()});for(const d of o){i+=d.distance;const I=await E.LaneHelper.deadReckoningTime((l=d.waypoints)==null?void 0:l.at(0),e.sample.all||e.sample.wps),v=await E.LaneHelper.deadReckoningTime((h=d.waypoints)==null?void 0:h.at(-1),e.sample.all||e.sample.wps);d.in=I,d.out=v,d.totalHrs=E.LngLatHelper.roundPrecision((v.positionTime-I.positionTime)/3600,3),d.totalDgoCons=E.LngLatHelper.roundPrecision(t.fo/24*d.totalHrs,3),n+=d.totalHrs,s+=d.totalDgoCons}return i=E.LngLatHelper.roundPrecision(i,3),n=E.LngLatHelper.roundPrecision(n,3),s=E.LngLatHelper.roundPrecision(s,3),{distanceInECA:i,hoursInECA:n,totalDgoConsInECA:s,eca:o}}static async mergeSpeeds(e,t={}){var f,c;const a={hours:[],wps:[],days:[],all:[]},o=e.reduce((m,y)=>m+y.distance,0),i=e.reduce((m,y)=>{var F;return m+(((F=y.extend)==null?void 0:F.distanceInECA)||0)},0),n=e.reduce((m,y)=>m+y.totalHrs,0),s=e.reduce((m,y)=>{var F;return m+(((F=y.extend)==null?void 0:F.hoursInECA)||0)},0),r=e.reduce((m,y)=>{var F;return m+(((F=y.extend)==null?void 0:F.totalDgoConsInECA)||0)},0),u=e.reduce((m,y)=>m+y.wxFactor*y.totalHrs/n,0),l=e.reduce((m,y)=>m+y.cFactor*y.totalHrs/n,0),h=e.reduce((m,y)=>m+y.totalFoCons,0),d=e.reduce((m,y)=>m+y.totalDgoCons,0),I=e.reduce((m,y)=>m+y.cost.total,0),v=e.reduce((m,y)=>m+y.cost.hire,0),T=e.reduce((m,y)=>m+y.cost.bunker,0),k=[],g=[];let b;for(const m of e){g.push(...((f=m.extend)==null?void 0:f.eca)||[]);const y=m.sample.hours,F=m.sample.all,p=m.sample.wps,L=m.sample.days,H=y.at(0);b&&(H.distanceFromPrevious=b.distanceFromPrevious,H.distanceFromStart=b.distanceFromStart,y.forEach((S,R)=>{R&&(S.distanceFromStart=S.distanceFromStart+b.distanceFromStart)}),F.at(0).distanceFromPrevious=b.distanceFromPrevious,F.at(0).distanceFromStart=b.distanceFromStart,F.forEach((S,R)=>{R&&(S.distanceFromStart=S.distanceFromStart+b.distanceFromStart)}),p.at(0).distanceFromPrevious=b.distanceFromPrevious,p.at(0).distanceFromStart=b.distanceFromStart,p.forEach((S,R)=>{R&&(S.distanceFromStart=S.distanceFromStart+b.distanceFromStart)}),L.at(0).distanceFromPrevious=b.distanceFromPrevious,L.at(0).distanceFromStart=b.distanceFromStart,L.forEach((S,R)=>{R&&(S.distanceFromStart=S.distanceFromStart+b.distanceFromStart)})),H.cp=m.cost.cp;const N=[m.etd,m.eta],W=k.findIndex(S=>S.id===H.cp.id);W===-1?(H.cp.segment=[N],k.push(H.cp)):k[W].segment.push(N),y.forEach(S=>{var q;((q=a.hours)==null?void 0:q.findIndex(z=>z.eta===S.eta))===-1&&a.hours.push(S)}),F.forEach(S=>{var q;((q=a.all)==null?void 0:q.findIndex(z=>z.eta===S.eta))===-1&&a.all.push(S)}),p.forEach(S=>{var q;((q=a.wps)==null?void 0:q.findIndex(z=>z.eta===S.eta))===-1&&a.wps.push(S)}),L.forEach(S=>{var q;((q=a==null?void 0:a.days)==null?void 0:q.findIndex(z=>z.eta===S.eta))===-1&&a.days.push(S)});const B=(c=a.wps)==null?void 0:c.findIndex(S=>S.eta===H.eta);B===-1?a.wps.push(H):a.wps[B]=H,b=y.at(-1)}return a.wps.sort((m,y)=>w(m.etd).unix()-w(y.etd).unix()),a.wps.forEach((m,y)=>{const F=a.wps[y-1];if(F){const p=m.distanceFromStart-(F.distanceFromStart||0),L=w(m.eta||m.etd).diff(w(F.etd||F.eta),"hour",!0),H=Math.round(p/L*100)/100;m.avgSpd=H;const N=E.LaneHelper.calculateBearing(F,m);F.bearing=N}}),{sample:a,etd:e.at(0).etd,eta:e.at(-1).eta,from:e.at(0).from,to:e.at(-1).to,v0:e.at(0).v0,label:"Combined",distance:Math.round(o*1e3)/1e3,totalHrs:Math.round(n*1e3)/1e3,avgSpeed:Math.round(o/n*1e3)/1e3,wxFactor:Math.round(u*1e3)/1e3,cFactor:Math.round(l*1e3)/1e3,totalFoCons:Math.round(h*1e3)/1e3,totalDgoCons:Math.round(d*1e3)/1e3,cost:{total:Math.round(I*1e3)/1e3,hire:Math.round(v*1e3)/1e3,bunker:Math.round(T*1e3)/1e3},extend:{cps:k,eca:g,distanceInECA:Math.round(i*1e3)/1e3,hoursInECA:Math.round(s*1e3)/1e3,totalDgoConsInECA:Math.round(r*1e3)/1e3,speeds:e}}}}P.AISImpl=G,P.AlertHelper=ht,P.AlertLevel=lt,P.HifleetImpl=vt,P.LoadCondition=mt,P.MyShipImpl=gt,P.MyVesselImpl=Mt,P.ShipxyImpl=bt,P.SpeedHelper=O,P.SpeedLabel=yt,P.VesselTag=ft,P.alertHelper=wt,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idm-plugin/vessel",
3
3
  "private": false,
4
- "version": "3.7.5",
4
+ "version": "3.7.6",
5
5
  "description": "idm plugin for vessel",
6
6
  "type": "module",
7
7
  "keywords": [