@idm-plugin/vessel 3.8.0 → 3.8.2

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
@@ -1096,7 +1096,7 @@ class H {
1096
1096
  let c = l * r * h / 100 * (e.speed - a);
1097
1097
  c = Math.round(c * 1.943844 * 1e4) / 1e4 * -1, e.tag === "tugs" && Math.abs(c) > 1 && (c = c / (Math.abs(Math.round(c)) + 1)), C == null || C.info("[%s] calculate wind wx factor: %d", o.requestId, c), u = R.includedAngle(e.bearing, (v = (w = t == null ? void 0 : t.wave) == null ? void 0 : w.sig) == null ? void 0 : v.degree);
1098
1098
  const I = H.waveHeightFactor(((d = (m = t == null ? void 0 : t.wave) == null ? void 0 : m.sig) == null ? void 0 : d.height) ?? 1, u, e.draught, o);
1099
- return C == null || C.info("[%s] calculate wave wx factor: %d", o.requestId, I), c = Math.abs(c) > Math.abs(I) ? c : 0.7 * c + 0.9 * I, C == null || C.info("[%s] calculate finial weather factor: %d (0.7 * wf) + (0.9 * hf)", o.requestId, c), c = Math.abs(c) > 4 ? 4 * (Math.abs(c) / c) + Math.abs(c) / c * (Math.abs(c) - 2) * 0.1 : c, Math.round((c || 0) * 100) / 100;
1099
+ return C == null || C.info("[%s] calculate wave wx factor: %d", o.requestId, I), c = Math.abs(c) > Math.abs(I) ? c : 0.6 * c + 0.8 * I, C == null || C.info("[%s] calculate finial weather factor: %d (0.6 * wf) + (0.8 * hf)", o.requestId, c), c = Math.abs(c) > 3 ? 3 * (Math.abs(c) / c) + Math.abs(c) / c * (Math.abs(c) - 2) * 0.1 : c, Math.round((c || 0) * 100) / 100;
1100
1100
  }
1101
1101
  /**
1102
1102
  * 以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,Mt,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 p;try{p=K.getLogger("vessel")}catch{}finally{}class G{parseStatus(e){let t,n;switch(e){case 0:t="在航(主机推动)",n="Underway Using Engine";break;case 1:t="锚泊",n="Anchored";break;case 2:t="失控",n="Not under command";break;case 3:t="操纵受限",n="Limited airworthiness";break;case 4:t="吃水受限",n="Limited by ship's draft";break;case 5:t="靠泊",n="Mooring";break;case 6:t="搁浅",n="Stranded";break;case 7:t="捕捞作业",n="Engaged in fishing";break;case 8:t="靠帆船提供动力",n="Sailing";break;default:t="未定义",n="Undefined"}return{labelCn:t,labelEn:n}}}class pt extends G{constructor(t,n){super();U(this,"clientId");U(this,"clientSecret");U(this,"token");this.clientId=t,this.clientSecret=n}async authToken(t={}){const n="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(n,o).json();p==null||p.info("[%s] fetch access token from: %s - %j",t.requestId,n,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 n;return(!this.token||w().diff(w(this.token.issuedAt),"seconds")>(((n=this.token)==null?void 0:n.expiresIn)||0)-300)&&await this.authToken(t),this.token}async suggest(t,n={}){var a,r;await this.checkToken(n);const o="https://market.myvessel.cn/sdc/v1/mkt/vessels/fuzzy",i={headers:{Authorization:`${(a=this.token)==null?void 0:a.tokenType} ${(r=this.token)==null?void 0:r.accessToken}`},json:{kw:t,recordNum:n.ps||10}};p==null||p.info("[%s] fetch suggest vessels from: %s - %j",n.requestId,o,i);const s=await x.post(o,i).json();return s.status!==200?(p==null||p.warn("[%s] fetch suggest vessels failed: %j",n.requestId,{message:s.message,status:s.status,code:s.code}),[]):(s.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,n={}){var u,l;await this.checkToken(n);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",s=o?{imo:t}:{mmsi:t},a={headers:{Authorization:`${(u=this.token)==null?void 0:u.tokenType} ${(l=this.token)==null?void 0:l.accessToken}`},searchParams:s};p==null||p.info("[%s] fetch vessel from: %s - %j",n.requestId,i,a);const r=await x.get(i,a).json();if(r.status!==200)return p==null||p.warn("[%s] fetch suggest vessels failed: %j",n.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,n={}){var a,r;await this.checkToken(n);const o="https://svc.data.myvessel.cn/sdc/v1/ship/info/batch",i={headers:{Authorization:`${(a=this.token)==null?void 0:a.tokenType} ${(r=this.token)==null?void 0:r.accessToken}`},json:{mmsiList:typeof t=="number"?[t]:t}};p==null||p.info("[%s] fetch vessel archive from: %s - %j",n.requestId,o,i);const s=await x.post(o,i).json();return s.status!==200?(p==null||p.warn("[%s] fetch vessel archive failed: %j",n.requestId,{message:s.message,status:s.status,code:s.code}),{}):s.data}async realTimePosition(t,n={}){var r,u;await this.checkToken(n);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}};p==null||p.info("[%s] fetch realtime position from: %s - %j",n.requestId,o,i);const s=await x.get(o,i).json();if(s.code)return p==null||p.warn("[%s] fetch realtime position failed: %j",n.requestId,{message:s.message,status:s.status,code:s.code}),s;const a=s.data;for(const l in a)!isNaN(a[l])&&Number(a[l])!==1/0&&(a[l]=Number(a[l]));if(a){const l=w(`${a.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:a.mmsi,name:a.vesselName||a.aisVesselName,imo:a.imo,callSign:a.callsign||a.aisCallSign,lat:a.lat,lng:a.lon,length:a.length,width:a.width,draught:a.currDraught,sog:a.sog,cog:a.cog,hdg:a.hdg,rot:a.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(a.eta)?w.utc(a.eta).format():void 0,destination:a.dest,positionTime:l.unix(),status:a.status,labelCn:a.statusNameCn,labelEn:a.statusNameEn,vesselType:a.vesselTypeNameEn,flag:a.flagCtryNameEn,clasz:a.classSociety,build:a.buildYear,dwt:a.dwt,grt:a.grt,net:a.net,method:"position",vendor:"myVessel",utc:l.utc().format()}}else return{}}async calculateRoute(t,n,o,i,s,a={}){var I,b,T;const r=w();await this.checkToken(a);const u="https://market.myvessel.cn/sdc/v1/mkt/routes/plan",l={maxDraught:a.draught||10,useAIModel:a.useAIModel??!0,withECA:a.withECA||!1,withSpecialRegion:a.withSpecial||!1};t.code&&(l.startPortCode=t.code),t.lng!==void 0&&t.lat!==void 0&&(l.startPoint={lon:t.lng,lat:t.lat}),n.code&&(l.endPortCode=n.code),n.lng!==void 0&&n.lat!==void 0&&(l.endPoint={lon:n.lng,lat:n.lat}),o!=null&&o.length&&(l.crossMonthList=o),i!=null&&i.length&&(l.excludeNodes=i),s!=null&&s.length&&(l.excludeSeaAreas=s);const h={headers:{Authorization:`${(I=this.token)==null?void 0:I.tokenType} ${(b=this.token)==null?void 0:b.accessToken}`},json:l};p==null||p.info("[%s] fetch route from: %s - %j",a.requestId,u,h);const c=await x.post(u,h).json();if(c.status!==200)return p==null||p.warn("[%s] fetch route failed: %j",a.requestId,{message:c.message,status:c.status,code:c.code}),{};{const k={status:"Success",nodes:[],seas:[],regions:[],waypoints:[],route:[],distance:0,memo:""},{nodes:g,seas:v,tracks:f,specialRegions:d,ecaLength:m}=c.data;k.nodes=g==null?void 0:g.map(M=>({code:M.nodeCode,nameEn:M.nameEn,nameCn:M.nameCn,center:{lat:Math.round(M.lat*1e6)/1e6,lng:Math.round(M.lon*1e6)/1e6},start:{lat:Math.round(M.startLat*1e6)/1e6,lng:Math.round(M.startLon*1e6)/1e6},end:{lat:Math.round(M.endLat*1e6)/1e6,lng:Math.round(M.endLat*1e6)/1e6},isKey:M.isKeyNode,isHub:M.isHubNode})),k.seas=v==null?void 0:v.map(M=>({code:M.mrgidSea,nameEn:M.nameEn,nameCn:M.nameCn,center:{lat:Math.round(M.centerLat*1e6)/1e6,lng:Math.round(M.centerLon*1e6)/1e6},min:{lat:Math.round(M.minLat*1e6)/1e6,lng:Math.round(M.minLon*1e6)/1e6},max:{lat:Math.round(M.maxLat*1e6)/1e6,lng:Math.round(M.maxLon*1e6)/1e6},level:M.mapLevel})),d==null||d.map(M=>{M.regionLength&&k.regions.push({type:M.regionType,distance:M.regionLength,rows:M.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(M=>({lat:Math.round(M.lat*1e5)/1e5,lng:Math.round(M.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`,p.info("[%s] calculate route cost: %d seconds",a.requestId,F),k}}async trajectory(t,n,o,i,s=!0,a={}){await this.checkToken(a);const r=await this.realTimePosition(t,a),u=w(n),l=w(o),h=[];for(;l.diff(u,"day",!0)>30;)await this.trajectoryIn30Day(t,u,u.clone().add(30,"day"),r,i,h,a),u.add(30,"day");return await this.trajectoryIn30Day(t,u,l,r,i,h,a),h}async trajectoryIn30Day(t,n,o,i,s,a,r={}){var b,T,k,g,v;const u="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",l={headers:{Authorization:`${(b=this.token)==null?void 0:b.tokenType} ${(T=this.token)==null?void 0:T.accessToken}`},json:{mmsi:t,startTime:n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:o.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};p==null||p.info("[%s] fetch trajectory from: %s - %j",r.requestId,u,l);const h=await x.post(u,l).json();if(h.code)return p==null||p.warn("[%s] fetch trajectory failed: %j",r.requestId,u,{message:h.message,status:h.status,code:h.code}),h;let c=-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(v=h.data)==null||v.forEach(f=>{for(const H in f)!isNaN(f[H])&&Number(f[H])!==1/0&&(f[H]=Number(f[H]));const d=w(`${f.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),m=f.status,{labelCn:y,labelEn:F}=this.parseStatus(m),M={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:d.unix(),labelCn:y,labelEn:F,method:"trajectory",vendor:"myVessel",utc:d.utc().format()},L=Math.floor(d.diff(I,"minute",!0)/(s||1));L!==c&&(c=L,a.push(M))}),a}}class bt extends G{constructor(t){super();U(this,"token");this.token=t}async realTimePosition(t,n={}){const o="https://api.hifleet.com/position/position/get/token",i={searchParams:{mmsi:t,usertoken:this.token}},s=await x.post(o,i).json();p==null||p.info("[%s] fetch realtime position from: %s - %j",n.requestId,o,i);const a=s==null?void 0:s.list;if(!a)return p==null||p.warn("[%s] fetch realtime position failed: %j",n.requestId,o,s),s;for(const I in a)!isNaN(a[I])&&Number(a[I])!==1/0&&(a[I]=Number(a[I]));a.status=a.sp>3?0:1;const r=a.status,{labelCn:u,labelEn:l}=this.parseStatus(r),h=w(`${a.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:a.m,name:a.n,imo:a.imonumber,callSign:a.callsign,lat:Math.round(a.la/60*1e5)/1e5,lng:Math.round(a.lo/60*1e5)/1e5,length:a.l,width:a.w,draught:a.draught,sog:a.sp,cog:a.co,hdg:a.h,rot:isNaN(a.rot)?0:a.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(a.eta)?w.utc(a.eta).format():void 0,destination:a.destination,vesselType:a.type,dwt:a.dwt,build:a.buildyear,flag:a.fn,positionTime:h.unix(),utc:h.utc().format(),status:r,labelCn:u,labelEn:l,method:"position",vendor:"hifleet"}}async search(t,n={}){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 s=await x.post(o,i).json();p==null||p.info("[%s] fetch vessel props from: %s - %j",n.requestId,o,i),s instanceof Array&&(s=s[0]);for(const r in s)!isNaN(s[r])&&Number(s[r])!==1/0&&(s[r]=Number(s[r]));const a={mmsi:s.m,name:s.n,imo:s.i,callSign:s.c,length:s.l,breadth:s.b,draught:s.dr,type:s.t};return o="https://www.hifleet.com/hifleetapi/sameShipSearch.do",s=await x.post(o,i).json(),p==null||p.info("[%s] search vessel dead weight from: %s - %j",n.requestId,o,i),s instanceof Array&&(s=s[0]),s&&(a.deadweight=Number(s.dwt)),a}async suggest(t,n={}){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"}},s=await x.post(o,i).json();p==null||p.info("[%s] suggest vessel props from: %s - %j",n.requestId,o,i);const a=[];for(const r of s)a.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 a.sort((r,u)=>u.score-r.score),a}async trajectory(t,n,o,i,s=!0,a={}){var f,d,m;const r=await this.realTimePosition(t,a);let u=w(n);const l=w(o),h=w();if(s){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 c={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",b=await x.get(I,c).json();p==null||p.info("[%s] fetch trajectory from: %s - %j",a.requestId,I,c);let T;b&&(T=((d=(f=b.ships)==null?void 0:f.offors)==null?void 0:d.ship)||[],T.length||p==null||p.warn("[%s] fetch trajectory failed: %j",a.requestId,b));const k=[];let g=-1;const v=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:M,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:M,method:"trajectory",vendor:"hifleet"},N=Math.floor(F.diff(v,"minute",!0)/(i||1));N!==g&&(g=N,k.push(H))}return k}}class vt extends G{constructor(t){super();U(this,"token");this.token=t}async realTimePosition(t,n={}){const o={searchParams:{id:t,k:this.token,enc:1}},i="https://api.shipxy.com/apicall/GetSingleShip",s=await x.get(i,o).json();if(p==null||p.info("[%s] fetch realtime position from: %s - %j",n.requestId,i,o),(s==null?void 0:s.status)!==0)return s;const a=s.data[0];for(const c in a)!isNaN(a[c])&&Number(a[c])!==1/0&&(a[c]=Number(a[c]));const{labelCn:r,labelEn:u}=await this.parseStatus(a.navistat),l=w.unix(a.lasttime);return{mmsi:a.ShipID,name:a.name,imo:a.imo,callSign:a.callsign,lat:Math.round(a.lat/1e6*1e5)/1e5,lng:Math.round(a.lon/1e6*1e5)/1e5,length:Math.round(a.length/10*100)/100,width:Math.round(a.width/10*100)/100,draught:Math.round(a.draught/1e3*100)/100,sog:Math.round(a.sog*3600/1e3/1852*100)/100,cog:Math.round(a.cog/100*100)/100,hdg:Math.round(a.hdg/100*100)/100,rot:Math.round(a.rot/100*100)/100,positionTime:a.lasttime,utc:l.utc().format(),status:a.navistat,labelEn:u,labelCn:r,method:"position",vendor:"shipxy"}}async trajectory(t,n,o,i,s=!0,a={}){var v;const r=await this.realTimePosition(t,a),u=w(n),l=w(o),h="https://api.shipxy.com/apicall/GetShipTrack",c={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:u.unix(),etm:l.unix()}},I=await x.get(h,c).json();if(p==null||p.info("[%s] fetch trajectory from: %s - %j",a.requestId,h,c),(I==null?void 0:I.status)!==0)return I;const b=I==null?void 0:I.points,T=[],k=w.unix((v=b[0])==null?void 0:v.utc);let g=-1;for(const f of b){const d=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:d.unix(),utc:d.utc().format(),method:"trajectory",vendor:"shipxy"},y=Math.floor(d.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,n={}){const o={headers:{appKey:this.token},json:{mmsiList:t}},i="https://api3.myships.com/sp/ships/getShipIdByMMSI",s=await x.post(i,o).json();return p==null||p.info("[%s] fetch ship id from: %s - %j",n.requestId,i,o),s.code!=="0"?s:s.data[0].shipId}async getShipInfo(t,n={}){const o={headers:{appKey:this.token},json:{shipId:t}},i="https://api3.myships.com/sp/ships/aissta",s=await x.post(i,o).json();if(p==null||p.info("[%s] fetch ship info from: %s - %j",n.requestId,i,o),s.code!=="0")return s;const a=s.data;let r=a.imo;return t==="407170"&&(r="9198379",p==null||p.warn("[%s] ship(%s) imo error: %s, should be %s",n.requestId,t,a.imo,r)),{mmsi:a.mmsi,name:a.shipnameEn,imo:r,callSign:a.callSign,length:a.length,width:a.breadth,draught:(a.draught||100)/10}}async realTimePosition(t,n={}){const o=await this.getShipId(t,n),i=await this.getShipInfo(o,n),s={headers:{appKey:this.token},json:{shipId:o}},a="https://api3.myships.com/sp/ships/position/latest",r=await x.post(a,s).json();p==null||p.info("[%s] fetch realtime position from: %s - %j",n.requestId,a,s);const u=r.data[0];for(const b in u)!isNaN(u[b])&&Number(u[b])!==1/0&&(u[b]=Number(u[b]));const{labelCn:l,labelEn:h}=await this.parseStatus(u.aisNavStatus),c=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:c.utc().format(),status:u.aisNavStatus,labelEn:h,labelCn:l,method:"position",vendor:"myship"}}async trajectory(t,n,o,i,s=!0,a={}){const r=w(n),u=w(o),l=await this.getShipId(t),h=await this.getShipInfo(l),c=[];for(;u.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(l,r.unix(),r.add(30,"day").unix(),h,t,i,c);return await this.trajectoryIn30Day(l,r.unix(),u.unix(),h,t,i,c),c}async trajectoryIn30Day(t,n,o,i,s,a,r,u={}){var k;const l={headers:{appKey:this.token},json:{shipId:t,startTime:n,endTime:o}},h="https://api3.myships.com/sp/ships/position/history",c=await x.post(h,l).json();if(p==null||p.info("[%s] fetch trajectory from: %s - %j",u.requestId,h,l),c.code!=="0")return p==null||p.warn("[%s] invoke myship trajectory failed: %j",u.requestId,c),c;const I=c.data;for(const g in I)!isNaN(I[g])&&Number(I[g])!==1/0&&(I[g]=Number(I[g]));const b=w.unix((k=I[0])==null?void 0:k.posTime);let T=-1;for(const g of I){const v=w.unix(g.posTime),f={imo:i==null?void 0:i.imo,mmsi:s,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:v.unix(),utc:v.utc().format(),method:"trajectory",vendor:"myship"},d=Math.floor(v.diff(b,"minute",!0)/(a||1));d!==T&&(T=d,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 a,r,u;_==null||_.debug("[%s] parse rule: %s",t.requestId,e);const n=new RegExp("(?<=\\[)(.+)(?=])","g"),o=e.match(n)?(a=e.match(n))==null?void 0:a[0]:void 0,i=o==null?void 0:o.split(";");if(!i)return;const s={};for(let l=0;l<(i==null?void 0:i.length);l++){const h=(u=(r=i[l].match(n))==null?void 0:r[0])==null?void 0:u.split("],");if(l===0&&!h)s.scope=i[0];else if(h)for(let c=0,I=h.length;c<I;c++){const b=this.parseRule(h[c]);b&&(s[b.level]?b.key?s[b.level][b==null?void 0:b.key]=b:s[b.level]=b:b.key?s[b.level]={[b==null?void 0:b.key]:b}:s[b.level]=b)}}return s}parseRule(e,t={}){var s;_==null||_.debug("[%s] parse rule: %s",t.requestId,e),e=e.startsWith("[")?e:`[${e}`,e=e.endsWith("]")?e:`${e}]`;const n=new RegExp("(?<=\\[)(.+?)(?=])","g"),o=(s=e==null?void 0:e.match(n))==null?void 0:s[0],i=o==null?void 0:o.split(",");if(i){let a=i[3]==="Number.MAX_VALUE"?100:Number(i[3]);return a=isNaN(a)?1:a,{operator:i[0],number:Number.isNaN(Number(i[1]))?i[1]:Number(i[1]),level:i[2],time:a,key:i[4]}}}checkWeather(e,t,n={}){var b,T,k,g,v,f,d,m,y,F,M,L,H,N,W;let o=0,i=0,s=0,a=0;const r=Math.round(((T=(b=t==null?void 0:t.SEVERE)==null?void 0:b.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=(v=t==null?void 0:t.HEAVY)==null?void 0:v.sigWave)==null?void 0:f.number,h=Math.round((((m=(d=t==null?void 0:t.SEVERE)==null?void 0:d.wind)==null?void 0:m.number)+2)*100)/100,c=(F=(y=t==null?void 0:t.SEVERE)==null?void 0:y.wind)==null?void 0:F.number,I=(L=(M=t==null?void 0:t.HEAVY)==null?void 0:M.wind)==null?void 0:L.number;for(let B=0;B<(e==null?void 0:e.length);B++){const C=e[B],R=(N=(H=C==null?void 0:C.meteo)==null?void 0:H.wave)==null?void 0:N.sig,q=(W=C==null?void 0:C.meteo)==null?void 0:W.wind,z=B?w(C.eta).diff(w(e[B-1].eta),"hour",!0):0;a=z>a?z:a,_==null||_.debug("[%s] check sig.wave: %j",n.requestId,{...R,dgThd4Wv:r,svThd4Wv:u,hvThd4Wv:l}),(R==null?void 0:R.height)>=r?C.isDangerous=!0:(R==null?void 0:R.height)>=u?C.isSevere=!0:(R==null?void 0:R.height)>=l&&(C.isHeavy=!0),_==null||_.debug("[%s] check wind: %j",n.requestId,{...q,dgThd4Wd:h,svThd4Wd:c,hvThd4Wd:I}),(q==null?void 0:q.scale)>=h?(C.isDangerous=!0,delete C.isSevere,delete C.isHeavy):(q==null?void 0:q.scale)>c?(C.isDangerous||(C.isSevere=!0),delete C.isHeavy):(q==null?void 0:q.scale)===I&&!C.isDangerous&&!C.isSevere&&(C.isHeavy=!0),o+=C.isDangerous?z:0,i+=C.isSevere?z:0,s+=C.isHeavy?z:0}return o=Math.round(o*100)/100,i=Math.round(i*100)/100,s=Math.round(s*100)/100,a=Math.round(a),{sample:e,dangerous:o,severe:i,heavy:s,step:a<3?3:a,wind:{dgThd4Wd:h,svThd4Wd:c,hvThd4Wd:I},sig:{dgThd4Wv:r,svThd4Wv:u,hvThd4Wv:l}}}}const wt=new ht;let S;try{S=K.getLogger("vessel")}catch{}finally{}const It=new Mt.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,n,o){let i=Math.round(e/(t*n*o)*100)/100;i=i<.55?.55:i>.85?.85:i;const s=[.55,.6,.65,.7,.75,.8,.85],a=s.map(r=>Math.abs(r-i));return s[a.indexOf(Math.min(...a))]}static froudeNumber(e,t,n=9.8){let o=Math.round(Math.sqrt(e*e/(n*t))*100)/100;return o=o<.05?.05:o>.3?.3:o,o}static amendFactor(e,t,n){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 s={.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 n==="Laden"&&(s=o[e]),s[0]+s[1]*t+s[2]*Math.pow(t,2)}static directionFactor(e,t=0){let n;return e>30&&e<=60?n=(1.7-.03*Math.pow(t-4,2))/2:e>60&&e<=150?n=(.9-.06*Math.pow(t-6,2))/2:e>150&&e<=180?n=(.4-.03*Math.pow(t-8,2))/2:n=1,Math.round(n*1e5)/1e5}static vesselTagFactor(e,t,n,o){let i;return n==="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,n=10,o={}){e=e<3?e*.7:e,e=e<0?.2:e,e=e>6?e-.9*(e-6):e,e=e>9?9:e;const i=Math.max(n>10?n-10:2.8);let s;return t>30&&t<=60?s=-.6:t>60&&t<=90?s=-.5:t>90&&t<=120?s=e<i?.2:-.3:t>120&&t<=150?s=e<i?.25:-.2:t>150&&t<=180?s=e<i?.3:-.1:s=-.7,S==null||S.info("[%s] calculate wave height factor with ht(%d), beta(%d), draught(%d) and factor(%d)",o.requestId,e,t,n,s),Math.round(s*(.144*Math.pow(e,2)+.378*e)*1e4)/1e4}static assembleProperties(e,t,n,o){var c;const i=e.lbp??e.length??e.lengthOverall??198.9642,s=e.draught??8,a=e.breadthMoulded??e.breadth??e.breadthExtreme??32.4572,r=e.deadweight??67035.7773,u=((c=e==null?void 0:e.type)==null?void 0:c.toLowerCase())||"common";return{tag:u.indexOf("container")>-1?"container":u.indexOf("tugs")>-1?"tugs":"common",lbp:i,loadCondition:t,draught:s,breadthMoulded:a,displacement:Math.round((r/1.025+s*a*i*.7)*1e4)/1e4,speed:Math.round((n??14.1382)*1852/3600*1e4)/1e4,bearing:o||90}}static async speedLoseAt(e,t,n,o="",i=2,s=!0,a=!1,r={}){let u;if(t.velocity&&a&&(e.speed=E.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),s){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),v=n.utc().format(),f=await It.spotForecast(t.lat,t.lng,v,!1,!1,!0,{...r,pastDays:1,forecastDays:2,weatherModels:k,marineModels:g}),[d]=it.Meteo2Assist.pickHourly(f,v);l=it.Meteo2Assist.toLegacy(d)}catch(k){S.warn("[%s] meteo2 spot(%j) forecast failed: %s",r.requestId,{...t,eta:n.utc().format(),source:o},k)}let h=O.currentFactor(e.bearing,l==null?void 0:l.current,i,r),c=O.weatherFactor(e,l,h,r);const I=e.speed*1.943844;I+h+c<=0&&(S.warn("[%s] v0(%d) is less then factor(%d) = wxFactor(%d) + cFactor(%d), scale factor with 0.6",r.requestId,I,c+h,c,h),h=Math.round(h*.6*1e3)/1e3,c=Math.round(c*.6*1e3)/1e3);const b=c<=(r.minV0Factor||-1)?Math.max(r.maxV0Factor||-2.5,-1*c*(c/1.2)):0;S==null||S.info("[%s] calculate speed lose with v0Factor(%d), cFactor(%d) and wxFactor(%d)",r.requestId,b,h,c),c+=b;let T=Math.round((I+h+c)*100)/100;T=T<=0?1:T,u={meteo:{...l},wxFactor:c,v0Factor:b,cFactor:h,speed:t.velocity&&a?t.velocity:T,eta:n.utc().format(),etd:n.utc().format()}}else u={wxFactor:0,v0Factor:0,cFactor:0,speed:t.velocity&&a?t.velocity:Math.round(e.speed*1.943844*100)/100,eta:n.utc().format(),etd:n.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,n,o,i,s,a="",r=!0,u=!1,l={}){t.utc();const h=t.clone().add(14,"days"),c=[],I=[],b=[];let T=0,k=0,g,v;for(let f=0;f<s.length-1;f++){let d=s[f];d.distanceFromStart=Math.round((i+k)*1e3)/1e3;const m=s[f+1];if(e.bearing=E.LaneHelper.calculateBearing(d,m,!m.gcToPrevious),d.bearing=e.bearing,d.suspend&&u){d.eta=d.eta||t.utc().format(),d.elapsed=d.elapsed??0;const M=d.suspend-d.elapsed;if(o-T>M)o=o-T-M,t.add(M,"hour"),d.elapsed=d.suspend;else{const L=o-T;d.elapsed+=L,t.add(L,"hour"),o=0}if(S==null||S.info(`[%s] suspend ${d.elapsed} hours at %j, and remain ${o} hours need to go...`,l.requestId,d),o===0)return d.distanceFromPrevious=k,{etd:t,from:v||d,to:d,next:s.filter(L=>L),wps:c,days:I,all:b}}else d.suspend=0;r=t.isAfter(h)?!1:r,d=await O.speedLoseAt(e,d,t,a,0,r,u,l),b.push(d),v=v||d,d.important&&c.push(d),t.isSameOrAfter(n)&&(I.push(d),n.add(24,"hour"));const y=E.LaneHelper.calculateDistance(d,m,!m.gcToPrevious);let F=Math.round(y/v.speed*1e5)/1e5;if(T+F<o){if(T+=F,t.add(F,"hour"),delete s[f],S==null||S.debug(`[%s] go to %j from %j with ${y}nm, and cost ${F} hours`,l.requestId,{lat:m.lat,lng:m.lng},{lat:v.lat,lng:v.lng,etd:v.etd}),k+=y,s.filter(M=>M).length<=1){g=m,g.eta=t.utc().format(),g.distanceFromPrevious=y,g.distanceFromStart=Math.round((i+k)*1e4)/1e4,c.push(g),b.push(g),delete s[f+1];break}}else{F=o-T,t.add(F,"hour");const M=E.LngLatHelper.roundPrecision(v.speed*F,5);g=E.LaneHelper.calculateCoordinate(d,e.bearing,M,"nauticalmiles",!m.gcToPrevious),g.eta=t.utc().format(),s[f]=g,S==null||S.debug(`[%s] go to %j from %j with ${M}nm, and cost ${F} hours`,l.requestId,{lat:g.lat,lng:g.lng},{lat:d.lat,lng:d.lng,etd:d.etd}),k+=M,g.distanceFromPrevious=Math.round(k*1e4)/1e4,g.distanceFromStart=Math.round((i+k)*1e4)/1e4;break}}return{etd:t,from:v,to:g,next:s.filter(f=>f),wps:c,days:I,all:b}}static currentFactor(e,t,n=0,o={}){const i=E.LaneHelper.includedAngle(e,(t==null?void 0:t.degree)||0)/180*Math.PI;let s;return Math.abs(i)===Math.PI/2&&(s=0),s=((t==null?void 0:t.kts)||0)*Math.cos(i),n&2?s=Math.ceil(s*100)/100:n&1?s=Math.floor(s*100)/100:s=Math.round(s*100)/100,S==null||S.info("[%s] calculate current factor with %j",o.requestId,{beta:i,current:t,factor:s,role:n}),Math.abs(s)>5?0:s}static weatherFactor(e,t,n=0,o={}){var b,T,k,g,v,f,d;S==null||S.info("[%s] calculate weather factor via: %j",o.requestId,{...e,...t});const i=O.blockCoefficient(e.displacement,e.lbp,e.breadthMoulded,e.draught),s=E.LngLatHelper.roundPrecision(n*1852/3600,6),a=O.froudeNumber(e.speed-s,e.lbp),r=O.amendFactor(i,a,e.loadCondition);let u=E.LaneHelper.includedAngle(e.bearing,(b=t==null?void 0:t.wind)==null?void 0:b.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)||10);let c=l*r*h/100*(e.speed-s);c=Math.round(c*1.943844*1e4)/1e4*-1,e.tag==="tugs"&&Math.abs(c)>1&&(c=c/(Math.abs(Math.round(c))+1)),S==null||S.info("[%s] calculate wind wx factor: %d",o.requestId,c),u=E.LaneHelper.includedAngle(e.bearing,(v=(g=t==null?void 0:t.wave)==null?void 0:g.sig)==null?void 0:v.degree);const I=O.waveHeightFactor(((d=(f=t==null?void 0:t.wave)==null?void 0:f.sig)==null?void 0:d.height)??1,u,e.draught,o);return S==null||S.info("[%s] calculate wave wx factor: %d",o.requestId,I),c=Math.abs(c)>Math.abs(I)?c:.7*c+.9*I,S==null||S.info("[%s] calculate finial weather factor: %d (0.7 * wf) + (0.9 * hf)",o.requestId,c),c=Math.abs(c)>4?4*(Math.abs(c)/c)+Math.abs(c)/c*(Math.abs(c)-2)*.1:c,Math.round((c||0)*100)/100}static async reduceDays(e,t=12*60*60){return e=e==null?void 0:e.reduce((n,o)=>(o.positionTime||(o.positionTime=w.utc(o.etd||o.eta).unix()),n.some(i=>Math.floor(i.positionTime/t)===Math.floor(o.positionTime/t))||n.push(o),n),[]),e}static async reduceWPS(e,t=60){return e=e==null?void 0:e.reduce((n,o)=>(n.some(i=>Math.floor(w(i.etd).unix()/t)===Math.floor(w(o.etd).unix()/t))||n.push(o),n),[]),e}static async analyseInstant(e,t,n,o,i,s="",a=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:c,waypoints:I}=i.points,b=E.LaneHelper.calculateSubRoute(e,c);if(((X=b[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(n,o.loadCondition,T,0),v=I.length?E.LaneHelper.calculateSubWaypoints(e,I):[];v.forEach(D=>D.important=!0);const f={from:{...e},route:b,waypoints:v,v0:T,label:k},d={hours:[],days:[],wps:[],all:[]};a||(E.LaneHelper.calculateRouteDistance(b)/o.speed<=72?a=3:a=6);let m=E.LaneHelper.simplifyRouteToCoordinates(b,v,0),y=0,F=0,M=0,L=0;t=w(t).utc();const H=t.clone();for(;m.length>0;){const D=a-t.hour()%a,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,s,r,u,l);if(d.all.push(...j.all),(Q=j.from)!=null&&Q.speed&&(d.hours.push(j.from),d.wps.push(...j.wps),d.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),s,0,r,u,l);V.bearing=g.bearing,d.hours.push(V),d.all.push(V)}y+=Math.round((((Z=j==null?void 0:j.to)==null?void 0:Z.distanceFromPrevious)??0)*1e4)/1e4}const N=d.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,M+=(N[D].cFactor||0)*J,L+=J}const W=N.reduce((D,J)=>D+(J.suspend||0),0);($=d.wps)==null||$.forEach((D,J)=>{D.positionTime=w.utc(D.etd||D.eta).unix();const j=d.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}}),d.wps=await O.reduceWPS(d.wps),d.days=await O.reduceDays(d.days),d.all=(tt=d.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=d;const B=d.hours.at(0),C=d.hours.at(-1);f.distance=Math.round(C.distanceFromStart*1e3)/1e3,f.etd=w(B.eta).utc().format(),f.eta=w(C.eta).utc().format(),f.wxFactor=Math.round(F/L*1e3)/1e3,f.cFactor=Math.round(M/L*1e3)/1e3,f.avgSpeed=Math.round(C.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:at}=await this.calculateECA(f,o,l),st=E.LngLatHelper.roundPrecision(o.fo/24*(L-z),3),ct=E.LngLatHelper.roundPrecision(o.dgo/24*L+R,3);f.extend={eca:at,distanceInECA:q,hoursInECA:z,totalDgoConsInECA:rt,totalDgoConsInSuspend:R},f.totalFoCons=st<0?0:st,f.totalDgoCons=ct;const nt=w().valueOf()-h,ut=((et=d==null?void 0:d.hours)==null?void 0:et.length)||1;return S==null||S.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,n,o,i,s,a,r="",u=3,l=!0,h=!1,c={}){var Z,$,tt,et,D,J;const I=w().valueOf();e.lng=E.LngLatHelper.convertToStdLng(e.lng);const{v0:b,label:T}=e.sog?{v0:e.sog,label:e.label||"Other"}:{v0:i.speed,label:"CP"},k=O.assembleProperties(o,i.loadCondition,b,0),g=E.LaneHelper.calculateSubRoute(e,s);if(((Z=g[0])==null?void 0:Z.length)<=1)return;const v=a.length?E.LaneHelper.calculateSubWaypoints(e,a):[];v.forEach(j=>j.important=!0);let f=E.LaneHelper.simplifyRouteToCoordinates(g,v,0),d=0,m=0,y=0,F=0;const M={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(n)?n.diff(t,"h",!0)*1e4/1e4:V;const Y=await O.speedLoseInHoursStep(k,t,L,V,d,f,r,l,h,c);if(M.all.push(...Y.all),($=Y.from)!=null&&$.speed&&(M.hours.push(Y.from),Y!=null&&Y.wps&&M.wps.push(...Y.wps),M.days.push(...Y.days)),f=Y==null?void 0:Y.next,f.length||M.hours.push(Y==null?void 0:Y.to),d+=Math.round((((tt=Y==null?void 0:Y.to)==null?void 0:tt.distanceFromPrevious)??0)*1e4)/1e4,!V)break}M.wps=await O.reduceWPS(M.wps),M.days=await O.reduceDays(M.days),M.all=(et=M.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=M.wps)==null||D.forEach((j,V)=>{const Y=M.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=M.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=M.hours.at(0),B=M.hours.at(-1),C=await E.LaneHelper.calculateRangeRoute(W,B,g),R=await E.LaneHelper.calculateRangeWaypoints(W,B,g,v),q={sample:M,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:C,waypoints:R,v0:b,label:T},z=E.LngLatHelper.roundPrecision(i.dgo/24*N,3),{distanceInECA:rt,hoursInECA:at,totalDgoConsInECA:st,eca:ct}=await this.calculateECA(q,i,c),dt=E.LngLatHelper.roundPrecision(i.fo/24*(F-at),3),nt=E.LngLatHelper.roundPrecision(i.dgo/24*F+z,3);q.extend={eca:ct,distanceInECA:rt,hoursInECA:at,totalDgoConsInECA:st,totalDgoConsInSuspend:z},q.totalDgoCons=nt,q.totalFoCons=dt<0?0:dt;const X=w().valueOf()-I,Q=((J=M==null?void 0:M.hours)==null?void 0:J.length)||1;return S==null||S.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",c==null?void 0:c.requestId,X,Q,Math.round(X/Q*1e3)/1e3),q}static async analyseCost(e,t,n,o,i={}){var g,v;const s=w().valueOf(),a=[];e.speedStep=e.speedStep||3,e.alterStep=e.alterStep??1;const r=E.LaneHelper.calculateRouteDistance(o.route);let u=0;n.forEach(f=>{const d=Math.ceil(r/f.speed/24);u=u<d?d:u}),u=u*1.3;const l=w.utc(e.etd).add(u??14,"day");let h=1;for(const f of n){const d=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,d,m,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,i);y&&(await O.calculateCost(y,f,e,i),a.push(y),S==null||S.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++}a.sort((f,d)=>f.cost.total-d.cost.total);const c=a.at(0),I=a.at(1),b=[];if(b.push({combined:!1,speeds:[c],cost:(g=c.cost)==null?void 0:g.total}),I){const f=c.cost.cp,d=I.cost.cp,m=w(c.eta),y=w(c.etd),F=m.diff(y,"days",!0);let M=Math.ceil(F/2);M=M>7?7:M<e.alterStep?e.alterStep:M;let L=2,H={combined:!1,speeds:[I],cost:(v=I.cost)==null?void 0:v.total},N;for(;M>=e.alterStep;){const W=await O.combinedAnalyse(e,t,l,[f,d],o,M,{...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),M<=e.alterStep)break;M=Math.ceil(M/2),L+=1}b.push(H),N&&b.push(N)}const k=w().valueOf()-s;return S==null||S.info("[%s] analyse elapsed: %d ms",i==null?void 0:i.requestId,k),b.sort((f,d)=>f.cost-d.cost)}static async combinedAnalyse(e,t,n,o,i,s,a={}){a.counter=1,S==null||S.info("[%s][L%d] analyse with alternate cp in every %d days",a.requestId,a.level,s);const r=await O.alternateAnalyse(e,t,n,o,0,i,s,a),u=r.reduce((d,m)=>d+m.cost.total,0),l=r.reduce((d,m)=>d+m.cost.hire,0),h=r.reduce((d,m)=>d+m.cost.bunker,0),c=r.reduce((d,m)=>d+m.distance,0),I=r.reduce((d,m)=>d+m.totalHrs,0);S==null||S.info("[%s][L%d] cost with cpa/cpb turn: %j",a.requestId,a.level,{cost:u,hire:l,bunker:h,distance:c,hours:I});const b=await O.alternateAnalyse(e,t,n,o,1,i,s,a),T=b.reduce((d,m)=>d+m.cost.total,0),k=b.reduce((d,m)=>d+m.cost.hire,0),g=b.reduce((d,m)=>d+m.cost.bunker,0),v=b.reduce((d,m)=>d+m.distance,0),f=b.reduce((d,m)=>d+m.totalHrs,0);return S==null||S.info("[%s][L%d] cost with cpb/cpa turn: %j",a.requestId,a.level,{cost:T,hire:k,bunker:g,distance:v,hours:f}),u<T?{combined:!0,cost:Math.round(u*1e3)/1e3,speeds:r,step:s}:{combined:!0,cost:Math.round(T*1e3)/1e3,speeds:b,step:s}}static async alternateAnalyse(e,t,n,o,i,s,a,r={}){var c,I;let u=w.utc(e.etd);const l={lat:e.lat,lng:e.lng},h=[];for(;u.isBefore(n);){const b=u.clone().utc().add(a,"day"),T=JSON.parse(JSON.stringify(s.route)),k=JSON.parse(JSON.stringify(s.waypoints)),g=o[i],v=await O.analyseInstantWithThreshed(l,u.utc().format(),b,t,g,T,k,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,r);v&&(await O.calculateCost(v,g,e,r),S==null||S.info("[%s][L%d-%d] analyse from %s to %s cost: %j",r.requestId,r.level,r.counter,u.utc().format(),b.utc().format(),{cost:v.cost.total,hire:v.cost.hire,bunker:v.cost.bunker,distance:v.distance,hours:v.totalHrs,cp:`${g.speed}/${g.fo}/${g.dgo}`})),r.counter=r.counter+1;const f=(I=(c=v==null?void 0:v.sample)==null?void 0:c.hours)==null?void 0:I.at(-1);if(f)l.lat=f.lat,l.lng=f.lng,u=w(f.eta),h.push(v),i=i?0:1;else break}return h}static async calculateCost(e,t,n,o={}){var i;if(e){const s=(n.addComm||0)>=1?(n.addComm||0)/100:n.addComm||0,a=Math.round((n.dailyHire||0)*(e.suspend||0)/24*1e3)/1e3,r=Math.round(e.totalHrs/24*(n.dailyHire||0)*(1-s)*1e3)/1e3+a,u=Math.round(e.totalFoCons*(n.priceFO||0)*1e3)/1e3,l=Math.round((e.totalDgoCons+(((i=e.extend)==null?void 0:i.totalDgoConsInECA)||0))*(n.priceDGO||0)*1e3)/1e3;e.cost={total:Math.round((r+u+l)*1e3)/1e3,hire:Math.round(r*1e3)/1e3,suspendHire:a,bunker:Math.round((u+l)*1e3)/1e3,cp:t}}return e}static async calculateECA(e,t,n={}){var r,u,l,h;const o=await E.LaneHelper.intersectInECA((e==null?void 0:e.route)||[]);let i=0,s=0,a=0;(u=(r=e==null?void 0:e.sample)==null?void 0:r.wps)==null||u.forEach(c=>{c.positionTime=w.utc(c.etd||c.eta).unix()});for(const c of o){i+=c.distance;const I=await E.LaneHelper.deadReckoningTime((l=c.waypoints)==null?void 0:l.at(0),e.sample.all||e.sample.wps),b=await E.LaneHelper.deadReckoningTime((h=c.waypoints)==null?void 0:h.at(-1),e.sample.all||e.sample.wps);c.in=I,c.out=b,c.totalHrs=E.LngLatHelper.roundPrecision((b.positionTime-I.positionTime)/3600,3),c.totalDgoCons=E.LngLatHelper.roundPrecision(t.fo/24*c.totalHrs,3),s+=c.totalHrs,a+=c.totalDgoCons}return i=E.LngLatHelper.roundPrecision(i,3),s=E.LngLatHelper.roundPrecision(s,3),a=E.LngLatHelper.roundPrecision(a,3),{distanceInECA:i,hoursInECA:s,totalDgoConsInECA:a,eca:o}}static async mergeSpeeds(e,t={}){var f,d;const n={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),s=e.reduce((m,y)=>m+y.totalHrs,0),a=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/s,0),l=e.reduce((m,y)=>m+y.cFactor*y.totalHrs/s,0),h=e.reduce((m,y)=>m+y.totalFoCons,0),c=e.reduce((m,y)=>m+y.totalDgoCons,0),I=e.reduce((m,y)=>m+y.cost.total,0),b=e.reduce((m,y)=>m+y.cost.hire,0),T=e.reduce((m,y)=>m+y.cost.bunker,0),k=[],g=[];let v;for(const m of e){g.push(...((f=m.extend)==null?void 0:f.eca)||[]);const y=m.sample.hours,F=m.sample.all,M=m.sample.wps,L=m.sample.days,H=y.at(0);v&&(H.distanceFromPrevious=v.distanceFromPrevious,H.distanceFromStart=v.distanceFromStart,y.forEach((C,R)=>{R&&(C.distanceFromStart=C.distanceFromStart+v.distanceFromStart)}),F.at(0).distanceFromPrevious=v.distanceFromPrevious,F.at(0).distanceFromStart=v.distanceFromStart,F.forEach((C,R)=>{R&&(C.distanceFromStart=C.distanceFromStart+v.distanceFromStart)}),M.at(0).distanceFromPrevious=v.distanceFromPrevious,M.at(0).distanceFromStart=v.distanceFromStart,M.forEach((C,R)=>{R&&(C.distanceFromStart=C.distanceFromStart+v.distanceFromStart)}),L.at(0).distanceFromPrevious=v.distanceFromPrevious,L.at(0).distanceFromStart=v.distanceFromStart,L.forEach((C,R)=>{R&&(C.distanceFromStart=C.distanceFromStart+v.distanceFromStart)})),H.cp=m.cost.cp;const N=[m.etd,m.eta],W=k.findIndex(C=>C.id===H.cp.id);W===-1?(H.cp.segment=[N],k.push(H.cp)):k[W].segment.push(N),y.forEach(C=>{var q;((q=n.hours)==null?void 0:q.findIndex(z=>z.eta===C.eta))===-1&&n.hours.push(C)}),F.forEach(C=>{var q;((q=n.all)==null?void 0:q.findIndex(z=>z.eta===C.eta))===-1&&n.all.push(C)}),M.forEach(C=>{var q;((q=n.wps)==null?void 0:q.findIndex(z=>z.eta===C.eta))===-1&&n.wps.push(C)}),L.forEach(C=>{var q;((q=n==null?void 0:n.days)==null?void 0:q.findIndex(z=>z.eta===C.eta))===-1&&n.days.push(C)});const B=(d=n.wps)==null?void 0:d.findIndex(C=>C.eta===H.eta);B===-1?n.wps.push(H):n.wps[B]=H,v=y.at(-1)}return n.wps.sort((m,y)=>w(m.etd).unix()-w(y.etd).unix()),n.wps.forEach((m,y)=>{const F=n.wps[y-1];if(F){const M=m.distanceFromStart-(F.distanceFromStart||0),L=w(m.eta||m.etd).diff(w(F.etd||F.eta),"hour",!0),H=Math.round(M/L*100)/100;m.avgSpd=H;const N=E.LaneHelper.calculateBearing(F,m);F.bearing=N}}),{sample:n,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(s*1e3)/1e3,avgSpeed:Math.round(o/s*1e3)/1e3,wxFactor:Math.round(u*1e3)/1e3,cFactor:Math.round(l*1e3)/1e3,totalFoCons:Math.round(h*1e3)/1e3,totalDgoCons:Math.round(c*1e3)/1e3,cost:{total:Math.round(I*1e3)/1e3,hire:Math.round(b*1e3)/1e3,bunker:Math.round(T*1e3)/1e3},extend:{cps:k,eca:g,distanceInECA:Math.round(i*1e3)/1e3,hoursInECA:Math.round(a*1e3)/1e3,totalDgoConsInECA:Math.round(r*1e3)/1e3,speeds:e}}}}P.AISImpl=G,P.AlertHelper=ht,P.AlertLevel=lt,P.HifleetImpl=bt,P.LoadCondition=mt,P.MyShipImpl=gt,P.MyVesselImpl=pt,P.ShipxyImpl=vt,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,Mt,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 p;try{p=K.getLogger("vessel")}catch{}finally{}class G{parseStatus(e){let t,n;switch(e){case 0:t="在航(主机推动)",n="Underway Using Engine";break;case 1:t="锚泊",n="Anchored";break;case 2:t="失控",n="Not under command";break;case 3:t="操纵受限",n="Limited airworthiness";break;case 4:t="吃水受限",n="Limited by ship's draft";break;case 5:t="靠泊",n="Mooring";break;case 6:t="搁浅",n="Stranded";break;case 7:t="捕捞作业",n="Engaged in fishing";break;case 8:t="靠帆船提供动力",n="Sailing";break;default:t="未定义",n="Undefined"}return{labelCn:t,labelEn:n}}}class pt extends G{constructor(t,n){super();U(this,"clientId");U(this,"clientSecret");U(this,"token");this.clientId=t,this.clientSecret=n}async authToken(t={}){const n="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(n,o).json();p==null||p.info("[%s] fetch access token from: %s - %j",t.requestId,n,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 n;return(!this.token||w().diff(w(this.token.issuedAt),"seconds")>(((n=this.token)==null?void 0:n.expiresIn)||0)-300)&&await this.authToken(t),this.token}async suggest(t,n={}){var a,r;await this.checkToken(n);const o="https://market.myvessel.cn/sdc/v1/mkt/vessels/fuzzy",i={headers:{Authorization:`${(a=this.token)==null?void 0:a.tokenType} ${(r=this.token)==null?void 0:r.accessToken}`},json:{kw:t,recordNum:n.ps||10}};p==null||p.info("[%s] fetch suggest vessels from: %s - %j",n.requestId,o,i);const s=await x.post(o,i).json();return s.status!==200?(p==null||p.warn("[%s] fetch suggest vessels failed: %j",n.requestId,{message:s.message,status:s.status,code:s.code}),[]):(s.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,n={}){var u,l;await this.checkToken(n);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",s=o?{imo:t}:{mmsi:t},a={headers:{Authorization:`${(u=this.token)==null?void 0:u.tokenType} ${(l=this.token)==null?void 0:l.accessToken}`},searchParams:s};p==null||p.info("[%s] fetch vessel from: %s - %j",n.requestId,i,a);const r=await x.get(i,a).json();if(r.status!==200)return p==null||p.warn("[%s] fetch suggest vessels failed: %j",n.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,n={}){var a,r;await this.checkToken(n);const o="https://svc.data.myvessel.cn/sdc/v1/ship/info/batch",i={headers:{Authorization:`${(a=this.token)==null?void 0:a.tokenType} ${(r=this.token)==null?void 0:r.accessToken}`},json:{mmsiList:typeof t=="number"?[t]:t}};p==null||p.info("[%s] fetch vessel archive from: %s - %j",n.requestId,o,i);const s=await x.post(o,i).json();return s.status!==200?(p==null||p.warn("[%s] fetch vessel archive failed: %j",n.requestId,{message:s.message,status:s.status,code:s.code}),{}):s.data}async realTimePosition(t,n={}){var r,u;await this.checkToken(n);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}};p==null||p.info("[%s] fetch realtime position from: %s - %j",n.requestId,o,i);const s=await x.get(o,i).json();if(s.code)return p==null||p.warn("[%s] fetch realtime position failed: %j",n.requestId,{message:s.message,status:s.status,code:s.code}),s;const a=s.data;for(const l in a)!isNaN(a[l])&&Number(a[l])!==1/0&&(a[l]=Number(a[l]));if(a){const l=w(`${a.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:a.mmsi,name:a.vesselName||a.aisVesselName,imo:a.imo,callSign:a.callsign||a.aisCallSign,lat:a.lat,lng:a.lon,length:a.length,width:a.width,draught:a.currDraught,sog:a.sog,cog:a.cog,hdg:a.hdg,rot:a.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(a.eta)?w.utc(a.eta).format():void 0,destination:a.dest,positionTime:l.unix(),status:a.status,labelCn:a.statusNameCn,labelEn:a.statusNameEn,vesselType:a.vesselTypeNameEn,flag:a.flagCtryNameEn,clasz:a.classSociety,build:a.buildYear,dwt:a.dwt,grt:a.grt,net:a.net,method:"position",vendor:"myVessel",utc:l.utc().format()}}else return{}}async calculateRoute(t,n,o,i,s,a={}){var I,b,T;const r=w();await this.checkToken(a);const u="https://market.myvessel.cn/sdc/v1/mkt/routes/plan",l={maxDraught:a.draught||10,useAIModel:a.useAIModel??!0,withECA:a.withECA||!1,withSpecialRegion:a.withSpecial||!1};t.code&&(l.startPortCode=t.code),t.lng!==void 0&&t.lat!==void 0&&(l.startPoint={lon:t.lng,lat:t.lat}),n.code&&(l.endPortCode=n.code),n.lng!==void 0&&n.lat!==void 0&&(l.endPoint={lon:n.lng,lat:n.lat}),o!=null&&o.length&&(l.crossMonthList=o),i!=null&&i.length&&(l.excludeNodes=i),s!=null&&s.length&&(l.excludeSeaAreas=s);const h={headers:{Authorization:`${(I=this.token)==null?void 0:I.tokenType} ${(b=this.token)==null?void 0:b.accessToken}`},json:l};p==null||p.info("[%s] fetch route from: %s - %j",a.requestId,u,h);const c=await x.post(u,h).json();if(c.status!==200)return p==null||p.warn("[%s] fetch route failed: %j",a.requestId,{message:c.message,status:c.status,code:c.code}),{};{const k={status:"Success",nodes:[],seas:[],regions:[],waypoints:[],route:[],distance:0,memo:""},{nodes:g,seas:v,tracks:f,specialRegions:d,ecaLength:m}=c.data;k.nodes=g==null?void 0:g.map(M=>({code:M.nodeCode,nameEn:M.nameEn,nameCn:M.nameCn,center:{lat:Math.round(M.lat*1e6)/1e6,lng:Math.round(M.lon*1e6)/1e6},start:{lat:Math.round(M.startLat*1e6)/1e6,lng:Math.round(M.startLon*1e6)/1e6},end:{lat:Math.round(M.endLat*1e6)/1e6,lng:Math.round(M.endLat*1e6)/1e6},isKey:M.isKeyNode,isHub:M.isHubNode})),k.seas=v==null?void 0:v.map(M=>({code:M.mrgidSea,nameEn:M.nameEn,nameCn:M.nameCn,center:{lat:Math.round(M.centerLat*1e6)/1e6,lng:Math.round(M.centerLon*1e6)/1e6},min:{lat:Math.round(M.minLat*1e6)/1e6,lng:Math.round(M.minLon*1e6)/1e6},max:{lat:Math.round(M.maxLat*1e6)/1e6,lng:Math.round(M.maxLon*1e6)/1e6},level:M.mapLevel})),d==null||d.map(M=>{M.regionLength&&k.regions.push({type:M.regionType,distance:M.regionLength,rows:M.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(M=>({lat:Math.round(M.lat*1e5)/1e5,lng:Math.round(M.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`,p.info("[%s] calculate route cost: %d seconds",a.requestId,F),k}}async trajectory(t,n,o,i,s=!0,a={}){await this.checkToken(a);const r=await this.realTimePosition(t,a),u=w(n),l=w(o),h=[];for(;l.diff(u,"day",!0)>30;)await this.trajectoryIn30Day(t,u,u.clone().add(30,"day"),r,i,h,a),u.add(30,"day");return await this.trajectoryIn30Day(t,u,l,r,i,h,a),h}async trajectoryIn30Day(t,n,o,i,s,a,r={}){var b,T,k,g,v;const u="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",l={headers:{Authorization:`${(b=this.token)==null?void 0:b.tokenType} ${(T=this.token)==null?void 0:T.accessToken}`},json:{mmsi:t,startTime:n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:o.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};p==null||p.info("[%s] fetch trajectory from: %s - %j",r.requestId,u,l);const h=await x.post(u,l).json();if(h.code)return p==null||p.warn("[%s] fetch trajectory failed: %j",r.requestId,u,{message:h.message,status:h.status,code:h.code}),h;let c=-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(v=h.data)==null||v.forEach(f=>{for(const H in f)!isNaN(f[H])&&Number(f[H])!==1/0&&(f[H]=Number(f[H]));const d=w(`${f.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),m=f.status,{labelCn:y,labelEn:F}=this.parseStatus(m),M={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:d.unix(),labelCn:y,labelEn:F,method:"trajectory",vendor:"myVessel",utc:d.utc().format()},L=Math.floor(d.diff(I,"minute",!0)/(s||1));L!==c&&(c=L,a.push(M))}),a}}class bt extends G{constructor(t){super();U(this,"token");this.token=t}async realTimePosition(t,n={}){const o="https://api.hifleet.com/position/position/get/token",i={searchParams:{mmsi:t,usertoken:this.token}},s=await x.post(o,i).json();p==null||p.info("[%s] fetch realtime position from: %s - %j",n.requestId,o,i);const a=s==null?void 0:s.list;if(!a)return p==null||p.warn("[%s] fetch realtime position failed: %j",n.requestId,o,s),s;for(const I in a)!isNaN(a[I])&&Number(a[I])!==1/0&&(a[I]=Number(a[I]));a.status=a.sp>3?0:1;const r=a.status,{labelCn:u,labelEn:l}=this.parseStatus(r),h=w(`${a.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:a.m,name:a.n,imo:a.imonumber,callSign:a.callsign,lat:Math.round(a.la/60*1e5)/1e5,lng:Math.round(a.lo/60*1e5)/1e5,length:a.l,width:a.w,draught:a.draught,sog:a.sp,cog:a.co,hdg:a.h,rot:isNaN(a.rot)?0:a.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(a.eta)?w.utc(a.eta).format():void 0,destination:a.destination,vesselType:a.type,dwt:a.dwt,build:a.buildyear,flag:a.fn,positionTime:h.unix(),utc:h.utc().format(),status:r,labelCn:u,labelEn:l,method:"position",vendor:"hifleet"}}async search(t,n={}){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 s=await x.post(o,i).json();p==null||p.info("[%s] fetch vessel props from: %s - %j",n.requestId,o,i),s instanceof Array&&(s=s[0]);for(const r in s)!isNaN(s[r])&&Number(s[r])!==1/0&&(s[r]=Number(s[r]));const a={mmsi:s.m,name:s.n,imo:s.i,callSign:s.c,length:s.l,breadth:s.b,draught:s.dr,type:s.t};return o="https://www.hifleet.com/hifleetapi/sameShipSearch.do",s=await x.post(o,i).json(),p==null||p.info("[%s] search vessel dead weight from: %s - %j",n.requestId,o,i),s instanceof Array&&(s=s[0]),s&&(a.deadweight=Number(s.dwt)),a}async suggest(t,n={}){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"}},s=await x.post(o,i).json();p==null||p.info("[%s] suggest vessel props from: %s - %j",n.requestId,o,i);const a=[];for(const r of s)a.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 a.sort((r,u)=>u.score-r.score),a}async trajectory(t,n,o,i,s=!0,a={}){var f,d,m;const r=await this.realTimePosition(t,a);let u=w(n);const l=w(o),h=w();if(s){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 c={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",b=await x.get(I,c).json();p==null||p.info("[%s] fetch trajectory from: %s - %j",a.requestId,I,c);let T;b&&(T=((d=(f=b.ships)==null?void 0:f.offors)==null?void 0:d.ship)||[],T.length||p==null||p.warn("[%s] fetch trajectory failed: %j",a.requestId,b));const k=[];let g=-1;const v=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:M,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:M,method:"trajectory",vendor:"hifleet"},N=Math.floor(F.diff(v,"minute",!0)/(i||1));N!==g&&(g=N,k.push(H))}return k}}class vt extends G{constructor(t){super();U(this,"token");this.token=t}async realTimePosition(t,n={}){const o={searchParams:{id:t,k:this.token,enc:1}},i="https://api.shipxy.com/apicall/GetSingleShip",s=await x.get(i,o).json();if(p==null||p.info("[%s] fetch realtime position from: %s - %j",n.requestId,i,o),(s==null?void 0:s.status)!==0)return s;const a=s.data[0];for(const c in a)!isNaN(a[c])&&Number(a[c])!==1/0&&(a[c]=Number(a[c]));const{labelCn:r,labelEn:u}=await this.parseStatus(a.navistat),l=w.unix(a.lasttime);return{mmsi:a.ShipID,name:a.name,imo:a.imo,callSign:a.callsign,lat:Math.round(a.lat/1e6*1e5)/1e5,lng:Math.round(a.lon/1e6*1e5)/1e5,length:Math.round(a.length/10*100)/100,width:Math.round(a.width/10*100)/100,draught:Math.round(a.draught/1e3*100)/100,sog:Math.round(a.sog*3600/1e3/1852*100)/100,cog:Math.round(a.cog/100*100)/100,hdg:Math.round(a.hdg/100*100)/100,rot:Math.round(a.rot/100*100)/100,positionTime:a.lasttime,utc:l.utc().format(),status:a.navistat,labelEn:u,labelCn:r,method:"position",vendor:"shipxy"}}async trajectory(t,n,o,i,s=!0,a={}){var v;const r=await this.realTimePosition(t,a),u=w(n),l=w(o),h="https://api.shipxy.com/apicall/GetShipTrack",c={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:u.unix(),etm:l.unix()}},I=await x.get(h,c).json();if(p==null||p.info("[%s] fetch trajectory from: %s - %j",a.requestId,h,c),(I==null?void 0:I.status)!==0)return I;const b=I==null?void 0:I.points,T=[],k=w.unix((v=b[0])==null?void 0:v.utc);let g=-1;for(const f of b){const d=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:d.unix(),utc:d.utc().format(),method:"trajectory",vendor:"shipxy"},y=Math.floor(d.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,n={}){const o={headers:{appKey:this.token},json:{mmsiList:t}},i="https://api3.myships.com/sp/ships/getShipIdByMMSI",s=await x.post(i,o).json();return p==null||p.info("[%s] fetch ship id from: %s - %j",n.requestId,i,o),s.code!=="0"?s:s.data[0].shipId}async getShipInfo(t,n={}){const o={headers:{appKey:this.token},json:{shipId:t}},i="https://api3.myships.com/sp/ships/aissta",s=await x.post(i,o).json();if(p==null||p.info("[%s] fetch ship info from: %s - %j",n.requestId,i,o),s.code!=="0")return s;const a=s.data;let r=a.imo;return t==="407170"&&(r="9198379",p==null||p.warn("[%s] ship(%s) imo error: %s, should be %s",n.requestId,t,a.imo,r)),{mmsi:a.mmsi,name:a.shipnameEn,imo:r,callSign:a.callSign,length:a.length,width:a.breadth,draught:(a.draught||100)/10}}async realTimePosition(t,n={}){const o=await this.getShipId(t,n),i=await this.getShipInfo(o,n),s={headers:{appKey:this.token},json:{shipId:o}},a="https://api3.myships.com/sp/ships/position/latest",r=await x.post(a,s).json();p==null||p.info("[%s] fetch realtime position from: %s - %j",n.requestId,a,s);const u=r.data[0];for(const b in u)!isNaN(u[b])&&Number(u[b])!==1/0&&(u[b]=Number(u[b]));const{labelCn:l,labelEn:h}=await this.parseStatus(u.aisNavStatus),c=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:c.utc().format(),status:u.aisNavStatus,labelEn:h,labelCn:l,method:"position",vendor:"myship"}}async trajectory(t,n,o,i,s=!0,a={}){const r=w(n),u=w(o),l=await this.getShipId(t),h=await this.getShipInfo(l),c=[];for(;u.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(l,r.unix(),r.add(30,"day").unix(),h,t,i,c);return await this.trajectoryIn30Day(l,r.unix(),u.unix(),h,t,i,c),c}async trajectoryIn30Day(t,n,o,i,s,a,r,u={}){var k;const l={headers:{appKey:this.token},json:{shipId:t,startTime:n,endTime:o}},h="https://api3.myships.com/sp/ships/position/history",c=await x.post(h,l).json();if(p==null||p.info("[%s] fetch trajectory from: %s - %j",u.requestId,h,l),c.code!=="0")return p==null||p.warn("[%s] invoke myship trajectory failed: %j",u.requestId,c),c;const I=c.data;for(const g in I)!isNaN(I[g])&&Number(I[g])!==1/0&&(I[g]=Number(I[g]));const b=w.unix((k=I[0])==null?void 0:k.posTime);let T=-1;for(const g of I){const v=w.unix(g.posTime),f={imo:i==null?void 0:i.imo,mmsi:s,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:v.unix(),utc:v.utc().format(),method:"trajectory",vendor:"myship"},d=Math.floor(v.diff(b,"minute",!0)/(a||1));d!==T&&(T=d,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 a,r,u;_==null||_.debug("[%s] parse rule: %s",t.requestId,e);const n=new RegExp("(?<=\\[)(.+)(?=])","g"),o=e.match(n)?(a=e.match(n))==null?void 0:a[0]:void 0,i=o==null?void 0:o.split(";");if(!i)return;const s={};for(let l=0;l<(i==null?void 0:i.length);l++){const h=(u=(r=i[l].match(n))==null?void 0:r[0])==null?void 0:u.split("],");if(l===0&&!h)s.scope=i[0];else if(h)for(let c=0,I=h.length;c<I;c++){const b=this.parseRule(h[c]);b&&(s[b.level]?b.key?s[b.level][b==null?void 0:b.key]=b:s[b.level]=b:b.key?s[b.level]={[b==null?void 0:b.key]:b}:s[b.level]=b)}}return s}parseRule(e,t={}){var s;_==null||_.debug("[%s] parse rule: %s",t.requestId,e),e=e.startsWith("[")?e:`[${e}`,e=e.endsWith("]")?e:`${e}]`;const n=new RegExp("(?<=\\[)(.+?)(?=])","g"),o=(s=e==null?void 0:e.match(n))==null?void 0:s[0],i=o==null?void 0:o.split(",");if(i){let a=i[3]==="Number.MAX_VALUE"?100:Number(i[3]);return a=isNaN(a)?1:a,{operator:i[0],number:Number.isNaN(Number(i[1]))?i[1]:Number(i[1]),level:i[2],time:a,key:i[4]}}}checkWeather(e,t,n={}){var b,T,k,g,v,f,d,m,y,F,M,L,H,N,W;let o=0,i=0,s=0,a=0;const r=Math.round(((T=(b=t==null?void 0:t.SEVERE)==null?void 0:b.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=(v=t==null?void 0:t.HEAVY)==null?void 0:v.sigWave)==null?void 0:f.number,h=Math.round((((m=(d=t==null?void 0:t.SEVERE)==null?void 0:d.wind)==null?void 0:m.number)+2)*100)/100,c=(F=(y=t==null?void 0:t.SEVERE)==null?void 0:y.wind)==null?void 0:F.number,I=(L=(M=t==null?void 0:t.HEAVY)==null?void 0:M.wind)==null?void 0:L.number;for(let B=0;B<(e==null?void 0:e.length);B++){const C=e[B],R=(N=(H=C==null?void 0:C.meteo)==null?void 0:H.wave)==null?void 0:N.sig,q=(W=C==null?void 0:C.meteo)==null?void 0:W.wind,z=B?w(C.eta).diff(w(e[B-1].eta),"hour",!0):0;a=z>a?z:a,_==null||_.debug("[%s] check sig.wave: %j",n.requestId,{...R,dgThd4Wv:r,svThd4Wv:u,hvThd4Wv:l}),(R==null?void 0:R.height)>=r?C.isDangerous=!0:(R==null?void 0:R.height)>=u?C.isSevere=!0:(R==null?void 0:R.height)>=l&&(C.isHeavy=!0),_==null||_.debug("[%s] check wind: %j",n.requestId,{...q,dgThd4Wd:h,svThd4Wd:c,hvThd4Wd:I}),(q==null?void 0:q.scale)>=h?(C.isDangerous=!0,delete C.isSevere,delete C.isHeavy):(q==null?void 0:q.scale)>c?(C.isDangerous||(C.isSevere=!0),delete C.isHeavy):(q==null?void 0:q.scale)===I&&!C.isDangerous&&!C.isSevere&&(C.isHeavy=!0),o+=C.isDangerous?z:0,i+=C.isSevere?z:0,s+=C.isHeavy?z:0}return o=Math.round(o*100)/100,i=Math.round(i*100)/100,s=Math.round(s*100)/100,a=Math.round(a),{sample:e,dangerous:o,severe:i,heavy:s,step:a<3?3:a,wind:{dgThd4Wd:h,svThd4Wd:c,hvThd4Wd:I},sig:{dgThd4Wv:r,svThd4Wv:u,hvThd4Wv:l}}}}const wt=new ht;let S;try{S=K.getLogger("vessel")}catch{}finally{}const It=new Mt.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,n,o){let i=Math.round(e/(t*n*o)*100)/100;i=i<.55?.55:i>.85?.85:i;const s=[.55,.6,.65,.7,.75,.8,.85],a=s.map(r=>Math.abs(r-i));return s[a.indexOf(Math.min(...a))]}static froudeNumber(e,t,n=9.8){let o=Math.round(Math.sqrt(e*e/(n*t))*100)/100;return o=o<.05?.05:o>.3?.3:o,o}static amendFactor(e,t,n){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 s={.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 n==="Laden"&&(s=o[e]),s[0]+s[1]*t+s[2]*Math.pow(t,2)}static directionFactor(e,t=0){let n;return e>30&&e<=60?n=(1.7-.03*Math.pow(t-4,2))/2:e>60&&e<=150?n=(.9-.06*Math.pow(t-6,2))/2:e>150&&e<=180?n=(.4-.03*Math.pow(t-8,2))/2:n=1,Math.round(n*1e5)/1e5}static vesselTagFactor(e,t,n,o){let i;return n==="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,n=10,o={}){e=e<3?e*.7:e,e=e<0?.2:e,e=e>6?e-.9*(e-6):e,e=e>9?9:e;const i=Math.max(n>10?n-10:2.8);let s;return t>30&&t<=60?s=-.6:t>60&&t<=90?s=-.5:t>90&&t<=120?s=e<i?.2:-.3:t>120&&t<=150?s=e<i?.25:-.2:t>150&&t<=180?s=e<i?.3:-.1:s=-.7,S==null||S.info("[%s] calculate wave height factor with ht(%d), beta(%d), draught(%d) and factor(%d)",o.requestId,e,t,n,s),Math.round(s*(.144*Math.pow(e,2)+.378*e)*1e4)/1e4}static assembleProperties(e,t,n,o){var c;const i=e.lbp??e.length??e.lengthOverall??198.9642,s=e.draught??8,a=e.breadthMoulded??e.breadth??e.breadthExtreme??32.4572,r=e.deadweight??67035.7773,u=((c=e==null?void 0:e.type)==null?void 0:c.toLowerCase())||"common";return{tag:u.indexOf("container")>-1?"container":u.indexOf("tugs")>-1?"tugs":"common",lbp:i,loadCondition:t,draught:s,breadthMoulded:a,displacement:Math.round((r/1.025+s*a*i*.7)*1e4)/1e4,speed:Math.round((n??14.1382)*1852/3600*1e4)/1e4,bearing:o||90}}static async speedLoseAt(e,t,n,o="",i=2,s=!0,a=!1,r={}){let u;if(t.velocity&&a&&(e.speed=E.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),s){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),v=n.utc().format(),f=await It.spotForecast(t.lat,t.lng,v,!1,!1,!0,{...r,pastDays:1,forecastDays:2,weatherModels:k,marineModels:g}),[d]=it.Meteo2Assist.pickHourly(f,v);l=it.Meteo2Assist.toLegacy(d)}catch(k){S.warn("[%s] meteo2 spot(%j) forecast failed: %s",r.requestId,{...t,eta:n.utc().format(),source:o},k)}let h=O.currentFactor(e.bearing,l==null?void 0:l.current,i,r),c=O.weatherFactor(e,l,h,r);const I=e.speed*1.943844;I+h+c<=0&&(S.warn("[%s] v0(%d) is less then factor(%d) = wxFactor(%d) + cFactor(%d), scale factor with 0.6",r.requestId,I,c+h,c,h),h=Math.round(h*.6*1e3)/1e3,c=Math.round(c*.6*1e3)/1e3);const b=c<=(r.minV0Factor||-1)?Math.max(r.maxV0Factor||-2.5,-1*c*(c/1.2)):0;S==null||S.info("[%s] calculate speed lose with v0Factor(%d), cFactor(%d) and wxFactor(%d)",r.requestId,b,h,c),c+=b;let T=Math.round((I+h+c)*100)/100;T=T<=0?1:T,u={meteo:{...l},wxFactor:c,v0Factor:b,cFactor:h,speed:t.velocity&&a?t.velocity:T,eta:n.utc().format(),etd:n.utc().format()}}else u={wxFactor:0,v0Factor:0,cFactor:0,speed:t.velocity&&a?t.velocity:Math.round(e.speed*1.943844*100)/100,eta:n.utc().format(),etd:n.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,n,o,i,s,a="",r=!0,u=!1,l={}){t.utc();const h=t.clone().add(14,"days"),c=[],I=[],b=[];let T=0,k=0,g,v;for(let f=0;f<s.length-1;f++){let d=s[f];d.distanceFromStart=Math.round((i+k)*1e3)/1e3;const m=s[f+1];if(e.bearing=E.LaneHelper.calculateBearing(d,m,!m.gcToPrevious),d.bearing=e.bearing,d.suspend&&u){d.eta=d.eta||t.utc().format(),d.elapsed=d.elapsed??0;const M=d.suspend-d.elapsed;if(o-T>M)o=o-T-M,t.add(M,"hour"),d.elapsed=d.suspend;else{const L=o-T;d.elapsed+=L,t.add(L,"hour"),o=0}if(S==null||S.info(`[%s] suspend ${d.elapsed} hours at %j, and remain ${o} hours need to go...`,l.requestId,d),o===0)return d.distanceFromPrevious=k,{etd:t,from:v||d,to:d,next:s.filter(L=>L),wps:c,days:I,all:b}}else d.suspend=0;r=t.isAfter(h)?!1:r,d=await O.speedLoseAt(e,d,t,a,0,r,u,l),b.push(d),v=v||d,d.important&&c.push(d),t.isSameOrAfter(n)&&(I.push(d),n.add(24,"hour"));const y=E.LaneHelper.calculateDistance(d,m,!m.gcToPrevious);let F=Math.round(y/v.speed*1e5)/1e5;if(T+F<o){if(T+=F,t.add(F,"hour"),delete s[f],S==null||S.debug(`[%s] go to %j from %j with ${y}nm, and cost ${F} hours`,l.requestId,{lat:m.lat,lng:m.lng},{lat:v.lat,lng:v.lng,etd:v.etd}),k+=y,s.filter(M=>M).length<=1){g=m,g.eta=t.utc().format(),g.distanceFromPrevious=y,g.distanceFromStart=Math.round((i+k)*1e4)/1e4,c.push(g),b.push(g),delete s[f+1];break}}else{F=o-T,t.add(F,"hour");const M=E.LngLatHelper.roundPrecision(v.speed*F,5);g=E.LaneHelper.calculateCoordinate(d,e.bearing,M,"nauticalmiles",!m.gcToPrevious),g.eta=t.utc().format(),s[f]=g,S==null||S.debug(`[%s] go to %j from %j with ${M}nm, and cost ${F} hours`,l.requestId,{lat:g.lat,lng:g.lng},{lat:d.lat,lng:d.lng,etd:d.etd}),k+=M,g.distanceFromPrevious=Math.round(k*1e4)/1e4,g.distanceFromStart=Math.round((i+k)*1e4)/1e4;break}}return{etd:t,from:v,to:g,next:s.filter(f=>f),wps:c,days:I,all:b}}static currentFactor(e,t,n=0,o={}){const i=E.LaneHelper.includedAngle(e,(t==null?void 0:t.degree)||0)/180*Math.PI;let s;return Math.abs(i)===Math.PI/2&&(s=0),s=((t==null?void 0:t.kts)||0)*Math.cos(i),n&2?s=Math.ceil(s*100)/100:n&1?s=Math.floor(s*100)/100:s=Math.round(s*100)/100,S==null||S.info("[%s] calculate current factor with %j",o.requestId,{beta:i,current:t,factor:s,role:n}),Math.abs(s)>5?0:s}static weatherFactor(e,t,n=0,o={}){var b,T,k,g,v,f,d;S==null||S.info("[%s] calculate weather factor via: %j",o.requestId,{...e,...t});const i=O.blockCoefficient(e.displacement,e.lbp,e.breadthMoulded,e.draught),s=E.LngLatHelper.roundPrecision(n*1852/3600,6),a=O.froudeNumber(e.speed-s,e.lbp),r=O.amendFactor(i,a,e.loadCondition);let u=E.LaneHelper.includedAngle(e.bearing,(b=t==null?void 0:t.wind)==null?void 0:b.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)||10);let c=l*r*h/100*(e.speed-s);c=Math.round(c*1.943844*1e4)/1e4*-1,e.tag==="tugs"&&Math.abs(c)>1&&(c=c/(Math.abs(Math.round(c))+1)),S==null||S.info("[%s] calculate wind wx factor: %d",o.requestId,c),u=E.LaneHelper.includedAngle(e.bearing,(v=(g=t==null?void 0:t.wave)==null?void 0:g.sig)==null?void 0:v.degree);const I=O.waveHeightFactor(((d=(f=t==null?void 0:t.wave)==null?void 0:f.sig)==null?void 0:d.height)??1,u,e.draught,o);return S==null||S.info("[%s] calculate wave wx factor: %d",o.requestId,I),c=Math.abs(c)>Math.abs(I)?c:.6*c+.8*I,S==null||S.info("[%s] calculate finial weather factor: %d (0.6 * wf) + (0.8 * hf)",o.requestId,c),c=Math.abs(c)>3?3*(Math.abs(c)/c)+Math.abs(c)/c*(Math.abs(c)-2)*.1:c,Math.round((c||0)*100)/100}static async reduceDays(e,t=12*60*60){return e=e==null?void 0:e.reduce((n,o)=>(o.positionTime||(o.positionTime=w.utc(o.etd||o.eta).unix()),n.some(i=>Math.floor(i.positionTime/t)===Math.floor(o.positionTime/t))||n.push(o),n),[]),e}static async reduceWPS(e,t=60){return e=e==null?void 0:e.reduce((n,o)=>(n.some(i=>Math.floor(w(i.etd).unix()/t)===Math.floor(w(o.etd).unix()/t))||n.push(o),n),[]),e}static async analyseInstant(e,t,n,o,i,s="",a=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:c,waypoints:I}=i.points,b=E.LaneHelper.calculateSubRoute(e,c);if(((X=b[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(n,o.loadCondition,T,0),v=I.length?E.LaneHelper.calculateSubWaypoints(e,I):[];v.forEach(D=>D.important=!0);const f={from:{...e},route:b,waypoints:v,v0:T,label:k},d={hours:[],days:[],wps:[],all:[]};a||(E.LaneHelper.calculateRouteDistance(b)/o.speed<=72?a=3:a=6);let m=E.LaneHelper.simplifyRouteToCoordinates(b,v,0),y=0,F=0,M=0,L=0;t=w(t).utc();const H=t.clone();for(;m.length>0;){const D=a-t.hour()%a,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,s,r,u,l);if(d.all.push(...j.all),(Q=j.from)!=null&&Q.speed&&(d.hours.push(j.from),d.wps.push(...j.wps),d.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),s,0,r,u,l);V.bearing=g.bearing,d.hours.push(V),d.all.push(V)}y+=Math.round((((Z=j==null?void 0:j.to)==null?void 0:Z.distanceFromPrevious)??0)*1e4)/1e4}const N=d.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,M+=(N[D].cFactor||0)*J,L+=J}const W=N.reduce((D,J)=>D+(J.suspend||0),0);($=d.wps)==null||$.forEach((D,J)=>{D.positionTime=w.utc(D.etd||D.eta).unix();const j=d.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}}),d.wps=await O.reduceWPS(d.wps),d.days=await O.reduceDays(d.days),d.all=(tt=d.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=d;const B=d.hours.at(0),C=d.hours.at(-1);f.distance=Math.round(C.distanceFromStart*1e3)/1e3,f.etd=w(B.eta).utc().format(),f.eta=w(C.eta).utc().format(),f.wxFactor=Math.round(F/L*1e3)/1e3,f.cFactor=Math.round(M/L*1e3)/1e3,f.avgSpeed=Math.round(C.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:at}=await this.calculateECA(f,o,l),st=E.LngLatHelper.roundPrecision(o.fo/24*(L-z),3),ct=E.LngLatHelper.roundPrecision(o.dgo/24*L+R,3);f.extend={eca:at,distanceInECA:q,hoursInECA:z,totalDgoConsInECA:rt,totalDgoConsInSuspend:R},f.totalFoCons=st<0?0:st,f.totalDgoCons=ct;const nt=w().valueOf()-h,ut=((et=d==null?void 0:d.hours)==null?void 0:et.length)||1;return S==null||S.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,n,o,i,s,a,r="",u=3,l=!0,h=!1,c={}){var Z,$,tt,et,D,J;const I=w().valueOf();e.lng=E.LngLatHelper.convertToStdLng(e.lng);const{v0:b,label:T}=e.sog?{v0:e.sog,label:e.label||"Other"}:{v0:i.speed,label:"CP"},k=O.assembleProperties(o,i.loadCondition,b,0),g=E.LaneHelper.calculateSubRoute(e,s);if(((Z=g[0])==null?void 0:Z.length)<=1)return;const v=a.length?E.LaneHelper.calculateSubWaypoints(e,a):[];v.forEach(j=>j.important=!0);let f=E.LaneHelper.simplifyRouteToCoordinates(g,v,0),d=0,m=0,y=0,F=0;const M={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(n)?n.diff(t,"h",!0)*1e4/1e4:V;const Y=await O.speedLoseInHoursStep(k,t,L,V,d,f,r,l,h,c);if(M.all.push(...Y.all),($=Y.from)!=null&&$.speed&&(M.hours.push(Y.from),Y!=null&&Y.wps&&M.wps.push(...Y.wps),M.days.push(...Y.days)),f=Y==null?void 0:Y.next,f.length||M.hours.push(Y==null?void 0:Y.to),d+=Math.round((((tt=Y==null?void 0:Y.to)==null?void 0:tt.distanceFromPrevious)??0)*1e4)/1e4,!V)break}M.wps=await O.reduceWPS(M.wps),M.days=await O.reduceDays(M.days),M.all=(et=M.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=M.wps)==null||D.forEach((j,V)=>{const Y=M.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=M.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=M.hours.at(0),B=M.hours.at(-1),C=await E.LaneHelper.calculateRangeRoute(W,B,g),R=await E.LaneHelper.calculateRangeWaypoints(W,B,g,v),q={sample:M,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:C,waypoints:R,v0:b,label:T},z=E.LngLatHelper.roundPrecision(i.dgo/24*N,3),{distanceInECA:rt,hoursInECA:at,totalDgoConsInECA:st,eca:ct}=await this.calculateECA(q,i,c),dt=E.LngLatHelper.roundPrecision(i.fo/24*(F-at),3),nt=E.LngLatHelper.roundPrecision(i.dgo/24*F+z,3);q.extend={eca:ct,distanceInECA:rt,hoursInECA:at,totalDgoConsInECA:st,totalDgoConsInSuspend:z},q.totalDgoCons=nt,q.totalFoCons=dt<0?0:dt;const X=w().valueOf()-I,Q=((J=M==null?void 0:M.hours)==null?void 0:J.length)||1;return S==null||S.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",c==null?void 0:c.requestId,X,Q,Math.round(X/Q*1e3)/1e3),q}static async analyseCost(e,t,n,o,i={}){var g,v;const s=w().valueOf(),a=[];e.speedStep=e.speedStep||3,e.alterStep=e.alterStep??1;const r=E.LaneHelper.calculateRouteDistance(o.route);let u=0;n.forEach(f=>{const d=Math.ceil(r/f.speed/24);u=u<d?d:u}),u=u*1.3;const l=w.utc(e.etd).add(u??14,"day");let h=1;for(const f of n){const d=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,d,m,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,i);y&&(await O.calculateCost(y,f,e,i),a.push(y),S==null||S.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++}a.sort((f,d)=>f.cost.total-d.cost.total);const c=a.at(0),I=a.at(1),b=[];if(b.push({combined:!1,speeds:[c],cost:(g=c.cost)==null?void 0:g.total}),I){const f=c.cost.cp,d=I.cost.cp,m=w(c.eta),y=w(c.etd),F=m.diff(y,"days",!0);let M=Math.ceil(F/2);M=M>7?7:M<e.alterStep?e.alterStep:M;let L=2,H={combined:!1,speeds:[I],cost:(v=I.cost)==null?void 0:v.total},N;for(;M>=e.alterStep;){const W=await O.combinedAnalyse(e,t,l,[f,d],o,M,{...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),M<=e.alterStep)break;M=Math.ceil(M/2),L+=1}b.push(H),N&&b.push(N)}const k=w().valueOf()-s;return S==null||S.info("[%s] analyse elapsed: %d ms",i==null?void 0:i.requestId,k),b.sort((f,d)=>f.cost-d.cost)}static async combinedAnalyse(e,t,n,o,i,s,a={}){a.counter=1,S==null||S.info("[%s][L%d] analyse with alternate cp in every %d days",a.requestId,a.level,s);const r=await O.alternateAnalyse(e,t,n,o,0,i,s,a),u=r.reduce((d,m)=>d+m.cost.total,0),l=r.reduce((d,m)=>d+m.cost.hire,0),h=r.reduce((d,m)=>d+m.cost.bunker,0),c=r.reduce((d,m)=>d+m.distance,0),I=r.reduce((d,m)=>d+m.totalHrs,0);S==null||S.info("[%s][L%d] cost with cpa/cpb turn: %j",a.requestId,a.level,{cost:u,hire:l,bunker:h,distance:c,hours:I});const b=await O.alternateAnalyse(e,t,n,o,1,i,s,a),T=b.reduce((d,m)=>d+m.cost.total,0),k=b.reduce((d,m)=>d+m.cost.hire,0),g=b.reduce((d,m)=>d+m.cost.bunker,0),v=b.reduce((d,m)=>d+m.distance,0),f=b.reduce((d,m)=>d+m.totalHrs,0);return S==null||S.info("[%s][L%d] cost with cpb/cpa turn: %j",a.requestId,a.level,{cost:T,hire:k,bunker:g,distance:v,hours:f}),u<T?{combined:!0,cost:Math.round(u*1e3)/1e3,speeds:r,step:s}:{combined:!0,cost:Math.round(T*1e3)/1e3,speeds:b,step:s}}static async alternateAnalyse(e,t,n,o,i,s,a,r={}){var c,I;let u=w.utc(e.etd);const l={lat:e.lat,lng:e.lng},h=[];for(;u.isBefore(n);){const b=u.clone().utc().add(a,"day"),T=JSON.parse(JSON.stringify(s.route)),k=JSON.parse(JSON.stringify(s.waypoints)),g=o[i],v=await O.analyseInstantWithThreshed(l,u.utc().format(),b,t,g,T,k,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,r);v&&(await O.calculateCost(v,g,e,r),S==null||S.info("[%s][L%d-%d] analyse from %s to %s cost: %j",r.requestId,r.level,r.counter,u.utc().format(),b.utc().format(),{cost:v.cost.total,hire:v.cost.hire,bunker:v.cost.bunker,distance:v.distance,hours:v.totalHrs,cp:`${g.speed}/${g.fo}/${g.dgo}`})),r.counter=r.counter+1;const f=(I=(c=v==null?void 0:v.sample)==null?void 0:c.hours)==null?void 0:I.at(-1);if(f)l.lat=f.lat,l.lng=f.lng,u=w(f.eta),h.push(v),i=i?0:1;else break}return h}static async calculateCost(e,t,n,o={}){var i;if(e){const s=(n.addComm||0)>=1?(n.addComm||0)/100:n.addComm||0,a=Math.round((n.dailyHire||0)*(e.suspend||0)/24*1e3)/1e3,r=Math.round(e.totalHrs/24*(n.dailyHire||0)*(1-s)*1e3)/1e3+a,u=Math.round(e.totalFoCons*(n.priceFO||0)*1e3)/1e3,l=Math.round((e.totalDgoCons+(((i=e.extend)==null?void 0:i.totalDgoConsInECA)||0))*(n.priceDGO||0)*1e3)/1e3;e.cost={total:Math.round((r+u+l)*1e3)/1e3,hire:Math.round(r*1e3)/1e3,suspendHire:a,bunker:Math.round((u+l)*1e3)/1e3,cp:t}}return e}static async calculateECA(e,t,n={}){var r,u,l,h;const o=await E.LaneHelper.intersectInECA((e==null?void 0:e.route)||[]);let i=0,s=0,a=0;(u=(r=e==null?void 0:e.sample)==null?void 0:r.wps)==null||u.forEach(c=>{c.positionTime=w.utc(c.etd||c.eta).unix()});for(const c of o){i+=c.distance;const I=await E.LaneHelper.deadReckoningTime((l=c.waypoints)==null?void 0:l.at(0),e.sample.all||e.sample.wps),b=await E.LaneHelper.deadReckoningTime((h=c.waypoints)==null?void 0:h.at(-1),e.sample.all||e.sample.wps);c.in=I,c.out=b,c.totalHrs=E.LngLatHelper.roundPrecision((b.positionTime-I.positionTime)/3600,3),c.totalDgoCons=E.LngLatHelper.roundPrecision(t.fo/24*c.totalHrs,3),s+=c.totalHrs,a+=c.totalDgoCons}return i=E.LngLatHelper.roundPrecision(i,3),s=E.LngLatHelper.roundPrecision(s,3),a=E.LngLatHelper.roundPrecision(a,3),{distanceInECA:i,hoursInECA:s,totalDgoConsInECA:a,eca:o}}static async mergeSpeeds(e,t={}){var f,d;const n={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),s=e.reduce((m,y)=>m+y.totalHrs,0),a=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/s,0),l=e.reduce((m,y)=>m+y.cFactor*y.totalHrs/s,0),h=e.reduce((m,y)=>m+y.totalFoCons,0),c=e.reduce((m,y)=>m+y.totalDgoCons,0),I=e.reduce((m,y)=>m+y.cost.total,0),b=e.reduce((m,y)=>m+y.cost.hire,0),T=e.reduce((m,y)=>m+y.cost.bunker,0),k=[],g=[];let v;for(const m of e){g.push(...((f=m.extend)==null?void 0:f.eca)||[]);const y=m.sample.hours,F=m.sample.all,M=m.sample.wps,L=m.sample.days,H=y.at(0);v&&(H.distanceFromPrevious=v.distanceFromPrevious,H.distanceFromStart=v.distanceFromStart,y.forEach((C,R)=>{R&&(C.distanceFromStart=C.distanceFromStart+v.distanceFromStart)}),F.at(0).distanceFromPrevious=v.distanceFromPrevious,F.at(0).distanceFromStart=v.distanceFromStart,F.forEach((C,R)=>{R&&(C.distanceFromStart=C.distanceFromStart+v.distanceFromStart)}),M.at(0).distanceFromPrevious=v.distanceFromPrevious,M.at(0).distanceFromStart=v.distanceFromStart,M.forEach((C,R)=>{R&&(C.distanceFromStart=C.distanceFromStart+v.distanceFromStart)}),L.at(0).distanceFromPrevious=v.distanceFromPrevious,L.at(0).distanceFromStart=v.distanceFromStart,L.forEach((C,R)=>{R&&(C.distanceFromStart=C.distanceFromStart+v.distanceFromStart)})),H.cp=m.cost.cp;const N=[m.etd,m.eta],W=k.findIndex(C=>C.id===H.cp.id);W===-1?(H.cp.segment=[N],k.push(H.cp)):k[W].segment.push(N),y.forEach(C=>{var q;((q=n.hours)==null?void 0:q.findIndex(z=>z.eta===C.eta))===-1&&n.hours.push(C)}),F.forEach(C=>{var q;((q=n.all)==null?void 0:q.findIndex(z=>z.eta===C.eta))===-1&&n.all.push(C)}),M.forEach(C=>{var q;((q=n.wps)==null?void 0:q.findIndex(z=>z.eta===C.eta))===-1&&n.wps.push(C)}),L.forEach(C=>{var q;((q=n==null?void 0:n.days)==null?void 0:q.findIndex(z=>z.eta===C.eta))===-1&&n.days.push(C)});const B=(d=n.wps)==null?void 0:d.findIndex(C=>C.eta===H.eta);B===-1?n.wps.push(H):n.wps[B]=H,v=y.at(-1)}return n.wps.sort((m,y)=>w(m.etd).unix()-w(y.etd).unix()),n.wps.forEach((m,y)=>{const F=n.wps[y-1];if(F){const M=m.distanceFromStart-(F.distanceFromStart||0),L=w(m.eta||m.etd).diff(w(F.etd||F.eta),"hour",!0),H=Math.round(M/L*100)/100;m.avgSpd=H;const N=E.LaneHelper.calculateBearing(F,m);F.bearing=N}}),{sample:n,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(s*1e3)/1e3,avgSpeed:Math.round(o/s*1e3)/1e3,wxFactor:Math.round(u*1e3)/1e3,cFactor:Math.round(l*1e3)/1e3,totalFoCons:Math.round(h*1e3)/1e3,totalDgoCons:Math.round(c*1e3)/1e3,cost:{total:Math.round(I*1e3)/1e3,hire:Math.round(b*1e3)/1e3,bunker:Math.round(T*1e3)/1e3},extend:{cps:k,eca:g,distanceInECA:Math.round(i*1e3)/1e3,hoursInECA:Math.round(a*1e3)/1e3,totalDgoConsInECA:Math.round(r*1e3)/1e3,speeds:e}}}}P.AISImpl=G,P.AlertHelper=ht,P.AlertLevel=lt,P.HifleetImpl=bt,P.LoadCondition=mt,P.MyShipImpl=gt,P.MyVesselImpl=pt,P.ShipxyImpl=vt,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.8.0",
4
+ "version": "3.8.2",
5
5
  "description": "idm plugin for vessel",
6
6
  "type": "module",
7
7
  "keywords": [
@@ -33,8 +33,8 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "@idm-plugin/geo2": "^1.6.8",
36
- "@idm-plugin/meteo": "^0.6.5",
37
- "@idm-plugin/meteo2": "^0.9.7",
36
+ "@idm-plugin/meteo": "^0.6.7",
37
+ "@idm-plugin/meteo2": "^0.9.9",
38
38
  "@idm-plugin/tag": "^0.3.0",
39
39
  "@turf/turf": "^6.5.0",
40
40
  "@types/jest": "^25.2.2",