@idm-plugin/vessel 2.0.3 → 2.0.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 +2 -2
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -571,7 +571,7 @@ class yt {
|
|
|
571
571
|
*/
|
|
572
572
|
parseRule(e, t = {}) {
|
|
573
573
|
var a;
|
|
574
|
-
_ == null || _.
|
|
574
|
+
_ == null || _.debug("[%s] parse rule: %s", t.requestId, e), e = e.startsWith("[") ? e : `[${e}`, e = e.endsWith("]") ? e : `${e}]`;
|
|
575
575
|
const n = new RegExp("(?<=\\[)(.+?)(?=])", "g"), i = (a = e == null ? void 0 : e.match(n)) == null ? void 0 : a[0], o = i == null ? void 0 : i.split(",");
|
|
576
576
|
if (o)
|
|
577
577
|
return {
|
|
@@ -594,7 +594,7 @@ class yt {
|
|
|
594
594
|
const d = Math.round(((C = (m = t == null ? void 0 : t.SEVERE) == null ? void 0 : m.sigWave) == null ? void 0 : C.number) * 1.6 * 100) / 100, r = (w = (S = t == null ? void 0 : t.SEVERE) == null ? void 0 : S.sigWave) == null ? void 0 : w.number, h = (c = (b = t == null ? void 0 : t.HEAVY) == null ? void 0 : b.sigWave) == null ? void 0 : c.number, M = Math.round((((l = (f = t == null ? void 0 : t.SEVERE) == null ? void 0 : f.wind) == null ? void 0 : l.number) + 2) * 100) / 100, y = (I = (u = t == null ? void 0 : t.SEVERE) == null ? void 0 : u.wind) == null ? void 0 : I.number, v = (D = (k = t == null ? void 0 : t.HEAVY) == null ? void 0 : k.wind) == null ? void 0 : D.number;
|
|
595
595
|
for (let T = 0; T < (e == null ? void 0 : e.length); T++) {
|
|
596
596
|
const N = e[T], A = (j = (Y = N == null ? void 0 : N.meteo) == null ? void 0 : Y.wave) == null ? void 0 : j.sig, R = (P = N == null ? void 0 : N.meteo) == null ? void 0 : P.wind, U = T ? g(N.eta).diff(g(e[T - 1].eta), "hour", !0) : 0;
|
|
597
|
-
s = U > s ? U : s, _ == null || _.
|
|
597
|
+
s = U > s ? U : s, _ == null || _.debug("[%s] check sig.wave: %j", n.requestId, { ...A, dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: h }), (A == null ? void 0 : A.height) >= d ? N.isDangerous = !0 : (A == null ? void 0 : A.height) >= r ? N.isSevere = !0 : (A == null ? void 0 : A.height) >= h && (N.isHeavy = !0), _ == null || _.debug("[%s] check wind: %j", n.requestId, { ...R, dgThd4Wd: M, svThd4Wd: y, hvThd4Wd: v }), (R == null ? void 0 : R.scale) >= M ? (N.isDangerous = !0, delete N.isSevere, delete N.isHeavy) : (R == null ? void 0 : R.scale) > y ? (N.isDangerous || (N.isSevere = !0), delete N.isHeavy) : (R == null ? void 0 : R.scale) === v && !N.isDangerous && !N.isSevere && (N.isHeavy = !0), i += N.isDangerous ? U : 0, o += N.isSevere ? U : 0, a += N.isHeavy ? U : 0;
|
|
598
598
|
}
|
|
599
599
|
return i = Math.round(i * 100) / 100, o = Math.round(o * 100) / 100, a = Math.round(a * 100) / 100, s = Math.round(s), { sample: e, dangerous: i, severe: o, heavy: a, step: s < 3 ? 3 : s, wind: { dgThd4Wd: M, svThd4Wd: y, hvThd4Wd: v }, sig: { dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: h } };
|
|
600
600
|
}
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(A,R){typeof exports=="object"&&typeof module<"u"?R(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"],R):(A=typeof globalThis<"u"?globalThis:A||self,R(A["idm-plugin-rabbitmq"]={},A.got,A["@log4js-node/log4js-api"],A.moment,A["@idm-plugin/geo2"],A["@idm-plugin/meteo2"],A["@idm-plugin/meteo"]))})(this,function(A,R,K,p,T,mt,at){"use strict";var St=Object.defineProperty;var kt=(A,R,K)=>R in A?St(A,R,{enumerable:!0,configurable:!0,writable:!0,value:K}):A[R]=K;var z=(A,R,K)=>(kt(A,typeof R!="symbol"?R+"":R,K),K);let b;try{b=K.getLogger("vessel")}catch{}finally{}class G{parseStatus(e){let t,o;switch(e){case 0:t="在航(主机推动)",o="Underway Using Engine";break;case 1:t="锚泊",o="Anchored";break;case 2:t="失控",o="Not operated";break;case 3:t="操纵受限",o="Limited airworthiness";break;case 4:t="吃水受限",o="Limited by ship's draft";break;case 5:t="靠泊",o="Mooring";break;case 6:t="搁浅",o="Stranded";break;case 7:t="捕捞作业",o="Engaged in fishing";break;case 8:t="靠帆船提供动力",o="Sailing";break;default:t="未定义",o="Undefined"}return{labelCn:t,labelEn:o}}}class yt extends G{constructor(t,o){super();z(this,"clientId");z(this,"clientSecret");z(this,"token");this.clientId=t,this.clientSecret=o}async authToken(t={}){const o="https://svc.data.myvessel.cn/ada/oauth/token",i={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},n=await R.post(o,i).json();b==null||b.info("[%s] fetch access token from: %s - %j",t.requestId,o,n),n.error||(this.token={accessToken:n.access_token,tokenType:n.token_type,expiresIn:n.expires_in,scope:n.scope,jti:n.jti,issuedAt:p().utc().format()})}async realTimePosition(t,o={}){var d,r,l;(!this.token||p().diff(p(this.token.issuedAt),"seconds")>((d=this.token)==null?void 0:d.expiresIn)-300)&&await this.authToken(o);const i="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",n={headers:{Authorization:`${(r=this.token)==null?void 0:r.tokenType} ${(l=this.token)==null?void 0:l.accessToken}`},searchParams:{mmsi:t}};b==null||b.info("[%s] fetch realtime position from: %s - %j",o.requestId,i,n);const a=await R.get(i,n).json();if(a.code)return b==null||b.warn("[%s] fetch realtime position failed: %j",o.requestId,i,{message:a.message,status:a.status,code:a.code}),a;const s=a.data;for(const M in s)!isNaN(s[M])&&Number(s[M])!==1/0&&(s[M]=Number(s[M]));if(s){const M=p(`${s.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:s.mmsi,name:s.vesselName||s.aisVesselName,imo:s.imo,callSign:s.callsign||s.aisCallSign,lat:s.lat,lng:s.lon,length:s.length,width:s.width,draught:s.currDraught,sog:s.sog,cog:s.cog,hdg:s.hdg,rot:s.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta)?p.utc(s.eta).format():void 0,destination:s.dest,positionTime:M.unix(),status:s.status,labelCn:s.statusNameCn,labelEn:s.statusNameEn,vesselType:s.vesselTypeNameEn,flag:s.flagCtryNameEn,clasz:s.classSociety,build:s.buildYear,dwt:s.dwt,grt:s.grt,net:s.net,method:"position",vendor:"myVessel",utc:M.utc().format()}}else return{}}async trajectory(t,o,i,n,a=!0,s={}){(!this.token||p().diff(p(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(s);const d=await this.realTimePosition(t,s),r=p(o),l=p(i),M=[];for(;l.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(t,r,r.clone().add(30,"day"),d,n,M,s),r.add(30,"day");return await this.trajectoryIn30Day(t,r,l,d,n,M,s),M}async trajectoryIn30Day(t,o,i,n,a,s,d={}){var m,C,k,v,g;const r="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:o.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};b==null||b.info("[%s] fetch trajectory from: %s - %j",d.requestId,r,l);const M=await R.post(r,l).json();if(M.code)return b==null||b.warn("[%s] fetch trajectory failed: %j",d.requestId,r,{message:M.message,status:M.status,code:M.code}),M;let y=-1;const w=p(`${(v=(k=M.data)==null?void 0:k[0])==null?void 0:v.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(g=M.data)==null||g.forEach(c=>{for(const P in c)!isNaN(c[P])&&Number(c[P])!==1/0&&(c[P]=Number(c[P]));const f=p(`${c.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),h=c.status,{labelCn:u,labelEn:I}=this.parseStatus(h),F={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:h,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(c.eta)?p(`${c.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").utc().format():void 0,destination:c.dest,positionTime:f.unix(),labelCn:u,labelEn:I,method:"trajectory",vendor:"myVessel",utc:f.utc().format()},N=Math.floor(f.diff(w,"minute",!0)/(a||1));N!==y&&(y=N,s.push(F))}),s}}class Mt extends G{constructor(t){super();z(this,"token");this.token=t}async realTimePosition(t,o={}){const i="https://api.hifleet.com/position/position/get/token",n={searchParams:{mmsi:t,usertoken:this.token}},a=await R.post(i,n).json();b==null||b.info("[%s] fetch realtime position from: %s - %j",o.requestId,i,n);const s=a==null?void 0:a.list;if(!s)return b==null||b.warn("[%s] fetch realtime position failed: %j",o.requestId,i,a),a;for(const w in s)!isNaN(s[w])&&Number(s[w])!==1/0&&(s[w]=Number(s[w]));s.status=s.sp>3?0:1;const d=s.status,{labelCn:r,labelEn:l}=this.parseStatus(d),M=p(`${s.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:s.m,name:s.n,imo:s.imonumber,callSign:s.callsign,lat:Math.round(s.la/60*1e5)/1e5,lng:Math.round(s.lo/60*1e5)/1e5,length:s.l,width:s.w,draught:s.draught,sog:s.sp,cog:s.co,hdg:s.h,rot:isNaN(s.rot)?0:s.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta)?p.utc(s.eta).format():void 0,destination:s.destination,vesselType:s.type,dwt:s.dwt,build:s.buildyear,flag:s.fn,positionTime:M.unix(),utc:M.utc().format(),status:d,labelCn:r,labelEn:l,method:"position",vendor:"hifleet"}}async search(t,o={}){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 a=await R.post(i,n).json();b==null||b.info("[%s] fetch vessel props from: %s - %j",o.requestId,i,n),a instanceof Array&&(a=a[0]);for(const d in a)!isNaN(a[d])&&Number(a[d])!==1/0&&(a[d]=Number(a[d]));const s={mmsi:a.m,name:a.n,imo:a.i,callSign:a.c,length:a.l,breadth:a.b,draught:a.dr,type:a.t};return i="https://www.hifleet.com/hifleetapi/sameShipSearch.do",a=await R.post(i,n).json(),b==null||b.info("[%s] search vessel dead weight from: %s - %j",o.requestId,i,n),a instanceof Array&&(a=a[0]),a&&(s.deadweight=Number(a.dwt)),s}async suggest(t,o={}){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"}},a=await R.post(i,n).json();b==null||b.info("[%s] suggest vessel props from: %s - %j",o.requestId,i,n);const s=[];for(const d of a)s.push({mmsi:!d.mmsi||isNaN(d.mmsi)?null:Number(d.mmsi),name:d.name,callSign:d.callsign,imo:!d.imo||isNaN(d.imo)?null:Number(d.imo),score:d._score});return s.sort((d,r)=>r.score-d.score),s}async trajectory(t,o,i,n,a=!0,s={}){var c,f,h;const d=await this.realTimePosition(t,s);let r=p(o);const l=p(i),M=p();if(a){let u=l.diff(r,"d",!0);u<0?r=l.clone().subtract(40,"d"):u<30?r.subtract(10,"d"):u<60?r.subtract(5,"d"):r=l.clone().subtract(80,"d"),u=M.diff(l,"d",!0),l.add(u>10?240:u*24,"h")}const y={searchParams:{endtime:l.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),starttime:r.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),mmsi:t,usertoken:this.token}},w="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",m=await R.get(w,y).json();b==null||b.info("[%s] fetch trajectory from: %s - %j",s.requestId,w,y);let C;m&&(C=((f=(c=m.ships)==null?void 0:c.offors)==null?void 0:f.ship)||[],C.length||b==null||b.warn("[%s] fetch trajectory failed: %j",s.requestId,m));const k=[];let v=-1;const g=p(`${(h=C==null?void 0:C[0])==null?void 0:h.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const u of C){for(const L in u)!isNaN(u[L])&&Number(u[L])!==1/0&&(u[L]=Number(u[L]));const I=p(`${u.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");u.status=u.sp>4?0:1;const{labelEn:F,labelCn:N}=this.parseStatus(u.status),P={mmsi:u.m,name:u.n,imo:d==null?void 0:d.imo,lat:u.la,lng:u.lo,draught:u.draught,sog:u.sp,cog:u.co,hdg:u.hdg,positionTime:I.unix(),utc:I.utc().format(),status:u.status,labelCn:N,labelEn:F,method:"trajectory",vendor:"hifleet"},E=Math.floor(I.diff(g,"minute",!0)/(n||1));E!==v&&(v=E,k.push(P))}return k}}class pt extends G{constructor(t){super();z(this,"token");this.token=t}async realTimePosition(t,o={}){const i={searchParams:{id:t,k:this.token,enc:1}},n="https://api.shipxy.com/apicall/GetSingleShip",a=await R.get(n,i).json();if(b==null||b.info("[%s] fetch realtime position from: %s - %j",o.requestId,n,i),(a==null?void 0:a.status)!==0)return a;const s=a.data[0];for(const y in s)!isNaN(s[y])&&Number(s[y])!==1/0&&(s[y]=Number(s[y]));const{labelCn:d,labelEn:r}=await this.parseStatus(s.navistat),l=p.unix(s.lasttime);return{mmsi:s.ShipID,name:s.name,imo:s.imo,callSign:s.callsign,lat:Math.round(s.lat/1e6*1e5)/1e5,lng:Math.round(s.lon/1e6*1e5)/1e5,length:Math.round(s.length/10*100)/100,width:Math.round(s.width/10*100)/100,draught:Math.round(s.draught/1e3*100)/100,sog:Math.round(s.sog*3600/1e3/1852*100)/100,cog:Math.round(s.cog/100*100)/100,hdg:Math.round(s.hdg/100*100)/100,rot:Math.round(s.rot/100*100)/100,positionTime:s.lasttime,utc:l.utc().format(),status:s.navistat,labelEn:r,labelCn:d,method:"position",vendor:"shipxy"}}async trajectory(t,o,i,n,a=!0,s={}){var g;const d=await this.realTimePosition(t,s),r=p(o),l=p(i),M="https://api.shipxy.com/apicall/GetShipTrack",y={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:r.unix(),etm:l.unix()}},w=await R.get(M,y).json();if(b==null||b.info("[%s] fetch trajectory from: %s - %j",s.requestId,M,y),(w==null?void 0:w.status)!==0)return w;const m=w==null?void 0:w.points,C=[],k=p.unix((g=m[0])==null?void 0:g.utc);let v=-1;for(const c of m){const f=p.unix(c.utc),h={imo:d==null?void 0:d.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:f.unix(),utc:f.utc().format(),method:"trajectory",vendor:"shipxy"},u=Math.floor(f.diff(k,"minute",!0)/(n||1));u!==v&&(v=u,C.push(h))}return C}}class bt extends G{constructor(t){super();z(this,"token");this.token=t}async getShipId(t,o={}){const i={headers:{appKey:this.token},json:{mmsiList:t}},n="https://api3.myships.com/sp/ships/getShipIdByMMSI",a=await R.post(n,i).json();return b==null||b.info("[%s] fetch ship id from: %s - %j",o.requestId,n,i),a.code!=="0"?a:a.data[0].shipId}async getShipInfo(t,o={}){const i={headers:{appKey:this.token},json:{shipId:t}},n="https://api3.myships.com/sp/ships/aissta",a=await R.post(n,i).json();if(b==null||b.info("[%s] fetch ship info from: %s - %j",o.requestId,n,i),a.code!=="0")return a;const s=a.data;let d=s.imo;return t==="407170"&&(d="9198379",b==null||b.warn("[%s] ship(%s) imo error: %s, should be %s",o.requestId,t,s.imo,d)),{mmsi:s.mmsi,name:s.shipnameEn,imo:d,callSign:s.callSign,length:s.length,width:s.breadth,draught:(s.draught||100)/10}}async realTimePosition(t,o={}){const i=await this.getShipId(t,o),n=await this.getShipInfo(i,o),a={headers:{appKey:this.token},json:{shipId:i}},s="https://api3.myships.com/sp/ships/position/latest",d=await R.post(s,a).json();b==null||b.info("[%s] fetch realtime position from: %s - %j",o.requestId,s,a);const r=d.data[0];for(const m in r)!isNaN(r[m])&&Number(r[m])!==1/0&&(r[m]=Number(r[m]));const{labelCn:l,labelEn:M}=await this.parseStatus(r.aisNavStatus),y=p.unix(r.posTime);return{...n,mmsi:t,lat:Math.round(r.lat/1e4/60*1e5)/1e5,lng:Math.round(r.lon/1e4/60*1e5)/1e5,sog:Math.round(r.sog/10*100)/100,cog:Math.round(r.cog/10*100)/100,hdg:Math.round(r.heading*100)/100,rot:Math.round(r.rot*100)/100,positionTime:r.posTime,utc:y.utc().format(),status:r.aisNavStatus,labelEn:M,labelCn:l,method:"position",vendor:"myship"}}async trajectory(t,o,i,n,a=!0,s={}){const d=p(o),r=p(i),l=await this.getShipId(t),M=await this.getShipInfo(l),y=[];for(;r.diff(d,"day",!0)>30;)await this.trajectoryIn30Day(l,d.unix(),d.add(30,"day").unix(),M,t,n,y);return await this.trajectoryIn30Day(l,d.unix(),r.unix(),M,t,n,y),y}async trajectoryIn30Day(t,o,i,n,a,s,d,r={}){var k;const l={headers:{appKey:this.token},json:{shipId:t,startTime:o,endTime:i}},M="https://api3.myships.com/sp/ships/position/history",y=await R.post(M,l).json();if(b==null||b.info("[%s] fetch trajectory from: %s - %j",r.requestId,M,l),y.code!=="0")return b==null||b.warn("[%s] invoke myship trajectory failed: %j",r.requestId,y),y;const w=y.data;for(const v in w)!isNaN(w[v])&&Number(w[v])!==1/0&&(w[v]=Number(w[v]));const m=p.unix((k=w[0])==null?void 0:k.posTime);let C=-1;for(const v of w){const g=p.unix(v.posTime),c={imo:n==null?void 0:n.imo,mmsi:a,lat:Math.round(v.lat/1e4/60*1e5)/1e5,lng:Math.round(v.lon/1e4/60*1e5)/1e5,sog:Math.round(v.sog/10*100)/100,cog:Math.round(v.cog/10*100)/100,hdg:Math.round(v.heading*100)/100,rot:Math.round(v.rot*100)/100,positionTime:g.unix(),utc:g.utc().format(),method:"trajectory",vendor:"myship"},f=Math.floor(g.diff(m,"minute",!0)/(s||1));f!==C&&(C=f,d.push(c))}return d}}let _;try{_=K.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(e,t={}){var s,d,r;_==null||_.info("[%s] parse rule: %s",t.requestId,e);const o=new RegExp("(?<=\\[)(.+)(?=])","g"),i=e.match(o)?(s=e.match(o))==null?void 0:s[0]:void 0,n=i==null?void 0:i.split(";");if(!n)return;const a={};for(let l=0;l<(n==null?void 0:n.length);l++){const M=(r=(d=n[l].match(o))==null?void 0:d[0])==null?void 0:r.split("],");if(l===0&&!M)a.scope=n[0];else if(M)for(let y=0,w=M.length;y<w;y++){const m=this.parseRule(M[y]);m&&(a[m.level]?m.key?a[m.level][m==null?void 0:m.key]=m:a[m.level]=m:m.key?a[m.level]={[m==null?void 0:m.key]:m}:a[m.level]=m)}}return a}parseRule(e,t={}){var a;_==null||_.info("[%s] parse rule: %s",t.requestId,e),e=e.startsWith("[")?e:`[${e}`,e=e.endsWith("]")?e:`${e}]`;const o=new RegExp("(?<=\\[)(.+?)(?=])","g"),i=(a=e==null?void 0:e.match(o))==null?void 0:a[0],n=i==null?void 0:i.split(",");if(n)return{operator:n[0],number:Number.isNaN(Number(n[1]))?n[1]:Number(n[1]),level:n[2],time:Number(n[3]),key:n[4]}}checkWeather(e,t,o={}){var m,C,k,v,g,c,f,h,u,I,F,N,P,E,L;let i=0,n=0,a=0,s=0;const d=Math.round(((C=(m=t==null?void 0:t.SEVERE)==null?void 0:m.sigWave)==null?void 0:C.number)*1.6*100)/100,r=(v=(k=t==null?void 0:t.SEVERE)==null?void 0:k.sigWave)==null?void 0:v.number,l=(c=(g=t==null?void 0:t.HEAVY)==null?void 0:g.sigWave)==null?void 0:c.number,M=Math.round((((h=(f=t==null?void 0:t.SEVERE)==null?void 0:f.wind)==null?void 0:h.number)+2)*100)/100,y=(I=(u=t==null?void 0:t.SEVERE)==null?void 0:u.wind)==null?void 0:I.number,w=(N=(F=t==null?void 0:t.HEAVY)==null?void 0:F.wind)==null?void 0:N.number;for(let x=0;x<(e==null?void 0:e.length);x++){const H=e[x],q=(E=(P=H==null?void 0:H.meteo)==null?void 0:P.wave)==null?void 0:E.sig,V=(L=H==null?void 0:H.meteo)==null?void 0:L.wind,U=x?p(H.eta).diff(p(e[x-1].eta),"hour",!0):0;s=U>s?U:s,_==null||_.info("[%s] check sig.wave: %j",o.requestId,{...q,dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:l}),(q==null?void 0:q.height)>=d?H.isDangerous=!0:(q==null?void 0:q.height)>=r?H.isSevere=!0:(q==null?void 0:q.height)>=l&&(H.isHeavy=!0),_==null||_.info("[%s] check wind: %j",o.requestId,{...V,dgThd4Wd:M,svThd4Wd:y,hvThd4Wd:w}),(V==null?void 0:V.scale)>=M?(H.isDangerous=!0,delete H.isSevere,delete H.isHeavy):(V==null?void 0:V.scale)>y?(H.isDangerous||(H.isSevere=!0),delete H.isHeavy):(V==null?void 0:V.scale)===w&&!H.isDangerous&&!H.isSevere&&(H.isHeavy=!0),i+=H.isDangerous?U:0,n+=H.isSevere?U:0,a+=H.isHeavy?U:0}return i=Math.round(i*100)/100,n=Math.round(n*100)/100,a=Math.round(a*100)/100,s=Math.round(s),{sample:e,dangerous:i,severe:n,heavy:a,step:s<3?3:s,wind:{dgThd4Wd:M,svThd4Wd:y,hvThd4Wd:w},sig:{dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:l}}}}const gt=new dt;let S;try{S=K.getLogger("vessel")}catch{}finally{}const vt=new mt.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(e,t,o,i){let n=Math.round(e/(t*o*i)*100)/100;n=n<.55?.55:n>.85?.85:n;const a=[.55,.6,.65,.7,.75,.8,.85],s=a.map(d=>Math.abs(d-n));return a[s.indexOf(Math.min(...s))]}static froudeNumber(e,t,o=9.8){let i=Math.round(Math.sqrt(e*e/(o*t))*100)/100;return i=i<.05?.05:i>.3?.3:i,i}static amendFactor(e,t,o){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 a={.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 o==="Laden"&&(a=i[e]),a[0]+a[1]*t+a[2]*Math.pow(t,2)}static directionFactor(e,t=0){let o;return e>30&&e<=60?o=(1.7-.03*Math.pow(t-4,2))/2:e>60&&e<=150?o=(.9-.06*Math.pow(t-6,2))/2:e>150&&e<=180?o=(.4-.03*Math.pow(t-8,2))/2:o=1,Math.round(o*1e5)/1e5}static vesselTagFactor(e,t,o,i=0){i=i>6?i-.9*(i-6):i;let n;return o==="container"?n=.7*i+Math.pow(i,6.5)/(22*Math.pow(e,2/3)):t==="Ballast"?n=.7*i+Math.pow(i,6.5)/(2.7*Math.pow(e,2/3)):n=.5*i+Math.pow(i,6.5)/(2.7*Math.pow(e,2/3)),n}static waveHeightFactor(e,t){e=e<0?.2:e,e=e>6?e-.9*(e-6):e,e=e>9?9:e;let o;return t>30&&t<=60?o=-.6:t>60&&t<=90?o=-.4:t>90&&t<=120?o=e<3?.4:-.3:t>120&&t<=150?o=e<3?.6:-.5:t>150&&t<=180?o=e<3?.7:-.6:o=-.7,Math.round(o*(.144*Math.pow(e,2)+.178*e)*1e4)/1e4}static assembleProperties(e,t,o,i){var y;const n=e.lbp??e.length??e.lengthOverall??198.9642,a=e.draught??8,s=e.breadthMoulded??e.breadth??e.breadthExtreme??32.4572,d=e.deadweight??67035.7773,r=((y=e==null?void 0:e.type)==null?void 0:y.toLowerCase())||"common";return{tag:r.indexOf("container")>-1?"container":r.indexOf("tugs")>-1?"tugs":"common",lbp:n,loadCondition:t,draught:a,breadthMoulded:s,displacement:Math.round((d/1.025+a*s*n*.7)*1e4)/1e4,speed:Math.round((o??14.1382)*1852/3600*1e4)/1e4,bearing:i||90}}static async speedLoseAt(e,t,o,i="",n=2,a=!0,s=!1,d={}){let r;if(t.velocity&&s&&(e.speed=T.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),a){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 at.Meteo2Assist.autoPickMeteoModel(i),k=await vt.spotForecast(t.lat,t.lng,o.utc().format(),!1,!1,!0,{...d,pastDays:1,forecastDays:1,weatherModels:m,marineModels:C}),[v]=at.Meteo2Assist.pickHourly(k,o);l=at.Meteo2Assist.toLegacy(v)}catch(m){S.warn("[%s] meteo2 spot(%j) forecast failed: %s",d.requestId,{...t,eta:o.utc().format(),source:i},m)}const M=W.weatherFactor(e,l),y=W.currentFactor(e.bearing,l==null?void 0:l.current,n),w=Math.round((e.speed*1.943844+M+y)*100)/100;r={meteo:{...l},wxFactor:M,cFactor:y,speed:t.velocity&&s?t.velocity:w<0?1:w,eta:o.utc().format(),etd:o.utc().format()}}else r={wxFactor:0,cFactor:0,speed:t.velocity&&s?t.velocity:Math.round((e.speed*1.943844+0+0)*100)/100,eta:o.utc().format(),etd:o.utc().format()};return delete t.meteo,delete t.wxFactor,delete t.cFactor,delete t.speed,delete t.etd,{...r,...t}}static async speedLoseInHoursStep(e,t,o,i,n,a,s="",d=!0,r=!1,l={}){t.utc();const M=t.clone().add(14,"days"),y=[],w=[];let m=0,C=0,k,v;for(let g=0;g<a.length-1;g++){let c=a[g];c.distanceFromStart=Math.round((n+C)*1e4)/1e4;const f=a[g+1];if(e.bearing=T.LaneHelper.calculateBearing(c,f,!f.gcToPrevious),c.bearing=e.bearing,c.suspend&&r){c.eta=c.eta||t.utc().format(),c.elapsed=c.elapsed??0;const I=c.suspend-c.elapsed;if(i-m>I)i=i-m-I,t.add(I,"hour"),c.elapsed=c.suspend;else{const F=i-m;c.elapsed+=F,t.add(F,"hour"),i=0}if(S==null||S.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:v||c,to:c,next:a.filter(F=>F),wps:y,days:w}}else c.suspend=0;d=t.isAfter(M)?!1:d,c=await W.speedLoseAt(e,c,t,s,0,d,r,l),v=v||c,c.important&&y.push(c),t.isSameOrAfter(o)&&(w.push(c),o.add(24,"hour"));const h=T.LaneHelper.calculateDistance(c,f,!f.gcToPrevious);let u=Math.round(h/v.speed*1e5)/1e5;if(m+u<i){if(m+=u,t.add(u,"hour"),delete a[g],S==null||S.debug(`[%s] go to %j from %j with ${h}nm, and cost ${u} hours`,l.requestId,{lat:f.lat,lng:f.lng},{lat:v.lat,lng:v.lng,etd:v.etd}),C+=h,a.filter(I=>I).length<=1){k=f,k.eta=t.utc().format(),k.distanceFromPrevious=h,k.distanceFromStart=Math.round((n+C)*1e4)/1e4,y.push(k),delete a[g+1];break}}else{u=i-m,t.add(u,"hour");const I=T.LngLatHelper.roundPrecision(v.speed*u,5);k=T.LaneHelper.calculateCoordinate(c,e.bearing,I,"nauticalmiles",!f.gcToPrevious),k.eta=t.utc().format(),a[g]=k,S==null||S.debug(`[%s] go to %j from %j with ${I}nm, and cost ${u} hours`,l.requestId,{lat:k.lat,lng:k.lng},{lat:c.lat,lng:c.lng,etd:c.etd}),C+=I,k.distanceFromPrevious=Math.round(C*1e4)/1e4,k.distanceFromStart=Math.round((n+C)*1e4)/1e4;break}}return{etd:t,from:v,to:k,next:a.filter(g=>g),wps:y,days:w}}static currentFactor(e,t,o=0){const i=(e-(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 o&2?n=Math.ceil(n*100)/100:o&1?n=Math.floor(n*100)/100:n=Math.round(n*100)/100,Math.abs(n)>5?0:n}static weatherFactor(e,t){var M,y,w,m,C,k,v;S==null||S.debug("calculate weather factor via: %j",{...e,...t});const o=W.blockCoefficient(e.displacement,e.lbp,e.breadthMoulded,e.draught),i=W.froudeNumber(e.speed,e.lbp),n=W.amendFactor(o,i,e.loadCondition);let a=Math.abs(e.bearing%360-(((M=t==null?void 0:t.wind)==null?void 0:M.degree)%360||0));a=a>180?360-a:a;const s=W.directionFactor(a,(y=t==null?void 0:t.wind)==null?void 0:y.scale),d=W.vesselTagFactor(e.displacement,e.loadCondition,e.tag,(w=t==null?void 0:t.wind)==null?void 0:w.scale);let r=s*n*d/100*e.speed;r=Math.round(r*1.943844*1e4)/1e4*-1,e.tag==="tugs"&&Math.abs(r)>1&&(r=r/(Math.abs(Math.round(r))+1)),S==null||S.debug("wind wx factor = %d",r),a=Math.abs(e.bearing%360-(((C=(m=t==null?void 0:t.wave)==null?void 0:m.sig)==null?void 0:C.degree)%360||0));const l=W.waveHeightFactor(((v=(k=t==null?void 0:t.wave)==null?void 0:k.sig)==null?void 0:v.height)??1,a);return S==null||S.debug("wave wx factor = %d",l),r=r*.4+l,S==null||S.debug("weather factor = %d",r),r=Math.abs(r)>4?4*(Math.abs(r)/r)+Math.abs(r)/r*(Math.abs(r)-4)*.1:r,Math.round((r||0)*100)/100}static async analyseInstant(e,t,o,i,n,a="",s=0,d=!0,r=!1,l={}){var Q,X,Z,$,tt,et;const M=p().valueOf();e.lng=T.LngLatHelper.convertToStdLng(e.lng);const{route:y,waypoints:w}=n.points,m=T.LaneHelper.calculateSubRoute(e,y);if(((Q=m[0])==null?void 0:Q.length)<=1)return;const{v0:C,label:k}=e.sog?{v0:e.sog,label:e.label||"Other"}:{v0:i.speed,label:"CP"},v=W.assembleProperties(o,i.loadCondition,C,0),g=w.length?T.LaneHelper.calculateSubWaypoints(e,w):[];g.forEach(Y=>Y.important=!0);const c={from:{...e},route:m,waypoints:g,v0:C,label:k},f={hours:[],days:[],wps:[]};s||(T.LaneHelper.calculateRouteDistance(m)/i.speed<=72?s=3:s=6);let h=T.LaneHelper.simplifyRouteToCoordinates(m,g,0),u=0,I=0,F=0,N=0;t=p(t).utc();const P=t.clone();for(;h.length>0;){const Y=s-t.hour()%s,J=Math.ceil(t.clone().add(Y,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,j=await W.speedLoseInHoursStep(v,t,P,J,u,h,a,d,r,l);(X=j.from)!=null&&X.speed&&(f.hours.push(j.from),f.wps.push(...j.wps),f.days.push(...j.days)),h=j==null?void 0:j.next,h.length||f.hours.push(j==null?void 0:j.to),u+=Math.round((((Z=j==null?void 0:j.to)==null?void 0:Z.distanceFromPrevious)??0)*1e4)/1e4}const E=f.hours;for(let Y=0;Y<E.length-1;Y++){const J=p(E[Y+1].eta).diff(E[Y].etd,"hour",!0)||1;I+=(E[Y].wxFactor||0)*J,F+=(E[Y].cFactor||0)*J,N+=J}($=f.wps)==null||$.forEach((Y,J)=>{Y.positionTime=p.utc(Y.etd||Y.eta).unix();const j=f.wps[J-1];if(j){const B=Y.distanceFromStart-j.distanceFromStart,O=p(Y.eta||Y.etd).diff(p(j.etd||j.eta),"h",!0);Y.avgSpd=Math.round(B/O*100)/100;const rt=T.LaneHelper.calculateBearing(j,Y);j.bearing=rt}}),f.wps=(tt=f.wps)==null?void 0:tt.reduce((Y,J)=>(Y.some(j=>Math.round(j.positionTime/60)===Math.round(J.positionTime/60))||Y.push(J),Y),[]),c.sample=f;const L=f.hours.at(0),x=f.hours.at(-1);c.distance=Math.round(x.distanceFromStart*1e4)/1e4,c.etd=p(L.eta).utc().format(),c.eta=p(x.eta).utc().format(),c.wxFactor=Math.round(I/N*1e4)/1e4,c.cFactor=Math.round(F/N*1e4)/1e4,c.avgSpeed=Math.round(x.distanceFromStart/N*1e4)/1e4,c.totalHrs=Math.round(N*1e4)/1e4;const{distanceInECA:H,hoursInECA:q,totalDgoConsInECA:V,eca:U}=await this.calculateECA(c,i,l),nt=T.LngLatHelper.roundPrecision(i.fo/24*(N-q),3),ot=T.LngLatHelper.roundPrecision(i.dgo/24*N,3);c.extend={eca:U,distanceInECA:H,hoursInECA:q,totalDgoConsInECA:V},c.totalFoCons=nt,c.totalDgoCons=ot;const st=p().valueOf()-M,it=((et=f==null?void 0:f.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,st,it,Math.round(st/it*1e3)/1e3),c}static async analyseInstantWithThreshed(e,t,o,i,n,a,s,d="",r=3,l=!0,M=!1,y={}){var Z,$,tt,et,Y,J;const w=p().valueOf();e.lng=T.LngLatHelper.convertToStdLng(e.lng);const{v0:m,label:C}=e.sog?{v0:e.sog,label:e.label||"Other"}:{v0:n.speed,label:"CP"},k=W.assembleProperties(i,n.loadCondition,m,0),v=T.LaneHelper.calculateSubRoute(e,a);if(((Z=v[0])==null?void 0:Z.length)<=1)return;const g=s.length?T.LaneHelper.calculateSubWaypoints(e,s):[];g.forEach(j=>j.important=!0);let c=T.LaneHelper.simplifyRouteToCoordinates(v,g,0),f=0,h=0,u=0,I=0;const F={hours:[],wps:[],days:[]};t=p(t).utc();const N=t.clone();for(;c.length>0;){const j=r-t.hour()%r;let B=Math.ceil(t.clone().add(j,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;B=t.clone().add(B,"h").isSameOrAfter(o)?o.diff(t,"h",!0)*1e4/1e4:B;const O=await W.speedLoseInHoursStep(k,t,N,B,f,c,d,l,M,y);if(($=O.from)!=null&&$.speed&&(F.hours.push(O.from),O!=null&&O.wps&&F.wps.push(...O.wps),F.days.push(...O.days)),c=O==null?void 0:O.next,c.length||F.hours.push(O==null?void 0:O.to),f+=Math.round((((tt=O==null?void 0:O.to)==null?void 0:tt.distanceFromPrevious)??0)*1e4)/1e4,!B)break}F.wps=(et=F.wps)==null?void 0:et.reduce((j,B)=>(j.some(O=>Math.round(p(O.etd).unix()/60)===Math.round(p(B.etd).unix()/60))||j.push(B),j),[]),(Y=F.wps)==null||Y.forEach((j,B)=>{const O=F.wps[B-1];if(O){const rt=j.distanceFromStart-O.distanceFromStart,wt=p(j.eta||j.etd).diff(p(O.etd||O.eta),"h",!0);j.avgSpd=Math.round(rt/wt*100)/100;const It=T.LaneHelper.calculateBearing(O,j);O.bearing=It}});const P=F.hours;for(let j=0;j<P.length-1;j++){const B=p(P[j+1].eta).diff(P[j].etd,"hour",!0);h+=P[j].wxFactor*B,u+=P[j].cFactor*B,I+=B}const E=F.hours.at(0),L=F.hours.at(-1),x=await T.LaneHelper.calculateRangeRoute(E,L,v),H=await T.LaneHelper.calculateRangeWaypoints(E,L,v,g),q={sample:F,distance:Math.round(((L==null?void 0:L.distanceFromStart)||0)*1e4)/1e4,etd:p(E.eta).utc().format(),eta:p(L==null?void 0:L.eta).utc().format(),wxFactor:Math.round(h/I*1e4)/1e4,cFactor:Math.round(u/I*1e4)/1e4,avgSpeed:Math.round(((L==null?void 0:L.distanceFromStart)||0)/I*1e4)/1e4,totalHrs:Math.round(I*1e4)/1e4,from:E,to:L,route:x,waypoints:H,v0:m,label:C},{distanceInECA:V,hoursInECA:U,totalDgoConsInECA:nt,eca:ot}=await this.calculateECA(q,n,y),ft=T.LngLatHelper.roundPrecision(n.fo/24*(I-U),3),st=T.LngLatHelper.roundPrecision(n.dgo/24*I,3);q.extend={eca:ot,distanceInECA:V,hoursInECA:U,totalDgoConsInECA:nt},q.totalDgoCons=st,q.totalFoCons=ft;const Q=p().valueOf()-w,X=((J=F==null?void 0:F.hours)==null?void 0:J.length)||1;return S==null||S.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",y==null?void 0:y.requestId,Q,X,Math.round(Q/X*1e3)/1e3),q}static async analyseCost(e,t,o,i,n={}){var v,g;const a=p().valueOf(),s=[];e.speedStep=e.speedStep||3,e.alterStep=e.alterStep??1;const d=T.LaneHelper.calculateRouteDistance(i.route);let r=0;o.forEach(c=>{const f=Math.ceil(d/c.speed/24);r=r<f?f:r}),r=r*1.3;const l=p.utc(e.etd).add(r??14,"day");let M=1;for(const c of o){const f=JSON.parse(JSON.stringify(i.route)),h=JSON.parse(JSON.stringify(i.waypoints)),u=await W.analyseInstantWithThreshed({lat:e.lat,lng:e.lng},e.etd,l,t,c,f,h,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,n);u&&(await W.calculateCost(u,c,e,n),s.push(u),S==null||S.info("[%s][L%d-%d] analyse from %s to %s cost: %j",n.requestId,1,M,e.etd,l.format(),{cost:u.cost.total,hire:u.cost.hire,bunker:u.cost.bunker,distance:u.distance,hours:u.totalHrs,cp:`${c.speed}/${c.fo}/${c.dgo}`})),M++}s.sort((c,f)=>c.cost.total-f.cost.total);const y=s.at(0),w=s.at(1),m=[];if(m.push({combined:!1,speeds:[y],cost:(v=y.cost)==null?void 0:v.total}),w){const c=y.cost.cp,f=w.cost.cp,h=p(y.eta),u=p(y.etd),I=h.diff(u,"days",!0);let F=Math.ceil(I/2);F=F>7?7:F<e.alterStep?e.alterStep:F;let N=2,P={combined:!1,speeds:[w],cost:(g=w.cost)==null?void 0:g.total},E;for(;F>=e.alterStep;){const L=await W.combinedAnalyse(e,t,l,[c,f],i,F,{...n,level:N});if(P.cost>L.cost?E?(E==null?void 0:E.cost)>L.cost&&(E=L):(E=P,P=L):(!E||(E==null?void 0:E.cost)>L.cost)&&(E=L),F<=e.alterStep)break;F=Math.ceil(F/2),N+=1}m.push(P),E&&m.push(E)}const k=p().valueOf()-a;return S==null||S.info("[%s] analyse elapsed: %d ms",n==null?void 0:n.requestId,k),m.sort((c,f)=>c.cost-f.cost)}static async combinedAnalyse(e,t,o,i,n,a,s={}){s.counter=1,S==null||S.info("[%s][L%d] analyse with alternate cp in every %d days",s.requestId,s.level,a);const d=await W.alternateAnalyse(e,t,o,i,0,n,a,s),r=d.reduce((f,h)=>f+h.cost.total,0),l=d.reduce((f,h)=>f+h.cost.hire,0),M=d.reduce((f,h)=>f+h.cost.bunker,0),y=d.reduce((f,h)=>f+h.distance,0),w=d.reduce((f,h)=>f+h.totalHrs,0);S==null||S.info("[%s][L%d] cost with cpa/cpb turn: %j",s.requestId,s.level,{cost:r,hire:l,bunker:M,distance:y,hours:w});const m=await W.alternateAnalyse(e,t,o,i,1,n,a,s),C=m.reduce((f,h)=>f+h.cost.total,0),k=m.reduce((f,h)=>f+h.cost.hire,0),v=m.reduce((f,h)=>f+h.cost.bunker,0),g=m.reduce((f,h)=>f+h.distance,0),c=m.reduce((f,h)=>f+h.totalHrs,0);return S==null||S.info("[%s][L%d] cost with cpb/cpa turn: %j",s.requestId,s.level,{cost:C,hire:k,bunker:v,distance:g,hours:c}),r<C?{combined:!0,cost:Math.round(r*1e3)/1e3,speeds:d,step:a}:{combined:!0,cost:Math.round(C*1e3)/1e3,speeds:m,step:a}}static async alternateAnalyse(e,t,o,i,n,a,s,d={}){var y,w;let r=p.utc(e.etd);const l={lat:e.lat,lng:e.lng},M=[];for(;r.isBefore(o);){const m=r.clone().utc().add(s,"day"),C=JSON.parse(JSON.stringify(a.route)),k=JSON.parse(JSON.stringify(a.waypoints)),v=i[n],g=await W.analyseInstantWithThreshed(l,r.utc().format(),m,t,v,C,k,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,d);g&&(await W.calculateCost(g,v,e,d),S==null||S.info("[%s][L%d-%d] analyse from %s to %s cost: %j",d.requestId,d.level,d.counter,r.utc().format(),m.utc().format(),{cost:g.cost.total,hire:g.cost.hire,bunker:g.cost.bunker,distance:g.distance,hours:g.totalHrs,cp:`${v.speed}/${v.fo}/${v.dgo}`})),d.counter=d.counter+1;const c=(w=(y=g==null?void 0:g.sample)==null?void 0:y.hours)==null?void 0:w.at(-1);if(c)l.lat=c.lat,l.lng=c.lng,r=p(c.eta),M.push(g),n=n?0:1;else break}return M}static async calculateCost(e,t,o,i={}){var n;if(e){const a=Math.round(e.totalHrs/24*(o.dailyHire||0)*(1-(o.addComm||0))*1e3)/1e3,s=Math.round(e.totalFoCons*(o.priceFO||0)*1e3)/1e3,d=Math.round((e.totalDgoCons+(((n=e.extend)==null?void 0:n.totalDgoConsInECA)||0))*(o.priceDGO||0)*1e3)/1e3;e.cost={total:Math.round((a+s+d)*1e3)/1e3,hire:a,bunker:Math.round((s+d)*1e3)/1e3,cp:t}}return e}static async calculateECA(e,t,o={}){var d,r;const i=await T.LaneHelper.intersectInECA(e.route);let n=0,a=0,s=0;e.sample.wps.forEach(l=>{l.positionTime=p.utc(l.etd||l.eta).unix()});for(const l of i){n+=l.distance;const M=await T.LaneHelper.deadReckoningTime((d=l.waypoints)==null?void 0:d.at(0),e.sample.wps),y=await T.LaneHelper.deadReckoningTime((r=l.waypoints)==null?void 0:r.at(-1),e.sample.wps);l.in=M,l.out=y,l.totalHrs=T.LngLatHelper.roundPrecision((y.positionTime-M.positionTime)/3600,2),l.totalDgoCons=T.LngLatHelper.roundPrecision(t.fo/24*l.totalHrs,3),a+=l.totalHrs,s+=l.totalDgoCons}return n=T.LngLatHelper.roundPrecision(n,3),a=T.LngLatHelper.roundPrecision(a,3),s=T.LngLatHelper.roundPrecision(s,3),{distanceInECA:n,hoursInECA:a,totalDgoConsInECA:s,eca:i}}static async mergeSpeeds(e,t={}){var c,f;const o={hours:[],wps:[],days:[]},i=e.reduce((h,u)=>h+u.distance,0),n=e.reduce((h,u)=>{var I;return h+(((I=u.extend)==null?void 0:I.distanceInECA)||0)},0),a=e.reduce((h,u)=>h+u.totalHrs,0),s=e.reduce((h,u)=>{var I;return h+(((I=u.extend)==null?void 0:I.hoursInECA)||0)},0),d=e.reduce((h,u)=>{var I;return h+(((I=u.extend)==null?void 0:I.totalDgoConsInECA)||0)},0),r=e.reduce((h,u)=>h+u.wxFactor*u.totalHrs/a,0),l=e.reduce((h,u)=>h+u.cFactor*u.totalHrs/a,0),M=e.reduce((h,u)=>h+u.totalFoCons,0),y=e.reduce((h,u)=>h+u.totalDgoCons,0),w=e.reduce((h,u)=>h+u.cost.total,0),m=e.reduce((h,u)=>h+u.cost.hire,0),C=e.reduce((h,u)=>h+u.cost.bunker,0),k=[],v=[];let g;for(const h of e){v.push(...((c=h.extend)==null?void 0:c.eca)||[]);const u=h.sample.hours,I=h.sample.wps,F=h.sample.days,N=u.at(0);g&&(N.distanceFromPrevious=g.distanceFromPrevious,N.distanceFromStart=g.distanceFromStart,u.forEach((x,H)=>{H&&(x.distanceFromStart=x.distanceFromStart+g.distanceFromStart)}),I.at(0).distanceFromPrevious=g.distanceFromPrevious,I.at(0).distanceFromStart=g.distanceFromStart,I.forEach((x,H)=>{H&&(x.distanceFromStart=x.distanceFromStart+g.distanceFromStart)}),F.at(0).distanceFromPrevious=g.distanceFromPrevious,F.at(0).distanceFromStart=g.distanceFromStart,F.forEach((x,H)=>{H&&(x.distanceFromStart=x.distanceFromStart+g.distanceFromStart)})),N.cp=h.cost.cp;const P=[h.etd,h.eta],E=k.findIndex(x=>x.id===N.cp.id);E===-1?(N.cp.segment=[P],k.push(N.cp)):k[E].segment.push(P),u.forEach(x=>{var q;((q=o.hours)==null?void 0:q.findIndex(V=>V.eta===x.eta))===-1&&o.hours.push(x)}),I.forEach(x=>{var q;((q=o.wps)==null?void 0:q.findIndex(V=>V.eta===x.eta))===-1&&o.wps.push(x)}),F.forEach(x=>{var q;((q=o==null?void 0:o.days)==null?void 0:q.findIndex(V=>V.eta===x.eta))===-1&&o.days.push(x)});const L=(f=o.wps)==null?void 0:f.findIndex(x=>x.eta===N.eta);L===-1?o.wps.push(N):o.wps[L]=N,g=u.at(-1)}return o.wps.sort((h,u)=>{p(h.etd).unix()-p(u.etd).unix()}),o.wps.forEach((h,u)=>{const I=o.wps[u-1];if(I){const F=h.distanceFromStart-(I.distanceFromStart||0),N=p(h.eta||h.etd).diff(p(I.etd||I.eta),"hour",!0),P=Math.round(F/N*100)/100;h.avgSpd=P;const E=T.LaneHelper.calculateBearing(I,h);I.bearing=E}}),{sample:o,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(i*1e4)/1e4,totalHrs:Math.round(a*1e3)/1e3,avgSpeed:Math.round(i/a*1e3)/1e3,wxFactor:Math.round(r*1e3)/1e3,cFactor:Math.round(l*1e3)/1e3,totalFoCons:Math.round(M*1e3)/1e3,totalDgoCons:Math.round(y*1e3)/1e3,cost:{total:Math.round(w*1e3)/1e3,hire:Math.round(m*1e3)/1e3,bunker:Math.round(C*1e3)/1e3},extend:{cps:k,eca:v,distanceInECA:Math.round(n*1e4)/1e4,hoursInECA:Math.round(s*1e3)/1e3,totalDgoConsInECA:Math.round(d*1e3)/1e3,speeds:e}}}}A.AISImpl=G,A.AlertHelper=dt,A.AlertLevel=ct,A.HifleetImpl=Mt,A.LoadCondition=lt,A.MyShipImpl=bt,A.MyVesselImpl=yt,A.ShipxyImpl=pt,A.SpeedHelper=W,A.SpeedLabel=ht,A.VesselTag=ut,A.alertHelper=gt,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(A,R){typeof exports=="object"&&typeof module<"u"?R(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"],R):(A=typeof globalThis<"u"?globalThis:A||self,R(A["idm-plugin-rabbitmq"]={},A.got,A["@log4js-node/log4js-api"],A.moment,A["@idm-plugin/geo2"],A["@idm-plugin/meteo2"],A["@idm-plugin/meteo"]))})(this,function(A,R,K,p,T,mt,at){"use strict";var St=Object.defineProperty;var kt=(A,R,K)=>R in A?St(A,R,{enumerable:!0,configurable:!0,writable:!0,value:K}):A[R]=K;var z=(A,R,K)=>(kt(A,typeof R!="symbol"?R+"":R,K),K);let b;try{b=K.getLogger("vessel")}catch{}finally{}class G{parseStatus(e){let t,o;switch(e){case 0:t="在航(主机推动)",o="Underway Using Engine";break;case 1:t="锚泊",o="Anchored";break;case 2:t="失控",o="Not operated";break;case 3:t="操纵受限",o="Limited airworthiness";break;case 4:t="吃水受限",o="Limited by ship's draft";break;case 5:t="靠泊",o="Mooring";break;case 6:t="搁浅",o="Stranded";break;case 7:t="捕捞作业",o="Engaged in fishing";break;case 8:t="靠帆船提供动力",o="Sailing";break;default:t="未定义",o="Undefined"}return{labelCn:t,labelEn:o}}}class yt extends G{constructor(t,o){super();z(this,"clientId");z(this,"clientSecret");z(this,"token");this.clientId=t,this.clientSecret=o}async authToken(t={}){const o="https://svc.data.myvessel.cn/ada/oauth/token",i={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},n=await R.post(o,i).json();b==null||b.info("[%s] fetch access token from: %s - %j",t.requestId,o,n),n.error||(this.token={accessToken:n.access_token,tokenType:n.token_type,expiresIn:n.expires_in,scope:n.scope,jti:n.jti,issuedAt:p().utc().format()})}async realTimePosition(t,o={}){var d,r,l;(!this.token||p().diff(p(this.token.issuedAt),"seconds")>((d=this.token)==null?void 0:d.expiresIn)-300)&&await this.authToken(o);const i="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",n={headers:{Authorization:`${(r=this.token)==null?void 0:r.tokenType} ${(l=this.token)==null?void 0:l.accessToken}`},searchParams:{mmsi:t}};b==null||b.info("[%s] fetch realtime position from: %s - %j",o.requestId,i,n);const a=await R.get(i,n).json();if(a.code)return b==null||b.warn("[%s] fetch realtime position failed: %j",o.requestId,i,{message:a.message,status:a.status,code:a.code}),a;const s=a.data;for(const M in s)!isNaN(s[M])&&Number(s[M])!==1/0&&(s[M]=Number(s[M]));if(s){const M=p(`${s.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:s.mmsi,name:s.vesselName||s.aisVesselName,imo:s.imo,callSign:s.callsign||s.aisCallSign,lat:s.lat,lng:s.lon,length:s.length,width:s.width,draught:s.currDraught,sog:s.sog,cog:s.cog,hdg:s.hdg,rot:s.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta)?p.utc(s.eta).format():void 0,destination:s.dest,positionTime:M.unix(),status:s.status,labelCn:s.statusNameCn,labelEn:s.statusNameEn,vesselType:s.vesselTypeNameEn,flag:s.flagCtryNameEn,clasz:s.classSociety,build:s.buildYear,dwt:s.dwt,grt:s.grt,net:s.net,method:"position",vendor:"myVessel",utc:M.utc().format()}}else return{}}async trajectory(t,o,i,n,a=!0,s={}){(!this.token||p().diff(p(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(s);const d=await this.realTimePosition(t,s),r=p(o),l=p(i),M=[];for(;l.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(t,r,r.clone().add(30,"day"),d,n,M,s),r.add(30,"day");return await this.trajectoryIn30Day(t,r,l,d,n,M,s),M}async trajectoryIn30Day(t,o,i,n,a,s,d={}){var m,C,k,v,g;const r="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:o.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};b==null||b.info("[%s] fetch trajectory from: %s - %j",d.requestId,r,l);const M=await R.post(r,l).json();if(M.code)return b==null||b.warn("[%s] fetch trajectory failed: %j",d.requestId,r,{message:M.message,status:M.status,code:M.code}),M;let y=-1;const w=p(`${(v=(k=M.data)==null?void 0:k[0])==null?void 0:v.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(g=M.data)==null||g.forEach(c=>{for(const P in c)!isNaN(c[P])&&Number(c[P])!==1/0&&(c[P]=Number(c[P]));const f=p(`${c.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),h=c.status,{labelCn:u,labelEn:I}=this.parseStatus(h),F={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:h,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(c.eta)?p(`${c.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").utc().format():void 0,destination:c.dest,positionTime:f.unix(),labelCn:u,labelEn:I,method:"trajectory",vendor:"myVessel",utc:f.utc().format()},N=Math.floor(f.diff(w,"minute",!0)/(a||1));N!==y&&(y=N,s.push(F))}),s}}class Mt extends G{constructor(t){super();z(this,"token");this.token=t}async realTimePosition(t,o={}){const i="https://api.hifleet.com/position/position/get/token",n={searchParams:{mmsi:t,usertoken:this.token}},a=await R.post(i,n).json();b==null||b.info("[%s] fetch realtime position from: %s - %j",o.requestId,i,n);const s=a==null?void 0:a.list;if(!s)return b==null||b.warn("[%s] fetch realtime position failed: %j",o.requestId,i,a),a;for(const w in s)!isNaN(s[w])&&Number(s[w])!==1/0&&(s[w]=Number(s[w]));s.status=s.sp>3?0:1;const d=s.status,{labelCn:r,labelEn:l}=this.parseStatus(d),M=p(`${s.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:s.m,name:s.n,imo:s.imonumber,callSign:s.callsign,lat:Math.round(s.la/60*1e5)/1e5,lng:Math.round(s.lo/60*1e5)/1e5,length:s.l,width:s.w,draught:s.draught,sog:s.sp,cog:s.co,hdg:s.h,rot:isNaN(s.rot)?0:s.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta)?p.utc(s.eta).format():void 0,destination:s.destination,vesselType:s.type,dwt:s.dwt,build:s.buildyear,flag:s.fn,positionTime:M.unix(),utc:M.utc().format(),status:d,labelCn:r,labelEn:l,method:"position",vendor:"hifleet"}}async search(t,o={}){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 a=await R.post(i,n).json();b==null||b.info("[%s] fetch vessel props from: %s - %j",o.requestId,i,n),a instanceof Array&&(a=a[0]);for(const d in a)!isNaN(a[d])&&Number(a[d])!==1/0&&(a[d]=Number(a[d]));const s={mmsi:a.m,name:a.n,imo:a.i,callSign:a.c,length:a.l,breadth:a.b,draught:a.dr,type:a.t};return i="https://www.hifleet.com/hifleetapi/sameShipSearch.do",a=await R.post(i,n).json(),b==null||b.info("[%s] search vessel dead weight from: %s - %j",o.requestId,i,n),a instanceof Array&&(a=a[0]),a&&(s.deadweight=Number(a.dwt)),s}async suggest(t,o={}){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"}},a=await R.post(i,n).json();b==null||b.info("[%s] suggest vessel props from: %s - %j",o.requestId,i,n);const s=[];for(const d of a)s.push({mmsi:!d.mmsi||isNaN(d.mmsi)?null:Number(d.mmsi),name:d.name,callSign:d.callsign,imo:!d.imo||isNaN(d.imo)?null:Number(d.imo),score:d._score});return s.sort((d,r)=>r.score-d.score),s}async trajectory(t,o,i,n,a=!0,s={}){var c,f,h;const d=await this.realTimePosition(t,s);let r=p(o);const l=p(i),M=p();if(a){let u=l.diff(r,"d",!0);u<0?r=l.clone().subtract(40,"d"):u<30?r.subtract(10,"d"):u<60?r.subtract(5,"d"):r=l.clone().subtract(80,"d"),u=M.diff(l,"d",!0),l.add(u>10?240:u*24,"h")}const y={searchParams:{endtime:l.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),starttime:r.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),mmsi:t,usertoken:this.token}},w="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",m=await R.get(w,y).json();b==null||b.info("[%s] fetch trajectory from: %s - %j",s.requestId,w,y);let C;m&&(C=((f=(c=m.ships)==null?void 0:c.offors)==null?void 0:f.ship)||[],C.length||b==null||b.warn("[%s] fetch trajectory failed: %j",s.requestId,m));const k=[];let v=-1;const g=p(`${(h=C==null?void 0:C[0])==null?void 0:h.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const u of C){for(const L in u)!isNaN(u[L])&&Number(u[L])!==1/0&&(u[L]=Number(u[L]));const I=p(`${u.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");u.status=u.sp>4?0:1;const{labelEn:F,labelCn:N}=this.parseStatus(u.status),P={mmsi:u.m,name:u.n,imo:d==null?void 0:d.imo,lat:u.la,lng:u.lo,draught:u.draught,sog:u.sp,cog:u.co,hdg:u.hdg,positionTime:I.unix(),utc:I.utc().format(),status:u.status,labelCn:N,labelEn:F,method:"trajectory",vendor:"hifleet"},E=Math.floor(I.diff(g,"minute",!0)/(n||1));E!==v&&(v=E,k.push(P))}return k}}class pt extends G{constructor(t){super();z(this,"token");this.token=t}async realTimePosition(t,o={}){const i={searchParams:{id:t,k:this.token,enc:1}},n="https://api.shipxy.com/apicall/GetSingleShip",a=await R.get(n,i).json();if(b==null||b.info("[%s] fetch realtime position from: %s - %j",o.requestId,n,i),(a==null?void 0:a.status)!==0)return a;const s=a.data[0];for(const y in s)!isNaN(s[y])&&Number(s[y])!==1/0&&(s[y]=Number(s[y]));const{labelCn:d,labelEn:r}=await this.parseStatus(s.navistat),l=p.unix(s.lasttime);return{mmsi:s.ShipID,name:s.name,imo:s.imo,callSign:s.callsign,lat:Math.round(s.lat/1e6*1e5)/1e5,lng:Math.round(s.lon/1e6*1e5)/1e5,length:Math.round(s.length/10*100)/100,width:Math.round(s.width/10*100)/100,draught:Math.round(s.draught/1e3*100)/100,sog:Math.round(s.sog*3600/1e3/1852*100)/100,cog:Math.round(s.cog/100*100)/100,hdg:Math.round(s.hdg/100*100)/100,rot:Math.round(s.rot/100*100)/100,positionTime:s.lasttime,utc:l.utc().format(),status:s.navistat,labelEn:r,labelCn:d,method:"position",vendor:"shipxy"}}async trajectory(t,o,i,n,a=!0,s={}){var g;const d=await this.realTimePosition(t,s),r=p(o),l=p(i),M="https://api.shipxy.com/apicall/GetShipTrack",y={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:r.unix(),etm:l.unix()}},w=await R.get(M,y).json();if(b==null||b.info("[%s] fetch trajectory from: %s - %j",s.requestId,M,y),(w==null?void 0:w.status)!==0)return w;const m=w==null?void 0:w.points,C=[],k=p.unix((g=m[0])==null?void 0:g.utc);let v=-1;for(const c of m){const f=p.unix(c.utc),h={imo:d==null?void 0:d.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:f.unix(),utc:f.utc().format(),method:"trajectory",vendor:"shipxy"},u=Math.floor(f.diff(k,"minute",!0)/(n||1));u!==v&&(v=u,C.push(h))}return C}}class bt extends G{constructor(t){super();z(this,"token");this.token=t}async getShipId(t,o={}){const i={headers:{appKey:this.token},json:{mmsiList:t}},n="https://api3.myships.com/sp/ships/getShipIdByMMSI",a=await R.post(n,i).json();return b==null||b.info("[%s] fetch ship id from: %s - %j",o.requestId,n,i),a.code!=="0"?a:a.data[0].shipId}async getShipInfo(t,o={}){const i={headers:{appKey:this.token},json:{shipId:t}},n="https://api3.myships.com/sp/ships/aissta",a=await R.post(n,i).json();if(b==null||b.info("[%s] fetch ship info from: %s - %j",o.requestId,n,i),a.code!=="0")return a;const s=a.data;let d=s.imo;return t==="407170"&&(d="9198379",b==null||b.warn("[%s] ship(%s) imo error: %s, should be %s",o.requestId,t,s.imo,d)),{mmsi:s.mmsi,name:s.shipnameEn,imo:d,callSign:s.callSign,length:s.length,width:s.breadth,draught:(s.draught||100)/10}}async realTimePosition(t,o={}){const i=await this.getShipId(t,o),n=await this.getShipInfo(i,o),a={headers:{appKey:this.token},json:{shipId:i}},s="https://api3.myships.com/sp/ships/position/latest",d=await R.post(s,a).json();b==null||b.info("[%s] fetch realtime position from: %s - %j",o.requestId,s,a);const r=d.data[0];for(const m in r)!isNaN(r[m])&&Number(r[m])!==1/0&&(r[m]=Number(r[m]));const{labelCn:l,labelEn:M}=await this.parseStatus(r.aisNavStatus),y=p.unix(r.posTime);return{...n,mmsi:t,lat:Math.round(r.lat/1e4/60*1e5)/1e5,lng:Math.round(r.lon/1e4/60*1e5)/1e5,sog:Math.round(r.sog/10*100)/100,cog:Math.round(r.cog/10*100)/100,hdg:Math.round(r.heading*100)/100,rot:Math.round(r.rot*100)/100,positionTime:r.posTime,utc:y.utc().format(),status:r.aisNavStatus,labelEn:M,labelCn:l,method:"position",vendor:"myship"}}async trajectory(t,o,i,n,a=!0,s={}){const d=p(o),r=p(i),l=await this.getShipId(t),M=await this.getShipInfo(l),y=[];for(;r.diff(d,"day",!0)>30;)await this.trajectoryIn30Day(l,d.unix(),d.add(30,"day").unix(),M,t,n,y);return await this.trajectoryIn30Day(l,d.unix(),r.unix(),M,t,n,y),y}async trajectoryIn30Day(t,o,i,n,a,s,d,r={}){var k;const l={headers:{appKey:this.token},json:{shipId:t,startTime:o,endTime:i}},M="https://api3.myships.com/sp/ships/position/history",y=await R.post(M,l).json();if(b==null||b.info("[%s] fetch trajectory from: %s - %j",r.requestId,M,l),y.code!=="0")return b==null||b.warn("[%s] invoke myship trajectory failed: %j",r.requestId,y),y;const w=y.data;for(const v in w)!isNaN(w[v])&&Number(w[v])!==1/0&&(w[v]=Number(w[v]));const m=p.unix((k=w[0])==null?void 0:k.posTime);let C=-1;for(const v of w){const g=p.unix(v.posTime),c={imo:n==null?void 0:n.imo,mmsi:a,lat:Math.round(v.lat/1e4/60*1e5)/1e5,lng:Math.round(v.lon/1e4/60*1e5)/1e5,sog:Math.round(v.sog/10*100)/100,cog:Math.round(v.cog/10*100)/100,hdg:Math.round(v.heading*100)/100,rot:Math.round(v.rot*100)/100,positionTime:g.unix(),utc:g.utc().format(),method:"trajectory",vendor:"myship"},f=Math.floor(g.diff(m,"minute",!0)/(s||1));f!==C&&(C=f,d.push(c))}return d}}let _;try{_=K.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(e,t={}){var s,d,r;_==null||_.info("[%s] parse rule: %s",t.requestId,e);const o=new RegExp("(?<=\\[)(.+)(?=])","g"),i=e.match(o)?(s=e.match(o))==null?void 0:s[0]:void 0,n=i==null?void 0:i.split(";");if(!n)return;const a={};for(let l=0;l<(n==null?void 0:n.length);l++){const M=(r=(d=n[l].match(o))==null?void 0:d[0])==null?void 0:r.split("],");if(l===0&&!M)a.scope=n[0];else if(M)for(let y=0,w=M.length;y<w;y++){const m=this.parseRule(M[y]);m&&(a[m.level]?m.key?a[m.level][m==null?void 0:m.key]=m:a[m.level]=m:m.key?a[m.level]={[m==null?void 0:m.key]:m}:a[m.level]=m)}}return a}parseRule(e,t={}){var a;_==null||_.debug("[%s] parse rule: %s",t.requestId,e),e=e.startsWith("[")?e:`[${e}`,e=e.endsWith("]")?e:`${e}]`;const o=new RegExp("(?<=\\[)(.+?)(?=])","g"),i=(a=e==null?void 0:e.match(o))==null?void 0:a[0],n=i==null?void 0:i.split(",");if(n)return{operator:n[0],number:Number.isNaN(Number(n[1]))?n[1]:Number(n[1]),level:n[2],time:Number(n[3]),key:n[4]}}checkWeather(e,t,o={}){var m,C,k,v,g,c,f,h,u,I,F,N,P,E,L;let i=0,n=0,a=0,s=0;const d=Math.round(((C=(m=t==null?void 0:t.SEVERE)==null?void 0:m.sigWave)==null?void 0:C.number)*1.6*100)/100,r=(v=(k=t==null?void 0:t.SEVERE)==null?void 0:k.sigWave)==null?void 0:v.number,l=(c=(g=t==null?void 0:t.HEAVY)==null?void 0:g.sigWave)==null?void 0:c.number,M=Math.round((((h=(f=t==null?void 0:t.SEVERE)==null?void 0:f.wind)==null?void 0:h.number)+2)*100)/100,y=(I=(u=t==null?void 0:t.SEVERE)==null?void 0:u.wind)==null?void 0:I.number,w=(N=(F=t==null?void 0:t.HEAVY)==null?void 0:F.wind)==null?void 0:N.number;for(let x=0;x<(e==null?void 0:e.length);x++){const H=e[x],q=(E=(P=H==null?void 0:H.meteo)==null?void 0:P.wave)==null?void 0:E.sig,V=(L=H==null?void 0:H.meteo)==null?void 0:L.wind,U=x?p(H.eta).diff(p(e[x-1].eta),"hour",!0):0;s=U>s?U:s,_==null||_.debug("[%s] check sig.wave: %j",o.requestId,{...q,dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:l}),(q==null?void 0:q.height)>=d?H.isDangerous=!0:(q==null?void 0:q.height)>=r?H.isSevere=!0:(q==null?void 0:q.height)>=l&&(H.isHeavy=!0),_==null||_.debug("[%s] check wind: %j",o.requestId,{...V,dgThd4Wd:M,svThd4Wd:y,hvThd4Wd:w}),(V==null?void 0:V.scale)>=M?(H.isDangerous=!0,delete H.isSevere,delete H.isHeavy):(V==null?void 0:V.scale)>y?(H.isDangerous||(H.isSevere=!0),delete H.isHeavy):(V==null?void 0:V.scale)===w&&!H.isDangerous&&!H.isSevere&&(H.isHeavy=!0),i+=H.isDangerous?U:0,n+=H.isSevere?U:0,a+=H.isHeavy?U:0}return i=Math.round(i*100)/100,n=Math.round(n*100)/100,a=Math.round(a*100)/100,s=Math.round(s),{sample:e,dangerous:i,severe:n,heavy:a,step:s<3?3:s,wind:{dgThd4Wd:M,svThd4Wd:y,hvThd4Wd:w},sig:{dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:l}}}}const gt=new dt;let S;try{S=K.getLogger("vessel")}catch{}finally{}const vt=new mt.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(e,t,o,i){let n=Math.round(e/(t*o*i)*100)/100;n=n<.55?.55:n>.85?.85:n;const a=[.55,.6,.65,.7,.75,.8,.85],s=a.map(d=>Math.abs(d-n));return a[s.indexOf(Math.min(...s))]}static froudeNumber(e,t,o=9.8){let i=Math.round(Math.sqrt(e*e/(o*t))*100)/100;return i=i<.05?.05:i>.3?.3:i,i}static amendFactor(e,t,o){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 a={.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 o==="Laden"&&(a=i[e]),a[0]+a[1]*t+a[2]*Math.pow(t,2)}static directionFactor(e,t=0){let o;return e>30&&e<=60?o=(1.7-.03*Math.pow(t-4,2))/2:e>60&&e<=150?o=(.9-.06*Math.pow(t-6,2))/2:e>150&&e<=180?o=(.4-.03*Math.pow(t-8,2))/2:o=1,Math.round(o*1e5)/1e5}static vesselTagFactor(e,t,o,i=0){i=i>6?i-.9*(i-6):i;let n;return o==="container"?n=.7*i+Math.pow(i,6.5)/(22*Math.pow(e,2/3)):t==="Ballast"?n=.7*i+Math.pow(i,6.5)/(2.7*Math.pow(e,2/3)):n=.5*i+Math.pow(i,6.5)/(2.7*Math.pow(e,2/3)),n}static waveHeightFactor(e,t){e=e<0?.2:e,e=e>6?e-.9*(e-6):e,e=e>9?9:e;let o;return t>30&&t<=60?o=-.6:t>60&&t<=90?o=-.4:t>90&&t<=120?o=e<3?.4:-.3:t>120&&t<=150?o=e<3?.6:-.5:t>150&&t<=180?o=e<3?.7:-.6:o=-.7,Math.round(o*(.144*Math.pow(e,2)+.178*e)*1e4)/1e4}static assembleProperties(e,t,o,i){var y;const n=e.lbp??e.length??e.lengthOverall??198.9642,a=e.draught??8,s=e.breadthMoulded??e.breadth??e.breadthExtreme??32.4572,d=e.deadweight??67035.7773,r=((y=e==null?void 0:e.type)==null?void 0:y.toLowerCase())||"common";return{tag:r.indexOf("container")>-1?"container":r.indexOf("tugs")>-1?"tugs":"common",lbp:n,loadCondition:t,draught:a,breadthMoulded:s,displacement:Math.round((d/1.025+a*s*n*.7)*1e4)/1e4,speed:Math.round((o??14.1382)*1852/3600*1e4)/1e4,bearing:i||90}}static async speedLoseAt(e,t,o,i="",n=2,a=!0,s=!1,d={}){let r;if(t.velocity&&s&&(e.speed=T.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),a){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 at.Meteo2Assist.autoPickMeteoModel(i),k=await vt.spotForecast(t.lat,t.lng,o.utc().format(),!1,!1,!0,{...d,pastDays:1,forecastDays:1,weatherModels:m,marineModels:C}),[v]=at.Meteo2Assist.pickHourly(k,o);l=at.Meteo2Assist.toLegacy(v)}catch(m){S.warn("[%s] meteo2 spot(%j) forecast failed: %s",d.requestId,{...t,eta:o.utc().format(),source:i},m)}const M=W.weatherFactor(e,l),y=W.currentFactor(e.bearing,l==null?void 0:l.current,n),w=Math.round((e.speed*1.943844+M+y)*100)/100;r={meteo:{...l},wxFactor:M,cFactor:y,speed:t.velocity&&s?t.velocity:w<0?1:w,eta:o.utc().format(),etd:o.utc().format()}}else r={wxFactor:0,cFactor:0,speed:t.velocity&&s?t.velocity:Math.round((e.speed*1.943844+0+0)*100)/100,eta:o.utc().format(),etd:o.utc().format()};return delete t.meteo,delete t.wxFactor,delete t.cFactor,delete t.speed,delete t.etd,{...r,...t}}static async speedLoseInHoursStep(e,t,o,i,n,a,s="",d=!0,r=!1,l={}){t.utc();const M=t.clone().add(14,"days"),y=[],w=[];let m=0,C=0,k,v;for(let g=0;g<a.length-1;g++){let c=a[g];c.distanceFromStart=Math.round((n+C)*1e4)/1e4;const f=a[g+1];if(e.bearing=T.LaneHelper.calculateBearing(c,f,!f.gcToPrevious),c.bearing=e.bearing,c.suspend&&r){c.eta=c.eta||t.utc().format(),c.elapsed=c.elapsed??0;const I=c.suspend-c.elapsed;if(i-m>I)i=i-m-I,t.add(I,"hour"),c.elapsed=c.suspend;else{const F=i-m;c.elapsed+=F,t.add(F,"hour"),i=0}if(S==null||S.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:v||c,to:c,next:a.filter(F=>F),wps:y,days:w}}else c.suspend=0;d=t.isAfter(M)?!1:d,c=await W.speedLoseAt(e,c,t,s,0,d,r,l),v=v||c,c.important&&y.push(c),t.isSameOrAfter(o)&&(w.push(c),o.add(24,"hour"));const h=T.LaneHelper.calculateDistance(c,f,!f.gcToPrevious);let u=Math.round(h/v.speed*1e5)/1e5;if(m+u<i){if(m+=u,t.add(u,"hour"),delete a[g],S==null||S.debug(`[%s] go to %j from %j with ${h}nm, and cost ${u} hours`,l.requestId,{lat:f.lat,lng:f.lng},{lat:v.lat,lng:v.lng,etd:v.etd}),C+=h,a.filter(I=>I).length<=1){k=f,k.eta=t.utc().format(),k.distanceFromPrevious=h,k.distanceFromStart=Math.round((n+C)*1e4)/1e4,y.push(k),delete a[g+1];break}}else{u=i-m,t.add(u,"hour");const I=T.LngLatHelper.roundPrecision(v.speed*u,5);k=T.LaneHelper.calculateCoordinate(c,e.bearing,I,"nauticalmiles",!f.gcToPrevious),k.eta=t.utc().format(),a[g]=k,S==null||S.debug(`[%s] go to %j from %j with ${I}nm, and cost ${u} hours`,l.requestId,{lat:k.lat,lng:k.lng},{lat:c.lat,lng:c.lng,etd:c.etd}),C+=I,k.distanceFromPrevious=Math.round(C*1e4)/1e4,k.distanceFromStart=Math.round((n+C)*1e4)/1e4;break}}return{etd:t,from:v,to:k,next:a.filter(g=>g),wps:y,days:w}}static currentFactor(e,t,o=0){const i=(e-(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 o&2?n=Math.ceil(n*100)/100:o&1?n=Math.floor(n*100)/100:n=Math.round(n*100)/100,Math.abs(n)>5?0:n}static weatherFactor(e,t){var M,y,w,m,C,k,v;S==null||S.debug("calculate weather factor via: %j",{...e,...t});const o=W.blockCoefficient(e.displacement,e.lbp,e.breadthMoulded,e.draught),i=W.froudeNumber(e.speed,e.lbp),n=W.amendFactor(o,i,e.loadCondition);let a=Math.abs(e.bearing%360-(((M=t==null?void 0:t.wind)==null?void 0:M.degree)%360||0));a=a>180?360-a:a;const s=W.directionFactor(a,(y=t==null?void 0:t.wind)==null?void 0:y.scale),d=W.vesselTagFactor(e.displacement,e.loadCondition,e.tag,(w=t==null?void 0:t.wind)==null?void 0:w.scale);let r=s*n*d/100*e.speed;r=Math.round(r*1.943844*1e4)/1e4*-1,e.tag==="tugs"&&Math.abs(r)>1&&(r=r/(Math.abs(Math.round(r))+1)),S==null||S.debug("wind wx factor = %d",r),a=Math.abs(e.bearing%360-(((C=(m=t==null?void 0:t.wave)==null?void 0:m.sig)==null?void 0:C.degree)%360||0));const l=W.waveHeightFactor(((v=(k=t==null?void 0:t.wave)==null?void 0:k.sig)==null?void 0:v.height)??1,a);return S==null||S.debug("wave wx factor = %d",l),r=r*.4+l,S==null||S.debug("weather factor = %d",r),r=Math.abs(r)>4?4*(Math.abs(r)/r)+Math.abs(r)/r*(Math.abs(r)-4)*.1:r,Math.round((r||0)*100)/100}static async analyseInstant(e,t,o,i,n,a="",s=0,d=!0,r=!1,l={}){var Q,X,Z,$,tt,et;const M=p().valueOf();e.lng=T.LngLatHelper.convertToStdLng(e.lng);const{route:y,waypoints:w}=n.points,m=T.LaneHelper.calculateSubRoute(e,y);if(((Q=m[0])==null?void 0:Q.length)<=1)return;const{v0:C,label:k}=e.sog?{v0:e.sog,label:e.label||"Other"}:{v0:i.speed,label:"CP"},v=W.assembleProperties(o,i.loadCondition,C,0),g=w.length?T.LaneHelper.calculateSubWaypoints(e,w):[];g.forEach(Y=>Y.important=!0);const c={from:{...e},route:m,waypoints:g,v0:C,label:k},f={hours:[],days:[],wps:[]};s||(T.LaneHelper.calculateRouteDistance(m)/i.speed<=72?s=3:s=6);let h=T.LaneHelper.simplifyRouteToCoordinates(m,g,0),u=0,I=0,F=0,N=0;t=p(t).utc();const P=t.clone();for(;h.length>0;){const Y=s-t.hour()%s,J=Math.ceil(t.clone().add(Y,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,j=await W.speedLoseInHoursStep(v,t,P,J,u,h,a,d,r,l);(X=j.from)!=null&&X.speed&&(f.hours.push(j.from),f.wps.push(...j.wps),f.days.push(...j.days)),h=j==null?void 0:j.next,h.length||f.hours.push(j==null?void 0:j.to),u+=Math.round((((Z=j==null?void 0:j.to)==null?void 0:Z.distanceFromPrevious)??0)*1e4)/1e4}const E=f.hours;for(let Y=0;Y<E.length-1;Y++){const J=p(E[Y+1].eta).diff(E[Y].etd,"hour",!0)||1;I+=(E[Y].wxFactor||0)*J,F+=(E[Y].cFactor||0)*J,N+=J}($=f.wps)==null||$.forEach((Y,J)=>{Y.positionTime=p.utc(Y.etd||Y.eta).unix();const j=f.wps[J-1];if(j){const B=Y.distanceFromStart-j.distanceFromStart,O=p(Y.eta||Y.etd).diff(p(j.etd||j.eta),"h",!0);Y.avgSpd=Math.round(B/O*100)/100;const rt=T.LaneHelper.calculateBearing(j,Y);j.bearing=rt}}),f.wps=(tt=f.wps)==null?void 0:tt.reduce((Y,J)=>(Y.some(j=>Math.round(j.positionTime/60)===Math.round(J.positionTime/60))||Y.push(J),Y),[]),c.sample=f;const L=f.hours.at(0),x=f.hours.at(-1);c.distance=Math.round(x.distanceFromStart*1e4)/1e4,c.etd=p(L.eta).utc().format(),c.eta=p(x.eta).utc().format(),c.wxFactor=Math.round(I/N*1e4)/1e4,c.cFactor=Math.round(F/N*1e4)/1e4,c.avgSpeed=Math.round(x.distanceFromStart/N*1e4)/1e4,c.totalHrs=Math.round(N*1e4)/1e4;const{distanceInECA:H,hoursInECA:q,totalDgoConsInECA:V,eca:U}=await this.calculateECA(c,i,l),nt=T.LngLatHelper.roundPrecision(i.fo/24*(N-q),3),ot=T.LngLatHelper.roundPrecision(i.dgo/24*N,3);c.extend={eca:U,distanceInECA:H,hoursInECA:q,totalDgoConsInECA:V},c.totalFoCons=nt,c.totalDgoCons=ot;const st=p().valueOf()-M,it=((et=f==null?void 0:f.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,st,it,Math.round(st/it*1e3)/1e3),c}static async analyseInstantWithThreshed(e,t,o,i,n,a,s,d="",r=3,l=!0,M=!1,y={}){var Z,$,tt,et,Y,J;const w=p().valueOf();e.lng=T.LngLatHelper.convertToStdLng(e.lng);const{v0:m,label:C}=e.sog?{v0:e.sog,label:e.label||"Other"}:{v0:n.speed,label:"CP"},k=W.assembleProperties(i,n.loadCondition,m,0),v=T.LaneHelper.calculateSubRoute(e,a);if(((Z=v[0])==null?void 0:Z.length)<=1)return;const g=s.length?T.LaneHelper.calculateSubWaypoints(e,s):[];g.forEach(j=>j.important=!0);let c=T.LaneHelper.simplifyRouteToCoordinates(v,g,0),f=0,h=0,u=0,I=0;const F={hours:[],wps:[],days:[]};t=p(t).utc();const N=t.clone();for(;c.length>0;){const j=r-t.hour()%r;let B=Math.ceil(t.clone().add(j,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;B=t.clone().add(B,"h").isSameOrAfter(o)?o.diff(t,"h",!0)*1e4/1e4:B;const O=await W.speedLoseInHoursStep(k,t,N,B,f,c,d,l,M,y);if(($=O.from)!=null&&$.speed&&(F.hours.push(O.from),O!=null&&O.wps&&F.wps.push(...O.wps),F.days.push(...O.days)),c=O==null?void 0:O.next,c.length||F.hours.push(O==null?void 0:O.to),f+=Math.round((((tt=O==null?void 0:O.to)==null?void 0:tt.distanceFromPrevious)??0)*1e4)/1e4,!B)break}F.wps=(et=F.wps)==null?void 0:et.reduce((j,B)=>(j.some(O=>Math.round(p(O.etd).unix()/60)===Math.round(p(B.etd).unix()/60))||j.push(B),j),[]),(Y=F.wps)==null||Y.forEach((j,B)=>{const O=F.wps[B-1];if(O){const rt=j.distanceFromStart-O.distanceFromStart,wt=p(j.eta||j.etd).diff(p(O.etd||O.eta),"h",!0);j.avgSpd=Math.round(rt/wt*100)/100;const It=T.LaneHelper.calculateBearing(O,j);O.bearing=It}});const P=F.hours;for(let j=0;j<P.length-1;j++){const B=p(P[j+1].eta).diff(P[j].etd,"hour",!0);h+=P[j].wxFactor*B,u+=P[j].cFactor*B,I+=B}const E=F.hours.at(0),L=F.hours.at(-1),x=await T.LaneHelper.calculateRangeRoute(E,L,v),H=await T.LaneHelper.calculateRangeWaypoints(E,L,v,g),q={sample:F,distance:Math.round(((L==null?void 0:L.distanceFromStart)||0)*1e4)/1e4,etd:p(E.eta).utc().format(),eta:p(L==null?void 0:L.eta).utc().format(),wxFactor:Math.round(h/I*1e4)/1e4,cFactor:Math.round(u/I*1e4)/1e4,avgSpeed:Math.round(((L==null?void 0:L.distanceFromStart)||0)/I*1e4)/1e4,totalHrs:Math.round(I*1e4)/1e4,from:E,to:L,route:x,waypoints:H,v0:m,label:C},{distanceInECA:V,hoursInECA:U,totalDgoConsInECA:nt,eca:ot}=await this.calculateECA(q,n,y),ft=T.LngLatHelper.roundPrecision(n.fo/24*(I-U),3),st=T.LngLatHelper.roundPrecision(n.dgo/24*I,3);q.extend={eca:ot,distanceInECA:V,hoursInECA:U,totalDgoConsInECA:nt},q.totalDgoCons=st,q.totalFoCons=ft;const Q=p().valueOf()-w,X=((J=F==null?void 0:F.hours)==null?void 0:J.length)||1;return S==null||S.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",y==null?void 0:y.requestId,Q,X,Math.round(Q/X*1e3)/1e3),q}static async analyseCost(e,t,o,i,n={}){var v,g;const a=p().valueOf(),s=[];e.speedStep=e.speedStep||3,e.alterStep=e.alterStep??1;const d=T.LaneHelper.calculateRouteDistance(i.route);let r=0;o.forEach(c=>{const f=Math.ceil(d/c.speed/24);r=r<f?f:r}),r=r*1.3;const l=p.utc(e.etd).add(r??14,"day");let M=1;for(const c of o){const f=JSON.parse(JSON.stringify(i.route)),h=JSON.parse(JSON.stringify(i.waypoints)),u=await W.analyseInstantWithThreshed({lat:e.lat,lng:e.lng},e.etd,l,t,c,f,h,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,n);u&&(await W.calculateCost(u,c,e,n),s.push(u),S==null||S.info("[%s][L%d-%d] analyse from %s to %s cost: %j",n.requestId,1,M,e.etd,l.format(),{cost:u.cost.total,hire:u.cost.hire,bunker:u.cost.bunker,distance:u.distance,hours:u.totalHrs,cp:`${c.speed}/${c.fo}/${c.dgo}`})),M++}s.sort((c,f)=>c.cost.total-f.cost.total);const y=s.at(0),w=s.at(1),m=[];if(m.push({combined:!1,speeds:[y],cost:(v=y.cost)==null?void 0:v.total}),w){const c=y.cost.cp,f=w.cost.cp,h=p(y.eta),u=p(y.etd),I=h.diff(u,"days",!0);let F=Math.ceil(I/2);F=F>7?7:F<e.alterStep?e.alterStep:F;let N=2,P={combined:!1,speeds:[w],cost:(g=w.cost)==null?void 0:g.total},E;for(;F>=e.alterStep;){const L=await W.combinedAnalyse(e,t,l,[c,f],i,F,{...n,level:N});if(P.cost>L.cost?E?(E==null?void 0:E.cost)>L.cost&&(E=L):(E=P,P=L):(!E||(E==null?void 0:E.cost)>L.cost)&&(E=L),F<=e.alterStep)break;F=Math.ceil(F/2),N+=1}m.push(P),E&&m.push(E)}const k=p().valueOf()-a;return S==null||S.info("[%s] analyse elapsed: %d ms",n==null?void 0:n.requestId,k),m.sort((c,f)=>c.cost-f.cost)}static async combinedAnalyse(e,t,o,i,n,a,s={}){s.counter=1,S==null||S.info("[%s][L%d] analyse with alternate cp in every %d days",s.requestId,s.level,a);const d=await W.alternateAnalyse(e,t,o,i,0,n,a,s),r=d.reduce((f,h)=>f+h.cost.total,0),l=d.reduce((f,h)=>f+h.cost.hire,0),M=d.reduce((f,h)=>f+h.cost.bunker,0),y=d.reduce((f,h)=>f+h.distance,0),w=d.reduce((f,h)=>f+h.totalHrs,0);S==null||S.info("[%s][L%d] cost with cpa/cpb turn: %j",s.requestId,s.level,{cost:r,hire:l,bunker:M,distance:y,hours:w});const m=await W.alternateAnalyse(e,t,o,i,1,n,a,s),C=m.reduce((f,h)=>f+h.cost.total,0),k=m.reduce((f,h)=>f+h.cost.hire,0),v=m.reduce((f,h)=>f+h.cost.bunker,0),g=m.reduce((f,h)=>f+h.distance,0),c=m.reduce((f,h)=>f+h.totalHrs,0);return S==null||S.info("[%s][L%d] cost with cpb/cpa turn: %j",s.requestId,s.level,{cost:C,hire:k,bunker:v,distance:g,hours:c}),r<C?{combined:!0,cost:Math.round(r*1e3)/1e3,speeds:d,step:a}:{combined:!0,cost:Math.round(C*1e3)/1e3,speeds:m,step:a}}static async alternateAnalyse(e,t,o,i,n,a,s,d={}){var y,w;let r=p.utc(e.etd);const l={lat:e.lat,lng:e.lng},M=[];for(;r.isBefore(o);){const m=r.clone().utc().add(s,"day"),C=JSON.parse(JSON.stringify(a.route)),k=JSON.parse(JSON.stringify(a.waypoints)),v=i[n],g=await W.analyseInstantWithThreshed(l,r.utc().format(),m,t,v,C,k,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,d);g&&(await W.calculateCost(g,v,e,d),S==null||S.info("[%s][L%d-%d] analyse from %s to %s cost: %j",d.requestId,d.level,d.counter,r.utc().format(),m.utc().format(),{cost:g.cost.total,hire:g.cost.hire,bunker:g.cost.bunker,distance:g.distance,hours:g.totalHrs,cp:`${v.speed}/${v.fo}/${v.dgo}`})),d.counter=d.counter+1;const c=(w=(y=g==null?void 0:g.sample)==null?void 0:y.hours)==null?void 0:w.at(-1);if(c)l.lat=c.lat,l.lng=c.lng,r=p(c.eta),M.push(g),n=n?0:1;else break}return M}static async calculateCost(e,t,o,i={}){var n;if(e){const a=Math.round(e.totalHrs/24*(o.dailyHire||0)*(1-(o.addComm||0))*1e3)/1e3,s=Math.round(e.totalFoCons*(o.priceFO||0)*1e3)/1e3,d=Math.round((e.totalDgoCons+(((n=e.extend)==null?void 0:n.totalDgoConsInECA)||0))*(o.priceDGO||0)*1e3)/1e3;e.cost={total:Math.round((a+s+d)*1e3)/1e3,hire:a,bunker:Math.round((s+d)*1e3)/1e3,cp:t}}return e}static async calculateECA(e,t,o={}){var d,r;const i=await T.LaneHelper.intersectInECA(e.route);let n=0,a=0,s=0;e.sample.wps.forEach(l=>{l.positionTime=p.utc(l.etd||l.eta).unix()});for(const l of i){n+=l.distance;const M=await T.LaneHelper.deadReckoningTime((d=l.waypoints)==null?void 0:d.at(0),e.sample.wps),y=await T.LaneHelper.deadReckoningTime((r=l.waypoints)==null?void 0:r.at(-1),e.sample.wps);l.in=M,l.out=y,l.totalHrs=T.LngLatHelper.roundPrecision((y.positionTime-M.positionTime)/3600,2),l.totalDgoCons=T.LngLatHelper.roundPrecision(t.fo/24*l.totalHrs,3),a+=l.totalHrs,s+=l.totalDgoCons}return n=T.LngLatHelper.roundPrecision(n,3),a=T.LngLatHelper.roundPrecision(a,3),s=T.LngLatHelper.roundPrecision(s,3),{distanceInECA:n,hoursInECA:a,totalDgoConsInECA:s,eca:i}}static async mergeSpeeds(e,t={}){var c,f;const o={hours:[],wps:[],days:[]},i=e.reduce((h,u)=>h+u.distance,0),n=e.reduce((h,u)=>{var I;return h+(((I=u.extend)==null?void 0:I.distanceInECA)||0)},0),a=e.reduce((h,u)=>h+u.totalHrs,0),s=e.reduce((h,u)=>{var I;return h+(((I=u.extend)==null?void 0:I.hoursInECA)||0)},0),d=e.reduce((h,u)=>{var I;return h+(((I=u.extend)==null?void 0:I.totalDgoConsInECA)||0)},0),r=e.reduce((h,u)=>h+u.wxFactor*u.totalHrs/a,0),l=e.reduce((h,u)=>h+u.cFactor*u.totalHrs/a,0),M=e.reduce((h,u)=>h+u.totalFoCons,0),y=e.reduce((h,u)=>h+u.totalDgoCons,0),w=e.reduce((h,u)=>h+u.cost.total,0),m=e.reduce((h,u)=>h+u.cost.hire,0),C=e.reduce((h,u)=>h+u.cost.bunker,0),k=[],v=[];let g;for(const h of e){v.push(...((c=h.extend)==null?void 0:c.eca)||[]);const u=h.sample.hours,I=h.sample.wps,F=h.sample.days,N=u.at(0);g&&(N.distanceFromPrevious=g.distanceFromPrevious,N.distanceFromStart=g.distanceFromStart,u.forEach((x,H)=>{H&&(x.distanceFromStart=x.distanceFromStart+g.distanceFromStart)}),I.at(0).distanceFromPrevious=g.distanceFromPrevious,I.at(0).distanceFromStart=g.distanceFromStart,I.forEach((x,H)=>{H&&(x.distanceFromStart=x.distanceFromStart+g.distanceFromStart)}),F.at(0).distanceFromPrevious=g.distanceFromPrevious,F.at(0).distanceFromStart=g.distanceFromStart,F.forEach((x,H)=>{H&&(x.distanceFromStart=x.distanceFromStart+g.distanceFromStart)})),N.cp=h.cost.cp;const P=[h.etd,h.eta],E=k.findIndex(x=>x.id===N.cp.id);E===-1?(N.cp.segment=[P],k.push(N.cp)):k[E].segment.push(P),u.forEach(x=>{var q;((q=o.hours)==null?void 0:q.findIndex(V=>V.eta===x.eta))===-1&&o.hours.push(x)}),I.forEach(x=>{var q;((q=o.wps)==null?void 0:q.findIndex(V=>V.eta===x.eta))===-1&&o.wps.push(x)}),F.forEach(x=>{var q;((q=o==null?void 0:o.days)==null?void 0:q.findIndex(V=>V.eta===x.eta))===-1&&o.days.push(x)});const L=(f=o.wps)==null?void 0:f.findIndex(x=>x.eta===N.eta);L===-1?o.wps.push(N):o.wps[L]=N,g=u.at(-1)}return o.wps.sort((h,u)=>{p(h.etd).unix()-p(u.etd).unix()}),o.wps.forEach((h,u)=>{const I=o.wps[u-1];if(I){const F=h.distanceFromStart-(I.distanceFromStart||0),N=p(h.eta||h.etd).diff(p(I.etd||I.eta),"hour",!0),P=Math.round(F/N*100)/100;h.avgSpd=P;const E=T.LaneHelper.calculateBearing(I,h);I.bearing=E}}),{sample:o,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(i*1e4)/1e4,totalHrs:Math.round(a*1e3)/1e3,avgSpeed:Math.round(i/a*1e3)/1e3,wxFactor:Math.round(r*1e3)/1e3,cFactor:Math.round(l*1e3)/1e3,totalFoCons:Math.round(M*1e3)/1e3,totalDgoCons:Math.round(y*1e3)/1e3,cost:{total:Math.round(w*1e3)/1e3,hire:Math.round(m*1e3)/1e3,bunker:Math.round(C*1e3)/1e3},extend:{cps:k,eca:v,distanceInECA:Math.round(n*1e4)/1e4,hoursInECA:Math.round(s*1e3)/1e3,totalDgoConsInECA:Math.round(d*1e3)/1e3,speeds:e}}}}A.AISImpl=G,A.AlertHelper=dt,A.AlertLevel=ct,A.HifleetImpl=Mt,A.LoadCondition=lt,A.MyShipImpl=bt,A.MyVesselImpl=yt,A.ShipxyImpl=pt,A.SpeedHelper=W,A.SpeedLabel=ht,A.VesselTag=ut,A.alertHelper=gt,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
|