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