@idm-plugin/vessel 2.3.4 → 2.3.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/index.js +89 -89
- package/dist/index.umd.cjs +1 -1
- package/dist/speed/src/index.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -277,11 +277,11 @@ class Ft extends st {
|
|
|
277
277
|
if (l.code)
|
|
278
278
|
return f == null || f.warn("[%s] fetch trajectory failed: %j", r.requestId, c, { message: l.message, status: l.status, code: l.code }), l;
|
|
279
279
|
let y = -1;
|
|
280
|
-
const
|
|
280
|
+
const g = w(`${(p = (I = l.data) == null ? void 0 : I[0]) == null ? void 0 : p.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
281
281
|
return (v = l.data) == null || v.forEach((d) => {
|
|
282
282
|
for (const P in d)
|
|
283
283
|
!isNaN(d[P]) && Number(d[P]) !== 1 / 0 && (d[P] = Number(d[P]));
|
|
284
|
-
const
|
|
284
|
+
const b = w(`${d.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), m = d.status, { labelCn: h, labelEn: k } = this.parseStatus(m), S = {
|
|
285
285
|
mmsi: d.mmsi,
|
|
286
286
|
imo: o == null ? void 0 : o.imo,
|
|
287
287
|
lat: d.lat,
|
|
@@ -293,13 +293,13 @@ class Ft extends st {
|
|
|
293
293
|
status: m,
|
|
294
294
|
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(d.eta) ? w(`${d.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00").utc().format() : void 0,
|
|
295
295
|
destination: d.dest,
|
|
296
|
-
positionTime:
|
|
296
|
+
positionTime: b.unix(),
|
|
297
297
|
labelCn: h,
|
|
298
298
|
labelEn: k,
|
|
299
299
|
method: "trajectory",
|
|
300
300
|
vendor: "myVessel",
|
|
301
|
-
utc:
|
|
302
|
-
}, D = Math.floor(
|
|
301
|
+
utc: b.utc().format()
|
|
302
|
+
}, D = Math.floor(b.diff(g, "minute", !0) / (n || 1));
|
|
303
303
|
D !== y && (y = D, e.push(S));
|
|
304
304
|
}), e;
|
|
305
305
|
}
|
|
@@ -321,8 +321,8 @@ class Et extends st {
|
|
|
321
321
|
const e = n == null ? void 0 : n.list;
|
|
322
322
|
if (!e)
|
|
323
323
|
return f == null || f.warn("[%s] fetch realtime position failed: %j", a.requestId, i, n), n;
|
|
324
|
-
for (const
|
|
325
|
-
!isNaN(e[
|
|
324
|
+
for (const g in e)
|
|
325
|
+
!isNaN(e[g]) && Number(e[g]) !== 1 / 0 && (e[g] = Number(e[g]));
|
|
326
326
|
e.status = e.sp > 3 ? 0 : 1;
|
|
327
327
|
const r = e.status, { labelCn: c, labelEn: u } = this.parseStatus(r), l = w(`${e.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
328
328
|
return {
|
|
@@ -406,7 +406,7 @@ class Et extends st {
|
|
|
406
406
|
return e.sort((r, c) => c.score - r.score), e;
|
|
407
407
|
}
|
|
408
408
|
async trajectory(t, a, i, o, n = !0, e = {}) {
|
|
409
|
-
var d,
|
|
409
|
+
var d, b, m;
|
|
410
410
|
const r = await this.realTimePosition(t, e);
|
|
411
411
|
let c = w(a);
|
|
412
412
|
const u = w(i), l = w();
|
|
@@ -421,10 +421,10 @@ class Et extends st {
|
|
|
421
421
|
mmsi: t,
|
|
422
422
|
usertoken: this.token
|
|
423
423
|
}
|
|
424
|
-
},
|
|
425
|
-
f == null || f.info("[%s] fetch trajectory from: %s - %j", e.requestId,
|
|
424
|
+
}, g = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", M = await L.get(g, y).json();
|
|
425
|
+
f == null || f.info("[%s] fetch trajectory from: %s - %j", e.requestId, g, y);
|
|
426
426
|
let j;
|
|
427
|
-
M && (j = ((
|
|
427
|
+
M && (j = ((b = (d = M.ships) == null ? void 0 : d.offors) == null ? void 0 : b.ship) || [], j.length || f == null || f.warn("[%s] fetch trajectory failed: %j", e.requestId, M));
|
|
428
428
|
const I = [];
|
|
429
429
|
let p = -1;
|
|
430
430
|
const v = w(`${(m = j == null ? void 0 : j[0]) == null ? void 0 : m.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
@@ -510,24 +510,24 @@ class Nt extends st {
|
|
|
510
510
|
btm: c.unix(),
|
|
511
511
|
etm: u.unix()
|
|
512
512
|
}
|
|
513
|
-
},
|
|
514
|
-
if (f == null || f.info("[%s] fetch trajectory from: %s - %j", e.requestId, l, y), (
|
|
515
|
-
return
|
|
516
|
-
const M =
|
|
513
|
+
}, g = await L.get(l, y).json();
|
|
514
|
+
if (f == null || f.info("[%s] fetch trajectory from: %s - %j", e.requestId, l, y), (g == null ? void 0 : g.status) !== 0)
|
|
515
|
+
return g;
|
|
516
|
+
const M = g == null ? void 0 : g.points, j = [], I = w.unix((v = M[0]) == null ? void 0 : v.utc);
|
|
517
517
|
let p = -1;
|
|
518
518
|
for (const d of M) {
|
|
519
|
-
const
|
|
519
|
+
const b = w.unix(d.utc), m = {
|
|
520
520
|
imo: r == null ? void 0 : r.imo,
|
|
521
521
|
mmsi: t,
|
|
522
522
|
sog: Math.round(d.sog * 3600 / 1e3 / 1852 * 100) / 100,
|
|
523
523
|
cog: Math.round(d.cog / 100 * 100) / 100,
|
|
524
524
|
lat: Math.round(d.lat / 1e6 * 1e5) / 1e5,
|
|
525
525
|
lng: Math.round(d.lon / 1e6 * 1e5) / 1e5,
|
|
526
|
-
positionTime:
|
|
527
|
-
utc:
|
|
526
|
+
positionTime: b.unix(),
|
|
527
|
+
utc: b.utc().format(),
|
|
528
528
|
method: "trajectory",
|
|
529
529
|
vendor: "shipxy"
|
|
530
|
-
}, h = Math.floor(
|
|
530
|
+
}, h = Math.floor(b.diff(I, "minute", !0) / (o || 1));
|
|
531
531
|
h !== p && (p = h, j.push(m));
|
|
532
532
|
}
|
|
533
533
|
return j;
|
|
@@ -625,12 +625,12 @@ class Tt extends st {
|
|
|
625
625
|
}, l = "https://api3.myships.com/sp/ships/position/history", y = await L.post(l, u).json();
|
|
626
626
|
if (f == null || f.info("[%s] fetch trajectory from: %s - %j", c.requestId, l, u), y.code !== "0")
|
|
627
627
|
return f == null || f.warn("[%s] invoke myship trajectory failed: %j", c.requestId, y), y;
|
|
628
|
-
const
|
|
629
|
-
for (const p in
|
|
630
|
-
!isNaN(
|
|
631
|
-
const M = w.unix((I =
|
|
628
|
+
const g = y.data;
|
|
629
|
+
for (const p in g)
|
|
630
|
+
!isNaN(g[p]) && Number(g[p]) !== 1 / 0 && (g[p] = Number(g[p]));
|
|
631
|
+
const M = w.unix((I = g[0]) == null ? void 0 : I.posTime);
|
|
632
632
|
let j = -1;
|
|
633
|
-
for (const p of
|
|
633
|
+
for (const p of g) {
|
|
634
634
|
const v = w.unix(p.posTime), d = {
|
|
635
635
|
imo: o == null ? void 0 : o.imo,
|
|
636
636
|
mmsi: n,
|
|
@@ -644,8 +644,8 @@ class Tt extends st {
|
|
|
644
644
|
utc: v.utc().format(),
|
|
645
645
|
method: "trajectory",
|
|
646
646
|
vendor: "myship"
|
|
647
|
-
},
|
|
648
|
-
|
|
647
|
+
}, b = Math.floor(v.diff(M, "minute", !0) / (e || 1));
|
|
648
|
+
b !== j && (j = b, r.push(d));
|
|
649
649
|
}
|
|
650
650
|
return r;
|
|
651
651
|
}
|
|
@@ -678,7 +678,7 @@ class yt {
|
|
|
678
678
|
if (u === 0 && !l)
|
|
679
679
|
n.scope = o[0];
|
|
680
680
|
else if (l)
|
|
681
|
-
for (let y = 0,
|
|
681
|
+
for (let y = 0, g = l.length; y < g; y++) {
|
|
682
682
|
const M = this.parseRule(l[y]);
|
|
683
683
|
M && (n[M.level] ? M.key ? n[M.level][M == null ? void 0 : M.key] = M : n[M.level] = M : M.key ? n[M.level] = { [M == null ? void 0 : M.key]: M } : n[M.level] = M);
|
|
684
684
|
}
|
|
@@ -713,14 +713,14 @@ class yt {
|
|
|
713
713
|
* @param options
|
|
714
714
|
*/
|
|
715
715
|
checkWeather(s, t, a = {}) {
|
|
716
|
-
var M, j, I, p, v, d,
|
|
716
|
+
var M, j, I, p, v, d, b, m, h, k, S, D, P, N, A;
|
|
717
717
|
let i = 0, o = 0, n = 0, e = 0;
|
|
718
|
-
const r = Math.round(((j = (M = t == null ? void 0 : t.SEVERE) == null ? void 0 : M.sigWave) == null ? void 0 : j.number) * 1.6 * 100) / 100, c = (p = (I = t == null ? void 0 : t.SEVERE) == null ? void 0 : I.sigWave) == null ? void 0 : p.number, u = (d = (v = t == null ? void 0 : t.HEAVY) == null ? void 0 : v.sigWave) == null ? void 0 : d.number, l = Math.round((((m = (
|
|
718
|
+
const r = Math.round(((j = (M = t == null ? void 0 : t.SEVERE) == null ? void 0 : M.sigWave) == null ? void 0 : j.number) * 1.6 * 100) / 100, c = (p = (I = t == null ? void 0 : t.SEVERE) == null ? void 0 : I.sigWave) == null ? void 0 : p.number, u = (d = (v = t == null ? void 0 : t.HEAVY) == null ? void 0 : v.sigWave) == null ? void 0 : d.number, l = Math.round((((m = (b = t == null ? void 0 : t.SEVERE) == null ? void 0 : b.wind) == null ? void 0 : m.number) + 2) * 100) / 100, y = (k = (h = t == null ? void 0 : t.SEVERE) == null ? void 0 : h.wind) == null ? void 0 : k.number, g = (D = (S = t == null ? void 0 : t.HEAVY) == null ? void 0 : S.wind) == null ? void 0 : D.number;
|
|
719
719
|
for (let x = 0; x < (s == null ? void 0 : s.length); x++) {
|
|
720
720
|
const T = s[x], q = (N = (P = T == null ? void 0 : T.meteo) == null ? void 0 : P.wave) == null ? void 0 : N.sig, R = (A = T == null ? void 0 : T.meteo) == null ? void 0 : A.wind, J = x ? w(T.eta).diff(w(s[x - 1].eta), "hour", !0) : 0;
|
|
721
|
-
e = J > e ? J : e, z == null || z.debug("[%s] check sig.wave: %j", a.requestId, { ...q, dgThd4Wv: r, svThd4Wv: c, hvThd4Wv: u }), (q == null ? void 0 : q.height) >= r ? T.isDangerous = !0 : (q == null ? void 0 : q.height) >= c ? T.isSevere = !0 : (q == null ? void 0 : q.height) >= u && (T.isHeavy = !0), z == null || z.debug("[%s] check wind: %j", a.requestId, { ...R, dgThd4Wd: l, svThd4Wd: y, hvThd4Wd:
|
|
721
|
+
e = J > e ? J : e, z == null || z.debug("[%s] check sig.wave: %j", a.requestId, { ...q, dgThd4Wv: r, svThd4Wv: c, hvThd4Wv: u }), (q == null ? void 0 : q.height) >= r ? T.isDangerous = !0 : (q == null ? void 0 : q.height) >= c ? T.isSevere = !0 : (q == null ? void 0 : q.height) >= u && (T.isHeavy = !0), z == null || z.debug("[%s] check wind: %j", a.requestId, { ...R, dgThd4Wd: l, svThd4Wd: y, hvThd4Wd: g }), (R == null ? void 0 : R.scale) >= l ? (T.isDangerous = !0, delete T.isSevere, delete T.isHeavy) : (R == null ? void 0 : R.scale) > y ? (T.isDangerous || (T.isSevere = !0), delete T.isHeavy) : (R == null ? void 0 : R.scale) === g && !T.isDangerous && !T.isSevere && (T.isHeavy = !0), i += T.isDangerous ? J : 0, o += T.isSevere ? J : 0, n += T.isHeavy ? J : 0;
|
|
722
722
|
}
|
|
723
|
-
return i = Math.round(i * 100) / 100, o = Math.round(o * 100) / 100, n = Math.round(n * 100) / 100, e = Math.round(e), { sample: s, dangerous: i, severe: o, heavy: n, step: e < 3 ? 3 : e, wind: { dgThd4Wd: l, svThd4Wd: y, hvThd4Wd:
|
|
723
|
+
return i = Math.round(i * 100) / 100, o = Math.round(o * 100) / 100, n = Math.round(n * 100) / 100, e = Math.round(e), { sample: s, dangerous: i, severe: o, heavy: n, step: e < 3 ? 3 : e, wind: { dgThd4Wd: l, svThd4Wd: y, hvThd4Wd: g }, sig: { dgThd4Wv: r, svThd4Wv: c, hvThd4Wv: u } };
|
|
724
724
|
}
|
|
725
725
|
}
|
|
726
726
|
const xt = new yt();
|
|
@@ -731,7 +731,7 @@ try {
|
|
|
731
731
|
} finally {
|
|
732
732
|
}
|
|
733
733
|
const Mt = new mt("", !0);
|
|
734
|
-
var
|
|
734
|
+
var bt = /* @__PURE__ */ ((E) => (E.common = "common", E.container = "container", E.tugs = "tugs", E))(bt || {}), gt = /* @__PURE__ */ ((E) => (E.Ballast = "Ballast", E.Laden = "Laden", E))(gt || {}), vt = /* @__PURE__ */ ((E) => (E.Cp = "CP", E.Perf = "Basis", E.Instruct = "Other", E))(vt || {});
|
|
735
735
|
class O {
|
|
736
736
|
/**
|
|
737
737
|
* @see https://baike.baidu.com/item/%E6%96%B9%E5%BD%A2%E7%B3%BB%E6%95%B0/4965568?fr=aladdin
|
|
@@ -817,13 +817,13 @@ class O {
|
|
|
817
817
|
* @param displacement 排水量,m^3
|
|
818
818
|
* @param loadCondition
|
|
819
819
|
* @param tag
|
|
820
|
-
* @param bn
|
|
820
|
+
* // @param bn
|
|
821
|
+
* @param kts
|
|
821
822
|
* @private
|
|
822
823
|
*/
|
|
823
|
-
static vesselTagFactor(s, t, a, i
|
|
824
|
-
i = i > 6 ? i - 0.9 * (i - 6) : i;
|
|
824
|
+
static vesselTagFactor(s, t, a, i) {
|
|
825
825
|
let o;
|
|
826
|
-
return a === "container" ? o = 0.7 * i + Math.pow(i,
|
|
826
|
+
return a === "container" ? o = 0.7 * i / 2 + Math.pow(i, 3) / (22 * Math.pow(s, 2 / 3)) : t === "Ballast" ? o = 0.7 * i / 2 + Math.pow(i, 3) / (2.7 * Math.pow(s, 2 / 3)) : o = 0.5 * i / 2 + Math.pow(i, 3) / (2.7 * Math.pow(s, 2 / 3)), o;
|
|
827
827
|
}
|
|
828
828
|
/**
|
|
829
829
|
* 浪高影响因子
|
|
@@ -888,12 +888,12 @@ class O {
|
|
|
888
888
|
} catch (M) {
|
|
889
889
|
C.warn("[%s] meteo2 spot(%j) forecast failed: %s", r.requestId, { ...t, eta: a.utc().format(), source: i }, M);
|
|
890
890
|
}
|
|
891
|
-
const l = O.weatherFactor(s, u), y = O.currentFactor(s.bearing, u == null ? void 0 : u.current, o),
|
|
891
|
+
const l = O.weatherFactor(s, u), y = O.currentFactor(s.bearing, u == null ? void 0 : u.current, o), g = Math.round((s.speed * 1.943844 + l + y) * 100) / 100;
|
|
892
892
|
c = {
|
|
893
893
|
meteo: { ...u },
|
|
894
894
|
wxFactor: l,
|
|
895
895
|
cFactor: y,
|
|
896
|
-
speed: t.velocity && e ? t.velocity :
|
|
896
|
+
speed: t.velocity && e ? t.velocity : g < 0 ? 1 : g,
|
|
897
897
|
eta: a.utc().format(),
|
|
898
898
|
etd: a.utc().format()
|
|
899
899
|
};
|
|
@@ -923,13 +923,13 @@ class O {
|
|
|
923
923
|
*/
|
|
924
924
|
static async speedLoseInHoursStep(s, t, a, i, o, n, e = "", r = !0, c = !1, u = {}) {
|
|
925
925
|
t.utc();
|
|
926
|
-
const l = t.clone().add(14, "days"), y = [],
|
|
926
|
+
const l = t.clone().add(14, "days"), y = [], g = [];
|
|
927
927
|
let M = 0, j = 0, I, p;
|
|
928
928
|
for (let v = 0; v < n.length - 1; v++) {
|
|
929
929
|
let d = n[v];
|
|
930
930
|
d.distanceFromStart = Math.round((o + j) * 1e3) / 1e3;
|
|
931
|
-
const
|
|
932
|
-
if (s.bearing = W.calculateBearing(d,
|
|
931
|
+
const b = n[v + 1];
|
|
932
|
+
if (s.bearing = W.calculateBearing(d, b, !b.gcToPrevious), d.bearing = s.bearing, d.suspend && c) {
|
|
933
933
|
d.eta = d.eta || t.utc().format(), d.elapsed = d.elapsed ?? 0;
|
|
934
934
|
const k = d.suspend - d.elapsed;
|
|
935
935
|
if (i - M > k)
|
|
@@ -939,26 +939,26 @@ class O {
|
|
|
939
939
|
d.elapsed += S, t.add(S, "hour"), i = 0;
|
|
940
940
|
}
|
|
941
941
|
if (C == null || C.info(`[%s] suspend ${d.elapsed} hours at %j, and remain ${i} hours need to go...`, u.requestId, d), i === 0)
|
|
942
|
-
return d.distanceFromPrevious = j, { etd: t, from: p || d, to: d, next: n.filter((S) => S), wps: y, days:
|
|
942
|
+
return d.distanceFromPrevious = j, { etd: t, from: p || d, to: d, next: n.filter((S) => S), wps: y, days: g };
|
|
943
943
|
} else
|
|
944
944
|
d.suspend = 0;
|
|
945
|
-
r = t.isAfter(l) ? !1 : r, d = await O.speedLoseAt(s, d, t, e, 0, r, c, u), p = p || d, d.important && y.push(d), t.isSameOrAfter(a) && (
|
|
946
|
-
const m = W.calculateDistance(d,
|
|
945
|
+
r = t.isAfter(l) ? !1 : r, d = await O.speedLoseAt(s, d, t, e, 0, r, c, u), p = p || d, d.important && y.push(d), t.isSameOrAfter(a) && (g.push(d), a.add(24, "hour"));
|
|
946
|
+
const m = W.calculateDistance(d, b, !b.gcToPrevious);
|
|
947
947
|
let h = Math.round(m / p.speed * 1e5) / 1e5;
|
|
948
948
|
if (M + h < i) {
|
|
949
949
|
if (M += h, t.add(h, "hour"), delete n[v], C == null || C.debug(
|
|
950
950
|
`[%s] go to %j from %j with ${m}nm, and cost ${h} hours`,
|
|
951
951
|
u.requestId,
|
|
952
|
-
{ lat:
|
|
952
|
+
{ lat: b.lat, lng: b.lng },
|
|
953
953
|
{ lat: p.lat, lng: p.lng, etd: p.etd }
|
|
954
954
|
), j += m, n.filter((k) => k).length <= 1) {
|
|
955
|
-
I =
|
|
955
|
+
I = b, I.eta = t.utc().format(), I.distanceFromPrevious = m, I.distanceFromStart = Math.round((o + j) * 1e4) / 1e4, y.push(I), delete n[v + 1];
|
|
956
956
|
break;
|
|
957
957
|
}
|
|
958
958
|
} else {
|
|
959
959
|
h = i - M, t.add(h, "hour");
|
|
960
960
|
const k = _.roundPrecision(p.speed * h, 5);
|
|
961
|
-
I = W.calculateCoordinate(d, s.bearing, k, "nauticalmiles", !
|
|
961
|
+
I = W.calculateCoordinate(d, s.bearing, k, "nauticalmiles", !b.gcToPrevious), I.eta = t.utc().format(), n[v] = I, C == null || C.debug(
|
|
962
962
|
`[%s] go to %j from %j with ${k}nm, and cost ${h} hours`,
|
|
963
963
|
u.requestId,
|
|
964
964
|
{ lat: I.lat, lng: I.lng },
|
|
@@ -967,7 +967,7 @@ class O {
|
|
|
967
967
|
break;
|
|
968
968
|
}
|
|
969
969
|
}
|
|
970
|
-
return { etd: t, from: p, to: I, next: n.filter((v) => v), wps: y, days:
|
|
970
|
+
return { etd: t, from: p, to: I, next: n.filter((v) => v), wps: y, days: g };
|
|
971
971
|
}
|
|
972
972
|
/**
|
|
973
973
|
* 洋流影响因子
|
|
@@ -988,12 +988,12 @@ class O {
|
|
|
988
988
|
* @param wwc 气象要素
|
|
989
989
|
*/
|
|
990
990
|
static weatherFactor(s, t) {
|
|
991
|
-
var l, y,
|
|
991
|
+
var l, y, g, M, j, I, p;
|
|
992
992
|
C == null || C.debug("calculate weather factor via: %j", { ...s, ...t });
|
|
993
993
|
const a = O.blockCoefficient(s.displacement, s.lbp, s.breadthMoulded, s.draught), i = O.froudeNumber(s.speed, s.lbp), o = O.amendFactor(a, i, s.loadCondition);
|
|
994
994
|
let n = Math.abs(s.bearing % 360 - (((l = t == null ? void 0 : t.wind) == null ? void 0 : l.degree) % 360 || 0));
|
|
995
995
|
n = n > 180 ? 360 - n : n;
|
|
996
|
-
const e = O.directionFactor(n, (y = t == null ? void 0 : t.wind) == null ? void 0 : y.scale), r = O.vesselTagFactor(s.displacement, s.loadCondition, s.tag, (
|
|
996
|
+
const e = O.directionFactor(n, (y = t == null ? void 0 : t.wind) == null ? void 0 : y.scale), r = O.vesselTagFactor(s.displacement, s.loadCondition, s.tag, (g = t == null ? void 0 : t.wind) == null ? void 0 : g.kts);
|
|
997
997
|
let c = e * o * r / 100 * s.speed;
|
|
998
998
|
c = Math.round(c * 1.943844 * 1e4) / 1e4 * -1, s.tag === "tugs" && Math.abs(c) > 1 && (c = c / (Math.abs(Math.round(c)) + 1)), C == null || C.debug("wind wx factor = %d", c), n = Math.abs(s.bearing % 360 - (((j = (M = t == null ? void 0 : t.wave) == null ? void 0 : M.sig) == null ? void 0 : j.degree) % 360 || 0));
|
|
999
999
|
const u = O.waveHeightFactor(((p = (I = t == null ? void 0 : t.wave) == null ? void 0 : I.sig) == null ? void 0 : p.height) ?? 1, n);
|
|
@@ -1016,7 +1016,7 @@ class O {
|
|
|
1016
1016
|
var K, G, X, Q, Z, $;
|
|
1017
1017
|
const l = w().valueOf();
|
|
1018
1018
|
s.lng = _.convertToStdLng(s.lng);
|
|
1019
|
-
const { route: y, waypoints:
|
|
1019
|
+
const { route: y, waypoints: g } = o.points, M = W.calculateSubRoute(s, y);
|
|
1020
1020
|
if (((K = M[0]) == null ? void 0 : K.length) <= 1)
|
|
1021
1021
|
return;
|
|
1022
1022
|
const { v0: j, label: I } = s.sog ? {
|
|
@@ -1027,7 +1027,7 @@ class O {
|
|
|
1027
1027
|
v0: i.speed,
|
|
1028
1028
|
label: "CP"
|
|
1029
1029
|
/* Cp */
|
|
1030
|
-
}, p = O.assembleProperties(a, i.loadCondition, j, 0), v =
|
|
1030
|
+
}, p = O.assembleProperties(a, i.loadCondition, j, 0), v = g.length ? W.calculateSubWaypoints(s, g) : [];
|
|
1031
1031
|
v.forEach((Y) => Y.important = !0);
|
|
1032
1032
|
const d = {
|
|
1033
1033
|
from: { ...s },
|
|
@@ -1035,7 +1035,7 @@ class O {
|
|
|
1035
1035
|
waypoints: v,
|
|
1036
1036
|
v0: j,
|
|
1037
1037
|
label: I
|
|
1038
|
-
},
|
|
1038
|
+
}, b = {
|
|
1039
1039
|
hours: [],
|
|
1040
1040
|
days: [],
|
|
1041
1041
|
wps: []
|
|
@@ -1057,22 +1057,22 @@ class O {
|
|
|
1057
1057
|
c,
|
|
1058
1058
|
u
|
|
1059
1059
|
);
|
|
1060
|
-
(G = F.from) != null && G.speed && (
|
|
1060
|
+
(G = F.from) != null && G.speed && (b.hours.push(F.from), b.wps.push(...F.wps), b.days.push(...F.days)), m = F == null ? void 0 : F.next, m.length || b.hours.push(F == null ? void 0 : F.to), h += Math.round((((X = F == null ? void 0 : F.to) == null ? void 0 : X.distanceFromPrevious) ?? 0) * 1e4) / 1e4;
|
|
1061
1061
|
}
|
|
1062
|
-
const N =
|
|
1062
|
+
const N = b.hours;
|
|
1063
1063
|
for (let Y = 0; Y < N.length - 1; Y++) {
|
|
1064
1064
|
const B = w(N[Y + 1].eta).diff(N[Y].etd, "hour", !0) || 1;
|
|
1065
1065
|
k += (N[Y].wxFactor || 0) * B, S += (N[Y].cFactor || 0) * B, D += B;
|
|
1066
1066
|
}
|
|
1067
|
-
(Q =
|
|
1067
|
+
(Q = b.wps) == null || Q.forEach((Y, B) => {
|
|
1068
1068
|
Y.positionTime = w.utc(Y.etd || Y.eta).unix();
|
|
1069
|
-
const F =
|
|
1069
|
+
const F = b.wps[B - 1];
|
|
1070
1070
|
if (F) {
|
|
1071
1071
|
const V = Y.distanceFromStart - F.distanceFromStart, H = w(Y.eta || Y.etd).diff(w(F.etd || F.eta), "h", !0);
|
|
1072
1072
|
Y.avgSpd = Math.round(V / H * 100) / 100, F.bearing = W.calculateBearing(F, Y);
|
|
1073
1073
|
}
|
|
1074
|
-
}),
|
|
1075
|
-
const A =
|
|
1074
|
+
}), b.wps = (Z = b.wps) == null ? void 0 : Z.reduce((Y, B) => (Y.some((F) => Math.round(F.positionTime / 60) === Math.round(B.positionTime / 60)) || Y.push(B), Y), []), d.sample = b;
|
|
1075
|
+
const A = b.hours.at(0), x = b.hours.at(-1);
|
|
1076
1076
|
d.distance = Math.round(x.distanceFromStart * 1e3) / 1e3, d.etd = w(A.eta).utc().format(), d.eta = w(x.eta).utc().format(), d.wxFactor = Math.round(k / D * 1e3) / 1e3, d.cFactor = Math.round(S / D * 1e3) / 1e3, d.avgSpeed = Math.round(x.distanceFromStart / D * 1e3) / 1e3, d.totalHrs = Math.round(D * 1e3) / 1e3;
|
|
1077
1077
|
const { distanceInECA: T, hoursInECA: q, totalDgoConsInECA: R, eca: J } = await this.calculateECA(d, i, u), tt = _.roundPrecision(i.fo / 24 * (D - q), 3), at = _.roundPrecision(i.dgo / 24 * D, 3);
|
|
1078
1078
|
d.extend = {
|
|
@@ -1081,7 +1081,7 @@ class O {
|
|
|
1081
1081
|
hoursInECA: q,
|
|
1082
1082
|
totalDgoConsInECA: R
|
|
1083
1083
|
}, d.totalFoCons = tt < 0 ? 0 : tt, d.totalDgoCons = at;
|
|
1084
|
-
const et = w().valueOf() - l, ot = (($ =
|
|
1084
|
+
const et = w().valueOf() - l, ot = (($ = b == null ? void 0 : b.hours) == null ? void 0 : $.length) || 1;
|
|
1085
1085
|
return C == null || C.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", u == null ? void 0 : u.requestId, et, ot, Math.round(et / ot * 1e3) / 1e3), d;
|
|
1086
1086
|
}
|
|
1087
1087
|
/**
|
|
@@ -1101,7 +1101,7 @@ class O {
|
|
|
1101
1101
|
*/
|
|
1102
1102
|
static async analyseInstantWithThreshed(s, t, a, i, o, n, e, r = "", c = 3, u = !0, l = !1, y = {}) {
|
|
1103
1103
|
var X, Q, Z, $, Y, B;
|
|
1104
|
-
const
|
|
1104
|
+
const g = w().valueOf();
|
|
1105
1105
|
s.lng = _.convertToStdLng(s.lng);
|
|
1106
1106
|
const { v0: M, label: j } = s.sog ? {
|
|
1107
1107
|
v0: s.sog,
|
|
@@ -1116,7 +1116,7 @@ class O {
|
|
|
1116
1116
|
return;
|
|
1117
1117
|
const v = e.length ? W.calculateSubWaypoints(s, e) : [];
|
|
1118
1118
|
v.forEach((F) => F.important = !0);
|
|
1119
|
-
let d = W.simplifyRouteToCoordinates(p, v, 0),
|
|
1119
|
+
let d = W.simplifyRouteToCoordinates(p, v, 0), b = 0, m = 0, h = 0, k = 0;
|
|
1120
1120
|
const S = {
|
|
1121
1121
|
hours: [],
|
|
1122
1122
|
wps: [],
|
|
@@ -1128,8 +1128,8 @@ class O {
|
|
|
1128
1128
|
const F = c - t.hour() % c;
|
|
1129
1129
|
let V = Math.ceil(t.clone().add(F, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4;
|
|
1130
1130
|
V = t.clone().add(V, "h").isSameOrAfter(a) ? a.diff(t, "h", !0) * 1e4 / 1e4 : V;
|
|
1131
|
-
const H = await O.speedLoseInHoursStep(I, t, D, V,
|
|
1132
|
-
if ((Q = H.from) != null && Q.speed && (S.hours.push(H.from), H != null && H.wps && S.wps.push(...H.wps), S.days.push(...H.days)), d = H == null ? void 0 : H.next, d.length || S.hours.push(H == null ? void 0 : H.to),
|
|
1131
|
+
const H = await O.speedLoseInHoursStep(I, t, D, V, b, d, r, u, l, y);
|
|
1132
|
+
if ((Q = H.from) != null && Q.speed && (S.hours.push(H.from), H != null && H.wps && S.wps.push(...H.wps), S.days.push(...H.days)), d = H == null ? void 0 : H.next, d.length || S.hours.push(H == null ? void 0 : H.to), b += Math.round((((Z = H == null ? void 0 : H.to) == null ? void 0 : Z.distanceFromPrevious) ?? 0) * 1e4) / 1e4, !V)
|
|
1133
1133
|
break;
|
|
1134
1134
|
}
|
|
1135
1135
|
S.wps = ($ = S.wps) == null ? void 0 : $.reduce((F, V) => (F.some((H) => Math.round(w(H.etd).unix() / 60) === Math.round(w(V.etd).unix() / 60)) || F.push(V), F), []), (Y = S.wps) == null || Y.forEach((F, V) => {
|
|
@@ -1169,7 +1169,7 @@ class O {
|
|
|
1169
1169
|
hoursInECA: J,
|
|
1170
1170
|
totalDgoConsInECA: tt
|
|
1171
1171
|
}, q.totalDgoCons = et, q.totalFoCons = nt < 0 ? 0 : nt;
|
|
1172
|
-
const K = w().valueOf() -
|
|
1172
|
+
const K = w().valueOf() - g, G = ((B = S == null ? void 0 : S.hours) == null ? void 0 : B.length) || 1;
|
|
1173
1173
|
return C == null || C.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", y == null ? void 0 : y.requestId, K, G, Math.round(K / G * 1e3) / 1e3), q;
|
|
1174
1174
|
}
|
|
1175
1175
|
/**
|
|
@@ -1194,19 +1194,19 @@ class O {
|
|
|
1194
1194
|
const r = W.calculateRouteDistance(i.route);
|
|
1195
1195
|
let c = 0;
|
|
1196
1196
|
a.forEach((d) => {
|
|
1197
|
-
const
|
|
1198
|
-
c = c <
|
|
1197
|
+
const b = Math.ceil(r / d.speed / 24);
|
|
1198
|
+
c = c < b ? b : c;
|
|
1199
1199
|
}), c = c * 1.3;
|
|
1200
1200
|
const u = w.utc(s.etd).add(c ?? 14, "day");
|
|
1201
1201
|
let l = 1;
|
|
1202
1202
|
for (const d of a) {
|
|
1203
|
-
const
|
|
1203
|
+
const b = JSON.parse(JSON.stringify(i.route)), m = JSON.parse(JSON.stringify(i.waypoints)), h = await O.analyseInstantWithThreshed(
|
|
1204
1204
|
{ lat: s.lat, lng: s.lng },
|
|
1205
1205
|
s.etd,
|
|
1206
1206
|
u,
|
|
1207
1207
|
t,
|
|
1208
1208
|
d,
|
|
1209
|
-
|
|
1209
|
+
b,
|
|
1210
1210
|
m,
|
|
1211
1211
|
s.meteoVendor,
|
|
1212
1212
|
s.speedStep,
|
|
@@ -1223,15 +1223,15 @@ class O {
|
|
|
1223
1223
|
cp: `${d.speed}/${d.fo}/${d.dgo}`
|
|
1224
1224
|
})), l++;
|
|
1225
1225
|
}
|
|
1226
|
-
e.sort((d,
|
|
1227
|
-
const y = e.at(0),
|
|
1228
|
-
if (M.push({ combined: !1, speeds: [y], cost: (p = y.cost) == null ? void 0 : p.total }),
|
|
1229
|
-
const d = y.cost.cp,
|
|
1226
|
+
e.sort((d, b) => d.cost.total - b.cost.total);
|
|
1227
|
+
const y = e.at(0), g = e.at(1), M = [];
|
|
1228
|
+
if (M.push({ combined: !1, speeds: [y], cost: (p = y.cost) == null ? void 0 : p.total }), g) {
|
|
1229
|
+
const d = y.cost.cp, b = g.cost.cp, m = w(y.eta), h = w(y.etd), k = m.diff(h, "days", !0);
|
|
1230
1230
|
let S = Math.ceil(k / 2);
|
|
1231
1231
|
S = S > 7 ? 7 : S < s.alterStep ? s.alterStep : S;
|
|
1232
|
-
let D = 2, P = { combined: !1, speeds: [
|
|
1232
|
+
let D = 2, P = { combined: !1, speeds: [g], cost: (v = g.cost) == null ? void 0 : v.total }, N;
|
|
1233
1233
|
for (; S >= s.alterStep; ) {
|
|
1234
|
-
const A = await O.combinedAnalyse(s, t, u, [d,
|
|
1234
|
+
const A = await O.combinedAnalyse(s, t, u, [d, b], i, S, { ...o, level: D });
|
|
1235
1235
|
if (P.cost > A.cost ? N ? (N == null ? void 0 : N.cost) > A.cost && (N = A) : (N = P, P = A) : (!N || (N == null ? void 0 : N.cost) > A.cost) && (N = A), S <= s.alterStep)
|
|
1236
1236
|
break;
|
|
1237
1237
|
S = Math.ceil(S / 2), D += 1;
|
|
@@ -1239,7 +1239,7 @@ class O {
|
|
|
1239
1239
|
M.push(P), N && M.push(N);
|
|
1240
1240
|
}
|
|
1241
1241
|
const I = w().valueOf() - n;
|
|
1242
|
-
return C == null || C.info("[%s] analyse elapsed: %d ms", o == null ? void 0 : o.requestId, I), M.sort((d,
|
|
1242
|
+
return C == null || C.info("[%s] analyse elapsed: %d ms", o == null ? void 0 : o.requestId, I), M.sort((d, b) => d.cost - b.cost);
|
|
1243
1243
|
}
|
|
1244
1244
|
/**
|
|
1245
1245
|
* 按步长多次减半,分别用7,4,2,1天步长及cpa,cpb交替计算各种组合下的成本
|
|
@@ -1253,15 +1253,15 @@ class O {
|
|
|
1253
1253
|
*/
|
|
1254
1254
|
static async combinedAnalyse(s, t, a, i, o, n, e = {}) {
|
|
1255
1255
|
e.counter = 1, C == null || C.info("[%s][L%d] analyse with alternate cp in every %d days", e.requestId, e.level, n);
|
|
1256
|
-
const r = await O.alternateAnalyse(s, t, a, i, 0, o, n, e), c = r.reduce((
|
|
1256
|
+
const r = await O.alternateAnalyse(s, t, a, i, 0, o, n, e), c = r.reduce((b, m) => b + m.cost.total, 0), u = r.reduce((b, m) => b + m.cost.hire, 0), l = r.reduce((b, m) => b + m.cost.bunker, 0), y = r.reduce((b, m) => b + m.distance, 0), g = r.reduce((b, m) => b + m.totalHrs, 0);
|
|
1257
1257
|
C == null || C.info("[%s][L%d] cost with cpa/cpb turn: %j", e.requestId, e.level, {
|
|
1258
1258
|
cost: c,
|
|
1259
1259
|
hire: u,
|
|
1260
1260
|
bunker: l,
|
|
1261
1261
|
distance: y,
|
|
1262
|
-
hours:
|
|
1262
|
+
hours: g
|
|
1263
1263
|
});
|
|
1264
|
-
const M = await O.alternateAnalyse(s, t, a, i, 1, o, n, e), j = M.reduce((
|
|
1264
|
+
const M = await O.alternateAnalyse(s, t, a, i, 1, o, n, e), j = M.reduce((b, m) => b + m.cost.total, 0), I = M.reduce((b, m) => b + m.cost.hire, 0), p = M.reduce((b, m) => b + m.cost.bunker, 0), v = M.reduce((b, m) => b + m.distance, 0), d = M.reduce((b, m) => b + m.totalHrs, 0);
|
|
1265
1265
|
return C == null || C.info("[%s][L%d] cost with cpb/cpa turn: %j", e.requestId, e.level, {
|
|
1266
1266
|
cost: j,
|
|
1267
1267
|
hire: I,
|
|
@@ -1282,7 +1282,7 @@ class O {
|
|
|
1282
1282
|
* @param options
|
|
1283
1283
|
*/
|
|
1284
1284
|
static async alternateAnalyse(s, t, a, i, o, n, e, r = {}) {
|
|
1285
|
-
var y,
|
|
1285
|
+
var y, g;
|
|
1286
1286
|
let c = w.utc(s.etd);
|
|
1287
1287
|
const u = { lat: s.lat, lng: s.lng }, l = [];
|
|
1288
1288
|
for (; c.isBefore(a); ) {
|
|
@@ -1316,7 +1316,7 @@ class O {
|
|
|
1316
1316
|
cp: `${p.speed}/${p.fo}/${p.dgo}`
|
|
1317
1317
|
}
|
|
1318
1318
|
)), r.counter = r.counter + 1;
|
|
1319
|
-
const d = (
|
|
1319
|
+
const d = (g = (y = v == null ? void 0 : v.sample) == null ? void 0 : y.hours) == null ? void 0 : g.at(-1);
|
|
1320
1320
|
if (d)
|
|
1321
1321
|
u.lat = d.lat, u.lng = d.lng, c = w(d.eta), l.push(v), o = o ? 0 : 1;
|
|
1322
1322
|
else
|
|
@@ -1357,8 +1357,8 @@ class O {
|
|
|
1357
1357
|
});
|
|
1358
1358
|
for (const y of i) {
|
|
1359
1359
|
o += y.distance;
|
|
1360
|
-
const
|
|
1361
|
-
y.in =
|
|
1360
|
+
const g = await W.deadReckoningTime((u = y.waypoints) == null ? void 0 : u.at(0), s.sample.wps), M = await W.deadReckoningTime((l = y.waypoints) == null ? void 0 : l.at(-1), s.sample.wps);
|
|
1361
|
+
y.in = g, y.out = M, y.totalHrs = _.roundPrecision((M.positionTime - g.positionTime) / 3600, 3), y.totalDgoCons = _.roundPrecision(t.fo / 24 * y.totalHrs, 3), n += y.totalHrs, e += y.totalDgoCons;
|
|
1362
1362
|
}
|
|
1363
1363
|
return o = _.roundPrecision(o, 3), n = _.roundPrecision(n, 3), e = _.roundPrecision(e, 3), {
|
|
1364
1364
|
distanceInECA: o,
|
|
@@ -1373,7 +1373,7 @@ class O {
|
|
|
1373
1373
|
* @param options
|
|
1374
1374
|
*/
|
|
1375
1375
|
static async mergeSpeeds(s, t = {}) {
|
|
1376
|
-
var d,
|
|
1376
|
+
var d, b;
|
|
1377
1377
|
const a = {
|
|
1378
1378
|
hours: [],
|
|
1379
1379
|
wps: [],
|
|
@@ -1387,7 +1387,7 @@ class O {
|
|
|
1387
1387
|
}, 0), r = s.reduce((m, h) => {
|
|
1388
1388
|
var k;
|
|
1389
1389
|
return m + (((k = h.extend) == null ? void 0 : k.totalDgoConsInECA) || 0);
|
|
1390
|
-
}, 0), c = s.reduce((m, h) => m + h.wxFactor * h.totalHrs / n, 0), u = s.reduce((m, h) => m + h.cFactor * h.totalHrs / n, 0), l = s.reduce((m, h) => m + h.totalFoCons, 0), y = s.reduce((m, h) => m + h.totalDgoCons, 0),
|
|
1390
|
+
}, 0), c = s.reduce((m, h) => m + h.wxFactor * h.totalHrs / n, 0), u = s.reduce((m, h) => m + h.cFactor * h.totalHrs / n, 0), l = s.reduce((m, h) => m + h.totalFoCons, 0), y = s.reduce((m, h) => m + h.totalDgoCons, 0), g = s.reduce((m, h) => m + h.cost.total, 0), M = s.reduce((m, h) => m + h.cost.hire, 0), j = s.reduce((m, h) => m + h.cost.bunker, 0), I = [], p = [];
|
|
1391
1391
|
let v;
|
|
1392
1392
|
for (const m of s) {
|
|
1393
1393
|
p.push(...((d = m.extend) == null ? void 0 : d.eca) || []);
|
|
@@ -1410,7 +1410,7 @@ class O {
|
|
|
1410
1410
|
var q;
|
|
1411
1411
|
((q = a == null ? void 0 : a.days) == null ? void 0 : q.findIndex((R) => R.eta === x.eta)) === -1 && a.days.push(x);
|
|
1412
1412
|
});
|
|
1413
|
-
const A = (
|
|
1413
|
+
const A = (b = a.wps) == null ? void 0 : b.findIndex((x) => x.eta === D.eta);
|
|
1414
1414
|
A === -1 ? a.wps.push(D) : a.wps[A] = D, v = h.at(-1);
|
|
1415
1415
|
}
|
|
1416
1416
|
return a.wps.sort((m, h) => {
|
|
@@ -1439,7 +1439,7 @@ class O {
|
|
|
1439
1439
|
totalFoCons: Math.round(l * 1e3) / 1e3,
|
|
1440
1440
|
totalDgoCons: Math.round(y * 1e3) / 1e3,
|
|
1441
1441
|
cost: {
|
|
1442
|
-
total: Math.round(
|
|
1442
|
+
total: Math.round(g * 1e3) / 1e3,
|
|
1443
1443
|
hire: Math.round(M * 1e3) / 1e3,
|
|
1444
1444
|
bunker: Math.round(j * 1e3) / 1e3
|
|
1445
1445
|
},
|
|
@@ -1459,12 +1459,12 @@ export {
|
|
|
1459
1459
|
yt as AlertHelper,
|
|
1460
1460
|
ft as AlertLevel,
|
|
1461
1461
|
Et as HifleetImpl,
|
|
1462
|
-
|
|
1462
|
+
gt as LoadCondition,
|
|
1463
1463
|
Tt as MyShipImpl,
|
|
1464
1464
|
Ft as MyVesselImpl,
|
|
1465
1465
|
Nt as ShipxyImpl,
|
|
1466
1466
|
O as SpeedHelper,
|
|
1467
1467
|
vt as SpeedLabel,
|
|
1468
|
-
|
|
1468
|
+
bt as VesselTag,
|
|
1469
1469
|
xt as alertHelper
|
|
1470
1470
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(q,A){typeof exports=="object"&&typeof module<"u"?A(exports,require("got"),require("@log4js-node/log4js-api"),require("moment"),require("@idm-plugin/geo2"),require("@idm-plugin/meteo2"),require("@idm-plugin/meteo")):typeof define=="function"&&define.amd?define(["exports","got","@log4js-node/log4js-api","moment","@idm-plugin/geo2","@idm-plugin/meteo2","@idm-plugin/meteo"],A):(q=typeof globalThis<"u"?globalThis:q||self,A(q["idm-plugin-vessel"]={},q.got,q["@log4js-node/log4js-api"],q.moment,q["@idm-plugin/geo2"],q["@idm-plugin/meteo2"],q["@idm-plugin/meteo"]))})(this,function(q,A,U,g,H,ft,nt){"use strict";var It=Object.defineProperty;var St=(q,A,U)=>A in q?It(q,A,{enumerable:!0,configurable:!0,writable:!0,value:U}):q[A]=U;var K=(q,A,U)=>(St(q,typeof A!="symbol"?A+"":A,U),U);let m;try{m=U.getLogger("vessel")}catch{}finally{}class G{parseStatus(s){let t,a;switch(s){case 0:t="在航(主机推动)",a="Underway Using Engine";break;case 1:t="锚泊",a="Anchored";break;case 2:t="失控",a="Not under command";break;case 3:t="操纵受限",a="Limited airworthiness";break;case 4:t="吃水受限",a="Limited by ship's draft";break;case 5:t="靠泊",a="Mooring";break;case 6:t="搁浅",a="Stranded";break;case 7:t="捕捞作业",a="Engaged in fishing";break;case 8:t="靠帆船提供动力",a="Sailing";break;default:t="未定义",a="Undefined"}return{labelCn:t,labelEn:a}}}class mt extends G{constructor(t,a){super();K(this,"clientId");K(this,"clientSecret");K(this,"token");this.clientId=t,this.clientSecret=a}async authToken(t={}){const a="https://svc.data.myvessel.cn/ada/oauth/token",i={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},o=await A.post(a,i).json();m==null||m.info("[%s] fetch access token from: %s - %j",t.requestId,a,o),o.error||(this.token={accessToken:o.access_token,tokenType:o.token_type,expiresIn:o.expires_in,scope:o.scope,jti:o.jti,issuedAt:g().utc().format()})}async checkToken(t={}){var a;return(!this.token||g().diff(g(this.token.issuedAt),"seconds")>(((a=this.token)==null?void 0:a.expiresIn)||0)-300)&&await this.authToken(t),this.token}async suggest(t,a={}){var e,c;await this.checkToken(a);const i="https://market.myvessel.cn/sdc/v1/mkt/vessels/fuzzy",o={headers:{Authorization:`${(e=this.token)==null?void 0:e.tokenType} ${(c=this.token)==null?void 0:c.accessToken}`},json:{kw:t,recordNum:a.ps||10}};m==null||m.info("[%s] fetch suggest vessels from: %s - %j",a.requestId,i,o);const n=await A.post(i,o).json();return n.status!==200?(m==null||m.warn("[%s] fetch suggest vessels failed: %j",a.requestId,{message:n.message,status:n.status,code:n.code}),[]):(n.data||[]).map(u=>({mmsi:u.mmsi,name:u.nameEn,nameCn:u.nameCn,imo:Number.isNaN(u.imo)?null:Number(u.imo),callSign:u.callsign,type:u.vesselTypeNameEn,flagName:u.flagCtry,vendor:"myvessel",raw:u}))}async search(t,a={}){var r,u;await this.checkToken(a);const i=/^\d{7}$/.test(t.toString()),o=i?"https://market.myvessel.cn/sdc/v1/mkt/vessels/detail/imo":"https://market.myvessel.cn/sdc/v1/mkt/vessels/detail/mmsi",n=i?{imo:t}:{mmsi:t},e={headers:{Authorization:`${(r=this.token)==null?void 0:r.tokenType} ${(u=this.token)==null?void 0:u.accessToken}`},searchParams:n};m==null||m.info("[%s] fetch vessel from: %s - %j",a.requestId,o,e);const c=await A.get(o,e).json();if(c.status!==200)return m==null||m.warn("[%s] fetch suggest vessels failed: %j",a.requestId,{message:c.message,status:c.status,code:c.code}),{};{const h=c.data;if(h)return{mmsi:h.mmsi,imo:Number.isNaN(h.imo)?null:Number(h.imo),callSign:h.callsign,name:h.nameEn,nameCn:h.nameCn,type:h.vesselTypeNameEn,flagName:h.flagCtry,clasz:h.classSociety,dateOfBuild:h.buildYearMonth,deadweight:h.dwt,grossTonnage:h.grt,netTonnage:h.net,teu:h.teu,length:h.length,breadth:h.width,height:h.height,draught:h.draught,speed:h.speed,passengerCapacity:h.passengercapacity,vendor:"myvessel",raw:h}}return{}}async archives(t,a={}){var e,c;await this.checkToken(a);const i="https://svc.data.myvessel.cn/sdc/v1/ship/info/batch",o={headers:{Authorization:`${(e=this.token)==null?void 0:e.tokenType} ${(c=this.token)==null?void 0:c.accessToken}`},json:{mmsiList:typeof t=="number"?[t]:t}};m==null||m.info("[%s] fetch vessel archive from: %s - %j",a.requestId,i,o);const n=await A.post(i,o).json();return n.status!==200?(m==null||m.warn("[%s] fetch vessel archive failed: %j",a.requestId,{message:n.message,status:n.status,code:n.code}),{}):n.data}async realTimePosition(t,a={}){var c,r;await this.checkToken(a);const i="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",o={headers:{Authorization:`${(c=this.token)==null?void 0:c.tokenType} ${(r=this.token)==null?void 0:r.accessToken}`},searchParams:{mmsi:t}};m==null||m.info("[%s] fetch realtime position from: %s - %j",a.requestId,i,o);const n=await A.get(i,o).json();if(n.code)return m==null||m.warn("[%s] fetch realtime position failed: %j",a.requestId,{message:n.message,status:n.status,code:n.code}),n;const e=n.data;for(const u in e)!isNaN(e[u])&&Number(e[u])!==1/0&&(e[u]=Number(e[u]));if(e){const u=g(`${e.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:e.mmsi,name:e.vesselName||e.aisVesselName,imo:e.imo,callSign:e.callsign||e.aisCallSign,lat:e.lat,lng:e.lon,length:e.length,width:e.width,draught:e.currDraught,sog:e.sog,cog:e.cog,hdg:e.hdg,rot:e.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta)?g.utc(e.eta).format():void 0,destination:e.dest,positionTime:u.unix(),status:e.status,labelCn:e.statusNameCn,labelEn:e.statusNameEn,vesselType:e.vesselTypeNameEn,flag:e.flagCtryNameEn,clasz:e.classSociety,build:e.buildYear,dwt:e.dwt,grt:e.grt,net:e.net,method:"position",vendor:"myVessel",utc:u.utc().format()}}else return{}}async calculateRoute(t,a,i={}){var c,r;await this.checkToken(i);const o="https://svc.data.myvessel.cn/sdc/v1/routes/routing/nodes",n={headers:{Authorization:`${(c=this.token)==null?void 0:c.tokenType} ${(r=this.token)==null?void 0:r.accessToken}`},json:{startPoint:{lon:t.lng,lat:t.lat},endPoint:{lon:a.lng,lat:a.lat},maxDraught:i.maxDraught||10,useAIModel:i.useAIModel||!1,withECA:i.withECA||!1}};m==null||m.info("[%s] fetch route from: %s - %j",i.requestId,o,n);const e=await A.post(o,n).json();return e.status!==200?(m==null||m.warn("[%s] fetch route failed: %j",i.requestId,{message:e.message,status:e.status,code:e.code}),{}):e.data}async trajectory(t,a,i,o,n=!0,e={}){await this.checkToken(e);const c=await this.realTimePosition(t,e),r=g(a),u=g(i),h=[];for(;u.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(t,r,r.clone().add(30,"day"),c,o,h,e),r.add(30,"day");return await this.trajectoryIn30Day(t,r,u,c,o,h,e),h}async trajectoryIn30Day(t,a,i,o,n,e,c={}){var M,C,S,w,v;const r="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",u={headers:{Authorization:`${(M=this.token)==null?void 0:M.tokenType} ${(C=this.token)==null?void 0:C.accessToken}`},json:{mmsi:t,startTime:a.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};m==null||m.info("[%s] fetch trajectory from: %s - %j",c.requestId,r,u);const h=await A.post(r,u).json();if(h.code)return m==null||m.warn("[%s] fetch trajectory failed: %j",c.requestId,r,{message:h.message,status:h.status,code:h.code}),h;let y=-1;const b=g(`${(w=(S=h.data)==null?void 0:S[0])==null?void 0:w.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(v=h.data)==null||v.forEach(d=>{for(const Y in d)!isNaN(d[Y])&&Number(d[Y])!==1/0&&(d[Y]=Number(d[Y]));const p=g(`${d.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),f=d.status,{labelCn:l,labelEn:k}=this.parseStatus(f),j={mmsi:d.mmsi,imo:o==null?void 0:o.imo,lat:d.lat,lng:d.lon,sog:d.sog,cog:d.cog,hdg:d.hdg,draught:d.draught,status:f,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(d.eta)?g(`${d.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").utc().format():void 0,destination:d.dest,positionTime:p.unix(),labelCn:l,labelEn:k,method:"trajectory",vendor:"myVessel",utc:p.utc().format()},x=Math.floor(p.diff(b,"minute",!0)/(n||1));x!==y&&(y=x,e.push(j))}),e}}class yt extends G{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,a={}){const i="https://api.hifleet.com/position/position/get/token",o={searchParams:{mmsi:t,usertoken:this.token}},n=await A.post(i,o).json();m==null||m.info("[%s] fetch realtime position from: %s - %j",a.requestId,i,o);const e=n==null?void 0:n.list;if(!e)return m==null||m.warn("[%s] fetch realtime position failed: %j",a.requestId,i,n),n;for(const b in e)!isNaN(e[b])&&Number(e[b])!==1/0&&(e[b]=Number(e[b]));e.status=e.sp>3?0:1;const c=e.status,{labelCn:r,labelEn:u}=this.parseStatus(c),h=g(`${e.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:e.m,name:e.n,imo:e.imonumber,callSign:e.callsign,lat:Math.round(e.la/60*1e5)/1e5,lng:Math.round(e.lo/60*1e5)/1e5,length:e.l,width:e.w,draught:e.draught,sog:e.sp,cog:e.co,hdg:e.h,rot:isNaN(e.rot)?0:e.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta)?g.utc(e.eta).format():void 0,destination:e.destination,vesselType:e.type,dwt:e.dwt,build:e.buildyear,flag:e.fn,positionTime:h.unix(),utc:h.utc().format(),status:c,labelCn:r,labelEn:u,method:"position",vendor:"hifleet"}}async search(t,a={}){let i="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 n=await A.post(i,o).json();m==null||m.info("[%s] fetch vessel props from: %s - %j",a.requestId,i,o),n instanceof Array&&(n=n[0]);for(const c in n)!isNaN(n[c])&&Number(n[c])!==1/0&&(n[c]=Number(n[c]));const e={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 A.post(i,o).json(),m==null||m.info("[%s] search vessel dead weight from: %s - %j",a.requestId,i,o),n instanceof Array&&(n=n[0]),n&&(e.deadweight=Number(n.dwt)),e}async suggest(t,a={}){const i="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"}},n=await A.post(i,o).json();m==null||m.info("[%s] suggest vessel props from: %s - %j",a.requestId,i,o);const e=[];for(const c of n)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,a,i,o,n=!0,e={}){var d,p,f;const c=await this.realTimePosition(t,e);let r=g(a);const u=g(i),h=g();if(n){let l=u.diff(r,"d",!0);l<0?r=u.clone().subtract(40,"d"):l<30?r.subtract(10,"d"):l<60?r.subtract(5,"d"):r=u.clone().subtract(80,"d"),l=h.diff(u,"d",!0),u.add(l>10?240:l*24,"h")}const y={searchParams:{endtime:u.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}},b="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",M=await A.get(b,y).json();m==null||m.info("[%s] fetch trajectory from: %s - %j",e.requestId,b,y);let C;M&&(C=((p=(d=M.ships)==null?void 0:d.offors)==null?void 0:p.ship)||[],C.length||m==null||m.warn("[%s] fetch trajectory failed: %j",e.requestId,M));const S=[];let w=-1;const v=g(`${(f=C==null?void 0:C[0])==null?void 0:f.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const l of C){for(const L in l)!isNaN(l[L])&&Number(l[L])!==1/0&&(l[L]=Number(l[L]));const k=g(`${l.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");l.status=l.sp>4?0:1;const{labelEn:j,labelCn:x}=this.parseStatus(l.status),Y={mmsi:l.m,name:l.n,imo:c==null?void 0:c.imo,lat:l.la,lng:l.lo,draught:l.draught,sog:l.sp,cog:l.co,hdg:l.hdg,positionTime:k.unix(),utc:k.utc().format(),status:l.status,labelCn:x,labelEn:j,method:"trajectory",vendor:"hifleet"},F=Math.floor(k.diff(v,"minute",!0)/(o||1));F!==w&&(w=F,S.push(Y))}return S}}class Mt extends G{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,a={}){const i={searchParams:{id:t,k:this.token,enc:1}},o="https://api.shipxy.com/apicall/GetSingleShip",n=await A.get(o,i).json();if(m==null||m.info("[%s] fetch realtime position from: %s - %j",a.requestId,o,i),(n==null?void 0:n.status)!==0)return n;const e=n.data[0];for(const y in e)!isNaN(e[y])&&Number(e[y])!==1/0&&(e[y]=Number(e[y]));const{labelCn:c,labelEn:r}=await this.parseStatus(e.navistat),u=g.unix(e.lasttime);return{mmsi:e.ShipID,name:e.name,imo:e.imo,callSign:e.callsign,lat:Math.round(e.lat/1e6*1e5)/1e5,lng:Math.round(e.lon/1e6*1e5)/1e5,length:Math.round(e.length/10*100)/100,width:Math.round(e.width/10*100)/100,draught:Math.round(e.draught/1e3*100)/100,sog:Math.round(e.sog*3600/1e3/1852*100)/100,cog:Math.round(e.cog/100*100)/100,hdg:Math.round(e.hdg/100*100)/100,rot:Math.round(e.rot/100*100)/100,positionTime:e.lasttime,utc:u.utc().format(),status:e.navistat,labelEn:r,labelCn:c,method:"position",vendor:"shipxy"}}async trajectory(t,a,i,o,n=!0,e={}){var v;const c=await this.realTimePosition(t,e),r=g(a),u=g(i),h="https://api.shipxy.com/apicall/GetShipTrack",y={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:r.unix(),etm:u.unix()}},b=await A.get(h,y).json();if(m==null||m.info("[%s] fetch trajectory from: %s - %j",e.requestId,h,y),(b==null?void 0:b.status)!==0)return b;const M=b==null?void 0:b.points,C=[],S=g.unix((v=M[0])==null?void 0:v.utc);let w=-1;for(const d of M){const p=g.unix(d.utc),f={imo:c==null?void 0:c.imo,mmsi:t,sog:Math.round(d.sog*3600/1e3/1852*100)/100,cog:Math.round(d.cog/100*100)/100,lat:Math.round(d.lat/1e6*1e5)/1e5,lng:Math.round(d.lon/1e6*1e5)/1e5,positionTime:p.unix(),utc:p.utc().format(),method:"trajectory",vendor:"shipxy"},l=Math.floor(p.diff(S,"minute",!0)/(o||1));l!==w&&(w=l,C.push(f))}return C}}class pt extends G{constructor(t){super();K(this,"token");this.token=t}async getShipId(t,a={}){const i={headers:{appKey:this.token},json:{mmsiList:t}},o="https://api3.myships.com/sp/ships/getShipIdByMMSI",n=await A.post(o,i).json();return m==null||m.info("[%s] fetch ship id from: %s - %j",a.requestId,o,i),n.code!=="0"?n:n.data[0].shipId}async getShipInfo(t,a={}){const i={headers:{appKey:this.token},json:{shipId:t}},o="https://api3.myships.com/sp/ships/aissta",n=await A.post(o,i).json();if(m==null||m.info("[%s] fetch ship info from: %s - %j",a.requestId,o,i),n.code!=="0")return n;const e=n.data;let c=e.imo;return t==="407170"&&(c="9198379",m==null||m.warn("[%s] ship(%s) imo error: %s, should be %s",a.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,a={}){const i=await this.getShipId(t,a),o=await this.getShipInfo(i,a),n={headers:{appKey:this.token},json:{shipId:i}},e="https://api3.myships.com/sp/ships/position/latest",c=await A.post(e,n).json();m==null||m.info("[%s] fetch realtime position from: %s - %j",a.requestId,e,n);const r=c.data[0];for(const M in r)!isNaN(r[M])&&Number(r[M])!==1/0&&(r[M]=Number(r[M]));const{labelCn:u,labelEn:h}=await this.parseStatus(r.aisNavStatus),y=g.unix(r.posTime);return{...o,mmsi:t,lat:Math.round(r.lat/1e4/60*1e5)/1e5,lng:Math.round(r.lon/1e4/60*1e5)/1e5,sog:Math.round(r.sog/10*100)/100,cog:Math.round(r.cog/10*100)/100,hdg:Math.round(r.heading*100)/100,rot:Math.round(r.rot*100)/100,positionTime:r.posTime,utc:y.utc().format(),status:r.aisNavStatus,labelEn:h,labelCn:u,method:"position",vendor:"myship"}}async trajectory(t,a,i,o,n=!0,e={}){const c=g(a),r=g(i),u=await this.getShipId(t),h=await this.getShipInfo(u),y=[];for(;r.diff(c,"day",!0)>30;)await this.trajectoryIn30Day(u,c.unix(),c.add(30,"day").unix(),h,t,o,y);return await this.trajectoryIn30Day(u,c.unix(),r.unix(),h,t,o,y),y}async trajectoryIn30Day(t,a,i,o,n,e,c,r={}){var S;const u={headers:{appKey:this.token},json:{shipId:t,startTime:a,endTime:i}},h="https://api3.myships.com/sp/ships/position/history",y=await A.post(h,u).json();if(m==null||m.info("[%s] fetch trajectory from: %s - %j",r.requestId,h,u),y.code!=="0")return m==null||m.warn("[%s] invoke myship trajectory failed: %j",r.requestId,y),y;const b=y.data;for(const w in b)!isNaN(b[w])&&Number(b[w])!==1/0&&(b[w]=Number(b[w]));const M=g.unix((S=b[0])==null?void 0:S.posTime);let C=-1;for(const w of b){const v=g.unix(w.posTime),d={imo:o==null?void 0:o.imo,mmsi:n,lat:Math.round(w.lat/1e4/60*1e5)/1e5,lng:Math.round(w.lon/1e4/60*1e5)/1e5,sog:Math.round(w.sog/10*100)/100,cog:Math.round(w.cog/10*100)/100,hdg:Math.round(w.heading*100)/100,rot:Math.round(w.rot*100)/100,positionTime:v.unix(),utc:v.utc().format(),method:"trajectory",vendor:"myship"},p=Math.floor(v.diff(M,"minute",!0)/(e||1));p!==C&&(C=p,c.push(d))}return c}}let z;try{z=U.getLogger("vessel")}catch{}finally{}var ct=(D=>(D.NOTICE="NOTICE",D.WARN="WARN",D.HEAVY="HEAVY",D.SEVERE="SEVERE",D.ERROR="ERROR",D.FATAL="FATAL",D))(ct||{});class dt{parsePrinciple(s,t={}){var e,c,r;z==null||z.debug("[%s] parse rule: %s",t.requestId,s);const a=new RegExp("(?<=\\[)(.+)(?=])","g"),i=s.match(a)?(e=s.match(a))==null?void 0:e[0]:void 0,o=i==null?void 0:i.split(";");if(!o)return;const n={};for(let u=0;u<(o==null?void 0:o.length);u++){const h=(r=(c=o[u].match(a))==null?void 0:c[0])==null?void 0:r.split("],");if(u===0&&!h)n.scope=o[0];else if(h)for(let y=0,b=h.length;y<b;y++){const M=this.parseRule(h[y]);M&&(n[M.level]?M.key?n[M.level][M==null?void 0:M.key]=M:n[M.level]=M:M.key?n[M.level]={[M==null?void 0:M.key]:M}:n[M.level]=M)}}return n}parseRule(s,t={}){var n;z==null||z.debug("[%s] parse rule: %s",t.requestId,s),s=s.startsWith("[")?s:`[${s}`,s=s.endsWith("]")?s:`${s}]`;const a=new RegExp("(?<=\\[)(.+?)(?=])","g"),i=(n=s==null?void 0:s.match(a))==null?void 0:n[0],o=i==null?void 0:i.split(",");if(o){let e=o[3]==="Number.MAX_VALUE"?100:Number(o[3]);return e=isNaN(e)?1:e,{operator:o[0],number:Number.isNaN(Number(o[1]))?o[1]:Number(o[1]),level:o[2],time:e,key:o[4]}}}checkWeather(s,t,a={}){var M,C,S,w,v,d,p,f,l,k,j,x,Y,F,L;let i=0,o=0,n=0,e=0;const c=Math.round(((C=(M=t==null?void 0:t.SEVERE)==null?void 0:M.sigWave)==null?void 0:C.number)*1.6*100)/100,r=(w=(S=t==null?void 0:t.SEVERE)==null?void 0:S.sigWave)==null?void 0:w.number,u=(d=(v=t==null?void 0:t.HEAVY)==null?void 0:v.sigWave)==null?void 0:d.number,h=Math.round((((f=(p=t==null?void 0:t.SEVERE)==null?void 0:p.wind)==null?void 0:f.number)+2)*100)/100,y=(k=(l=t==null?void 0:t.SEVERE)==null?void 0:l.wind)==null?void 0:k.number,b=(x=(j=t==null?void 0:t.HEAVY)==null?void 0:j.wind)==null?void 0:x.number;for(let N=0;N<(s==null?void 0:s.length);N++){const E=s[N],P=(F=(Y=E==null?void 0:E.meteo)==null?void 0:Y.wave)==null?void 0:F.sig,V=(L=E==null?void 0:E.meteo)==null?void 0:L.wind,J=N?g(E.eta).diff(g(s[N-1].eta),"hour",!0):0;e=J>e?J:e,z==null||z.debug("[%s] check sig.wave: %j",a.requestId,{...P,dgThd4Wv:c,svThd4Wv:r,hvThd4Wv:u}),(P==null?void 0:P.height)>=c?E.isDangerous=!0:(P==null?void 0:P.height)>=r?E.isSevere=!0:(P==null?void 0:P.height)>=u&&(E.isHeavy=!0),z==null||z.debug("[%s] check wind: %j",a.requestId,{...V,dgThd4Wd:h,svThd4Wd:y,hvThd4Wd:b}),(V==null?void 0:V.scale)>=h?(E.isDangerous=!0,delete E.isSevere,delete E.isHeavy):(V==null?void 0:V.scale)>y?(E.isDangerous||(E.isSevere=!0),delete E.isHeavy):(V==null?void 0:V.scale)===b&&!E.isDangerous&&!E.isSevere&&(E.isHeavy=!0),i+=E.isDangerous?J:0,o+=E.isSevere?J:0,n+=E.isHeavy?J:0}return i=Math.round(i*100)/100,o=Math.round(o*100)/100,n=Math.round(n*100)/100,e=Math.round(e),{sample:s,dangerous:i,severe:o,heavy:n,step:e<3?3:e,wind:{dgThd4Wd:h,svThd4Wd:y,hvThd4Wd:b},sig:{dgThd4Wv:c,svThd4Wv:r,hvThd4Wv:u}}}}const bt=new dt;let I;try{I=U.getLogger("vessel")}catch{}finally{}const vt=new ft.MeteoHelper2("",!0);var ut=(D=>(D.common="common",D.container="container",D.tugs="tugs",D))(ut||{}),lt=(D=>(D.Ballast="Ballast",D.Laden="Laden",D))(lt||{}),ht=(D=>(D.Cp="CP",D.Perf="Basis",D.Instruct="Other",D))(ht||{});class W{static blockCoefficient(s,t,a,i){let o=Math.round(s/(t*a*i)*100)/100;o=o<.55?.55:o>.85?.85:o;const n=[.55,.6,.65,.7,.75,.8,.85],e=n.map(c=>Math.abs(c-o));return n[e.indexOf(Math.min(...e))]}static froudeNumber(s,t,a=9.8){let i=Math.round(Math.sqrt(s*s/(a*t))*100)/100;return i=i<.05?.05:i>.3?.3:i,i}static amendFactor(s,t,a){const i={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.4,-10.6,-9.5],.8:[2.6,-13.1,-15.1],.85:[3.1,-18.7,28]};let 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]}[s];return a==="Laden"&&(n=i[s]),n[0]+n[1]*t+n[2]*Math.pow(t,2)}static directionFactor(s,t=0){let a;return s>30&&s<=60?a=(1.7-.03*Math.pow(t-4,2))/2:s>60&&s<=150?a=(.9-.06*Math.pow(t-6,2))/2:s>150&&s<=180?a=(.4-.03*Math.pow(t-8,2))/2:a=1,Math.round(a*1e5)/1e5}static vesselTagFactor(s,t,a,i=0){i=i>6?i-.9*(i-6):i;let o;return a==="container"?o=.7*i+Math.pow(i,6.5)/(22*Math.pow(s,2/3)):t==="Ballast"?o=.7*i+Math.pow(i,6.5)/(2.7*Math.pow(s,2/3)):o=.5*i+Math.pow(i,6.5)/(2.7*Math.pow(s,2/3)),o}static waveHeightFactor(s,t){s=s<3?s*.7:s,s=s<0?.2:s,s=s>6?s-.9*(s-6):s,s=s>9?9:s;let a;return t>30&&t<=60?a=-.6:t>60&&t<=90?a=-.4:t>90&&t<=120?a=s<3?.4:-.3:t>120&&t<=150?a=s<3?.6:-.5:t>150&&t<=180?a=s<3?.7:-.6:a=-.7,Math.round(a*(.144*Math.pow(s,2)+.278*s)*1e4)/1e4}static assembleProperties(s,t,a,i){var y;const o=s.lbp??s.length??s.lengthOverall??198.9642,n=s.draught??8,e=s.breadthMoulded??s.breadth??s.breadthExtreme??32.4572,c=s.deadweight??67035.7773,r=((y=s==null?void 0:s.type)==null?void 0:y.toLowerCase())||"common";return{tag:r.indexOf("container")>-1?"container":r.indexOf("tugs")>-1?"tugs":"common",lbp:o,loadCondition:t,draught:n,breadthMoulded:e,displacement:Math.round((c/1.025+n*e*o*.7)*1e4)/1e4,speed:Math.round((a??14.1382)*1852/3600*1e4)/1e4,bearing:i||90}}static async speedLoseAt(s,t,a,i="",o=2,n=!0,e=!1,c={}){let r;if(t.velocity&&e&&(s.speed=H.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),n){let u;try{i=(i==null?void 0:i.toUpperCase())==="CMEMS"?"ECMWF":i,i=(i==null?void 0:i.toUpperCase())==="METEO2"?"best_match":i;const{weatherModels:M,marineModels:C}=await nt.Meteo2Assist.autoPickMeteoModel(i),S=await vt.spotForecast(t.lat,t.lng,a.utc().format(),!1,!1,!0,{...c,pastDays:1,forecastDays:1,weatherModels:M,marineModels:C}),[w]=nt.Meteo2Assist.pickHourly(S,a);u=nt.Meteo2Assist.toLegacy(w)}catch(M){I.warn("[%s] meteo2 spot(%j) forecast failed: %s",c.requestId,{...t,eta:a.utc().format(),source:i},M)}const h=W.weatherFactor(s,u),y=W.currentFactor(s.bearing,u==null?void 0:u.current,o),b=Math.round((s.speed*1.943844+h+y)*100)/100;r={meteo:{...u},wxFactor:h,cFactor:y,speed:t.velocity&&e?t.velocity:b<0?1:b,eta:a.utc().format(),etd:a.utc().format()}}else r={wxFactor:0,cFactor:0,speed:t.velocity&&e?t.velocity:Math.round((s.speed*1.943844+0+0)*100)/100,eta:a.utc().format(),etd:a.utc().format()};return delete t.meteo,delete t.wxFactor,delete t.cFactor,delete t.speed,delete t.etd,{...r,...t}}static async speedLoseInHoursStep(s,t,a,i,o,n,e="",c=!0,r=!1,u={}){t.utc();const h=t.clone().add(14,"days"),y=[],b=[];let M=0,C=0,S,w;for(let v=0;v<n.length-1;v++){let d=n[v];d.distanceFromStart=Math.round((o+C)*1e3)/1e3;const p=n[v+1];if(s.bearing=H.LaneHelper.calculateBearing(d,p,!p.gcToPrevious),d.bearing=s.bearing,d.suspend&&r){d.eta=d.eta||t.utc().format(),d.elapsed=d.elapsed??0;const k=d.suspend-d.elapsed;if(i-M>k)i=i-M-k,t.add(k,"hour"),d.elapsed=d.suspend;else{const j=i-M;d.elapsed+=j,t.add(j,"hour"),i=0}if(I==null||I.info(`[%s] suspend ${d.elapsed} hours at %j, and remain ${i} hours need to go...`,u.requestId,d),i===0)return d.distanceFromPrevious=C,{etd:t,from:w||d,to:d,next:n.filter(j=>j),wps:y,days:b}}else d.suspend=0;c=t.isAfter(h)?!1:c,d=await W.speedLoseAt(s,d,t,e,0,c,r,u),w=w||d,d.important&&y.push(d),t.isSameOrAfter(a)&&(b.push(d),a.add(24,"hour"));const f=H.LaneHelper.calculateDistance(d,p,!p.gcToPrevious);let l=Math.round(f/w.speed*1e5)/1e5;if(M+l<i){if(M+=l,t.add(l,"hour"),delete n[v],I==null||I.debug(`[%s] go to %j from %j with ${f}nm, and cost ${l} hours`,u.requestId,{lat:p.lat,lng:p.lng},{lat:w.lat,lng:w.lng,etd:w.etd}),C+=f,n.filter(k=>k).length<=1){S=p,S.eta=t.utc().format(),S.distanceFromPrevious=f,S.distanceFromStart=Math.round((o+C)*1e4)/1e4,y.push(S),delete n[v+1];break}}else{l=i-M,t.add(l,"hour");const k=H.LngLatHelper.roundPrecision(w.speed*l,5);S=H.LaneHelper.calculateCoordinate(d,s.bearing,k,"nauticalmiles",!p.gcToPrevious),S.eta=t.utc().format(),n[v]=S,I==null||I.debug(`[%s] go to %j from %j with ${k}nm, and cost ${l} hours`,u.requestId,{lat:S.lat,lng:S.lng},{lat:d.lat,lng:d.lng,etd:d.etd}),C+=k,S.distanceFromPrevious=Math.round(C*1e4)/1e4,S.distanceFromStart=Math.round((o+C)*1e4)/1e4;break}}return{etd:t,from:w,to:S,next:n.filter(v=>v),wps:y,days:b}}static currentFactor(s,t,a=0){const i=(s-(t==null?void 0:t.degree)||0)/180*Math.PI;if(Math.abs(i)===Math.PI/2)return 0;let o=((t==null?void 0:t.kts)||0)*Math.cos(i);return a&2?o=Math.ceil(o*100)/100:a&1?o=Math.floor(o*100)/100:o=Math.round(o*100)/100,Math.abs(o)>5?0:o}static weatherFactor(s,t){var h,y,b,M,C,S,w;I==null||I.debug("calculate weather factor via: %j",{...s,...t});const a=W.blockCoefficient(s.displacement,s.lbp,s.breadthMoulded,s.draught),i=W.froudeNumber(s.speed,s.lbp),o=W.amendFactor(a,i,s.loadCondition);let n=Math.abs(s.bearing%360-(((h=t==null?void 0:t.wind)==null?void 0:h.degree)%360||0));n=n>180?360-n:n;const e=W.directionFactor(n,(y=t==null?void 0:t.wind)==null?void 0:y.scale),c=W.vesselTagFactor(s.displacement,s.loadCondition,s.tag,(b=t==null?void 0:t.wind)==null?void 0:b.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)),I==null||I.debug("wind wx factor = %d",r),n=Math.abs(s.bearing%360-(((C=(M=t==null?void 0:t.wave)==null?void 0:M.sig)==null?void 0:C.degree)%360||0));const u=W.waveHeightFactor(((w=(S=t==null?void 0:t.wave)==null?void 0:S.sig)==null?void 0:w.height)??1,n);return I==null||I.debug("wave wx factor = %d",u),r=Math.abs(r)>Math.abs(u)?r:r*.3+u*.7,I==null||I.debug("weather factor = %d",r),r=Math.abs(r)>3?3*(Math.abs(r)/r)+Math.abs(r)/r*(Math.abs(r)-2)*.1:r,Math.round((r||0)*100)/100}static async analyseInstant(s,t,a,i,o,n="",e=0,c=!0,r=!1,u={}){var X,Q,Z,$,tt,et;const h=g().valueOf();s.lng=H.LngLatHelper.convertToStdLng(s.lng);const{route:y,waypoints:b}=o.points,M=H.LaneHelper.calculateSubRoute(s,y);if(((X=M[0])==null?void 0:X.length)<=1)return;const{v0:C,label:S}=s.sog?{v0:s.sog,label:s.label||"Other"}:{v0:i.speed,label:"CP"},w=W.assembleProperties(a,i.loadCondition,C,0),v=b.length?H.LaneHelper.calculateSubWaypoints(s,b):[];v.forEach(O=>O.important=!0);const d={from:{...s},route:M,waypoints:v,v0:C,label:S},p={hours:[],days:[],wps:[]};e||(H.LaneHelper.calculateRouteDistance(M)/i.speed<=72?e=3:e=6);let f=H.LaneHelper.simplifyRouteToCoordinates(M,v,0),l=0,k=0,j=0,x=0;t=g(t).utc();const Y=t.clone();for(;f.length>0;){const O=e-t.hour()%e,_=Math.ceil(t.clone().add(O,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,T=await W.speedLoseInHoursStep(w,t,Y,_,l,f,n,c,r,u);(Q=T.from)!=null&&Q.speed&&(p.hours.push(T.from),p.wps.push(...T.wps),p.days.push(...T.days)),f=T==null?void 0:T.next,f.length||p.hours.push(T==null?void 0:T.to),l+=Math.round((((Z=T==null?void 0:T.to)==null?void 0:Z.distanceFromPrevious)??0)*1e4)/1e4}const F=p.hours;for(let O=0;O<F.length-1;O++){const _=g(F[O+1].eta).diff(F[O].etd,"hour",!0)||1;k+=(F[O].wxFactor||0)*_,j+=(F[O].cFactor||0)*_,x+=_}($=p.wps)==null||$.forEach((O,_)=>{O.positionTime=g.utc(O.etd||O.eta).unix();const T=p.wps[_-1];if(T){const B=O.distanceFromStart-T.distanceFromStart,R=g(O.eta||O.etd).diff(g(T.etd||T.eta),"h",!0);O.avgSpd=Math.round(B/R*100)/100,T.bearing=H.LaneHelper.calculateBearing(T,O)}}),p.wps=(tt=p.wps)==null?void 0:tt.reduce((O,_)=>(O.some(T=>Math.round(T.positionTime/60)===Math.round(_.positionTime/60))||O.push(_),O),[]),d.sample=p;const L=p.hours.at(0),N=p.hours.at(-1);d.distance=Math.round(N.distanceFromStart*1e3)/1e3,d.etd=g(L.eta).utc().format(),d.eta=g(N.eta).utc().format(),d.wxFactor=Math.round(k/x*1e3)/1e3,d.cFactor=Math.round(j/x*1e3)/1e3,d.avgSpeed=Math.round(N.distanceFromStart/x*1e3)/1e3,d.totalHrs=Math.round(x*1e3)/1e3;const{distanceInECA:E,hoursInECA:P,totalDgoConsInECA:V,eca:J}=await this.calculateECA(d,i,u),st=H.LngLatHelper.roundPrecision(i.fo/24*(x-P),3),ot=H.LngLatHelper.roundPrecision(i.dgo/24*x,3);d.extend={eca:J,distanceInECA:E,hoursInECA:P,totalDgoConsInECA:V},d.totalFoCons=st<0?0:st,d.totalDgoCons=ot;const at=g().valueOf()-h,rt=((et=p==null?void 0:p.hours)==null?void 0:et.length)||1;return I==null||I.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",u==null?void 0:u.requestId,at,rt,Math.round(at/rt*1e3)/1e3),d}static async analyseInstantWithThreshed(s,t,a,i,o,n,e,c="",r=3,u=!0,h=!1,y={}){var Z,$,tt,et,O,_;const b=g().valueOf();s.lng=H.LngLatHelper.convertToStdLng(s.lng);const{v0:M,label:C}=s.sog?{v0:s.sog,label:s.label||"Other"}:{v0:o.speed,label:"CP"},S=W.assembleProperties(i,o.loadCondition,M,0),w=H.LaneHelper.calculateSubRoute(s,n);if(((Z=w[0])==null?void 0:Z.length)<=1)return;const v=e.length?H.LaneHelper.calculateSubWaypoints(s,e):[];v.forEach(T=>T.important=!0);let d=H.LaneHelper.simplifyRouteToCoordinates(w,v,0),p=0,f=0,l=0,k=0;const j={hours:[],wps:[],days:[]};t=g(t).utc();const x=t.clone();for(;d.length>0;){const T=r-t.hour()%r;let B=Math.ceil(t.clone().add(T,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;B=t.clone().add(B,"h").isSameOrAfter(a)?a.diff(t,"h",!0)*1e4/1e4:B;const R=await W.speedLoseInHoursStep(S,t,x,B,p,d,c,u,h,y);if(($=R.from)!=null&&$.speed&&(j.hours.push(R.from),R!=null&&R.wps&&j.wps.push(...R.wps),j.days.push(...R.days)),d=R==null?void 0:R.next,d.length||j.hours.push(R==null?void 0:R.to),p+=Math.round((((tt=R==null?void 0:R.to)==null?void 0:tt.distanceFromPrevious)??0)*1e4)/1e4,!B)break}j.wps=(et=j.wps)==null?void 0:et.reduce((T,B)=>(T.some(R=>Math.round(g(R.etd).unix()/60)===Math.round(g(B.etd).unix()/60))||T.push(B),T),[]),(O=j.wps)==null||O.forEach((T,B)=>{const R=j.wps[B-1];if(R){const gt=T.distanceFromStart-R.distanceFromStart,wt=g(T.eta||T.etd).diff(g(R.etd||R.eta),"h",!0);T.avgSpd=Math.round(gt/wt*100)/100;const kt=H.LaneHelper.calculateBearing(R,T);R.bearing=kt}});const Y=j.hours;for(let T=0;T<Y.length-1;T++){const B=g(Y[T+1].eta).diff(Y[T].etd,"hour",!0);f+=Y[T].wxFactor*B,l+=Y[T].cFactor*B,k+=B}const F=j.hours.at(0),L=j.hours.at(-1),N=await H.LaneHelper.calculateRangeRoute(F,L,w),E=await H.LaneHelper.calculateRangeWaypoints(F,L,w,v),P={sample:j,distance:Math.round(((L==null?void 0:L.distanceFromStart)||0)*1e4)/1e4,etd:g(F.eta).utc().format(),eta:g(L==null?void 0:L.eta).utc().format(),wxFactor:Math.round(f/k*1e3)/1e3,cFactor:Math.round(l/k*1e3)/1e3,avgSpeed:Math.round(((L==null?void 0:L.distanceFromStart)||0)/k*1e3)/1e3,totalHrs:Math.round(k*1e3)/1e3,from:F,to:L,route:N,waypoints:E,v0:M,label:C},{distanceInECA:V,hoursInECA:J,totalDgoConsInECA:st,eca:ot}=await this.calculateECA(P,o,y),it=H.LngLatHelper.roundPrecision(o.fo/24*(k-J),3),at=H.LngLatHelper.roundPrecision(o.dgo/24*k,3);P.extend={eca:ot,distanceInECA:V,hoursInECA:J,totalDgoConsInECA:st},P.totalDgoCons=at,P.totalFoCons=it<0?0:it;const X=g().valueOf()-b,Q=((_=j==null?void 0:j.hours)==null?void 0:_.length)||1;return I==null||I.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",y==null?void 0:y.requestId,X,Q,Math.round(X/Q*1e3)/1e3),P}static async analyseCost(s,t,a,i,o={}){var w,v;const n=g().valueOf(),e=[];s.speedStep=s.speedStep||3,s.alterStep=s.alterStep??1;const c=H.LaneHelper.calculateRouteDistance(i.route);let r=0;a.forEach(d=>{const p=Math.ceil(c/d.speed/24);r=r<p?p:r}),r=r*1.3;const u=g.utc(s.etd).add(r??14,"day");let h=1;for(const d of a){const p=JSON.parse(JSON.stringify(i.route)),f=JSON.parse(JSON.stringify(i.waypoints)),l=await W.analyseInstantWithThreshed({lat:s.lat,lng:s.lng},s.etd,u,t,d,p,f,s.meteoVendor,s.speedStep,s.useMeteo,s.useRouteParam,o);l&&(await W.calculateCost(l,d,s,o),e.push(l),I==null||I.info("[%s][L%d-%d] analyse from %s to %s cost: %j",o.requestId,1,h,s.etd,u.format(),{cost:l.cost.total,hire:l.cost.hire,bunker:l.cost.bunker,distance:l.distance,hours:l.totalHrs,cp:`${d.speed}/${d.fo}/${d.dgo}`})),h++}e.sort((d,p)=>d.cost.total-p.cost.total);const y=e.at(0),b=e.at(1),M=[];if(M.push({combined:!1,speeds:[y],cost:(w=y.cost)==null?void 0:w.total}),b){const d=y.cost.cp,p=b.cost.cp,f=g(y.eta),l=g(y.etd),k=f.diff(l,"days",!0);let j=Math.ceil(k/2);j=j>7?7:j<s.alterStep?s.alterStep:j;let x=2,Y={combined:!1,speeds:[b],cost:(v=b.cost)==null?void 0:v.total},F;for(;j>=s.alterStep;){const L=await W.combinedAnalyse(s,t,u,[d,p],i,j,{...o,level:x});if(Y.cost>L.cost?F?(F==null?void 0:F.cost)>L.cost&&(F=L):(F=Y,Y=L):(!F||(F==null?void 0:F.cost)>L.cost)&&(F=L),j<=s.alterStep)break;j=Math.ceil(j/2),x+=1}M.push(Y),F&&M.push(F)}const S=g().valueOf()-n;return I==null||I.info("[%s] analyse elapsed: %d ms",o==null?void 0:o.requestId,S),M.sort((d,p)=>d.cost-p.cost)}static async combinedAnalyse(s,t,a,i,o,n,e={}){e.counter=1,I==null||I.info("[%s][L%d] analyse with alternate cp in every %d days",e.requestId,e.level,n);const c=await W.alternateAnalyse(s,t,a,i,0,o,n,e),r=c.reduce((p,f)=>p+f.cost.total,0),u=c.reduce((p,f)=>p+f.cost.hire,0),h=c.reduce((p,f)=>p+f.cost.bunker,0),y=c.reduce((p,f)=>p+f.distance,0),b=c.reduce((p,f)=>p+f.totalHrs,0);I==null||I.info("[%s][L%d] cost with cpa/cpb turn: %j",e.requestId,e.level,{cost:r,hire:u,bunker:h,distance:y,hours:b});const M=await W.alternateAnalyse(s,t,a,i,1,o,n,e),C=M.reduce((p,f)=>p+f.cost.total,0),S=M.reduce((p,f)=>p+f.cost.hire,0),w=M.reduce((p,f)=>p+f.cost.bunker,0),v=M.reduce((p,f)=>p+f.distance,0),d=M.reduce((p,f)=>p+f.totalHrs,0);return I==null||I.info("[%s][L%d] cost with cpb/cpa turn: %j",e.requestId,e.level,{cost:C,hire:S,bunker:w,distance:v,hours:d}),r<C?{combined:!0,cost:Math.round(r*1e3)/1e3,speeds:c,step:n}:{combined:!0,cost:Math.round(C*1e3)/1e3,speeds:M,step:n}}static async alternateAnalyse(s,t,a,i,o,n,e,c={}){var y,b;let r=g.utc(s.etd);const u={lat:s.lat,lng:s.lng},h=[];for(;r.isBefore(a);){const M=r.clone().utc().add(e,"day"),C=JSON.parse(JSON.stringify(n.route)),S=JSON.parse(JSON.stringify(n.waypoints)),w=i[o],v=await W.analyseInstantWithThreshed(u,r.utc().format(),M,t,w,C,S,s.meteoVendor,s.speedStep,s.useMeteo,s.useRouteParam,c);v&&(await W.calculateCost(v,w,s,c),I==null||I.info("[%s][L%d-%d] analyse from %s to %s cost: %j",c.requestId,c.level,c.counter,r.utc().format(),M.utc().format(),{cost:v.cost.total,hire:v.cost.hire,bunker:v.cost.bunker,distance:v.distance,hours:v.totalHrs,cp:`${w.speed}/${w.fo}/${w.dgo}`})),c.counter=c.counter+1;const d=(b=(y=v==null?void 0:v.sample)==null?void 0:y.hours)==null?void 0:b.at(-1);if(d)u.lat=d.lat,u.lng=d.lng,r=g(d.eta),h.push(v),o=o?0:1;else break}return h}static async calculateCost(s,t,a,i={}){var o;if(s){const n=(a.addComm||0)>=1?(a.addComm||0)/100:a.addComm||0,e=Math.round(s.totalHrs/24*(a.dailyHire||0)*(1-n)*1e3)/1e3,c=Math.round(s.totalFoCons*(a.priceFO||0)*1e3)/1e3,r=Math.round((s.totalDgoCons+(((o=s.extend)==null?void 0:o.totalDgoConsInECA)||0))*(a.priceDGO||0)*1e3)/1e3;s.cost={total:Math.round((e+c+r)*1e3)/1e3,hire:e,bunker:Math.round((c+r)*1e3)/1e3,cp:t}}return s}static async calculateECA(s,t,a={}){var c,r,u,h;const i=await H.LaneHelper.intersectInECA((s==null?void 0:s.route)||[]);let o=0,n=0,e=0;(r=(c=s==null?void 0:s.sample)==null?void 0:c.wps)==null||r.forEach(y=>{y.positionTime=g.utc(y.etd||y.eta).unix()});for(const y of i){o+=y.distance;const b=await H.LaneHelper.deadReckoningTime((u=y.waypoints)==null?void 0:u.at(0),s.sample.wps),M=await H.LaneHelper.deadReckoningTime((h=y.waypoints)==null?void 0:h.at(-1),s.sample.wps);y.in=b,y.out=M,y.totalHrs=H.LngLatHelper.roundPrecision((M.positionTime-b.positionTime)/3600,3),y.totalDgoCons=H.LngLatHelper.roundPrecision(t.fo/24*y.totalHrs,3),n+=y.totalHrs,e+=y.totalDgoCons}return o=H.LngLatHelper.roundPrecision(o,3),n=H.LngLatHelper.roundPrecision(n,3),e=H.LngLatHelper.roundPrecision(e,3),{distanceInECA:o,hoursInECA:n,totalDgoConsInECA:e,eca:i}}static async mergeSpeeds(s,t={}){var d,p;const a={hours:[],wps:[],days:[]},i=s.reduce((f,l)=>f+l.distance,0),o=s.reduce((f,l)=>{var k;return f+(((k=l.extend)==null?void 0:k.distanceInECA)||0)},0),n=s.reduce((f,l)=>f+l.totalHrs,0),e=s.reduce((f,l)=>{var k;return f+(((k=l.extend)==null?void 0:k.hoursInECA)||0)},0),c=s.reduce((f,l)=>{var k;return f+(((k=l.extend)==null?void 0:k.totalDgoConsInECA)||0)},0),r=s.reduce((f,l)=>f+l.wxFactor*l.totalHrs/n,0),u=s.reduce((f,l)=>f+l.cFactor*l.totalHrs/n,0),h=s.reduce((f,l)=>f+l.totalFoCons,0),y=s.reduce((f,l)=>f+l.totalDgoCons,0),b=s.reduce((f,l)=>f+l.cost.total,0),M=s.reduce((f,l)=>f+l.cost.hire,0),C=s.reduce((f,l)=>f+l.cost.bunker,0),S=[],w=[];let v;for(const f of s){w.push(...((d=f.extend)==null?void 0:d.eca)||[]);const l=f.sample.hours,k=f.sample.wps,j=f.sample.days,x=l.at(0);v&&(x.distanceFromPrevious=v.distanceFromPrevious,x.distanceFromStart=v.distanceFromStart,l.forEach((N,E)=>{E&&(N.distanceFromStart=N.distanceFromStart+v.distanceFromStart)}),k.at(0).distanceFromPrevious=v.distanceFromPrevious,k.at(0).distanceFromStart=v.distanceFromStart,k.forEach((N,E)=>{E&&(N.distanceFromStart=N.distanceFromStart+v.distanceFromStart)}),j.at(0).distanceFromPrevious=v.distanceFromPrevious,j.at(0).distanceFromStart=v.distanceFromStart,j.forEach((N,E)=>{E&&(N.distanceFromStart=N.distanceFromStart+v.distanceFromStart)})),x.cp=f.cost.cp;const Y=[f.etd,f.eta],F=S.findIndex(N=>N.id===x.cp.id);F===-1?(x.cp.segment=[Y],S.push(x.cp)):S[F].segment.push(Y),l.forEach(N=>{var P;((P=a.hours)==null?void 0:P.findIndex(V=>V.eta===N.eta))===-1&&a.hours.push(N)}),k.forEach(N=>{var P;((P=a.wps)==null?void 0:P.findIndex(V=>V.eta===N.eta))===-1&&a.wps.push(N)}),j.forEach(N=>{var P;((P=a==null?void 0:a.days)==null?void 0:P.findIndex(V=>V.eta===N.eta))===-1&&a.days.push(N)});const L=(p=a.wps)==null?void 0:p.findIndex(N=>N.eta===x.eta);L===-1?a.wps.push(x):a.wps[L]=x,v=l.at(-1)}return a.wps.sort((f,l)=>{g(f.etd).unix()-g(l.etd).unix()}),a.wps.forEach((f,l)=>{const k=a.wps[l-1];if(k){const j=f.distanceFromStart-(k.distanceFromStart||0),x=g(f.eta||f.etd).diff(g(k.etd||k.eta),"hour",!0),Y=Math.round(j/x*100)/100;f.avgSpd=Y;const F=H.LaneHelper.calculateBearing(k,f);k.bearing=F}}),{sample:a,etd:s.at(0).etd,eta:s.at(-1).eta,from:s.at(0).from,to:s.at(-1).to,v0:s.at(0).v0,label:"Combined",distance:Math.round(i*1e3)/1e3,totalHrs:Math.round(n*1e3)/1e3,avgSpeed:Math.round(i/n*1e3)/1e3,wxFactor:Math.round(r*1e3)/1e3,cFactor:Math.round(u*1e3)/1e3,totalFoCons:Math.round(h*1e3)/1e3,totalDgoCons:Math.round(y*1e3)/1e3,cost:{total:Math.round(b*1e3)/1e3,hire:Math.round(M*1e3)/1e3,bunker:Math.round(C*1e3)/1e3},extend:{cps:S,eca:w,distanceInECA:Math.round(o*1e3)/1e3,hoursInECA:Math.round(e*1e3)/1e3,totalDgoConsInECA:Math.round(c*1e3)/1e3,speeds:s}}}}q.AISImpl=G,q.AlertHelper=dt,q.AlertLevel=ct,q.HifleetImpl=yt,q.LoadCondition=lt,q.MyShipImpl=pt,q.MyVesselImpl=mt,q.ShipxyImpl=Mt,q.SpeedHelper=W,q.SpeedLabel=ht,q.VesselTag=ut,q.alertHelper=bt,Object.defineProperty(q,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(q,A){typeof exports=="object"&&typeof module<"u"?A(exports,require("got"),require("@log4js-node/log4js-api"),require("moment"),require("@idm-plugin/geo2"),require("@idm-plugin/meteo2"),require("@idm-plugin/meteo")):typeof define=="function"&&define.amd?define(["exports","got","@log4js-node/log4js-api","moment","@idm-plugin/geo2","@idm-plugin/meteo2","@idm-plugin/meteo"],A):(q=typeof globalThis<"u"?globalThis:q||self,A(q["idm-plugin-vessel"]={},q.got,q["@log4js-node/log4js-api"],q.moment,q["@idm-plugin/geo2"],q["@idm-plugin/meteo2"],q["@idm-plugin/meteo"]))})(this,function(q,A,U,g,H,ft,nt){"use strict";var It=Object.defineProperty;var St=(q,A,U)=>A in q?It(q,A,{enumerable:!0,configurable:!0,writable:!0,value:U}):q[A]=U;var K=(q,A,U)=>(St(q,typeof A!="symbol"?A+"":A,U),U);let m;try{m=U.getLogger("vessel")}catch{}finally{}class G{parseStatus(s){let t,a;switch(s){case 0:t="在航(主机推动)",a="Underway Using Engine";break;case 1:t="锚泊",a="Anchored";break;case 2:t="失控",a="Not under command";break;case 3:t="操纵受限",a="Limited airworthiness";break;case 4:t="吃水受限",a="Limited by ship's draft";break;case 5:t="靠泊",a="Mooring";break;case 6:t="搁浅",a="Stranded";break;case 7:t="捕捞作业",a="Engaged in fishing";break;case 8:t="靠帆船提供动力",a="Sailing";break;default:t="未定义",a="Undefined"}return{labelCn:t,labelEn:a}}}class mt extends G{constructor(t,a){super();K(this,"clientId");K(this,"clientSecret");K(this,"token");this.clientId=t,this.clientSecret=a}async authToken(t={}){const a="https://svc.data.myvessel.cn/ada/oauth/token",i={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},o=await A.post(a,i).json();m==null||m.info("[%s] fetch access token from: %s - %j",t.requestId,a,o),o.error||(this.token={accessToken:o.access_token,tokenType:o.token_type,expiresIn:o.expires_in,scope:o.scope,jti:o.jti,issuedAt:g().utc().format()})}async checkToken(t={}){var a;return(!this.token||g().diff(g(this.token.issuedAt),"seconds")>(((a=this.token)==null?void 0:a.expiresIn)||0)-300)&&await this.authToken(t),this.token}async suggest(t,a={}){var e,c;await this.checkToken(a);const i="https://market.myvessel.cn/sdc/v1/mkt/vessels/fuzzy",o={headers:{Authorization:`${(e=this.token)==null?void 0:e.tokenType} ${(c=this.token)==null?void 0:c.accessToken}`},json:{kw:t,recordNum:a.ps||10}};m==null||m.info("[%s] fetch suggest vessels from: %s - %j",a.requestId,i,o);const n=await A.post(i,o).json();return n.status!==200?(m==null||m.warn("[%s] fetch suggest vessels failed: %j",a.requestId,{message:n.message,status:n.status,code:n.code}),[]):(n.data||[]).map(u=>({mmsi:u.mmsi,name:u.nameEn,nameCn:u.nameCn,imo:Number.isNaN(u.imo)?null:Number(u.imo),callSign:u.callsign,type:u.vesselTypeNameEn,flagName:u.flagCtry,vendor:"myvessel",raw:u}))}async search(t,a={}){var r,u;await this.checkToken(a);const i=/^\d{7}$/.test(t.toString()),o=i?"https://market.myvessel.cn/sdc/v1/mkt/vessels/detail/imo":"https://market.myvessel.cn/sdc/v1/mkt/vessels/detail/mmsi",n=i?{imo:t}:{mmsi:t},e={headers:{Authorization:`${(r=this.token)==null?void 0:r.tokenType} ${(u=this.token)==null?void 0:u.accessToken}`},searchParams:n};m==null||m.info("[%s] fetch vessel from: %s - %j",a.requestId,o,e);const c=await A.get(o,e).json();if(c.status!==200)return m==null||m.warn("[%s] fetch suggest vessels failed: %j",a.requestId,{message:c.message,status:c.status,code:c.code}),{};{const h=c.data;if(h)return{mmsi:h.mmsi,imo:Number.isNaN(h.imo)?null:Number(h.imo),callSign:h.callsign,name:h.nameEn,nameCn:h.nameCn,type:h.vesselTypeNameEn,flagName:h.flagCtry,clasz:h.classSociety,dateOfBuild:h.buildYearMonth,deadweight:h.dwt,grossTonnage:h.grt,netTonnage:h.net,teu:h.teu,length:h.length,breadth:h.width,height:h.height,draught:h.draught,speed:h.speed,passengerCapacity:h.passengercapacity,vendor:"myvessel",raw:h}}return{}}async archives(t,a={}){var e,c;await this.checkToken(a);const i="https://svc.data.myvessel.cn/sdc/v1/ship/info/batch",o={headers:{Authorization:`${(e=this.token)==null?void 0:e.tokenType} ${(c=this.token)==null?void 0:c.accessToken}`},json:{mmsiList:typeof t=="number"?[t]:t}};m==null||m.info("[%s] fetch vessel archive from: %s - %j",a.requestId,i,o);const n=await A.post(i,o).json();return n.status!==200?(m==null||m.warn("[%s] fetch vessel archive failed: %j",a.requestId,{message:n.message,status:n.status,code:n.code}),{}):n.data}async realTimePosition(t,a={}){var c,r;await this.checkToken(a);const i="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",o={headers:{Authorization:`${(c=this.token)==null?void 0:c.tokenType} ${(r=this.token)==null?void 0:r.accessToken}`},searchParams:{mmsi:t}};m==null||m.info("[%s] fetch realtime position from: %s - %j",a.requestId,i,o);const n=await A.get(i,o).json();if(n.code)return m==null||m.warn("[%s] fetch realtime position failed: %j",a.requestId,{message:n.message,status:n.status,code:n.code}),n;const e=n.data;for(const u in e)!isNaN(e[u])&&Number(e[u])!==1/0&&(e[u]=Number(e[u]));if(e){const u=g(`${e.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:e.mmsi,name:e.vesselName||e.aisVesselName,imo:e.imo,callSign:e.callsign||e.aisCallSign,lat:e.lat,lng:e.lon,length:e.length,width:e.width,draught:e.currDraught,sog:e.sog,cog:e.cog,hdg:e.hdg,rot:e.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta)?g.utc(e.eta).format():void 0,destination:e.dest,positionTime:u.unix(),status:e.status,labelCn:e.statusNameCn,labelEn:e.statusNameEn,vesselType:e.vesselTypeNameEn,flag:e.flagCtryNameEn,clasz:e.classSociety,build:e.buildYear,dwt:e.dwt,grt:e.grt,net:e.net,method:"position",vendor:"myVessel",utc:u.utc().format()}}else return{}}async calculateRoute(t,a,i={}){var c,r;await this.checkToken(i);const o="https://svc.data.myvessel.cn/sdc/v1/routes/routing/nodes",n={headers:{Authorization:`${(c=this.token)==null?void 0:c.tokenType} ${(r=this.token)==null?void 0:r.accessToken}`},json:{startPoint:{lon:t.lng,lat:t.lat},endPoint:{lon:a.lng,lat:a.lat},maxDraught:i.maxDraught||10,useAIModel:i.useAIModel||!1,withECA:i.withECA||!1}};m==null||m.info("[%s] fetch route from: %s - %j",i.requestId,o,n);const e=await A.post(o,n).json();return e.status!==200?(m==null||m.warn("[%s] fetch route failed: %j",i.requestId,{message:e.message,status:e.status,code:e.code}),{}):e.data}async trajectory(t,a,i,o,n=!0,e={}){await this.checkToken(e);const c=await this.realTimePosition(t,e),r=g(a),u=g(i),h=[];for(;u.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(t,r,r.clone().add(30,"day"),c,o,h,e),r.add(30,"day");return await this.trajectoryIn30Day(t,r,u,c,o,h,e),h}async trajectoryIn30Day(t,a,i,o,n,e,c={}){var M,C,S,w,v;const r="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",u={headers:{Authorization:`${(M=this.token)==null?void 0:M.tokenType} ${(C=this.token)==null?void 0:C.accessToken}`},json:{mmsi:t,startTime:a.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};m==null||m.info("[%s] fetch trajectory from: %s - %j",c.requestId,r,u);const h=await A.post(r,u).json();if(h.code)return m==null||m.warn("[%s] fetch trajectory failed: %j",c.requestId,r,{message:h.message,status:h.status,code:h.code}),h;let y=-1;const b=g(`${(w=(S=h.data)==null?void 0:S[0])==null?void 0:w.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(v=h.data)==null||v.forEach(d=>{for(const Y in d)!isNaN(d[Y])&&Number(d[Y])!==1/0&&(d[Y]=Number(d[Y]));const p=g(`${d.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),f=d.status,{labelCn:l,labelEn:k}=this.parseStatus(f),j={mmsi:d.mmsi,imo:o==null?void 0:o.imo,lat:d.lat,lng:d.lon,sog:d.sog,cog:d.cog,hdg:d.hdg,draught:d.draught,status:f,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(d.eta)?g(`${d.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").utc().format():void 0,destination:d.dest,positionTime:p.unix(),labelCn:l,labelEn:k,method:"trajectory",vendor:"myVessel",utc:p.utc().format()},x=Math.floor(p.diff(b,"minute",!0)/(n||1));x!==y&&(y=x,e.push(j))}),e}}class yt extends G{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,a={}){const i="https://api.hifleet.com/position/position/get/token",o={searchParams:{mmsi:t,usertoken:this.token}},n=await A.post(i,o).json();m==null||m.info("[%s] fetch realtime position from: %s - %j",a.requestId,i,o);const e=n==null?void 0:n.list;if(!e)return m==null||m.warn("[%s] fetch realtime position failed: %j",a.requestId,i,n),n;for(const b in e)!isNaN(e[b])&&Number(e[b])!==1/0&&(e[b]=Number(e[b]));e.status=e.sp>3?0:1;const c=e.status,{labelCn:r,labelEn:u}=this.parseStatus(c),h=g(`${e.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:e.m,name:e.n,imo:e.imonumber,callSign:e.callsign,lat:Math.round(e.la/60*1e5)/1e5,lng:Math.round(e.lo/60*1e5)/1e5,length:e.l,width:e.w,draught:e.draught,sog:e.sp,cog:e.co,hdg:e.h,rot:isNaN(e.rot)?0:e.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta)?g.utc(e.eta).format():void 0,destination:e.destination,vesselType:e.type,dwt:e.dwt,build:e.buildyear,flag:e.fn,positionTime:h.unix(),utc:h.utc().format(),status:c,labelCn:r,labelEn:u,method:"position",vendor:"hifleet"}}async search(t,a={}){let i="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 n=await A.post(i,o).json();m==null||m.info("[%s] fetch vessel props from: %s - %j",a.requestId,i,o),n instanceof Array&&(n=n[0]);for(const c in n)!isNaN(n[c])&&Number(n[c])!==1/0&&(n[c]=Number(n[c]));const e={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 A.post(i,o).json(),m==null||m.info("[%s] search vessel dead weight from: %s - %j",a.requestId,i,o),n instanceof Array&&(n=n[0]),n&&(e.deadweight=Number(n.dwt)),e}async suggest(t,a={}){const i="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"}},n=await A.post(i,o).json();m==null||m.info("[%s] suggest vessel props from: %s - %j",a.requestId,i,o);const e=[];for(const c of n)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,a,i,o,n=!0,e={}){var d,p,f;const c=await this.realTimePosition(t,e);let r=g(a);const u=g(i),h=g();if(n){let l=u.diff(r,"d",!0);l<0?r=u.clone().subtract(40,"d"):l<30?r.subtract(10,"d"):l<60?r.subtract(5,"d"):r=u.clone().subtract(80,"d"),l=h.diff(u,"d",!0),u.add(l>10?240:l*24,"h")}const y={searchParams:{endtime:u.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}},b="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",M=await A.get(b,y).json();m==null||m.info("[%s] fetch trajectory from: %s - %j",e.requestId,b,y);let C;M&&(C=((p=(d=M.ships)==null?void 0:d.offors)==null?void 0:p.ship)||[],C.length||m==null||m.warn("[%s] fetch trajectory failed: %j",e.requestId,M));const S=[];let w=-1;const v=g(`${(f=C==null?void 0:C[0])==null?void 0:f.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const l of C){for(const L in l)!isNaN(l[L])&&Number(l[L])!==1/0&&(l[L]=Number(l[L]));const k=g(`${l.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");l.status=l.sp>4?0:1;const{labelEn:j,labelCn:x}=this.parseStatus(l.status),Y={mmsi:l.m,name:l.n,imo:c==null?void 0:c.imo,lat:l.la,lng:l.lo,draught:l.draught,sog:l.sp,cog:l.co,hdg:l.hdg,positionTime:k.unix(),utc:k.utc().format(),status:l.status,labelCn:x,labelEn:j,method:"trajectory",vendor:"hifleet"},F=Math.floor(k.diff(v,"minute",!0)/(o||1));F!==w&&(w=F,S.push(Y))}return S}}class Mt extends G{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,a={}){const i={searchParams:{id:t,k:this.token,enc:1}},o="https://api.shipxy.com/apicall/GetSingleShip",n=await A.get(o,i).json();if(m==null||m.info("[%s] fetch realtime position from: %s - %j",a.requestId,o,i),(n==null?void 0:n.status)!==0)return n;const e=n.data[0];for(const y in e)!isNaN(e[y])&&Number(e[y])!==1/0&&(e[y]=Number(e[y]));const{labelCn:c,labelEn:r}=await this.parseStatus(e.navistat),u=g.unix(e.lasttime);return{mmsi:e.ShipID,name:e.name,imo:e.imo,callSign:e.callsign,lat:Math.round(e.lat/1e6*1e5)/1e5,lng:Math.round(e.lon/1e6*1e5)/1e5,length:Math.round(e.length/10*100)/100,width:Math.round(e.width/10*100)/100,draught:Math.round(e.draught/1e3*100)/100,sog:Math.round(e.sog*3600/1e3/1852*100)/100,cog:Math.round(e.cog/100*100)/100,hdg:Math.round(e.hdg/100*100)/100,rot:Math.round(e.rot/100*100)/100,positionTime:e.lasttime,utc:u.utc().format(),status:e.navistat,labelEn:r,labelCn:c,method:"position",vendor:"shipxy"}}async trajectory(t,a,i,o,n=!0,e={}){var v;const c=await this.realTimePosition(t,e),r=g(a),u=g(i),h="https://api.shipxy.com/apicall/GetShipTrack",y={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:r.unix(),etm:u.unix()}},b=await A.get(h,y).json();if(m==null||m.info("[%s] fetch trajectory from: %s - %j",e.requestId,h,y),(b==null?void 0:b.status)!==0)return b;const M=b==null?void 0:b.points,C=[],S=g.unix((v=M[0])==null?void 0:v.utc);let w=-1;for(const d of M){const p=g.unix(d.utc),f={imo:c==null?void 0:c.imo,mmsi:t,sog:Math.round(d.sog*3600/1e3/1852*100)/100,cog:Math.round(d.cog/100*100)/100,lat:Math.round(d.lat/1e6*1e5)/1e5,lng:Math.round(d.lon/1e6*1e5)/1e5,positionTime:p.unix(),utc:p.utc().format(),method:"trajectory",vendor:"shipxy"},l=Math.floor(p.diff(S,"minute",!0)/(o||1));l!==w&&(w=l,C.push(f))}return C}}class pt extends G{constructor(t){super();K(this,"token");this.token=t}async getShipId(t,a={}){const i={headers:{appKey:this.token},json:{mmsiList:t}},o="https://api3.myships.com/sp/ships/getShipIdByMMSI",n=await A.post(o,i).json();return m==null||m.info("[%s] fetch ship id from: %s - %j",a.requestId,o,i),n.code!=="0"?n:n.data[0].shipId}async getShipInfo(t,a={}){const i={headers:{appKey:this.token},json:{shipId:t}},o="https://api3.myships.com/sp/ships/aissta",n=await A.post(o,i).json();if(m==null||m.info("[%s] fetch ship info from: %s - %j",a.requestId,o,i),n.code!=="0")return n;const e=n.data;let c=e.imo;return t==="407170"&&(c="9198379",m==null||m.warn("[%s] ship(%s) imo error: %s, should be %s",a.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,a={}){const i=await this.getShipId(t,a),o=await this.getShipInfo(i,a),n={headers:{appKey:this.token},json:{shipId:i}},e="https://api3.myships.com/sp/ships/position/latest",c=await A.post(e,n).json();m==null||m.info("[%s] fetch realtime position from: %s - %j",a.requestId,e,n);const r=c.data[0];for(const M in r)!isNaN(r[M])&&Number(r[M])!==1/0&&(r[M]=Number(r[M]));const{labelCn:u,labelEn:h}=await this.parseStatus(r.aisNavStatus),y=g.unix(r.posTime);return{...o,mmsi:t,lat:Math.round(r.lat/1e4/60*1e5)/1e5,lng:Math.round(r.lon/1e4/60*1e5)/1e5,sog:Math.round(r.sog/10*100)/100,cog:Math.round(r.cog/10*100)/100,hdg:Math.round(r.heading*100)/100,rot:Math.round(r.rot*100)/100,positionTime:r.posTime,utc:y.utc().format(),status:r.aisNavStatus,labelEn:h,labelCn:u,method:"position",vendor:"myship"}}async trajectory(t,a,i,o,n=!0,e={}){const c=g(a),r=g(i),u=await this.getShipId(t),h=await this.getShipInfo(u),y=[];for(;r.diff(c,"day",!0)>30;)await this.trajectoryIn30Day(u,c.unix(),c.add(30,"day").unix(),h,t,o,y);return await this.trajectoryIn30Day(u,c.unix(),r.unix(),h,t,o,y),y}async trajectoryIn30Day(t,a,i,o,n,e,c,r={}){var S;const u={headers:{appKey:this.token},json:{shipId:t,startTime:a,endTime:i}},h="https://api3.myships.com/sp/ships/position/history",y=await A.post(h,u).json();if(m==null||m.info("[%s] fetch trajectory from: %s - %j",r.requestId,h,u),y.code!=="0")return m==null||m.warn("[%s] invoke myship trajectory failed: %j",r.requestId,y),y;const b=y.data;for(const w in b)!isNaN(b[w])&&Number(b[w])!==1/0&&(b[w]=Number(b[w]));const M=g.unix((S=b[0])==null?void 0:S.posTime);let C=-1;for(const w of b){const v=g.unix(w.posTime),d={imo:o==null?void 0:o.imo,mmsi:n,lat:Math.round(w.lat/1e4/60*1e5)/1e5,lng:Math.round(w.lon/1e4/60*1e5)/1e5,sog:Math.round(w.sog/10*100)/100,cog:Math.round(w.cog/10*100)/100,hdg:Math.round(w.heading*100)/100,rot:Math.round(w.rot*100)/100,positionTime:v.unix(),utc:v.utc().format(),method:"trajectory",vendor:"myship"},p=Math.floor(v.diff(M,"minute",!0)/(e||1));p!==C&&(C=p,c.push(d))}return c}}let z;try{z=U.getLogger("vessel")}catch{}finally{}var ct=(D=>(D.NOTICE="NOTICE",D.WARN="WARN",D.HEAVY="HEAVY",D.SEVERE="SEVERE",D.ERROR="ERROR",D.FATAL="FATAL",D))(ct||{});class dt{parsePrinciple(s,t={}){var e,c,r;z==null||z.debug("[%s] parse rule: %s",t.requestId,s);const a=new RegExp("(?<=\\[)(.+)(?=])","g"),i=s.match(a)?(e=s.match(a))==null?void 0:e[0]:void 0,o=i==null?void 0:i.split(";");if(!o)return;const n={};for(let u=0;u<(o==null?void 0:o.length);u++){const h=(r=(c=o[u].match(a))==null?void 0:c[0])==null?void 0:r.split("],");if(u===0&&!h)n.scope=o[0];else if(h)for(let y=0,b=h.length;y<b;y++){const M=this.parseRule(h[y]);M&&(n[M.level]?M.key?n[M.level][M==null?void 0:M.key]=M:n[M.level]=M:M.key?n[M.level]={[M==null?void 0:M.key]:M}:n[M.level]=M)}}return n}parseRule(s,t={}){var n;z==null||z.debug("[%s] parse rule: %s",t.requestId,s),s=s.startsWith("[")?s:`[${s}`,s=s.endsWith("]")?s:`${s}]`;const a=new RegExp("(?<=\\[)(.+?)(?=])","g"),i=(n=s==null?void 0:s.match(a))==null?void 0:n[0],o=i==null?void 0:i.split(",");if(o){let e=o[3]==="Number.MAX_VALUE"?100:Number(o[3]);return e=isNaN(e)?1:e,{operator:o[0],number:Number.isNaN(Number(o[1]))?o[1]:Number(o[1]),level:o[2],time:e,key:o[4]}}}checkWeather(s,t,a={}){var M,C,S,w,v,d,p,f,l,k,j,x,Y,F,L;let i=0,o=0,n=0,e=0;const c=Math.round(((C=(M=t==null?void 0:t.SEVERE)==null?void 0:M.sigWave)==null?void 0:C.number)*1.6*100)/100,r=(w=(S=t==null?void 0:t.SEVERE)==null?void 0:S.sigWave)==null?void 0:w.number,u=(d=(v=t==null?void 0:t.HEAVY)==null?void 0:v.sigWave)==null?void 0:d.number,h=Math.round((((f=(p=t==null?void 0:t.SEVERE)==null?void 0:p.wind)==null?void 0:f.number)+2)*100)/100,y=(k=(l=t==null?void 0:t.SEVERE)==null?void 0:l.wind)==null?void 0:k.number,b=(x=(j=t==null?void 0:t.HEAVY)==null?void 0:j.wind)==null?void 0:x.number;for(let N=0;N<(s==null?void 0:s.length);N++){const E=s[N],P=(F=(Y=E==null?void 0:E.meteo)==null?void 0:Y.wave)==null?void 0:F.sig,V=(L=E==null?void 0:E.meteo)==null?void 0:L.wind,J=N?g(E.eta).diff(g(s[N-1].eta),"hour",!0):0;e=J>e?J:e,z==null||z.debug("[%s] check sig.wave: %j",a.requestId,{...P,dgThd4Wv:c,svThd4Wv:r,hvThd4Wv:u}),(P==null?void 0:P.height)>=c?E.isDangerous=!0:(P==null?void 0:P.height)>=r?E.isSevere=!0:(P==null?void 0:P.height)>=u&&(E.isHeavy=!0),z==null||z.debug("[%s] check wind: %j",a.requestId,{...V,dgThd4Wd:h,svThd4Wd:y,hvThd4Wd:b}),(V==null?void 0:V.scale)>=h?(E.isDangerous=!0,delete E.isSevere,delete E.isHeavy):(V==null?void 0:V.scale)>y?(E.isDangerous||(E.isSevere=!0),delete E.isHeavy):(V==null?void 0:V.scale)===b&&!E.isDangerous&&!E.isSevere&&(E.isHeavy=!0),i+=E.isDangerous?J:0,o+=E.isSevere?J:0,n+=E.isHeavy?J:0}return i=Math.round(i*100)/100,o=Math.round(o*100)/100,n=Math.round(n*100)/100,e=Math.round(e),{sample:s,dangerous:i,severe:o,heavy:n,step:e<3?3:e,wind:{dgThd4Wd:h,svThd4Wd:y,hvThd4Wd:b},sig:{dgThd4Wv:c,svThd4Wv:r,hvThd4Wv:u}}}}const bt=new dt;let I;try{I=U.getLogger("vessel")}catch{}finally{}const vt=new ft.MeteoHelper2("",!0);var ut=(D=>(D.common="common",D.container="container",D.tugs="tugs",D))(ut||{}),lt=(D=>(D.Ballast="Ballast",D.Laden="Laden",D))(lt||{}),ht=(D=>(D.Cp="CP",D.Perf="Basis",D.Instruct="Other",D))(ht||{});class W{static blockCoefficient(s,t,a,i){let o=Math.round(s/(t*a*i)*100)/100;o=o<.55?.55:o>.85?.85:o;const n=[.55,.6,.65,.7,.75,.8,.85],e=n.map(c=>Math.abs(c-o));return n[e.indexOf(Math.min(...e))]}static froudeNumber(s,t,a=9.8){let i=Math.round(Math.sqrt(s*s/(a*t))*100)/100;return i=i<.05?.05:i>.3?.3:i,i}static amendFactor(s,t,a){const i={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.4,-10.6,-9.5],.8:[2.6,-13.1,-15.1],.85:[3.1,-18.7,28]};let 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]}[s];return a==="Laden"&&(n=i[s]),n[0]+n[1]*t+n[2]*Math.pow(t,2)}static directionFactor(s,t=0){let a;return s>30&&s<=60?a=(1.7-.03*Math.pow(t-4,2))/2:s>60&&s<=150?a=(.9-.06*Math.pow(t-6,2))/2:s>150&&s<=180?a=(.4-.03*Math.pow(t-8,2))/2:a=1,Math.round(a*1e5)/1e5}static vesselTagFactor(s,t,a,i){let o;return a==="container"?o=.7*i/2+Math.pow(i,3)/(22*Math.pow(s,2/3)):t==="Ballast"?o=.7*i/2+Math.pow(i,3)/(2.7*Math.pow(s,2/3)):o=.5*i/2+Math.pow(i,3)/(2.7*Math.pow(s,2/3)),o}static waveHeightFactor(s,t){s=s<3?s*.7:s,s=s<0?.2:s,s=s>6?s-.9*(s-6):s,s=s>9?9:s;let a;return t>30&&t<=60?a=-.6:t>60&&t<=90?a=-.4:t>90&&t<=120?a=s<3?.4:-.3:t>120&&t<=150?a=s<3?.6:-.5:t>150&&t<=180?a=s<3?.7:-.6:a=-.7,Math.round(a*(.144*Math.pow(s,2)+.278*s)*1e4)/1e4}static assembleProperties(s,t,a,i){var y;const o=s.lbp??s.length??s.lengthOverall??198.9642,n=s.draught??8,e=s.breadthMoulded??s.breadth??s.breadthExtreme??32.4572,c=s.deadweight??67035.7773,r=((y=s==null?void 0:s.type)==null?void 0:y.toLowerCase())||"common";return{tag:r.indexOf("container")>-1?"container":r.indexOf("tugs")>-1?"tugs":"common",lbp:o,loadCondition:t,draught:n,breadthMoulded:e,displacement:Math.round((c/1.025+n*e*o*.7)*1e4)/1e4,speed:Math.round((a??14.1382)*1852/3600*1e4)/1e4,bearing:i||90}}static async speedLoseAt(s,t,a,i="",o=2,n=!0,e=!1,c={}){let r;if(t.velocity&&e&&(s.speed=H.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),n){let u;try{i=(i==null?void 0:i.toUpperCase())==="CMEMS"?"ECMWF":i,i=(i==null?void 0:i.toUpperCase())==="METEO2"?"best_match":i;const{weatherModels:M,marineModels:C}=await nt.Meteo2Assist.autoPickMeteoModel(i),S=await vt.spotForecast(t.lat,t.lng,a.utc().format(),!1,!1,!0,{...c,pastDays:1,forecastDays:1,weatherModels:M,marineModels:C}),[w]=nt.Meteo2Assist.pickHourly(S,a);u=nt.Meteo2Assist.toLegacy(w)}catch(M){I.warn("[%s] meteo2 spot(%j) forecast failed: %s",c.requestId,{...t,eta:a.utc().format(),source:i},M)}const h=W.weatherFactor(s,u),y=W.currentFactor(s.bearing,u==null?void 0:u.current,o),b=Math.round((s.speed*1.943844+h+y)*100)/100;r={meteo:{...u},wxFactor:h,cFactor:y,speed:t.velocity&&e?t.velocity:b<0?1:b,eta:a.utc().format(),etd:a.utc().format()}}else r={wxFactor:0,cFactor:0,speed:t.velocity&&e?t.velocity:Math.round((s.speed*1.943844+0+0)*100)/100,eta:a.utc().format(),etd:a.utc().format()};return delete t.meteo,delete t.wxFactor,delete t.cFactor,delete t.speed,delete t.etd,{...r,...t}}static async speedLoseInHoursStep(s,t,a,i,o,n,e="",c=!0,r=!1,u={}){t.utc();const h=t.clone().add(14,"days"),y=[],b=[];let M=0,C=0,S,w;for(let v=0;v<n.length-1;v++){let d=n[v];d.distanceFromStart=Math.round((o+C)*1e3)/1e3;const p=n[v+1];if(s.bearing=H.LaneHelper.calculateBearing(d,p,!p.gcToPrevious),d.bearing=s.bearing,d.suspend&&r){d.eta=d.eta||t.utc().format(),d.elapsed=d.elapsed??0;const k=d.suspend-d.elapsed;if(i-M>k)i=i-M-k,t.add(k,"hour"),d.elapsed=d.suspend;else{const j=i-M;d.elapsed+=j,t.add(j,"hour"),i=0}if(I==null||I.info(`[%s] suspend ${d.elapsed} hours at %j, and remain ${i} hours need to go...`,u.requestId,d),i===0)return d.distanceFromPrevious=C,{etd:t,from:w||d,to:d,next:n.filter(j=>j),wps:y,days:b}}else d.suspend=0;c=t.isAfter(h)?!1:c,d=await W.speedLoseAt(s,d,t,e,0,c,r,u),w=w||d,d.important&&y.push(d),t.isSameOrAfter(a)&&(b.push(d),a.add(24,"hour"));const f=H.LaneHelper.calculateDistance(d,p,!p.gcToPrevious);let l=Math.round(f/w.speed*1e5)/1e5;if(M+l<i){if(M+=l,t.add(l,"hour"),delete n[v],I==null||I.debug(`[%s] go to %j from %j with ${f}nm, and cost ${l} hours`,u.requestId,{lat:p.lat,lng:p.lng},{lat:w.lat,lng:w.lng,etd:w.etd}),C+=f,n.filter(k=>k).length<=1){S=p,S.eta=t.utc().format(),S.distanceFromPrevious=f,S.distanceFromStart=Math.round((o+C)*1e4)/1e4,y.push(S),delete n[v+1];break}}else{l=i-M,t.add(l,"hour");const k=H.LngLatHelper.roundPrecision(w.speed*l,5);S=H.LaneHelper.calculateCoordinate(d,s.bearing,k,"nauticalmiles",!p.gcToPrevious),S.eta=t.utc().format(),n[v]=S,I==null||I.debug(`[%s] go to %j from %j with ${k}nm, and cost ${l} hours`,u.requestId,{lat:S.lat,lng:S.lng},{lat:d.lat,lng:d.lng,etd:d.etd}),C+=k,S.distanceFromPrevious=Math.round(C*1e4)/1e4,S.distanceFromStart=Math.round((o+C)*1e4)/1e4;break}}return{etd:t,from:w,to:S,next:n.filter(v=>v),wps:y,days:b}}static currentFactor(s,t,a=0){const i=(s-(t==null?void 0:t.degree)||0)/180*Math.PI;if(Math.abs(i)===Math.PI/2)return 0;let o=((t==null?void 0:t.kts)||0)*Math.cos(i);return a&2?o=Math.ceil(o*100)/100:a&1?o=Math.floor(o*100)/100:o=Math.round(o*100)/100,Math.abs(o)>5?0:o}static weatherFactor(s,t){var h,y,b,M,C,S,w;I==null||I.debug("calculate weather factor via: %j",{...s,...t});const a=W.blockCoefficient(s.displacement,s.lbp,s.breadthMoulded,s.draught),i=W.froudeNumber(s.speed,s.lbp),o=W.amendFactor(a,i,s.loadCondition);let n=Math.abs(s.bearing%360-(((h=t==null?void 0:t.wind)==null?void 0:h.degree)%360||0));n=n>180?360-n:n;const e=W.directionFactor(n,(y=t==null?void 0:t.wind)==null?void 0:y.scale),c=W.vesselTagFactor(s.displacement,s.loadCondition,s.tag,(b=t==null?void 0:t.wind)==null?void 0:b.kts);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)),I==null||I.debug("wind wx factor = %d",r),n=Math.abs(s.bearing%360-(((C=(M=t==null?void 0:t.wave)==null?void 0:M.sig)==null?void 0:C.degree)%360||0));const u=W.waveHeightFactor(((w=(S=t==null?void 0:t.wave)==null?void 0:S.sig)==null?void 0:w.height)??1,n);return I==null||I.debug("wave wx factor = %d",u),r=Math.abs(r)>Math.abs(u)?r:r*.3+u*.7,I==null||I.debug("weather factor = %d",r),r=Math.abs(r)>3?3*(Math.abs(r)/r)+Math.abs(r)/r*(Math.abs(r)-2)*.1:r,Math.round((r||0)*100)/100}static async analyseInstant(s,t,a,i,o,n="",e=0,c=!0,r=!1,u={}){var X,Q,Z,$,tt,et;const h=g().valueOf();s.lng=H.LngLatHelper.convertToStdLng(s.lng);const{route:y,waypoints:b}=o.points,M=H.LaneHelper.calculateSubRoute(s,y);if(((X=M[0])==null?void 0:X.length)<=1)return;const{v0:C,label:S}=s.sog?{v0:s.sog,label:s.label||"Other"}:{v0:i.speed,label:"CP"},w=W.assembleProperties(a,i.loadCondition,C,0),v=b.length?H.LaneHelper.calculateSubWaypoints(s,b):[];v.forEach(O=>O.important=!0);const d={from:{...s},route:M,waypoints:v,v0:C,label:S},p={hours:[],days:[],wps:[]};e||(H.LaneHelper.calculateRouteDistance(M)/i.speed<=72?e=3:e=6);let f=H.LaneHelper.simplifyRouteToCoordinates(M,v,0),l=0,k=0,j=0,x=0;t=g(t).utc();const Y=t.clone();for(;f.length>0;){const O=e-t.hour()%e,_=Math.ceil(t.clone().add(O,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,T=await W.speedLoseInHoursStep(w,t,Y,_,l,f,n,c,r,u);(Q=T.from)!=null&&Q.speed&&(p.hours.push(T.from),p.wps.push(...T.wps),p.days.push(...T.days)),f=T==null?void 0:T.next,f.length||p.hours.push(T==null?void 0:T.to),l+=Math.round((((Z=T==null?void 0:T.to)==null?void 0:Z.distanceFromPrevious)??0)*1e4)/1e4}const F=p.hours;for(let O=0;O<F.length-1;O++){const _=g(F[O+1].eta).diff(F[O].etd,"hour",!0)||1;k+=(F[O].wxFactor||0)*_,j+=(F[O].cFactor||0)*_,x+=_}($=p.wps)==null||$.forEach((O,_)=>{O.positionTime=g.utc(O.etd||O.eta).unix();const T=p.wps[_-1];if(T){const B=O.distanceFromStart-T.distanceFromStart,R=g(O.eta||O.etd).diff(g(T.etd||T.eta),"h",!0);O.avgSpd=Math.round(B/R*100)/100,T.bearing=H.LaneHelper.calculateBearing(T,O)}}),p.wps=(tt=p.wps)==null?void 0:tt.reduce((O,_)=>(O.some(T=>Math.round(T.positionTime/60)===Math.round(_.positionTime/60))||O.push(_),O),[]),d.sample=p;const L=p.hours.at(0),N=p.hours.at(-1);d.distance=Math.round(N.distanceFromStart*1e3)/1e3,d.etd=g(L.eta).utc().format(),d.eta=g(N.eta).utc().format(),d.wxFactor=Math.round(k/x*1e3)/1e3,d.cFactor=Math.round(j/x*1e3)/1e3,d.avgSpeed=Math.round(N.distanceFromStart/x*1e3)/1e3,d.totalHrs=Math.round(x*1e3)/1e3;const{distanceInECA:E,hoursInECA:P,totalDgoConsInECA:V,eca:J}=await this.calculateECA(d,i,u),st=H.LngLatHelper.roundPrecision(i.fo/24*(x-P),3),ot=H.LngLatHelper.roundPrecision(i.dgo/24*x,3);d.extend={eca:J,distanceInECA:E,hoursInECA:P,totalDgoConsInECA:V},d.totalFoCons=st<0?0:st,d.totalDgoCons=ot;const at=g().valueOf()-h,rt=((et=p==null?void 0:p.hours)==null?void 0:et.length)||1;return I==null||I.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",u==null?void 0:u.requestId,at,rt,Math.round(at/rt*1e3)/1e3),d}static async analyseInstantWithThreshed(s,t,a,i,o,n,e,c="",r=3,u=!0,h=!1,y={}){var Z,$,tt,et,O,_;const b=g().valueOf();s.lng=H.LngLatHelper.convertToStdLng(s.lng);const{v0:M,label:C}=s.sog?{v0:s.sog,label:s.label||"Other"}:{v0:o.speed,label:"CP"},S=W.assembleProperties(i,o.loadCondition,M,0),w=H.LaneHelper.calculateSubRoute(s,n);if(((Z=w[0])==null?void 0:Z.length)<=1)return;const v=e.length?H.LaneHelper.calculateSubWaypoints(s,e):[];v.forEach(T=>T.important=!0);let d=H.LaneHelper.simplifyRouteToCoordinates(w,v,0),p=0,f=0,l=0,k=0;const j={hours:[],wps:[],days:[]};t=g(t).utc();const x=t.clone();for(;d.length>0;){const T=r-t.hour()%r;let B=Math.ceil(t.clone().add(T,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;B=t.clone().add(B,"h").isSameOrAfter(a)?a.diff(t,"h",!0)*1e4/1e4:B;const R=await W.speedLoseInHoursStep(S,t,x,B,p,d,c,u,h,y);if(($=R.from)!=null&&$.speed&&(j.hours.push(R.from),R!=null&&R.wps&&j.wps.push(...R.wps),j.days.push(...R.days)),d=R==null?void 0:R.next,d.length||j.hours.push(R==null?void 0:R.to),p+=Math.round((((tt=R==null?void 0:R.to)==null?void 0:tt.distanceFromPrevious)??0)*1e4)/1e4,!B)break}j.wps=(et=j.wps)==null?void 0:et.reduce((T,B)=>(T.some(R=>Math.round(g(R.etd).unix()/60)===Math.round(g(B.etd).unix()/60))||T.push(B),T),[]),(O=j.wps)==null||O.forEach((T,B)=>{const R=j.wps[B-1];if(R){const gt=T.distanceFromStart-R.distanceFromStart,wt=g(T.eta||T.etd).diff(g(R.etd||R.eta),"h",!0);T.avgSpd=Math.round(gt/wt*100)/100;const kt=H.LaneHelper.calculateBearing(R,T);R.bearing=kt}});const Y=j.hours;for(let T=0;T<Y.length-1;T++){const B=g(Y[T+1].eta).diff(Y[T].etd,"hour",!0);f+=Y[T].wxFactor*B,l+=Y[T].cFactor*B,k+=B}const F=j.hours.at(0),L=j.hours.at(-1),N=await H.LaneHelper.calculateRangeRoute(F,L,w),E=await H.LaneHelper.calculateRangeWaypoints(F,L,w,v),P={sample:j,distance:Math.round(((L==null?void 0:L.distanceFromStart)||0)*1e4)/1e4,etd:g(F.eta).utc().format(),eta:g(L==null?void 0:L.eta).utc().format(),wxFactor:Math.round(f/k*1e3)/1e3,cFactor:Math.round(l/k*1e3)/1e3,avgSpeed:Math.round(((L==null?void 0:L.distanceFromStart)||0)/k*1e3)/1e3,totalHrs:Math.round(k*1e3)/1e3,from:F,to:L,route:N,waypoints:E,v0:M,label:C},{distanceInECA:V,hoursInECA:J,totalDgoConsInECA:st,eca:ot}=await this.calculateECA(P,o,y),it=H.LngLatHelper.roundPrecision(o.fo/24*(k-J),3),at=H.LngLatHelper.roundPrecision(o.dgo/24*k,3);P.extend={eca:ot,distanceInECA:V,hoursInECA:J,totalDgoConsInECA:st},P.totalDgoCons=at,P.totalFoCons=it<0?0:it;const X=g().valueOf()-b,Q=((_=j==null?void 0:j.hours)==null?void 0:_.length)||1;return I==null||I.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",y==null?void 0:y.requestId,X,Q,Math.round(X/Q*1e3)/1e3),P}static async analyseCost(s,t,a,i,o={}){var w,v;const n=g().valueOf(),e=[];s.speedStep=s.speedStep||3,s.alterStep=s.alterStep??1;const c=H.LaneHelper.calculateRouteDistance(i.route);let r=0;a.forEach(d=>{const p=Math.ceil(c/d.speed/24);r=r<p?p:r}),r=r*1.3;const u=g.utc(s.etd).add(r??14,"day");let h=1;for(const d of a){const p=JSON.parse(JSON.stringify(i.route)),f=JSON.parse(JSON.stringify(i.waypoints)),l=await W.analyseInstantWithThreshed({lat:s.lat,lng:s.lng},s.etd,u,t,d,p,f,s.meteoVendor,s.speedStep,s.useMeteo,s.useRouteParam,o);l&&(await W.calculateCost(l,d,s,o),e.push(l),I==null||I.info("[%s][L%d-%d] analyse from %s to %s cost: %j",o.requestId,1,h,s.etd,u.format(),{cost:l.cost.total,hire:l.cost.hire,bunker:l.cost.bunker,distance:l.distance,hours:l.totalHrs,cp:`${d.speed}/${d.fo}/${d.dgo}`})),h++}e.sort((d,p)=>d.cost.total-p.cost.total);const y=e.at(0),b=e.at(1),M=[];if(M.push({combined:!1,speeds:[y],cost:(w=y.cost)==null?void 0:w.total}),b){const d=y.cost.cp,p=b.cost.cp,f=g(y.eta),l=g(y.etd),k=f.diff(l,"days",!0);let j=Math.ceil(k/2);j=j>7?7:j<s.alterStep?s.alterStep:j;let x=2,Y={combined:!1,speeds:[b],cost:(v=b.cost)==null?void 0:v.total},F;for(;j>=s.alterStep;){const L=await W.combinedAnalyse(s,t,u,[d,p],i,j,{...o,level:x});if(Y.cost>L.cost?F?(F==null?void 0:F.cost)>L.cost&&(F=L):(F=Y,Y=L):(!F||(F==null?void 0:F.cost)>L.cost)&&(F=L),j<=s.alterStep)break;j=Math.ceil(j/2),x+=1}M.push(Y),F&&M.push(F)}const S=g().valueOf()-n;return I==null||I.info("[%s] analyse elapsed: %d ms",o==null?void 0:o.requestId,S),M.sort((d,p)=>d.cost-p.cost)}static async combinedAnalyse(s,t,a,i,o,n,e={}){e.counter=1,I==null||I.info("[%s][L%d] analyse with alternate cp in every %d days",e.requestId,e.level,n);const c=await W.alternateAnalyse(s,t,a,i,0,o,n,e),r=c.reduce((p,f)=>p+f.cost.total,0),u=c.reduce((p,f)=>p+f.cost.hire,0),h=c.reduce((p,f)=>p+f.cost.bunker,0),y=c.reduce((p,f)=>p+f.distance,0),b=c.reduce((p,f)=>p+f.totalHrs,0);I==null||I.info("[%s][L%d] cost with cpa/cpb turn: %j",e.requestId,e.level,{cost:r,hire:u,bunker:h,distance:y,hours:b});const M=await W.alternateAnalyse(s,t,a,i,1,o,n,e),C=M.reduce((p,f)=>p+f.cost.total,0),S=M.reduce((p,f)=>p+f.cost.hire,0),w=M.reduce((p,f)=>p+f.cost.bunker,0),v=M.reduce((p,f)=>p+f.distance,0),d=M.reduce((p,f)=>p+f.totalHrs,0);return I==null||I.info("[%s][L%d] cost with cpb/cpa turn: %j",e.requestId,e.level,{cost:C,hire:S,bunker:w,distance:v,hours:d}),r<C?{combined:!0,cost:Math.round(r*1e3)/1e3,speeds:c,step:n}:{combined:!0,cost:Math.round(C*1e3)/1e3,speeds:M,step:n}}static async alternateAnalyse(s,t,a,i,o,n,e,c={}){var y,b;let r=g.utc(s.etd);const u={lat:s.lat,lng:s.lng},h=[];for(;r.isBefore(a);){const M=r.clone().utc().add(e,"day"),C=JSON.parse(JSON.stringify(n.route)),S=JSON.parse(JSON.stringify(n.waypoints)),w=i[o],v=await W.analyseInstantWithThreshed(u,r.utc().format(),M,t,w,C,S,s.meteoVendor,s.speedStep,s.useMeteo,s.useRouteParam,c);v&&(await W.calculateCost(v,w,s,c),I==null||I.info("[%s][L%d-%d] analyse from %s to %s cost: %j",c.requestId,c.level,c.counter,r.utc().format(),M.utc().format(),{cost:v.cost.total,hire:v.cost.hire,bunker:v.cost.bunker,distance:v.distance,hours:v.totalHrs,cp:`${w.speed}/${w.fo}/${w.dgo}`})),c.counter=c.counter+1;const d=(b=(y=v==null?void 0:v.sample)==null?void 0:y.hours)==null?void 0:b.at(-1);if(d)u.lat=d.lat,u.lng=d.lng,r=g(d.eta),h.push(v),o=o?0:1;else break}return h}static async calculateCost(s,t,a,i={}){var o;if(s){const n=(a.addComm||0)>=1?(a.addComm||0)/100:a.addComm||0,e=Math.round(s.totalHrs/24*(a.dailyHire||0)*(1-n)*1e3)/1e3,c=Math.round(s.totalFoCons*(a.priceFO||0)*1e3)/1e3,r=Math.round((s.totalDgoCons+(((o=s.extend)==null?void 0:o.totalDgoConsInECA)||0))*(a.priceDGO||0)*1e3)/1e3;s.cost={total:Math.round((e+c+r)*1e3)/1e3,hire:e,bunker:Math.round((c+r)*1e3)/1e3,cp:t}}return s}static async calculateECA(s,t,a={}){var c,r,u,h;const i=await H.LaneHelper.intersectInECA((s==null?void 0:s.route)||[]);let o=0,n=0,e=0;(r=(c=s==null?void 0:s.sample)==null?void 0:c.wps)==null||r.forEach(y=>{y.positionTime=g.utc(y.etd||y.eta).unix()});for(const y of i){o+=y.distance;const b=await H.LaneHelper.deadReckoningTime((u=y.waypoints)==null?void 0:u.at(0),s.sample.wps),M=await H.LaneHelper.deadReckoningTime((h=y.waypoints)==null?void 0:h.at(-1),s.sample.wps);y.in=b,y.out=M,y.totalHrs=H.LngLatHelper.roundPrecision((M.positionTime-b.positionTime)/3600,3),y.totalDgoCons=H.LngLatHelper.roundPrecision(t.fo/24*y.totalHrs,3),n+=y.totalHrs,e+=y.totalDgoCons}return o=H.LngLatHelper.roundPrecision(o,3),n=H.LngLatHelper.roundPrecision(n,3),e=H.LngLatHelper.roundPrecision(e,3),{distanceInECA:o,hoursInECA:n,totalDgoConsInECA:e,eca:i}}static async mergeSpeeds(s,t={}){var d,p;const a={hours:[],wps:[],days:[]},i=s.reduce((f,l)=>f+l.distance,0),o=s.reduce((f,l)=>{var k;return f+(((k=l.extend)==null?void 0:k.distanceInECA)||0)},0),n=s.reduce((f,l)=>f+l.totalHrs,0),e=s.reduce((f,l)=>{var k;return f+(((k=l.extend)==null?void 0:k.hoursInECA)||0)},0),c=s.reduce((f,l)=>{var k;return f+(((k=l.extend)==null?void 0:k.totalDgoConsInECA)||0)},0),r=s.reduce((f,l)=>f+l.wxFactor*l.totalHrs/n,0),u=s.reduce((f,l)=>f+l.cFactor*l.totalHrs/n,0),h=s.reduce((f,l)=>f+l.totalFoCons,0),y=s.reduce((f,l)=>f+l.totalDgoCons,0),b=s.reduce((f,l)=>f+l.cost.total,0),M=s.reduce((f,l)=>f+l.cost.hire,0),C=s.reduce((f,l)=>f+l.cost.bunker,0),S=[],w=[];let v;for(const f of s){w.push(...((d=f.extend)==null?void 0:d.eca)||[]);const l=f.sample.hours,k=f.sample.wps,j=f.sample.days,x=l.at(0);v&&(x.distanceFromPrevious=v.distanceFromPrevious,x.distanceFromStart=v.distanceFromStart,l.forEach((N,E)=>{E&&(N.distanceFromStart=N.distanceFromStart+v.distanceFromStart)}),k.at(0).distanceFromPrevious=v.distanceFromPrevious,k.at(0).distanceFromStart=v.distanceFromStart,k.forEach((N,E)=>{E&&(N.distanceFromStart=N.distanceFromStart+v.distanceFromStart)}),j.at(0).distanceFromPrevious=v.distanceFromPrevious,j.at(0).distanceFromStart=v.distanceFromStart,j.forEach((N,E)=>{E&&(N.distanceFromStart=N.distanceFromStart+v.distanceFromStart)})),x.cp=f.cost.cp;const Y=[f.etd,f.eta],F=S.findIndex(N=>N.id===x.cp.id);F===-1?(x.cp.segment=[Y],S.push(x.cp)):S[F].segment.push(Y),l.forEach(N=>{var P;((P=a.hours)==null?void 0:P.findIndex(V=>V.eta===N.eta))===-1&&a.hours.push(N)}),k.forEach(N=>{var P;((P=a.wps)==null?void 0:P.findIndex(V=>V.eta===N.eta))===-1&&a.wps.push(N)}),j.forEach(N=>{var P;((P=a==null?void 0:a.days)==null?void 0:P.findIndex(V=>V.eta===N.eta))===-1&&a.days.push(N)});const L=(p=a.wps)==null?void 0:p.findIndex(N=>N.eta===x.eta);L===-1?a.wps.push(x):a.wps[L]=x,v=l.at(-1)}return a.wps.sort((f,l)=>{g(f.etd).unix()-g(l.etd).unix()}),a.wps.forEach((f,l)=>{const k=a.wps[l-1];if(k){const j=f.distanceFromStart-(k.distanceFromStart||0),x=g(f.eta||f.etd).diff(g(k.etd||k.eta),"hour",!0),Y=Math.round(j/x*100)/100;f.avgSpd=Y;const F=H.LaneHelper.calculateBearing(k,f);k.bearing=F}}),{sample:a,etd:s.at(0).etd,eta:s.at(-1).eta,from:s.at(0).from,to:s.at(-1).to,v0:s.at(0).v0,label:"Combined",distance:Math.round(i*1e3)/1e3,totalHrs:Math.round(n*1e3)/1e3,avgSpeed:Math.round(i/n*1e3)/1e3,wxFactor:Math.round(r*1e3)/1e3,cFactor:Math.round(u*1e3)/1e3,totalFoCons:Math.round(h*1e3)/1e3,totalDgoCons:Math.round(y*1e3)/1e3,cost:{total:Math.round(b*1e3)/1e3,hire:Math.round(M*1e3)/1e3,bunker:Math.round(C*1e3)/1e3},extend:{cps:S,eca:w,distanceInECA:Math.round(o*1e3)/1e3,hoursInECA:Math.round(e*1e3)/1e3,totalDgoConsInECA:Math.round(c*1e3)/1e3,speeds:s}}}}q.AISImpl=G,q.AlertHelper=dt,q.AlertLevel=ct,q.HifleetImpl=yt,q.LoadCondition=lt,q.MyShipImpl=pt,q.MyVesselImpl=mt,q.ShipxyImpl=Mt,q.SpeedHelper=W,q.SpeedLabel=ht,q.VesselTag=ut,q.alertHelper=bt,Object.defineProperty(q,Symbol.toStringTag,{value:"Module"})});
|