@idm-plugin/vessel 1.4.2 → 1.4.3

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
@@ -816,7 +816,7 @@ class C {
816
816
  let r = e * n * c / 100 * s.speed;
817
817
  r = Math.round(r * 1.943844 * 1e4) / 1e4 * -1, s.tag === "tugs" && Math.abs(r) > 1 && (r = r / (Math.abs(Math.round(r)) + 1)), D == null || D.debug("wind wx factor = %d", r), a = Math.abs(s.bearing % 360 - (((Y = (m = t == null ? void 0 : t.wave) == null ? void 0 : m.sig) == null ? void 0 : Y.degree) % 360 || 0));
818
818
  const d = C.waveHeightFactor(((b = (j = t == null ? void 0 : t.wave) == null ? void 0 : j.sig) == null ? void 0 : b.height) ?? 1, a);
819
- return D == null || D.debug("wave wx factor = %d", d), r = r * 0.6 + d, D == null || D.debug("weather factor = %d", r), r = Math.abs(r) > 4 ? 4 * (Math.abs(r) / r) + Math.abs(r) / r * (Math.abs(r) - 4) * 0.1 : r, Math.round(r * 100) / 100;
819
+ return D == null || D.debug("wave wx factor = %d", d), r = r * 0.4 + d, D == null || D.debug("weather factor = %d", r), r = Math.abs(r) > 4 ? 4 * (Math.abs(r) / r) + Math.abs(r) / r * (Math.abs(r) - 4) * 0.1 : r, Math.round(r * 100) / 100;
820
820
  }
821
821
  /**
822
822
  * 全程失速分析(走完航程)
@@ -1 +1 @@
1
- (function(H,D){typeof exports=="object"&&typeof module<"u"?D(exports,require("got"),require("@log4js-node/log4js-api"),require("moment"),require("@idm-plugin/geo"),require("@idm-plugin/meteo")):typeof define=="function"&&define.amd?define(["exports","got","@log4js-node/log4js-api","moment","@idm-plugin/geo","@idm-plugin/meteo"],D):(H=typeof globalThis<"u"?globalThis:H||self,D(H["idm-plugin-rabbitmq"]={},H.got,H["@log4js-node/log4js-api"],H.moment,H["@idm-plugin/geo"],H["@idm-plugin/meteo"]))})(this,function(H,D,Z,g,O,ot){"use strict";var lt=Object.defineProperty;var ft=(H,D,Z)=>D in H?lt(H,D,{enumerable:!0,configurable:!0,writable:!0,value:Z}):H[D]=Z;var K=(H,D,Z)=>(ft(H,typeof D!="symbol"?D+"":D,Z),Z);let u;try{u=Z.getLogger("vessel")}catch{}finally{}class z{parseStatus(s){let t,i;switch(s){case 0:t="在航(主机推动)",i="The engine is in use";break;case 1:t="锚泊",i="Anchored";break;case 2:t="失控",i="Not operated";break;case 3:t="操纵受限",i="Limited airworthiness";break;case 4:t="吃水受限",i="Limited by ship's draft";break;case 5:t="靠泊",i="Mooring";break;case 6:t="搁浅",i="Stranded";break;case 7:t="捕捞作业",i="Engaged in fishing";break;case 8:t="靠帆船提供动力",i="Sailing";break;default:t="未定义",i="Undefined"}return{labelCn:t,labelEn:i}}}class it extends z{constructor(t,i){super();K(this,"clientId");K(this,"clientSecret");K(this,"token");this.clientId=t,this.clientSecret=i}async authToken(t={}){const i="https://svc.data.myvessel.cn/ada/oauth/token",n={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},o=await D.post(i,n).json();u==null||u.info("[%s] fetch access token from: %s - %j",t.requestId,i,o),o.error||(this.token={accessToken:o.access_token,tokenType:o.token_type,expiresIn:o.expires_in,scope:o.scope,jti:o.jti,issuedAt:g().utc().format()})}async realTimePosition(t,i={}){var d,l,p;(!this.token||g().diff(g(this.token.issuedAt),"seconds")>((d=this.token)==null?void 0:d.expiresIn)-300)&&await this.authToken(i);const n="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",o={headers:{Authorization:`${(l=this.token)==null?void 0:l.tokenType} ${(p=this.token)==null?void 0:p.accessToken}`},searchParams:{mmsi:t}};u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,n,o);const a=await D.get(n,o).json();if(a.code)return u==null||u.warn("[%s] fetch realtime position failed: %j",i.requestId,n,{message:a.message,status:a.status,code:a.code}),a;const e=a.data;for(const f in e)!isNaN(e[f])&&Number(e[f])!==1/0&&(e[f]=Number(e[f]));const c=g(`${e.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:e.mmsi,name:e.vesselName,imo:e.imo,callSign:e.callsign,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:e.eta,destination:e.dest,positionTime:c.unix(),status:e.status,labelCn:e.statusNameCn,labelEn:e.statusNameEn,method:"position",vendor:"myVessel",utc:c.utc().format()}}async trajectory(t,i,n,o,a=!0,e={}){(!this.token||g().diff(g(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(e);const c=await this.realTimePosition(t,e),r=g(i),d=g(n),l=[];for(;d.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(t,r,r.clone().add(30,"day"),c,o,l,e),r.add(30,"day");return await this.trajectoryIn30Day(t,r,d,c,o,l,e),l}async trajectoryIn30Day(t,i,n,o,a,e,c={}){var m,Y,j,v,M;const r="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",d={headers:{Authorization:`${(m=this.token)==null?void 0:m.tokenType} ${(Y=this.token)==null?void 0:Y.accessToken}`},json:{mmsi:t,startTime:i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};u==null||u.info("[%s] fetch trajectory from: %s - %j",c.requestId,r,d);const l=await D.post(r,d).json();if(l.code)return u==null||u.warn("[%s] fetch trajectory failed: %j",c.requestId,r,{message:l.message,status:l.status,code:l.code}),l;let p=-1;const f=g(`${(v=(j=l.data)==null?void 0:j[0])==null?void 0:v.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(M=l.data)==null||M.forEach(h=>{for(const S in h)!isNaN(h[S])&&Number(h[S])!==1/0&&(h[S]=Number(h[S]));const I=g(`${h.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),w=h.eta?g(`${h.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,y=h.status,{labelCn:b,labelEn:x}=this.parseStatus(y),E={mmsi:h.mmsi,imo:o==null?void 0:o.imo,lat:h.lat,lng:h.lon,sog:h.sog,cog:h.cog,hdg:h.hdg,draught:h.draught,status:y,eta:w==null?void 0:w.unix(),destination:h.dest,positionTime:I.unix(),labelCn:b,labelEn:x,method:"trajectory",vendor:"myVessel",utc:I.utc().format()},V=Math.floor(I.diff(f,"minute",!0)/(a||1));V!==p&&(p=V,e.push(E))}),e}}class rt extends z{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,i={}){const n="https://api.hifleet.com/position/position/get/token",o={searchParams:{mmsi:t,usertoken:this.token}},a=await D.post(n,o).json();u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,n,o);const e=a==null?void 0:a.list;if(!e)return u==null||u.warn("[%s] fetch realtime position failed: %j",i.requestId,n,a),a;for(const f in e)!isNaN(e[f])&&Number(e[f])!==1/0&&(e[f]=Number(e[f]));e.status=e.sp>3?0:1;const c=e.status,{labelCn:r,labelEn:d}=this.parseStatus(c),l=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(`${e.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").unix():void 0,destination:e.destination,positionTime:l.unix(),utc:l.utc().format(),status:c,labelCn:r,labelEn:d,method:"position",vendor:"hifleet"}}async search(t,i={}){let n="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const o={searchParams:{keyword:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let a=await D.post(n,o).json();u==null||u.info("[%s] fetch vessel props from: %s - %j",i.requestId,n,o),a instanceof Array&&(a=a[0]);for(const c in a)!isNaN(a[c])&&Number(a[c])!==1/0&&(a[c]=Number(a[c]));const e={mmsi:a.m,name:a.n,imo:a.i,callSign:a.c,length:a.l,breadth:a.b,draught:a.dr};return n="https://www.hifleet.com/hifleetapi/sameShipSearch.do",a=await D.post(n,o).json(),u==null||u.info("[%s] fetch vessel dead weight from: %s - %j",i.requestId,n,o),a instanceof Array&&(a=a[0]),a&&(e.deadweight=Number(a.dwt)),e}async trajectory(t,i,n,o,a=!0,e={}){var h,I,w;const c=await this.realTimePosition(t,e);let r=g(i);const d=g(n),l=g();if(a){let y=d.diff(r,"d",!0);y<0?r=d.clone().subtract(40,"d"):y<30?r.subtract(10,"d"):y<60?r.subtract(5,"d"):r=d.clone().subtract(80,"d"),y=l.diff(d,"d",!0),d.add(y>10?240:y*24,"h")}const p={searchParams:{endtime:d.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}},f="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",m=await D.get(f,p).json();u==null||u.info("[%s] fetch trajectory from: %s - %j",e.requestId,f,p);let Y;m&&(Y=((I=(h=m.ships)==null?void 0:h.offors)==null?void 0:I.ship)||[],Y.length||u==null||u.warn("[%s] fetch trajectory failed: %j",e.requestId,m));const j=[];let v=-1;const M=g(`${(w=Y==null?void 0:Y[0])==null?void 0:w.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const y of Y){for(const _ in y)!isNaN(y[_])&&Number(y[_])!==1/0&&(y[_]=Number(y[_]));const b=g(`${y.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");y.status=y.sp>4?0:1;const{labelEn:x,labelCn:E}=this.parseStatus(y.status),V={mmsi:y.m,name:y.n,imo:c==null?void 0:c.imo,lat:y.la,lng:y.lo,draught:y.draught,sog:y.sp,cog:y.co,hdg:y.hdg,positionTime:b.unix(),utc:b.utc().format(),status:y.status,labelCn:E,labelEn:x,method:"trajectory",vendor:"hifleet"},S=Math.floor(b.diff(M,"minute",!0)/(o||1));S!==v&&(v=S,j.push(V))}return j}}class ct extends z{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,i={}){const n={searchParams:{id:t,k:this.token,enc:1}},o="https://api.shipxy.com/apicall/GetSingleShip",a=await D.get(o,n).json();if(u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,o,n),(a==null?void 0:a.status)!==0)return a;const e=a.data[0];for(const p in e)!isNaN(e[p])&&Number(e[p])!==1/0&&(e[p]=Number(e[p]));const{labelCn:c,labelEn:r}=await this.parseStatus(e.navistat),d=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:d.utc().format(),status:e.navistat,labelEn:r,labelCn:c,method:"position",vendor:"shipxy"}}async trajectory(t,i,n,o,a=!0,e={}){var M;const c=await this.realTimePosition(t,e),r=g(i),d=g(n),l="https://api.shipxy.com/apicall/GetShipTrack",p={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:r.unix(),etm:d.unix()}},f=await D.get(l,p).json();if(u==null||u.info("[%s] fetch trajectory from: %s - %j",e.requestId,l,p),(f==null?void 0:f.status)!==0)return f;const m=f==null?void 0:f.points,Y=[],j=g.unix((M=m[0])==null?void 0:M.utc);let v=-1;for(const h of m){const I=g.unix(h.utc),w={imo:c==null?void 0:c.imo,mmsi:t,sog:Math.round(h.sog*3600/1e3/1852*100)/100,cog:Math.round(h.cog/100*100)/100,lat:Math.round(h.lat/1e6*1e5)/1e5,lng:Math.round(h.lon/1e6*1e5)/1e5,positionTime:I.unix(),utc:I.utc().format(),method:"trajectory",vendor:"shipxy"},y=Math.floor(I.diff(j,"minute",!0)/(o||1));y!==v&&(v=y,Y.push(w))}return Y}}class dt extends z{constructor(t){super();K(this,"token");this.token=t}async getShipId(t,i={}){const n={headers:{appKey:this.token},json:{mmsiList:t}},o="https://api3.myships.com/sp/ships/getShipIdByMMSI",a=await D.post(o,n).json();return u==null||u.info("[%s] fetch ship id from: %s - %j",i.requestId,o,n),a.code!=="0"?a:a.data[0].shipId}async getShipInfo(t,i={}){const n={headers:{appKey:this.token},json:{shipId:t}},o="https://api3.myships.com/sp/ships/aissta",a=await D.post(o,n).json();if(u==null||u.info("[%s] fetch ship info from: %s - %j",i.requestId,o,n),a.code!=="0")return a;const e=a.data;let c=e.imo;return t==="407170"&&(c="9198379",u==null||u.warn("[%s] ship(%s) imo error: %s, should be %s",i.requestId,t,e.imo,c)),{mmsi:e.mmsi,name:e.shipnameEn,imo:c,callSign:e.callSign,length:e.length,width:e.breadth,draught:(e.draught||100)/10}}async realTimePosition(t,i={}){const n=await this.getShipId(t,i),o=await this.getShipInfo(n,i),a={headers:{appKey:this.token},json:{shipId:n}},e="https://api3.myships.com/sp/ships/position/latest",c=await D.post(e,a).json();u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,e,a);const r=c.data[0];for(const m in r)!isNaN(r[m])&&Number(r[m])!==1/0&&(r[m]=Number(r[m]));const{labelCn:d,labelEn:l}=await this.parseStatus(r.aisNavStatus),p=g.unix(r.posTime);return{...o,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:p.utc().format(),status:r.aisNavStatus,labelEn:l,labelCn:d,method:"position",vendor:"myship"}}async trajectory(t,i,n,o,a=!0,e={}){const c=g(i),r=g(n),d=await this.getShipId(t),l=await this.getShipInfo(d),p=[];for(;r.diff(c,"day",!0)>30;)await this.trajectoryIn30Day(d,c.unix(),c.add(30,"day").unix(),l,t,o,p);return await this.trajectoryIn30Day(d,c.unix(),r.unix(),l,t,o,p),p}async trajectoryIn30Day(t,i,n,o,a,e,c,r={}){var j;const d={headers:{appKey:this.token},json:{shipId:t,startTime:i,endTime:n}},l="https://api3.myships.com/sp/ships/position/history",p=await D.post(l,d).json();if(u==null||u.info("[%s] fetch trajectory from: %s - %j",r.requestId,l,d),p.code!=="0")return u==null||u.warn("[%s] invoke myship trajectory failed: %j",r.requestId,p),p;const f=p.data;for(const v in f)!isNaN(f[v])&&Number(f[v])!==1/0&&(f[v]=Number(f[v]));const m=g.unix((j=f[0])==null?void 0:j.posTime);let Y=-1;for(const v of f){const M=g.unix(v.posTime),h={imo:o==null?void 0:o.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:M.unix(),utc:M.utc().format(),method:"trajectory",vendor:"myship"},I=Math.floor(M.diff(m,"minute",!0)/(e||1));I!==Y&&(Y=I,c.push(h))}return c}}let R;try{R=Z.getLogger("vessel")}catch{}finally{}var G=(k=>(k.NOTICE="NOTICE",k.WARN="WARN",k.HEAVY="HEAVY",k.SEVERE="SEVERE",k.ERROR="ERROR",k.FATAL="FATAL",k))(G||{});class U{parsePrinciple(s,t={}){var e,c,r;R==null||R.info("[%s] parse rule: %s",t.requestId,s);const i=new RegExp("(?<=\\[)(.+)(?=])","g"),n=s.match(i)?(e=s.match(i))==null?void 0:e[0]:void 0,o=n==null?void 0:n.split(";");if(!o)return;const a={};for(let d=0;d<(o==null?void 0:o.length);d++){const l=(r=(c=o[d].match(i))==null?void 0:c[0])==null?void 0:r.split("],");if(d===0&&!l)a.scope=o[0];else if(l)for(let p=0,f=l.length;p<f;p++){const m=this.parseRule(l[p]);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(s,t={}){var a;R==null||R.info("[%s] parse rule: %s",t.requestId,s),s=s.startsWith("[")?s:`[${s}`,s=s.endsWith("]")?s:`${s}]`;const i=new RegExp("(?<=\\[)(.+?)(?=])","g"),n=(a=s==null?void 0:s.match(i))==null?void 0:a[0],o=n==null?void 0:n.split(",");if(o)return{operator:o[0],number:Number.isNaN(Number(o[1]))?o[1]:Number(o[1]),level:o[2],time:Number(o[3]),key:o[4]}}checkWeather(s,t,i={}){var m,Y,j,v,M,h,I,w,y,b,x,E,V,S,_;let n=0,o=0,a=0,e=0;const c=Math.round(((Y=(m=t==null?void 0:t.SEVERE)==null?void 0:m.sigWave)==null?void 0:Y.number)*1.6*100)/100,r=(v=(j=t==null?void 0:t.SEVERE)==null?void 0:j.sigWave)==null?void 0:v.number,d=(h=(M=t==null?void 0:t.HEAVY)==null?void 0:M.sigWave)==null?void 0:h.number,l=Math.round((((w=(I=t==null?void 0:t.SEVERE)==null?void 0:I.wind)==null?void 0:w.number)+2)*100)/100,p=(b=(y=t==null?void 0:t.SEVERE)==null?void 0:y.wind)==null?void 0:b.number,f=(E=(x=t==null?void 0:t.HEAVY)==null?void 0:x.wind)==null?void 0:E.number;for(let W=0;W<(s==null?void 0:s.length);W++){const T=s[W],C=(S=(V=T==null?void 0:T.meteo)==null?void 0:V.wave)==null?void 0:S.sig,F=(_=T==null?void 0:T.meteo)==null?void 0:_.wind,P=W?g(T.eta).diff(g(s[W-1].eta),"hour",!0):0;e=P>e?P:e,R==null||R.info("[%s] check sig.wave: %j",i.requestId,{...C,dgThd4Wv:c,svThd4Wv:r,hvThd4Wv:d}),(C==null?void 0:C.height)>=c?T.isDangerous=!0:(C==null?void 0:C.height)>=r?T.isSevere=!0:(C==null?void 0:C.height)>=d&&(T.isHeavy=!0),R==null||R.info("[%s] check wind: %j",i.requestId,{...F,dgThd4Wd:l,svThd4Wd:p,hvThd4Wd:f}),(F==null?void 0:F.scale)>=l?(T.isDangerous=!0,delete T.isSevere,delete T.isHeavy):(F==null?void 0:F.scale)>p?(T.isDangerous||(T.isSevere=!0),delete T.isHeavy):(F==null?void 0:F.scale)===f&&!T.isDangerous&&!T.isSevere&&(T.isHeavy=!0),n+=T.isDangerous?P:0,o+=T.isSevere?P:0,a+=T.isHeavy?P:0}return n=Math.round(n*100)/100,o=Math.round(o*100)/100,a=Math.round(a*100)/100,e=Math.round(e),{sample:s,dangerous:n,severe:o,heavy:a,step:e<3?3:e,wind:{dgThd4Wd:l,svThd4Wd:p,hvThd4Wd:f},sig:{dgThd4Wv:c,svThd4Wv:r,hvThd4Wv:d}}}}const ut=new U;let N;try{N=Z.getLogger("vessel")}catch{}finally{}var J=(k=>(k.common="common",k.container="container",k.tugs="tugs",k))(J||{}),Q=(k=>(k.Ballast="Ballast",k.Laden="Laden",k))(Q||{}),X=(k=>(k.Cp="CP",k.Perf="Basis",k.Instruct="Other",k))(X||{});class A{static blockCoefficient(s,t,i,n){let o=Math.round(s/(t*i*n)*100)/100;o=o<.55?.55:o>.85?.85:o;const a=[.55,.6,.65,.7,.75,.8,.85],e=a.map(c=>Math.abs(c-o));return a[e.indexOf(Math.min(...e))]}static froudeNumber(s,t,i=9.8){let n=Math.round(Math.sqrt(s*s/(i*t))*100)/100;return n=n<.05?.05:n>.3?.3:n,n}static amendFactor(s,t,i){const n={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.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]}[s];return i==="Laden"&&(a=n[s]),a[0]+a[1]*t+a[2]*Math.pow(t,2)}static directionFactor(s,t=0){let i;return s>30&&s<=60?i=(1.7-.03*Math.pow(t-4,2))/2:s>60&&s<=150?i=(.9-.06*Math.pow(t-6,2))/2:s>150&&s<=180?i=(.4-.03*Math.pow(t-8,2))/2:i=1,Math.round(i*1e5)/1e5}static vesselTagFactor(s,t,i,n=0){n=n>6?n-.9*(n-6):n;let o;return i==="container"?o=.7*n+Math.pow(n,6.5)/(22*Math.pow(s,2/3)):t==="Ballast"?o=.7*n+Math.pow(n,6.5)/(2.7*Math.pow(s,2/3)):o=.5*n+Math.pow(n,6.5)/(2.7*Math.pow(s,2/3)),o}static waveHeightFactor(s,t){s=s<0?.2:s,s=s>6?s-.9*(s-6):s,s=s>9?9:s;let i;return t>30&&t<=60?i=-.6:t>60&&t<=90?i=-.4:t>90&&t<=120?i=s<3?.4:-.3:t>120&&t<=150?i=s<3?.6:-.5:t>150&&t<=180?i=s<3?.7:-.6:i=-.7,Math.round(i*(.144*Math.pow(s,2)+.178*s)*1e4)/1e4}static assembleProperties(s,t,i,n){var p;const o=s.lbp??s.length??s.lengthOverall??198.9642,a=s.draught??8,e=s.breadthMoulded??s.breadth??s.breadthExtreme??32.4572,c=s.deadweight??67035.7773,r=((p=s==null?void 0:s.type)==null?void 0:p.toLowerCase())||"common";return{tag:r.indexOf("container")>-1?"container":r.indexOf("tugs")>-1?"tugs":"common",lbp:o,loadCondition:t,draught:a,breadthMoulded:e,displacement:Math.round((c/1.025+a*e*o*.7)*1e4)/1e4,speed:Math.round((i??14.1382)*1852/3600*1e4)/1e4,bearing:n||90}}static async speedLoseAt(s,t,i,n="",o=2,a=!0,e=!1,c={}){let r;if(t.velocity&&e&&(s.speed=O.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),a){const d=await ot.MeteoHelper.queryPointFactor(t.lng,t.lat,i.valueOf(),"wind,wave,current,watertemp",n,c),l=A.weatherFactor(s,d),p=A.currentFactor(s.bearing,d==null?void 0:d.current,o),f=Math.round((s.speed*1.943844+l+p)*100)/100;r={meteo:{...d},wxFactor:l,cFactor:p,speed:t.velocity&&e?t.velocity:f<0?1:f,eta:i.utc().format("YYYY-MM-DDTHH:mm[Z]"),etd:i.utc().format("YYYY-MM-DDTHH:mm[Z]")}}else r={wxFactor:0,cFactor:0,speed:t.velocity&&e?t.velocity:Math.round((s.speed*1.943844+0+0)*100)/100,eta:i.utc().format("YYYY-MM-DDTHH:mm[Z]"),etd:i.utc().format("YYYY-MM-DDTHH:mm[Z]")};return delete t.meteo,delete t.wxFactor,delete t.cFactor,delete t.speed,delete t.etd,{...r,...t}}static async speedLoseInHoursStep(s,t,i,n,o,a,e="",c=!0,r=!1,d={}){t.utc();const l=[],p=[];let f=0,m=0,Y,j;for(let v=0;v<a.length-1;v++){let M=a[v];M.distanceFromStart=o+m;const h=a[v+1];if(s.bearing=O.LaneHelper.calculateBearing(M,h,!h.gcToPrevious),M.bearing=s.bearing,M.suspend&&r){M.eta=M.eta||t.format("YYYY-MM-DDTHH:mm[Z]"),M.elapsed=M.elapsed??0;const y=M.suspend-M.elapsed;if(n-f>y)n=n-f-y,t.add(y,"hour"),M.elapsed=M.suspend;else{const b=n-f;M.elapsed+=b,t.add(b,"hour"),n=0}if(N==null||N.info(`[%s] suspend ${M.elapsed} hours at %j, and remain ${n} hours need to go...`,d.requestId,M),n===0)return M.distanceFromPrevious=m,{etd:t,from:j||M,to:M,next:a.filter(b=>b),wps:l,days:p}}M=await A.speedLoseAt(s,M,t,e,0,c,r,d),j=j||M,M.important&&l.push(M),t.isSameOrAfter(i)&&(p.push(M),i.add(24,"hour"));const I=O.LaneHelper.calculateDistance(M,h,!h.gcToPrevious);let w=Math.ceil(I/j.speed*1e4)/1e4;if(f+w<n){if(f+=w,t.add(w,"hour"),delete a[v],N==null||N.info(`[%s] go to %j from %j with ${I}nm, and cost ${w} hours`,d.requestId,{lat:h.lat,lng:h.lng},{lat:j.lat,lng:j.lng,etd:j.etd}),m+=I,a.filter(y=>y).length<=1){Y=h,Y.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),Y.distanceFromPrevious=I,Y.distanceFromStart=o+m,l.push(Y),delete a[v+1];break}}else{w=n-f,t.add(w,"hour");const y=O.LngLatHelper.roundPrecision(j.speed*w,4);Y=O.LaneHelper.calculateCoordinate(M,s.bearing,y,"nauticalmiles",!h.gcToPrevious),Y.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),a[v]=Y,N==null||N.info(`[%s] go to %j from %j with ${y}nm, and cost ${w} hours`,d.requestId,{lat:Y.lat,lng:Y.lng},{lat:M.lat,lng:M.lng,etd:M.etd}),m+=y,Y.distanceFromPrevious=m,Y.distanceFromStart=o+m;break}}return{etd:t,from:j,to:Y,next:a.filter(v=>v),wps:l,days:p}}static currentFactor(s,t,i=0){const n=(s-(t==null?void 0:t.degree)||0)/180*Math.PI;if(Math.abs(n)===Math.PI/2)return 0;let o=((t==null?void 0:t.kts)||0)*Math.cos(n);return i&2?o=Math.ceil(o*100)/100:i&1?o=Math.floor(o*100)/100:o=Math.round(o*100)/100,Math.abs(o)>5?0:o}static weatherFactor(s,t){var l,p,f,m,Y,j,v;N==null||N.debug("calculate weather factor via: %j",{...s,...t});const i=A.blockCoefficient(s.displacement,s.lbp,s.breadthMoulded,s.draught),n=A.froudeNumber(s.speed,s.lbp),o=A.amendFactor(i,n,s.loadCondition);let a=Math.abs(s.bearing%360-(((l=t==null?void 0:t.wind)==null?void 0:l.degree)%360||0));a=a>180?360-a:a;const e=A.directionFactor(a,(p=t==null?void 0:t.wind)==null?void 0:p.scale),c=A.vesselTagFactor(s.displacement,s.loadCondition,s.tag,(f=t==null?void 0:t.wind)==null?void 0:f.scale);let r=e*o*c/100*s.speed;r=Math.round(r*1.943844*1e4)/1e4*-1,s.tag==="tugs"&&Math.abs(r)>1&&(r=r/(Math.abs(Math.round(r))+1)),N==null||N.debug("wind wx factor = %d",r),a=Math.abs(s.bearing%360-(((Y=(m=t==null?void 0:t.wave)==null?void 0:m.sig)==null?void 0:Y.degree)%360||0));const d=A.waveHeightFactor(((v=(j=t==null?void 0:t.wave)==null?void 0:j.sig)==null?void 0:v.height)??1,a);return N==null||N.debug("wave wx factor = %d",d),r=r*.6+d,N==null||N.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*100)/100}static async analyseInstant(s,t,i,n,o,a="",e=0,c=!0,r=!1,d={}){var P,$,tt,et,st;const l=g().valueOf();s.lng=O.LngLatHelper.convertToStdLng(s.lng);const{route:p,waypoints:f}=o.points,m=O.LaneHelper.calculateSubRoute(s,p);if(((P=m[0])==null?void 0:P.length)<=1)return;const{v0:Y,label:j}=s.sog?{v0:s.sog,label:"Other"}:{v0:n.speed,label:"CP"},v=A.assembleProperties(i,n.loadCondition,Y,0),M=f.length?O.LaneHelper.calculateSubWaypoints(s,f):[];M.forEach(q=>q.important=!0);const h={from:{...s},route:m,waypoints:M,v0:Y,label:j},I={hours:[],days:[],wps:[]};e||(O.LaneHelper.calculateRouteDistance(m)/n.speed<=72?e=3:e=6);let w=O.LaneHelper.simplifyRouteToCoordinates(m,M,0),y=0,b=0,x=0,E=0;t=g(t).utc();const V=t.clone();for(;w.length>0;){const q=e-t.hour()%e,B=Math.ceil(t.clone().add(q,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,L=await A.speedLoseInHoursStep(v,t,V,B,y,w,a,c,r,d);($=L.from)!=null&&$.speed&&(I.hours.push(L.from),I.wps.push(...L.wps),I.days.push(...L.days)),w=L==null?void 0:L.next,w.length||I.hours.push(L==null?void 0:L.to),y+=((tt=L==null?void 0:L.to)==null?void 0:tt.distanceFromPrevious)??0}const S=I.hours;for(let q=0;q<S.length-1;q++){const B=g(S[q+1].eta).diff(S[q].etd,"hour",!0)||1;b+=(S[q].wxFactor||0)*B,x+=(S[q].cFactor||0)*B,E+=B}(et=I.wps)==null||et.forEach((q,B)=>{if(B){const L=I.wps[B-1],ht=q.distanceFromStart-L.distanceFromStart,at=g(q.eta).diff(g(L.etd),"h",!0);if(at<1)q.avgSpd=L.speed;else{q.avgSpd=Math.round(ht/at*100)/100;const nt=Math.round((L.speed+q.speed)/2*100)/100;q.avgSpd=q.avgSpd>nt?nt:q.avgSpd}}}),h.sample=I;const _=I.hours.at(0),W=I.hours.at(-1);h.distance=Math.round(W.distanceFromStart*1e4)/1e4,h.etd=g(_.eta).utc().format(),h.eta=g(W.eta).utc().format(),h.wxFactor=Math.round(b/E*1e4)/1e4,h.cFactor=Math.round(x/E*1e4)/1e4,h.avgSpeed=Math.round(W.distanceFromStart/E*1e4)/1e4,h.totalHrs=Math.round(E*1e4)/1e4,h.totalFoCons=Math.round((n==null?void 0:n.fo)/24*h.totalHrs*1e3)/1e3,h.totalDgoCons=Math.round((n==null?void 0:n.dgo)/24*h.totalHrs*1e3)/1e3;const C=g().valueOf()-l,F=((st=I==null?void 0:I.hours)==null?void 0:st.length)||1;return N==null||N.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",d==null?void 0:d.requestId,C,F,Math.round(C/F*1e3)/1e3),h}static async analyseInstantWithThreshed(s,t,i,n,o,a,e,c="",r=3,d=!0,l=!1,p={}){var W,T,C;s.lng=O.LngLatHelper.convertToStdLng(s.lng);const{v0:f,label:m}=s.sog?{v0:s.sog,label:"Other"}:{v0:o.speed,label:"CP"},Y=A.assembleProperties(n,o.loadCondition,f,0),j=O.LaneHelper.calculateSubRoute(s,a);if(((W=j[0])==null?void 0:W.length)<=1)return;const v=e.length?O.LaneHelper.calculateSubWaypoints(s,e):[];v.forEach(F=>F.important=!0);let M=O.LaneHelper.simplifyRouteToCoordinates(j,v,0),h=0,I=0,w=0,y=0,b;const x={hours:[],wps:[],days:[]};for(t=g(t).utc();M.length>0;){const F=r-t.hour()%r;let P=Math.ceil(t.clone().add(F,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;if(P=t.clone().add(P,"h").isAfter(i)?i.diff(t,"h",!0)*1e4/1e4:P,P)b=await A.speedLoseInHoursStep(Y,t,i.clone(),P,h,M,c,d,l,p),(T=b.from)!=null&&T.speed&&(x.hours.push(b.from),b!=null&&b.wps&&x.wps.push(...b.wps),x.days.push(...b.days)),M=b==null?void 0:b.next,M.length||(x.hours.push(b==null?void 0:b.to),b!=null&&b.wps&&x.wps.push(...b.wps),x.days.push(b==null?void 0:b.to)),h+=((C=b==null?void 0:b.to)==null?void 0:C.distanceFromPrevious)??0;else{b&&(x.hours.push(b.to),b!=null&&b.wps&&x.wps.push(...b.wps),x.days.push(b.to));break}}const E=x.hours;for(let F=0;F<E.length-1;F++){const P=g(E[F+1].eta).diff(E[F].etd,"hour",!0);I+=E[F].wxFactor*P,w+=E[F].cFactor*P,y+=P}const V=x.hours.at(0),S=x.hours.at(-1);return{sample:x,distance:Math.round(((S==null?void 0:S.distanceFromStart)||0)*1e4)/1e4,etd:g(V.eta).utc().format(),eta:g(S==null?void 0:S.eta).utc().format(),wxFactor:Math.round(I/y*1e4)/1e4,cFactor:Math.round(w/y*1e4)/1e4,avgSpeed:Math.round(((S==null?void 0:S.distanceFromStart)||0)/y*1e4)/1e4,totalHrs:Math.round(y*1e4)/1e4,from:s,to:S,route:j,waypoints:v,v0:f,label:m}}}H.AISImpl=z,H.AlertHelper=U,H.AlertLevel=G,H.HifleetImpl=rt,H.LoadCondition=Q,H.MyShipImpl=dt,H.MyVesselImpl=it,H.ShipxyImpl=ct,H.SpeedHelper=A,H.SpeedLabel=X,H.VesselTag=J,H.alertHelper=ut,Object.defineProperty(H,Symbol.toStringTag,{value:"Module"})});
1
+ (function(H,D){typeof exports=="object"&&typeof module<"u"?D(exports,require("got"),require("@log4js-node/log4js-api"),require("moment"),require("@idm-plugin/geo"),require("@idm-plugin/meteo")):typeof define=="function"&&define.amd?define(["exports","got","@log4js-node/log4js-api","moment","@idm-plugin/geo","@idm-plugin/meteo"],D):(H=typeof globalThis<"u"?globalThis:H||self,D(H["idm-plugin-rabbitmq"]={},H.got,H["@log4js-node/log4js-api"],H.moment,H["@idm-plugin/geo"],H["@idm-plugin/meteo"]))})(this,function(H,D,Z,g,O,ot){"use strict";var lt=Object.defineProperty;var ft=(H,D,Z)=>D in H?lt(H,D,{enumerable:!0,configurable:!0,writable:!0,value:Z}):H[D]=Z;var K=(H,D,Z)=>(ft(H,typeof D!="symbol"?D+"":D,Z),Z);let u;try{u=Z.getLogger("vessel")}catch{}finally{}class z{parseStatus(s){let t,i;switch(s){case 0:t="在航(主机推动)",i="The engine is in use";break;case 1:t="锚泊",i="Anchored";break;case 2:t="失控",i="Not operated";break;case 3:t="操纵受限",i="Limited airworthiness";break;case 4:t="吃水受限",i="Limited by ship's draft";break;case 5:t="靠泊",i="Mooring";break;case 6:t="搁浅",i="Stranded";break;case 7:t="捕捞作业",i="Engaged in fishing";break;case 8:t="靠帆船提供动力",i="Sailing";break;default:t="未定义",i="Undefined"}return{labelCn:t,labelEn:i}}}class it extends z{constructor(t,i){super();K(this,"clientId");K(this,"clientSecret");K(this,"token");this.clientId=t,this.clientSecret=i}async authToken(t={}){const i="https://svc.data.myvessel.cn/ada/oauth/token",n={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},o=await D.post(i,n).json();u==null||u.info("[%s] fetch access token from: %s - %j",t.requestId,i,o),o.error||(this.token={accessToken:o.access_token,tokenType:o.token_type,expiresIn:o.expires_in,scope:o.scope,jti:o.jti,issuedAt:g().utc().format()})}async realTimePosition(t,i={}){var d,l,p;(!this.token||g().diff(g(this.token.issuedAt),"seconds")>((d=this.token)==null?void 0:d.expiresIn)-300)&&await this.authToken(i);const n="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",o={headers:{Authorization:`${(l=this.token)==null?void 0:l.tokenType} ${(p=this.token)==null?void 0:p.accessToken}`},searchParams:{mmsi:t}};u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,n,o);const a=await D.get(n,o).json();if(a.code)return u==null||u.warn("[%s] fetch realtime position failed: %j",i.requestId,n,{message:a.message,status:a.status,code:a.code}),a;const e=a.data;for(const f in e)!isNaN(e[f])&&Number(e[f])!==1/0&&(e[f]=Number(e[f]));const c=g(`${e.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:e.mmsi,name:e.vesselName,imo:e.imo,callSign:e.callsign,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:e.eta,destination:e.dest,positionTime:c.unix(),status:e.status,labelCn:e.statusNameCn,labelEn:e.statusNameEn,method:"position",vendor:"myVessel",utc:c.utc().format()}}async trajectory(t,i,n,o,a=!0,e={}){(!this.token||g().diff(g(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(e);const c=await this.realTimePosition(t,e),r=g(i),d=g(n),l=[];for(;d.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(t,r,r.clone().add(30,"day"),c,o,l,e),r.add(30,"day");return await this.trajectoryIn30Day(t,r,d,c,o,l,e),l}async trajectoryIn30Day(t,i,n,o,a,e,c={}){var m,Y,j,v,M;const r="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",d={headers:{Authorization:`${(m=this.token)==null?void 0:m.tokenType} ${(Y=this.token)==null?void 0:Y.accessToken}`},json:{mmsi:t,startTime:i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};u==null||u.info("[%s] fetch trajectory from: %s - %j",c.requestId,r,d);const l=await D.post(r,d).json();if(l.code)return u==null||u.warn("[%s] fetch trajectory failed: %j",c.requestId,r,{message:l.message,status:l.status,code:l.code}),l;let p=-1;const f=g(`${(v=(j=l.data)==null?void 0:j[0])==null?void 0:v.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(M=l.data)==null||M.forEach(h=>{for(const S in h)!isNaN(h[S])&&Number(h[S])!==1/0&&(h[S]=Number(h[S]));const I=g(`${h.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),w=h.eta?g(`${h.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,y=h.status,{labelCn:b,labelEn:x}=this.parseStatus(y),E={mmsi:h.mmsi,imo:o==null?void 0:o.imo,lat:h.lat,lng:h.lon,sog:h.sog,cog:h.cog,hdg:h.hdg,draught:h.draught,status:y,eta:w==null?void 0:w.unix(),destination:h.dest,positionTime:I.unix(),labelCn:b,labelEn:x,method:"trajectory",vendor:"myVessel",utc:I.utc().format()},V=Math.floor(I.diff(f,"minute",!0)/(a||1));V!==p&&(p=V,e.push(E))}),e}}class rt extends z{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,i={}){const n="https://api.hifleet.com/position/position/get/token",o={searchParams:{mmsi:t,usertoken:this.token}},a=await D.post(n,o).json();u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,n,o);const e=a==null?void 0:a.list;if(!e)return u==null||u.warn("[%s] fetch realtime position failed: %j",i.requestId,n,a),a;for(const f in e)!isNaN(e[f])&&Number(e[f])!==1/0&&(e[f]=Number(e[f]));e.status=e.sp>3?0:1;const c=e.status,{labelCn:r,labelEn:d}=this.parseStatus(c),l=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(`${e.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").unix():void 0,destination:e.destination,positionTime:l.unix(),utc:l.utc().format(),status:c,labelCn:r,labelEn:d,method:"position",vendor:"hifleet"}}async search(t,i={}){let n="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const o={searchParams:{keyword:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let a=await D.post(n,o).json();u==null||u.info("[%s] fetch vessel props from: %s - %j",i.requestId,n,o),a instanceof Array&&(a=a[0]);for(const c in a)!isNaN(a[c])&&Number(a[c])!==1/0&&(a[c]=Number(a[c]));const e={mmsi:a.m,name:a.n,imo:a.i,callSign:a.c,length:a.l,breadth:a.b,draught:a.dr};return n="https://www.hifleet.com/hifleetapi/sameShipSearch.do",a=await D.post(n,o).json(),u==null||u.info("[%s] fetch vessel dead weight from: %s - %j",i.requestId,n,o),a instanceof Array&&(a=a[0]),a&&(e.deadweight=Number(a.dwt)),e}async trajectory(t,i,n,o,a=!0,e={}){var h,I,w;const c=await this.realTimePosition(t,e);let r=g(i);const d=g(n),l=g();if(a){let y=d.diff(r,"d",!0);y<0?r=d.clone().subtract(40,"d"):y<30?r.subtract(10,"d"):y<60?r.subtract(5,"d"):r=d.clone().subtract(80,"d"),y=l.diff(d,"d",!0),d.add(y>10?240:y*24,"h")}const p={searchParams:{endtime:d.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}},f="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",m=await D.get(f,p).json();u==null||u.info("[%s] fetch trajectory from: %s - %j",e.requestId,f,p);let Y;m&&(Y=((I=(h=m.ships)==null?void 0:h.offors)==null?void 0:I.ship)||[],Y.length||u==null||u.warn("[%s] fetch trajectory failed: %j",e.requestId,m));const j=[];let v=-1;const M=g(`${(w=Y==null?void 0:Y[0])==null?void 0:w.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const y of Y){for(const _ in y)!isNaN(y[_])&&Number(y[_])!==1/0&&(y[_]=Number(y[_]));const b=g(`${y.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");y.status=y.sp>4?0:1;const{labelEn:x,labelCn:E}=this.parseStatus(y.status),V={mmsi:y.m,name:y.n,imo:c==null?void 0:c.imo,lat:y.la,lng:y.lo,draught:y.draught,sog:y.sp,cog:y.co,hdg:y.hdg,positionTime:b.unix(),utc:b.utc().format(),status:y.status,labelCn:E,labelEn:x,method:"trajectory",vendor:"hifleet"},S=Math.floor(b.diff(M,"minute",!0)/(o||1));S!==v&&(v=S,j.push(V))}return j}}class ct extends z{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,i={}){const n={searchParams:{id:t,k:this.token,enc:1}},o="https://api.shipxy.com/apicall/GetSingleShip",a=await D.get(o,n).json();if(u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,o,n),(a==null?void 0:a.status)!==0)return a;const e=a.data[0];for(const p in e)!isNaN(e[p])&&Number(e[p])!==1/0&&(e[p]=Number(e[p]));const{labelCn:c,labelEn:r}=await this.parseStatus(e.navistat),d=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:d.utc().format(),status:e.navistat,labelEn:r,labelCn:c,method:"position",vendor:"shipxy"}}async trajectory(t,i,n,o,a=!0,e={}){var M;const c=await this.realTimePosition(t,e),r=g(i),d=g(n),l="https://api.shipxy.com/apicall/GetShipTrack",p={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:r.unix(),etm:d.unix()}},f=await D.get(l,p).json();if(u==null||u.info("[%s] fetch trajectory from: %s - %j",e.requestId,l,p),(f==null?void 0:f.status)!==0)return f;const m=f==null?void 0:f.points,Y=[],j=g.unix((M=m[0])==null?void 0:M.utc);let v=-1;for(const h of m){const I=g.unix(h.utc),w={imo:c==null?void 0:c.imo,mmsi:t,sog:Math.round(h.sog*3600/1e3/1852*100)/100,cog:Math.round(h.cog/100*100)/100,lat:Math.round(h.lat/1e6*1e5)/1e5,lng:Math.round(h.lon/1e6*1e5)/1e5,positionTime:I.unix(),utc:I.utc().format(),method:"trajectory",vendor:"shipxy"},y=Math.floor(I.diff(j,"minute",!0)/(o||1));y!==v&&(v=y,Y.push(w))}return Y}}class dt extends z{constructor(t){super();K(this,"token");this.token=t}async getShipId(t,i={}){const n={headers:{appKey:this.token},json:{mmsiList:t}},o="https://api3.myships.com/sp/ships/getShipIdByMMSI",a=await D.post(o,n).json();return u==null||u.info("[%s] fetch ship id from: %s - %j",i.requestId,o,n),a.code!=="0"?a:a.data[0].shipId}async getShipInfo(t,i={}){const n={headers:{appKey:this.token},json:{shipId:t}},o="https://api3.myships.com/sp/ships/aissta",a=await D.post(o,n).json();if(u==null||u.info("[%s] fetch ship info from: %s - %j",i.requestId,o,n),a.code!=="0")return a;const e=a.data;let c=e.imo;return t==="407170"&&(c="9198379",u==null||u.warn("[%s] ship(%s) imo error: %s, should be %s",i.requestId,t,e.imo,c)),{mmsi:e.mmsi,name:e.shipnameEn,imo:c,callSign:e.callSign,length:e.length,width:e.breadth,draught:(e.draught||100)/10}}async realTimePosition(t,i={}){const n=await this.getShipId(t,i),o=await this.getShipInfo(n,i),a={headers:{appKey:this.token},json:{shipId:n}},e="https://api3.myships.com/sp/ships/position/latest",c=await D.post(e,a).json();u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,e,a);const r=c.data[0];for(const m in r)!isNaN(r[m])&&Number(r[m])!==1/0&&(r[m]=Number(r[m]));const{labelCn:d,labelEn:l}=await this.parseStatus(r.aisNavStatus),p=g.unix(r.posTime);return{...o,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:p.utc().format(),status:r.aisNavStatus,labelEn:l,labelCn:d,method:"position",vendor:"myship"}}async trajectory(t,i,n,o,a=!0,e={}){const c=g(i),r=g(n),d=await this.getShipId(t),l=await this.getShipInfo(d),p=[];for(;r.diff(c,"day",!0)>30;)await this.trajectoryIn30Day(d,c.unix(),c.add(30,"day").unix(),l,t,o,p);return await this.trajectoryIn30Day(d,c.unix(),r.unix(),l,t,o,p),p}async trajectoryIn30Day(t,i,n,o,a,e,c,r={}){var j;const d={headers:{appKey:this.token},json:{shipId:t,startTime:i,endTime:n}},l="https://api3.myships.com/sp/ships/position/history",p=await D.post(l,d).json();if(u==null||u.info("[%s] fetch trajectory from: %s - %j",r.requestId,l,d),p.code!=="0")return u==null||u.warn("[%s] invoke myship trajectory failed: %j",r.requestId,p),p;const f=p.data;for(const v in f)!isNaN(f[v])&&Number(f[v])!==1/0&&(f[v]=Number(f[v]));const m=g.unix((j=f[0])==null?void 0:j.posTime);let Y=-1;for(const v of f){const M=g.unix(v.posTime),h={imo:o==null?void 0:o.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:M.unix(),utc:M.utc().format(),method:"trajectory",vendor:"myship"},I=Math.floor(M.diff(m,"minute",!0)/(e||1));I!==Y&&(Y=I,c.push(h))}return c}}let R;try{R=Z.getLogger("vessel")}catch{}finally{}var G=(k=>(k.NOTICE="NOTICE",k.WARN="WARN",k.HEAVY="HEAVY",k.SEVERE="SEVERE",k.ERROR="ERROR",k.FATAL="FATAL",k))(G||{});class U{parsePrinciple(s,t={}){var e,c,r;R==null||R.info("[%s] parse rule: %s",t.requestId,s);const i=new RegExp("(?<=\\[)(.+)(?=])","g"),n=s.match(i)?(e=s.match(i))==null?void 0:e[0]:void 0,o=n==null?void 0:n.split(";");if(!o)return;const a={};for(let d=0;d<(o==null?void 0:o.length);d++){const l=(r=(c=o[d].match(i))==null?void 0:c[0])==null?void 0:r.split("],");if(d===0&&!l)a.scope=o[0];else if(l)for(let p=0,f=l.length;p<f;p++){const m=this.parseRule(l[p]);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(s,t={}){var a;R==null||R.info("[%s] parse rule: %s",t.requestId,s),s=s.startsWith("[")?s:`[${s}`,s=s.endsWith("]")?s:`${s}]`;const i=new RegExp("(?<=\\[)(.+?)(?=])","g"),n=(a=s==null?void 0:s.match(i))==null?void 0:a[0],o=n==null?void 0:n.split(",");if(o)return{operator:o[0],number:Number.isNaN(Number(o[1]))?o[1]:Number(o[1]),level:o[2],time:Number(o[3]),key:o[4]}}checkWeather(s,t,i={}){var m,Y,j,v,M,h,I,w,y,b,x,E,V,S,_;let n=0,o=0,a=0,e=0;const c=Math.round(((Y=(m=t==null?void 0:t.SEVERE)==null?void 0:m.sigWave)==null?void 0:Y.number)*1.6*100)/100,r=(v=(j=t==null?void 0:t.SEVERE)==null?void 0:j.sigWave)==null?void 0:v.number,d=(h=(M=t==null?void 0:t.HEAVY)==null?void 0:M.sigWave)==null?void 0:h.number,l=Math.round((((w=(I=t==null?void 0:t.SEVERE)==null?void 0:I.wind)==null?void 0:w.number)+2)*100)/100,p=(b=(y=t==null?void 0:t.SEVERE)==null?void 0:y.wind)==null?void 0:b.number,f=(E=(x=t==null?void 0:t.HEAVY)==null?void 0:x.wind)==null?void 0:E.number;for(let W=0;W<(s==null?void 0:s.length);W++){const T=s[W],C=(S=(V=T==null?void 0:T.meteo)==null?void 0:V.wave)==null?void 0:S.sig,F=(_=T==null?void 0:T.meteo)==null?void 0:_.wind,P=W?g(T.eta).diff(g(s[W-1].eta),"hour",!0):0;e=P>e?P:e,R==null||R.info("[%s] check sig.wave: %j",i.requestId,{...C,dgThd4Wv:c,svThd4Wv:r,hvThd4Wv:d}),(C==null?void 0:C.height)>=c?T.isDangerous=!0:(C==null?void 0:C.height)>=r?T.isSevere=!0:(C==null?void 0:C.height)>=d&&(T.isHeavy=!0),R==null||R.info("[%s] check wind: %j",i.requestId,{...F,dgThd4Wd:l,svThd4Wd:p,hvThd4Wd:f}),(F==null?void 0:F.scale)>=l?(T.isDangerous=!0,delete T.isSevere,delete T.isHeavy):(F==null?void 0:F.scale)>p?(T.isDangerous||(T.isSevere=!0),delete T.isHeavy):(F==null?void 0:F.scale)===f&&!T.isDangerous&&!T.isSevere&&(T.isHeavy=!0),n+=T.isDangerous?P:0,o+=T.isSevere?P:0,a+=T.isHeavy?P:0}return n=Math.round(n*100)/100,o=Math.round(o*100)/100,a=Math.round(a*100)/100,e=Math.round(e),{sample:s,dangerous:n,severe:o,heavy:a,step:e<3?3:e,wind:{dgThd4Wd:l,svThd4Wd:p,hvThd4Wd:f},sig:{dgThd4Wv:c,svThd4Wv:r,hvThd4Wv:d}}}}const ut=new U;let N;try{N=Z.getLogger("vessel")}catch{}finally{}var J=(k=>(k.common="common",k.container="container",k.tugs="tugs",k))(J||{}),Q=(k=>(k.Ballast="Ballast",k.Laden="Laden",k))(Q||{}),X=(k=>(k.Cp="CP",k.Perf="Basis",k.Instruct="Other",k))(X||{});class A{static blockCoefficient(s,t,i,n){let o=Math.round(s/(t*i*n)*100)/100;o=o<.55?.55:o>.85?.85:o;const a=[.55,.6,.65,.7,.75,.8,.85],e=a.map(c=>Math.abs(c-o));return a[e.indexOf(Math.min(...e))]}static froudeNumber(s,t,i=9.8){let n=Math.round(Math.sqrt(s*s/(i*t))*100)/100;return n=n<.05?.05:n>.3?.3:n,n}static amendFactor(s,t,i){const n={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.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]}[s];return i==="Laden"&&(a=n[s]),a[0]+a[1]*t+a[2]*Math.pow(t,2)}static directionFactor(s,t=0){let i;return s>30&&s<=60?i=(1.7-.03*Math.pow(t-4,2))/2:s>60&&s<=150?i=(.9-.06*Math.pow(t-6,2))/2:s>150&&s<=180?i=(.4-.03*Math.pow(t-8,2))/2:i=1,Math.round(i*1e5)/1e5}static vesselTagFactor(s,t,i,n=0){n=n>6?n-.9*(n-6):n;let o;return i==="container"?o=.7*n+Math.pow(n,6.5)/(22*Math.pow(s,2/3)):t==="Ballast"?o=.7*n+Math.pow(n,6.5)/(2.7*Math.pow(s,2/3)):o=.5*n+Math.pow(n,6.5)/(2.7*Math.pow(s,2/3)),o}static waveHeightFactor(s,t){s=s<0?.2:s,s=s>6?s-.9*(s-6):s,s=s>9?9:s;let i;return t>30&&t<=60?i=-.6:t>60&&t<=90?i=-.4:t>90&&t<=120?i=s<3?.4:-.3:t>120&&t<=150?i=s<3?.6:-.5:t>150&&t<=180?i=s<3?.7:-.6:i=-.7,Math.round(i*(.144*Math.pow(s,2)+.178*s)*1e4)/1e4}static assembleProperties(s,t,i,n){var p;const o=s.lbp??s.length??s.lengthOverall??198.9642,a=s.draught??8,e=s.breadthMoulded??s.breadth??s.breadthExtreme??32.4572,c=s.deadweight??67035.7773,r=((p=s==null?void 0:s.type)==null?void 0:p.toLowerCase())||"common";return{tag:r.indexOf("container")>-1?"container":r.indexOf("tugs")>-1?"tugs":"common",lbp:o,loadCondition:t,draught:a,breadthMoulded:e,displacement:Math.round((c/1.025+a*e*o*.7)*1e4)/1e4,speed:Math.round((i??14.1382)*1852/3600*1e4)/1e4,bearing:n||90}}static async speedLoseAt(s,t,i,n="",o=2,a=!0,e=!1,c={}){let r;if(t.velocity&&e&&(s.speed=O.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),a){const d=await ot.MeteoHelper.queryPointFactor(t.lng,t.lat,i.valueOf(),"wind,wave,current,watertemp",n,c),l=A.weatherFactor(s,d),p=A.currentFactor(s.bearing,d==null?void 0:d.current,o),f=Math.round((s.speed*1.943844+l+p)*100)/100;r={meteo:{...d},wxFactor:l,cFactor:p,speed:t.velocity&&e?t.velocity:f<0?1:f,eta:i.utc().format("YYYY-MM-DDTHH:mm[Z]"),etd:i.utc().format("YYYY-MM-DDTHH:mm[Z]")}}else r={wxFactor:0,cFactor:0,speed:t.velocity&&e?t.velocity:Math.round((s.speed*1.943844+0+0)*100)/100,eta:i.utc().format("YYYY-MM-DDTHH:mm[Z]"),etd:i.utc().format("YYYY-MM-DDTHH:mm[Z]")};return delete t.meteo,delete t.wxFactor,delete t.cFactor,delete t.speed,delete t.etd,{...r,...t}}static async speedLoseInHoursStep(s,t,i,n,o,a,e="",c=!0,r=!1,d={}){t.utc();const l=[],p=[];let f=0,m=0,Y,j;for(let v=0;v<a.length-1;v++){let M=a[v];M.distanceFromStart=o+m;const h=a[v+1];if(s.bearing=O.LaneHelper.calculateBearing(M,h,!h.gcToPrevious),M.bearing=s.bearing,M.suspend&&r){M.eta=M.eta||t.format("YYYY-MM-DDTHH:mm[Z]"),M.elapsed=M.elapsed??0;const y=M.suspend-M.elapsed;if(n-f>y)n=n-f-y,t.add(y,"hour"),M.elapsed=M.suspend;else{const b=n-f;M.elapsed+=b,t.add(b,"hour"),n=0}if(N==null||N.info(`[%s] suspend ${M.elapsed} hours at %j, and remain ${n} hours need to go...`,d.requestId,M),n===0)return M.distanceFromPrevious=m,{etd:t,from:j||M,to:M,next:a.filter(b=>b),wps:l,days:p}}M=await A.speedLoseAt(s,M,t,e,0,c,r,d),j=j||M,M.important&&l.push(M),t.isSameOrAfter(i)&&(p.push(M),i.add(24,"hour"));const I=O.LaneHelper.calculateDistance(M,h,!h.gcToPrevious);let w=Math.ceil(I/j.speed*1e4)/1e4;if(f+w<n){if(f+=w,t.add(w,"hour"),delete a[v],N==null||N.info(`[%s] go to %j from %j with ${I}nm, and cost ${w} hours`,d.requestId,{lat:h.lat,lng:h.lng},{lat:j.lat,lng:j.lng,etd:j.etd}),m+=I,a.filter(y=>y).length<=1){Y=h,Y.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),Y.distanceFromPrevious=I,Y.distanceFromStart=o+m,l.push(Y),delete a[v+1];break}}else{w=n-f,t.add(w,"hour");const y=O.LngLatHelper.roundPrecision(j.speed*w,4);Y=O.LaneHelper.calculateCoordinate(M,s.bearing,y,"nauticalmiles",!h.gcToPrevious),Y.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),a[v]=Y,N==null||N.info(`[%s] go to %j from %j with ${y}nm, and cost ${w} hours`,d.requestId,{lat:Y.lat,lng:Y.lng},{lat:M.lat,lng:M.lng,etd:M.etd}),m+=y,Y.distanceFromPrevious=m,Y.distanceFromStart=o+m;break}}return{etd:t,from:j,to:Y,next:a.filter(v=>v),wps:l,days:p}}static currentFactor(s,t,i=0){const n=(s-(t==null?void 0:t.degree)||0)/180*Math.PI;if(Math.abs(n)===Math.PI/2)return 0;let o=((t==null?void 0:t.kts)||0)*Math.cos(n);return i&2?o=Math.ceil(o*100)/100:i&1?o=Math.floor(o*100)/100:o=Math.round(o*100)/100,Math.abs(o)>5?0:o}static weatherFactor(s,t){var l,p,f,m,Y,j,v;N==null||N.debug("calculate weather factor via: %j",{...s,...t});const i=A.blockCoefficient(s.displacement,s.lbp,s.breadthMoulded,s.draught),n=A.froudeNumber(s.speed,s.lbp),o=A.amendFactor(i,n,s.loadCondition);let a=Math.abs(s.bearing%360-(((l=t==null?void 0:t.wind)==null?void 0:l.degree)%360||0));a=a>180?360-a:a;const e=A.directionFactor(a,(p=t==null?void 0:t.wind)==null?void 0:p.scale),c=A.vesselTagFactor(s.displacement,s.loadCondition,s.tag,(f=t==null?void 0:t.wind)==null?void 0:f.scale);let r=e*o*c/100*s.speed;r=Math.round(r*1.943844*1e4)/1e4*-1,s.tag==="tugs"&&Math.abs(r)>1&&(r=r/(Math.abs(Math.round(r))+1)),N==null||N.debug("wind wx factor = %d",r),a=Math.abs(s.bearing%360-(((Y=(m=t==null?void 0:t.wave)==null?void 0:m.sig)==null?void 0:Y.degree)%360||0));const d=A.waveHeightFactor(((v=(j=t==null?void 0:t.wave)==null?void 0:j.sig)==null?void 0:v.height)??1,a);return N==null||N.debug("wave wx factor = %d",d),r=r*.4+d,N==null||N.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*100)/100}static async analyseInstant(s,t,i,n,o,a="",e=0,c=!0,r=!1,d={}){var P,$,tt,et,st;const l=g().valueOf();s.lng=O.LngLatHelper.convertToStdLng(s.lng);const{route:p,waypoints:f}=o.points,m=O.LaneHelper.calculateSubRoute(s,p);if(((P=m[0])==null?void 0:P.length)<=1)return;const{v0:Y,label:j}=s.sog?{v0:s.sog,label:"Other"}:{v0:n.speed,label:"CP"},v=A.assembleProperties(i,n.loadCondition,Y,0),M=f.length?O.LaneHelper.calculateSubWaypoints(s,f):[];M.forEach(q=>q.important=!0);const h={from:{...s},route:m,waypoints:M,v0:Y,label:j},I={hours:[],days:[],wps:[]};e||(O.LaneHelper.calculateRouteDistance(m)/n.speed<=72?e=3:e=6);let w=O.LaneHelper.simplifyRouteToCoordinates(m,M,0),y=0,b=0,x=0,E=0;t=g(t).utc();const V=t.clone();for(;w.length>0;){const q=e-t.hour()%e,B=Math.ceil(t.clone().add(q,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,L=await A.speedLoseInHoursStep(v,t,V,B,y,w,a,c,r,d);($=L.from)!=null&&$.speed&&(I.hours.push(L.from),I.wps.push(...L.wps),I.days.push(...L.days)),w=L==null?void 0:L.next,w.length||I.hours.push(L==null?void 0:L.to),y+=((tt=L==null?void 0:L.to)==null?void 0:tt.distanceFromPrevious)??0}const S=I.hours;for(let q=0;q<S.length-1;q++){const B=g(S[q+1].eta).diff(S[q].etd,"hour",!0)||1;b+=(S[q].wxFactor||0)*B,x+=(S[q].cFactor||0)*B,E+=B}(et=I.wps)==null||et.forEach((q,B)=>{if(B){const L=I.wps[B-1],ht=q.distanceFromStart-L.distanceFromStart,at=g(q.eta).diff(g(L.etd),"h",!0);if(at<1)q.avgSpd=L.speed;else{q.avgSpd=Math.round(ht/at*100)/100;const nt=Math.round((L.speed+q.speed)/2*100)/100;q.avgSpd=q.avgSpd>nt?nt:q.avgSpd}}}),h.sample=I;const _=I.hours.at(0),W=I.hours.at(-1);h.distance=Math.round(W.distanceFromStart*1e4)/1e4,h.etd=g(_.eta).utc().format(),h.eta=g(W.eta).utc().format(),h.wxFactor=Math.round(b/E*1e4)/1e4,h.cFactor=Math.round(x/E*1e4)/1e4,h.avgSpeed=Math.round(W.distanceFromStart/E*1e4)/1e4,h.totalHrs=Math.round(E*1e4)/1e4,h.totalFoCons=Math.round((n==null?void 0:n.fo)/24*h.totalHrs*1e3)/1e3,h.totalDgoCons=Math.round((n==null?void 0:n.dgo)/24*h.totalHrs*1e3)/1e3;const C=g().valueOf()-l,F=((st=I==null?void 0:I.hours)==null?void 0:st.length)||1;return N==null||N.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",d==null?void 0:d.requestId,C,F,Math.round(C/F*1e3)/1e3),h}static async analyseInstantWithThreshed(s,t,i,n,o,a,e,c="",r=3,d=!0,l=!1,p={}){var W,T,C;s.lng=O.LngLatHelper.convertToStdLng(s.lng);const{v0:f,label:m}=s.sog?{v0:s.sog,label:"Other"}:{v0:o.speed,label:"CP"},Y=A.assembleProperties(n,o.loadCondition,f,0),j=O.LaneHelper.calculateSubRoute(s,a);if(((W=j[0])==null?void 0:W.length)<=1)return;const v=e.length?O.LaneHelper.calculateSubWaypoints(s,e):[];v.forEach(F=>F.important=!0);let M=O.LaneHelper.simplifyRouteToCoordinates(j,v,0),h=0,I=0,w=0,y=0,b;const x={hours:[],wps:[],days:[]};for(t=g(t).utc();M.length>0;){const F=r-t.hour()%r;let P=Math.ceil(t.clone().add(F,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;if(P=t.clone().add(P,"h").isAfter(i)?i.diff(t,"h",!0)*1e4/1e4:P,P)b=await A.speedLoseInHoursStep(Y,t,i.clone(),P,h,M,c,d,l,p),(T=b.from)!=null&&T.speed&&(x.hours.push(b.from),b!=null&&b.wps&&x.wps.push(...b.wps),x.days.push(...b.days)),M=b==null?void 0:b.next,M.length||(x.hours.push(b==null?void 0:b.to),b!=null&&b.wps&&x.wps.push(...b.wps),x.days.push(b==null?void 0:b.to)),h+=((C=b==null?void 0:b.to)==null?void 0:C.distanceFromPrevious)??0;else{b&&(x.hours.push(b.to),b!=null&&b.wps&&x.wps.push(...b.wps),x.days.push(b.to));break}}const E=x.hours;for(let F=0;F<E.length-1;F++){const P=g(E[F+1].eta).diff(E[F].etd,"hour",!0);I+=E[F].wxFactor*P,w+=E[F].cFactor*P,y+=P}const V=x.hours.at(0),S=x.hours.at(-1);return{sample:x,distance:Math.round(((S==null?void 0:S.distanceFromStart)||0)*1e4)/1e4,etd:g(V.eta).utc().format(),eta:g(S==null?void 0:S.eta).utc().format(),wxFactor:Math.round(I/y*1e4)/1e4,cFactor:Math.round(w/y*1e4)/1e4,avgSpeed:Math.round(((S==null?void 0:S.distanceFromStart)||0)/y*1e4)/1e4,totalHrs:Math.round(y*1e4)/1e4,from:s,to:S,route:j,waypoints:v,v0:f,label:m}}}H.AISImpl=z,H.AlertHelper=U,H.AlertLevel=G,H.HifleetImpl=rt,H.LoadCondition=Q,H.MyShipImpl=dt,H.MyVesselImpl=it,H.ShipxyImpl=ct,H.SpeedHelper=A,H.SpeedLabel=X,H.VesselTag=J,H.alertHelper=ut,Object.defineProperty(H,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idm-plugin/vessel",
3
3
  "private": false,
4
- "version": "1.4.2",
4
+ "version": "1.4.3",
5
5
  "description": "idm plugin for vessel",
6
6
  "type": "module",
7
7
  "keywords": [