@idm-plugin/vessel 1.6.5 → 1.6.7
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 +330 -331
- package/dist/index.umd.cjs +1 -1
- package/dist/speed/src/index.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(T,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):(T=typeof globalThis<"u"?globalThis:T||self,D(T["idm-plugin-rabbitmq"]={},T.got,T["@log4js-node/log4js-api"],T.moment,T["@idm-plugin/geo"],T["@idm-plugin/meteo2"],T["@idm-plugin/meteo"]))})(this,function(T,D,K,g,R,X,$){"use strict";var mt=Object.defineProperty;var yt=(T,D,K)=>D in T?mt(T,D,{enumerable:!0,configurable:!0,writable:!0,value:K}):T[D]=K;var _=(T,D,K)=>(yt(T,typeof D!="symbol"?D+"":D,K),K);let M;try{M=K.getLogger("vessel")}catch{}finally{}class G{parseStatus(e){let t,o;switch(e){case 0:t="在航(主机推动)",o="The engine is in use";break;case 1:t="锚泊",o="Anchored";break;case 2:t="失控",o="Not operated";break;case 3:t="操纵受限",o="Limited airworthiness";break;case 4:t="吃水受限",o="Limited by ship's draft";break;case 5:t="靠泊",o="Mooring";break;case 6:t="搁浅",o="Stranded";break;case 7:t="捕捞作业",o="Engaged in fishing";break;case 8:t="靠帆船提供动力",o="Sailing";break;default:t="未定义",o="Undefined"}return{labelCn:t,labelEn:o}}}class rt extends G{constructor(t,o){super();_(this,"clientId");_(this,"clientSecret");_(this,"token");this.clientId=t,this.clientSecret=o}async authToken(t={}){const o="https://svc.data.myvessel.cn/ada/oauth/token",i={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},a=await D.post(o,i).json();M==null||M.info("[%s] fetch access token from: %s - %j",t.requestId,o,a),a.error||(this.token={accessToken:a.access_token,tokenType:a.token_type,expiresIn:a.expires_in,scope:a.scope,jti:a.jti,issuedAt:g().utc().format()})}async realTimePosition(t,o={}){var l,y,f;(!this.token||g().diff(g(this.token.issuedAt),"seconds")>((l=this.token)==null?void 0:l.expiresIn)-300)&&await this.authToken(o);const i="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",a={headers:{Authorization:`${(y=this.token)==null?void 0:y.tokenType} ${(f=this.token)==null?void 0:f.accessToken}`},searchParams:{mmsi:t}};M==null||M.info("[%s] fetch realtime position from: %s - %j",o.requestId,i,a);const n=await D.get(i,a).json();if(n.code)return M==null||M.warn("[%s] fetch realtime position failed: %j",o.requestId,i,{message:n.message,status:n.status,code:n.code}),n;const s=n.data;for(const h in s)!isNaN(s[h])&&Number(s[h])!==1/0&&(s[h]=Number(s[h]));const d=g(`${s.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:s.mmsi,name:s.vesselName,imo:s.imo,callSign:s.callsign,lat:s.lat,lng:s.lon,length:s.length,width:s.width,draught:s.currDraught,sog:s.sog,cog:s.cog,hdg:s.hdg,rot:s.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta)?g.utc(s.eta).format():void 0,destination:s.dest,positionTime:d.unix(),status:s.status,labelCn:s.statusNameCn,labelEn:s.statusNameEn,method:"position",vendor:"myVessel",utc:d.utc().format()}}async trajectory(t,o,i,a,n=!0,s={}){(!this.token||g().diff(g(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(s);const d=await this.realTimePosition(t,s),r=g(o),l=g(i),y=[];for(;l.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(t,r,r.clone().add(30,"day"),d,a,y,s),r.add(30,"day");return await this.trajectoryIn30Day(t,r,l,d,a,y,s),y}async trajectoryIn30Day(t,o,i,a,n,s,d={}){var u,I,k,m,v;const r="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",l={headers:{Authorization:`${(u=this.token)==null?void 0:u.tokenType} ${(I=this.token)==null?void 0:I.accessToken}`},json:{mmsi:t,startTime:o.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};M==null||M.info("[%s] fetch trajectory from: %s - %j",d.requestId,r,l);const y=await D.post(r,l).json();if(y.code)return M==null||M.warn("[%s] fetch trajectory failed: %j",d.requestId,r,{message:y.message,status:y.status,code:y.code}),y;let f=-1;const h=g(`${(m=(k=y.data)==null?void 0:k[0])==null?void 0:m.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(v=y.data)==null||v.forEach(c=>{for(const x in c)!isNaN(c[x])&&Number(c[x])!==1/0&&(c[x]=Number(c[x]));const b=g(`${c.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),q=c.status,{labelCn:p,labelEn:j}=this.parseStatus(q),S={mmsi:c.mmsi,imo:a==null?void 0:a.imo,lat:c.lat,lng:c.lon,sog:c.sog,cog:c.cog,hdg:c.hdg,draught:c.draught,status:q,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(c.eta)?g(`${c.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").utc().format():void 0,destination:c.dest,positionTime:b.unix(),labelCn:p,labelEn:j,method:"trajectory",vendor:"myVessel",utc:b.utc().format()},N=Math.floor(b.diff(h,"minute",!0)/(n||1));N!==f&&(f=N,s.push(S))}),s}}class ct extends G{constructor(t){super();_(this,"token");this.token=t}async realTimePosition(t,o={}){const i="https://api.hifleet.com/position/position/get/token",a={searchParams:{mmsi:t,usertoken:this.token}},n=await D.post(i,a).json();M==null||M.info("[%s] fetch realtime position from: %s - %j",o.requestId,i,a);const s=n==null?void 0:n.list;if(!s)return M==null||M.warn("[%s] fetch realtime position failed: %j",o.requestId,i,n),n;for(const h in s)!isNaN(s[h])&&Number(s[h])!==1/0&&(s[h]=Number(s[h]));s.status=s.sp>3?0:1;const d=s.status,{labelCn:r,labelEn:l}=this.parseStatus(d),y=g(`${s.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:s.m,name:s.n,imo:s.imonumber,callSign:s.callsign,lat:Math.round(s.la/60*1e5)/1e5,lng:Math.round(s.lo/60*1e5)/1e5,length:s.l,width:s.w,draught:s.draught,sog:s.sp,cog:s.co,hdg:s.h,rot:isNaN(s.rot)?0:s.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta)?g.utc(s.eta).format():void 0,destination:s.destination,positionTime:y.unix(),utc:y.utc().format(),status:d,labelCn:r,labelEn:l,method:"position",vendor:"hifleet"}}async search(t,o={}){let i="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const a={searchParams:{keyword:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let n=await D.post(i,a).json();M==null||M.info("[%s] fetch vessel props from: %s - %j",o.requestId,i,a),n instanceof Array&&(n=n[0]);for(const d in n)!isNaN(n[d])&&Number(n[d])!==1/0&&(n[d]=Number(n[d]));const s={mmsi:n.m,name:n.n,imo:n.i,callSign:n.c,length:n.l,breadth:n.b,draught:n.dr,type:n.t};return i="https://www.hifleet.com/hifleetapi/sameShipSearch.do",n=await D.post(i,a).json(),M==null||M.info("[%s] search vessel dead weight from: %s - %j",o.requestId,i,a),n instanceof Array&&(n=n[0]),n&&(s.deadweight=Number(n.dwt)),s}async suggest(t,o={}){const i="https://www.hifleet.com/hifleetapi/getShipSuggest.do",a={searchParams:{q:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}},n=await D.post(i,a).json();M==null||M.info("[%s] suggest vessel props from: %s - %j",o.requestId,i,a);const s=[];for(const d of n)s.push({mmsi:!d.mmsi||isNaN(d.mmsi)?null:Number(d.mmsi),name:d.name,callSign:d.callsign,imo:!d.imo||isNaN(d.imo)?null:Number(d.imo),score:d._score});return s.sort((d,r)=>r.score-d.score),s}async trajectory(t,o,i,a,n=!0,s={}){var c,b,q;const d=await this.realTimePosition(t,s);let r=g(o);const l=g(i),y=g();if(n){let p=l.diff(r,"d",!0);p<0?r=l.clone().subtract(40,"d"):p<30?r.subtract(10,"d"):p<60?r.subtract(5,"d"):r=l.clone().subtract(80,"d"),p=y.diff(l,"d",!0),l.add(p>10?240:p*24,"h")}const f={searchParams:{endtime:l.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),starttime:r.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),mmsi:t,usertoken:this.token}},h="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",u=await D.get(h,f).json();M==null||M.info("[%s] fetch trajectory from: %s - %j",s.requestId,h,f);let I;u&&(I=((b=(c=u.ships)==null?void 0:c.offors)==null?void 0:b.ship)||[],I.length||M==null||M.warn("[%s] fetch trajectory failed: %j",s.requestId,u));const k=[];let m=-1;const v=g(`${(q=I==null?void 0:I[0])==null?void 0:q.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const p of I){for(const L in p)!isNaN(p[L])&&Number(p[L])!==1/0&&(p[L]=Number(p[L]));const j=g(`${p.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");p.status=p.sp>4?0:1;const{labelEn:S,labelCn:N}=this.parseStatus(p.status),x={mmsi:p.m,name:p.n,imo:d==null?void 0:d.imo,lat:p.la,lng:p.lo,draught:p.draught,sog:p.sp,cog:p.co,hdg:p.hdg,positionTime:j.unix(),utc:j.utc().format(),status:p.status,labelCn:N,labelEn:S,method:"trajectory",vendor:"hifleet"},W=Math.floor(j.diff(v,"minute",!0)/(a||1));W!==m&&(m=W,k.push(x))}return k}}class dt extends G{constructor(t){super();_(this,"token");this.token=t}async realTimePosition(t,o={}){const i={searchParams:{id:t,k:this.token,enc:1}},a="https://api.shipxy.com/apicall/GetSingleShip",n=await D.get(a,i).json();if(M==null||M.info("[%s] fetch realtime position from: %s - %j",o.requestId,a,i),(n==null?void 0:n.status)!==0)return n;const s=n.data[0];for(const f in s)!isNaN(s[f])&&Number(s[f])!==1/0&&(s[f]=Number(s[f]));const{labelCn:d,labelEn:r}=await this.parseStatus(s.navistat),l=g.unix(s.lasttime);return{mmsi:s.ShipID,name:s.name,imo:s.imo,callSign:s.callsign,lat:Math.round(s.lat/1e6*1e5)/1e5,lng:Math.round(s.lon/1e6*1e5)/1e5,length:Math.round(s.length/10*100)/100,width:Math.round(s.width/10*100)/100,draught:Math.round(s.draught/1e3*100)/100,sog:Math.round(s.sog*3600/1e3/1852*100)/100,cog:Math.round(s.cog/100*100)/100,hdg:Math.round(s.hdg/100*100)/100,rot:Math.round(s.rot/100*100)/100,positionTime:s.lasttime,utc:l.utc().format(),status:s.navistat,labelEn:r,labelCn:d,method:"position",vendor:"shipxy"}}async trajectory(t,o,i,a,n=!0,s={}){var v;const d=await this.realTimePosition(t,s),r=g(o),l=g(i),y="https://api.shipxy.com/apicall/GetShipTrack",f={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:r.unix(),etm:l.unix()}},h=await D.get(y,f).json();if(M==null||M.info("[%s] fetch trajectory from: %s - %j",s.requestId,y,f),(h==null?void 0:h.status)!==0)return h;const u=h==null?void 0:h.points,I=[],k=g.unix((v=u[0])==null?void 0:v.utc);let m=-1;for(const c of u){const b=g.unix(c.utc),q={imo:d==null?void 0:d.imo,mmsi:t,sog:Math.round(c.sog*3600/1e3/1852*100)/100,cog:Math.round(c.cog/100*100)/100,lat:Math.round(c.lat/1e6*1e5)/1e5,lng:Math.round(c.lon/1e6*1e5)/1e5,positionTime:b.unix(),utc:b.utc().format(),method:"trajectory",vendor:"shipxy"},p=Math.floor(b.diff(k,"minute",!0)/(a||1));p!==m&&(m=p,I.push(q))}return I}}class ut extends G{constructor(t){super();_(this,"token");this.token=t}async getShipId(t,o={}){const i={headers:{appKey:this.token},json:{mmsiList:t}},a="https://api3.myships.com/sp/ships/getShipIdByMMSI",n=await D.post(a,i).json();return M==null||M.info("[%s] fetch ship id from: %s - %j",o.requestId,a,i),n.code!=="0"?n:n.data[0].shipId}async getShipInfo(t,o={}){const i={headers:{appKey:this.token},json:{shipId:t}},a="https://api3.myships.com/sp/ships/aissta",n=await D.post(a,i).json();if(M==null||M.info("[%s] fetch ship info from: %s - %j",o.requestId,a,i),n.code!=="0")return n;const s=n.data;let d=s.imo;return t==="407170"&&(d="9198379",M==null||M.warn("[%s] ship(%s) imo error: %s, should be %s",o.requestId,t,s.imo,d)),{mmsi:s.mmsi,name:s.shipnameEn,imo:d,callSign:s.callSign,length:s.length,width:s.breadth,draught:(s.draught||100)/10}}async realTimePosition(t,o={}){const i=await this.getShipId(t,o),a=await this.getShipInfo(i,o),n={headers:{appKey:this.token},json:{shipId:i}},s="https://api3.myships.com/sp/ships/position/latest",d=await D.post(s,n).json();M==null||M.info("[%s] fetch realtime position from: %s - %j",o.requestId,s,n);const r=d.data[0];for(const u in r)!isNaN(r[u])&&Number(r[u])!==1/0&&(r[u]=Number(r[u]));const{labelCn:l,labelEn:y}=await this.parseStatus(r.aisNavStatus),f=g.unix(r.posTime);return{...a,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:f.utc().format(),status:r.aisNavStatus,labelEn:y,labelCn:l,method:"position",vendor:"myship"}}async trajectory(t,o,i,a,n=!0,s={}){const d=g(o),r=g(i),l=await this.getShipId(t),y=await this.getShipInfo(l),f=[];for(;r.diff(d,"day",!0)>30;)await this.trajectoryIn30Day(l,d.unix(),d.add(30,"day").unix(),y,t,a,f);return await this.trajectoryIn30Day(l,d.unix(),r.unix(),y,t,a,f),f}async trajectoryIn30Day(t,o,i,a,n,s,d,r={}){var k;const l={headers:{appKey:this.token},json:{shipId:t,startTime:o,endTime:i}},y="https://api3.myships.com/sp/ships/position/history",f=await D.post(y,l).json();if(M==null||M.info("[%s] fetch trajectory from: %s - %j",r.requestId,y,l),f.code!=="0")return M==null||M.warn("[%s] invoke myship trajectory failed: %j",r.requestId,f),f;const h=f.data;for(const m in h)!isNaN(h[m])&&Number(h[m])!==1/0&&(h[m]=Number(h[m]));const u=g.unix((k=h[0])==null?void 0:k.posTime);let I=-1;for(const m of h){const v=g.unix(m.posTime),c={imo:a==null?void 0:a.imo,mmsi:n,lat:Math.round(m.lat/1e4/60*1e5)/1e5,lng:Math.round(m.lon/1e4/60*1e5)/1e5,sog:Math.round(m.sog/10*100)/100,cog:Math.round(m.cog/10*100)/100,hdg:Math.round(m.heading*100)/100,rot:Math.round(m.rot*100)/100,positionTime:v.unix(),utc:v.utc().format(),method:"trajectory",vendor:"myship"},b=Math.floor(v.diff(u,"minute",!0)/(s||1));b!==I&&(I=b,d.push(c))}return d}}let V;try{V=K.getLogger("vessel")}catch{}finally{}var tt=(Y=>(Y.NOTICE="NOTICE",Y.WARN="WARN",Y.HEAVY="HEAVY",Y.SEVERE="SEVERE",Y.ERROR="ERROR",Y.FATAL="FATAL",Y))(tt||{});class et{parsePrinciple(e,t={}){var s,d,r;V==null||V.info("[%s] parse rule: %s",t.requestId,e);const o=new RegExp("(?<=\\[)(.+)(?=])","g"),i=e.match(o)?(s=e.match(o))==null?void 0:s[0]:void 0,a=i==null?void 0:i.split(";");if(!a)return;const n={};for(let l=0;l<(a==null?void 0:a.length);l++){const y=(r=(d=a[l].match(o))==null?void 0:d[0])==null?void 0:r.split("],");if(l===0&&!y)n.scope=a[0];else if(y)for(let f=0,h=y.length;f<h;f++){const u=this.parseRule(y[f]);u&&(n[u.level]?u.key?n[u.level][u==null?void 0:u.key]=u:n[u.level]=u:u.key?n[u.level]={[u==null?void 0:u.key]:u}:n[u.level]=u)}}return n}parseRule(e,t={}){var n;V==null||V.info("[%s] parse rule: %s",t.requestId,e),e=e.startsWith("[")?e:`[${e}`,e=e.endsWith("]")?e:`${e}]`;const o=new RegExp("(?<=\\[)(.+?)(?=])","g"),i=(n=e==null?void 0:e.match(o))==null?void 0:n[0],a=i==null?void 0:i.split(",");if(a)return{operator:a[0],number:Number.isNaN(Number(a[1]))?a[1]:Number(a[1]),level:a[2],time:Number(a[3]),key:a[4]}}checkWeather(e,t,o={}){var u,I,k,m,v,c,b,q,p,j,S,N,x,W,L;let i=0,a=0,n=0,s=0;const d=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=(m=(k=t==null?void 0:t.SEVERE)==null?void 0:k.sigWave)==null?void 0:m.number,l=(c=(v=t==null?void 0:t.HEAVY)==null?void 0:v.sigWave)==null?void 0:c.number,y=Math.round((((q=(b=t==null?void 0:t.SEVERE)==null?void 0:b.wind)==null?void 0:q.number)+2)*100)/100,f=(j=(p=t==null?void 0:t.SEVERE)==null?void 0:p.wind)==null?void 0:j.number,h=(N=(S=t==null?void 0:t.HEAVY)==null?void 0:S.wind)==null?void 0:N.number;for(let B=0;B<(e==null?void 0:e.length);B++){const E=e[B],P=(W=(x=E==null?void 0:E.meteo)==null?void 0:x.wave)==null?void 0:W.sig,A=(L=E==null?void 0:E.meteo)==null?void 0:L.wind,Z=B?g(E.eta).diff(g(e[B-1].eta),"hour",!0):0;s=Z>s?Z:s,V==null||V.info("[%s] check sig.wave: %j",o.requestId,{...P,dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:l}),(P==null?void 0:P.height)>=d?E.isDangerous=!0:(P==null?void 0:P.height)>=r?E.isSevere=!0:(P==null?void 0:P.height)>=l&&(E.isHeavy=!0),V==null||V.info("[%s] check wind: %j",o.requestId,{...A,dgThd4Wd:y,svThd4Wd:f,hvThd4Wd:h}),(A==null?void 0:A.scale)>=y?(E.isDangerous=!0,delete E.isSevere,delete E.isHeavy):(A==null?void 0:A.scale)>f?(E.isDangerous||(E.isSevere=!0),delete E.isHeavy):(A==null?void 0:A.scale)===h&&!E.isDangerous&&!E.isSevere&&(E.isHeavy=!0),i+=E.isDangerous?Z:0,a+=E.isSevere?Z:0,n+=E.isHeavy?Z:0}return i=Math.round(i*100)/100,a=Math.round(a*100)/100,n=Math.round(n*100)/100,s=Math.round(s),{sample:e,dangerous:i,severe:a,heavy:n,step:s<3?3:s,wind:{dgThd4Wd:y,svThd4Wd:f,hvThd4Wd:h},sig:{dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:l}}}}const ht=new et;let w;try{w=K.getLogger("vessel")}catch{}finally{}const lt=new X.MeteoHelper2("",!0);var st=(Y=>(Y.common="common",Y.container="container",Y.tugs="tugs",Y))(st||{}),at=(Y=>(Y.Ballast="Ballast",Y.Laden="Laden",Y))(at||{}),ot=(Y=>(Y.Cp="CP",Y.Perf="Basis",Y.Instruct="Other",Y))(ot||{});class C{static blockCoefficient(e,t,o,i){let a=Math.round(e/(t*o*i)*100)/100;a=a<.55?.55:a>.85?.85:a;const n=[.55,.6,.65,.7,.75,.8,.85],s=n.map(d=>Math.abs(d-a));return n[s.indexOf(Math.min(...s))]}static froudeNumber(e,t,o=9.8){let i=Math.round(Math.sqrt(e*e/(o*t))*100)/100;return i=i<.05?.05:i>.3?.3:i,i}static amendFactor(e,t,o){const i={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.4,-10.6,-9.5],.8:[2.6,-13.1,-15.1],.85:[3.1,-18.7,28]};let 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.6,-12.5,-13.5],.8:[3,-16.3,-21.6],.85:[3.4,-20.9,31.8]}[e];return o==="Laden"&&(n=i[e]),n[0]+n[1]*t+n[2]*Math.pow(t,2)}static directionFactor(e,t=0){let o;return e>30&&e<=60?o=(1.7-.03*Math.pow(t-4,2))/2:e>60&&e<=150?o=(.9-.06*Math.pow(t-6,2))/2:e>150&&e<=180?o=(.4-.03*Math.pow(t-8,2))/2:o=1,Math.round(o*1e5)/1e5}static vesselTagFactor(e,t,o,i=0){i=i>6?i-.9*(i-6):i;let a;return o==="container"?a=.7*i+Math.pow(i,6.5)/(22*Math.pow(e,2/3)):t==="Ballast"?a=.7*i+Math.pow(i,6.5)/(2.7*Math.pow(e,2/3)):a=.5*i+Math.pow(i,6.5)/(2.7*Math.pow(e,2/3)),a}static waveHeightFactor(e,t){e=e<0?.2:e,e=e>6?e-.9*(e-6):e,e=e>9?9:e;let o;return t>30&&t<=60?o=-.6:t>60&&t<=90?o=-.4:t>90&&t<=120?o=e<3?.4:-.3:t>120&&t<=150?o=e<3?.6:-.5:t>150&&t<=180?o=e<3?.7:-.6:o=-.7,Math.round(o*(.144*Math.pow(e,2)+.178*e)*1e4)/1e4}static assembleProperties(e,t,o,i){var f;const a=e.lbp??e.length??e.lengthOverall??198.9642,n=e.draught??8,s=e.breadthMoulded??e.breadth??e.breadthExtreme??32.4572,d=e.deadweight??67035.7773,r=((f=e==null?void 0:e.type)==null?void 0:f.toLowerCase())||"common";return{tag:r.indexOf("container")>-1?"container":r.indexOf("tugs")>-1?"tugs":"common",lbp:a,loadCondition:t,draught:n,breadthMoulded:s,displacement:Math.round((d/1.025+n*s*a*.7)*1e4)/1e4,speed:Math.round((o??14.1382)*1852/3600*1e4)/1e4,bearing:i||90}}static async speedLoseAt(e,t,o,i="",a=2,n=!0,s=!1,d={}){let r;if(t.velocity&&s&&(e.speed=R.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),n){let l;if(d.meteo2)try{const u=await lt.spotForecast(t.lat,t.lng,o.utc().format(),!1,!1,!0,d),[I]=$.Meteo2Assist.pickHourly(u,o);l=$.Meteo2Assist.toLegacy(I)}catch(u){w.warn("[%s] meteo2 spot(%j) forecast failed: %s",d.requestId,{...t,eta:o.utc().format()},u)}else l=await X.MeteoHelper.queryPointFactor(t.lng,t.lat,o.valueOf(),"wind,wave,current,watertemp",i,d);const y=C.weatherFactor(e,l),f=C.currentFactor(e.bearing,l==null?void 0:l.current,a),h=Math.round((e.speed*1.943844+y+f)*100)/100;r={meteo:{...l},wxFactor:y,cFactor:f,speed:t.velocity&&s?t.velocity:h<0?1:h,eta:o.utc().format("YYYY-MM-DDTHH:mm[Z]"),etd:o.utc().format("YYYY-MM-DDTHH:mm[Z]")}}else r={wxFactor:0,cFactor:0,speed:t.velocity&&s?t.velocity:Math.round((e.speed*1.943844+0+0)*100)/100,eta:o.utc().format("YYYY-MM-DDTHH:mm[Z]"),etd:o.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(e,t,o,i,a,n,s="",d=!0,r=!1,l={}){t.utc();const y=t.clone().add(14,"days"),f=[],h=[];let u=0,I=0,k,m;for(let v=0;v<n.length-1;v++){let c=n[v];c.distanceFromStart=Math.round((a+I)*1e4)/1e4;const b=n[v+1];if(e.bearing=R.LaneHelper.calculateBearing(c,b,!b.gcToPrevious),c.bearing=e.bearing,c.suspend&&r){c.eta=c.eta||t.format("YYYY-MM-DDTHH:mm[Z]"),c.elapsed=c.elapsed??0;const j=c.suspend-c.elapsed;if(i-u>j)i=i-u-j,t.add(j,"hour"),c.elapsed=c.suspend;else{const S=i-u;c.elapsed+=S,t.add(S,"hour"),i=0}if(w==null||w.info(`[%s] suspend ${c.elapsed} hours at %j, and remain ${i} hours need to go...`,l.requestId,c),i===0)return c.distanceFromPrevious=I,{etd:t,from:m||c,to:c,next:n.filter(S=>S),wps:f,days:h}}else c.suspend=0;d=t.isAfter(y)?!1:d,c=await C.speedLoseAt(e,c,t,s,0,d,r,l),m=m||c,c.important&&f.push(c),t.isSameOrAfter(o)&&(h.push(c),o.add(24,"hour"));const q=R.LaneHelper.calculateDistance(c,b,!b.gcToPrevious);let p=Math.ceil(q/m.speed*1e4)/1e4;if(u+p<i){if(u+=p,t.add(p,"hour"),delete n[v],w==null||w.debug(`[%s] go to %j from %j with ${q}nm, and cost ${p} hours`,l.requestId,{lat:b.lat,lng:b.lng},{lat:m.lat,lng:m.lng,etd:m.etd}),I+=q,n.filter(j=>j).length<=1){k=b,k.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),k.distanceFromPrevious=q,k.distanceFromStart=Math.round((a+I)*1e4)/1e4,f.push(k),delete n[v+1];break}}else{p=i-u,t.add(p,"hour");const j=R.LngLatHelper.roundPrecision(m.speed*p,4);k=R.LaneHelper.calculateCoordinate(c,e.bearing,j,"nauticalmiles",!b.gcToPrevious),k.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),n[v]=k,w==null||w.debug(`[%s] go to %j from %j with ${j}nm, and cost ${p} hours`,l.requestId,{lat:k.lat,lng:k.lng},{lat:c.lat,lng:c.lng,etd:c.etd}),I+=j,k.distanceFromPrevious=Math.round(I*1e4)/1e4,k.distanceFromStart=Math.round((a+I)*1e4)/1e4;break}}return{etd:t,from:m,to:k,next:n.filter(v=>v),wps:f,days:h}}static currentFactor(e,t,o=0){const i=(e-(t==null?void 0:t.degree)||0)/180*Math.PI;if(Math.abs(i)===Math.PI/2)return 0;let a=((t==null?void 0:t.kts)||0)*Math.cos(i);return o&2?a=Math.ceil(a*100)/100:o&1?a=Math.floor(a*100)/100:a=Math.round(a*100)/100,Math.abs(a)>5?0:a}static weatherFactor(e,t){var y,f,h,u,I,k,m;w==null||w.debug("calculate weather factor via: %j",{...e,...t});const o=C.blockCoefficient(e.displacement,e.lbp,e.breadthMoulded,e.draught),i=C.froudeNumber(e.speed,e.lbp),a=C.amendFactor(o,i,e.loadCondition);let n=Math.abs(e.bearing%360-(((y=t==null?void 0:t.wind)==null?void 0:y.degree)%360||0));n=n>180?360-n:n;const s=C.directionFactor(n,(f=t==null?void 0:t.wind)==null?void 0:f.scale),d=C.vesselTagFactor(e.displacement,e.loadCondition,e.tag,(h=t==null?void 0:t.wind)==null?void 0:h.scale);let r=s*a*d/100*e.speed;r=Math.round(r*1.943844*1e4)/1e4*-1,e.tag==="tugs"&&Math.abs(r)>1&&(r=r/(Math.abs(Math.round(r))+1)),w==null||w.debug("wind wx factor = %d",r),n=Math.abs(e.bearing%360-(((I=(u=t==null?void 0:t.wave)==null?void 0:u.sig)==null?void 0:I.degree)%360||0));const l=C.waveHeightFactor(((m=(k=t==null?void 0:t.wave)==null?void 0:k.sig)==null?void 0:m.height)??1,n);return w==null||w.debug("wave wx factor = %d",l),r=r*.4+l,w==null||w.debug("weather factor = %d",r),r=Math.abs(r)>4?4*(Math.abs(r)/r)+Math.abs(r)/r*(Math.abs(r)-4)*.1:r,Math.round((r||0)*100)/100}static async analyseInstant(e,t,o,i,a,n="",s=0,d=!0,r=!1,l={}){var Z,z,U,Q,J;const y=g().valueOf();e.lng=R.LngLatHelper.convertToStdLng(e.lng);const{route:f,waypoints:h}=a.points,u=R.LaneHelper.calculateSubRoute(e,f);if(((Z=u[0])==null?void 0:Z.length)<=1)return;const{v0:I,label:k}=e.sog?{v0:e.sog,label:"Other"}:{v0:i.speed,label:"CP"},m=C.assembleProperties(o,i.loadCondition,I,0),v=h.length?R.LaneHelper.calculateSubWaypoints(e,h):[];v.forEach(H=>H.important=!0);const c={from:{...e},route:u,waypoints:v,v0:I,label:k},b={hours:[],days:[],wps:[]};s||(R.LaneHelper.calculateRouteDistance(u)/i.speed<=72?s=3:s=6);let q=R.LaneHelper.simplifyRouteToCoordinates(u,v,0),p=0,j=0,S=0,N=0;t=g(t).utc();const x=t.clone();for(;q.length>0;){const H=s-t.hour()%s,F=Math.ceil(t.clone().add(H,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,O=await C.speedLoseInHoursStep(m,t,x,F,p,q,n,d,r,l);(z=O.from)!=null&&z.speed&&(b.hours.push(O.from),b.wps.push(...O.wps),b.days.push(...O.days)),q=O==null?void 0:O.next,q.length||b.hours.push(O==null?void 0:O.to),p+=Math.round((((U=O==null?void 0:O.to)==null?void 0:U.distanceFromPrevious)??0)*1e4)/1e4}const W=b.hours;for(let H=0;H<W.length-1;H++){const F=g(W[H+1].eta).diff(W[H].etd,"hour",!0)||1;j+=(W[H].wxFactor||0)*F,S+=(W[H].cFactor||0)*F,N+=F}(Q=b.wps)==null||Q.forEach((H,F)=>{if(F){const O=b.wps[F-1],ft=H.distanceFromStart-O.distanceFromStart,nt=g(H.eta).diff(g(O.etd),"h",!0);if(nt<1)H.avgSpd=O.speed;else{H.avgSpd=Math.round(ft/nt*100)/100;const it=Math.round((O.speed+H.speed)/2*100)/100;H.avgSpd=H.avgSpd>it?it:H.avgSpd}}}),c.sample=b;const L=b.hours.at(0),B=b.hours.at(-1);c.distance=Math.round(B.distanceFromStart*1e4)/1e4,c.etd=g(L.eta).utc().format(),c.eta=g(B.eta).utc().format(),c.wxFactor=Math.round(j/N*1e4)/1e4,c.cFactor=Math.round(S/N*1e4)/1e4,c.avgSpeed=Math.round(B.distanceFromStart/N*1e4)/1e4,c.totalHrs=Math.round(N*1e4)/1e4,c.totalFoCons=Math.round((i==null?void 0:i.fo)/24*c.totalHrs*1e3)/1e3,c.totalDgoCons=Math.round((i==null?void 0:i.dgo)/24*c.totalHrs*1e3)/1e3;const P=g().valueOf()-y,A=((J=b==null?void 0:b.hours)==null?void 0:J.length)||1;return w==null||w.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",l==null?void 0:l.requestId,P,A,Math.round(P/A*1e3)/1e3),c}static async analyseInstantWithThreshed(e,t,o,i,a,n,s,d="",r=3,l=!0,y=!1,f={}){var Z,z,U,Q;const h=g().valueOf();e.lng=R.LngLatHelper.convertToStdLng(e.lng);const{v0:u,label:I}=e.sog?{v0:e.sog,label:"Other"}:{v0:a.speed,label:"CP"},k=C.assembleProperties(i,a.loadCondition,u,0),m=R.LaneHelper.calculateSubRoute(e,n);if(((Z=m[0])==null?void 0:Z.length)<=1)return;const v=s.length?R.LaneHelper.calculateSubWaypoints(e,s):[];v.forEach(J=>J.important=!0);let c=R.LaneHelper.simplifyRouteToCoordinates(m,v,0),b=0,q=0,p=0,j=0;const S={hours:[],wps:[],days:[]};t=g(t).utc();const N=t.clone();for(;c.length>0;){const J=r-t.hour()%r;let H=Math.ceil(t.clone().add(J,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;if(H=t.clone().add(H,"h").isAfter(o)?o.diff(t,"h",!0)*1e4/1e4:H,H){const F=await C.speedLoseInHoursStep(k,t,N,H,b,c,d,l,y,f);(z=F.from)!=null&&z.speed&&(S.hours.push(F.from),F!=null&&F.wps&&S.wps.push(...F.wps),S.days.push(...F.days)),c=F==null?void 0:F.next,c.length||S.hours.push(F==null?void 0:F.to),b+=Math.round((((U=F==null?void 0:F.to)==null?void 0:U.distanceFromPrevious)??0)*1e4)/1e4}else break}const x=S.hours;for(let J=0;J<x.length-1;J++){const H=g(x[J+1].eta).diff(x[J].etd,"hour",!0);q+=x[J].wxFactor*H,p+=x[J].cFactor*H,j+=H}const W=S.hours.at(0),L=S.hours.at(-1),B={sample:S,distance:Math.round(((L==null?void 0:L.distanceFromStart)||0)*1e4)/1e4,etd:g(W.eta).utc().format(),eta:g(L==null?void 0:L.eta).utc().format(),wxFactor:Math.round(q/j*1e4)/1e4,cFactor:Math.round(p/j*1e4)/1e4,avgSpeed:Math.round(((L==null?void 0:L.distanceFromStart)||0)/j*1e4)/1e4,totalHrs:Math.round(j*1e4)/1e4,totalFoCons:Math.round((a==null?void 0:a.fo)/24*j*1e3)/1e3,totalDgoCons:Math.round((a==null?void 0:a.dgo)/24*j*1e3)/1e3,from:W,to:L,route:m,waypoints:v,v0:u,label:I},P=g().valueOf()-h,A=((Q=S==null?void 0:S.hours)==null?void 0:Q.length)||1;return w==null||w.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",f==null?void 0:f.requestId,P,A,Math.round(P/A*1e3)/1e3),B}static async analyseCost(e,t,o,i,a={}){var I,k;const n=g().valueOf(),s=[];a.meteo2=!0,e.speedStep=e.speedStep||3;const d=g.utc(e.etd).add(a.maxDays??14,"day");let r=1;for(const m of o){const v=JSON.parse(JSON.stringify(i.route)),c=JSON.parse(JSON.stringify(i.waypoints)),b=await C.analyseInstantWithThreshed({lat:e.lat,lng:e.lng},e.etd,d,t,m,v,c,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,a);b&&(await C.calculateCost(b,m,e,a),s.push(b),w==null||w.info("[%s][L%d-%d] analyse from %s to %s cost: %j",a.requestId,1,r,e.etd,d.format(),{cost:b.cost.total,distance:b.distance,hours:b.totalHrs,cp:`${m.speed}/${m.fo}/${m.dgo}`})),r++}s.sort((m,v)=>m.cost.total-v.cost.total);const l=s.at(0),y=s.at(1),f=[];if(f.push({combined:!1,speeds:[l],cost:(I=l.cost)==null?void 0:I.total}),y){const m=l.cost.cp,v=y.cost.cp,c=g(l.eta),b=g(l.etd),q=c.diff(b,"days",!0);let p=Math.ceil(q/2);p=p>7?7:p;let j=2,S={combined:!1,speeds:[y],cost:(k=y.cost)==null?void 0:k.total},N;for(;p>=1;){const x=await C.combinedAnalyse(e,t,d,[m,v],i,p,{...a,level:j});if(S.cost>x.cost?N?(N==null?void 0:N.cost)>x.cost&&(N=x):(N=S,S=x):(!N||(N==null?void 0:N.cost)>x.cost)&&(N=x),p===1)break;p=Math.ceil(p/2),j+=1}f.push(S),N&&f.push(N)}const u=g().valueOf()-n;return w==null||w.info("[%s] analyse elapsed: %d ms",a==null?void 0:a.requestId,u),f.sort((m,v)=>m.cost-v.cost)}static async combinedAnalyse(e,t,o,i,a,n,s={}){s.counter=1,w==null||w.info("[%s][L%d] analyse with alternate cp in every %d days",s.requestId,s.level,n);const d=await C.alternateAnalyse(e,t,o,i,0,a,n,s),r=d.reduce((f,h)=>f+h.cost.total,0);w==null||w.info("[%s][L%d] cost with cpa/cpb turn: %d",s.requestId,s.level,r);const l=await C.alternateAnalyse(e,t,o,i,1,a,n,s),y=l.reduce((f,h)=>f+h.cost.total,0);return w==null||w.info("[%s][L%d] cost with cpb/cpa turn: %d",s.requestId,s.level,y),r<y?{combined:!0,cost:Math.round(r*1e3)/1e3,speeds:d}:{combined:!0,cost:Math.round(y*1e3)/1e3,speeds:l}}static async alternateAnalyse(e,t,o,i,a,n,s,d={}){var f,h;let r=g.utc(e.etd);const l={lat:e.lat,lng:e.lng},y=[];for(;r.isBefore(o);){const u=r.clone().utc().add(s,"day"),I=JSON.parse(JSON.stringify(n.route)),k=JSON.parse(JSON.stringify(n.waypoints)),m=i[a],v=await C.analyseInstantWithThreshed(l,r.format(),u,t,m,I,k,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,d);v&&(await C.calculateCost(v,m,e,d),w==null||w.info("[%s][L%d-%d] analyse from %s to %s cost: %j",d.requestId,d.level,d.counter,r.utc().format(),u.utc().format(),{cost:v.cost.total,distance:v.distance,hours:v.totalHrs,cp:`${m.speed}/${m.fo}/${m.dgo}`})),d.counter=d.counter+1;const c=(h=(f=v==null?void 0:v.sample)==null?void 0:f.hours)==null?void 0:h.at(-1);if(c)l.lat=c.lat,l.lng=c.lng,r=g(c.eta),y.push(v),a=a?0:1;else break}return y}static async calculateCost(e,t,o,i={}){if(e){const a=Math.round(e.totalHrs/24*(o.dailyHire||0)*(1-(o.addComm||0))*1e3)/1e3,n=Math.round(e.totalFoCons*(o.priceFO||0)*1e3)/1e3,s=Math.round(e.totalDgoCons*(o.priceDGO||0)*1e3)/1e3;e.cost={total:Math.round((a+n+s)*1e3)/1e3,hire:a,bunker:Math.round((n+s)*1e3)/1e3,cp:t}}return e}static async mergeSpeeds(e,t={}){const o={hours:[],wps:[],days:[]},i=e.reduce((h,u)=>h+u.distance,0),a=e.reduce((h,u)=>h+u.totalHrs,0),n=e.reduce((h,u)=>h+u.wxFactor*u.totalHrs/a,0),s=e.reduce((h,u)=>h+u.cFactor*u.totalHrs/a,0),d=e.reduce((h,u)=>h+u.totalFoCons,0),r=e.reduce((h,u)=>h+u.totalDgoCons,0),l=e.reduce((h,u)=>h+u.cost.total,0),y=e.reduce((h,u)=>h+u.cost.hire,0),f=e.reduce((h,u)=>h+u.cost.bunker,0);for(const h of e){const u=h.sample.hours,I=h.sample.wps,k=h.sample.days;u.forEach(m=>{var c;((c=o.hours)==null?void 0:c.findIndex(b=>b.eta===m.eta))===-1&&o.hours.push(m)}),I.forEach(m=>{var c;((c=o.wps)==null?void 0:c.findIndex(b=>b.eta===m.eta))===-1&&o.wps.push(m)}),k.forEach(m=>{var c;((c=o==null?void 0:o.days)==null?void 0:c.findIndex(b=>b.eta===m.eta))===-1&&o.days.push(m)})}return{sample:o,etd:e.at(0).etd,eta:e.at(-1).eta,from:e.at(0).from,to:e.at(-1).to,label:"combined",distance:Math.round(i*1e4)/1e4,totalHrs:Math.round(a*1e3)/1e3,avgSpeed:Math.round(i/a*1e3)/1e3,wxFactor:Math.round(n/a*1e3)/1e3,cFactor:Math.round(s/a*1e3)/1e3,totalFoCons:Math.round(d*1e3)/1e3,totalDgoCons:Math.round(r*1e3)/1e3,cost:{total:Math.round(l*1e3)/1e3,hire:Math.round(y*1e3)/1e3,bunker:Math.round(f*1e3)/1e3}}}}T.AISImpl=G,T.AlertHelper=et,T.AlertLevel=tt,T.HifleetImpl=ct,T.LoadCondition=at,T.MyShipImpl=ut,T.MyVesselImpl=rt,T.ShipxyImpl=dt,T.SpeedHelper=C,T.SpeedLabel=ot,T.VesselTag=st,T.alertHelper=ht,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(N,x){typeof exports=="object"&&typeof module<"u"?x(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"],x):(N=typeof globalThis<"u"?globalThis:N||self,x(N["idm-plugin-rabbitmq"]={},N.got,N["@log4js-node/log4js-api"],N.moment,N["@idm-plugin/geo"],N["@idm-plugin/meteo2"],N["@idm-plugin/meteo"]))})(this,function(N,x,_,w,W,X,$){"use strict";var mt=Object.defineProperty;var yt=(N,x,_)=>x in N?mt(N,x,{enumerable:!0,configurable:!0,writable:!0,value:_}):N[x]=_;var K=(N,x,_)=>(yt(N,typeof x!="symbol"?x+"":x,_),_);let p;try{p=_.getLogger("vessel")}catch{}finally{}class G{parseStatus(e){let t,n;switch(e){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 G{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",i={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},a=await x.post(n,i).json();p==null||p.info("[%s] fetch access token from: %s - %j",t.requestId,n,a),a.error||(this.token={accessToken:a.access_token,tokenType:a.token_type,expiresIn:a.expires_in,scope:a.scope,jti:a.jti,issuedAt:w().utc().format()})}async realTimePosition(t,n={}){var h,y,l;(!this.token||w().diff(w(this.token.issuedAt),"seconds")>((h=this.token)==null?void 0:h.expiresIn)-300)&&await this.authToken(n);const i="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",a={headers:{Authorization:`${(y=this.token)==null?void 0:y.tokenType} ${(l=this.token)==null?void 0:l.accessToken}`},searchParams:{mmsi:t}};p==null||p.info("[%s] fetch realtime position from: %s - %j",n.requestId,i,a);const o=await x.get(i,a).json();if(o.code)return p==null||p.warn("[%s] fetch realtime position failed: %j",n.requestId,i,{message:o.message,status:o.status,code:o.code}),o;const s=o.data;for(const f in s)!isNaN(s[f])&&Number(s[f])!==1/0&&(s[f]=Number(s[f]));const d=w(`${s.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:s.mmsi,name:s.vesselName,imo:s.imo,callSign:s.callsign,lat:s.lat,lng:s.lon,length:s.length,width:s.width,draught:s.currDraught,sog:s.sog,cog:s.cog,hdg:s.hdg,rot:s.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta)?w.utc(s.eta).format():void 0,destination:s.dest,positionTime:d.unix(),status:s.status,labelCn:s.statusNameCn,labelEn:s.statusNameEn,method:"position",vendor:"myVessel",utc:d.utc().format()}}async trajectory(t,n,i,a,o=!0,s={}){(!this.token||w().diff(w(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(s);const d=await this.realTimePosition(t,s),r=w(n),h=w(i),y=[];for(;h.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(t,r,r.clone().add(30,"day"),d,a,y,s),r.add(30,"day");return await this.trajectoryIn30Day(t,r,h,d,a,y,s),y}async trajectoryIn30Day(t,n,i,a,o,s,d={}){var u,b,S,v,I;const r="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",h={headers:{Authorization:`${(u=this.token)==null?void 0:u.tokenType} ${(b=this.token)==null?void 0:b.accessToken}`},json:{mmsi:t,startTime:n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};p==null||p.info("[%s] fetch trajectory from: %s - %j",d.requestId,r,h);const y=await x.post(r,h).json();if(y.code)return p==null||p.warn("[%s] fetch trajectory failed: %j",d.requestId,r,{message:y.message,status:y.status,code:y.code}),y;let l=-1;const f=w(`${(v=(S=y.data)==null?void 0:S[0])==null?void 0:v.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(I=y.data)==null||I.forEach(c=>{for(const L in c)!isNaN(c[L])&&Number(c[L])!==1/0&&(c[L]=Number(c[L]));const M=w(`${c.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),H=c.status,{labelCn:m,labelEn:k}=this.parseStatus(H),j={mmsi:c.mmsi,imo:a==null?void 0:a.imo,lat:c.lat,lng:c.lon,sog:c.sog,cog:c.cog,hdg:c.hdg,draught:c.draught,status:H,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(c.eta)?w(`${c.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").utc().format():void 0,destination:c.dest,positionTime:M.unix(),labelCn:m,labelEn:k,method:"trajectory",vendor:"myVessel",utc:M.utc().format()},O=Math.floor(M.diff(f,"minute",!0)/(o||1));O!==l&&(l=O,s.push(j))}),s}}class ct extends G{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,n={}){const i="https://api.hifleet.com/position/position/get/token",a={searchParams:{mmsi:t,usertoken:this.token}},o=await x.post(i,a).json();p==null||p.info("[%s] fetch realtime position from: %s - %j",n.requestId,i,a);const s=o==null?void 0:o.list;if(!s)return p==null||p.warn("[%s] fetch realtime position failed: %j",n.requestId,i,o),o;for(const f in s)!isNaN(s[f])&&Number(s[f])!==1/0&&(s[f]=Number(s[f]));s.status=s.sp>3?0:1;const d=s.status,{labelCn:r,labelEn:h}=this.parseStatus(d),y=w(`${s.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:s.m,name:s.n,imo:s.imonumber,callSign:s.callsign,lat:Math.round(s.la/60*1e5)/1e5,lng:Math.round(s.lo/60*1e5)/1e5,length:s.l,width:s.w,draught:s.draught,sog:s.sp,cog:s.co,hdg:s.h,rot:isNaN(s.rot)?0:s.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta)?w.utc(s.eta).format():void 0,destination:s.destination,positionTime:y.unix(),utc:y.utc().format(),status:d,labelCn:r,labelEn:h,method:"position",vendor:"hifleet"}}async search(t,n={}){let i="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const a={searchParams:{keyword:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let o=await x.post(i,a).json();p==null||p.info("[%s] fetch vessel props from: %s - %j",n.requestId,i,a),o instanceof Array&&(o=o[0]);for(const d in o)!isNaN(o[d])&&Number(o[d])!==1/0&&(o[d]=Number(o[d]));const s={mmsi:o.m,name:o.n,imo:o.i,callSign:o.c,length:o.l,breadth:o.b,draught:o.dr,type:o.t};return i="https://www.hifleet.com/hifleetapi/sameShipSearch.do",o=await x.post(i,a).json(),p==null||p.info("[%s] search vessel dead weight from: %s - %j",n.requestId,i,a),o instanceof Array&&(o=o[0]),o&&(s.deadweight=Number(o.dwt)),s}async suggest(t,n={}){const i="https://www.hifleet.com/hifleetapi/getShipSuggest.do",a={searchParams:{q:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}},o=await x.post(i,a).json();p==null||p.info("[%s] suggest vessel props from: %s - %j",n.requestId,i,a);const s=[];for(const d of o)s.push({mmsi:!d.mmsi||isNaN(d.mmsi)?null:Number(d.mmsi),name:d.name,callSign:d.callsign,imo:!d.imo||isNaN(d.imo)?null:Number(d.imo),score:d._score});return s.sort((d,r)=>r.score-d.score),s}async trajectory(t,n,i,a,o=!0,s={}){var c,M,H;const d=await this.realTimePosition(t,s);let r=w(n);const h=w(i),y=w();if(o){let m=h.diff(r,"d",!0);m<0?r=h.clone().subtract(40,"d"):m<30?r.subtract(10,"d"):m<60?r.subtract(5,"d"):r=h.clone().subtract(80,"d"),m=y.diff(h,"d",!0),h.add(m>10?240:m*24,"h")}const l={searchParams:{endtime:h.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",u=await x.get(f,l).json();p==null||p.info("[%s] fetch trajectory from: %s - %j",s.requestId,f,l);let b;u&&(b=((M=(c=u.ships)==null?void 0:c.offors)==null?void 0:M.ship)||[],b.length||p==null||p.warn("[%s] fetch trajectory failed: %j",s.requestId,u));const S=[];let v=-1;const I=w(`${(H=b==null?void 0:b[0])==null?void 0:H.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const m of b){for(const F in m)!isNaN(m[F])&&Number(m[F])!==1/0&&(m[F]=Number(m[F]));const k=w(`${m.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");m.status=m.sp>4?0:1;const{labelEn:j,labelCn:O}=this.parseStatus(m.status),L={mmsi:m.m,name:m.n,imo:d==null?void 0:d.imo,lat:m.la,lng:m.lo,draught:m.draught,sog:m.sp,cog:m.co,hdg:m.hdg,positionTime:k.unix(),utc:k.utc().format(),status:m.status,labelCn:O,labelEn:j,method:"trajectory",vendor:"hifleet"},D=Math.floor(k.diff(I,"minute",!0)/(a||1));D!==v&&(v=D,S.push(L))}return S}}class dt extends G{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,n={}){const i={searchParams:{id:t,k:this.token,enc:1}},a="https://api.shipxy.com/apicall/GetSingleShip",o=await x.get(a,i).json();if(p==null||p.info("[%s] fetch realtime position from: %s - %j",n.requestId,a,i),(o==null?void 0:o.status)!==0)return o;const s=o.data[0];for(const l in s)!isNaN(s[l])&&Number(s[l])!==1/0&&(s[l]=Number(s[l]));const{labelCn:d,labelEn:r}=await this.parseStatus(s.navistat),h=w.unix(s.lasttime);return{mmsi:s.ShipID,name:s.name,imo:s.imo,callSign:s.callsign,lat:Math.round(s.lat/1e6*1e5)/1e5,lng:Math.round(s.lon/1e6*1e5)/1e5,length:Math.round(s.length/10*100)/100,width:Math.round(s.width/10*100)/100,draught:Math.round(s.draught/1e3*100)/100,sog:Math.round(s.sog*3600/1e3/1852*100)/100,cog:Math.round(s.cog/100*100)/100,hdg:Math.round(s.hdg/100*100)/100,rot:Math.round(s.rot/100*100)/100,positionTime:s.lasttime,utc:h.utc().format(),status:s.navistat,labelEn:r,labelCn:d,method:"position",vendor:"shipxy"}}async trajectory(t,n,i,a,o=!0,s={}){var I;const d=await this.realTimePosition(t,s),r=w(n),h=w(i),y="https://api.shipxy.com/apicall/GetShipTrack",l={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:r.unix(),etm:h.unix()}},f=await x.get(y,l).json();if(p==null||p.info("[%s] fetch trajectory from: %s - %j",s.requestId,y,l),(f==null?void 0:f.status)!==0)return f;const u=f==null?void 0:f.points,b=[],S=w.unix((I=u[0])==null?void 0:I.utc);let v=-1;for(const c of u){const M=w.unix(c.utc),H={imo:d==null?void 0:d.imo,mmsi:t,sog:Math.round(c.sog*3600/1e3/1852*100)/100,cog:Math.round(c.cog/100*100)/100,lat:Math.round(c.lat/1e6*1e5)/1e5,lng:Math.round(c.lon/1e6*1e5)/1e5,positionTime:M.unix(),utc:M.utc().format(),method:"trajectory",vendor:"shipxy"},m=Math.floor(M.diff(S,"minute",!0)/(a||1));m!==v&&(v=m,b.push(H))}return b}}class ut extends G{constructor(t){super();K(this,"token");this.token=t}async getShipId(t,n={}){const i={headers:{appKey:this.token},json:{mmsiList:t}},a="https://api3.myships.com/sp/ships/getShipIdByMMSI",o=await x.post(a,i).json();return p==null||p.info("[%s] fetch ship id from: %s - %j",n.requestId,a,i),o.code!=="0"?o:o.data[0].shipId}async getShipInfo(t,n={}){const i={headers:{appKey:this.token},json:{shipId:t}},a="https://api3.myships.com/sp/ships/aissta",o=await x.post(a,i).json();if(p==null||p.info("[%s] fetch ship info from: %s - %j",n.requestId,a,i),o.code!=="0")return o;const s=o.data;let d=s.imo;return t==="407170"&&(d="9198379",p==null||p.warn("[%s] ship(%s) imo error: %s, should be %s",n.requestId,t,s.imo,d)),{mmsi:s.mmsi,name:s.shipnameEn,imo:d,callSign:s.callSign,length:s.length,width:s.breadth,draught:(s.draught||100)/10}}async realTimePosition(t,n={}){const i=await this.getShipId(t,n),a=await this.getShipInfo(i,n),o={headers:{appKey:this.token},json:{shipId:i}},s="https://api3.myships.com/sp/ships/position/latest",d=await x.post(s,o).json();p==null||p.info("[%s] fetch realtime position from: %s - %j",n.requestId,s,o);const r=d.data[0];for(const u in r)!isNaN(r[u])&&Number(r[u])!==1/0&&(r[u]=Number(r[u]));const{labelCn:h,labelEn:y}=await this.parseStatus(r.aisNavStatus),l=w.unix(r.posTime);return{...a,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:l.utc().format(),status:r.aisNavStatus,labelEn:y,labelCn:h,method:"position",vendor:"myship"}}async trajectory(t,n,i,a,o=!0,s={}){const d=w(n),r=w(i),h=await this.getShipId(t),y=await this.getShipInfo(h),l=[];for(;r.diff(d,"day",!0)>30;)await this.trajectoryIn30Day(h,d.unix(),d.add(30,"day").unix(),y,t,a,l);return await this.trajectoryIn30Day(h,d.unix(),r.unix(),y,t,a,l),l}async trajectoryIn30Day(t,n,i,a,o,s,d,r={}){var S;const h={headers:{appKey:this.token},json:{shipId:t,startTime:n,endTime:i}},y="https://api3.myships.com/sp/ships/position/history",l=await x.post(y,h).json();if(p==null||p.info("[%s] fetch trajectory from: %s - %j",r.requestId,y,h),l.code!=="0")return p==null||p.warn("[%s] invoke myship trajectory failed: %j",r.requestId,l),l;const f=l.data;for(const v in f)!isNaN(f[v])&&Number(f[v])!==1/0&&(f[v]=Number(f[v]));const u=w.unix((S=f[0])==null?void 0:S.posTime);let b=-1;for(const v of f){const I=w.unix(v.posTime),c={imo:a==null?void 0:a.imo,mmsi:o,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:I.unix(),utc:I.utc().format(),method:"trajectory",vendor:"myship"},M=Math.floor(I.diff(u,"minute",!0)/(s||1));M!==b&&(b=M,d.push(c))}return d}}let V;try{V=_.getLogger("vessel")}catch{}finally{}var tt=(Y=>(Y.NOTICE="NOTICE",Y.WARN="WARN",Y.HEAVY="HEAVY",Y.SEVERE="SEVERE",Y.ERROR="ERROR",Y.FATAL="FATAL",Y))(tt||{});class et{parsePrinciple(e,t={}){var s,d,r;V==null||V.info("[%s] parse rule: %s",t.requestId,e);const n=new RegExp("(?<=\\[)(.+)(?=])","g"),i=e.match(n)?(s=e.match(n))==null?void 0:s[0]:void 0,a=i==null?void 0:i.split(";");if(!a)return;const o={};for(let h=0;h<(a==null?void 0:a.length);h++){const y=(r=(d=a[h].match(n))==null?void 0:d[0])==null?void 0:r.split("],");if(h===0&&!y)o.scope=a[0];else if(y)for(let l=0,f=y.length;l<f;l++){const u=this.parseRule(y[l]);u&&(o[u.level]?u.key?o[u.level][u==null?void 0:u.key]=u:o[u.level]=u:u.key?o[u.level]={[u==null?void 0:u.key]:u}:o[u.level]=u)}}return o}parseRule(e,t={}){var o;V==null||V.info("[%s] parse rule: %s",t.requestId,e),e=e.startsWith("[")?e:`[${e}`,e=e.endsWith("]")?e:`${e}]`;const n=new RegExp("(?<=\\[)(.+?)(?=])","g"),i=(o=e==null?void 0:e.match(n))==null?void 0:o[0],a=i==null?void 0:i.split(",");if(a)return{operator:a[0],number:Number.isNaN(Number(a[1]))?a[1]:Number(a[1]),level:a[2],time:Number(a[3]),key:a[4]}}checkWeather(e,t,n={}){var u,b,S,v,I,c,M,H,m,k,j,O,L,D,F;let i=0,a=0,o=0,s=0;const d=Math.round(((b=(u=t==null?void 0:t.SEVERE)==null?void 0:u.sigWave)==null?void 0:b.number)*1.6*100)/100,r=(v=(S=t==null?void 0:t.SEVERE)==null?void 0:S.sigWave)==null?void 0:v.number,h=(c=(I=t==null?void 0:t.HEAVY)==null?void 0:I.sigWave)==null?void 0:c.number,y=Math.round((((H=(M=t==null?void 0:t.SEVERE)==null?void 0:M.wind)==null?void 0:H.number)+2)*100)/100,l=(k=(m=t==null?void 0:t.SEVERE)==null?void 0:m.wind)==null?void 0:k.number,f=(O=(j=t==null?void 0:t.HEAVY)==null?void 0:j.wind)==null?void 0:O.number;for(let B=0;B<(e==null?void 0:e.length);B++){const E=e[B],A=(D=(L=E==null?void 0:E.meteo)==null?void 0:L.wave)==null?void 0:D.sig,R=(F=E==null?void 0:E.meteo)==null?void 0:F.wind,Z=B?w(E.eta).diff(w(e[B-1].eta),"hour",!0):0;s=Z>s?Z:s,V==null||V.info("[%s] check sig.wave: %j",n.requestId,{...A,dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:h}),(A==null?void 0:A.height)>=d?E.isDangerous=!0:(A==null?void 0:A.height)>=r?E.isSevere=!0:(A==null?void 0:A.height)>=h&&(E.isHeavy=!0),V==null||V.info("[%s] check wind: %j",n.requestId,{...R,dgThd4Wd:y,svThd4Wd:l,hvThd4Wd:f}),(R==null?void 0:R.scale)>=y?(E.isDangerous=!0,delete E.isSevere,delete E.isHeavy):(R==null?void 0:R.scale)>l?(E.isDangerous||(E.isSevere=!0),delete E.isHeavy):(R==null?void 0:R.scale)===f&&!E.isDangerous&&!E.isSevere&&(E.isHeavy=!0),i+=E.isDangerous?Z:0,a+=E.isSevere?Z:0,o+=E.isHeavy?Z:0}return i=Math.round(i*100)/100,a=Math.round(a*100)/100,o=Math.round(o*100)/100,s=Math.round(s),{sample:e,dangerous:i,severe:a,heavy:o,step:s<3?3:s,wind:{dgThd4Wd:y,svThd4Wd:l,hvThd4Wd:f},sig:{dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:h}}}}const ht=new et;let g;try{g=_.getLogger("vessel")}catch{}finally{}const lt=new X.MeteoHelper2("",!0);var st=(Y=>(Y.common="common",Y.container="container",Y.tugs="tugs",Y))(st||{}),at=(Y=>(Y.Ballast="Ballast",Y.Laden="Laden",Y))(at||{}),nt=(Y=>(Y.Cp="CP",Y.Perf="Basis",Y.Instruct="Other",Y))(nt||{});class C{static blockCoefficient(e,t,n,i){let a=Math.round(e/(t*n*i)*100)/100;a=a<.55?.55:a>.85?.85:a;const o=[.55,.6,.65,.7,.75,.8,.85],s=o.map(d=>Math.abs(d-a));return o[s.indexOf(Math.min(...s))]}static froudeNumber(e,t,n=9.8){let i=Math.round(Math.sqrt(e*e/(n*t))*100)/100;return i=i<.05?.05:i>.3?.3:i,i}static amendFactor(e,t,n){const i={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.4,-10.6,-9.5],.8:[2.6,-13.1,-15.1],.85:[3.1,-18.7,28]};let o={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.6,-12.5,-13.5],.8:[3,-16.3,-21.6],.85:[3.4,-20.9,31.8]}[e];return n==="Laden"&&(o=i[e]),o[0]+o[1]*t+o[2]*Math.pow(t,2)}static directionFactor(e,t=0){let n;return e>30&&e<=60?n=(1.7-.03*Math.pow(t-4,2))/2:e>60&&e<=150?n=(.9-.06*Math.pow(t-6,2))/2:e>150&&e<=180?n=(.4-.03*Math.pow(t-8,2))/2:n=1,Math.round(n*1e5)/1e5}static vesselTagFactor(e,t,n,i=0){i=i>6?i-.9*(i-6):i;let a;return n==="container"?a=.7*i+Math.pow(i,6.5)/(22*Math.pow(e,2/3)):t==="Ballast"?a=.7*i+Math.pow(i,6.5)/(2.7*Math.pow(e,2/3)):a=.5*i+Math.pow(i,6.5)/(2.7*Math.pow(e,2/3)),a}static waveHeightFactor(e,t){e=e<0?.2:e,e=e>6?e-.9*(e-6):e,e=e>9?9:e;let n;return t>30&&t<=60?n=-.6:t>60&&t<=90?n=-.4:t>90&&t<=120?n=e<3?.4:-.3:t>120&&t<=150?n=e<3?.6:-.5:t>150&&t<=180?n=e<3?.7:-.6:n=-.7,Math.round(n*(.144*Math.pow(e,2)+.178*e)*1e4)/1e4}static assembleProperties(e,t,n,i){var l;const a=e.lbp??e.length??e.lengthOverall??198.9642,o=e.draught??8,s=e.breadthMoulded??e.breadth??e.breadthExtreme??32.4572,d=e.deadweight??67035.7773,r=((l=e==null?void 0:e.type)==null?void 0:l.toLowerCase())||"common";return{tag:r.indexOf("container")>-1?"container":r.indexOf("tugs")>-1?"tugs":"common",lbp:a,loadCondition:t,draught:o,breadthMoulded:s,displacement:Math.round((d/1.025+o*s*a*.7)*1e4)/1e4,speed:Math.round((n??14.1382)*1852/3600*1e4)/1e4,bearing:i||90}}static async speedLoseAt(e,t,n,i="",a=2,o=!0,s=!1,d={}){let r;if(t.velocity&&s&&(e.speed=W.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),o){let h;if(d.meteo2)try{const u=await lt.spotForecast(t.lat,t.lng,n.utc().format(),!1,!1,!0,d),[b]=$.Meteo2Assist.pickHourly(u,n);h=$.Meteo2Assist.toLegacy(b)}catch(u){g.warn("[%s] meteo2 spot(%j) forecast failed: %s",d.requestId,{...t,eta:n.utc().format()},u)}else h=await X.MeteoHelper.queryPointFactor(t.lng,t.lat,n.valueOf(),"wind,wave,current,watertemp",i,d);const y=C.weatherFactor(e,h),l=C.currentFactor(e.bearing,h==null?void 0:h.current,a),f=Math.round((e.speed*1.943844+y+l)*100)/100;r={meteo:{...h},wxFactor:y,cFactor:l,speed:t.velocity&&s?t.velocity:f<0?1:f,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&&s?t.velocity:Math.round((e.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(e,t,n,i,a,o,s="",d=!0,r=!1,h={}){t.utc();const y=t.clone().add(14,"days"),l=[],f=[];let u=0,b=0,S,v;for(let I=0;I<o.length-1;I++){let c=o[I];c.distanceFromStart=Math.round((a+b)*1e4)/1e4;const M=o[I+1];if(e.bearing=W.LaneHelper.calculateBearing(c,M,!M.gcToPrevious),c.bearing=e.bearing,c.suspend&&r){c.eta=c.eta||t.format("YYYY-MM-DDTHH:mm[Z]"),c.elapsed=c.elapsed??0;const k=c.suspend-c.elapsed;if(i-u>k)i=i-u-k,t.add(k,"hour"),c.elapsed=c.suspend;else{const j=i-u;c.elapsed+=j,t.add(j,"hour"),i=0}if(g==null||g.info(`[%s] suspend ${c.elapsed} hours at %j, and remain ${i} hours need to go...`,h.requestId,c),i===0)return c.distanceFromPrevious=b,{etd:t,from:v||c,to:c,next:o.filter(j=>j),wps:l,days:f}}else c.suspend=0;d=t.isAfter(y)?!1:d,c=await C.speedLoseAt(e,c,t,s,0,d,r,h),v=v||c,c.important&&l.push(c),t.isSameOrAfter(n)&&(f.push(c),n.add(24,"hour"));const H=W.LaneHelper.calculateDistance(c,M,!M.gcToPrevious);let m=Math.ceil(H/v.speed*1e4)/1e4;if(u+m<i){if(u+=m,t.add(m,"hour"),delete o[I],g==null||g.debug(`[%s] go to %j from %j with ${H}nm, and cost ${m} hours`,h.requestId,{lat:M.lat,lng:M.lng},{lat:v.lat,lng:v.lng,etd:v.etd}),b+=H,o.filter(k=>k).length<=1){S=M,S.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),S.distanceFromPrevious=H,S.distanceFromStart=Math.round((a+b)*1e4)/1e4,l.push(S),delete o[I+1];break}}else{m=i-u,t.add(m,"hour");const k=W.LngLatHelper.roundPrecision(v.speed*m,4);S=W.LaneHelper.calculateCoordinate(c,e.bearing,k,"nauticalmiles",!M.gcToPrevious),S.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),o[I]=S,g==null||g.debug(`[%s] go to %j from %j with ${k}nm, and cost ${m} hours`,h.requestId,{lat:S.lat,lng:S.lng},{lat:c.lat,lng:c.lng,etd:c.etd}),b+=k,S.distanceFromPrevious=Math.round(b*1e4)/1e4,S.distanceFromStart=Math.round((a+b)*1e4)/1e4;break}}return{etd:t,from:v,to:S,next:o.filter(I=>I),wps:l,days:f}}static currentFactor(e,t,n=0){const i=(e-(t==null?void 0:t.degree)||0)/180*Math.PI;if(Math.abs(i)===Math.PI/2)return 0;let a=((t==null?void 0:t.kts)||0)*Math.cos(i);return n&2?a=Math.ceil(a*100)/100:n&1?a=Math.floor(a*100)/100:a=Math.round(a*100)/100,Math.abs(a)>5?0:a}static weatherFactor(e,t){var y,l,f,u,b,S,v;g==null||g.debug("calculate weather factor via: %j",{...e,...t});const n=C.blockCoefficient(e.displacement,e.lbp,e.breadthMoulded,e.draught),i=C.froudeNumber(e.speed,e.lbp),a=C.amendFactor(n,i,e.loadCondition);let o=Math.abs(e.bearing%360-(((y=t==null?void 0:t.wind)==null?void 0:y.degree)%360||0));o=o>180?360-o:o;const s=C.directionFactor(o,(l=t==null?void 0:t.wind)==null?void 0:l.scale),d=C.vesselTagFactor(e.displacement,e.loadCondition,e.tag,(f=t==null?void 0:t.wind)==null?void 0:f.scale);let r=s*a*d/100*e.speed;r=Math.round(r*1.943844*1e4)/1e4*-1,e.tag==="tugs"&&Math.abs(r)>1&&(r=r/(Math.abs(Math.round(r))+1)),g==null||g.debug("wind wx factor = %d",r),o=Math.abs(e.bearing%360-(((b=(u=t==null?void 0:t.wave)==null?void 0:u.sig)==null?void 0:b.degree)%360||0));const h=C.waveHeightFactor(((v=(S=t==null?void 0:t.wave)==null?void 0:S.sig)==null?void 0:v.height)??1,o);return g==null||g.debug("wave wx factor = %d",h),r=r*.4+h,g==null||g.debug("weather factor = %d",r),r=Math.abs(r)>4?4*(Math.abs(r)/r)+Math.abs(r)/r*(Math.abs(r)-4)*.1:r,Math.round((r||0)*100)/100}static async analyseInstant(e,t,n,i,a,o="",s=0,d=!0,r=!1,h={}){var Z,z,U,Q,J;const y=w().valueOf();e.lng=W.LngLatHelper.convertToStdLng(e.lng);const{route:l,waypoints:f}=a.points,u=W.LaneHelper.calculateSubRoute(e,l);if(((Z=u[0])==null?void 0:Z.length)<=1)return;const{v0:b,label:S}=e.sog?{v0:e.sog,label:"Other"}:{v0:i.speed,label:"CP"},v=C.assembleProperties(n,i.loadCondition,b,0),I=f.length?W.LaneHelper.calculateSubWaypoints(e,f):[];I.forEach(T=>T.important=!0);const c={from:{...e},route:u,waypoints:I,v0:b,label:S},M={hours:[],days:[],wps:[]};s||(W.LaneHelper.calculateRouteDistance(u)/i.speed<=72?s=3:s=6);let H=W.LaneHelper.simplifyRouteToCoordinates(u,I,0),m=0,k=0,j=0,O=0;t=w(t).utc();const L=t.clone();for(;H.length>0;){const T=s-t.hour()%s,q=Math.ceil(t.clone().add(T,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,P=await C.speedLoseInHoursStep(v,t,L,q,m,H,o,d,r,h);(z=P.from)!=null&&z.speed&&(M.hours.push(P.from),M.wps.push(...P.wps),M.days.push(...P.days)),H=P==null?void 0:P.next,H.length||M.hours.push(P==null?void 0:P.to),m+=Math.round((((U=P==null?void 0:P.to)==null?void 0:U.distanceFromPrevious)??0)*1e4)/1e4}const D=M.hours;for(let T=0;T<D.length-1;T++){const q=w(D[T+1].eta).diff(D[T].etd,"hour",!0)||1;k+=(D[T].wxFactor||0)*q,j+=(D[T].cFactor||0)*q,O+=q}(Q=M.wps)==null||Q.forEach((T,q)=>{if(q){const P=M.wps[q-1],ft=T.distanceFromStart-P.distanceFromStart,ot=w(T.eta).diff(w(P.etd),"h",!0);if(ot<1)T.avgSpd=P.speed;else{T.avgSpd=Math.round(ft/ot*100)/100;const it=Math.round((P.speed+T.speed)/2*100)/100;T.avgSpd=T.avgSpd>it?it:T.avgSpd}}}),c.sample=M;const F=M.hours.at(0),B=M.hours.at(-1);c.distance=Math.round(B.distanceFromStart*1e4)/1e4,c.etd=w(F.eta).utc().format(),c.eta=w(B.eta).utc().format(),c.wxFactor=Math.round(k/O*1e4)/1e4,c.cFactor=Math.round(j/O*1e4)/1e4,c.avgSpeed=Math.round(B.distanceFromStart/O*1e4)/1e4,c.totalHrs=Math.round(O*1e4)/1e4,c.totalFoCons=Math.round((i==null?void 0:i.fo)/24*c.totalHrs*1e3)/1e3,c.totalDgoCons=Math.round((i==null?void 0:i.dgo)/24*c.totalHrs*1e3)/1e3;const A=w().valueOf()-y,R=((J=M==null?void 0:M.hours)==null?void 0:J.length)||1;return g==null||g.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",h==null?void 0:h.requestId,A,R,Math.round(A/R*1e3)/1e3),c}static async analyseInstantWithThreshed(e,t,n,i,a,o,s,d="",r=3,h=!0,y=!1,l={}){var Z,z,U,Q;const f=w().valueOf();e.lng=W.LngLatHelper.convertToStdLng(e.lng);const{v0:u,label:b}=e.sog?{v0:e.sog,label:"Other"}:{v0:a.speed,label:"CP"},S=C.assembleProperties(i,a.loadCondition,u,0),v=W.LaneHelper.calculateSubRoute(e,o);if(((Z=v[0])==null?void 0:Z.length)<=1)return;const I=s.length?W.LaneHelper.calculateSubWaypoints(e,s):[];I.forEach(J=>J.important=!0);let c=W.LaneHelper.simplifyRouteToCoordinates(v,I,0),M=0,H=0,m=0,k=0;const j={hours:[],wps:[],days:[]};t=w(t).utc();const O=t.clone();for(;c.length>0;){const J=r-t.hour()%r;let T=Math.ceil(t.clone().add(J,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;T=t.clone().add(T,"h").isSameOrAfter(n)?n.diff(t,"h",!0)*1e4/1e4:T;const q=await C.speedLoseInHoursStep(S,t,O,T,M,c,d,h,y,l);if((z=q.from)!=null&&z.speed&&(j.hours.push(q.from),q!=null&&q.wps&&j.wps.push(...q.wps),j.days.push(...q.days)),c=q==null?void 0:q.next,c.length||j.hours.push(q==null?void 0:q.to),M+=Math.round((((U=q==null?void 0:q.to)==null?void 0:U.distanceFromPrevious)??0)*1e4)/1e4,!T)break}const L=j.hours;for(let J=0;J<L.length-1;J++){const T=w(L[J+1].eta).diff(L[J].etd,"hour",!0);H+=L[J].wxFactor*T,m+=L[J].cFactor*T,k+=T}const D=j.hours.at(0),F=j.hours.at(-1),B={sample:j,distance:Math.round(((F==null?void 0:F.distanceFromStart)||0)*1e4)/1e4,etd:w(D.eta).utc().format(),eta:w(F==null?void 0:F.eta).utc().format(),wxFactor:Math.round(H/k*1e4)/1e4,cFactor:Math.round(m/k*1e4)/1e4,avgSpeed:Math.round(((F==null?void 0:F.distanceFromStart)||0)/k*1e4)/1e4,totalHrs:Math.round(k*1e4)/1e4,totalFoCons:Math.round((a==null?void 0:a.fo)/24*k*1e3)/1e3,totalDgoCons:Math.round((a==null?void 0:a.dgo)/24*k*1e3)/1e3,from:D,to:F,route:v,waypoints:I,v0:u,label:b},A=w().valueOf()-f,R=((Q=j==null?void 0:j.hours)==null?void 0:Q.length)||1;return g==null||g.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",l==null?void 0:l.requestId,A,R,Math.round(A/R*1e3)/1e3),B}static async analyseCost(e,t,n,i,a={}){var v,I;const o=w().valueOf(),s=[];a.meteo2=!0,e.speedStep=e.speedStep||3,e.alterStep=e.alterStep??1;const d=W.LaneHelper.calculateRouteDistance(i.route);let r=0;n.forEach(c=>{const M=Math.ceil(d/c.speed/24);r=r<M?M:r}),r=r*1.3;const h=w.utc(e.etd).add(r??14,"day");let y=1;for(const c of n){const M=JSON.parse(JSON.stringify(i.route)),H=JSON.parse(JSON.stringify(i.waypoints)),m=await C.analyseInstantWithThreshed({lat:e.lat,lng:e.lng},e.etd,h,t,c,M,H,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,a);m&&(await C.calculateCost(m,c,e,a),s.push(m),g==null||g.info("[%s][L%d-%d] analyse from %s to %s cost: %j",a.requestId,1,y,e.etd,h.format(),{cost:m.cost.total,distance:m.distance,hours:m.totalHrs,cp:`${c.speed}/${c.fo}/${c.dgo}`})),y++}s.sort((c,M)=>c.cost.total-M.cost.total);const l=s.at(0),f=s.at(1),u=[];if(u.push({combined:!1,speeds:[l],cost:(v=l.cost)==null?void 0:v.total}),f){const c=l.cost.cp,M=f.cost.cp,H=w(l.eta),m=w(l.etd),k=H.diff(m,"days",!0);let j=Math.ceil(k/2);j=j>7?7:j<e.alterStep?e.alterStep:j;let O=2,L={combined:!1,speeds:[f],cost:(I=f.cost)==null?void 0:I.total},D;for(;j>=e.alterStep;){const F=await C.combinedAnalyse(e,t,h,[c,M],i,j,{...a,level:O});if(L.cost>F.cost?D?(D==null?void 0:D.cost)>F.cost&&(D=F):(D=L,L=F):(!D||(D==null?void 0:D.cost)>F.cost)&&(D=F),j<=e.alterStep)break;j=Math.ceil(j/2),O+=1}u.push(L),D&&u.push(D)}const S=w().valueOf()-o;return g==null||g.info("[%s] analyse elapsed: %d ms",a==null?void 0:a.requestId,S),u.sort((c,M)=>c.cost-M.cost)}static async combinedAnalyse(e,t,n,i,a,o,s={}){s.counter=1,g==null||g.info("[%s][L%d] analyse with alternate cp in every %d days",s.requestId,s.level,o);const d=await C.alternateAnalyse(e,t,n,i,0,a,o,s),r=d.reduce((l,f)=>l+f.cost.total,0);g==null||g.info("[%s][L%d] cost with cpa/cpb turn: %d",s.requestId,s.level,r);const h=await C.alternateAnalyse(e,t,n,i,1,a,o,s),y=h.reduce((l,f)=>l+f.cost.total,0);return g==null||g.info("[%s][L%d] cost with cpb/cpa turn: %d",s.requestId,s.level,y),r<y?{combined:!0,cost:Math.round(r*1e3)/1e3,speeds:d,step:o}:{combined:!0,cost:Math.round(y*1e3)/1e3,speeds:h,step:o}}static async alternateAnalyse(e,t,n,i,a,o,s,d={}){var l,f;let r=w.utc(e.etd);const h={lat:e.lat,lng:e.lng},y=[];for(;r.isBefore(n);){const u=r.clone().utc().add(s,"day"),b=JSON.parse(JSON.stringify(o.route)),S=JSON.parse(JSON.stringify(o.waypoints)),v=i[a],I=await C.analyseInstantWithThreshed(h,r.format(),u,t,v,b,S,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,d);I&&(await C.calculateCost(I,v,e,d),g==null||g.info("[%s][L%d-%d] analyse from %s to %s cost: %j",d.requestId,d.level,d.counter,r.utc().format(),u.utc().format(),{cost:I.cost.total,distance:I.distance,hours:I.totalHrs,cp:`${v.speed}/${v.fo}/${v.dgo}`})),d.counter=d.counter+1;const c=(f=(l=I==null?void 0:I.sample)==null?void 0:l.hours)==null?void 0:f.at(-1);if(c)h.lat=c.lat,h.lng=c.lng,r=w(c.eta),y.push(I),a=a?0:1;else break}return y}static async calculateCost(e,t,n,i={}){if(e){const a=Math.round(e.totalHrs/24*(n.dailyHire||0)*(1-(n.addComm||0))*1e3)/1e3,o=Math.round(e.totalFoCons*(n.priceFO||0)*1e3)/1e3,s=Math.round(e.totalDgoCons*(n.priceDGO||0)*1e3)/1e3;e.cost={total:Math.round((a+o+s)*1e3)/1e3,hire:a,bunker:Math.round((o+s)*1e3)/1e3,cp:t}}return e}static async mergeSpeeds(e,t={}){var f;const n={hours:[],wps:[],days:[]},i=e.reduce((u,b)=>u+b.distance,0),a=e.reduce((u,b)=>u+b.totalHrs,0),o=e.reduce((u,b)=>u+b.wxFactor*b.totalHrs/a,0),s=e.reduce((u,b)=>u+b.cFactor*b.totalHrs/a,0),d=e.reduce((u,b)=>u+b.totalFoCons,0),r=e.reduce((u,b)=>u+b.totalDgoCons,0),h=e.reduce((u,b)=>u+b.cost.total,0),y=e.reduce((u,b)=>u+b.cost.hire,0),l=e.reduce((u,b)=>u+b.cost.bunker,0);for(const u of e){const b=u.sample.hours,S=b.at(0);S.cp=u.cost.cp;const v=u.sample.wps,I=u.sample.days;b.forEach(M=>{var m;((m=n.hours)==null?void 0:m.findIndex(k=>k.eta===M.eta))===-1&&n.hours.push(M)}),v.forEach(M=>{var m;((m=n.wps)==null?void 0:m.findIndex(k=>k.eta===M.eta))===-1&&n.wps.push(M)}),I.forEach(M=>{var m;((m=n==null?void 0:n.days)==null?void 0:m.findIndex(k=>k.eta===M.eta))===-1&&n.days.push(M)});const c=(f=n.wps)==null?void 0:f.findIndex(M=>M.eta===S.eta);c===-1?n.wps.push(S):n.wps[c]=S}return{sample:n,etd:e.at(0).etd,eta:e.at(-1).eta,from:e.at(0).from,to:e.at(-1).to,label:"combined",distance:Math.round(i*1e4)/1e4,totalHrs:Math.round(a*1e3)/1e3,avgSpeed:Math.round(i/a*1e3)/1e3,wxFactor:Math.round(o/a*1e3)/1e3,cFactor:Math.round(s/a*1e3)/1e3,totalFoCons:Math.round(d*1e3)/1e3,totalDgoCons:Math.round(r*1e3)/1e3,cost:{total:Math.round(h*1e3)/1e3,hire:Math.round(y*1e3)/1e3,bunker:Math.round(l*1e3)/1e3}}}}N.AISImpl=G,N.AlertHelper=et,N.AlertLevel=tt,N.HifleetImpl=ct,N.LoadCondition=at,N.MyShipImpl=ut,N.MyVesselImpl=rt,N.ShipxyImpl=dt,N.SpeedHelper=C,N.SpeedLabel=nt,N.VesselTag=st,N.alertHelper=ht,Object.defineProperty(N,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -67,6 +67,7 @@ export interface SpeedProps extends CostProps {
|
|
|
67
67
|
usePerfSpeed?: boolean;
|
|
68
68
|
useRouteParam?: boolean;
|
|
69
69
|
useMeteo?: boolean;
|
|
70
|
+
alterStep?: number;
|
|
70
71
|
lat?: number;
|
|
71
72
|
lng?: number;
|
|
72
73
|
etd?: string;
|
|
@@ -273,7 +274,6 @@ export declare class SpeedHelper {
|
|
|
273
274
|
}, options?: {
|
|
274
275
|
requestId?: string;
|
|
275
276
|
meteo2?: boolean;
|
|
276
|
-
maxDays?: number;
|
|
277
277
|
}): Promise<any[]>;
|
|
278
278
|
/**
|
|
279
279
|
* 按步长多次减半,分别用7,4,2,1天步长及cpa,cpb交替计算各种组合下的成本
|
|
@@ -297,6 +297,7 @@ export declare class SpeedHelper {
|
|
|
297
297
|
combined: boolean;
|
|
298
298
|
cost: number;
|
|
299
299
|
speeds: any[];
|
|
300
|
+
step: number;
|
|
300
301
|
}>;
|
|
301
302
|
/**
|
|
302
303
|
* 基于cp索引,交替计算指定步长下的成本
|