@idm-plugin/vessel 1.2.9 → 1.3.1
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 +90 -90
- package/dist/index.umd.cjs +1 -1
- package/dist/speed/src/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var tt = Object.defineProperty;
|
|
2
2
|
var et = (k, s, t) => s in k ? tt(k, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : k[s] = t;
|
|
3
3
|
var Z = (k, s, t) => (et(k, typeof s != "symbol" ? s + "" : s, t), t);
|
|
4
|
-
import
|
|
4
|
+
import O from "got";
|
|
5
5
|
import z from "@log4js-node/log4js-api";
|
|
6
6
|
import g from "moment";
|
|
7
|
-
import { LngLatHelper as B, LaneHelper as
|
|
7
|
+
import { LngLatHelper as B, LaneHelper as V } from "@idm-plugin/geo";
|
|
8
8
|
import { MeteoHelper as st } from "@idm-plugin/meteo";
|
|
9
9
|
let h;
|
|
10
10
|
try {
|
|
@@ -68,7 +68,7 @@ class mt extends K {
|
|
|
68
68
|
client_secret: this.clientSecret,
|
|
69
69
|
grant_type: "client_credentials"
|
|
70
70
|
}
|
|
71
|
-
}, n = await
|
|
71
|
+
}, n = await O.post(i, o).json();
|
|
72
72
|
h == null || h.info("[%s] fetch access token from: %s - %j", t.requestId, i, n), n.error || (this.token = {
|
|
73
73
|
accessToken: n.access_token,
|
|
74
74
|
tokenType: n.token_type,
|
|
@@ -88,12 +88,12 @@ class mt extends K {
|
|
|
88
88
|
searchParams: { mmsi: t }
|
|
89
89
|
};
|
|
90
90
|
h == null || h.info("[%s] fetch realtime position from: %s - %j", i.requestId, o, n);
|
|
91
|
-
const a = await
|
|
91
|
+
const a = await O.get(o, n).json();
|
|
92
92
|
if (a.code)
|
|
93
93
|
return h == null || h.warn("[%s] fetch realtime position failed: %j", i.requestId, o, { message: a.message, status: a.status, code: a.code }), a;
|
|
94
94
|
const e = a.data;
|
|
95
|
-
for (const
|
|
96
|
-
!isNaN(e[
|
|
95
|
+
for (const m in e)
|
|
96
|
+
!isNaN(e[m]) && Number(e[m]) !== 1 / 0 && (e[m] = Number(e[m]));
|
|
97
97
|
const d = g(`${e.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
98
98
|
return {
|
|
99
99
|
mmsi: e.mmsi,
|
|
@@ -128,7 +128,7 @@ class mt extends K {
|
|
|
128
128
|
return await this.trajectoryIn30Day(t, r, c, d, n, u, e), u;
|
|
129
129
|
}
|
|
130
130
|
async trajectoryIn30Day(t, i, o, n, a, e, d = {}) {
|
|
131
|
-
var f, v, I, Y,
|
|
131
|
+
var f, v, I, Y, p;
|
|
132
132
|
const r = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", c = {
|
|
133
133
|
headers: {
|
|
134
134
|
Authorization: `${(f = this.token) == null ? void 0 : f.tokenType} ${(v = this.token) == null ? void 0 : v.accessToken}`
|
|
@@ -140,12 +140,12 @@ class mt extends K {
|
|
|
140
140
|
}
|
|
141
141
|
};
|
|
142
142
|
h == null || h.info("[%s] fetch trajectory from: %s - %j", d.requestId, r, c);
|
|
143
|
-
const u = await
|
|
143
|
+
const u = await O.post(r, c).json();
|
|
144
144
|
if (u.code)
|
|
145
145
|
return h == null || h.warn("[%s] fetch trajectory failed: %j", d.requestId, r, { message: u.message, status: u.status, code: u.code }), u;
|
|
146
146
|
let y = -1;
|
|
147
|
-
const
|
|
148
|
-
return (
|
|
147
|
+
const m = g(`${(Y = (I = u.data) == null ? void 0 : I[0]) == null ? void 0 : Y.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
148
|
+
return (p = u.data) == null || p.forEach((l) => {
|
|
149
149
|
for (const T in l)
|
|
150
150
|
!isNaN(l[T]) && Number(l[T]) !== 1 / 0 && (l[T] = Number(l[T]));
|
|
151
151
|
const w = g(`${l.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), j = l.eta ? g(`${l.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00") : void 0, M = l.status, { labelCn: b, labelEn: N } = this.parseStatus(M), x = {
|
|
@@ -166,7 +166,7 @@ class mt extends K {
|
|
|
166
166
|
method: "trajectory",
|
|
167
167
|
vendor: "myVessel",
|
|
168
168
|
utc: w.utc().format()
|
|
169
|
-
}, W = Math.floor(w.diff(
|
|
169
|
+
}, W = Math.floor(w.diff(m, "minute", !0) / (a || 1));
|
|
170
170
|
W !== y && (y = W, e.push(x));
|
|
171
171
|
}), e;
|
|
172
172
|
}
|
|
@@ -183,13 +183,13 @@ class pt extends K {
|
|
|
183
183
|
mmsi: t,
|
|
184
184
|
usertoken: this.token
|
|
185
185
|
}
|
|
186
|
-
}, a = await
|
|
186
|
+
}, a = await O.post(o, n).json();
|
|
187
187
|
h == null || h.info("[%s] fetch realtime position from: %s - %j", i.requestId, o, n);
|
|
188
188
|
const e = a == null ? void 0 : a.list;
|
|
189
189
|
if (!e)
|
|
190
190
|
return h == null || h.warn("[%s] fetch realtime position failed: %j", i.requestId, o, a), a;
|
|
191
|
-
for (const
|
|
192
|
-
!isNaN(e[
|
|
191
|
+
for (const m in e)
|
|
192
|
+
!isNaN(e[m]) && Number(e[m]) !== 1 / 0 && (e[m] = Number(e[m]));
|
|
193
193
|
e.status = e.sp > 3 ? 0 : 1;
|
|
194
194
|
const d = e.status, { labelCn: r, labelEn: c } = this.parseStatus(d), u = g(`${e.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
195
195
|
return {
|
|
@@ -229,7 +229,7 @@ class pt extends K {
|
|
|
229
229
|
Host: "www.hifleet.com"
|
|
230
230
|
}
|
|
231
231
|
};
|
|
232
|
-
let a = await
|
|
232
|
+
let a = await O.post(o, n).json();
|
|
233
233
|
h == null || h.info("[%s] fetch vessel props from: %s - %j", i.requestId, o, n), a instanceof Array && (a = a[0]);
|
|
234
234
|
for (const d in a)
|
|
235
235
|
!isNaN(a[d]) && Number(a[d]) !== 1 / 0 && (a[d] = Number(a[d]));
|
|
@@ -242,7 +242,7 @@ class pt extends K {
|
|
|
242
242
|
breadth: a.b,
|
|
243
243
|
draught: a.dr
|
|
244
244
|
};
|
|
245
|
-
return o = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", a = await
|
|
245
|
+
return o = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", a = await O.post(o, n).json(), h == null || h.info("[%s] fetch vessel dead weight from: %s - %j", i.requestId, o, n), a instanceof Array && (a = a[0]), a && (e.deadweight = Number(a.dwt)), e;
|
|
246
246
|
}
|
|
247
247
|
async trajectory(t, i, o, n, a = !0, e = {}) {
|
|
248
248
|
var l, w, j;
|
|
@@ -260,16 +260,16 @@ class pt extends K {
|
|
|
260
260
|
mmsi: t,
|
|
261
261
|
usertoken: this.token
|
|
262
262
|
}
|
|
263
|
-
},
|
|
264
|
-
h == null || h.info("[%s] fetch trajectory from: %s - %j", e.requestId,
|
|
263
|
+
}, m = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", f = await O.get(m, y).json();
|
|
264
|
+
h == null || h.info("[%s] fetch trajectory from: %s - %j", e.requestId, m, y);
|
|
265
265
|
let v;
|
|
266
266
|
f && (v = ((w = (l = f.ships) == null ? void 0 : l.offors) == null ? void 0 : w.ship) || [], v.length || h == null || h.warn("[%s] fetch trajectory failed: %j", e.requestId, f));
|
|
267
267
|
const I = [];
|
|
268
268
|
let Y = -1;
|
|
269
|
-
const
|
|
269
|
+
const p = g(`${(j = v == null ? void 0 : v[0]) == null ? void 0 : j.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
270
270
|
for (const M of v) {
|
|
271
|
-
for (const
|
|
272
|
-
!isNaN(M[
|
|
271
|
+
for (const L in M)
|
|
272
|
+
!isNaN(M[L]) && Number(M[L]) !== 1 / 0 && (M[L] = Number(M[L]));
|
|
273
273
|
const b = g(`${M.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
274
274
|
M.status = M.sp > 4 ? 0 : 1;
|
|
275
275
|
const { labelEn: N, labelCn: x } = this.parseStatus(M.status), W = {
|
|
@@ -289,7 +289,7 @@ class pt extends K {
|
|
|
289
289
|
labelEn: N,
|
|
290
290
|
method: "trajectory",
|
|
291
291
|
vendor: "hifleet"
|
|
292
|
-
}, T = Math.floor(b.diff(
|
|
292
|
+
}, T = Math.floor(b.diff(p, "minute", !0) / (n || 1));
|
|
293
293
|
T !== Y && (Y = T, I.push(W));
|
|
294
294
|
}
|
|
295
295
|
return I;
|
|
@@ -308,7 +308,7 @@ class Mt extends K {
|
|
|
308
308
|
k: this.token,
|
|
309
309
|
enc: 1
|
|
310
310
|
}
|
|
311
|
-
}, n = "https://api.shipxy.com/apicall/GetSingleShip", a = await
|
|
311
|
+
}, n = "https://api.shipxy.com/apicall/GetSingleShip", a = await O.get(n, o).json();
|
|
312
312
|
if (h == null || h.info("[%s] fetch realtime position from: %s - %j", i.requestId, n, o), (a == null ? void 0 : a.status) !== 0)
|
|
313
313
|
return a;
|
|
314
314
|
const e = a.data[0];
|
|
@@ -339,7 +339,7 @@ class Mt extends K {
|
|
|
339
339
|
};
|
|
340
340
|
}
|
|
341
341
|
async trajectory(t, i, o, n, a = !0, e = {}) {
|
|
342
|
-
var
|
|
342
|
+
var p;
|
|
343
343
|
const d = await this.realTimePosition(t, e), r = g(i), c = g(o), u = "https://api.shipxy.com/apicall/GetShipTrack", y = {
|
|
344
344
|
searchParams: {
|
|
345
345
|
id: t,
|
|
@@ -349,10 +349,10 @@ class Mt extends K {
|
|
|
349
349
|
btm: r.unix(),
|
|
350
350
|
etm: c.unix()
|
|
351
351
|
}
|
|
352
|
-
},
|
|
353
|
-
if (h == null || h.info("[%s] fetch trajectory from: %s - %j", e.requestId, u, y), (
|
|
354
|
-
return
|
|
355
|
-
const f =
|
|
352
|
+
}, m = await O.get(u, y).json();
|
|
353
|
+
if (h == null || h.info("[%s] fetch trajectory from: %s - %j", e.requestId, u, y), (m == null ? void 0 : m.status) !== 0)
|
|
354
|
+
return m;
|
|
355
|
+
const f = m == null ? void 0 : m.points, v = [], I = g.unix((p = f[0]) == null ? void 0 : p.utc);
|
|
356
356
|
let Y = -1;
|
|
357
357
|
for (const l of f) {
|
|
358
358
|
const w = g.unix(l.utc), j = {
|
|
@@ -386,7 +386,7 @@ class yt extends K {
|
|
|
386
386
|
json: {
|
|
387
387
|
mmsiList: t
|
|
388
388
|
}
|
|
389
|
-
}, n = "https://api3.myships.com/sp/ships/getShipIdByMMSI", a = await
|
|
389
|
+
}, n = "https://api3.myships.com/sp/ships/getShipIdByMMSI", a = await O.post(n, o).json();
|
|
390
390
|
return h == null || h.info("[%s] fetch ship id from: %s - %j", i.requestId, n, o), a.code !== "0" ? a : a.data[0].shipId;
|
|
391
391
|
}
|
|
392
392
|
async getShipInfo(t, i = {}) {
|
|
@@ -397,7 +397,7 @@ class yt extends K {
|
|
|
397
397
|
json: {
|
|
398
398
|
shipId: t
|
|
399
399
|
}
|
|
400
|
-
}, n = "https://api3.myships.com/sp/ships/aissta", a = await
|
|
400
|
+
}, n = "https://api3.myships.com/sp/ships/aissta", a = await O.post(n, o).json();
|
|
401
401
|
if (h == null || h.info("[%s] fetch ship info from: %s - %j", i.requestId, n, o), a.code !== "0")
|
|
402
402
|
return a;
|
|
403
403
|
const e = a.data;
|
|
@@ -420,7 +420,7 @@ class yt extends K {
|
|
|
420
420
|
json: {
|
|
421
421
|
shipId: o
|
|
422
422
|
}
|
|
423
|
-
}, e = "https://api3.myships.com/sp/ships/position/latest", d = await
|
|
423
|
+
}, e = "https://api3.myships.com/sp/ships/position/latest", d = await O.post(e, a).json();
|
|
424
424
|
h == null || h.info("[%s] fetch realtime position from: %s - %j", i.requestId, e, a);
|
|
425
425
|
const r = d.data[0];
|
|
426
426
|
for (const f in r)
|
|
@@ -461,16 +461,16 @@ class yt extends K {
|
|
|
461
461
|
startTime: i,
|
|
462
462
|
endTime: o
|
|
463
463
|
}
|
|
464
|
-
}, u = "https://api3.myships.com/sp/ships/position/history", y = await
|
|
464
|
+
}, u = "https://api3.myships.com/sp/ships/position/history", y = await O.post(u, c).json();
|
|
465
465
|
if (h == null || h.info("[%s] fetch trajectory from: %s - %j", r.requestId, u, c), y.code !== "0")
|
|
466
466
|
return h == null || h.warn("[%s] invoke myship trajectory failed: %j", r.requestId, y), y;
|
|
467
|
-
const
|
|
468
|
-
for (const Y in
|
|
469
|
-
!isNaN(
|
|
470
|
-
const f = g.unix((I =
|
|
467
|
+
const m = y.data;
|
|
468
|
+
for (const Y in m)
|
|
469
|
+
!isNaN(m[Y]) && Number(m[Y]) !== 1 / 0 && (m[Y] = Number(m[Y]));
|
|
470
|
+
const f = g.unix((I = m[0]) == null ? void 0 : I.posTime);
|
|
471
471
|
let v = -1;
|
|
472
|
-
for (const Y of
|
|
473
|
-
const
|
|
472
|
+
for (const Y of m) {
|
|
473
|
+
const p = g.unix(Y.posTime), l = {
|
|
474
474
|
imo: n == null ? void 0 : n.imo,
|
|
475
475
|
mmsi: a,
|
|
476
476
|
lat: Math.round(Y.lat / 1e4 / 60 * 1e5) / 1e5,
|
|
@@ -479,11 +479,11 @@ class yt extends K {
|
|
|
479
479
|
cog: Math.round(Y.cog / 10 * 100) / 100,
|
|
480
480
|
hdg: Math.round(Y.heading * 100) / 100,
|
|
481
481
|
rot: Math.round(Y.rot * 100) / 100,
|
|
482
|
-
positionTime:
|
|
483
|
-
utc:
|
|
482
|
+
positionTime: p.unix(),
|
|
483
|
+
utc: p.utc().format(),
|
|
484
484
|
method: "trajectory",
|
|
485
485
|
vendor: "myship"
|
|
486
|
-
}, w = Math.floor(
|
|
486
|
+
}, w = Math.floor(p.diff(f, "minute", !0) / (e || 1));
|
|
487
487
|
w !== v && (v = w, d.push(l));
|
|
488
488
|
}
|
|
489
489
|
return d;
|
|
@@ -517,7 +517,7 @@ class ot {
|
|
|
517
517
|
if (c === 0 && !u)
|
|
518
518
|
a.scope = n[0];
|
|
519
519
|
else if (u)
|
|
520
|
-
for (let y = 0,
|
|
520
|
+
for (let y = 0, m = u.length; y < m; y++) {
|
|
521
521
|
const f = this.parseRule(u[y]);
|
|
522
522
|
f && (a[f.level] ? f.key ? a[f.level][f == null ? void 0 : f.key] = f : a[f.level] = f : f.key ? a[f.level] = { [f == null ? void 0 : f.key]: f } : a[f.level] = f);
|
|
523
523
|
}
|
|
@@ -550,14 +550,14 @@ class ot {
|
|
|
550
550
|
* @param options
|
|
551
551
|
*/
|
|
552
552
|
checkWeather(s, t, i = {}) {
|
|
553
|
-
var f, v, I, Y,
|
|
553
|
+
var f, v, I, Y, p, l, w, j, M, b, N, x, W, T, L;
|
|
554
554
|
let o = 0, n = 0, a = 0, e = 0;
|
|
555
|
-
const d = Math.round(((v = (f = t == null ? void 0 : t.SEVERE) == null ? void 0 : f.sigWave) == null ? void 0 : v.number) * 1.6 * 100) / 100, r = (Y = (I = t == null ? void 0 : t.SEVERE) == null ? void 0 : I.sigWave) == null ? void 0 : Y.number, c = (l = (
|
|
556
|
-
for (let
|
|
557
|
-
const D = s[
|
|
558
|
-
e = F > e ? F : e, R == null || R.info("[%s] check sig.wave: %j", i.requestId, { ...q, dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: c }), (q == null ? void 0 : q.height) >= d ? D.isDangerous = !0 : (q == null ? void 0 : q.height) >= r ? D.isSevere = !0 : (q == null ? void 0 : q.height) >= c && (D.isHeavy = !0), R == null || R.info("[%s] check wind: %j", i.requestId, { ...S, dgThd4Wd: u, svThd4Wd: y, hvThd4Wd:
|
|
555
|
+
const d = Math.round(((v = (f = t == null ? void 0 : t.SEVERE) == null ? void 0 : f.sigWave) == null ? void 0 : v.number) * 1.6 * 100) / 100, r = (Y = (I = t == null ? void 0 : t.SEVERE) == null ? void 0 : I.sigWave) == null ? void 0 : Y.number, c = (l = (p = t == null ? void 0 : t.HEAVY) == null ? void 0 : p.sigWave) == null ? void 0 : l.number, u = Math.round((((j = (w = t == null ? void 0 : t.SEVERE) == null ? void 0 : w.wind) == null ? void 0 : j.number) + 2) * 100) / 100, y = (b = (M = t == null ? void 0 : t.SEVERE) == null ? void 0 : M.wind) == null ? void 0 : b.number, m = (x = (N = t == null ? void 0 : t.HEAVY) == null ? void 0 : N.wind) == null ? void 0 : x.number;
|
|
556
|
+
for (let A = 0; A < (s == null ? void 0 : s.length); A++) {
|
|
557
|
+
const D = s[A], q = (T = (W = D == null ? void 0 : D.meteo) == null ? void 0 : W.wave) == null ? void 0 : T.sig, S = (L = D == null ? void 0 : D.meteo) == null ? void 0 : L.wind, F = A ? g(D.eta).diff(g(s[A - 1].eta), "hour", !0) : 0;
|
|
558
|
+
e = F > e ? F : e, R == null || R.info("[%s] check sig.wave: %j", i.requestId, { ...q, dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: c }), (q == null ? void 0 : q.height) >= d ? D.isDangerous = !0 : (q == null ? void 0 : q.height) >= r ? D.isSevere = !0 : (q == null ? void 0 : q.height) >= c && (D.isHeavy = !0), R == null || R.info("[%s] check wind: %j", i.requestId, { ...S, dgThd4Wd: u, svThd4Wd: y, hvThd4Wd: m }), (S == null ? void 0 : S.scale) >= u ? (D.isDangerous = !0, delete D.isSevere, delete D.isHeavy) : (S == null ? void 0 : S.scale) > y ? (D.isDangerous || (D.isSevere = !0), delete D.isHeavy) : (S == null ? void 0 : S.scale) === m && !D.isDangerous && !D.isSevere && (D.isHeavy = !0), o += D.isDangerous ? F : 0, n += D.isSevere ? F : 0, a += D.isHeavy ? F : 0;
|
|
559
559
|
}
|
|
560
|
-
return o = Math.round(o * 100) / 100, n = Math.round(n * 100) / 100, a = Math.round(a * 100) / 100, e = Math.round(e), { sample: s, dangerous: o, severe: n, heavy: a, step: e < 3 ? 3 : e, wind: { dgThd4Wd: u, svThd4Wd: y, hvThd4Wd:
|
|
560
|
+
return o = Math.round(o * 100) / 100, n = Math.round(n * 100) / 100, a = Math.round(a * 100) / 100, e = Math.round(e), { sample: s, dangerous: o, severe: n, heavy: a, step: e < 3 ? 3 : e, wind: { dgThd4Wd: u, svThd4Wd: y, hvThd4Wd: m }, sig: { dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: c } };
|
|
561
561
|
}
|
|
562
562
|
}
|
|
563
563
|
const bt = new ot();
|
|
@@ -743,28 +743,28 @@ class C {
|
|
|
743
743
|
static async speedLoseInHoursStep(s, t, i, o, n, a, e = "", d = !0, r = !1, c = {}) {
|
|
744
744
|
t.utc();
|
|
745
745
|
const u = [], y = [];
|
|
746
|
-
let
|
|
746
|
+
let m = 0, f = 0, v, I;
|
|
747
747
|
for (let Y = 0; Y < a.length - 1; Y++) {
|
|
748
|
-
let
|
|
749
|
-
|
|
748
|
+
let p = a[Y];
|
|
749
|
+
p.distanceFromStart = n + f;
|
|
750
750
|
const l = a[Y + 1];
|
|
751
|
-
if (s.bearing =
|
|
752
|
-
|
|
753
|
-
const M =
|
|
754
|
-
if (o -
|
|
755
|
-
o = o -
|
|
751
|
+
if (s.bearing = V.calculateBearing(p, l, !l.gcToPrevious), p.bearing = s.bearing, p.suspend && r) {
|
|
752
|
+
p.eta = p.eta || t.format("YYYY-MM-DDTHH:mm[Z]"), p.elapsed = p.elapsed ?? 0;
|
|
753
|
+
const M = p.suspend - p.elapsed;
|
|
754
|
+
if (o - m > M)
|
|
755
|
+
o = o - m - M, t.add(M, "hour"), p.elapsed = p.suspend;
|
|
756
756
|
else {
|
|
757
|
-
const b = o -
|
|
758
|
-
|
|
757
|
+
const b = o - m;
|
|
758
|
+
p.elapsed += b, t.add(b, "hour"), o = 0;
|
|
759
759
|
}
|
|
760
|
-
if (H == null || H.info(`[%s] suspend ${
|
|
761
|
-
return
|
|
760
|
+
if (H == null || H.info(`[%s] suspend ${p.elapsed} hours at %j, and remain ${o} hours need to go...`, c.requestId, p), o === 0)
|
|
761
|
+
return p.distanceFromPrevious = f, { etd: t, from: I || p, to: p, next: a.filter((b) => b), wps: u, days: y };
|
|
762
762
|
}
|
|
763
|
-
|
|
764
|
-
const w =
|
|
763
|
+
p = await C.speedLoseAt(s, p, t, e, 0, d, r, c), I = I || p, p.important && u.push(p), t.isSameOrAfter(i) && (y.push(p), i.add(24, "hour"));
|
|
764
|
+
const w = V.calculateDistance(p, l, !l.gcToPrevious);
|
|
765
765
|
let j = Math.ceil(w / I.speed * 1e4) / 1e4;
|
|
766
|
-
if (
|
|
767
|
-
if (
|
|
766
|
+
if (m + j < o) {
|
|
767
|
+
if (m += j, t.add(j, "hour"), delete a[Y], H == null || H.info(
|
|
768
768
|
`[%s] go to %j from %j with ${w}nm, and cost ${j} hours`,
|
|
769
769
|
c.requestId,
|
|
770
770
|
{ lat: l.lat, lng: l.lng },
|
|
@@ -774,13 +774,13 @@ class C {
|
|
|
774
774
|
break;
|
|
775
775
|
}
|
|
776
776
|
} else {
|
|
777
|
-
j = o -
|
|
777
|
+
j = o - m, t.add(j, "hour");
|
|
778
778
|
const M = B.roundPrecision(I.speed * j, 4);
|
|
779
|
-
v =
|
|
779
|
+
v = V.calculateCoordinate(p, s.bearing, M, "nauticalmiles", !l.gcToPrevious), v.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), a[Y] = v, H == null || H.info(
|
|
780
780
|
`[%s] go to %j from %j with ${M}nm, and cost ${j} hours`,
|
|
781
781
|
c.requestId,
|
|
782
782
|
{ lat: v.lat, lng: v.lng },
|
|
783
|
-
{ lat:
|
|
783
|
+
{ lat: p.lat, lng: p.lng, etd: p.etd }
|
|
784
784
|
), f += M, v.distanceFromPrevious = f, v.distanceFromStart = n + f;
|
|
785
785
|
break;
|
|
786
786
|
}
|
|
@@ -806,12 +806,12 @@ class C {
|
|
|
806
806
|
* @param wwc 气象要素
|
|
807
807
|
*/
|
|
808
808
|
static weatherFactor(s, t) {
|
|
809
|
-
var u, y,
|
|
809
|
+
var u, y, m, f, v;
|
|
810
810
|
H == null || H.debug("calculate weather factor via: %j", { ...s, ...t });
|
|
811
811
|
const i = C.blockCoefficient(s.displacement, s.lbp, s.breadthMoulded, s.draught), o = C.froudeNumber(s.speed, s.lbp), n = C.amendFactor(i, o, s.loadCondition);
|
|
812
812
|
let a = Math.abs(s.bearing % 360 - (((u = t == null ? void 0 : t.wind) == null ? void 0 : u.degree) % 360 || 0));
|
|
813
813
|
a = a > 180 ? 360 - a : a;
|
|
814
|
-
const e = C.directionFactor(a, (y = t == null ? void 0 : t.wind) == null ? void 0 : y.scale), d = C.vesselTagFactor(s.displacement, s.loadCondition, s.tag, (
|
|
814
|
+
const e = C.directionFactor(a, (y = t == null ? void 0 : t.wind) == null ? void 0 : y.scale), d = C.vesselTagFactor(s.displacement, s.loadCondition, s.tag, (m = t == null ? void 0 : t.wind) == null ? void 0 : m.scale);
|
|
815
815
|
let r = e * n * d / 100 * s.speed;
|
|
816
816
|
r = Math.round(r * 1.943844 * 1e4) / 1e4 * -1;
|
|
817
817
|
const c = C.waveHeightFactor(((v = (f = t == null ? void 0 : t.wave) == null ? void 0 : f.sig) == null ? void 0 : v.height) ?? 1);
|
|
@@ -833,7 +833,7 @@ class C {
|
|
|
833
833
|
var F, G, U, J, Q;
|
|
834
834
|
const u = g().valueOf();
|
|
835
835
|
s.lng = B.convertToStdLng(s.lng);
|
|
836
|
-
const { route: y, waypoints:
|
|
836
|
+
const { route: y, waypoints: m } = n.points, f = V.calculateSubRoute(s, y);
|
|
837
837
|
if (((F = f[0]) == null ? void 0 : F.length) <= 1)
|
|
838
838
|
return;
|
|
839
839
|
const { v0: v, label: I } = s.sog ? {
|
|
@@ -844,12 +844,12 @@ class C {
|
|
|
844
844
|
v0: o.speed,
|
|
845
845
|
label: "CP"
|
|
846
846
|
/* Cp */
|
|
847
|
-
}, Y = C.assembleProperties(i, o.loadCondition, v, 0),
|
|
848
|
-
|
|
847
|
+
}, Y = C.assembleProperties(i, o.loadCondition, v, 0), p = m.length ? V.calculateSubWaypoints(s, m) : [];
|
|
848
|
+
p.forEach((P) => P.important = !0);
|
|
849
849
|
const l = {
|
|
850
850
|
from: { ...s },
|
|
851
851
|
route: f,
|
|
852
|
-
waypoints:
|
|
852
|
+
waypoints: p,
|
|
853
853
|
v0: v,
|
|
854
854
|
label: I
|
|
855
855
|
}, w = {
|
|
@@ -857,8 +857,8 @@ class C {
|
|
|
857
857
|
days: [],
|
|
858
858
|
wps: []
|
|
859
859
|
};
|
|
860
|
-
e || (
|
|
861
|
-
let j =
|
|
860
|
+
e || (V.calculateRouteDistance(f) / o.speed <= 72 ? e = 3 : e = 6);
|
|
861
|
+
let j = V.simplifyRouteToCoordinates(f, p, 0), M = 0, b = 0, N = 0, x = 0;
|
|
862
862
|
t = g(t).utc();
|
|
863
863
|
const W = t.clone();
|
|
864
864
|
for (; j.length > 0; ) {
|
|
@@ -879,7 +879,7 @@ class C {
|
|
|
879
879
|
const T = w.hours;
|
|
880
880
|
for (let P = 0; P < T.length - 1; P++) {
|
|
881
881
|
const _ = g(T[P + 1].eta).diff(T[P].etd, "hour", !0) || 1;
|
|
882
|
-
b += T[P].wxFactor || 0 * _, N += T[P].cFactor || 0 * _, x += _;
|
|
882
|
+
b += (T[P].wxFactor || 0) * _, N += (T[P].cFactor || 0) * _, x += _;
|
|
883
883
|
}
|
|
884
884
|
(J = w.wps) == null || J.forEach((P, _) => {
|
|
885
885
|
if (_) {
|
|
@@ -887,8 +887,8 @@ class C {
|
|
|
887
887
|
X < 1 ? P.avgSpd = E.speed : P.avgSpd = Math.round($ / X * 100) / 100;
|
|
888
888
|
}
|
|
889
889
|
}), l.sample = w;
|
|
890
|
-
const
|
|
891
|
-
l.distance = Math.round(
|
|
890
|
+
const L = w.hours.at(0), A = w.hours.at(-1);
|
|
891
|
+
l.distance = Math.round(A.distanceFromStart * 1e4) / 1e4, l.etd = g(L.eta).utc().format(), l.eta = g(A.eta).utc().format(), l.wxFactor = Math.round(b / x * 1e4) / 1e4, l.cFactor = Math.round(N / x * 1e4) / 1e4, l.avgSpeed = Math.round(A.distanceFromStart / x * 1e4) / 1e4, l.totalHrs = Math.round(x * 1e4) / 1e4, l.totalFoCons = Math.round((o == null ? void 0 : o.fo) / 24 * l.totalHrs * 1e3) / 1e3, l.totalDgoCons = Math.round((o == null ? void 0 : o.dgo) / 24 * l.totalHrs * 1e3) / 1e3;
|
|
892
892
|
const q = g().valueOf() - u, S = ((Q = w == null ? void 0 : w.hours) == null ? void 0 : Q.length) || 1;
|
|
893
893
|
return H == null || H.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", c == null ? void 0 : c.requestId, q, S, Math.round(q / S * 1e3) / 1e3), l;
|
|
894
894
|
}
|
|
@@ -906,9 +906,9 @@ class C {
|
|
|
906
906
|
* @param useRouteParam
|
|
907
907
|
*/
|
|
908
908
|
static async analyseInstantWithThreshed(s, t, i, o, n, a, e, d = "", r = 3, c = !0, u = !1, y = {}) {
|
|
909
|
-
var
|
|
909
|
+
var A, D, q;
|
|
910
910
|
s.lng = B.convertToStdLng(s.lng);
|
|
911
|
-
const { v0:
|
|
911
|
+
const { v0: m, label: f } = s.sog ? {
|
|
912
912
|
v0: s.sog,
|
|
913
913
|
label: "Other"
|
|
914
914
|
/* Instruct */
|
|
@@ -916,18 +916,18 @@ class C {
|
|
|
916
916
|
v0: n.speed,
|
|
917
917
|
label: "CP"
|
|
918
918
|
/* Cp */
|
|
919
|
-
}, v = C.assembleProperties(o, n.loadCondition,
|
|
920
|
-
if (((
|
|
919
|
+
}, v = C.assembleProperties(o, n.loadCondition, m, 0), I = V.calculateSubRoute(s, a);
|
|
920
|
+
if (((A = I[0]) == null ? void 0 : A.length) <= 1)
|
|
921
921
|
return;
|
|
922
|
-
const Y = e.length ?
|
|
922
|
+
const Y = e.length ? V.calculateSubWaypoints(s, e) : [];
|
|
923
923
|
Y.forEach((S) => S.important = !0);
|
|
924
|
-
let
|
|
924
|
+
let p = V.simplifyRouteToCoordinates(I, Y, 0), l = 0, w = 0, j = 0, M = 0, b;
|
|
925
925
|
const N = {
|
|
926
926
|
hours: [],
|
|
927
927
|
wps: [],
|
|
928
928
|
days: []
|
|
929
929
|
};
|
|
930
|
-
for (t = g(t).utc();
|
|
930
|
+
for (t = g(t).utc(); p.length > 0; ) {
|
|
931
931
|
const S = r - t.hour() % r;
|
|
932
932
|
let F = Math.ceil(t.clone().add(S, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4;
|
|
933
933
|
if (F = t.clone().add(F, "h").isAfter(i) ? i.diff(t, "h", !0) * 1e4 / 1e4 : F, F)
|
|
@@ -937,12 +937,12 @@ class C {
|
|
|
937
937
|
i.clone(),
|
|
938
938
|
F,
|
|
939
939
|
l,
|
|
940
|
-
|
|
940
|
+
p,
|
|
941
941
|
d,
|
|
942
942
|
c,
|
|
943
943
|
u,
|
|
944
944
|
y
|
|
945
|
-
), (D = b.from) != null && D.speed && (N.hours.push(b.from), b != null && b.wps && N.wps.push(...b.wps), N.days.push(...b.days)),
|
|
945
|
+
), (D = b.from) != null && D.speed && (N.hours.push(b.from), b != null && b.wps && N.wps.push(...b.wps), N.days.push(...b.days)), p = b == null ? void 0 : b.next, p.length || (N.hours.push(b == null ? void 0 : b.to), b != null && b.wps && N.wps.push(...b.wps), N.days.push(b == null ? void 0 : b.to)), l += ((q = b == null ? void 0 : b.to) == null ? void 0 : q.distanceFromPrevious) ?? 0;
|
|
946
946
|
else {
|
|
947
947
|
b && (N.hours.push(b.to), b != null && b.wps && N.wps.push(...b.wps), N.days.push(b.to));
|
|
948
948
|
break;
|
|
@@ -966,9 +966,9 @@ class C {
|
|
|
966
966
|
totalHrs: Math.round(M * 1e4) / 1e4,
|
|
967
967
|
from: s,
|
|
968
968
|
to: T,
|
|
969
|
-
route:
|
|
970
|
-
|
|
971
|
-
v0:
|
|
969
|
+
route: I,
|
|
970
|
+
waypoints: Y,
|
|
971
|
+
v0: m,
|
|
972
972
|
label: f
|
|
973
973
|
};
|
|
974
974
|
}
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(w,D){typeof exports=="object"&&typeof module<"u"?D(exports,require("got"),require("@log4js-node/log4js-api"),require("moment"),require("@idm-plugin/geo"),require("@idm-plugin/meteo")):typeof define=="function"&&define.amd?define(["exports","got","@log4js-node/log4js-api","moment","@idm-plugin/geo","@idm-plugin/meteo"],D):(w=typeof globalThis<"u"?globalThis:w||self,D(w["idm-plugin-rabbitmq"]={},w.got,w["@log4js-node/log4js-api"],w.moment,w["@idm-plugin/geo"],w["@idm-plugin/meteo"]))})(this,function(w,D,Z,v,A,nt){"use strict";var ht=Object.defineProperty;var lt=(w,D,Z)=>D in w?ht(w,D,{enumerable:!0,configurable:!0,writable:!0,value:Z}):w[D]=Z;var K=(w,D,Z)=>(lt(w,typeof D!="symbol"?D+"":D,Z),Z);let u;try{u=Z.getLogger("vessel")}catch{}finally{}class z{parseStatus(s){let t,i;switch(s){case 0:t="在航(主机推动)",i="The engine is in use";break;case 1:t="锚泊",i="Anchored";break;case 2:t="失控",i="Not operated";break;case 3:t="操纵受限",i="Limited airworthiness";break;case 4:t="吃水受限",i="Limited by ship's draft";break;case 5:t="靠泊",i="Mooring";break;case 6:t="搁浅",i="Stranded";break;case 7:t="捕捞作业",i="Engaged in fishing";break;case 8:t="靠帆船提供动力",i="Sailing";break;default:t="未定义",i="Undefined"}return{labelCn:t,labelEn:i}}}class ot extends z{constructor(t,i){super();K(this,"clientId");K(this,"clientSecret");K(this,"token");this.clientId=t,this.clientSecret=i}async authToken(t={}){const i="https://svc.data.myvessel.cn/ada/oauth/token",n={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},o=await D.post(i,n).json();u==null||u.info("[%s] fetch access token from: %s - %j",t.requestId,i,o),o.error||(this.token={accessToken:o.access_token,tokenType:o.token_type,expiresIn:o.expires_in,scope:o.scope,jti:o.jti,issuedAt:v().utc().format()})}async realTimePosition(t,i={}){var c,h,M;(!this.token||v().diff(v(this.token.issuedAt),"seconds")>((c=this.token)==null?void 0:c.expiresIn)-300)&&await this.authToken(i);const n="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",o={headers:{Authorization:`${(h=this.token)==null?void 0:h.tokenType} ${(M=this.token)==null?void 0:M.accessToken}`},searchParams:{mmsi:t}};u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,n,o);const a=await D.get(n,o).json();if(a.code)return u==null||u.warn("[%s] fetch realtime position failed: %j",i.requestId,n,{message:a.message,status:a.status,code:a.code}),a;const e=a.data;for(const p in e)!isNaN(e[p])&&Number(e[p])!==1/0&&(e[p]=Number(e[p]));const d=v(`${e.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:e.mmsi,name:e.vesselName,imo:e.imo,callSign:e.callsign,lat:e.lat,lng:e.lon,length:e.length,width:e.width,draught:e.currDraught,sog:e.sog,cog:e.cog,hdg:e.hdg,rot:e.rot,eta:e.eta,destination:e.dest,positionTime:d.unix(),status:e.status,labelCn:e.statusNameCn,labelEn:e.statusNameEn,method:"position",vendor:"myVessel",utc:d.utc().format()}}async trajectory(t,i,n,o,a=!0,e={}){(!this.token||v().diff(v(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(e);const d=await this.realTimePosition(t,e),r=v(i),c=v(n),h=[];for(;c.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(t,r,r.clone().add(30,"day"),d,o,h,e),r.add(30,"day");return await this.trajectoryIn30Day(t,r,c,d,o,h,e),h}async trajectoryIn30Day(t,i,n,o,a,e,d={}){var f,g,k,Y,m;const r="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",c={headers:{Authorization:`${(f=this.token)==null?void 0:f.tokenType} ${(g=this.token)==null?void 0:g.accessToken}`},json:{mmsi:t,startTime:i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};u==null||u.info("[%s] fetch trajectory from: %s - %j",d.requestId,r,c);const h=await D.post(r,c).json();if(h.code)return u==null||u.warn("[%s] fetch trajectory failed: %j",d.requestId,r,{message:h.message,status:h.status,code:h.code}),h;let M=-1;const p=v(`${(Y=(k=h.data)==null?void 0:k[0])==null?void 0:Y.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(m=h.data)==null||m.forEach(l=>{for(const T in l)!isNaN(l[T])&&Number(l[T])!==1/0&&(l[T]=Number(l[T]));const I=v(`${l.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),H=l.eta?v(`${l.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,y=l.status,{labelCn:b,labelEn:F}=this.parseStatus(y),x={mmsi:l.mmsi,imo:o==null?void 0:o.imo,lat:l.lat,lng:l.lon,sog:l.sog,cog:l.cog,hdg:l.hdg,draught:l.draught,status:y,eta:H==null?void 0:H.unix(),destination:l.dest,positionTime:I.unix(),labelCn:b,labelEn:F,method:"trajectory",vendor:"myVessel",utc:I.utc().format()},V=Math.floor(I.diff(p,"minute",!0)/(a||1));V!==M&&(M=V,e.push(x))}),e}}class it extends z{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,i={}){const n="https://api.hifleet.com/position/position/get/token",o={searchParams:{mmsi:t,usertoken:this.token}},a=await D.post(n,o).json();u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,n,o);const e=a==null?void 0:a.list;if(!e)return u==null||u.warn("[%s] fetch realtime position failed: %j",i.requestId,n,a),a;for(const p in e)!isNaN(e[p])&&Number(e[p])!==1/0&&(e[p]=Number(e[p]));e.status=e.sp>3?0:1;const d=e.status,{labelCn:r,labelEn:c}=this.parseStatus(d),h=v(`${e.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:e.m,name:e.n,imo:e.imonumber,callSign:e.callsign,lat:Math.round(e.la/60*1e5)/1e5,lng:Math.round(e.lo/60*1e5)/1e5,length:e.l,width:e.w,draught:e.draught,sog:e.sp,cog:e.co,hdg:e.h,rot:isNaN(e.rot)?0:e.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta)?v(`${e.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").unix():void 0,destination:e.destination,positionTime:h.unix(),utc:h.utc().format(),status:d,labelCn:r,labelEn:c,method:"position",vendor:"hifleet"}}async search(t,i={}){let n="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const o={searchParams:{keyword:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let a=await D.post(n,o).json();u==null||u.info("[%s] fetch vessel props from: %s - %j",i.requestId,n,o),a instanceof Array&&(a=a[0]);for(const d in a)!isNaN(a[d])&&Number(a[d])!==1/0&&(a[d]=Number(a[d]));const e={mmsi:a.m,name:a.n,imo:a.i,callSign:a.c,length:a.l,breadth:a.b,draught:a.dr};return n="https://www.hifleet.com/hifleetapi/sameShipSearch.do",a=await D.post(n,o).json(),u==null||u.info("[%s] fetch vessel dead weight from: %s - %j",i.requestId,n,o),a instanceof Array&&(a=a[0]),a&&(e.deadweight=Number(a.dwt)),e}async trajectory(t,i,n,o,a=!0,e={}){var l,I,H;const d=await this.realTimePosition(t,e);let r=v(i);const c=v(n),h=v();if(a){let y=c.diff(r,"d",!0);y<0?r=c.clone().subtract(40,"d"):y<30?r.subtract(10,"d"):y<60?r.subtract(5,"d"):r=c.clone().subtract(80,"d"),y=h.diff(c,"d",!0),c.add(y>10?240:y*24,"h")}const M={searchParams:{endtime:c.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}},p="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",f=await D.get(p,M).json();u==null||u.info("[%s] fetch trajectory from: %s - %j",e.requestId,p,M);let g;f&&(g=((I=(l=f.ships)==null?void 0:l.offors)==null?void 0:I.ship)||[],g.length||u==null||u.warn("[%s] fetch trajectory failed: %j",e.requestId,f));const k=[];let Y=-1;const m=v(`${(H=g==null?void 0:g[0])==null?void 0:H.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const y of g){for(const _ in y)!isNaN(y[_])&&Number(y[_])!==1/0&&(y[_]=Number(y[_]));const b=v(`${y.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");y.status=y.sp>4?0:1;const{labelEn:F,labelCn:x}=this.parseStatus(y.status),V={mmsi:y.m,name:y.n,imo:d==null?void 0:d.imo,lat:y.la,lng:y.lo,draught:y.draught,sog:y.sp,cog:y.co,hdg:y.hdg,positionTime:b.unix(),utc:b.utc().format(),status:y.status,labelCn:x,labelEn:F,method:"trajectory",vendor:"hifleet"},T=Math.floor(b.diff(m,"minute",!0)/(o||1));T!==Y&&(Y=T,k.push(V))}return k}}class rt extends z{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,i={}){const n={searchParams:{id:t,k:this.token,enc:1}},o="https://api.shipxy.com/apicall/GetSingleShip",a=await D.get(o,n).json();if(u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,o,n),(a==null?void 0:a.status)!==0)return a;const e=a.data[0];for(const M in e)!isNaN(e[M])&&Number(e[M])!==1/0&&(e[M]=Number(e[M]));const{labelCn:d,labelEn:r}=await this.parseStatus(e.navistat),c=v.unix(e.lasttime);return{mmsi:e.ShipID,name:e.name,imo:e.imo,callSign:e.callsign,lat:Math.round(e.lat/1e6*1e5)/1e5,lng:Math.round(e.lon/1e6*1e5)/1e5,length:Math.round(e.length/10*100)/100,width:Math.round(e.width/10*100)/100,draught:Math.round(e.draught/1e3*100)/100,sog:Math.round(e.sog*3600/1e3/1852*100)/100,cog:Math.round(e.cog/100*100)/100,hdg:Math.round(e.hdg/100*100)/100,rot:Math.round(e.rot/100*100)/100,positionTime:e.lasttime,utc:c.utc().format(),status:e.navistat,labelEn:r,labelCn:d,method:"position",vendor:"shipxy"}}async trajectory(t,i,n,o,a=!0,e={}){var m;const d=await this.realTimePosition(t,e),r=v(i),c=v(n),h="https://api.shipxy.com/apicall/GetShipTrack",M={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:r.unix(),etm:c.unix()}},p=await D.get(h,M).json();if(u==null||u.info("[%s] fetch trajectory from: %s - %j",e.requestId,h,M),(p==null?void 0:p.status)!==0)return p;const f=p==null?void 0:p.points,g=[],k=v.unix((m=f[0])==null?void 0:m.utc);let Y=-1;for(const l of f){const I=v.unix(l.utc),H={imo:d==null?void 0:d.imo,mmsi:t,sog:Math.round(l.sog*3600/1e3/1852*100)/100,cog:Math.round(l.cog/100*100)/100,lat:Math.round(l.lat/1e6*1e5)/1e5,lng:Math.round(l.lon/1e6*1e5)/1e5,positionTime:I.unix(),utc:I.utc().format(),method:"trajectory",vendor:"shipxy"},y=Math.floor(I.diff(k,"minute",!0)/(o||1));y!==Y&&(Y=y,g.push(H))}return g}}class ct extends z{constructor(t){super();K(this,"token");this.token=t}async getShipId(t,i={}){const n={headers:{appKey:this.token},json:{mmsiList:t}},o="https://api3.myships.com/sp/ships/getShipIdByMMSI",a=await D.post(o,n).json();return u==null||u.info("[%s] fetch ship id from: %s - %j",i.requestId,o,n),a.code!=="0"?a:a.data[0].shipId}async getShipInfo(t,i={}){const n={headers:{appKey:this.token},json:{shipId:t}},o="https://api3.myships.com/sp/ships/aissta",a=await D.post(o,n).json();if(u==null||u.info("[%s] fetch ship info from: %s - %j",i.requestId,o,n),a.code!=="0")return a;const e=a.data;let d=e.imo;return t==="407170"&&(d="9198379",u==null||u.warn("[%s] ship(%s) imo error: %s, should be %s",i.requestId,t,e.imo,d)),{mmsi:e.mmsi,name:e.shipnameEn,imo:d,callSign:e.callSign,length:e.length,width:e.breadth,draught:(e.draught||100)/10}}async realTimePosition(t,i={}){const n=await this.getShipId(t,i),o=await this.getShipInfo(n,i),a={headers:{appKey:this.token},json:{shipId:n}},e="https://api3.myships.com/sp/ships/position/latest",d=await D.post(e,a).json();u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,e,a);const r=d.data[0];for(const f in r)!isNaN(r[f])&&Number(r[f])!==1/0&&(r[f]=Number(r[f]));const{labelCn:c,labelEn:h}=await this.parseStatus(r.aisNavStatus),M=v.unix(r.posTime);return{...o,mmsi:t,lat:Math.round(r.lat/1e4/60*1e5)/1e5,lng:Math.round(r.lon/1e4/60*1e5)/1e5,sog:Math.round(r.sog/10*100)/100,cog:Math.round(r.cog/10*100)/100,hdg:Math.round(r.heading*100)/100,rot:Math.round(r.rot*100)/100,positionTime:r.posTime,utc:M.utc().format(),status:r.aisNavStatus,labelEn:h,labelCn:c,method:"position",vendor:"myship"}}async trajectory(t,i,n,o,a=!0,e={}){const d=v(i),r=v(n),c=await this.getShipId(t),h=await this.getShipInfo(c),M=[];for(;r.diff(d,"day",!0)>30;)await this.trajectoryIn30Day(c,d.unix(),d.add(30,"day").unix(),h,t,o,M);return await this.trajectoryIn30Day(c,d.unix(),r.unix(),h,t,o,M),M}async trajectoryIn30Day(t,i,n,o,a,e,d,r={}){var k;const c={headers:{appKey:this.token},json:{shipId:t,startTime:i,endTime:n}},h="https://api3.myships.com/sp/ships/position/history",M=await D.post(h,c).json();if(u==null||u.info("[%s] fetch trajectory from: %s - %j",r.requestId,h,c),M.code!=="0")return u==null||u.warn("[%s] invoke myship trajectory failed: %j",r.requestId,M),M;const p=M.data;for(const Y in p)!isNaN(p[Y])&&Number(p[Y])!==1/0&&(p[Y]=Number(p[Y]));const f=v.unix((k=p[0])==null?void 0:k.posTime);let g=-1;for(const Y of p){const m=v.unix(Y.posTime),l={imo:o==null?void 0:o.imo,mmsi:a,lat:Math.round(Y.lat/1e4/60*1e5)/1e5,lng:Math.round(Y.lon/1e4/60*1e5)/1e5,sog:Math.round(Y.sog/10*100)/100,cog:Math.round(Y.cog/10*100)/100,hdg:Math.round(Y.heading*100)/100,rot:Math.round(Y.rot*100)/100,positionTime:m.unix(),utc:m.utc().format(),method:"trajectory",vendor:"myship"},I=Math.floor(m.diff(f,"minute",!0)/(e||1));I!==g&&(g=I,d.push(l))}return d}}let O;try{O=Z.getLogger("vessel")}catch{}finally{}var G=(j=>(j.NOTICE="NOTICE",j.WARN="WARN",j.HEAVY="HEAVY",j.SEVERE="SEVERE",j.ERROR="ERROR",j.FATAL="FATAL",j))(G||{});class U{parsePrinciple(s,t={}){var e,d,r;O==null||O.info("[%s] parse rule: %s",t.requestId,s);const i=new RegExp("(?<=\\[)(.+)(?=])","g"),n=s.match(i)?(e=s.match(i))==null?void 0:e[0]:void 0,o=n==null?void 0:n.split(";");if(!o)return;const a={};for(let c=0;c<(o==null?void 0:o.length);c++){const h=(r=(d=o[c].match(i))==null?void 0:d[0])==null?void 0:r.split("],");if(c===0&&!h)a.scope=o[0];else if(h)for(let M=0,p=h.length;M<p;M++){const f=this.parseRule(h[M]);f&&(a[f.level]?f.key?a[f.level][f==null?void 0:f.key]=f:a[f.level]=f:f.key?a[f.level]={[f==null?void 0:f.key]:f}:a[f.level]=f)}}return a}parseRule(s,t={}){var a;O==null||O.info("[%s] parse rule: %s",t.requestId,s),s=s.startsWith("[")?s:`[${s}`,s=s.endsWith("]")?s:`${s}]`;const i=new RegExp("(?<=\\[)(.+?)(?=])","g"),n=(a=s==null?void 0:s.match(i))==null?void 0:a[0],o=n==null?void 0:n.split(",");if(o)return{operator:o[0],number:Number.isNaN(Number(o[1]))?o[1]:Number(o[1]),level:o[2],time:Number(o[3]),key:o[4]}}checkWeather(s,t,i={}){var f,g,k,Y,m,l,I,H,y,b,F,x,V,T,_;let n=0,o=0,a=0,e=0;const d=Math.round(((g=(f=t==null?void 0:t.SEVERE)==null?void 0:f.sigWave)==null?void 0:g.number)*1.6*100)/100,r=(Y=(k=t==null?void 0:t.SEVERE)==null?void 0:k.sigWave)==null?void 0:Y.number,c=(l=(m=t==null?void 0:t.HEAVY)==null?void 0:m.sigWave)==null?void 0:l.number,h=Math.round((((H=(I=t==null?void 0:t.SEVERE)==null?void 0:I.wind)==null?void 0:H.number)+2)*100)/100,M=(b=(y=t==null?void 0:t.SEVERE)==null?void 0:y.wind)==null?void 0:b.number,p=(x=(F=t==null?void 0:t.HEAVY)==null?void 0:F.wind)==null?void 0:x.number;for(let W=0;W<(s==null?void 0:s.length);W++){const S=s[W],P=(T=(V=S==null?void 0:S.meteo)==null?void 0:V.wave)==null?void 0:T.sig,N=(_=S==null?void 0:S.meteo)==null?void 0:_.wind,E=W?v(S.eta).diff(v(s[W-1].eta),"hour",!0):0;e=E>e?E:e,O==null||O.info("[%s] check sig.wave: %j",i.requestId,{...P,dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:c}),(P==null?void 0:P.height)>=d?S.isDangerous=!0:(P==null?void 0:P.height)>=r?S.isSevere=!0:(P==null?void 0:P.height)>=c&&(S.isHeavy=!0),O==null||O.info("[%s] check wind: %j",i.requestId,{...N,dgThd4Wd:h,svThd4Wd:M,hvThd4Wd:p}),(N==null?void 0:N.scale)>=h?(S.isDangerous=!0,delete S.isSevere,delete S.isHeavy):(N==null?void 0:N.scale)>M?(S.isDangerous||(S.isSevere=!0),delete S.isHeavy):(N==null?void 0:N.scale)===p&&!S.isDangerous&&!S.isSevere&&(S.isHeavy=!0),n+=S.isDangerous?E:0,o+=S.isSevere?E:0,a+=S.isHeavy?E:0}return n=Math.round(n*100)/100,o=Math.round(o*100)/100,a=Math.round(a*100)/100,e=Math.round(e),{sample:s,dangerous:n,severe:o,heavy:a,step:e<3?3:e,wind:{dgThd4Wd:h,svThd4Wd:M,hvThd4Wd:p},sig:{dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:c}}}}const dt=new U;let q;try{q=Z.getLogger("vessel")}catch{}finally{}var J=(j=>(j.common="common",j.container="container",j))(J||{}),Q=(j=>(j.Ballast="Ballast",j.Laden="Laden",j))(Q||{}),X=(j=>(j.Cp="CP",j.Perf="Basis",j.Instruct="Other",j))(X||{});class R{static blockCoefficient(s,t,i,n){let o=Math.round(s/(t*i*n)*100)/100;o=o<.55?.55:o>.85?.85:o;const a=[.55,.6,.65,.7,.75,.8,.85],e=a.map(d=>Math.abs(d-o));return a[e.indexOf(Math.min(...e))]}static froudeNumber(s,t,i=9.8){let n=Math.round(Math.sqrt(s*s/(i*t))*100)/100;return n=n<.05?.05:n>.3?.3:n,n}static amendFactor(s,t,i){const n={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.4,-10.6,-9.5],.8:[2.6,-13.1,-15.1],.85:[3.1,-18.7,28]};let a={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.6,-12.5,-13.5],.8:[3,-16.3,-21.6],.85:[3.4,-20.9,31.8]}[s];return i==="Laden"&&(a=n[s]),a[0]+a[1]*t+a[2]*Math.pow(t,2)}static directionFactor(s,t=0){let i;return s>30&&s<=60?i=(1.7-.03*Math.pow(t-4,2))/2:s>60&&s<=150?i=(.9-.06*Math.pow(t-6,2))/2:i=(.4-.03*Math.pow(t-8,2))/2,Math.round(i*1e5)/1e5}static vesselTagFactor(s,t,i,n=0){n=n>5?n-.9*(n-5):n;let o;return i==="container"?o=.7*n+Math.pow(n,6.5)/(22*Math.pow(s,2/3)):t==="Ballast"?o=.7*n+Math.pow(n,6.5)/(2.7*Math.pow(s,2/3)):o=.5*n+Math.pow(n,6.5)/(2.7*Math.pow(s,2/3)),o}static waveHeightFactor(s){return s=s<1.25?1.25:s,s=s>6?s-.9*(s-6):s,Math.round((-.144*Math.pow(s,2)+.178*s)*1e4)/1e4}static assembleProperties(s,t,i,n){var c,h;const o=s.lbp??s.length??s.lengthOverall??198.9642,a=s.draught??8,e=s.breadthMoulded??s.breadth??s.breadthExtreme??32.4572,d=s.deadweight??67035.7773;return{tag:((h=(c=s==null?void 0:s.type)==null?void 0:c.toLowerCase())==null?void 0:h.indexOf("container"))>-1?"container":"common",lbp:o,loadCondition:t,draught:a,breadthMoulded:e,displacement:Math.round((d/1.025+a*e*o*.7)*1e4)/1e4,speed:Math.round((i??14.1382)*1852/3600*1e4)/1e4,bearing:n||90}}static async speedLoseAt(s,t,i,n="",o=2,a=!0,e=!1,d={}){let r;if(t.velocity&&e&&(s.speed=A.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),a){const c=await nt.MeteoHelper.queryPointFactor(t.lng,t.lat,i.valueOf(),"wind,wave,current,watertemp",n,d),h=R.weatherFactor(s,c),M=R.currentFactor(s.bearing,c==null?void 0:c.current,o);r={meteo:{...c},wxFactor:h,cFactor:M,speed:t.velocity&&e?t.velocity:Math.round((s.speed*1.943844+h+M)*100)/100,eta:i.utc().format("YYYY-MM-DDTHH:mm[Z]"),etd:i.utc().format("YYYY-MM-DDTHH:mm[Z]")}}else r={wxFactor:0,cFactor:0,speed:t.velocity&&e?t.velocity:Math.round((s.speed*1.943844+0+0)*100)/100,eta:i.utc().format("YYYY-MM-DDTHH:mm[Z]"),etd:i.utc().format("YYYY-MM-DDTHH:mm[Z]")};return delete t.meteo,delete t.wxFactor,delete t.cFactor,delete t.speed,delete t.etd,{...r,...t}}static async speedLoseInHoursStep(s,t,i,n,o,a,e="",d=!0,r=!1,c={}){t.utc();const h=[],M=[];let p=0,f=0,g,k;for(let Y=0;Y<a.length-1;Y++){let m=a[Y];m.distanceFromStart=o+f;const l=a[Y+1];if(s.bearing=A.LaneHelper.calculateBearing(m,l,!l.gcToPrevious),m.bearing=s.bearing,m.suspend&&r){m.eta=m.eta||t.format("YYYY-MM-DDTHH:mm[Z]"),m.elapsed=m.elapsed??0;const y=m.suspend-m.elapsed;if(n-p>y)n=n-p-y,t.add(y,"hour"),m.elapsed=m.suspend;else{const b=n-p;m.elapsed+=b,t.add(b,"hour"),n=0}if(q==null||q.info(`[%s] suspend ${m.elapsed} hours at %j, and remain ${n} hours need to go...`,c.requestId,m),n===0)return m.distanceFromPrevious=f,{etd:t,from:k||m,to:m,next:a.filter(b=>b),wps:h,days:M}}m=await R.speedLoseAt(s,m,t,e,0,d,r,c),k=k||m,m.important&&h.push(m),t.isSameOrAfter(i)&&(M.push(m),i.add(24,"hour"));const I=A.LaneHelper.calculateDistance(m,l,!l.gcToPrevious);let H=Math.ceil(I/k.speed*1e4)/1e4;if(p+H<n){if(p+=H,t.add(H,"hour"),delete a[Y],q==null||q.info(`[%s] go to %j from %j with ${I}nm, and cost ${H} hours`,c.requestId,{lat:l.lat,lng:l.lng},{lat:k.lat,lng:k.lng,etd:k.etd}),f+=I,a.filter(y=>y).length<=1){g=l,g.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),g.distanceFromPrevious=I,g.distanceFromStart=o+f,h.push(g),delete a[Y+1];break}}else{H=n-p,t.add(H,"hour");const y=A.LngLatHelper.roundPrecision(k.speed*H,4);g=A.LaneHelper.calculateCoordinate(m,s.bearing,y,"nauticalmiles",!l.gcToPrevious),g.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),a[Y]=g,q==null||q.info(`[%s] go to %j from %j with ${y}nm, and cost ${H} hours`,c.requestId,{lat:g.lat,lng:g.lng},{lat:m.lat,lng:m.lng,etd:m.etd}),f+=y,g.distanceFromPrevious=f,g.distanceFromStart=o+f;break}}return{etd:t,from:k,to:g,next:a.filter(Y=>Y),wps:h,days:M}}static currentFactor(s,t,i=0){const n=(s-(t==null?void 0:t.degree)||0)/180*Math.PI;if(Math.abs(n)===Math.PI/2)return 0;let o=((t==null?void 0:t.kts)||0)*Math.cos(n);return i&2?o=Math.ceil(o*100)/100:i&1?o=Math.floor(o*100)/100:o=Math.round(o*100)/100,Math.abs(o)>5?0:o}static weatherFactor(s,t){var h,M,p,f,g;q==null||q.debug("calculate weather factor via: %j",{...s,...t});const i=R.blockCoefficient(s.displacement,s.lbp,s.breadthMoulded,s.draught),n=R.froudeNumber(s.speed,s.lbp),o=R.amendFactor(i,n,s.loadCondition);let a=Math.abs(s.bearing%360-(((h=t==null?void 0:t.wind)==null?void 0:h.degree)%360||0));a=a>180?360-a:a;const e=R.directionFactor(a,(M=t==null?void 0:t.wind)==null?void 0:M.scale),d=R.vesselTagFactor(s.displacement,s.loadCondition,s.tag,(p=t==null?void 0:t.wind)==null?void 0:p.scale);let r=e*o*d/100*s.speed;r=Math.round(r*1.943844*1e4)/1e4*-1;const c=R.waveHeightFactor(((g=(f=t==null?void 0:t.wave)==null?void 0:f.sig)==null?void 0:g.height)??1);return r=r*.24+c*.76,q==null||q.debug("weather factor = %s",r),Math.round(r*100)/100}static async analyseInstant(s,t,i,n,o,a="",e=0,d=!0,r=!1,c={}){var E,$,tt,et,st;const h=v().valueOf();s.lng=A.LngLatHelper.convertToStdLng(s.lng);const{route:M,waypoints:p}=o.points,f=A.LaneHelper.calculateSubRoute(s,M);if(((E=f[0])==null?void 0:E.length)<=1)return;const{v0:g,label:k}=s.sog?{v0:s.sog,label:"Other"}:{v0:n.speed,label:"CP"},Y=R.assembleProperties(i,n.loadCondition,g,0),m=p.length?A.LaneHelper.calculateSubWaypoints(s,p):[];m.forEach(C=>C.important=!0);const l={from:{...s},route:f,waypoints:m,v0:g,label:k},I={hours:[],days:[],wps:[]};e||(A.LaneHelper.calculateRouteDistance(f)/n.speed<=72?e=3:e=6);let H=A.LaneHelper.simplifyRouteToCoordinates(f,m,0),y=0,b=0,F=0,x=0;t=v(t).utc();const V=t.clone();for(;H.length>0;){const C=e-t.hour()%e,B=Math.ceil(t.clone().add(C,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,L=await R.speedLoseInHoursStep(Y,t,V,B,y,H,a,d,r,c);($=L.from)!=null&&$.speed&&(I.hours.push(L.from),I.wps.push(...L.wps),I.days.push(...L.days)),H=L==null?void 0:L.next,H.length||I.hours.push(L==null?void 0:L.to),y+=((tt=L==null?void 0:L.to)==null?void 0:tt.distanceFromPrevious)??0}const T=I.hours;for(let C=0;C<T.length-1;C++){const B=v(T[C+1].eta).diff(T[C].etd,"hour",!0)||1;b+=T[C].wxFactor||0*B,F+=T[C].cFactor||0*B,x+=B}(et=I.wps)==null||et.forEach((C,B)=>{if(B){const L=I.wps[B-1],ut=C.distanceFromStart-L.distanceFromStart,at=v(C.eta).diff(v(L.etd),"h",!0);at<1?C.avgSpd=L.speed:C.avgSpd=Math.round(ut/at*100)/100}}),l.sample=I;const _=I.hours.at(0),W=I.hours.at(-1);l.distance=Math.round(W.distanceFromStart*1e4)/1e4,l.etd=v(_.eta).utc().format(),l.eta=v(W.eta).utc().format(),l.wxFactor=Math.round(b/x*1e4)/1e4,l.cFactor=Math.round(F/x*1e4)/1e4,l.avgSpeed=Math.round(W.distanceFromStart/x*1e4)/1e4,l.totalHrs=Math.round(x*1e4)/1e4,l.totalFoCons=Math.round((n==null?void 0:n.fo)/24*l.totalHrs*1e3)/1e3,l.totalDgoCons=Math.round((n==null?void 0:n.dgo)/24*l.totalHrs*1e3)/1e3;const P=v().valueOf()-h,N=((st=I==null?void 0:I.hours)==null?void 0:st.length)||1;return q==null||q.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",c==null?void 0:c.requestId,P,N,Math.round(P/N*1e3)/1e3),l}static async analyseInstantWithThreshed(s,t,i,n,o,a,e,d="",r=3,c=!0,h=!1,M={}){var W,S,P;s.lng=A.LngLatHelper.convertToStdLng(s.lng);const{v0:p,label:f}=s.sog?{v0:s.sog,label:"Other"}:{v0:o.speed,label:"CP"},g=R.assembleProperties(n,o.loadCondition,p,0),k=A.LaneHelper.calculateSubRoute(s,a);if(((W=k[0])==null?void 0:W.length)<=1)return;const Y=e.length?A.LaneHelper.calculateSubWaypoints(s,e):[];Y.forEach(N=>N.important=!0);let m=A.LaneHelper.simplifyRouteToCoordinates(k,Y,0),l=0,I=0,H=0,y=0,b;const F={hours:[],wps:[],days:[]};for(t=v(t).utc();m.length>0;){const N=r-t.hour()%r;let E=Math.ceil(t.clone().add(N,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;if(E=t.clone().add(E,"h").isAfter(i)?i.diff(t,"h",!0)*1e4/1e4:E,E)b=await R.speedLoseInHoursStep(g,t,i.clone(),E,l,m,d,c,h,M),(S=b.from)!=null&&S.speed&&(F.hours.push(b.from),b!=null&&b.wps&&F.wps.push(...b.wps),F.days.push(...b.days)),m=b==null?void 0:b.next,m.length||(F.hours.push(b==null?void 0:b.to),b!=null&&b.wps&&F.wps.push(...b.wps),F.days.push(b==null?void 0:b.to)),l+=((P=b==null?void 0:b.to)==null?void 0:P.distanceFromPrevious)??0;else{b&&(F.hours.push(b.to),b!=null&&b.wps&&F.wps.push(...b.wps),F.days.push(b.to));break}}const x=F.hours;for(let N=0;N<x.length-1;N++){const E=v(x[N+1].eta).diff(x[N].etd,"hour",!0);I+=x[N].wxFactor*E,H+=x[N].cFactor*E,y+=E}const V=F.hours.at(0),T=F.hours.at(-1);return{sample:F,distance:Math.round(((T==null?void 0:T.distanceFromStart)||0)*1e4)/1e4,etd:v(V.eta).utc().format(),eta:v(T==null?void 0:T.eta).utc().format(),wxFactor:Math.round(I/y*1e4)/1e4,cFactor:Math.round(H/y*1e4)/1e4,avgSpeed:Math.round(((T==null?void 0:T.distanceFromStart)||0)/y*1e4)/1e4,totalHrs:Math.round(y*1e4)/1e4,from:s,to:T,route:A.LaneHelper.generateRouteAccordingToWaypoints(m),subWaypoints:Y,v0:p,label:f}}}w.AISImpl=z,w.AlertHelper=U,w.AlertLevel=G,w.HifleetImpl=it,w.LoadCondition=Q,w.MyShipImpl=ct,w.MyVesselImpl=ot,w.ShipxyImpl=rt,w.SpeedHelper=R,w.SpeedLabel=X,w.VesselTag=J,w.alertHelper=dt,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(k,D){typeof exports=="object"&&typeof module<"u"?D(exports,require("got"),require("@log4js-node/log4js-api"),require("moment"),require("@idm-plugin/geo"),require("@idm-plugin/meteo")):typeof define=="function"&&define.amd?define(["exports","got","@log4js-node/log4js-api","moment","@idm-plugin/geo","@idm-plugin/meteo"],D):(k=typeof globalThis<"u"?globalThis:k||self,D(k["idm-plugin-rabbitmq"]={},k.got,k["@log4js-node/log4js-api"],k.moment,k["@idm-plugin/geo"],k["@idm-plugin/meteo"]))})(this,function(k,D,Z,v,O,nt){"use strict";var ht=Object.defineProperty;var lt=(k,D,Z)=>D in k?ht(k,D,{enumerable:!0,configurable:!0,writable:!0,value:Z}):k[D]=Z;var K=(k,D,Z)=>(lt(k,typeof D!="symbol"?D+"":D,Z),Z);let u;try{u=Z.getLogger("vessel")}catch{}finally{}class z{parseStatus(s){let t,i;switch(s){case 0:t="在航(主机推动)",i="The engine is in use";break;case 1:t="锚泊",i="Anchored";break;case 2:t="失控",i="Not operated";break;case 3:t="操纵受限",i="Limited airworthiness";break;case 4:t="吃水受限",i="Limited by ship's draft";break;case 5:t="靠泊",i="Mooring";break;case 6:t="搁浅",i="Stranded";break;case 7:t="捕捞作业",i="Engaged in fishing";break;case 8:t="靠帆船提供动力",i="Sailing";break;default:t="未定义",i="Undefined"}return{labelCn:t,labelEn:i}}}class ot extends z{constructor(t,i){super();K(this,"clientId");K(this,"clientSecret");K(this,"token");this.clientId=t,this.clientSecret=i}async authToken(t={}){const i="https://svc.data.myvessel.cn/ada/oauth/token",n={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},o=await D.post(i,n).json();u==null||u.info("[%s] fetch access token from: %s - %j",t.requestId,i,o),o.error||(this.token={accessToken:o.access_token,tokenType:o.token_type,expiresIn:o.expires_in,scope:o.scope,jti:o.jti,issuedAt:v().utc().format()})}async realTimePosition(t,i={}){var c,h,M;(!this.token||v().diff(v(this.token.issuedAt),"seconds")>((c=this.token)==null?void 0:c.expiresIn)-300)&&await this.authToken(i);const n="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",o={headers:{Authorization:`${(h=this.token)==null?void 0:h.tokenType} ${(M=this.token)==null?void 0:M.accessToken}`},searchParams:{mmsi:t}};u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,n,o);const a=await D.get(n,o).json();if(a.code)return u==null||u.warn("[%s] fetch realtime position failed: %j",i.requestId,n,{message:a.message,status:a.status,code:a.code}),a;const e=a.data;for(const m in e)!isNaN(e[m])&&Number(e[m])!==1/0&&(e[m]=Number(e[m]));const d=v(`${e.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:e.mmsi,name:e.vesselName,imo:e.imo,callSign:e.callsign,lat:e.lat,lng:e.lon,length:e.length,width:e.width,draught:e.currDraught,sog:e.sog,cog:e.cog,hdg:e.hdg,rot:e.rot,eta:e.eta,destination:e.dest,positionTime:d.unix(),status:e.status,labelCn:e.statusNameCn,labelEn:e.statusNameEn,method:"position",vendor:"myVessel",utc:d.utc().format()}}async trajectory(t,i,n,o,a=!0,e={}){(!this.token||v().diff(v(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(e);const d=await this.realTimePosition(t,e),r=v(i),c=v(n),h=[];for(;c.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(t,r,r.clone().add(30,"day"),d,o,h,e),r.add(30,"day");return await this.trajectoryIn30Day(t,r,c,d,o,h,e),h}async trajectoryIn30Day(t,i,n,o,a,e,d={}){var f,g,j,Y,p;const r="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",c={headers:{Authorization:`${(f=this.token)==null?void 0:f.tokenType} ${(g=this.token)==null?void 0:g.accessToken}`},json:{mmsi:t,startTime:i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};u==null||u.info("[%s] fetch trajectory from: %s - %j",d.requestId,r,c);const h=await D.post(r,c).json();if(h.code)return u==null||u.warn("[%s] fetch trajectory failed: %j",d.requestId,r,{message:h.message,status:h.status,code:h.code}),h;let M=-1;const m=v(`${(Y=(j=h.data)==null?void 0:j[0])==null?void 0:Y.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(p=h.data)==null||p.forEach(l=>{for(const T in l)!isNaN(l[T])&&Number(l[T])!==1/0&&(l[T]=Number(l[T]));const I=v(`${l.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),H=l.eta?v(`${l.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,y=l.status,{labelCn:b,labelEn:F}=this.parseStatus(y),x={mmsi:l.mmsi,imo:o==null?void 0:o.imo,lat:l.lat,lng:l.lon,sog:l.sog,cog:l.cog,hdg:l.hdg,draught:l.draught,status:y,eta:H==null?void 0:H.unix(),destination:l.dest,positionTime:I.unix(),labelCn:b,labelEn:F,method:"trajectory",vendor:"myVessel",utc:I.utc().format()},V=Math.floor(I.diff(m,"minute",!0)/(a||1));V!==M&&(M=V,e.push(x))}),e}}class it extends z{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,i={}){const n="https://api.hifleet.com/position/position/get/token",o={searchParams:{mmsi:t,usertoken:this.token}},a=await D.post(n,o).json();u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,n,o);const e=a==null?void 0:a.list;if(!e)return u==null||u.warn("[%s] fetch realtime position failed: %j",i.requestId,n,a),a;for(const m in e)!isNaN(e[m])&&Number(e[m])!==1/0&&(e[m]=Number(e[m]));e.status=e.sp>3?0:1;const d=e.status,{labelCn:r,labelEn:c}=this.parseStatus(d),h=v(`${e.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:e.m,name:e.n,imo:e.imonumber,callSign:e.callsign,lat:Math.round(e.la/60*1e5)/1e5,lng:Math.round(e.lo/60*1e5)/1e5,length:e.l,width:e.w,draught:e.draught,sog:e.sp,cog:e.co,hdg:e.h,rot:isNaN(e.rot)?0:e.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta)?v(`${e.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").unix():void 0,destination:e.destination,positionTime:h.unix(),utc:h.utc().format(),status:d,labelCn:r,labelEn:c,method:"position",vendor:"hifleet"}}async search(t,i={}){let n="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const o={searchParams:{keyword:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let a=await D.post(n,o).json();u==null||u.info("[%s] fetch vessel props from: %s - %j",i.requestId,n,o),a instanceof Array&&(a=a[0]);for(const d in a)!isNaN(a[d])&&Number(a[d])!==1/0&&(a[d]=Number(a[d]));const e={mmsi:a.m,name:a.n,imo:a.i,callSign:a.c,length:a.l,breadth:a.b,draught:a.dr};return n="https://www.hifleet.com/hifleetapi/sameShipSearch.do",a=await D.post(n,o).json(),u==null||u.info("[%s] fetch vessel dead weight from: %s - %j",i.requestId,n,o),a instanceof Array&&(a=a[0]),a&&(e.deadweight=Number(a.dwt)),e}async trajectory(t,i,n,o,a=!0,e={}){var l,I,H;const d=await this.realTimePosition(t,e);let r=v(i);const c=v(n),h=v();if(a){let y=c.diff(r,"d",!0);y<0?r=c.clone().subtract(40,"d"):y<30?r.subtract(10,"d"):y<60?r.subtract(5,"d"):r=c.clone().subtract(80,"d"),y=h.diff(c,"d",!0),c.add(y>10?240:y*24,"h")}const M={searchParams:{endtime:c.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),starttime:r.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),mmsi:t,usertoken:this.token}},m="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",f=await D.get(m,M).json();u==null||u.info("[%s] fetch trajectory from: %s - %j",e.requestId,m,M);let g;f&&(g=((I=(l=f.ships)==null?void 0:l.offors)==null?void 0:I.ship)||[],g.length||u==null||u.warn("[%s] fetch trajectory failed: %j",e.requestId,f));const j=[];let Y=-1;const p=v(`${(H=g==null?void 0:g[0])==null?void 0:H.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const y of g){for(const _ in y)!isNaN(y[_])&&Number(y[_])!==1/0&&(y[_]=Number(y[_]));const b=v(`${y.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");y.status=y.sp>4?0:1;const{labelEn:F,labelCn:x}=this.parseStatus(y.status),V={mmsi:y.m,name:y.n,imo:d==null?void 0:d.imo,lat:y.la,lng:y.lo,draught:y.draught,sog:y.sp,cog:y.co,hdg:y.hdg,positionTime:b.unix(),utc:b.utc().format(),status:y.status,labelCn:x,labelEn:F,method:"trajectory",vendor:"hifleet"},T=Math.floor(b.diff(p,"minute",!0)/(o||1));T!==Y&&(Y=T,j.push(V))}return j}}class rt extends z{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,i={}){const n={searchParams:{id:t,k:this.token,enc:1}},o="https://api.shipxy.com/apicall/GetSingleShip",a=await D.get(o,n).json();if(u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,o,n),(a==null?void 0:a.status)!==0)return a;const e=a.data[0];for(const M in e)!isNaN(e[M])&&Number(e[M])!==1/0&&(e[M]=Number(e[M]));const{labelCn:d,labelEn:r}=await this.parseStatus(e.navistat),c=v.unix(e.lasttime);return{mmsi:e.ShipID,name:e.name,imo:e.imo,callSign:e.callsign,lat:Math.round(e.lat/1e6*1e5)/1e5,lng:Math.round(e.lon/1e6*1e5)/1e5,length:Math.round(e.length/10*100)/100,width:Math.round(e.width/10*100)/100,draught:Math.round(e.draught/1e3*100)/100,sog:Math.round(e.sog*3600/1e3/1852*100)/100,cog:Math.round(e.cog/100*100)/100,hdg:Math.round(e.hdg/100*100)/100,rot:Math.round(e.rot/100*100)/100,positionTime:e.lasttime,utc:c.utc().format(),status:e.navistat,labelEn:r,labelCn:d,method:"position",vendor:"shipxy"}}async trajectory(t,i,n,o,a=!0,e={}){var p;const d=await this.realTimePosition(t,e),r=v(i),c=v(n),h="https://api.shipxy.com/apicall/GetShipTrack",M={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:r.unix(),etm:c.unix()}},m=await D.get(h,M).json();if(u==null||u.info("[%s] fetch trajectory from: %s - %j",e.requestId,h,M),(m==null?void 0:m.status)!==0)return m;const f=m==null?void 0:m.points,g=[],j=v.unix((p=f[0])==null?void 0:p.utc);let Y=-1;for(const l of f){const I=v.unix(l.utc),H={imo:d==null?void 0:d.imo,mmsi:t,sog:Math.round(l.sog*3600/1e3/1852*100)/100,cog:Math.round(l.cog/100*100)/100,lat:Math.round(l.lat/1e6*1e5)/1e5,lng:Math.round(l.lon/1e6*1e5)/1e5,positionTime:I.unix(),utc:I.utc().format(),method:"trajectory",vendor:"shipxy"},y=Math.floor(I.diff(j,"minute",!0)/(o||1));y!==Y&&(Y=y,g.push(H))}return g}}class ct extends z{constructor(t){super();K(this,"token");this.token=t}async getShipId(t,i={}){const n={headers:{appKey:this.token},json:{mmsiList:t}},o="https://api3.myships.com/sp/ships/getShipIdByMMSI",a=await D.post(o,n).json();return u==null||u.info("[%s] fetch ship id from: %s - %j",i.requestId,o,n),a.code!=="0"?a:a.data[0].shipId}async getShipInfo(t,i={}){const n={headers:{appKey:this.token},json:{shipId:t}},o="https://api3.myships.com/sp/ships/aissta",a=await D.post(o,n).json();if(u==null||u.info("[%s] fetch ship info from: %s - %j",i.requestId,o,n),a.code!=="0")return a;const e=a.data;let d=e.imo;return t==="407170"&&(d="9198379",u==null||u.warn("[%s] ship(%s) imo error: %s, should be %s",i.requestId,t,e.imo,d)),{mmsi:e.mmsi,name:e.shipnameEn,imo:d,callSign:e.callSign,length:e.length,width:e.breadth,draught:(e.draught||100)/10}}async realTimePosition(t,i={}){const n=await this.getShipId(t,i),o=await this.getShipInfo(n,i),a={headers:{appKey:this.token},json:{shipId:n}},e="https://api3.myships.com/sp/ships/position/latest",d=await D.post(e,a).json();u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,e,a);const r=d.data[0];for(const f in r)!isNaN(r[f])&&Number(r[f])!==1/0&&(r[f]=Number(r[f]));const{labelCn:c,labelEn:h}=await this.parseStatus(r.aisNavStatus),M=v.unix(r.posTime);return{...o,mmsi:t,lat:Math.round(r.lat/1e4/60*1e5)/1e5,lng:Math.round(r.lon/1e4/60*1e5)/1e5,sog:Math.round(r.sog/10*100)/100,cog:Math.round(r.cog/10*100)/100,hdg:Math.round(r.heading*100)/100,rot:Math.round(r.rot*100)/100,positionTime:r.posTime,utc:M.utc().format(),status:r.aisNavStatus,labelEn:h,labelCn:c,method:"position",vendor:"myship"}}async trajectory(t,i,n,o,a=!0,e={}){const d=v(i),r=v(n),c=await this.getShipId(t),h=await this.getShipInfo(c),M=[];for(;r.diff(d,"day",!0)>30;)await this.trajectoryIn30Day(c,d.unix(),d.add(30,"day").unix(),h,t,o,M);return await this.trajectoryIn30Day(c,d.unix(),r.unix(),h,t,o,M),M}async trajectoryIn30Day(t,i,n,o,a,e,d,r={}){var j;const c={headers:{appKey:this.token},json:{shipId:t,startTime:i,endTime:n}},h="https://api3.myships.com/sp/ships/position/history",M=await D.post(h,c).json();if(u==null||u.info("[%s] fetch trajectory from: %s - %j",r.requestId,h,c),M.code!=="0")return u==null||u.warn("[%s] invoke myship trajectory failed: %j",r.requestId,M),M;const m=M.data;for(const Y in m)!isNaN(m[Y])&&Number(m[Y])!==1/0&&(m[Y]=Number(m[Y]));const f=v.unix((j=m[0])==null?void 0:j.posTime);let g=-1;for(const Y of m){const p=v.unix(Y.posTime),l={imo:o==null?void 0:o.imo,mmsi:a,lat:Math.round(Y.lat/1e4/60*1e5)/1e5,lng:Math.round(Y.lon/1e4/60*1e5)/1e5,sog:Math.round(Y.sog/10*100)/100,cog:Math.round(Y.cog/10*100)/100,hdg:Math.round(Y.heading*100)/100,rot:Math.round(Y.rot*100)/100,positionTime:p.unix(),utc:p.utc().format(),method:"trajectory",vendor:"myship"},I=Math.floor(p.diff(f,"minute",!0)/(e||1));I!==g&&(g=I,d.push(l))}return d}}let R;try{R=Z.getLogger("vessel")}catch{}finally{}var G=(w=>(w.NOTICE="NOTICE",w.WARN="WARN",w.HEAVY="HEAVY",w.SEVERE="SEVERE",w.ERROR="ERROR",w.FATAL="FATAL",w))(G||{});class U{parsePrinciple(s,t={}){var e,d,r;R==null||R.info("[%s] parse rule: %s",t.requestId,s);const i=new RegExp("(?<=\\[)(.+)(?=])","g"),n=s.match(i)?(e=s.match(i))==null?void 0:e[0]:void 0,o=n==null?void 0:n.split(";");if(!o)return;const a={};for(let c=0;c<(o==null?void 0:o.length);c++){const h=(r=(d=o[c].match(i))==null?void 0:d[0])==null?void 0:r.split("],");if(c===0&&!h)a.scope=o[0];else if(h)for(let M=0,m=h.length;M<m;M++){const f=this.parseRule(h[M]);f&&(a[f.level]?f.key?a[f.level][f==null?void 0:f.key]=f:a[f.level]=f:f.key?a[f.level]={[f==null?void 0:f.key]:f}:a[f.level]=f)}}return a}parseRule(s,t={}){var a;R==null||R.info("[%s] parse rule: %s",t.requestId,s),s=s.startsWith("[")?s:`[${s}`,s=s.endsWith("]")?s:`${s}]`;const i=new RegExp("(?<=\\[)(.+?)(?=])","g"),n=(a=s==null?void 0:s.match(i))==null?void 0:a[0],o=n==null?void 0:n.split(",");if(o)return{operator:o[0],number:Number.isNaN(Number(o[1]))?o[1]:Number(o[1]),level:o[2],time:Number(o[3]),key:o[4]}}checkWeather(s,t,i={}){var f,g,j,Y,p,l,I,H,y,b,F,x,V,T,_;let n=0,o=0,a=0,e=0;const d=Math.round(((g=(f=t==null?void 0:t.SEVERE)==null?void 0:f.sigWave)==null?void 0:g.number)*1.6*100)/100,r=(Y=(j=t==null?void 0:t.SEVERE)==null?void 0:j.sigWave)==null?void 0:Y.number,c=(l=(p=t==null?void 0:t.HEAVY)==null?void 0:p.sigWave)==null?void 0:l.number,h=Math.round((((H=(I=t==null?void 0:t.SEVERE)==null?void 0:I.wind)==null?void 0:H.number)+2)*100)/100,M=(b=(y=t==null?void 0:t.SEVERE)==null?void 0:y.wind)==null?void 0:b.number,m=(x=(F=t==null?void 0:t.HEAVY)==null?void 0:F.wind)==null?void 0:x.number;for(let W=0;W<(s==null?void 0:s.length);W++){const S=s[W],L=(T=(V=S==null?void 0:S.meteo)==null?void 0:V.wave)==null?void 0:T.sig,N=(_=S==null?void 0:S.meteo)==null?void 0:_.wind,E=W?v(S.eta).diff(v(s[W-1].eta),"hour",!0):0;e=E>e?E:e,R==null||R.info("[%s] check sig.wave: %j",i.requestId,{...L,dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:c}),(L==null?void 0:L.height)>=d?S.isDangerous=!0:(L==null?void 0:L.height)>=r?S.isSevere=!0:(L==null?void 0:L.height)>=c&&(S.isHeavy=!0),R==null||R.info("[%s] check wind: %j",i.requestId,{...N,dgThd4Wd:h,svThd4Wd:M,hvThd4Wd:m}),(N==null?void 0:N.scale)>=h?(S.isDangerous=!0,delete S.isSevere,delete S.isHeavy):(N==null?void 0:N.scale)>M?(S.isDangerous||(S.isSevere=!0),delete S.isHeavy):(N==null?void 0:N.scale)===m&&!S.isDangerous&&!S.isSevere&&(S.isHeavy=!0),n+=S.isDangerous?E:0,o+=S.isSevere?E:0,a+=S.isHeavy?E:0}return n=Math.round(n*100)/100,o=Math.round(o*100)/100,a=Math.round(a*100)/100,e=Math.round(e),{sample:s,dangerous:n,severe:o,heavy:a,step:e<3?3:e,wind:{dgThd4Wd:h,svThd4Wd:M,hvThd4Wd:m},sig:{dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:c}}}}const dt=new U;let q;try{q=Z.getLogger("vessel")}catch{}finally{}var J=(w=>(w.common="common",w.container="container",w))(J||{}),Q=(w=>(w.Ballast="Ballast",w.Laden="Laden",w))(Q||{}),X=(w=>(w.Cp="CP",w.Perf="Basis",w.Instruct="Other",w))(X||{});class A{static blockCoefficient(s,t,i,n){let o=Math.round(s/(t*i*n)*100)/100;o=o<.55?.55:o>.85?.85:o;const a=[.55,.6,.65,.7,.75,.8,.85],e=a.map(d=>Math.abs(d-o));return a[e.indexOf(Math.min(...e))]}static froudeNumber(s,t,i=9.8){let n=Math.round(Math.sqrt(s*s/(i*t))*100)/100;return n=n<.05?.05:n>.3?.3:n,n}static amendFactor(s,t,i){const n={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.4,-10.6,-9.5],.8:[2.6,-13.1,-15.1],.85:[3.1,-18.7,28]};let a={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.6,-12.5,-13.5],.8:[3,-16.3,-21.6],.85:[3.4,-20.9,31.8]}[s];return i==="Laden"&&(a=n[s]),a[0]+a[1]*t+a[2]*Math.pow(t,2)}static directionFactor(s,t=0){let i;return s>30&&s<=60?i=(1.7-.03*Math.pow(t-4,2))/2:s>60&&s<=150?i=(.9-.06*Math.pow(t-6,2))/2:i=(.4-.03*Math.pow(t-8,2))/2,Math.round(i*1e5)/1e5}static vesselTagFactor(s,t,i,n=0){n=n>5?n-.9*(n-5):n;let o;return i==="container"?o=.7*n+Math.pow(n,6.5)/(22*Math.pow(s,2/3)):t==="Ballast"?o=.7*n+Math.pow(n,6.5)/(2.7*Math.pow(s,2/3)):o=.5*n+Math.pow(n,6.5)/(2.7*Math.pow(s,2/3)),o}static waveHeightFactor(s){return s=s<1.25?1.25:s,s=s>6?s-.9*(s-6):s,Math.round((-.144*Math.pow(s,2)+.178*s)*1e4)/1e4}static assembleProperties(s,t,i,n){var c,h;const o=s.lbp??s.length??s.lengthOverall??198.9642,a=s.draught??8,e=s.breadthMoulded??s.breadth??s.breadthExtreme??32.4572,d=s.deadweight??67035.7773;return{tag:((h=(c=s==null?void 0:s.type)==null?void 0:c.toLowerCase())==null?void 0:h.indexOf("container"))>-1?"container":"common",lbp:o,loadCondition:t,draught:a,breadthMoulded:e,displacement:Math.round((d/1.025+a*e*o*.7)*1e4)/1e4,speed:Math.round((i??14.1382)*1852/3600*1e4)/1e4,bearing:n||90}}static async speedLoseAt(s,t,i,n="",o=2,a=!0,e=!1,d={}){let r;if(t.velocity&&e&&(s.speed=O.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),a){const c=await nt.MeteoHelper.queryPointFactor(t.lng,t.lat,i.valueOf(),"wind,wave,current,watertemp",n,d),h=A.weatherFactor(s,c),M=A.currentFactor(s.bearing,c==null?void 0:c.current,o);r={meteo:{...c},wxFactor:h,cFactor:M,speed:t.velocity&&e?t.velocity:Math.round((s.speed*1.943844+h+M)*100)/100,eta:i.utc().format("YYYY-MM-DDTHH:mm[Z]"),etd:i.utc().format("YYYY-MM-DDTHH:mm[Z]")}}else r={wxFactor:0,cFactor:0,speed:t.velocity&&e?t.velocity:Math.round((s.speed*1.943844+0+0)*100)/100,eta:i.utc().format("YYYY-MM-DDTHH:mm[Z]"),etd:i.utc().format("YYYY-MM-DDTHH:mm[Z]")};return delete t.meteo,delete t.wxFactor,delete t.cFactor,delete t.speed,delete t.etd,{...r,...t}}static async speedLoseInHoursStep(s,t,i,n,o,a,e="",d=!0,r=!1,c={}){t.utc();const h=[],M=[];let m=0,f=0,g,j;for(let Y=0;Y<a.length-1;Y++){let p=a[Y];p.distanceFromStart=o+f;const l=a[Y+1];if(s.bearing=O.LaneHelper.calculateBearing(p,l,!l.gcToPrevious),p.bearing=s.bearing,p.suspend&&r){p.eta=p.eta||t.format("YYYY-MM-DDTHH:mm[Z]"),p.elapsed=p.elapsed??0;const y=p.suspend-p.elapsed;if(n-m>y)n=n-m-y,t.add(y,"hour"),p.elapsed=p.suspend;else{const b=n-m;p.elapsed+=b,t.add(b,"hour"),n=0}if(q==null||q.info(`[%s] suspend ${p.elapsed} hours at %j, and remain ${n} hours need to go...`,c.requestId,p),n===0)return p.distanceFromPrevious=f,{etd:t,from:j||p,to:p,next:a.filter(b=>b),wps:h,days:M}}p=await A.speedLoseAt(s,p,t,e,0,d,r,c),j=j||p,p.important&&h.push(p),t.isSameOrAfter(i)&&(M.push(p),i.add(24,"hour"));const I=O.LaneHelper.calculateDistance(p,l,!l.gcToPrevious);let H=Math.ceil(I/j.speed*1e4)/1e4;if(m+H<n){if(m+=H,t.add(H,"hour"),delete a[Y],q==null||q.info(`[%s] go to %j from %j with ${I}nm, and cost ${H} hours`,c.requestId,{lat:l.lat,lng:l.lng},{lat:j.lat,lng:j.lng,etd:j.etd}),f+=I,a.filter(y=>y).length<=1){g=l,g.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),g.distanceFromPrevious=I,g.distanceFromStart=o+f,h.push(g),delete a[Y+1];break}}else{H=n-m,t.add(H,"hour");const y=O.LngLatHelper.roundPrecision(j.speed*H,4);g=O.LaneHelper.calculateCoordinate(p,s.bearing,y,"nauticalmiles",!l.gcToPrevious),g.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),a[Y]=g,q==null||q.info(`[%s] go to %j from %j with ${y}nm, and cost ${H} hours`,c.requestId,{lat:g.lat,lng:g.lng},{lat:p.lat,lng:p.lng,etd:p.etd}),f+=y,g.distanceFromPrevious=f,g.distanceFromStart=o+f;break}}return{etd:t,from:j,to:g,next:a.filter(Y=>Y),wps:h,days:M}}static currentFactor(s,t,i=0){const n=(s-(t==null?void 0:t.degree)||0)/180*Math.PI;if(Math.abs(n)===Math.PI/2)return 0;let o=((t==null?void 0:t.kts)||0)*Math.cos(n);return i&2?o=Math.ceil(o*100)/100:i&1?o=Math.floor(o*100)/100:o=Math.round(o*100)/100,Math.abs(o)>5?0:o}static weatherFactor(s,t){var h,M,m,f,g;q==null||q.debug("calculate weather factor via: %j",{...s,...t});const i=A.blockCoefficient(s.displacement,s.lbp,s.breadthMoulded,s.draught),n=A.froudeNumber(s.speed,s.lbp),o=A.amendFactor(i,n,s.loadCondition);let a=Math.abs(s.bearing%360-(((h=t==null?void 0:t.wind)==null?void 0:h.degree)%360||0));a=a>180?360-a:a;const e=A.directionFactor(a,(M=t==null?void 0:t.wind)==null?void 0:M.scale),d=A.vesselTagFactor(s.displacement,s.loadCondition,s.tag,(m=t==null?void 0:t.wind)==null?void 0:m.scale);let r=e*o*d/100*s.speed;r=Math.round(r*1.943844*1e4)/1e4*-1;const c=A.waveHeightFactor(((g=(f=t==null?void 0:t.wave)==null?void 0:f.sig)==null?void 0:g.height)??1);return r=r*.24+c*.76,q==null||q.debug("weather factor = %s",r),Math.round(r*100)/100}static async analyseInstant(s,t,i,n,o,a="",e=0,d=!0,r=!1,c={}){var E,$,tt,et,st;const h=v().valueOf();s.lng=O.LngLatHelper.convertToStdLng(s.lng);const{route:M,waypoints:m}=o.points,f=O.LaneHelper.calculateSubRoute(s,M);if(((E=f[0])==null?void 0:E.length)<=1)return;const{v0:g,label:j}=s.sog?{v0:s.sog,label:"Other"}:{v0:n.speed,label:"CP"},Y=A.assembleProperties(i,n.loadCondition,g,0),p=m.length?O.LaneHelper.calculateSubWaypoints(s,m):[];p.forEach(C=>C.important=!0);const l={from:{...s},route:f,waypoints:p,v0:g,label:j},I={hours:[],days:[],wps:[]};e||(O.LaneHelper.calculateRouteDistance(f)/n.speed<=72?e=3:e=6);let H=O.LaneHelper.simplifyRouteToCoordinates(f,p,0),y=0,b=0,F=0,x=0;t=v(t).utc();const V=t.clone();for(;H.length>0;){const C=e-t.hour()%e,B=Math.ceil(t.clone().add(C,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,P=await A.speedLoseInHoursStep(Y,t,V,B,y,H,a,d,r,c);($=P.from)!=null&&$.speed&&(I.hours.push(P.from),I.wps.push(...P.wps),I.days.push(...P.days)),H=P==null?void 0:P.next,H.length||I.hours.push(P==null?void 0:P.to),y+=((tt=P==null?void 0:P.to)==null?void 0:tt.distanceFromPrevious)??0}const T=I.hours;for(let C=0;C<T.length-1;C++){const B=v(T[C+1].eta).diff(T[C].etd,"hour",!0)||1;b+=(T[C].wxFactor||0)*B,F+=(T[C].cFactor||0)*B,x+=B}(et=I.wps)==null||et.forEach((C,B)=>{if(B){const P=I.wps[B-1],ut=C.distanceFromStart-P.distanceFromStart,at=v(C.eta).diff(v(P.etd),"h",!0);at<1?C.avgSpd=P.speed:C.avgSpd=Math.round(ut/at*100)/100}}),l.sample=I;const _=I.hours.at(0),W=I.hours.at(-1);l.distance=Math.round(W.distanceFromStart*1e4)/1e4,l.etd=v(_.eta).utc().format(),l.eta=v(W.eta).utc().format(),l.wxFactor=Math.round(b/x*1e4)/1e4,l.cFactor=Math.round(F/x*1e4)/1e4,l.avgSpeed=Math.round(W.distanceFromStart/x*1e4)/1e4,l.totalHrs=Math.round(x*1e4)/1e4,l.totalFoCons=Math.round((n==null?void 0:n.fo)/24*l.totalHrs*1e3)/1e3,l.totalDgoCons=Math.round((n==null?void 0:n.dgo)/24*l.totalHrs*1e3)/1e3;const L=v().valueOf()-h,N=((st=I==null?void 0:I.hours)==null?void 0:st.length)||1;return q==null||q.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",c==null?void 0:c.requestId,L,N,Math.round(L/N*1e3)/1e3),l}static async analyseInstantWithThreshed(s,t,i,n,o,a,e,d="",r=3,c=!0,h=!1,M={}){var W,S,L;s.lng=O.LngLatHelper.convertToStdLng(s.lng);const{v0:m,label:f}=s.sog?{v0:s.sog,label:"Other"}:{v0:o.speed,label:"CP"},g=A.assembleProperties(n,o.loadCondition,m,0),j=O.LaneHelper.calculateSubRoute(s,a);if(((W=j[0])==null?void 0:W.length)<=1)return;const Y=e.length?O.LaneHelper.calculateSubWaypoints(s,e):[];Y.forEach(N=>N.important=!0);let p=O.LaneHelper.simplifyRouteToCoordinates(j,Y,0),l=0,I=0,H=0,y=0,b;const F={hours:[],wps:[],days:[]};for(t=v(t).utc();p.length>0;){const N=r-t.hour()%r;let E=Math.ceil(t.clone().add(N,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;if(E=t.clone().add(E,"h").isAfter(i)?i.diff(t,"h",!0)*1e4/1e4:E,E)b=await A.speedLoseInHoursStep(g,t,i.clone(),E,l,p,d,c,h,M),(S=b.from)!=null&&S.speed&&(F.hours.push(b.from),b!=null&&b.wps&&F.wps.push(...b.wps),F.days.push(...b.days)),p=b==null?void 0:b.next,p.length||(F.hours.push(b==null?void 0:b.to),b!=null&&b.wps&&F.wps.push(...b.wps),F.days.push(b==null?void 0:b.to)),l+=((L=b==null?void 0:b.to)==null?void 0:L.distanceFromPrevious)??0;else{b&&(F.hours.push(b.to),b!=null&&b.wps&&F.wps.push(...b.wps),F.days.push(b.to));break}}const x=F.hours;for(let N=0;N<x.length-1;N++){const E=v(x[N+1].eta).diff(x[N].etd,"hour",!0);I+=x[N].wxFactor*E,H+=x[N].cFactor*E,y+=E}const V=F.hours.at(0),T=F.hours.at(-1);return{sample:F,distance:Math.round(((T==null?void 0:T.distanceFromStart)||0)*1e4)/1e4,etd:v(V.eta).utc().format(),eta:v(T==null?void 0:T.eta).utc().format(),wxFactor:Math.round(I/y*1e4)/1e4,cFactor:Math.round(H/y*1e4)/1e4,avgSpeed:Math.round(((T==null?void 0:T.distanceFromStart)||0)/y*1e4)/1e4,totalHrs:Math.round(y*1e4)/1e4,from:s,to:T,route:j,waypoints:Y,v0:m,label:f}}}k.AISImpl=z,k.AlertHelper=U,k.AlertLevel=G,k.HifleetImpl=it,k.LoadCondition=Q,k.MyShipImpl=ct,k.MyVesselImpl=ot,k.ShipxyImpl=rt,k.SpeedHelper=A,k.SpeedLabel=X,k.VesselTag=J,k.alertHelper=dt,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
|