@idm-plugin/vessel 2.3.7 → 2.3.8

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
@@ -828,6 +828,7 @@ class O {
828
828
  /**
829
829
  * 浪高影响因子
830
830
  * @param ht 浪高,单位m
831
+ * @param beta 夹角
831
832
  * @private
832
833
  */
833
834
  static waveHeightFactor(s, t) {
@@ -996,7 +997,7 @@ class O {
996
997
  c = c > 180 ? 360 - c : c;
997
998
  const d = O.directionFactor(c, (M = t == null ? void 0 : t.wind) == null ? void 0 : M.scale), h = O.vesselTagFactor(s.displacement, s.loadCondition, s.tag, (j = t == null ? void 0 : t.wind) == null ? void 0 : j.kts);
998
999
  let u = d * e * h / 100 * (s.speed - n);
999
- u = Math.round(u * 1.943844 * 1e4) / 1e4 * -1, s.tag === "tugs" && Math.abs(u) > 1 && (u = u / (Math.abs(Math.round(u)) + 1)), C == null || C.debug("wind wx factor = %d", u), c = Math.abs(s.bearing % 360 - (((w = (I = t == null ? void 0 : t.wave) == null ? void 0 : I.sig) == null ? void 0 : w.degree) % 360 || 0));
1000
+ u = Math.round(u * 1.943844 * 1e4) / 1e4, s.tag === "tugs" && Math.abs(u) > 1 && (u = u / (Math.abs(Math.round(u)) + 1)), C == null || C.debug("wind wx factor = %d", u), c = Math.abs(s.bearing % 360 - (((w = (I = t == null ? void 0 : t.wave) == null ? void 0 : I.sig) == null ? void 0 : w.degree) % 360 || 0)), c = c > 180 ? 360 - c : c;
1000
1001
  const y = O.waveHeightFactor(((r = (g = t == null ? void 0 : t.wave) == null ? void 0 : g.sig) == null ? void 0 : r.height) ?? 1, c);
1001
1002
  return C == null || C.debug("wave wx factor = %d", y), u = Math.abs(u) > Math.abs(y) ? u : u * 0.3 + y * 0.7, C == null || C.debug("weather factor = %d", u), u = Math.abs(u) > 3 ? 3 * (Math.abs(u) / u) + Math.abs(u) / u * (Math.abs(u) - 2) * 0.1 : u, Math.round((u || 0) * 100) / 100;
1002
1003
  }
@@ -1 +1 @@
1
- (function(q,A){typeof exports=="object"&&typeof module<"u"?A(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"],A):(q=typeof globalThis<"u"?globalThis:q||self,A(q["idm-plugin-vessel"]={},q.got,q["@log4js-node/log4js-api"],q.moment,q["@idm-plugin/geo2"],q["@idm-plugin/meteo2"],q["@idm-plugin/meteo"]))})(this,function(q,A,U,g,N,ft,nt){"use strict";var It=Object.defineProperty;var St=(q,A,U)=>A in q?It(q,A,{enumerable:!0,configurable:!0,writable:!0,value:U}):q[A]=U;var K=(q,A,U)=>(St(q,typeof A!="symbol"?A+"":A,U),U);let m;try{m=U.getLogger("vessel")}catch{}finally{}class G{parseStatus(s){let t,a;switch(s){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();K(this,"clientId");K(this,"clientSecret");K(this,"token");this.clientId=t,this.clientSecret=a}async authToken(t={}){const a="https://svc.data.myvessel.cn/ada/oauth/token",i={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},n=await A.post(a,i).json();m==null||m.info("[%s] fetch access token from: %s - %j",t.requestId,a,n),n.error||(this.token={accessToken:n.access_token,tokenType:n.token_type,expiresIn:n.expires_in,scope:n.scope,jti:n.jti,issuedAt:g().utc().format()})}async checkToken(t={}){var a;return(!this.token||g().diff(g(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 e,r;await this.checkToken(a);const i="https://market.myvessel.cn/sdc/v1/mkt/vessels/fuzzy",n={headers:{Authorization:`${(e=this.token)==null?void 0:e.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,i,n);const o=await A.post(i,n).json();return o.status!==200?(m==null||m.warn("[%s] fetch suggest vessels failed: %j",a.requestId,{message:o.message,status:o.status,code:o.code}),[]):(o.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 d,l;await this.checkToken(a);const i=/^\d{7}$/.test(t.toString()),n=i?"https://market.myvessel.cn/sdc/v1/mkt/vessels/detail/imo":"https://market.myvessel.cn/sdc/v1/mkt/vessels/detail/mmsi",o=i?{imo:t}:{mmsi:t},e={headers:{Authorization:`${(d=this.token)==null?void 0:d.tokenType} ${(l=this.token)==null?void 0:l.accessToken}`},searchParams:o};m==null||m.info("[%s] fetch vessel from: %s - %j",a.requestId,n,e);const r=await A.get(n,e).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 u=r.data;if(u)return{mmsi:u.mmsi,imo:Number.isNaN(u.imo)?null:Number(u.imo),callSign:u.callsign,name:u.nameEn,nameCn:u.nameCn,type:u.vesselTypeNameEn,flagName:u.flagCtry,clasz:u.classSociety,dateOfBuild:u.buildYearMonth,deadweight:u.dwt,grossTonnage:u.grt,netTonnage:u.net,teu:u.teu,length:u.length,breadth:u.width,height:u.height,draught:u.draught,speed:u.speed,passengerCapacity:u.passengercapacity,vendor:"myvessel",raw:u}}return{}}async archives(t,a={}){var e,r;await this.checkToken(a);const i="https://svc.data.myvessel.cn/sdc/v1/ship/info/batch",n={headers:{Authorization:`${(e=this.token)==null?void 0:e.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,i,n);const o=await A.post(i,n).json();return o.status!==200?(m==null||m.warn("[%s] fetch vessel archive failed: %j",a.requestId,{message:o.message,status:o.status,code:o.code}),{}):o.data}async realTimePosition(t,a={}){var r,d;await this.checkToken(a);const i="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",n={headers:{Authorization:`${(r=this.token)==null?void 0:r.tokenType} ${(d=this.token)==null?void 0:d.accessToken}`},searchParams:{mmsi:t}};m==null||m.info("[%s] fetch realtime position from: %s - %j",a.requestId,i,n);const o=await A.get(i,n).json();if(o.code)return m==null||m.warn("[%s] fetch realtime position failed: %j",a.requestId,{message:o.message,status:o.status,code:o.code}),o;const e=o.data;for(const l in e)!isNaN(e[l])&&Number(e[l])!==1/0&&(e[l]=Number(e[l]));if(e){const l=g(`${e.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:e.mmsi,name:e.vesselName||e.aisVesselName,imo:e.imo,callSign:e.callsign||e.aisCallSign,lat:e.lat,lng:e.lon,length:e.length,width:e.width,draught:e.currDraught,sog:e.sog,cog:e.cog,hdg:e.hdg,rot:e.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta)?g.utc(e.eta).format():void 0,destination:e.dest,positionTime:l.unix(),status:e.status,labelCn:e.statusNameCn,labelEn:e.statusNameEn,vesselType:e.vesselTypeNameEn,flag:e.flagCtryNameEn,clasz:e.classSociety,build:e.buildYear,dwt:e.dwt,grt:e.grt,net:e.net,method:"position",vendor:"myVessel",utc:l.utc().format()}}else return{}}async calculateRoute(t,a,i={}){var r,d;await this.checkToken(i);const n="https://svc.data.myvessel.cn/sdc/v1/routes/routing/nodes",o={headers:{Authorization:`${(r=this.token)==null?void 0:r.tokenType} ${(d=this.token)==null?void 0:d.accessToken}`},json:{startPoint:{lon:t.lng,lat:t.lat},endPoint:{lon:a.lng,lat:a.lat},maxDraught:i.maxDraught||10,useAIModel:i.useAIModel||!1,withECA:i.withECA||!1}};m==null||m.info("[%s] fetch route from: %s - %j",i.requestId,n,o);const e=await A.post(n,o).json();return e.status!==200?(m==null||m.warn("[%s] fetch route failed: %j",i.requestId,{message:e.message,status:e.status,code:e.code}),{}):e.data}async trajectory(t,a,i,n,o=!0,e={}){await this.checkToken(e);const r=await this.realTimePosition(t,e),d=g(a),l=g(i),u=[];for(;l.diff(d,"day",!0)>30;)await this.trajectoryIn30Day(t,d,d.clone().add(30,"day"),r,n,u,e),d.add(30,"day");return await this.trajectoryIn30Day(t,d,l,r,n,u,e),u}async trajectoryIn30Day(t,a,i,n,o,e,r={}){var M,C,S,w,b;const d="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",l={headers:{Authorization:`${(M=this.token)==null?void 0:M.tokenType} ${(C=this.token)==null?void 0:C.accessToken}`},json:{mmsi:t,startTime:a.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};m==null||m.info("[%s] fetch trajectory from: %s - %j",r.requestId,d,l);const u=await A.post(d,l).json();if(u.code)return m==null||m.warn("[%s] fetch trajectory failed: %j",r.requestId,d,{message:u.message,status:u.status,code:u.code}),u;let y=-1;const v=g(`${(w=(S=u.data)==null?void 0:S[0])==null?void 0:w.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(b=u.data)==null||b.forEach(c=>{for(const Y in c)!isNaN(c[Y])&&Number(c[Y])!==1/0&&(c[Y]=Number(c[Y]));const p=g(`${c.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),f=c.status,{labelCn:h,labelEn:k}=this.parseStatus(f),j={mmsi:c.mmsi,imo:n==null?void 0:n.imo,lat:c.lat,lng:c.lon,sog:c.sog,cog:c.cog,hdg:c.hdg,draught:c.draught,status:f,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(c.eta)?g(`${c.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").utc().format():void 0,destination:c.dest,positionTime:p.unix(),labelCn:h,labelEn:k,method:"trajectory",vendor:"myVessel",utc:p.utc().format()},x=Math.floor(p.diff(v,"minute",!0)/(o||1));x!==y&&(y=x,e.push(j))}),e}}class yt extends G{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,a={}){const i="https://api.hifleet.com/position/position/get/token",n={searchParams:{mmsi:t,usertoken:this.token}},o=await A.post(i,n).json();m==null||m.info("[%s] fetch realtime position from: %s - %j",a.requestId,i,n);const e=o==null?void 0:o.list;if(!e)return m==null||m.warn("[%s] fetch realtime position failed: %j",a.requestId,i,o),o;for(const v in e)!isNaN(e[v])&&Number(e[v])!==1/0&&(e[v]=Number(e[v]));e.status=e.sp>3?0:1;const r=e.status,{labelCn:d,labelEn:l}=this.parseStatus(r),u=g(`${e.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:e.m,name:e.n,imo:e.imonumber,callSign:e.callsign,lat:Math.round(e.la/60*1e5)/1e5,lng:Math.round(e.lo/60*1e5)/1e5,length:e.l,width:e.w,draught:e.draught,sog:e.sp,cog:e.co,hdg:e.h,rot:isNaN(e.rot)?0:e.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta)?g.utc(e.eta).format():void 0,destination:e.destination,vesselType:e.type,dwt:e.dwt,build:e.buildyear,flag:e.fn,positionTime:u.unix(),utc:u.utc().format(),status:r,labelCn:d,labelEn:l,method:"position",vendor:"hifleet"}}async search(t,a={}){let i="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const n={searchParams:{keyword:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let o=await A.post(i,n).json();m==null||m.info("[%s] fetch vessel props from: %s - %j",a.requestId,i,n),o instanceof Array&&(o=o[0]);for(const r in o)!isNaN(o[r])&&Number(o[r])!==1/0&&(o[r]=Number(o[r]));const e={mmsi:o.m,name:o.n,imo:o.i,callSign:o.c,length:o.l,breadth:o.b,draught:o.dr,type:o.t};return i="https://www.hifleet.com/hifleetapi/sameShipSearch.do",o=await A.post(i,n).json(),m==null||m.info("[%s] search vessel dead weight from: %s - %j",a.requestId,i,n),o instanceof Array&&(o=o[0]),o&&(e.deadweight=Number(o.dwt)),e}async suggest(t,a={}){const i="https://www.hifleet.com/hifleetapi/getShipSuggest.do",n={searchParams:{q:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}},o=await A.post(i,n).json();m==null||m.info("[%s] suggest vessel props from: %s - %j",a.requestId,i,n);const e=[];for(const r of o)e.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 e.sort((r,d)=>d.score-r.score),e}async trajectory(t,a,i,n,o=!0,e={}){var c,p,f;const r=await this.realTimePosition(t,e);let d=g(a);const l=g(i),u=g();if(o){let h=l.diff(d,"d",!0);h<0?d=l.clone().subtract(40,"d"):h<30?d.subtract(10,"d"):h<60?d.subtract(5,"d"):d=l.clone().subtract(80,"d"),h=u.diff(l,"d",!0),l.add(h>10?240:h*24,"h")}const y={searchParams:{endtime:l.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),starttime:d.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),mmsi:t,usertoken:this.token}},v="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",M=await A.get(v,y).json();m==null||m.info("[%s] fetch trajectory from: %s - %j",e.requestId,v,y);let C;M&&(C=((p=(c=M.ships)==null?void 0:c.offors)==null?void 0:p.ship)||[],C.length||m==null||m.warn("[%s] fetch trajectory failed: %j",e.requestId,M));const S=[];let w=-1;const b=g(`${(f=C==null?void 0:C[0])==null?void 0:f.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const h of C){for(const L in h)!isNaN(h[L])&&Number(h[L])!==1/0&&(h[L]=Number(h[L]));const k=g(`${h.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");h.status=h.sp>4?0:1;const{labelEn:j,labelCn:x}=this.parseStatus(h.status),Y={mmsi:h.m,name:h.n,imo:r==null?void 0:r.imo,lat:h.la,lng:h.lo,draught:h.draught,sog:h.sp,cog:h.co,hdg:h.hdg,positionTime:k.unix(),utc:k.utc().format(),status:h.status,labelCn:x,labelEn:j,method:"trajectory",vendor:"hifleet"},F=Math.floor(k.diff(b,"minute",!0)/(n||1));F!==w&&(w=F,S.push(Y))}return S}}class Mt extends G{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,a={}){const i={searchParams:{id:t,k:this.token,enc:1}},n="https://api.shipxy.com/apicall/GetSingleShip",o=await A.get(n,i).json();if(m==null||m.info("[%s] fetch realtime position from: %s - %j",a.requestId,n,i),(o==null?void 0:o.status)!==0)return o;const e=o.data[0];for(const y in e)!isNaN(e[y])&&Number(e[y])!==1/0&&(e[y]=Number(e[y]));const{labelCn:r,labelEn:d}=await this.parseStatus(e.navistat),l=g.unix(e.lasttime);return{mmsi:e.ShipID,name:e.name,imo:e.imo,callSign:e.callsign,lat:Math.round(e.lat/1e6*1e5)/1e5,lng:Math.round(e.lon/1e6*1e5)/1e5,length:Math.round(e.length/10*100)/100,width:Math.round(e.width/10*100)/100,draught:Math.round(e.draught/1e3*100)/100,sog:Math.round(e.sog*3600/1e3/1852*100)/100,cog:Math.round(e.cog/100*100)/100,hdg:Math.round(e.hdg/100*100)/100,rot:Math.round(e.rot/100*100)/100,positionTime:e.lasttime,utc:l.utc().format(),status:e.navistat,labelEn:d,labelCn:r,method:"position",vendor:"shipxy"}}async trajectory(t,a,i,n,o=!0,e={}){var b;const r=await this.realTimePosition(t,e),d=g(a),l=g(i),u="https://api.shipxy.com/apicall/GetShipTrack",y={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:d.unix(),etm:l.unix()}},v=await A.get(u,y).json();if(m==null||m.info("[%s] fetch trajectory from: %s - %j",e.requestId,u,y),(v==null?void 0:v.status)!==0)return v;const M=v==null?void 0:v.points,C=[],S=g.unix((b=M[0])==null?void 0:b.utc);let w=-1;for(const c of M){const p=g.unix(c.utc),f={imo:r==null?void 0:r.imo,mmsi:t,sog:Math.round(c.sog*3600/1e3/1852*100)/100,cog:Math.round(c.cog/100*100)/100,lat:Math.round(c.lat/1e6*1e5)/1e5,lng:Math.round(c.lon/1e6*1e5)/1e5,positionTime:p.unix(),utc:p.utc().format(),method:"trajectory",vendor:"shipxy"},h=Math.floor(p.diff(S,"minute",!0)/(n||1));h!==w&&(w=h,C.push(f))}return C}}class pt extends G{constructor(t){super();K(this,"token");this.token=t}async getShipId(t,a={}){const i={headers:{appKey:this.token},json:{mmsiList:t}},n="https://api3.myships.com/sp/ships/getShipIdByMMSI",o=await A.post(n,i).json();return m==null||m.info("[%s] fetch ship id from: %s - %j",a.requestId,n,i),o.code!=="0"?o:o.data[0].shipId}async getShipInfo(t,a={}){const i={headers:{appKey:this.token},json:{shipId:t}},n="https://api3.myships.com/sp/ships/aissta",o=await A.post(n,i).json();if(m==null||m.info("[%s] fetch ship info from: %s - %j",a.requestId,n,i),o.code!=="0")return o;const e=o.data;let r=e.imo;return t==="407170"&&(r="9198379",m==null||m.warn("[%s] ship(%s) imo error: %s, should be %s",a.requestId,t,e.imo,r)),{mmsi:e.mmsi,name:e.shipnameEn,imo:r,callSign:e.callSign,length:e.length,width:e.breadth,draught:(e.draught||100)/10}}async realTimePosition(t,a={}){const i=await this.getShipId(t,a),n=await this.getShipInfo(i,a),o={headers:{appKey:this.token},json:{shipId:i}},e="https://api3.myships.com/sp/ships/position/latest",r=await A.post(e,o).json();m==null||m.info("[%s] fetch realtime position from: %s - %j",a.requestId,e,o);const d=r.data[0];for(const M in d)!isNaN(d[M])&&Number(d[M])!==1/0&&(d[M]=Number(d[M]));const{labelCn:l,labelEn:u}=await this.parseStatus(d.aisNavStatus),y=g.unix(d.posTime);return{...n,mmsi:t,lat:Math.round(d.lat/1e4/60*1e5)/1e5,lng:Math.round(d.lon/1e4/60*1e5)/1e5,sog:Math.round(d.sog/10*100)/100,cog:Math.round(d.cog/10*100)/100,hdg:Math.round(d.heading*100)/100,rot:Math.round(d.rot*100)/100,positionTime:d.posTime,utc:y.utc().format(),status:d.aisNavStatus,labelEn:u,labelCn:l,method:"position",vendor:"myship"}}async trajectory(t,a,i,n,o=!0,e={}){const r=g(a),d=g(i),l=await this.getShipId(t),u=await this.getShipInfo(l),y=[];for(;d.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(l,r.unix(),r.add(30,"day").unix(),u,t,n,y);return await this.trajectoryIn30Day(l,r.unix(),d.unix(),u,t,n,y),y}async trajectoryIn30Day(t,a,i,n,o,e,r,d={}){var S;const l={headers:{appKey:this.token},json:{shipId:t,startTime:a,endTime:i}},u="https://api3.myships.com/sp/ships/position/history",y=await A.post(u,l).json();if(m==null||m.info("[%s] fetch trajectory from: %s - %j",d.requestId,u,l),y.code!=="0")return m==null||m.warn("[%s] invoke myship trajectory failed: %j",d.requestId,y),y;const v=y.data;for(const w in v)!isNaN(v[w])&&Number(v[w])!==1/0&&(v[w]=Number(v[w]));const M=g.unix((S=v[0])==null?void 0:S.posTime);let C=-1;for(const w of v){const b=g.unix(w.posTime),c={imo:n==null?void 0:n.imo,mmsi:o,lat:Math.round(w.lat/1e4/60*1e5)/1e5,lng:Math.round(w.lon/1e4/60*1e5)/1e5,sog:Math.round(w.sog/10*100)/100,cog:Math.round(w.cog/10*100)/100,hdg:Math.round(w.heading*100)/100,rot:Math.round(w.rot*100)/100,positionTime:b.unix(),utc:b.utc().format(),method:"trajectory",vendor:"myship"},p=Math.floor(b.diff(M,"minute",!0)/(e||1));p!==C&&(C=p,r.push(c))}return r}}let _;try{_=U.getLogger("vessel")}catch{}finally{}var ct=(D=>(D.NOTICE="NOTICE",D.WARN="WARN",D.HEAVY="HEAVY",D.SEVERE="SEVERE",D.ERROR="ERROR",D.FATAL="FATAL",D))(ct||{});class dt{parsePrinciple(s,t={}){var e,r,d;_==null||_.debug("[%s] parse rule: %s",t.requestId,s);const a=new RegExp("(?<=\\[)(.+)(?=])","g"),i=s.match(a)?(e=s.match(a))==null?void 0:e[0]:void 0,n=i==null?void 0:i.split(";");if(!n)return;const o={};for(let l=0;l<(n==null?void 0:n.length);l++){const u=(d=(r=n[l].match(a))==null?void 0:r[0])==null?void 0:d.split("],");if(l===0&&!u)o.scope=n[0];else if(u)for(let y=0,v=u.length;y<v;y++){const M=this.parseRule(u[y]);M&&(o[M.level]?M.key?o[M.level][M==null?void 0:M.key]=M:o[M.level]=M:M.key?o[M.level]={[M==null?void 0:M.key]:M}:o[M.level]=M)}}return o}parseRule(s,t={}){var o;_==null||_.debug("[%s] parse rule: %s",t.requestId,s),s=s.startsWith("[")?s:`[${s}`,s=s.endsWith("]")?s:`${s}]`;const a=new RegExp("(?<=\\[)(.+?)(?=])","g"),i=(o=s==null?void 0:s.match(a))==null?void 0:o[0],n=i==null?void 0:i.split(",");if(n){let e=n[3]==="Number.MAX_VALUE"?100:Number(n[3]);return e=isNaN(e)?1:e,{operator:n[0],number:Number.isNaN(Number(n[1]))?n[1]:Number(n[1]),level:n[2],time:e,key:n[4]}}}checkWeather(s,t,a={}){var M,C,S,w,b,c,p,f,h,k,j,x,Y,F,L;let i=0,n=0,o=0,e=0;const r=Math.round(((C=(M=t==null?void 0:t.SEVERE)==null?void 0:M.sigWave)==null?void 0:C.number)*1.6*100)/100,d=(w=(S=t==null?void 0:t.SEVERE)==null?void 0:S.sigWave)==null?void 0:w.number,l=(c=(b=t==null?void 0:t.HEAVY)==null?void 0:b.sigWave)==null?void 0:c.number,u=Math.round((((f=(p=t==null?void 0:t.SEVERE)==null?void 0:p.wind)==null?void 0:f.number)+2)*100)/100,y=(k=(h=t==null?void 0:t.SEVERE)==null?void 0:h.wind)==null?void 0:k.number,v=(x=(j=t==null?void 0:t.HEAVY)==null?void 0:j.wind)==null?void 0:x.number;for(let H=0;H<(s==null?void 0:s.length);H++){const E=s[H],P=(F=(Y=E==null?void 0:E.meteo)==null?void 0:Y.wave)==null?void 0:F.sig,V=(L=E==null?void 0:E.meteo)==null?void 0:L.wind,J=H?g(E.eta).diff(g(s[H-1].eta),"hour",!0):0;e=J>e?J:e,_==null||_.debug("[%s] check sig.wave: %j",a.requestId,{...P,dgThd4Wv:r,svThd4Wv:d,hvThd4Wv:l}),(P==null?void 0:P.height)>=r?E.isDangerous=!0:(P==null?void 0:P.height)>=d?E.isSevere=!0:(P==null?void 0:P.height)>=l&&(E.isHeavy=!0),_==null||_.debug("[%s] check wind: %j",a.requestId,{...V,dgThd4Wd:u,svThd4Wd:y,hvThd4Wd:v}),(V==null?void 0:V.scale)>=u?(E.isDangerous=!0,delete E.isSevere,delete E.isHeavy):(V==null?void 0:V.scale)>y?(E.isDangerous||(E.isSevere=!0),delete E.isHeavy):(V==null?void 0:V.scale)===v&&!E.isDangerous&&!E.isSevere&&(E.isHeavy=!0),i+=E.isDangerous?J:0,n+=E.isSevere?J:0,o+=E.isHeavy?J:0}return i=Math.round(i*100)/100,n=Math.round(n*100)/100,o=Math.round(o*100)/100,e=Math.round(e),{sample:s,dangerous:i,severe:n,heavy:o,step:e<3?3:e,wind:{dgThd4Wd:u,svThd4Wd:y,hvThd4Wd:v},sig:{dgThd4Wv:r,svThd4Wv:d,hvThd4Wv:l}}}}const bt=new dt;let I;try{I=U.getLogger("vessel")}catch{}finally{}const vt=new ft.MeteoHelper2("",!0);var ut=(D=>(D.common="common",D.container="container",D.tugs="tugs",D))(ut||{}),lt=(D=>(D.Ballast="Ballast",D.Laden="Laden",D))(lt||{}),ht=(D=>(D.Cp="CP",D.Perf="Basis",D.Instruct="Other",D))(ht||{});class W{static blockCoefficient(s,t,a,i){let n=Math.round(s/(t*a*i)*100)/100;n=n<.55?.55:n>.85?.85:n;const o=[.55,.6,.65,.7,.75,.8,.85],e=o.map(r=>Math.abs(r-n));return o[e.indexOf(Math.min(...e))]}static froudeNumber(s,t,a=9.8){let i=Math.round(Math.sqrt(s*s/(a*t))*100)/100;return i=i<.05?.05:i>.3?.3:i,i}static amendFactor(s,t,a){const i={.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 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.6,-12.5,-13.5],.8:[3,-16.3,-21.6],.85:[3.4,-20.9,31.8]}[s];return a==="Laden"&&(o=i[s]),o[0]+o[1]*t+o[2]*Math.pow(t,2)}static directionFactor(s,t=0){let a;return s>30&&s<=60?a=(1.7-.03*Math.pow(t-4,2))/2:s>60&&s<=150?a=(.9-.06*Math.pow(t-6,2))/2:s>150&&s<=180?a=(.4-.03*Math.pow(t-8,2))/2:a=1,Math.round(a*1e5)/1e5}static vesselTagFactor(s,t,a,i){let n;return a==="container"?n=.7*i/2+Math.pow(i,3)/(22*Math.pow(s,2/3)):t==="Ballast"?n=.7*i/2+Math.pow(i,3)/(2.7*Math.pow(s,2/3)):n=.5*i/2+Math.pow(i,3)/(2.7*Math.pow(s,2/3)),n}static waveHeightFactor(s,t){s=s<3?s*.7:s,s=s<0?.2:s,s=s>6?s-.9*(s-6):s,s=s>9?9:s;let a;return t>30&&t<=60?a=-.6:t>60&&t<=90?a=-.4:t>90&&t<=120?a=s<3?.4:-.3:t>120&&t<=150?a=s<3?.6:-.5:t>150&&t<=180?a=s<3?.7:-.6:a=-.7,Math.round(a*(.144*Math.pow(s,2)+.278*s)*1e4)/1e4}static assembleProperties(s,t,a,i){var y;const n=s.lbp??s.length??s.lengthOverall??198.9642,o=s.draught??8,e=s.breadthMoulded??s.breadth??s.breadthExtreme??32.4572,r=s.deadweight??67035.7773,d=((y=s==null?void 0:s.type)==null?void 0:y.toLowerCase())||"common";return{tag:d.indexOf("container")>-1?"container":d.indexOf("tugs")>-1?"tugs":"common",lbp:n,loadCondition:t,draught:o,breadthMoulded:e,displacement:Math.round((r/1.025+o*e*n*.7)*1e4)/1e4,speed:Math.round((a??14.1382)*1852/3600*1e4)/1e4,bearing:i||90}}static async speedLoseAt(s,t,a,i="",n=2,o=!0,e=!1,r={}){let d;if(t.velocity&&e&&(s.speed=N.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),o){let l;try{i=(i==null?void 0:i.toUpperCase())==="CMEMS"?"ECMWF":i,i=(i==null?void 0:i.toUpperCase())==="METEO2"?"best_match":i;const{weatherModels:M,marineModels:C}=await nt.Meteo2Assist.autoPickMeteoModel(i),S=await vt.spotForecast(t.lat,t.lng,a.utc().format(),!1,!1,!0,{...r,pastDays:1,forecastDays:1,weatherModels:M,marineModels:C}),[w]=nt.Meteo2Assist.pickHourly(S,a);l=nt.Meteo2Assist.toLegacy(w)}catch(M){I.warn("[%s] meteo2 spot(%j) forecast failed: %s",r.requestId,{...t,eta:a.utc().format(),source:i},M)}const u=W.currentFactor(s.bearing,l==null?void 0:l.current,n),y=W.weatherFactor(s,l,u),v=Math.round(s.speed*1.943844*100)/100;d={meteo:{...l},wxFactor:y,cFactor:u,speed:t.velocity&&e?t.velocity:v<0?1:v,eta:a.utc().format(),etd:a.utc().format()}}else d={wxFactor:0,cFactor:0,speed:t.velocity&&e?t.velocity:Math.round(s.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,{...d,...t}}static async speedLoseInHoursStep(s,t,a,i,n,o,e="",r=!0,d=!1,l={}){t.utc();const u=t.clone().add(14,"days"),y=[],v=[];let M=0,C=0,S,w;for(let b=0;b<o.length-1;b++){let c=o[b];c.distanceFromStart=Math.round((n+C)*1e3)/1e3;const p=o[b+1];if(s.bearing=N.LaneHelper.calculateBearing(c,p,!p.gcToPrevious),c.bearing=s.bearing,c.suspend&&d){c.eta=c.eta||t.utc().format(),c.elapsed=c.elapsed??0;const k=c.suspend-c.elapsed;if(i-M>k)i=i-M-k,t.add(k,"hour"),c.elapsed=c.suspend;else{const j=i-M;c.elapsed+=j,t.add(j,"hour"),i=0}if(I==null||I.info(`[%s] suspend ${c.elapsed} hours at %j, and remain ${i} hours need to go...`,l.requestId,c),i===0)return c.distanceFromPrevious=C,{etd:t,from:w||c,to:c,next:o.filter(j=>j),wps:y,days:v}}else c.suspend=0;r=t.isAfter(u)?!1:r,c=await W.speedLoseAt(s,c,t,e,0,r,d,l),w=w||c,c.important&&y.push(c),t.isSameOrAfter(a)&&(v.push(c),a.add(24,"hour"));const f=N.LaneHelper.calculateDistance(c,p,!p.gcToPrevious);let h=Math.round(f/w.speed*1e5)/1e5;if(M+h<i){if(M+=h,t.add(h,"hour"),delete o[b],I==null||I.debug(`[%s] go to %j from %j with ${f}nm, and cost ${h} hours`,l.requestId,{lat:p.lat,lng:p.lng},{lat:w.lat,lng:w.lng,etd:w.etd}),C+=f,o.filter(k=>k).length<=1){S=p,S.eta=t.utc().format(),S.distanceFromPrevious=f,S.distanceFromStart=Math.round((n+C)*1e4)/1e4,y.push(S),delete o[b+1];break}}else{h=i-M,t.add(h,"hour");const k=N.LngLatHelper.roundPrecision(w.speed*h,5);S=N.LaneHelper.calculateCoordinate(c,s.bearing,k,"nauticalmiles",!p.gcToPrevious),S.eta=t.utc().format(),o[b]=S,I==null||I.debug(`[%s] go to %j from %j with ${k}nm, and cost ${h} hours`,l.requestId,{lat:S.lat,lng:S.lng},{lat:c.lat,lng:c.lng,etd:c.etd}),C+=k,S.distanceFromPrevious=Math.round(C*1e4)/1e4,S.distanceFromStart=Math.round((n+C)*1e4)/1e4;break}}return{etd:t,from:w,to:S,next:o.filter(b=>b),wps:y,days:v}}static currentFactor(s,t,a=0){const i=(s-(t==null?void 0:t.degree)||0)/180*Math.PI;if(Math.abs(i)===Math.PI/2)return 0;let n=((t==null?void 0:t.kts)||0)*Math.cos(i);return a&2?n=Math.ceil(n*100)/100:a&1?n=Math.floor(n*100)/100:n=Math.round(n*100)/100,Math.abs(n)>5?0:n}static weatherFactor(s,t,a=0){var v,M,C,S,w,b,c;I==null||I.debug("calculate weather factor via: %j",{...s,...t});const i=W.blockCoefficient(s.displacement,s.lbp,s.breadthMoulded,s.draught),n=N.LngLatHelper.roundPrecision(a*1852/3600,6),o=W.froudeNumber(s.speed-n,s.lbp),e=W.amendFactor(i,o,s.loadCondition);let r=Math.abs(s.bearing%360-(((v=t==null?void 0:t.wind)==null?void 0:v.degree)%360||0));r=r>180?360-r:r;const d=W.directionFactor(r,(M=t==null?void 0:t.wind)==null?void 0:M.scale),l=W.vesselTagFactor(s.displacement,s.loadCondition,s.tag,(C=t==null?void 0:t.wind)==null?void 0:C.kts);let u=d*e*l/100*(s.speed-n);u=Math.round(u*1.943844*1e4)/1e4*-1,s.tag==="tugs"&&Math.abs(u)>1&&(u=u/(Math.abs(Math.round(u))+1)),I==null||I.debug("wind wx factor = %d",u),r=Math.abs(s.bearing%360-(((w=(S=t==null?void 0:t.wave)==null?void 0:S.sig)==null?void 0:w.degree)%360||0));const y=W.waveHeightFactor(((c=(b=t==null?void 0:t.wave)==null?void 0:b.sig)==null?void 0:c.height)??1,r);return I==null||I.debug("wave wx factor = %d",y),u=Math.abs(u)>Math.abs(y)?u:u*.3+y*.7,I==null||I.debug("weather factor = %d",u),u=Math.abs(u)>3?3*(Math.abs(u)/u)+Math.abs(u)/u*(Math.abs(u)-2)*.1:u,Math.round((u||0)*100)/100}static async analyseInstant(s,t,a,i,n,o="",e=0,r=!0,d=!1,l={}){var X,Q,Z,$,tt,et;const u=g().valueOf();s.lng=N.LngLatHelper.convertToStdLng(s.lng);const{route:y,waypoints:v}=n.points,M=N.LaneHelper.calculateSubRoute(s,y);if(((X=M[0])==null?void 0:X.length)<=1)return;const{v0:C,label:S}=s.sog?{v0:s.sog,label:s.label||"Other"}:{v0:i.speed,label:"CP"},w=W.assembleProperties(a,i.loadCondition,C,0),b=v.length?N.LaneHelper.calculateSubWaypoints(s,v):[];b.forEach(O=>O.important=!0);const c={from:{...s},route:M,waypoints:b,v0:C,label:S},p={hours:[],days:[],wps:[]};e||(N.LaneHelper.calculateRouteDistance(M)/i.speed<=72?e=3:e=6);let f=N.LaneHelper.simplifyRouteToCoordinates(M,b,0),h=0,k=0,j=0,x=0;t=g(t).utc();const Y=t.clone();for(;f.length>0;){const O=e-t.hour()%e,z=Math.ceil(t.clone().add(O,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,T=await W.speedLoseInHoursStep(w,t,Y,z,h,f,o,r,d,l);if((Q=T.from)!=null&&Q.speed&&(p.hours.push(T.from),p.wps.push(...T.wps),p.days.push(...T.days)),f=T==null?void 0:T.next,!f.length){const B=await W.speedLoseAt(w,T.to,g(T.to.eta),o,0,r,d,l);p.hours.push(B)}h+=Math.round((((Z=T==null?void 0:T.to)==null?void 0:Z.distanceFromPrevious)??0)*1e4)/1e4}const F=p.hours;for(let O=0;O<F.length-1;O++){const z=g(F[O+1].eta).diff(F[O].etd,"hour",!0)||1;k+=(F[O].wxFactor||0)*z,j+=(F[O].cFactor||0)*z,x+=z}($=p.wps)==null||$.forEach((O,z)=>{O.positionTime=g.utc(O.etd||O.eta).unix();const T=p.wps[z-1];if(T){const B=O.distanceFromStart-T.distanceFromStart,R=g(O.eta||O.etd).diff(g(T.etd||T.eta),"h",!0);O.avgSpd=Math.round(B/R*100)/100,T.bearing=N.LaneHelper.calculateBearing(T,O)}}),p.wps=(tt=p.wps)==null?void 0:tt.reduce((O,z)=>(O.some(T=>Math.round(T.positionTime/60)===Math.round(z.positionTime/60))||O.push(z),O),[]),c.sample=p;const L=p.hours.at(0),H=p.hours.at(-1);c.distance=Math.round(H.distanceFromStart*1e3)/1e3,c.etd=g(L.eta).utc().format(),c.eta=g(H.eta).utc().format(),c.wxFactor=Math.round(k/x*1e3)/1e3,c.cFactor=Math.round(j/x*1e3)/1e3,c.avgSpeed=Math.round(H.distanceFromStart/x*1e3)/1e3,c.totalHrs=Math.round(x*1e3)/1e3;const{distanceInECA:E,hoursInECA:P,totalDgoConsInECA:V,eca:J}=await this.calculateECA(c,i,l),st=N.LngLatHelper.roundPrecision(i.fo/24*(x-P),3),ot=N.LngLatHelper.roundPrecision(i.dgo/24*x,3);c.extend={eca:J,distanceInECA:E,hoursInECA:P,totalDgoConsInECA:V},c.totalFoCons=st<0?0:st,c.totalDgoCons=ot;const at=g().valueOf()-u,rt=((et=p==null?void 0:p.hours)==null?void 0:et.length)||1;return I==null||I.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",l==null?void 0:l.requestId,at,rt,Math.round(at/rt*1e3)/1e3),c}static async analyseInstantWithThreshed(s,t,a,i,n,o,e,r="",d=3,l=!0,u=!1,y={}){var Z,$,tt,et,O,z;const v=g().valueOf();s.lng=N.LngLatHelper.convertToStdLng(s.lng);const{v0:M,label:C}=s.sog?{v0:s.sog,label:s.label||"Other"}:{v0:n.speed,label:"CP"},S=W.assembleProperties(i,n.loadCondition,M,0),w=N.LaneHelper.calculateSubRoute(s,o);if(((Z=w[0])==null?void 0:Z.length)<=1)return;const b=e.length?N.LaneHelper.calculateSubWaypoints(s,e):[];b.forEach(T=>T.important=!0);let c=N.LaneHelper.simplifyRouteToCoordinates(w,b,0),p=0,f=0,h=0,k=0;const j={hours:[],wps:[],days:[]};t=g(t).utc();const x=t.clone();for(;c.length>0;){const T=d-t.hour()%d;let B=Math.ceil(t.clone().add(T,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;B=t.clone().add(B,"h").isSameOrAfter(a)?a.diff(t,"h",!0)*1e4/1e4:B;const R=await W.speedLoseInHoursStep(S,t,x,B,p,c,r,l,u,y);if(($=R.from)!=null&&$.speed&&(j.hours.push(R.from),R!=null&&R.wps&&j.wps.push(...R.wps),j.days.push(...R.days)),c=R==null?void 0:R.next,c.length||j.hours.push(R==null?void 0:R.to),p+=Math.round((((tt=R==null?void 0:R.to)==null?void 0:tt.distanceFromPrevious)??0)*1e4)/1e4,!B)break}j.wps=(et=j.wps)==null?void 0:et.reduce((T,B)=>(T.some(R=>Math.round(g(R.etd).unix()/60)===Math.round(g(B.etd).unix()/60))||T.push(B),T),[]),(O=j.wps)==null||O.forEach((T,B)=>{const R=j.wps[B-1];if(R){const gt=T.distanceFromStart-R.distanceFromStart,wt=g(T.eta||T.etd).diff(g(R.etd||R.eta),"h",!0);T.avgSpd=Math.round(gt/wt*100)/100;const kt=N.LaneHelper.calculateBearing(R,T);R.bearing=kt}});const Y=j.hours;for(let T=0;T<Y.length-1;T++){const B=g(Y[T+1].eta).diff(Y[T].etd,"hour",!0);f+=Y[T].wxFactor*B,h+=Y[T].cFactor*B,k+=B}const F=j.hours.at(0),L=j.hours.at(-1),H=await N.LaneHelper.calculateRangeRoute(F,L,w),E=await N.LaneHelper.calculateRangeWaypoints(F,L,w,b),P={sample:j,distance:Math.round(((L==null?void 0:L.distanceFromStart)||0)*1e4)/1e4,etd:g(F.eta).utc().format(),eta:g(L==null?void 0:L.eta).utc().format(),wxFactor:Math.round(f/k*1e3)/1e3,cFactor:Math.round(h/k*1e3)/1e3,avgSpeed:Math.round(((L==null?void 0:L.distanceFromStart)||0)/k*1e3)/1e3,totalHrs:Math.round(k*1e3)/1e3,from:F,to:L,route:H,waypoints:E,v0:M,label:C},{distanceInECA:V,hoursInECA:J,totalDgoConsInECA:st,eca:ot}=await this.calculateECA(P,n,y),it=N.LngLatHelper.roundPrecision(n.fo/24*(k-J),3),at=N.LngLatHelper.roundPrecision(n.dgo/24*k,3);P.extend={eca:ot,distanceInECA:V,hoursInECA:J,totalDgoConsInECA:st},P.totalDgoCons=at,P.totalFoCons=it<0?0:it;const X=g().valueOf()-v,Q=((z=j==null?void 0:j.hours)==null?void 0:z.length)||1;return I==null||I.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",y==null?void 0:y.requestId,X,Q,Math.round(X/Q*1e3)/1e3),P}static async analyseCost(s,t,a,i,n={}){var w,b;const o=g().valueOf(),e=[];s.speedStep=s.speedStep||3,s.alterStep=s.alterStep??1;const r=N.LaneHelper.calculateRouteDistance(i.route);let d=0;a.forEach(c=>{const p=Math.ceil(r/c.speed/24);d=d<p?p:d}),d=d*1.3;const l=g.utc(s.etd).add(d??14,"day");let u=1;for(const c of a){const p=JSON.parse(JSON.stringify(i.route)),f=JSON.parse(JSON.stringify(i.waypoints)),h=await W.analyseInstantWithThreshed({lat:s.lat,lng:s.lng},s.etd,l,t,c,p,f,s.meteoVendor,s.speedStep,s.useMeteo,s.useRouteParam,n);h&&(await W.calculateCost(h,c,s,n),e.push(h),I==null||I.info("[%s][L%d-%d] analyse from %s to %s cost: %j",n.requestId,1,u,s.etd,l.format(),{cost:h.cost.total,hire:h.cost.hire,bunker:h.cost.bunker,distance:h.distance,hours:h.totalHrs,cp:`${c.speed}/${c.fo}/${c.dgo}`})),u++}e.sort((c,p)=>c.cost.total-p.cost.total);const y=e.at(0),v=e.at(1),M=[];if(M.push({combined:!1,speeds:[y],cost:(w=y.cost)==null?void 0:w.total}),v){const c=y.cost.cp,p=v.cost.cp,f=g(y.eta),h=g(y.etd),k=f.diff(h,"days",!0);let j=Math.ceil(k/2);j=j>7?7:j<s.alterStep?s.alterStep:j;let x=2,Y={combined:!1,speeds:[v],cost:(b=v.cost)==null?void 0:b.total},F;for(;j>=s.alterStep;){const L=await W.combinedAnalyse(s,t,l,[c,p],i,j,{...n,level:x});if(Y.cost>L.cost?F?(F==null?void 0:F.cost)>L.cost&&(F=L):(F=Y,Y=L):(!F||(F==null?void 0:F.cost)>L.cost)&&(F=L),j<=s.alterStep)break;j=Math.ceil(j/2),x+=1}M.push(Y),F&&M.push(F)}const S=g().valueOf()-o;return I==null||I.info("[%s] analyse elapsed: %d ms",n==null?void 0:n.requestId,S),M.sort((c,p)=>c.cost-p.cost)}static async combinedAnalyse(s,t,a,i,n,o,e={}){e.counter=1,I==null||I.info("[%s][L%d] analyse with alternate cp in every %d days",e.requestId,e.level,o);const r=await W.alternateAnalyse(s,t,a,i,0,n,o,e),d=r.reduce((p,f)=>p+f.cost.total,0),l=r.reduce((p,f)=>p+f.cost.hire,0),u=r.reduce((p,f)=>p+f.cost.bunker,0),y=r.reduce((p,f)=>p+f.distance,0),v=r.reduce((p,f)=>p+f.totalHrs,0);I==null||I.info("[%s][L%d] cost with cpa/cpb turn: %j",e.requestId,e.level,{cost:d,hire:l,bunker:u,distance:y,hours:v});const M=await W.alternateAnalyse(s,t,a,i,1,n,o,e),C=M.reduce((p,f)=>p+f.cost.total,0),S=M.reduce((p,f)=>p+f.cost.hire,0),w=M.reduce((p,f)=>p+f.cost.bunker,0),b=M.reduce((p,f)=>p+f.distance,0),c=M.reduce((p,f)=>p+f.totalHrs,0);return I==null||I.info("[%s][L%d] cost with cpb/cpa turn: %j",e.requestId,e.level,{cost:C,hire:S,bunker:w,distance:b,hours:c}),d<C?{combined:!0,cost:Math.round(d*1e3)/1e3,speeds:r,step:o}:{combined:!0,cost:Math.round(C*1e3)/1e3,speeds:M,step:o}}static async alternateAnalyse(s,t,a,i,n,o,e,r={}){var y,v;let d=g.utc(s.etd);const l={lat:s.lat,lng:s.lng},u=[];for(;d.isBefore(a);){const M=d.clone().utc().add(e,"day"),C=JSON.parse(JSON.stringify(o.route)),S=JSON.parse(JSON.stringify(o.waypoints)),w=i[n],b=await W.analyseInstantWithThreshed(l,d.utc().format(),M,t,w,C,S,s.meteoVendor,s.speedStep,s.useMeteo,s.useRouteParam,r);b&&(await W.calculateCost(b,w,s,r),I==null||I.info("[%s][L%d-%d] analyse from %s to %s cost: %j",r.requestId,r.level,r.counter,d.utc().format(),M.utc().format(),{cost:b.cost.total,hire:b.cost.hire,bunker:b.cost.bunker,distance:b.distance,hours:b.totalHrs,cp:`${w.speed}/${w.fo}/${w.dgo}`})),r.counter=r.counter+1;const c=(v=(y=b==null?void 0:b.sample)==null?void 0:y.hours)==null?void 0:v.at(-1);if(c)l.lat=c.lat,l.lng=c.lng,d=g(c.eta),u.push(b),n=n?0:1;else break}return u}static async calculateCost(s,t,a,i={}){var n;if(s){const o=(a.addComm||0)>=1?(a.addComm||0)/100:a.addComm||0,e=Math.round(s.totalHrs/24*(a.dailyHire||0)*(1-o)*1e3)/1e3,r=Math.round(s.totalFoCons*(a.priceFO||0)*1e3)/1e3,d=Math.round((s.totalDgoCons+(((n=s.extend)==null?void 0:n.totalDgoConsInECA)||0))*(a.priceDGO||0)*1e3)/1e3;s.cost={total:Math.round((e+r+d)*1e3)/1e3,hire:e,bunker:Math.round((r+d)*1e3)/1e3,cp:t}}return s}static async calculateECA(s,t,a={}){var r,d,l,u;const i=await N.LaneHelper.intersectInECA((s==null?void 0:s.route)||[]);let n=0,o=0,e=0;(d=(r=s==null?void 0:s.sample)==null?void 0:r.wps)==null||d.forEach(y=>{y.positionTime=g.utc(y.etd||y.eta).unix()});for(const y of i){n+=y.distance;const v=await N.LaneHelper.deadReckoningTime((l=y.waypoints)==null?void 0:l.at(0),s.sample.wps),M=await N.LaneHelper.deadReckoningTime((u=y.waypoints)==null?void 0:u.at(-1),s.sample.wps);y.in=v,y.out=M,y.totalHrs=N.LngLatHelper.roundPrecision((M.positionTime-v.positionTime)/3600,3),y.totalDgoCons=N.LngLatHelper.roundPrecision(t.fo/24*y.totalHrs,3),o+=y.totalHrs,e+=y.totalDgoCons}return n=N.LngLatHelper.roundPrecision(n,3),o=N.LngLatHelper.roundPrecision(o,3),e=N.LngLatHelper.roundPrecision(e,3),{distanceInECA:n,hoursInECA:o,totalDgoConsInECA:e,eca:i}}static async mergeSpeeds(s,t={}){var c,p;const a={hours:[],wps:[],days:[]},i=s.reduce((f,h)=>f+h.distance,0),n=s.reduce((f,h)=>{var k;return f+(((k=h.extend)==null?void 0:k.distanceInECA)||0)},0),o=s.reduce((f,h)=>f+h.totalHrs,0),e=s.reduce((f,h)=>{var k;return f+(((k=h.extend)==null?void 0:k.hoursInECA)||0)},0),r=s.reduce((f,h)=>{var k;return f+(((k=h.extend)==null?void 0:k.totalDgoConsInECA)||0)},0),d=s.reduce((f,h)=>f+h.wxFactor*h.totalHrs/o,0),l=s.reduce((f,h)=>f+h.cFactor*h.totalHrs/o,0),u=s.reduce((f,h)=>f+h.totalFoCons,0),y=s.reduce((f,h)=>f+h.totalDgoCons,0),v=s.reduce((f,h)=>f+h.cost.total,0),M=s.reduce((f,h)=>f+h.cost.hire,0),C=s.reduce((f,h)=>f+h.cost.bunker,0),S=[],w=[];let b;for(const f of s){w.push(...((c=f.extend)==null?void 0:c.eca)||[]);const h=f.sample.hours,k=f.sample.wps,j=f.sample.days,x=h.at(0);b&&(x.distanceFromPrevious=b.distanceFromPrevious,x.distanceFromStart=b.distanceFromStart,h.forEach((H,E)=>{E&&(H.distanceFromStart=H.distanceFromStart+b.distanceFromStart)}),k.at(0).distanceFromPrevious=b.distanceFromPrevious,k.at(0).distanceFromStart=b.distanceFromStart,k.forEach((H,E)=>{E&&(H.distanceFromStart=H.distanceFromStart+b.distanceFromStart)}),j.at(0).distanceFromPrevious=b.distanceFromPrevious,j.at(0).distanceFromStart=b.distanceFromStart,j.forEach((H,E)=>{E&&(H.distanceFromStart=H.distanceFromStart+b.distanceFromStart)})),x.cp=f.cost.cp;const Y=[f.etd,f.eta],F=S.findIndex(H=>H.id===x.cp.id);F===-1?(x.cp.segment=[Y],S.push(x.cp)):S[F].segment.push(Y),h.forEach(H=>{var P;((P=a.hours)==null?void 0:P.findIndex(V=>V.eta===H.eta))===-1&&a.hours.push(H)}),k.forEach(H=>{var P;((P=a.wps)==null?void 0:P.findIndex(V=>V.eta===H.eta))===-1&&a.wps.push(H)}),j.forEach(H=>{var P;((P=a==null?void 0:a.days)==null?void 0:P.findIndex(V=>V.eta===H.eta))===-1&&a.days.push(H)});const L=(p=a.wps)==null?void 0:p.findIndex(H=>H.eta===x.eta);L===-1?a.wps.push(x):a.wps[L]=x,b=h.at(-1)}return a.wps.sort((f,h)=>{g(f.etd).unix()-g(h.etd).unix()}),a.wps.forEach((f,h)=>{const k=a.wps[h-1];if(k){const j=f.distanceFromStart-(k.distanceFromStart||0),x=g(f.eta||f.etd).diff(g(k.etd||k.eta),"hour",!0),Y=Math.round(j/x*100)/100;f.avgSpd=Y;const F=N.LaneHelper.calculateBearing(k,f);k.bearing=F}}),{sample:a,etd:s.at(0).etd,eta:s.at(-1).eta,from:s.at(0).from,to:s.at(-1).to,v0:s.at(0).v0,label:"Combined",distance:Math.round(i*1e3)/1e3,totalHrs:Math.round(o*1e3)/1e3,avgSpeed:Math.round(i/o*1e3)/1e3,wxFactor:Math.round(d*1e3)/1e3,cFactor:Math.round(l*1e3)/1e3,totalFoCons:Math.round(u*1e3)/1e3,totalDgoCons:Math.round(y*1e3)/1e3,cost:{total:Math.round(v*1e3)/1e3,hire:Math.round(M*1e3)/1e3,bunker:Math.round(C*1e3)/1e3},extend:{cps:S,eca:w,distanceInECA:Math.round(n*1e3)/1e3,hoursInECA:Math.round(e*1e3)/1e3,totalDgoConsInECA:Math.round(r*1e3)/1e3,speeds:s}}}}q.AISImpl=G,q.AlertHelper=dt,q.AlertLevel=ct,q.HifleetImpl=yt,q.LoadCondition=lt,q.MyShipImpl=pt,q.MyVesselImpl=mt,q.ShipxyImpl=Mt,q.SpeedHelper=W,q.SpeedLabel=ht,q.VesselTag=ut,q.alertHelper=bt,Object.defineProperty(q,Symbol.toStringTag,{value:"Module"})});
1
+ (function(q,A){typeof exports=="object"&&typeof module<"u"?A(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"],A):(q=typeof globalThis<"u"?globalThis:q||self,A(q["idm-plugin-vessel"]={},q.got,q["@log4js-node/log4js-api"],q.moment,q["@idm-plugin/geo2"],q["@idm-plugin/meteo2"],q["@idm-plugin/meteo"]))})(this,function(q,A,U,g,N,ft,nt){"use strict";var It=Object.defineProperty;var St=(q,A,U)=>A in q?It(q,A,{enumerable:!0,configurable:!0,writable:!0,value:U}):q[A]=U;var K=(q,A,U)=>(St(q,typeof A!="symbol"?A+"":A,U),U);let m;try{m=U.getLogger("vessel")}catch{}finally{}class G{parseStatus(s){let t,a;switch(s){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();K(this,"clientId");K(this,"clientSecret");K(this,"token");this.clientId=t,this.clientSecret=a}async authToken(t={}){const a="https://svc.data.myvessel.cn/ada/oauth/token",i={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},n=await A.post(a,i).json();m==null||m.info("[%s] fetch access token from: %s - %j",t.requestId,a,n),n.error||(this.token={accessToken:n.access_token,tokenType:n.token_type,expiresIn:n.expires_in,scope:n.scope,jti:n.jti,issuedAt:g().utc().format()})}async checkToken(t={}){var a;return(!this.token||g().diff(g(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 e,r;await this.checkToken(a);const i="https://market.myvessel.cn/sdc/v1/mkt/vessels/fuzzy",n={headers:{Authorization:`${(e=this.token)==null?void 0:e.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,i,n);const o=await A.post(i,n).json();return o.status!==200?(m==null||m.warn("[%s] fetch suggest vessels failed: %j",a.requestId,{message:o.message,status:o.status,code:o.code}),[]):(o.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 d,l;await this.checkToken(a);const i=/^\d{7}$/.test(t.toString()),n=i?"https://market.myvessel.cn/sdc/v1/mkt/vessels/detail/imo":"https://market.myvessel.cn/sdc/v1/mkt/vessels/detail/mmsi",o=i?{imo:t}:{mmsi:t},e={headers:{Authorization:`${(d=this.token)==null?void 0:d.tokenType} ${(l=this.token)==null?void 0:l.accessToken}`},searchParams:o};m==null||m.info("[%s] fetch vessel from: %s - %j",a.requestId,n,e);const r=await A.get(n,e).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 u=r.data;if(u)return{mmsi:u.mmsi,imo:Number.isNaN(u.imo)?null:Number(u.imo),callSign:u.callsign,name:u.nameEn,nameCn:u.nameCn,type:u.vesselTypeNameEn,flagName:u.flagCtry,clasz:u.classSociety,dateOfBuild:u.buildYearMonth,deadweight:u.dwt,grossTonnage:u.grt,netTonnage:u.net,teu:u.teu,length:u.length,breadth:u.width,height:u.height,draught:u.draught,speed:u.speed,passengerCapacity:u.passengercapacity,vendor:"myvessel",raw:u}}return{}}async archives(t,a={}){var e,r;await this.checkToken(a);const i="https://svc.data.myvessel.cn/sdc/v1/ship/info/batch",n={headers:{Authorization:`${(e=this.token)==null?void 0:e.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,i,n);const o=await A.post(i,n).json();return o.status!==200?(m==null||m.warn("[%s] fetch vessel archive failed: %j",a.requestId,{message:o.message,status:o.status,code:o.code}),{}):o.data}async realTimePosition(t,a={}){var r,d;await this.checkToken(a);const i="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",n={headers:{Authorization:`${(r=this.token)==null?void 0:r.tokenType} ${(d=this.token)==null?void 0:d.accessToken}`},searchParams:{mmsi:t}};m==null||m.info("[%s] fetch realtime position from: %s - %j",a.requestId,i,n);const o=await A.get(i,n).json();if(o.code)return m==null||m.warn("[%s] fetch realtime position failed: %j",a.requestId,{message:o.message,status:o.status,code:o.code}),o;const e=o.data;for(const l in e)!isNaN(e[l])&&Number(e[l])!==1/0&&(e[l]=Number(e[l]));if(e){const l=g(`${e.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:e.mmsi,name:e.vesselName||e.aisVesselName,imo:e.imo,callSign:e.callsign||e.aisCallSign,lat:e.lat,lng:e.lon,length:e.length,width:e.width,draught:e.currDraught,sog:e.sog,cog:e.cog,hdg:e.hdg,rot:e.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta)?g.utc(e.eta).format():void 0,destination:e.dest,positionTime:l.unix(),status:e.status,labelCn:e.statusNameCn,labelEn:e.statusNameEn,vesselType:e.vesselTypeNameEn,flag:e.flagCtryNameEn,clasz:e.classSociety,build:e.buildYear,dwt:e.dwt,grt:e.grt,net:e.net,method:"position",vendor:"myVessel",utc:l.utc().format()}}else return{}}async calculateRoute(t,a,i={}){var r,d;await this.checkToken(i);const n="https://svc.data.myvessel.cn/sdc/v1/routes/routing/nodes",o={headers:{Authorization:`${(r=this.token)==null?void 0:r.tokenType} ${(d=this.token)==null?void 0:d.accessToken}`},json:{startPoint:{lon:t.lng,lat:t.lat},endPoint:{lon:a.lng,lat:a.lat},maxDraught:i.maxDraught||10,useAIModel:i.useAIModel||!1,withECA:i.withECA||!1}};m==null||m.info("[%s] fetch route from: %s - %j",i.requestId,n,o);const e=await A.post(n,o).json();return e.status!==200?(m==null||m.warn("[%s] fetch route failed: %j",i.requestId,{message:e.message,status:e.status,code:e.code}),{}):e.data}async trajectory(t,a,i,n,o=!0,e={}){await this.checkToken(e);const r=await this.realTimePosition(t,e),d=g(a),l=g(i),u=[];for(;l.diff(d,"day",!0)>30;)await this.trajectoryIn30Day(t,d,d.clone().add(30,"day"),r,n,u,e),d.add(30,"day");return await this.trajectoryIn30Day(t,d,l,r,n,u,e),u}async trajectoryIn30Day(t,a,i,n,o,e,r={}){var M,C,S,w,b;const d="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",l={headers:{Authorization:`${(M=this.token)==null?void 0:M.tokenType} ${(C=this.token)==null?void 0:C.accessToken}`},json:{mmsi:t,startTime:a.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};m==null||m.info("[%s] fetch trajectory from: %s - %j",r.requestId,d,l);const u=await A.post(d,l).json();if(u.code)return m==null||m.warn("[%s] fetch trajectory failed: %j",r.requestId,d,{message:u.message,status:u.status,code:u.code}),u;let y=-1;const v=g(`${(w=(S=u.data)==null?void 0:S[0])==null?void 0:w.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(b=u.data)==null||b.forEach(c=>{for(const Y in c)!isNaN(c[Y])&&Number(c[Y])!==1/0&&(c[Y]=Number(c[Y]));const p=g(`${c.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),f=c.status,{labelCn:h,labelEn:k}=this.parseStatus(f),j={mmsi:c.mmsi,imo:n==null?void 0:n.imo,lat:c.lat,lng:c.lon,sog:c.sog,cog:c.cog,hdg:c.hdg,draught:c.draught,status:f,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(c.eta)?g(`${c.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").utc().format():void 0,destination:c.dest,positionTime:p.unix(),labelCn:h,labelEn:k,method:"trajectory",vendor:"myVessel",utc:p.utc().format()},x=Math.floor(p.diff(v,"minute",!0)/(o||1));x!==y&&(y=x,e.push(j))}),e}}class yt extends G{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,a={}){const i="https://api.hifleet.com/position/position/get/token",n={searchParams:{mmsi:t,usertoken:this.token}},o=await A.post(i,n).json();m==null||m.info("[%s] fetch realtime position from: %s - %j",a.requestId,i,n);const e=o==null?void 0:o.list;if(!e)return m==null||m.warn("[%s] fetch realtime position failed: %j",a.requestId,i,o),o;for(const v in e)!isNaN(e[v])&&Number(e[v])!==1/0&&(e[v]=Number(e[v]));e.status=e.sp>3?0:1;const r=e.status,{labelCn:d,labelEn:l}=this.parseStatus(r),u=g(`${e.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:e.m,name:e.n,imo:e.imonumber,callSign:e.callsign,lat:Math.round(e.la/60*1e5)/1e5,lng:Math.round(e.lo/60*1e5)/1e5,length:e.l,width:e.w,draught:e.draught,sog:e.sp,cog:e.co,hdg:e.h,rot:isNaN(e.rot)?0:e.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta)?g.utc(e.eta).format():void 0,destination:e.destination,vesselType:e.type,dwt:e.dwt,build:e.buildyear,flag:e.fn,positionTime:u.unix(),utc:u.utc().format(),status:r,labelCn:d,labelEn:l,method:"position",vendor:"hifleet"}}async search(t,a={}){let i="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const n={searchParams:{keyword:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let o=await A.post(i,n).json();m==null||m.info("[%s] fetch vessel props from: %s - %j",a.requestId,i,n),o instanceof Array&&(o=o[0]);for(const r in o)!isNaN(o[r])&&Number(o[r])!==1/0&&(o[r]=Number(o[r]));const e={mmsi:o.m,name:o.n,imo:o.i,callSign:o.c,length:o.l,breadth:o.b,draught:o.dr,type:o.t};return i="https://www.hifleet.com/hifleetapi/sameShipSearch.do",o=await A.post(i,n).json(),m==null||m.info("[%s] search vessel dead weight from: %s - %j",a.requestId,i,n),o instanceof Array&&(o=o[0]),o&&(e.deadweight=Number(o.dwt)),e}async suggest(t,a={}){const i="https://www.hifleet.com/hifleetapi/getShipSuggest.do",n={searchParams:{q:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}},o=await A.post(i,n).json();m==null||m.info("[%s] suggest vessel props from: %s - %j",a.requestId,i,n);const e=[];for(const r of o)e.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 e.sort((r,d)=>d.score-r.score),e}async trajectory(t,a,i,n,o=!0,e={}){var c,p,f;const r=await this.realTimePosition(t,e);let d=g(a);const l=g(i),u=g();if(o){let h=l.diff(d,"d",!0);h<0?d=l.clone().subtract(40,"d"):h<30?d.subtract(10,"d"):h<60?d.subtract(5,"d"):d=l.clone().subtract(80,"d"),h=u.diff(l,"d",!0),l.add(h>10?240:h*24,"h")}const y={searchParams:{endtime:l.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),starttime:d.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),mmsi:t,usertoken:this.token}},v="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",M=await A.get(v,y).json();m==null||m.info("[%s] fetch trajectory from: %s - %j",e.requestId,v,y);let C;M&&(C=((p=(c=M.ships)==null?void 0:c.offors)==null?void 0:p.ship)||[],C.length||m==null||m.warn("[%s] fetch trajectory failed: %j",e.requestId,M));const S=[];let w=-1;const b=g(`${(f=C==null?void 0:C[0])==null?void 0:f.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const h of C){for(const L in h)!isNaN(h[L])&&Number(h[L])!==1/0&&(h[L]=Number(h[L]));const k=g(`${h.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");h.status=h.sp>4?0:1;const{labelEn:j,labelCn:x}=this.parseStatus(h.status),Y={mmsi:h.m,name:h.n,imo:r==null?void 0:r.imo,lat:h.la,lng:h.lo,draught:h.draught,sog:h.sp,cog:h.co,hdg:h.hdg,positionTime:k.unix(),utc:k.utc().format(),status:h.status,labelCn:x,labelEn:j,method:"trajectory",vendor:"hifleet"},F=Math.floor(k.diff(b,"minute",!0)/(n||1));F!==w&&(w=F,S.push(Y))}return S}}class Mt extends G{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,a={}){const i={searchParams:{id:t,k:this.token,enc:1}},n="https://api.shipxy.com/apicall/GetSingleShip",o=await A.get(n,i).json();if(m==null||m.info("[%s] fetch realtime position from: %s - %j",a.requestId,n,i),(o==null?void 0:o.status)!==0)return o;const e=o.data[0];for(const y in e)!isNaN(e[y])&&Number(e[y])!==1/0&&(e[y]=Number(e[y]));const{labelCn:r,labelEn:d}=await this.parseStatus(e.navistat),l=g.unix(e.lasttime);return{mmsi:e.ShipID,name:e.name,imo:e.imo,callSign:e.callsign,lat:Math.round(e.lat/1e6*1e5)/1e5,lng:Math.round(e.lon/1e6*1e5)/1e5,length:Math.round(e.length/10*100)/100,width:Math.round(e.width/10*100)/100,draught:Math.round(e.draught/1e3*100)/100,sog:Math.round(e.sog*3600/1e3/1852*100)/100,cog:Math.round(e.cog/100*100)/100,hdg:Math.round(e.hdg/100*100)/100,rot:Math.round(e.rot/100*100)/100,positionTime:e.lasttime,utc:l.utc().format(),status:e.navistat,labelEn:d,labelCn:r,method:"position",vendor:"shipxy"}}async trajectory(t,a,i,n,o=!0,e={}){var b;const r=await this.realTimePosition(t,e),d=g(a),l=g(i),u="https://api.shipxy.com/apicall/GetShipTrack",y={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:d.unix(),etm:l.unix()}},v=await A.get(u,y).json();if(m==null||m.info("[%s] fetch trajectory from: %s - %j",e.requestId,u,y),(v==null?void 0:v.status)!==0)return v;const M=v==null?void 0:v.points,C=[],S=g.unix((b=M[0])==null?void 0:b.utc);let w=-1;for(const c of M){const p=g.unix(c.utc),f={imo:r==null?void 0:r.imo,mmsi:t,sog:Math.round(c.sog*3600/1e3/1852*100)/100,cog:Math.round(c.cog/100*100)/100,lat:Math.round(c.lat/1e6*1e5)/1e5,lng:Math.round(c.lon/1e6*1e5)/1e5,positionTime:p.unix(),utc:p.utc().format(),method:"trajectory",vendor:"shipxy"},h=Math.floor(p.diff(S,"minute",!0)/(n||1));h!==w&&(w=h,C.push(f))}return C}}class pt extends G{constructor(t){super();K(this,"token");this.token=t}async getShipId(t,a={}){const i={headers:{appKey:this.token},json:{mmsiList:t}},n="https://api3.myships.com/sp/ships/getShipIdByMMSI",o=await A.post(n,i).json();return m==null||m.info("[%s] fetch ship id from: %s - %j",a.requestId,n,i),o.code!=="0"?o:o.data[0].shipId}async getShipInfo(t,a={}){const i={headers:{appKey:this.token},json:{shipId:t}},n="https://api3.myships.com/sp/ships/aissta",o=await A.post(n,i).json();if(m==null||m.info("[%s] fetch ship info from: %s - %j",a.requestId,n,i),o.code!=="0")return o;const e=o.data;let r=e.imo;return t==="407170"&&(r="9198379",m==null||m.warn("[%s] ship(%s) imo error: %s, should be %s",a.requestId,t,e.imo,r)),{mmsi:e.mmsi,name:e.shipnameEn,imo:r,callSign:e.callSign,length:e.length,width:e.breadth,draught:(e.draught||100)/10}}async realTimePosition(t,a={}){const i=await this.getShipId(t,a),n=await this.getShipInfo(i,a),o={headers:{appKey:this.token},json:{shipId:i}},e="https://api3.myships.com/sp/ships/position/latest",r=await A.post(e,o).json();m==null||m.info("[%s] fetch realtime position from: %s - %j",a.requestId,e,o);const d=r.data[0];for(const M in d)!isNaN(d[M])&&Number(d[M])!==1/0&&(d[M]=Number(d[M]));const{labelCn:l,labelEn:u}=await this.parseStatus(d.aisNavStatus),y=g.unix(d.posTime);return{...n,mmsi:t,lat:Math.round(d.lat/1e4/60*1e5)/1e5,lng:Math.round(d.lon/1e4/60*1e5)/1e5,sog:Math.round(d.sog/10*100)/100,cog:Math.round(d.cog/10*100)/100,hdg:Math.round(d.heading*100)/100,rot:Math.round(d.rot*100)/100,positionTime:d.posTime,utc:y.utc().format(),status:d.aisNavStatus,labelEn:u,labelCn:l,method:"position",vendor:"myship"}}async trajectory(t,a,i,n,o=!0,e={}){const r=g(a),d=g(i),l=await this.getShipId(t),u=await this.getShipInfo(l),y=[];for(;d.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(l,r.unix(),r.add(30,"day").unix(),u,t,n,y);return await this.trajectoryIn30Day(l,r.unix(),d.unix(),u,t,n,y),y}async trajectoryIn30Day(t,a,i,n,o,e,r,d={}){var S;const l={headers:{appKey:this.token},json:{shipId:t,startTime:a,endTime:i}},u="https://api3.myships.com/sp/ships/position/history",y=await A.post(u,l).json();if(m==null||m.info("[%s] fetch trajectory from: %s - %j",d.requestId,u,l),y.code!=="0")return m==null||m.warn("[%s] invoke myship trajectory failed: %j",d.requestId,y),y;const v=y.data;for(const w in v)!isNaN(v[w])&&Number(v[w])!==1/0&&(v[w]=Number(v[w]));const M=g.unix((S=v[0])==null?void 0:S.posTime);let C=-1;for(const w of v){const b=g.unix(w.posTime),c={imo:n==null?void 0:n.imo,mmsi:o,lat:Math.round(w.lat/1e4/60*1e5)/1e5,lng:Math.round(w.lon/1e4/60*1e5)/1e5,sog:Math.round(w.sog/10*100)/100,cog:Math.round(w.cog/10*100)/100,hdg:Math.round(w.heading*100)/100,rot:Math.round(w.rot*100)/100,positionTime:b.unix(),utc:b.utc().format(),method:"trajectory",vendor:"myship"},p=Math.floor(b.diff(M,"minute",!0)/(e||1));p!==C&&(C=p,r.push(c))}return r}}let _;try{_=U.getLogger("vessel")}catch{}finally{}var ct=(D=>(D.NOTICE="NOTICE",D.WARN="WARN",D.HEAVY="HEAVY",D.SEVERE="SEVERE",D.ERROR="ERROR",D.FATAL="FATAL",D))(ct||{});class dt{parsePrinciple(s,t={}){var e,r,d;_==null||_.debug("[%s] parse rule: %s",t.requestId,s);const a=new RegExp("(?<=\\[)(.+)(?=])","g"),i=s.match(a)?(e=s.match(a))==null?void 0:e[0]:void 0,n=i==null?void 0:i.split(";");if(!n)return;const o={};for(let l=0;l<(n==null?void 0:n.length);l++){const u=(d=(r=n[l].match(a))==null?void 0:r[0])==null?void 0:d.split("],");if(l===0&&!u)o.scope=n[0];else if(u)for(let y=0,v=u.length;y<v;y++){const M=this.parseRule(u[y]);M&&(o[M.level]?M.key?o[M.level][M==null?void 0:M.key]=M:o[M.level]=M:M.key?o[M.level]={[M==null?void 0:M.key]:M}:o[M.level]=M)}}return o}parseRule(s,t={}){var o;_==null||_.debug("[%s] parse rule: %s",t.requestId,s),s=s.startsWith("[")?s:`[${s}`,s=s.endsWith("]")?s:`${s}]`;const a=new RegExp("(?<=\\[)(.+?)(?=])","g"),i=(o=s==null?void 0:s.match(a))==null?void 0:o[0],n=i==null?void 0:i.split(",");if(n){let e=n[3]==="Number.MAX_VALUE"?100:Number(n[3]);return e=isNaN(e)?1:e,{operator:n[0],number:Number.isNaN(Number(n[1]))?n[1]:Number(n[1]),level:n[2],time:e,key:n[4]}}}checkWeather(s,t,a={}){var M,C,S,w,b,c,p,f,h,k,j,x,Y,F,L;let i=0,n=0,o=0,e=0;const r=Math.round(((C=(M=t==null?void 0:t.SEVERE)==null?void 0:M.sigWave)==null?void 0:C.number)*1.6*100)/100,d=(w=(S=t==null?void 0:t.SEVERE)==null?void 0:S.sigWave)==null?void 0:w.number,l=(c=(b=t==null?void 0:t.HEAVY)==null?void 0:b.sigWave)==null?void 0:c.number,u=Math.round((((f=(p=t==null?void 0:t.SEVERE)==null?void 0:p.wind)==null?void 0:f.number)+2)*100)/100,y=(k=(h=t==null?void 0:t.SEVERE)==null?void 0:h.wind)==null?void 0:k.number,v=(x=(j=t==null?void 0:t.HEAVY)==null?void 0:j.wind)==null?void 0:x.number;for(let H=0;H<(s==null?void 0:s.length);H++){const E=s[H],P=(F=(Y=E==null?void 0:E.meteo)==null?void 0:Y.wave)==null?void 0:F.sig,V=(L=E==null?void 0:E.meteo)==null?void 0:L.wind,J=H?g(E.eta).diff(g(s[H-1].eta),"hour",!0):0;e=J>e?J:e,_==null||_.debug("[%s] check sig.wave: %j",a.requestId,{...P,dgThd4Wv:r,svThd4Wv:d,hvThd4Wv:l}),(P==null?void 0:P.height)>=r?E.isDangerous=!0:(P==null?void 0:P.height)>=d?E.isSevere=!0:(P==null?void 0:P.height)>=l&&(E.isHeavy=!0),_==null||_.debug("[%s] check wind: %j",a.requestId,{...V,dgThd4Wd:u,svThd4Wd:y,hvThd4Wd:v}),(V==null?void 0:V.scale)>=u?(E.isDangerous=!0,delete E.isSevere,delete E.isHeavy):(V==null?void 0:V.scale)>y?(E.isDangerous||(E.isSevere=!0),delete E.isHeavy):(V==null?void 0:V.scale)===v&&!E.isDangerous&&!E.isSevere&&(E.isHeavy=!0),i+=E.isDangerous?J:0,n+=E.isSevere?J:0,o+=E.isHeavy?J:0}return i=Math.round(i*100)/100,n=Math.round(n*100)/100,o=Math.round(o*100)/100,e=Math.round(e),{sample:s,dangerous:i,severe:n,heavy:o,step:e<3?3:e,wind:{dgThd4Wd:u,svThd4Wd:y,hvThd4Wd:v},sig:{dgThd4Wv:r,svThd4Wv:d,hvThd4Wv:l}}}}const bt=new dt;let I;try{I=U.getLogger("vessel")}catch{}finally{}const vt=new ft.MeteoHelper2("",!0);var ut=(D=>(D.common="common",D.container="container",D.tugs="tugs",D))(ut||{}),lt=(D=>(D.Ballast="Ballast",D.Laden="Laden",D))(lt||{}),ht=(D=>(D.Cp="CP",D.Perf="Basis",D.Instruct="Other",D))(ht||{});class W{static blockCoefficient(s,t,a,i){let n=Math.round(s/(t*a*i)*100)/100;n=n<.55?.55:n>.85?.85:n;const o=[.55,.6,.65,.7,.75,.8,.85],e=o.map(r=>Math.abs(r-n));return o[e.indexOf(Math.min(...e))]}static froudeNumber(s,t,a=9.8){let i=Math.round(Math.sqrt(s*s/(a*t))*100)/100;return i=i<.05?.05:i>.3?.3:i,i}static amendFactor(s,t,a){const i={.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 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.6,-12.5,-13.5],.8:[3,-16.3,-21.6],.85:[3.4,-20.9,31.8]}[s];return a==="Laden"&&(o=i[s]),o[0]+o[1]*t+o[2]*Math.pow(t,2)}static directionFactor(s,t=0){let a;return s>30&&s<=60?a=(1.7-.03*Math.pow(t-4,2))/2:s>60&&s<=150?a=(.9-.06*Math.pow(t-6,2))/2:s>150&&s<=180?a=(.4-.03*Math.pow(t-8,2))/2:a=1,Math.round(a*1e5)/1e5}static vesselTagFactor(s,t,a,i){let n;return a==="container"?n=.7*i/2+Math.pow(i,3)/(22*Math.pow(s,2/3)):t==="Ballast"?n=.7*i/2+Math.pow(i,3)/(2.7*Math.pow(s,2/3)):n=.5*i/2+Math.pow(i,3)/(2.7*Math.pow(s,2/3)),n}static waveHeightFactor(s,t){s=s<3?s*.7:s,s=s<0?.2:s,s=s>6?s-.9*(s-6):s,s=s>9?9:s;let a;return t>30&&t<=60?a=-.6:t>60&&t<=90?a=-.4:t>90&&t<=120?a=s<3?.4:-.3:t>120&&t<=150?a=s<3?.6:-.5:t>150&&t<=180?a=s<3?.7:-.6:a=-.7,Math.round(a*(.144*Math.pow(s,2)+.278*s)*1e4)/1e4}static assembleProperties(s,t,a,i){var y;const n=s.lbp??s.length??s.lengthOverall??198.9642,o=s.draught??8,e=s.breadthMoulded??s.breadth??s.breadthExtreme??32.4572,r=s.deadweight??67035.7773,d=((y=s==null?void 0:s.type)==null?void 0:y.toLowerCase())||"common";return{tag:d.indexOf("container")>-1?"container":d.indexOf("tugs")>-1?"tugs":"common",lbp:n,loadCondition:t,draught:o,breadthMoulded:e,displacement:Math.round((r/1.025+o*e*n*.7)*1e4)/1e4,speed:Math.round((a??14.1382)*1852/3600*1e4)/1e4,bearing:i||90}}static async speedLoseAt(s,t,a,i="",n=2,o=!0,e=!1,r={}){let d;if(t.velocity&&e&&(s.speed=N.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),o){let l;try{i=(i==null?void 0:i.toUpperCase())==="CMEMS"?"ECMWF":i,i=(i==null?void 0:i.toUpperCase())==="METEO2"?"best_match":i;const{weatherModels:M,marineModels:C}=await nt.Meteo2Assist.autoPickMeteoModel(i),S=await vt.spotForecast(t.lat,t.lng,a.utc().format(),!1,!1,!0,{...r,pastDays:1,forecastDays:1,weatherModels:M,marineModels:C}),[w]=nt.Meteo2Assist.pickHourly(S,a);l=nt.Meteo2Assist.toLegacy(w)}catch(M){I.warn("[%s] meteo2 spot(%j) forecast failed: %s",r.requestId,{...t,eta:a.utc().format(),source:i},M)}const u=W.currentFactor(s.bearing,l==null?void 0:l.current,n),y=W.weatherFactor(s,l,u),v=Math.round(s.speed*1.943844*100)/100;d={meteo:{...l},wxFactor:y,cFactor:u,speed:t.velocity&&e?t.velocity:v<0?1:v,eta:a.utc().format(),etd:a.utc().format()}}else d={wxFactor:0,cFactor:0,speed:t.velocity&&e?t.velocity:Math.round(s.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,{...d,...t}}static async speedLoseInHoursStep(s,t,a,i,n,o,e="",r=!0,d=!1,l={}){t.utc();const u=t.clone().add(14,"days"),y=[],v=[];let M=0,C=0,S,w;for(let b=0;b<o.length-1;b++){let c=o[b];c.distanceFromStart=Math.round((n+C)*1e3)/1e3;const p=o[b+1];if(s.bearing=N.LaneHelper.calculateBearing(c,p,!p.gcToPrevious),c.bearing=s.bearing,c.suspend&&d){c.eta=c.eta||t.utc().format(),c.elapsed=c.elapsed??0;const k=c.suspend-c.elapsed;if(i-M>k)i=i-M-k,t.add(k,"hour"),c.elapsed=c.suspend;else{const j=i-M;c.elapsed+=j,t.add(j,"hour"),i=0}if(I==null||I.info(`[%s] suspend ${c.elapsed} hours at %j, and remain ${i} hours need to go...`,l.requestId,c),i===0)return c.distanceFromPrevious=C,{etd:t,from:w||c,to:c,next:o.filter(j=>j),wps:y,days:v}}else c.suspend=0;r=t.isAfter(u)?!1:r,c=await W.speedLoseAt(s,c,t,e,0,r,d,l),w=w||c,c.important&&y.push(c),t.isSameOrAfter(a)&&(v.push(c),a.add(24,"hour"));const f=N.LaneHelper.calculateDistance(c,p,!p.gcToPrevious);let h=Math.round(f/w.speed*1e5)/1e5;if(M+h<i){if(M+=h,t.add(h,"hour"),delete o[b],I==null||I.debug(`[%s] go to %j from %j with ${f}nm, and cost ${h} hours`,l.requestId,{lat:p.lat,lng:p.lng},{lat:w.lat,lng:w.lng,etd:w.etd}),C+=f,o.filter(k=>k).length<=1){S=p,S.eta=t.utc().format(),S.distanceFromPrevious=f,S.distanceFromStart=Math.round((n+C)*1e4)/1e4,y.push(S),delete o[b+1];break}}else{h=i-M,t.add(h,"hour");const k=N.LngLatHelper.roundPrecision(w.speed*h,5);S=N.LaneHelper.calculateCoordinate(c,s.bearing,k,"nauticalmiles",!p.gcToPrevious),S.eta=t.utc().format(),o[b]=S,I==null||I.debug(`[%s] go to %j from %j with ${k}nm, and cost ${h} hours`,l.requestId,{lat:S.lat,lng:S.lng},{lat:c.lat,lng:c.lng,etd:c.etd}),C+=k,S.distanceFromPrevious=Math.round(C*1e4)/1e4,S.distanceFromStart=Math.round((n+C)*1e4)/1e4;break}}return{etd:t,from:w,to:S,next:o.filter(b=>b),wps:y,days:v}}static currentFactor(s,t,a=0){const i=(s-(t==null?void 0:t.degree)||0)/180*Math.PI;if(Math.abs(i)===Math.PI/2)return 0;let n=((t==null?void 0:t.kts)||0)*Math.cos(i);return a&2?n=Math.ceil(n*100)/100:a&1?n=Math.floor(n*100)/100:n=Math.round(n*100)/100,Math.abs(n)>5?0:n}static weatherFactor(s,t,a=0){var v,M,C,S,w,b,c;I==null||I.debug("calculate weather factor via: %j",{...s,...t});const i=W.blockCoefficient(s.displacement,s.lbp,s.breadthMoulded,s.draught),n=N.LngLatHelper.roundPrecision(a*1852/3600,6),o=W.froudeNumber(s.speed-n,s.lbp),e=W.amendFactor(i,o,s.loadCondition);let r=Math.abs(s.bearing%360-(((v=t==null?void 0:t.wind)==null?void 0:v.degree)%360||0));r=r>180?360-r:r;const d=W.directionFactor(r,(M=t==null?void 0:t.wind)==null?void 0:M.scale),l=W.vesselTagFactor(s.displacement,s.loadCondition,s.tag,(C=t==null?void 0:t.wind)==null?void 0:C.kts);let u=d*e*l/100*(s.speed-n);u=Math.round(u*1.943844*1e4)/1e4,s.tag==="tugs"&&Math.abs(u)>1&&(u=u/(Math.abs(Math.round(u))+1)),I==null||I.debug("wind wx factor = %d",u),r=Math.abs(s.bearing%360-(((w=(S=t==null?void 0:t.wave)==null?void 0:S.sig)==null?void 0:w.degree)%360||0)),r=r>180?360-r:r;const y=W.waveHeightFactor(((c=(b=t==null?void 0:t.wave)==null?void 0:b.sig)==null?void 0:c.height)??1,r);return I==null||I.debug("wave wx factor = %d",y),u=Math.abs(u)>Math.abs(y)?u:u*.3+y*.7,I==null||I.debug("weather factor = %d",u),u=Math.abs(u)>3?3*(Math.abs(u)/u)+Math.abs(u)/u*(Math.abs(u)-2)*.1:u,Math.round((u||0)*100)/100}static async analyseInstant(s,t,a,i,n,o="",e=0,r=!0,d=!1,l={}){var X,Q,Z,$,tt,et;const u=g().valueOf();s.lng=N.LngLatHelper.convertToStdLng(s.lng);const{route:y,waypoints:v}=n.points,M=N.LaneHelper.calculateSubRoute(s,y);if(((X=M[0])==null?void 0:X.length)<=1)return;const{v0:C,label:S}=s.sog?{v0:s.sog,label:s.label||"Other"}:{v0:i.speed,label:"CP"},w=W.assembleProperties(a,i.loadCondition,C,0),b=v.length?N.LaneHelper.calculateSubWaypoints(s,v):[];b.forEach(O=>O.important=!0);const c={from:{...s},route:M,waypoints:b,v0:C,label:S},p={hours:[],days:[],wps:[]};e||(N.LaneHelper.calculateRouteDistance(M)/i.speed<=72?e=3:e=6);let f=N.LaneHelper.simplifyRouteToCoordinates(M,b,0),h=0,k=0,j=0,x=0;t=g(t).utc();const Y=t.clone();for(;f.length>0;){const O=e-t.hour()%e,z=Math.ceil(t.clone().add(O,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,T=await W.speedLoseInHoursStep(w,t,Y,z,h,f,o,r,d,l);if((Q=T.from)!=null&&Q.speed&&(p.hours.push(T.from),p.wps.push(...T.wps),p.days.push(...T.days)),f=T==null?void 0:T.next,!f.length){const B=await W.speedLoseAt(w,T.to,g(T.to.eta),o,0,r,d,l);p.hours.push(B)}h+=Math.round((((Z=T==null?void 0:T.to)==null?void 0:Z.distanceFromPrevious)??0)*1e4)/1e4}const F=p.hours;for(let O=0;O<F.length-1;O++){const z=g(F[O+1].eta).diff(F[O].etd,"hour",!0)||1;k+=(F[O].wxFactor||0)*z,j+=(F[O].cFactor||0)*z,x+=z}($=p.wps)==null||$.forEach((O,z)=>{O.positionTime=g.utc(O.etd||O.eta).unix();const T=p.wps[z-1];if(T){const B=O.distanceFromStart-T.distanceFromStart,R=g(O.eta||O.etd).diff(g(T.etd||T.eta),"h",!0);O.avgSpd=Math.round(B/R*100)/100,T.bearing=N.LaneHelper.calculateBearing(T,O)}}),p.wps=(tt=p.wps)==null?void 0:tt.reduce((O,z)=>(O.some(T=>Math.round(T.positionTime/60)===Math.round(z.positionTime/60))||O.push(z),O),[]),c.sample=p;const L=p.hours.at(0),H=p.hours.at(-1);c.distance=Math.round(H.distanceFromStart*1e3)/1e3,c.etd=g(L.eta).utc().format(),c.eta=g(H.eta).utc().format(),c.wxFactor=Math.round(k/x*1e3)/1e3,c.cFactor=Math.round(j/x*1e3)/1e3,c.avgSpeed=Math.round(H.distanceFromStart/x*1e3)/1e3,c.totalHrs=Math.round(x*1e3)/1e3;const{distanceInECA:E,hoursInECA:P,totalDgoConsInECA:V,eca:J}=await this.calculateECA(c,i,l),st=N.LngLatHelper.roundPrecision(i.fo/24*(x-P),3),ot=N.LngLatHelper.roundPrecision(i.dgo/24*x,3);c.extend={eca:J,distanceInECA:E,hoursInECA:P,totalDgoConsInECA:V},c.totalFoCons=st<0?0:st,c.totalDgoCons=ot;const at=g().valueOf()-u,rt=((et=p==null?void 0:p.hours)==null?void 0:et.length)||1;return I==null||I.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",l==null?void 0:l.requestId,at,rt,Math.round(at/rt*1e3)/1e3),c}static async analyseInstantWithThreshed(s,t,a,i,n,o,e,r="",d=3,l=!0,u=!1,y={}){var Z,$,tt,et,O,z;const v=g().valueOf();s.lng=N.LngLatHelper.convertToStdLng(s.lng);const{v0:M,label:C}=s.sog?{v0:s.sog,label:s.label||"Other"}:{v0:n.speed,label:"CP"},S=W.assembleProperties(i,n.loadCondition,M,0),w=N.LaneHelper.calculateSubRoute(s,o);if(((Z=w[0])==null?void 0:Z.length)<=1)return;const b=e.length?N.LaneHelper.calculateSubWaypoints(s,e):[];b.forEach(T=>T.important=!0);let c=N.LaneHelper.simplifyRouteToCoordinates(w,b,0),p=0,f=0,h=0,k=0;const j={hours:[],wps:[],days:[]};t=g(t).utc();const x=t.clone();for(;c.length>0;){const T=d-t.hour()%d;let B=Math.ceil(t.clone().add(T,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;B=t.clone().add(B,"h").isSameOrAfter(a)?a.diff(t,"h",!0)*1e4/1e4:B;const R=await W.speedLoseInHoursStep(S,t,x,B,p,c,r,l,u,y);if(($=R.from)!=null&&$.speed&&(j.hours.push(R.from),R!=null&&R.wps&&j.wps.push(...R.wps),j.days.push(...R.days)),c=R==null?void 0:R.next,c.length||j.hours.push(R==null?void 0:R.to),p+=Math.round((((tt=R==null?void 0:R.to)==null?void 0:tt.distanceFromPrevious)??0)*1e4)/1e4,!B)break}j.wps=(et=j.wps)==null?void 0:et.reduce((T,B)=>(T.some(R=>Math.round(g(R.etd).unix()/60)===Math.round(g(B.etd).unix()/60))||T.push(B),T),[]),(O=j.wps)==null||O.forEach((T,B)=>{const R=j.wps[B-1];if(R){const gt=T.distanceFromStart-R.distanceFromStart,wt=g(T.eta||T.etd).diff(g(R.etd||R.eta),"h",!0);T.avgSpd=Math.round(gt/wt*100)/100;const kt=N.LaneHelper.calculateBearing(R,T);R.bearing=kt}});const Y=j.hours;for(let T=0;T<Y.length-1;T++){const B=g(Y[T+1].eta).diff(Y[T].etd,"hour",!0);f+=Y[T].wxFactor*B,h+=Y[T].cFactor*B,k+=B}const F=j.hours.at(0),L=j.hours.at(-1),H=await N.LaneHelper.calculateRangeRoute(F,L,w),E=await N.LaneHelper.calculateRangeWaypoints(F,L,w,b),P={sample:j,distance:Math.round(((L==null?void 0:L.distanceFromStart)||0)*1e4)/1e4,etd:g(F.eta).utc().format(),eta:g(L==null?void 0:L.eta).utc().format(),wxFactor:Math.round(f/k*1e3)/1e3,cFactor:Math.round(h/k*1e3)/1e3,avgSpeed:Math.round(((L==null?void 0:L.distanceFromStart)||0)/k*1e3)/1e3,totalHrs:Math.round(k*1e3)/1e3,from:F,to:L,route:H,waypoints:E,v0:M,label:C},{distanceInECA:V,hoursInECA:J,totalDgoConsInECA:st,eca:ot}=await this.calculateECA(P,n,y),it=N.LngLatHelper.roundPrecision(n.fo/24*(k-J),3),at=N.LngLatHelper.roundPrecision(n.dgo/24*k,3);P.extend={eca:ot,distanceInECA:V,hoursInECA:J,totalDgoConsInECA:st},P.totalDgoCons=at,P.totalFoCons=it<0?0:it;const X=g().valueOf()-v,Q=((z=j==null?void 0:j.hours)==null?void 0:z.length)||1;return I==null||I.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",y==null?void 0:y.requestId,X,Q,Math.round(X/Q*1e3)/1e3),P}static async analyseCost(s,t,a,i,n={}){var w,b;const o=g().valueOf(),e=[];s.speedStep=s.speedStep||3,s.alterStep=s.alterStep??1;const r=N.LaneHelper.calculateRouteDistance(i.route);let d=0;a.forEach(c=>{const p=Math.ceil(r/c.speed/24);d=d<p?p:d}),d=d*1.3;const l=g.utc(s.etd).add(d??14,"day");let u=1;for(const c of a){const p=JSON.parse(JSON.stringify(i.route)),f=JSON.parse(JSON.stringify(i.waypoints)),h=await W.analyseInstantWithThreshed({lat:s.lat,lng:s.lng},s.etd,l,t,c,p,f,s.meteoVendor,s.speedStep,s.useMeteo,s.useRouteParam,n);h&&(await W.calculateCost(h,c,s,n),e.push(h),I==null||I.info("[%s][L%d-%d] analyse from %s to %s cost: %j",n.requestId,1,u,s.etd,l.format(),{cost:h.cost.total,hire:h.cost.hire,bunker:h.cost.bunker,distance:h.distance,hours:h.totalHrs,cp:`${c.speed}/${c.fo}/${c.dgo}`})),u++}e.sort((c,p)=>c.cost.total-p.cost.total);const y=e.at(0),v=e.at(1),M=[];if(M.push({combined:!1,speeds:[y],cost:(w=y.cost)==null?void 0:w.total}),v){const c=y.cost.cp,p=v.cost.cp,f=g(y.eta),h=g(y.etd),k=f.diff(h,"days",!0);let j=Math.ceil(k/2);j=j>7?7:j<s.alterStep?s.alterStep:j;let x=2,Y={combined:!1,speeds:[v],cost:(b=v.cost)==null?void 0:b.total},F;for(;j>=s.alterStep;){const L=await W.combinedAnalyse(s,t,l,[c,p],i,j,{...n,level:x});if(Y.cost>L.cost?F?(F==null?void 0:F.cost)>L.cost&&(F=L):(F=Y,Y=L):(!F||(F==null?void 0:F.cost)>L.cost)&&(F=L),j<=s.alterStep)break;j=Math.ceil(j/2),x+=1}M.push(Y),F&&M.push(F)}const S=g().valueOf()-o;return I==null||I.info("[%s] analyse elapsed: %d ms",n==null?void 0:n.requestId,S),M.sort((c,p)=>c.cost-p.cost)}static async combinedAnalyse(s,t,a,i,n,o,e={}){e.counter=1,I==null||I.info("[%s][L%d] analyse with alternate cp in every %d days",e.requestId,e.level,o);const r=await W.alternateAnalyse(s,t,a,i,0,n,o,e),d=r.reduce((p,f)=>p+f.cost.total,0),l=r.reduce((p,f)=>p+f.cost.hire,0),u=r.reduce((p,f)=>p+f.cost.bunker,0),y=r.reduce((p,f)=>p+f.distance,0),v=r.reduce((p,f)=>p+f.totalHrs,0);I==null||I.info("[%s][L%d] cost with cpa/cpb turn: %j",e.requestId,e.level,{cost:d,hire:l,bunker:u,distance:y,hours:v});const M=await W.alternateAnalyse(s,t,a,i,1,n,o,e),C=M.reduce((p,f)=>p+f.cost.total,0),S=M.reduce((p,f)=>p+f.cost.hire,0),w=M.reduce((p,f)=>p+f.cost.bunker,0),b=M.reduce((p,f)=>p+f.distance,0),c=M.reduce((p,f)=>p+f.totalHrs,0);return I==null||I.info("[%s][L%d] cost with cpb/cpa turn: %j",e.requestId,e.level,{cost:C,hire:S,bunker:w,distance:b,hours:c}),d<C?{combined:!0,cost:Math.round(d*1e3)/1e3,speeds:r,step:o}:{combined:!0,cost:Math.round(C*1e3)/1e3,speeds:M,step:o}}static async alternateAnalyse(s,t,a,i,n,o,e,r={}){var y,v;let d=g.utc(s.etd);const l={lat:s.lat,lng:s.lng},u=[];for(;d.isBefore(a);){const M=d.clone().utc().add(e,"day"),C=JSON.parse(JSON.stringify(o.route)),S=JSON.parse(JSON.stringify(o.waypoints)),w=i[n],b=await W.analyseInstantWithThreshed(l,d.utc().format(),M,t,w,C,S,s.meteoVendor,s.speedStep,s.useMeteo,s.useRouteParam,r);b&&(await W.calculateCost(b,w,s,r),I==null||I.info("[%s][L%d-%d] analyse from %s to %s cost: %j",r.requestId,r.level,r.counter,d.utc().format(),M.utc().format(),{cost:b.cost.total,hire:b.cost.hire,bunker:b.cost.bunker,distance:b.distance,hours:b.totalHrs,cp:`${w.speed}/${w.fo}/${w.dgo}`})),r.counter=r.counter+1;const c=(v=(y=b==null?void 0:b.sample)==null?void 0:y.hours)==null?void 0:v.at(-1);if(c)l.lat=c.lat,l.lng=c.lng,d=g(c.eta),u.push(b),n=n?0:1;else break}return u}static async calculateCost(s,t,a,i={}){var n;if(s){const o=(a.addComm||0)>=1?(a.addComm||0)/100:a.addComm||0,e=Math.round(s.totalHrs/24*(a.dailyHire||0)*(1-o)*1e3)/1e3,r=Math.round(s.totalFoCons*(a.priceFO||0)*1e3)/1e3,d=Math.round((s.totalDgoCons+(((n=s.extend)==null?void 0:n.totalDgoConsInECA)||0))*(a.priceDGO||0)*1e3)/1e3;s.cost={total:Math.round((e+r+d)*1e3)/1e3,hire:e,bunker:Math.round((r+d)*1e3)/1e3,cp:t}}return s}static async calculateECA(s,t,a={}){var r,d,l,u;const i=await N.LaneHelper.intersectInECA((s==null?void 0:s.route)||[]);let n=0,o=0,e=0;(d=(r=s==null?void 0:s.sample)==null?void 0:r.wps)==null||d.forEach(y=>{y.positionTime=g.utc(y.etd||y.eta).unix()});for(const y of i){n+=y.distance;const v=await N.LaneHelper.deadReckoningTime((l=y.waypoints)==null?void 0:l.at(0),s.sample.wps),M=await N.LaneHelper.deadReckoningTime((u=y.waypoints)==null?void 0:u.at(-1),s.sample.wps);y.in=v,y.out=M,y.totalHrs=N.LngLatHelper.roundPrecision((M.positionTime-v.positionTime)/3600,3),y.totalDgoCons=N.LngLatHelper.roundPrecision(t.fo/24*y.totalHrs,3),o+=y.totalHrs,e+=y.totalDgoCons}return n=N.LngLatHelper.roundPrecision(n,3),o=N.LngLatHelper.roundPrecision(o,3),e=N.LngLatHelper.roundPrecision(e,3),{distanceInECA:n,hoursInECA:o,totalDgoConsInECA:e,eca:i}}static async mergeSpeeds(s,t={}){var c,p;const a={hours:[],wps:[],days:[]},i=s.reduce((f,h)=>f+h.distance,0),n=s.reduce((f,h)=>{var k;return f+(((k=h.extend)==null?void 0:k.distanceInECA)||0)},0),o=s.reduce((f,h)=>f+h.totalHrs,0),e=s.reduce((f,h)=>{var k;return f+(((k=h.extend)==null?void 0:k.hoursInECA)||0)},0),r=s.reduce((f,h)=>{var k;return f+(((k=h.extend)==null?void 0:k.totalDgoConsInECA)||0)},0),d=s.reduce((f,h)=>f+h.wxFactor*h.totalHrs/o,0),l=s.reduce((f,h)=>f+h.cFactor*h.totalHrs/o,0),u=s.reduce((f,h)=>f+h.totalFoCons,0),y=s.reduce((f,h)=>f+h.totalDgoCons,0),v=s.reduce((f,h)=>f+h.cost.total,0),M=s.reduce((f,h)=>f+h.cost.hire,0),C=s.reduce((f,h)=>f+h.cost.bunker,0),S=[],w=[];let b;for(const f of s){w.push(...((c=f.extend)==null?void 0:c.eca)||[]);const h=f.sample.hours,k=f.sample.wps,j=f.sample.days,x=h.at(0);b&&(x.distanceFromPrevious=b.distanceFromPrevious,x.distanceFromStart=b.distanceFromStart,h.forEach((H,E)=>{E&&(H.distanceFromStart=H.distanceFromStart+b.distanceFromStart)}),k.at(0).distanceFromPrevious=b.distanceFromPrevious,k.at(0).distanceFromStart=b.distanceFromStart,k.forEach((H,E)=>{E&&(H.distanceFromStart=H.distanceFromStart+b.distanceFromStart)}),j.at(0).distanceFromPrevious=b.distanceFromPrevious,j.at(0).distanceFromStart=b.distanceFromStart,j.forEach((H,E)=>{E&&(H.distanceFromStart=H.distanceFromStart+b.distanceFromStart)})),x.cp=f.cost.cp;const Y=[f.etd,f.eta],F=S.findIndex(H=>H.id===x.cp.id);F===-1?(x.cp.segment=[Y],S.push(x.cp)):S[F].segment.push(Y),h.forEach(H=>{var P;((P=a.hours)==null?void 0:P.findIndex(V=>V.eta===H.eta))===-1&&a.hours.push(H)}),k.forEach(H=>{var P;((P=a.wps)==null?void 0:P.findIndex(V=>V.eta===H.eta))===-1&&a.wps.push(H)}),j.forEach(H=>{var P;((P=a==null?void 0:a.days)==null?void 0:P.findIndex(V=>V.eta===H.eta))===-1&&a.days.push(H)});const L=(p=a.wps)==null?void 0:p.findIndex(H=>H.eta===x.eta);L===-1?a.wps.push(x):a.wps[L]=x,b=h.at(-1)}return a.wps.sort((f,h)=>{g(f.etd).unix()-g(h.etd).unix()}),a.wps.forEach((f,h)=>{const k=a.wps[h-1];if(k){const j=f.distanceFromStart-(k.distanceFromStart||0),x=g(f.eta||f.etd).diff(g(k.etd||k.eta),"hour",!0),Y=Math.round(j/x*100)/100;f.avgSpd=Y;const F=N.LaneHelper.calculateBearing(k,f);k.bearing=F}}),{sample:a,etd:s.at(0).etd,eta:s.at(-1).eta,from:s.at(0).from,to:s.at(-1).to,v0:s.at(0).v0,label:"Combined",distance:Math.round(i*1e3)/1e3,totalHrs:Math.round(o*1e3)/1e3,avgSpeed:Math.round(i/o*1e3)/1e3,wxFactor:Math.round(d*1e3)/1e3,cFactor:Math.round(l*1e3)/1e3,totalFoCons:Math.round(u*1e3)/1e3,totalDgoCons:Math.round(y*1e3)/1e3,cost:{total:Math.round(v*1e3)/1e3,hire:Math.round(M*1e3)/1e3,bunker:Math.round(C*1e3)/1e3},extend:{cps:S,eca:w,distanceInECA:Math.round(n*1e3)/1e3,hoursInECA:Math.round(e*1e3)/1e3,totalDgoConsInECA:Math.round(r*1e3)/1e3,speeds:s}}}}q.AISImpl=G,q.AlertHelper=dt,q.AlertLevel=ct,q.HifleetImpl=yt,q.LoadCondition=lt,q.MyShipImpl=pt,q.MyVesselImpl=mt,q.ShipxyImpl=Mt,q.SpeedHelper=W,q.SpeedLabel=ht,q.VesselTag=ut,q.alertHelper=bt,Object.defineProperty(q,Symbol.toStringTag,{value:"Module"})});
@@ -146,6 +146,7 @@ export declare class SpeedHelper {
146
146
  /**
147
147
  * 浪高影响因子
148
148
  * @param ht 浪高,单位m
149
+ * @param beta 夹角
149
150
  * @private
150
151
  */
151
152
  private static waveHeightFactor;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idm-plugin/vessel",
3
3
  "private": false,
4
- "version": "2.3.7",
4
+ "version": "2.3.8",
5
5
  "description": "idm plugin for vessel",
6
6
  "type": "module",
7
7
  "keywords": [