@idm-plugin/vessel 1.7.5 → 1.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +161 -163
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -54,7 +54,7 @@ class et {
|
|
|
54
54
|
return { labelCn: t, labelEn: n };
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
class
|
|
57
|
+
class Ct extends et {
|
|
58
58
|
constructor(t, n) {
|
|
59
59
|
super();
|
|
60
60
|
G(this, "clientId");
|
|
@@ -80,8 +80,8 @@ class xt extends et {
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
async realTimePosition(t, n = {}) {
|
|
83
|
-
var
|
|
84
|
-
(!this.token || p().diff(p(this.token.issuedAt), "seconds") > ((
|
|
83
|
+
var u, m, l;
|
|
84
|
+
(!this.token || p().diff(p(this.token.issuedAt), "seconds") > ((u = this.token) == null ? void 0 : u.expiresIn) - 300) && await this.authToken(n);
|
|
85
85
|
const i = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit", o = {
|
|
86
86
|
headers: {
|
|
87
87
|
Authorization: `${(m = this.token) == null ? void 0 : m.tokenType} ${(l = this.token) == null ? void 0 : l.accessToken}`
|
|
@@ -123,16 +123,16 @@ class xt extends et {
|
|
|
123
123
|
}
|
|
124
124
|
async trajectory(t, n, i, o, a = !0, s = {}) {
|
|
125
125
|
(!this.token || p().diff(p(this.token.issuedAt), "seconds") > this.token.expiresIn - 300) && await this.authToken(s);
|
|
126
|
-
const d = await this.realTimePosition(t, s), r = p(n),
|
|
127
|
-
for (;
|
|
126
|
+
const d = await this.realTimePosition(t, s), r = p(n), u = p(i), m = [];
|
|
127
|
+
for (; u.diff(r, "day", !0) > 30; )
|
|
128
128
|
await this.trajectoryIn30Day(t, r, r.clone().add(30, "day"), d, o, m, s), r.add(30, "day");
|
|
129
|
-
return await this.trajectoryIn30Day(t, r,
|
|
129
|
+
return await this.trajectoryIn30Day(t, r, u, d, o, m, s), m;
|
|
130
130
|
}
|
|
131
131
|
async trajectoryIn30Day(t, n, i, o, a, s, d = {}) {
|
|
132
|
-
var f,
|
|
133
|
-
const r = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",
|
|
132
|
+
var f, x, k, v, b;
|
|
133
|
+
const r = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", u = {
|
|
134
134
|
headers: {
|
|
135
|
-
Authorization: `${(f = this.token) == null ? void 0 : f.tokenType} ${(
|
|
135
|
+
Authorization: `${(f = this.token) == null ? void 0 : f.tokenType} ${(x = this.token) == null ? void 0 : x.accessToken}`
|
|
136
136
|
},
|
|
137
137
|
json: {
|
|
138
138
|
mmsi: t,
|
|
@@ -140,8 +140,8 @@ class xt extends et {
|
|
|
140
140
|
endTime: i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
|
-
g == null || g.info("[%s] fetch trajectory from: %s - %j", d.requestId, r,
|
|
144
|
-
const m = await J.post(r,
|
|
143
|
+
g == null || g.info("[%s] fetch trajectory from: %s - %j", d.requestId, r, u);
|
|
144
|
+
const m = await J.post(r, u).json();
|
|
145
145
|
if (m.code)
|
|
146
146
|
return g == null || g.warn("[%s] fetch trajectory failed: %j", d.requestId, r, { message: m.message, status: m.status, code: m.code }), m;
|
|
147
147
|
let l = -1;
|
|
@@ -149,7 +149,7 @@ class xt extends et {
|
|
|
149
149
|
return (b = m.data) == null || b.forEach((c) => {
|
|
150
150
|
for (const Y in c)
|
|
151
151
|
!isNaN(c[Y]) && Number(c[Y]) !== 1 / 0 && (c[Y] = Number(c[Y]));
|
|
152
|
-
const w = p(`${c.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), M = c.status, { labelCn:
|
|
152
|
+
const w = p(`${c.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), M = c.status, { labelCn: h, labelEn: I } = this.parseStatus(M), S = {
|
|
153
153
|
mmsi: c.mmsi,
|
|
154
154
|
imo: o == null ? void 0 : o.imo,
|
|
155
155
|
lat: c.lat,
|
|
@@ -162,7 +162,7 @@ class xt extends et {
|
|
|
162
162
|
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(c.eta) ? p(`${c.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00").utc().format() : void 0,
|
|
163
163
|
destination: c.dest,
|
|
164
164
|
positionTime: w.unix(),
|
|
165
|
-
labelCn:
|
|
165
|
+
labelCn: h,
|
|
166
166
|
labelEn: I,
|
|
167
167
|
method: "trajectory",
|
|
168
168
|
vendor: "myVessel",
|
|
@@ -192,7 +192,7 @@ class jt extends et {
|
|
|
192
192
|
for (const y in s)
|
|
193
193
|
!isNaN(s[y]) && Number(s[y]) !== 1 / 0 && (s[y] = Number(s[y]));
|
|
194
194
|
s.status = s.sp > 3 ? 0 : 1;
|
|
195
|
-
const d = s.status, { labelCn: r, labelEn:
|
|
195
|
+
const d = s.status, { labelCn: r, labelEn: u } = this.parseStatus(d), m = p(`${s.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
196
196
|
return {
|
|
197
197
|
mmsi: s.m,
|
|
198
198
|
name: s.n,
|
|
@@ -213,7 +213,7 @@ class jt extends et {
|
|
|
213
213
|
utc: m.utc().format(),
|
|
214
214
|
status: d,
|
|
215
215
|
labelCn: r,
|
|
216
|
-
labelEn:
|
|
216
|
+
labelEn: u,
|
|
217
217
|
method: "position",
|
|
218
218
|
vendor: "hifleet"
|
|
219
219
|
};
|
|
@@ -273,43 +273,43 @@ class jt extends et {
|
|
|
273
273
|
var c, w, M;
|
|
274
274
|
const d = await this.realTimePosition(t, s);
|
|
275
275
|
let r = p(n);
|
|
276
|
-
const
|
|
276
|
+
const u = p(i), m = p();
|
|
277
277
|
if (a) {
|
|
278
|
-
let
|
|
279
|
-
|
|
278
|
+
let h = u.diff(r, "d", !0);
|
|
279
|
+
h < 0 ? r = u.clone().subtract(40, "d") : h < 30 ? r.subtract(10, "d") : h < 60 ? r.subtract(5, "d") : r = u.clone().subtract(80, "d"), h = m.diff(u, "d", !0), u.add(h > 10 ? 240 : h * 24, "h");
|
|
280
280
|
}
|
|
281
281
|
const l = {
|
|
282
282
|
searchParams: {
|
|
283
|
-
endtime:
|
|
283
|
+
endtime: u.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
|
|
284
284
|
starttime: r.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
|
|
285
285
|
mmsi: t,
|
|
286
286
|
usertoken: this.token
|
|
287
287
|
}
|
|
288
288
|
}, y = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", f = await J.get(y, l).json();
|
|
289
289
|
g == null || g.info("[%s] fetch trajectory from: %s - %j", s.requestId, y, l);
|
|
290
|
-
let
|
|
291
|
-
f && (
|
|
290
|
+
let x;
|
|
291
|
+
f && (x = ((w = (c = f.ships) == null ? void 0 : c.offors) == null ? void 0 : w.ship) || [], x.length || g == null || g.warn("[%s] fetch trajectory failed: %j", s.requestId, f));
|
|
292
292
|
const k = [];
|
|
293
293
|
let v = -1;
|
|
294
|
-
const b = p(`${(M =
|
|
295
|
-
for (const
|
|
296
|
-
for (const P in
|
|
297
|
-
!isNaN(
|
|
298
|
-
const I = p(`${
|
|
299
|
-
|
|
300
|
-
const { labelEn: S, labelCn: D } = this.parseStatus(
|
|
301
|
-
mmsi:
|
|
302
|
-
name:
|
|
294
|
+
const b = p(`${(M = x == null ? void 0 : x[0]) == null ? void 0 : M.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
295
|
+
for (const h of x) {
|
|
296
|
+
for (const P in h)
|
|
297
|
+
!isNaN(h[P]) && Number(h[P]) !== 1 / 0 && (h[P] = Number(h[P]));
|
|
298
|
+
const I = p(`${h.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
299
|
+
h.status = h.sp > 4 ? 0 : 1;
|
|
300
|
+
const { labelEn: S, labelCn: D } = this.parseStatus(h.status), Y = {
|
|
301
|
+
mmsi: h.m,
|
|
302
|
+
name: h.n,
|
|
303
303
|
imo: d == null ? void 0 : d.imo,
|
|
304
|
-
lat:
|
|
305
|
-
lng:
|
|
306
|
-
draught:
|
|
307
|
-
sog:
|
|
308
|
-
cog:
|
|
309
|
-
hdg:
|
|
304
|
+
lat: h.la,
|
|
305
|
+
lng: h.lo,
|
|
306
|
+
draught: h.draught,
|
|
307
|
+
sog: h.sp,
|
|
308
|
+
cog: h.co,
|
|
309
|
+
hdg: h.hdg,
|
|
310
310
|
positionTime: I.unix(),
|
|
311
311
|
utc: I.utc().format(),
|
|
312
|
-
status:
|
|
312
|
+
status: h.status,
|
|
313
313
|
labelCn: D,
|
|
314
314
|
labelEn: S,
|
|
315
315
|
method: "trajectory",
|
|
@@ -339,7 +339,7 @@ class Et extends et {
|
|
|
339
339
|
const s = a.data[0];
|
|
340
340
|
for (const l in s)
|
|
341
341
|
!isNaN(s[l]) && Number(s[l]) !== 1 / 0 && (s[l] = Number(s[l]));
|
|
342
|
-
const { labelCn: d, labelEn: r } = await this.parseStatus(s.navistat),
|
|
342
|
+
const { labelCn: d, labelEn: r } = await this.parseStatus(s.navistat), u = p.unix(s.lasttime);
|
|
343
343
|
return {
|
|
344
344
|
mmsi: s.ShipID,
|
|
345
345
|
name: s.name,
|
|
@@ -355,7 +355,7 @@ class Et extends et {
|
|
|
355
355
|
hdg: Math.round(s.hdg / 100 * 100) / 100,
|
|
356
356
|
rot: Math.round(s.rot / 100 * 100) / 100,
|
|
357
357
|
positionTime: s.lasttime,
|
|
358
|
-
utc:
|
|
358
|
+
utc: u.utc().format(),
|
|
359
359
|
status: s.navistat,
|
|
360
360
|
labelEn: r,
|
|
361
361
|
labelCn: d,
|
|
@@ -365,19 +365,19 @@ class Et extends et {
|
|
|
365
365
|
}
|
|
366
366
|
async trajectory(t, n, i, o, a = !0, s = {}) {
|
|
367
367
|
var b;
|
|
368
|
-
const d = await this.realTimePosition(t, s), r = p(n),
|
|
368
|
+
const d = await this.realTimePosition(t, s), r = p(n), u = p(i), m = "https://api.shipxy.com/apicall/GetShipTrack", l = {
|
|
369
369
|
searchParams: {
|
|
370
370
|
id: t,
|
|
371
371
|
k: this.token,
|
|
372
372
|
enc: 1,
|
|
373
373
|
cut: 0,
|
|
374
374
|
btm: r.unix(),
|
|
375
|
-
etm:
|
|
375
|
+
etm: u.unix()
|
|
376
376
|
}
|
|
377
377
|
}, y = await J.get(m, l).json();
|
|
378
378
|
if (g == null || g.info("[%s] fetch trajectory from: %s - %j", s.requestId, m, l), (y == null ? void 0 : y.status) !== 0)
|
|
379
379
|
return y;
|
|
380
|
-
const f = y == null ? void 0 : y.points,
|
|
380
|
+
const f = y == null ? void 0 : y.points, x = [], k = p.unix((b = f[0]) == null ? void 0 : b.utc);
|
|
381
381
|
let v = -1;
|
|
382
382
|
for (const c of f) {
|
|
383
383
|
const w = p.unix(c.utc), M = {
|
|
@@ -391,10 +391,10 @@ class Et extends et {
|
|
|
391
391
|
utc: w.utc().format(),
|
|
392
392
|
method: "trajectory",
|
|
393
393
|
vendor: "shipxy"
|
|
394
|
-
},
|
|
395
|
-
|
|
394
|
+
}, h = Math.floor(w.diff(k, "minute", !0) / (o || 1));
|
|
395
|
+
h !== v && (v = h, x.push(M));
|
|
396
396
|
}
|
|
397
|
-
return
|
|
397
|
+
return x;
|
|
398
398
|
}
|
|
399
399
|
}
|
|
400
400
|
class Nt extends et {
|
|
@@ -450,7 +450,7 @@ class Nt extends et {
|
|
|
450
450
|
const r = d.data[0];
|
|
451
451
|
for (const f in r)
|
|
452
452
|
!isNaN(r[f]) && Number(r[f]) !== 1 / 0 && (r[f] = Number(r[f]));
|
|
453
|
-
const { labelCn:
|
|
453
|
+
const { labelCn: u, labelEn: m } = await this.parseStatus(r.aisNavStatus), l = p.unix(r.posTime);
|
|
454
454
|
return {
|
|
455
455
|
...o,
|
|
456
456
|
mmsi: t,
|
|
@@ -464,20 +464,20 @@ class Nt extends et {
|
|
|
464
464
|
utc: l.utc().format(),
|
|
465
465
|
status: r.aisNavStatus,
|
|
466
466
|
labelEn: m,
|
|
467
|
-
labelCn:
|
|
467
|
+
labelCn: u,
|
|
468
468
|
method: "position",
|
|
469
469
|
vendor: "myship"
|
|
470
470
|
};
|
|
471
471
|
}
|
|
472
472
|
async trajectory(t, n, i, o, a = !0, s = {}) {
|
|
473
|
-
const d = p(n), r = p(i),
|
|
473
|
+
const d = p(n), r = p(i), u = await this.getShipId(t), m = await this.getShipInfo(u), l = [];
|
|
474
474
|
for (; r.diff(d, "day", !0) > 30; )
|
|
475
|
-
await this.trajectoryIn30Day(
|
|
476
|
-
return await this.trajectoryIn30Day(
|
|
475
|
+
await this.trajectoryIn30Day(u, d.unix(), d.add(30, "day").unix(), m, t, o, l);
|
|
476
|
+
return await this.trajectoryIn30Day(u, d.unix(), r.unix(), m, t, o, l), l;
|
|
477
477
|
}
|
|
478
478
|
async trajectoryIn30Day(t, n, i, o, a, s, d, r = {}) {
|
|
479
479
|
var k;
|
|
480
|
-
const
|
|
480
|
+
const u = {
|
|
481
481
|
headers: {
|
|
482
482
|
appKey: this.token
|
|
483
483
|
},
|
|
@@ -486,14 +486,14 @@ class Nt extends et {
|
|
|
486
486
|
startTime: n,
|
|
487
487
|
endTime: i
|
|
488
488
|
}
|
|
489
|
-
}, m = "https://api3.myships.com/sp/ships/position/history", l = await J.post(m,
|
|
490
|
-
if (g == null || g.info("[%s] fetch trajectory from: %s - %j", r.requestId, m,
|
|
489
|
+
}, m = "https://api3.myships.com/sp/ships/position/history", l = await J.post(m, u).json();
|
|
490
|
+
if (g == null || g.info("[%s] fetch trajectory from: %s - %j", r.requestId, m, u), l.code !== "0")
|
|
491
491
|
return g == null || g.warn("[%s] invoke myship trajectory failed: %j", r.requestId, l), l;
|
|
492
492
|
const y = l.data;
|
|
493
493
|
for (const v in y)
|
|
494
494
|
!isNaN(y[v]) && Number(y[v]) !== 1 / 0 && (y[v] = Number(y[v]));
|
|
495
495
|
const f = p.unix((k = y[0]) == null ? void 0 : k.posTime);
|
|
496
|
-
let
|
|
496
|
+
let x = -1;
|
|
497
497
|
for (const v of y) {
|
|
498
498
|
const b = p.unix(v.posTime), c = {
|
|
499
499
|
imo: o == null ? void 0 : o.imo,
|
|
@@ -509,7 +509,7 @@ class Nt extends et {
|
|
|
509
509
|
method: "trajectory",
|
|
510
510
|
vendor: "myship"
|
|
511
511
|
}, w = Math.floor(b.diff(f, "minute", !0) / (s || 1));
|
|
512
|
-
w !==
|
|
512
|
+
w !== x && (x = w, d.push(c));
|
|
513
513
|
}
|
|
514
514
|
return d;
|
|
515
515
|
}
|
|
@@ -537,9 +537,9 @@ class yt {
|
|
|
537
537
|
if (!o)
|
|
538
538
|
return;
|
|
539
539
|
const a = {};
|
|
540
|
-
for (let
|
|
541
|
-
const m = (r = (d = o[
|
|
542
|
-
if (
|
|
540
|
+
for (let u = 0; u < (o == null ? void 0 : o.length); u++) {
|
|
541
|
+
const m = (r = (d = o[u].match(n)) == null ? void 0 : d[0]) == null ? void 0 : r.split("],");
|
|
542
|
+
if (u === 0 && !m)
|
|
543
543
|
a.scope = o[0];
|
|
544
544
|
else if (m)
|
|
545
545
|
for (let l = 0, y = m.length; l < y; l++) {
|
|
@@ -575,14 +575,14 @@ class yt {
|
|
|
575
575
|
* @param options
|
|
576
576
|
*/
|
|
577
577
|
checkWeather(e, t, n = {}) {
|
|
578
|
-
var f,
|
|
578
|
+
var f, x, k, v, b, c, w, M, h, I, S, D, Y, N, P;
|
|
579
579
|
let i = 0, o = 0, a = 0, s = 0;
|
|
580
|
-
const d = Math.round(((
|
|
580
|
+
const d = Math.round(((x = (f = t == null ? void 0 : t.SEVERE) == null ? void 0 : f.sigWave) == null ? void 0 : x.number) * 1.6 * 100) / 100, r = (v = (k = t == null ? void 0 : t.SEVERE) == null ? void 0 : k.sigWave) == null ? void 0 : v.number, u = (c = (b = t == null ? void 0 : t.HEAVY) == null ? void 0 : b.sigWave) == null ? void 0 : c.number, m = Math.round((((M = (w = t == null ? void 0 : t.SEVERE) == null ? void 0 : w.wind) == null ? void 0 : M.number) + 2) * 100) / 100, l = (I = (h = t == null ? void 0 : t.SEVERE) == null ? void 0 : h.wind) == null ? void 0 : I.number, y = (D = (S = t == null ? void 0 : t.HEAVY) == null ? void 0 : S.wind) == null ? void 0 : D.number;
|
|
581
581
|
for (let T = 0; T < (e == null ? void 0 : e.length); T++) {
|
|
582
582
|
const E = e[T], A = (N = (Y = E == null ? void 0 : E.meteo) == null ? void 0 : Y.wave) == null ? void 0 : N.sig, R = (P = E == null ? void 0 : E.meteo) == null ? void 0 : P.wind, K = T ? p(E.eta).diff(p(e[T - 1].eta), "hour", !0) : 0;
|
|
583
|
-
s = K > s ? K : s, _ == null || _.info("[%s] check sig.wave: %j", n.requestId, { ...A, dgThd4Wv: d, svThd4Wv: r, hvThd4Wv:
|
|
583
|
+
s = K > s ? K : s, _ == null || _.info("[%s] check sig.wave: %j", n.requestId, { ...A, dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: u }), (A == null ? void 0 : A.height) >= d ? E.isDangerous = !0 : (A == null ? void 0 : A.height) >= r ? E.isSevere = !0 : (A == null ? void 0 : A.height) >= u && (E.isHeavy = !0), _ == null || _.info("[%s] check wind: %j", n.requestId, { ...R, dgThd4Wd: m, svThd4Wd: l, hvThd4Wd: y }), (R == null ? void 0 : R.scale) >= m ? (E.isDangerous = !0, delete E.isSevere, delete E.isHeavy) : (R == null ? void 0 : R.scale) > l ? (E.isDangerous || (E.isSevere = !0), delete E.isHeavy) : (R == null ? void 0 : R.scale) === y && !E.isDangerous && !E.isSevere && (E.isHeavy = !0), i += E.isDangerous ? K : 0, o += E.isSevere ? K : 0, a += E.isHeavy ? K : 0;
|
|
584
584
|
}
|
|
585
|
-
return i = Math.round(i * 100) / 100, o = Math.round(o * 100) / 100, a = Math.round(a * 100) / 100, s = Math.round(s), { sample: e, dangerous: i, severe: o, heavy: a, step: s < 3 ? 3 : s, wind: { dgThd4Wd: m, svThd4Wd: l, hvThd4Wd: y }, sig: { dgThd4Wv: d, svThd4Wv: r, hvThd4Wv:
|
|
585
|
+
return i = Math.round(i * 100) / 100, o = Math.round(o * 100) / 100, a = Math.round(a * 100) / 100, s = Math.round(s), { sample: e, dangerous: i, severe: o, heavy: a, step: s < 3 ? 3 : s, wind: { dgThd4Wd: m, svThd4Wd: l, hvThd4Wd: y }, sig: { dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: u } };
|
|
586
586
|
}
|
|
587
587
|
}
|
|
588
588
|
const Tt = new yt();
|
|
@@ -735,19 +735,19 @@ class O {
|
|
|
735
735
|
static async speedLoseAt(e, t, n, i = "", o = 2, a = !0, s = !1, d = {}) {
|
|
736
736
|
let r;
|
|
737
737
|
if (t.velocity && s && (e.speed = B.roundPrecision(t.velocity * 1852 / 3600, 6)), a) {
|
|
738
|
-
let
|
|
738
|
+
let u;
|
|
739
739
|
if (d.meteo2)
|
|
740
740
|
try {
|
|
741
|
-
const f = await Mt.spotForecast(t.lat, t.lng, n.utc().format(), !1, !1, !0, d), [
|
|
742
|
-
|
|
741
|
+
const f = await Mt.spotForecast(t.lat, t.lng, n.utc().format(), !1, !1, !0, d), [x] = rt.pickHourly(f, n);
|
|
742
|
+
u = rt.toLegacy(x);
|
|
743
743
|
} catch (f) {
|
|
744
744
|
F.warn("[%s] meteo2 spot(%j) forecast failed: %s", d.requestId, { ...t, eta: n.utc().format() }, f);
|
|
745
745
|
}
|
|
746
746
|
else
|
|
747
|
-
|
|
748
|
-
const m = O.weatherFactor(e,
|
|
747
|
+
u = await ft.queryPointFactor(t.lng, t.lat, n.valueOf(), "wind,wave,current,watertemp", i, d);
|
|
748
|
+
const m = O.weatherFactor(e, u), l = O.currentFactor(e.bearing, u == null ? void 0 : u.current, o), y = Math.round((e.speed * 1.943844 + m + l) * 100) / 100;
|
|
749
749
|
r = {
|
|
750
|
-
meteo: { ...
|
|
750
|
+
meteo: { ...u },
|
|
751
751
|
wxFactor: m,
|
|
752
752
|
cFactor: l,
|
|
753
753
|
speed: t.velocity && s ? t.velocity : y < 0 ? 1 : y,
|
|
@@ -777,13 +777,13 @@ class O {
|
|
|
777
777
|
* @param useRouteParam true 启用航线上设置的参数 { suspend: 停留时长(小时), velocity: 速度(kts)}
|
|
778
778
|
* @private
|
|
779
779
|
*/
|
|
780
|
-
static async speedLoseInHoursStep(e, t, n, i, o, a, s = "", d = !0, r = !1,
|
|
780
|
+
static async speedLoseInHoursStep(e, t, n, i, o, a, s = "", d = !0, r = !1, u = {}) {
|
|
781
781
|
t.utc();
|
|
782
782
|
const m = t.clone().add(14, "days"), l = [], y = [];
|
|
783
|
-
let f = 0,
|
|
783
|
+
let f = 0, x = 0, k, v;
|
|
784
784
|
for (let b = 0; b < a.length - 1; b++) {
|
|
785
785
|
let c = a[b];
|
|
786
|
-
c.distanceFromStart = Math.round((o +
|
|
786
|
+
c.distanceFromStart = Math.round((o + x) * 1e4) / 1e4;
|
|
787
787
|
const w = a[b + 1];
|
|
788
788
|
if (e.bearing = L.calculateBearing(c, w, !w.gcToPrevious), c.bearing = e.bearing, c.suspend && r) {
|
|
789
789
|
c.eta = c.eta || t.utc().format(), c.elapsed = c.elapsed ?? 0;
|
|
@@ -794,32 +794,32 @@ class O {
|
|
|
794
794
|
const S = i - f;
|
|
795
795
|
c.elapsed += S, t.add(S, "hour"), i = 0;
|
|
796
796
|
}
|
|
797
|
-
if (F == null || F.info(`[%s] suspend ${c.elapsed} hours at %j, and remain ${i} hours need to go...`,
|
|
798
|
-
return c.distanceFromPrevious =
|
|
797
|
+
if (F == null || F.info(`[%s] suspend ${c.elapsed} hours at %j, and remain ${i} hours need to go...`, u.requestId, c), i === 0)
|
|
798
|
+
return c.distanceFromPrevious = x, { etd: t, from: v || c, to: c, next: a.filter((S) => S), wps: l, days: y };
|
|
799
799
|
} else
|
|
800
800
|
c.suspend = 0;
|
|
801
|
-
d = t.isAfter(m) ? !1 : d, c = await O.speedLoseAt(e, c, t, s, 0, d, r,
|
|
801
|
+
d = t.isAfter(m) ? !1 : d, c = await O.speedLoseAt(e, c, t, s, 0, d, r, u), v = v || c, c.important && l.push(c), t.isSameOrAfter(n) && (y.push(c), n.add(24, "hour"));
|
|
802
802
|
const M = L.calculateDistance(c, w, !w.gcToPrevious);
|
|
803
|
-
let
|
|
804
|
-
if (f +
|
|
805
|
-
if (f +=
|
|
806
|
-
`[%s] go to %j from %j with ${M}nm, and cost ${
|
|
807
|
-
|
|
803
|
+
let h = Math.round(M / v.speed * 1e5) / 1e5;
|
|
804
|
+
if (f + h < i) {
|
|
805
|
+
if (f += h, t.add(h, "hour"), delete a[b], F == null || F.debug(
|
|
806
|
+
`[%s] go to %j from %j with ${M}nm, and cost ${h} hours`,
|
|
807
|
+
u.requestId,
|
|
808
808
|
{ lat: w.lat, lng: w.lng },
|
|
809
809
|
{ lat: v.lat, lng: v.lng, etd: v.etd }
|
|
810
|
-
),
|
|
811
|
-
k = w, k.eta = t.utc().format(), k.distanceFromPrevious = M, k.distanceFromStart = Math.round((o +
|
|
810
|
+
), x += M, a.filter((I) => I).length <= 1) {
|
|
811
|
+
k = w, k.eta = t.utc().format(), k.distanceFromPrevious = M, k.distanceFromStart = Math.round((o + x) * 1e4) / 1e4, l.push(k), delete a[b + 1];
|
|
812
812
|
break;
|
|
813
813
|
}
|
|
814
814
|
} else {
|
|
815
|
-
|
|
816
|
-
const I = B.roundPrecision(v.speed *
|
|
815
|
+
h = i - f, t.add(h, "hour");
|
|
816
|
+
const I = B.roundPrecision(v.speed * h, 5);
|
|
817
817
|
k = L.calculateCoordinate(c, e.bearing, I, "nauticalmiles", !w.gcToPrevious), k.eta = t.utc().format(), a[b] = k, F == null || F.debug(
|
|
818
|
-
`[%s] go to %j from %j with ${I}nm, and cost ${
|
|
819
|
-
|
|
818
|
+
`[%s] go to %j from %j with ${I}nm, and cost ${h} hours`,
|
|
819
|
+
u.requestId,
|
|
820
820
|
{ lat: k.lat, lng: k.lng },
|
|
821
821
|
{ lat: c.lat, lng: c.lng, etd: c.etd }
|
|
822
|
-
),
|
|
822
|
+
), x += I, k.distanceFromPrevious = Math.round(x * 1e4) / 1e4, k.distanceFromStart = Math.round((o + x) * 1e4) / 1e4;
|
|
823
823
|
break;
|
|
824
824
|
}
|
|
825
825
|
}
|
|
@@ -844,16 +844,16 @@ class O {
|
|
|
844
844
|
* @param wwc 气象要素
|
|
845
845
|
*/
|
|
846
846
|
static weatherFactor(e, t) {
|
|
847
|
-
var m, l, y, f,
|
|
847
|
+
var m, l, y, f, x, k, v;
|
|
848
848
|
F == null || F.debug("calculate weather factor via: %j", { ...e, ...t });
|
|
849
849
|
const n = O.blockCoefficient(e.displacement, e.lbp, e.breadthMoulded, e.draught), i = O.froudeNumber(e.speed, e.lbp), o = O.amendFactor(n, i, e.loadCondition);
|
|
850
850
|
let a = Math.abs(e.bearing % 360 - (((m = t == null ? void 0 : t.wind) == null ? void 0 : m.degree) % 360 || 0));
|
|
851
851
|
a = a > 180 ? 360 - a : a;
|
|
852
852
|
const s = O.directionFactor(a, (l = t == null ? void 0 : t.wind) == null ? void 0 : l.scale), d = O.vesselTagFactor(e.displacement, e.loadCondition, e.tag, (y = t == null ? void 0 : t.wind) == null ? void 0 : y.scale);
|
|
853
853
|
let r = s * o * d / 100 * e.speed;
|
|
854
|
-
r = Math.round(r * 1.943844 * 1e4) / 1e4 * -1, e.tag === "tugs" && Math.abs(r) > 1 && (r = r / (Math.abs(Math.round(r)) + 1)), F == null || F.debug("wind wx factor = %d", r), a = Math.abs(e.bearing % 360 - (((
|
|
855
|
-
const
|
|
856
|
-
return F == null || F.debug("wave wx factor = %d",
|
|
854
|
+
r = Math.round(r * 1.943844 * 1e4) / 1e4 * -1, e.tag === "tugs" && Math.abs(r) > 1 && (r = r / (Math.abs(Math.round(r)) + 1)), F == null || F.debug("wind wx factor = %d", r), a = Math.abs(e.bearing % 360 - (((x = (f = t == null ? void 0 : t.wave) == null ? void 0 : f.sig) == null ? void 0 : x.degree) % 360 || 0));
|
|
855
|
+
const u = O.waveHeightFactor(((v = (k = t == null ? void 0 : t.wave) == null ? void 0 : k.sig) == null ? void 0 : v.height) ?? 1, a);
|
|
856
|
+
return F == null || F.debug("wave wx factor = %d", u), r = r * 0.4 + u, F == null || F.debug("weather factor = %d", r), r = Math.abs(r) > 4 ? 4 * (Math.abs(r) / r) + Math.abs(r) / r * (Math.abs(r) - 4) * 0.1 : r, Math.round((r || 0) * 100) / 100;
|
|
857
857
|
}
|
|
858
858
|
/**
|
|
859
859
|
* 全程失速分析(走完航程)
|
|
@@ -867,14 +867,14 @@ class O {
|
|
|
867
867
|
* @param useMeteo true 启用气象分析
|
|
868
868
|
* @param useRouteParam
|
|
869
869
|
*/
|
|
870
|
-
static async analyseInstant(e, t, n, i, o, a = "", s = 0, d = !0, r = !1,
|
|
870
|
+
static async analyseInstant(e, t, n, i, o, a = "", s = 0, d = !0, r = !1, u = {}) {
|
|
871
871
|
var z, U, Q, X, Z, $;
|
|
872
872
|
const m = p().valueOf();
|
|
873
873
|
e.lng = B.convertToStdLng(e.lng);
|
|
874
874
|
const { route: l, waypoints: y } = o.points, f = L.calculateSubRoute(e, l);
|
|
875
875
|
if (((z = f[0]) == null ? void 0 : z.length) <= 1)
|
|
876
876
|
return;
|
|
877
|
-
const { v0:
|
|
877
|
+
const { v0: x, label: k } = e.sog ? {
|
|
878
878
|
v0: e.sog,
|
|
879
879
|
label: "Other"
|
|
880
880
|
/* Instruct */
|
|
@@ -882,13 +882,13 @@ class O {
|
|
|
882
882
|
v0: i.speed,
|
|
883
883
|
label: "CP"
|
|
884
884
|
/* Cp */
|
|
885
|
-
}, v = O.assembleProperties(n, i.loadCondition,
|
|
885
|
+
}, v = O.assembleProperties(n, i.loadCondition, x, 0), b = y.length ? L.calculateSubWaypoints(e, y) : [];
|
|
886
886
|
b.forEach((q) => q.important = !0);
|
|
887
887
|
const c = {
|
|
888
888
|
from: { ...e },
|
|
889
889
|
route: f,
|
|
890
890
|
waypoints: b,
|
|
891
|
-
v0:
|
|
891
|
+
v0: x,
|
|
892
892
|
label: k
|
|
893
893
|
}, w = {
|
|
894
894
|
hours: [],
|
|
@@ -896,23 +896,23 @@ class O {
|
|
|
896
896
|
wps: []
|
|
897
897
|
};
|
|
898
898
|
s || (L.calculateRouteDistance(f) / i.speed <= 72 ? s = 3 : s = 6);
|
|
899
|
-
let M = L.simplifyRouteToCoordinates(f, b, 0),
|
|
899
|
+
let M = L.simplifyRouteToCoordinates(f, b, 0), h = 0, I = 0, S = 0, D = 0;
|
|
900
900
|
t = p(t).utc();
|
|
901
901
|
const Y = t.clone();
|
|
902
902
|
for (; M.length > 0; ) {
|
|
903
|
-
const q = s - t.hour() % s, V = Math.ceil(t.clone().add(q, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4,
|
|
903
|
+
const q = s - t.hour() % s, V = Math.ceil(t.clone().add(q, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4, C = await O.speedLoseInHoursStep(
|
|
904
904
|
v,
|
|
905
905
|
t,
|
|
906
906
|
Y,
|
|
907
907
|
V,
|
|
908
|
-
|
|
908
|
+
h,
|
|
909
909
|
M,
|
|
910
910
|
a,
|
|
911
911
|
d,
|
|
912
912
|
r,
|
|
913
|
-
|
|
913
|
+
u
|
|
914
914
|
);
|
|
915
|
-
(U =
|
|
915
|
+
(U = C.from) != null && U.speed && (w.hours.push(C.from), w.wps.push(...C.wps), w.days.push(...C.days)), M = C == null ? void 0 : C.next, M.length || w.hours.push(C == null ? void 0 : C.to), h += Math.round((((Q = C == null ? void 0 : C.to) == null ? void 0 : Q.distanceFromPrevious) ?? 0) * 1e4) / 1e4;
|
|
916
916
|
}
|
|
917
917
|
const N = w.hours;
|
|
918
918
|
for (let q = 0; q < N.length - 1; q++) {
|
|
@@ -921,13 +921,13 @@ class O {
|
|
|
921
921
|
}
|
|
922
922
|
(X = w.wps) == null || X.forEach((q, V) => {
|
|
923
923
|
if (q.positionTime = p.utc(q.etd || q.eta).unix(), V) {
|
|
924
|
-
const
|
|
924
|
+
const C = w.wps[V - 1], W = q.distanceFromStart - C.distanceFromStart, H = p(q.eta).diff(p(C.etd), "h", !0);
|
|
925
925
|
q.avgSpd = Math.round(W / H * 100) / 100;
|
|
926
926
|
}
|
|
927
|
-
}), w.wps = (Z = w.wps) == null ? void 0 : Z.reduce((q, V) => (q.some((
|
|
927
|
+
}), w.wps = (Z = w.wps) == null ? void 0 : Z.reduce((q, V) => (q.some((C) => C.positionTime === V.positionTime) || q.push(V), q), []), c.sample = w;
|
|
928
928
|
const P = w.hours.at(0), T = w.hours.at(-1);
|
|
929
929
|
c.distance = Math.round(T.distanceFromStart * 1e4) / 1e4, c.etd = p(P.eta).utc().format(), c.eta = p(T.eta).utc().format(), c.wxFactor = Math.round(I / D * 1e4) / 1e4, c.cFactor = Math.round(S / D * 1e4) / 1e4, c.avgSpeed = Math.round(T.distanceFromStart / D * 1e4) / 1e4, c.totalHrs = Math.round(D * 1e4) / 1e4;
|
|
930
|
-
const { distanceInECA: E, hoursInECA: A, totalDgoConsInECA: R, eca: K } = await this.calculateECA(c, i,
|
|
930
|
+
const { distanceInECA: E, hoursInECA: A, totalDgoConsInECA: R, eca: K } = await this.calculateECA(c, i, u), st = B.roundPrecision(i.fo / 24 * (D - A), 3), at = B.roundPrecision(i.dgo / 24 * D, 3);
|
|
931
931
|
c.extend = {
|
|
932
932
|
eca: K,
|
|
933
933
|
distanceInECA: E,
|
|
@@ -935,7 +935,7 @@ class O {
|
|
|
935
935
|
totalDgoConsInECA: R
|
|
936
936
|
}, c.totalFoCons = st, c.totalDgoCons = at;
|
|
937
937
|
const tt = p().valueOf() - m, ot = (($ = w == null ? void 0 : w.hours) == null ? void 0 : $.length) || 1;
|
|
938
|
-
return F == null || F.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",
|
|
938
|
+
return F == null || F.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", u == null ? void 0 : u.requestId, tt, ot, Math.round(tt / ot * 1e3) / 1e3), c;
|
|
939
939
|
}
|
|
940
940
|
/**
|
|
941
941
|
* 分段失速分析(最多走hours 小时)
|
|
@@ -950,11 +950,11 @@ class O {
|
|
|
950
950
|
* @param useMeteo true 启用气象分析
|
|
951
951
|
* @param useRouteParam
|
|
952
952
|
*/
|
|
953
|
-
static async analyseInstantWithThreshed(e, t, n, i, o, a, s, d = "", r = 3,
|
|
953
|
+
static async analyseInstantWithThreshed(e, t, n, i, o, a, s, d = "", r = 3, u = !0, m = !1, l = {}) {
|
|
954
954
|
var Q, X, Z, $, q, V;
|
|
955
955
|
const y = p().valueOf();
|
|
956
956
|
e.lng = B.convertToStdLng(e.lng);
|
|
957
|
-
const { v0: f, label:
|
|
957
|
+
const { v0: f, label: x } = e.sog ? {
|
|
958
958
|
v0: e.sog,
|
|
959
959
|
label: "Other"
|
|
960
960
|
/* Instruct */
|
|
@@ -966,8 +966,8 @@ class O {
|
|
|
966
966
|
if (((Q = v[0]) == null ? void 0 : Q.length) <= 1)
|
|
967
967
|
return;
|
|
968
968
|
const b = s.length ? L.calculateSubWaypoints(e, s) : [];
|
|
969
|
-
b.forEach((
|
|
970
|
-
let c = L.simplifyRouteToCoordinates(v, b, 0), w = 0, M = 0,
|
|
969
|
+
b.forEach((C) => C.important = !0);
|
|
970
|
+
let c = L.simplifyRouteToCoordinates(v, b, 0), w = 0, M = 0, h = 0, I = 0;
|
|
971
971
|
const S = {
|
|
972
972
|
hours: [],
|
|
973
973
|
wps: [],
|
|
@@ -976,23 +976,23 @@ class O {
|
|
|
976
976
|
t = p(t).utc();
|
|
977
977
|
const D = t.clone();
|
|
978
978
|
for (; c.length > 0; ) {
|
|
979
|
-
const
|
|
980
|
-
let W = Math.ceil(t.clone().add(
|
|
979
|
+
const C = r - t.hour() % r;
|
|
980
|
+
let W = Math.ceil(t.clone().add(C, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4;
|
|
981
981
|
W = t.clone().add(W, "h").isSameOrAfter(n) ? n.diff(t, "h", !0) * 1e4 / 1e4 : W;
|
|
982
|
-
const H = await O.speedLoseInHoursStep(k, t, D, W, w, c, d,
|
|
982
|
+
const H = await O.speedLoseInHoursStep(k, t, D, W, w, c, d, u, m, l);
|
|
983
983
|
if ((X = H.from) != null && X.speed && (S.hours.push(H.from), H != null && H.wps && S.wps.push(...H.wps), S.days.push(...H.days)), c = H == null ? void 0 : H.next, c.length || S.hours.push(H == null ? void 0 : H.to), w += Math.round((((Z = H == null ? void 0 : H.to) == null ? void 0 : Z.distanceFromPrevious) ?? 0) * 1e4) / 1e4, !W)
|
|
984
984
|
break;
|
|
985
985
|
}
|
|
986
|
-
S.wps = ($ = S.wps) == null ? void 0 : $.reduce((
|
|
986
|
+
S.wps = ($ = S.wps) == null ? void 0 : $.reduce((C, W) => (C.some((H) => H.etd === W.etd) || C.push(W), C), []), (q = S.wps) == null || q.forEach((C, W) => {
|
|
987
987
|
if (W) {
|
|
988
|
-
const H = S.wps[W - 1], ct =
|
|
989
|
-
|
|
988
|
+
const H = S.wps[W - 1], ct = C.distanceFromStart - H.distanceFromStart, dt = p(C.eta).diff(p(H.etd), "h", !0);
|
|
989
|
+
C.avgSpd = Math.round(ct / dt * 100) / 100;
|
|
990
990
|
}
|
|
991
991
|
});
|
|
992
992
|
const Y = S.hours;
|
|
993
|
-
for (let
|
|
994
|
-
const W = p(Y[
|
|
995
|
-
M += Y[
|
|
993
|
+
for (let C = 0; C < Y.length - 1; C++) {
|
|
994
|
+
const W = p(Y[C + 1].eta).diff(Y[C].etd, "hour", !0);
|
|
995
|
+
M += Y[C].wxFactor * W, h += Y[C].cFactor * W, I += W;
|
|
996
996
|
}
|
|
997
997
|
const N = S.hours.at(0), P = S.hours.at(-1), T = await L.calculateRangeRoute(N, P, v), E = await L.calculateRangeWaypoints(N, P, v, b), A = {
|
|
998
998
|
sample: S,
|
|
@@ -1001,7 +1001,7 @@ class O {
|
|
|
1001
1001
|
etd: p(N.eta).utc().format(),
|
|
1002
1002
|
eta: p(P == null ? void 0 : P.eta).utc().format(),
|
|
1003
1003
|
wxFactor: Math.round(M / I * 1e4) / 1e4,
|
|
1004
|
-
cFactor: Math.round(
|
|
1004
|
+
cFactor: Math.round(h / I * 1e4) / 1e4,
|
|
1005
1005
|
avgSpeed: Math.round(((P == null ? void 0 : P.distanceFromStart) || 0) / I * 1e4) / 1e4,
|
|
1006
1006
|
totalHrs: Math.round(I * 1e4) / 1e4,
|
|
1007
1007
|
from: N,
|
|
@@ -1009,7 +1009,7 @@ class O {
|
|
|
1009
1009
|
route: T,
|
|
1010
1010
|
waypoints: E,
|
|
1011
1011
|
v0: f,
|
|
1012
|
-
label:
|
|
1012
|
+
label: x
|
|
1013
1013
|
}, { distanceInECA: R, hoursInECA: K, totalDgoConsInECA: st, eca: at } = await this.calculateECA(A, o, l), it = B.roundPrecision(o.fo / 24 * (I - K), 3), tt = B.roundPrecision(o.dgo / 24 * I, 3);
|
|
1014
1014
|
A.extend = {
|
|
1015
1015
|
eca: at,
|
|
@@ -1045,13 +1045,13 @@ class O {
|
|
|
1045
1045
|
const w = Math.ceil(d / c.speed / 24);
|
|
1046
1046
|
r = r < w ? w : r;
|
|
1047
1047
|
}), r = r * 1.3;
|
|
1048
|
-
const
|
|
1048
|
+
const u = p.utc(e.etd).add(r ?? 14, "day");
|
|
1049
1049
|
let m = 1;
|
|
1050
1050
|
for (const c of n) {
|
|
1051
|
-
const w = JSON.parse(JSON.stringify(i.route)), M = JSON.parse(JSON.stringify(i.waypoints)),
|
|
1051
|
+
const w = JSON.parse(JSON.stringify(i.route)), M = JSON.parse(JSON.stringify(i.waypoints)), h = await O.analyseInstantWithThreshed(
|
|
1052
1052
|
{ lat: e.lat, lng: e.lng },
|
|
1053
1053
|
e.etd,
|
|
1054
|
-
|
|
1054
|
+
u,
|
|
1055
1055
|
t,
|
|
1056
1056
|
c,
|
|
1057
1057
|
w,
|
|
@@ -1062,22 +1062,22 @@ class O {
|
|
|
1062
1062
|
e.useRouteParam,
|
|
1063
1063
|
o
|
|
1064
1064
|
);
|
|
1065
|
-
|
|
1066
|
-
cost:
|
|
1067
|
-
distance:
|
|
1068
|
-
hours:
|
|
1065
|
+
h && (await O.calculateCost(h, c, e, o), s.push(h), F == null || F.info("[%s][L%d-%d] analyse from %s to %s cost: %j", o.requestId, 1, m, e.etd, u.format(), {
|
|
1066
|
+
cost: h.cost.total,
|
|
1067
|
+
distance: h.distance,
|
|
1068
|
+
hours: h.totalHrs,
|
|
1069
1069
|
cp: `${c.speed}/${c.fo}/${c.dgo}`
|
|
1070
1070
|
})), m++;
|
|
1071
1071
|
}
|
|
1072
1072
|
s.sort((c, w) => c.cost.total - w.cost.total);
|
|
1073
1073
|
const l = s.at(0), y = s.at(1), f = [];
|
|
1074
1074
|
if (f.push({ combined: !1, speeds: [l], cost: (v = l.cost) == null ? void 0 : v.total }), y) {
|
|
1075
|
-
const c = l.cost.cp, w = y.cost.cp, M = p(l.eta),
|
|
1075
|
+
const c = l.cost.cp, w = y.cost.cp, M = p(l.eta), h = p(l.etd), I = M.diff(h, "days", !0);
|
|
1076
1076
|
let S = Math.ceil(I / 2);
|
|
1077
1077
|
S = S > 7 ? 7 : S < e.alterStep ? e.alterStep : S;
|
|
1078
1078
|
let D = 2, Y = { combined: !1, speeds: [y], cost: (b = y.cost) == null ? void 0 : b.total }, N;
|
|
1079
1079
|
for (; S >= e.alterStep; ) {
|
|
1080
|
-
const P = await O.combinedAnalyse(e, t,
|
|
1080
|
+
const P = await O.combinedAnalyse(e, t, u, [c, w], i, S, { ...o, level: D });
|
|
1081
1081
|
if (Y.cost > P.cost ? N ? (N == null ? void 0 : N.cost) > P.cost && (N = P) : (N = Y, Y = P) : (!N || (N == null ? void 0 : N.cost) > P.cost) && (N = P), S <= e.alterStep)
|
|
1082
1082
|
break;
|
|
1083
1083
|
S = Math.ceil(S / 2), D += 1;
|
|
@@ -1101,8 +1101,8 @@ class O {
|
|
|
1101
1101
|
s.counter = 1, F == null || F.info("[%s][L%d] analyse with alternate cp in every %d days", s.requestId, s.level, a);
|
|
1102
1102
|
const d = await O.alternateAnalyse(e, t, n, i, 0, o, a, s), r = d.reduce((l, y) => l + y.cost.total, 0);
|
|
1103
1103
|
F == null || F.info("[%s][L%d] cost with cpa/cpb turn: %d", s.requestId, s.level, r);
|
|
1104
|
-
const
|
|
1105
|
-
return F == null || F.info("[%s][L%d] cost with cpb/cpa turn: %d", s.requestId, s.level, m), r < m ? { combined: !0, cost: Math.round(r * 1e3) / 1e3, speeds: d, step: a } : { combined: !0, cost: Math.round(m * 1e3) / 1e3, speeds:
|
|
1104
|
+
const u = await O.alternateAnalyse(e, t, n, i, 1, o, a, s), m = u.reduce((l, y) => l + y.cost.total, 0);
|
|
1105
|
+
return F == null || F.info("[%s][L%d] cost with cpb/cpa turn: %d", s.requestId, s.level, m), r < m ? { combined: !0, cost: Math.round(r * 1e3) / 1e3, speeds: d, step: a } : { combined: !0, cost: Math.round(m * 1e3) / 1e3, speeds: u, step: a };
|
|
1106
1106
|
}
|
|
1107
1107
|
/**
|
|
1108
1108
|
* 基于cp索引,交替计算指定步长下的成本
|
|
@@ -1118,15 +1118,15 @@ class O {
|
|
|
1118
1118
|
static async alternateAnalyse(e, t, n, i, o, a, s, d = {}) {
|
|
1119
1119
|
var l, y;
|
|
1120
1120
|
let r = p.utc(e.etd);
|
|
1121
|
-
const
|
|
1121
|
+
const u = { lat: e.lat, lng: e.lng }, m = [];
|
|
1122
1122
|
for (; r.isBefore(n); ) {
|
|
1123
|
-
const f = r.clone().utc().add(s, "day"),
|
|
1124
|
-
|
|
1123
|
+
const f = r.clone().utc().add(s, "day"), x = JSON.parse(JSON.stringify(a.route)), k = JSON.parse(JSON.stringify(a.waypoints)), v = i[o], b = await O.analyseInstantWithThreshed(
|
|
1124
|
+
u,
|
|
1125
1125
|
r.utc().format(),
|
|
1126
1126
|
f,
|
|
1127
1127
|
t,
|
|
1128
1128
|
v,
|
|
1129
|
-
|
|
1129
|
+
x,
|
|
1130
1130
|
k,
|
|
1131
1131
|
e.meteoVendor,
|
|
1132
1132
|
e.speedStep,
|
|
@@ -1145,7 +1145,7 @@ class O {
|
|
|
1145
1145
|
)), d.counter = d.counter + 1;
|
|
1146
1146
|
const c = (y = (l = b == null ? void 0 : b.sample) == null ? void 0 : l.hours) == null ? void 0 : y.at(-1);
|
|
1147
1147
|
if (c)
|
|
1148
|
-
|
|
1148
|
+
u.lat = c.lat, u.lng = c.lng, r = p(c.eta), m.push(b), o = o ? 0 : 1;
|
|
1149
1149
|
else
|
|
1150
1150
|
break;
|
|
1151
1151
|
}
|
|
@@ -1178,13 +1178,13 @@ class O {
|
|
|
1178
1178
|
var d, r;
|
|
1179
1179
|
const i = await L.intersectInECA(e.route);
|
|
1180
1180
|
let o = 0, a = 0, s = 0;
|
|
1181
|
-
e.sample.wps.forEach((
|
|
1182
|
-
|
|
1181
|
+
e.sample.wps.forEach((u) => {
|
|
1182
|
+
u.positionTime = p.utc(u.etd || u.eta).unix();
|
|
1183
1183
|
});
|
|
1184
|
-
for (const
|
|
1185
|
-
o +=
|
|
1186
|
-
const m = await L.deadReckoningTime((d =
|
|
1187
|
-
|
|
1184
|
+
for (const u of i) {
|
|
1185
|
+
o += u.distance;
|
|
1186
|
+
const m = await L.deadReckoningTime((d = u.waypoints) == null ? void 0 : d.at(0), e.sample.wps), l = await L.deadReckoningTime((r = u.waypoints) == null ? void 0 : r.at(-1), e.sample.wps);
|
|
1187
|
+
u.in = m, u.out = l, u.totalHrs = B.roundPrecision((l.positionTime - m.positionTime) / 3600, 2), u.totalDgoCons = B.roundPrecision(t.fo / 24 * u.totalHrs, 3), a += u.totalHrs, s += u.totalDgoCons;
|
|
1188
1188
|
}
|
|
1189
1189
|
return o = B.roundPrecision(o, 3), a = B.roundPrecision(a, 3), s = B.roundPrecision(s, 3), {
|
|
1190
1190
|
distanceInECA: o,
|
|
@@ -1204,21 +1204,21 @@ class O {
|
|
|
1204
1204
|
hours: [],
|
|
1205
1205
|
wps: [],
|
|
1206
1206
|
days: []
|
|
1207
|
-
}, i = e.reduce((M,
|
|
1207
|
+
}, i = e.reduce((M, h) => M + h.distance, 0), o = e.reduce((M, h) => {
|
|
1208
1208
|
var I;
|
|
1209
|
-
return M + (((I =
|
|
1210
|
-
}, 0), a = e.reduce((M,
|
|
1209
|
+
return M + (((I = h.extend) == null ? void 0 : I.distanceInECA) || 0);
|
|
1210
|
+
}, 0), a = e.reduce((M, h) => M + h.totalHrs, 0), s = e.reduce((M, h) => {
|
|
1211
1211
|
var I;
|
|
1212
|
-
return M + (((I =
|
|
1213
|
-
}, 0), d = e.reduce((M,
|
|
1212
|
+
return M + (((I = h.extend) == null ? void 0 : I.hoursInECA) || 0);
|
|
1213
|
+
}, 0), d = e.reduce((M, h) => {
|
|
1214
1214
|
var I;
|
|
1215
|
-
return M + (((I =
|
|
1216
|
-
}, 0), r = e.reduce((M,
|
|
1215
|
+
return M + (((I = h.extend) == null ? void 0 : I.totalDgoConsInECA) || 0);
|
|
1216
|
+
}, 0), r = e.reduce((M, h) => M + h.wxFactor * h.totalHrs / a, 0), u = e.reduce((M, h) => M + h.cFactor * h.totalHrs / a, 0), m = e.reduce((M, h) => M + h.totalFoCons, 0), l = e.reduce((M, h) => M + h.totalDgoCons, 0), y = e.reduce((M, h) => M + h.cost.total, 0), f = e.reduce((M, h) => M + h.cost.hire, 0), x = e.reduce((M, h) => M + h.cost.bunker, 0), k = [], v = [];
|
|
1217
1217
|
let b;
|
|
1218
1218
|
for (const M of e) {
|
|
1219
1219
|
v.push(...((c = M.extend) == null ? void 0 : c.eca) || []);
|
|
1220
|
-
const
|
|
1221
|
-
b && (D.distanceFromPrevious = b.distanceFromPrevious, D.distanceFromStart = b.distanceFromStart,
|
|
1220
|
+
const h = M.sample.hours, I = M.sample.wps, S = M.sample.days, D = h.at(0);
|
|
1221
|
+
b && (D.distanceFromPrevious = b.distanceFromPrevious, D.distanceFromStart = b.distanceFromStart, h.forEach((T, E) => {
|
|
1222
1222
|
E && (T.distanceFromStart = T.distanceFromStart + b.distanceFromStart);
|
|
1223
1223
|
}), I.at(0).distanceFromPrevious = b.distanceFromPrevious, I.at(0).distanceFromStart = b.distanceFromStart, I.forEach((T, E) => {
|
|
1224
1224
|
E && (T.distanceFromStart = T.distanceFromStart + b.distanceFromStart);
|
|
@@ -1226,7 +1226,7 @@ class O {
|
|
|
1226
1226
|
E && (T.distanceFromStart = T.distanceFromStart + b.distanceFromStart);
|
|
1227
1227
|
})), D.cp = M.cost.cp;
|
|
1228
1228
|
const Y = [M.etd, M.eta], N = k.findIndex((T) => T.id === D.cp.id);
|
|
1229
|
-
N === -1 ? (D.cp.segment = [Y], k.push(D.cp)) : k[N].segment.push(Y),
|
|
1229
|
+
N === -1 ? (D.cp.segment = [Y], k.push(D.cp)) : k[N].segment.push(Y), h.forEach((T) => {
|
|
1230
1230
|
var A;
|
|
1231
1231
|
((A = n.hours) == null ? void 0 : A.findIndex((R) => R.eta === T.eta)) === -1 && n.hours.push(T);
|
|
1232
1232
|
}), I.forEach((T) => {
|
|
@@ -1237,17 +1237,15 @@ class O {
|
|
|
1237
1237
|
((A = n == null ? void 0 : n.days) == null ? void 0 : A.findIndex((R) => R.eta === T.eta)) === -1 && n.days.push(T);
|
|
1238
1238
|
});
|
|
1239
1239
|
const P = (w = n.wps) == null ? void 0 : w.findIndex((T) => T.eta === D.eta);
|
|
1240
|
-
P === -1 ? n.wps.push(D) : n.wps[P] = D, b =
|
|
1240
|
+
P === -1 ? n.wps.push(D) : n.wps[P] = D, b = h.at(-1);
|
|
1241
1241
|
}
|
|
1242
|
-
return n.wps.sort((M,
|
|
1243
|
-
p(M.etd).unix() - p(
|
|
1244
|
-
}), n.wps.forEach((M,
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
M.avgSpd = Y;
|
|
1250
|
-
}
|
|
1242
|
+
return n.wps.sort((M, h) => {
|
|
1243
|
+
p(M.etd).unix() - p(h.etd).unix();
|
|
1244
|
+
}), n.wps.forEach((M, h) => {
|
|
1245
|
+
const I = n.wps.at(h + 1);
|
|
1246
|
+
if (I) {
|
|
1247
|
+
const S = I.distanceFromStart - (M.distanceFromStart || 0), D = p(I.etd || I.eta).diff(p(M.etd || M.eta), "hour", !0), Y = Math.round(S / D * 100) / 100;
|
|
1248
|
+
M.avgSpd = Y;
|
|
1251
1249
|
}
|
|
1252
1250
|
}), {
|
|
1253
1251
|
sample: n,
|
|
@@ -1261,13 +1259,13 @@ class O {
|
|
|
1261
1259
|
totalHrs: Math.round(a * 1e3) / 1e3,
|
|
1262
1260
|
avgSpeed: Math.round(i / a * 1e3) / 1e3,
|
|
1263
1261
|
wxFactor: Math.round(r / a * 1e3) / 1e3,
|
|
1264
|
-
cFactor: Math.round(
|
|
1262
|
+
cFactor: Math.round(u / a * 1e3) / 1e3,
|
|
1265
1263
|
totalFoCons: Math.round(m * 1e3) / 1e3,
|
|
1266
1264
|
totalDgoCons: Math.round(l * 1e3) / 1e3,
|
|
1267
1265
|
cost: {
|
|
1268
1266
|
total: Math.round(y * 1e3) / 1e3,
|
|
1269
1267
|
hire: Math.round(f * 1e3) / 1e3,
|
|
1270
|
-
bunker: Math.round(
|
|
1268
|
+
bunker: Math.round(x * 1e3) / 1e3
|
|
1271
1269
|
},
|
|
1272
1270
|
extend: {
|
|
1273
1271
|
cps: k,
|
|
@@ -1287,7 +1285,7 @@ export {
|
|
|
1287
1285
|
jt as HifleetImpl,
|
|
1288
1286
|
pt as LoadCondition,
|
|
1289
1287
|
Nt as MyShipImpl,
|
|
1290
|
-
|
|
1288
|
+
Ct as MyVesselImpl,
|
|
1291
1289
|
Et as ShipxyImpl,
|
|
1292
1290
|
O as SpeedHelper,
|
|
1293
1291
|
wt as SpeedLabel,
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(D,Y){typeof exports=="object"&&typeof module<"u"?Y(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"],Y):(D=typeof globalThis<"u"?globalThis:D||self,Y(D["idm-plugin-rabbitmq"]={},D.got,D["@log4js-node/log4js-api"],D.moment,D["@idm-plugin/geo2"],D["@idm-plugin/meteo2"],D["@idm-plugin/meteo"]))})(this,function(D,Y,G,w,q,it,rt){"use strict";var It=Object.defineProperty;var St=(D,Y,G)=>Y in D?It(D,Y,{enumerable:!0,configurable:!0,writable:!0,value:G}):D[Y]=G;var z=(D,Y,G)=>(St(D,typeof Y!="symbol"?Y+"":Y,G),G);let M;try{M=G.getLogger("vessel")}catch{}finally{}class U{parseStatus(e){let t,o;switch(e){case 0:t="在航(主机推动)",o="The engine is in use";break;case 1:t="锚泊",o="Anchored";break;case 2:t="失控",o="Not operated";break;case 3:t="操纵受限",o="Limited airworthiness";break;case 4:t="吃水受限",o="Limited by ship's draft";break;case 5:t="靠泊",o="Mooring";break;case 6:t="搁浅",o="Stranded";break;case 7:t="捕捞作业",o="Engaged in fishing";break;case 8:t="靠帆船提供动力",o="Sailing";break;default:t="未定义",o="Undefined"}return{labelCn:t,labelEn:o}}}class mt extends U{constructor(t,o){super();z(this,"clientId");z(this,"clientSecret");z(this,"token");this.clientId=t,this.clientSecret=o}async authToken(t={}){const o="https://svc.data.myvessel.cn/ada/oauth/token",i={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},n=await Y.post(o,i).json();M==null||M.info("[%s] fetch access token from: %s - %j",t.requestId,o,n),n.error||(this.token={accessToken:n.access_token,tokenType:n.token_type,expiresIn:n.expires_in,scope:n.scope,jti:n.jti,issuedAt:w().utc().format()})}async realTimePosition(t,o={}){var l,m,h;(!this.token||w().diff(w(this.token.issuedAt),"seconds")>((l=this.token)==null?void 0:l.expiresIn)-300)&&await this.authToken(o);const i="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",n={headers:{Authorization:`${(m=this.token)==null?void 0:m.tokenType} ${(h=this.token)==null?void 0:h.accessToken}`},searchParams:{mmsi:t}};M==null||M.info("[%s] fetch realtime position from: %s - %j",o.requestId,i,n);const a=await Y.get(i,n).json();if(a.code)return M==null||M.warn("[%s] fetch realtime position failed: %j",o.requestId,i,{message:a.message,status:a.status,code:a.code}),a;const s=a.data;for(const y in s)!isNaN(s[y])&&Number(s[y])!==1/0&&(s[y]=Number(s[y]));const d=w(`${s.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:s.mmsi,name:s.vesselName,imo:s.imo,callSign:s.callsign,lat:s.lat,lng:s.lon,length:s.length,width:s.width,draught:s.currDraught,sog:s.sog,cog:s.cog,hdg:s.hdg,rot:s.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta)?w.utc(s.eta).format():void 0,destination:s.dest,positionTime:d.unix(),status:s.status,labelCn:s.statusNameCn,labelEn:s.statusNameEn,method:"position",vendor:"myVessel",utc:d.utc().format()}}async trajectory(t,o,i,n,a=!0,s={}){(!this.token||w().diff(w(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(s);const d=await this.realTimePosition(t,s),r=w(o),l=w(i),m=[];for(;l.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(t,r,r.clone().add(30,"day"),d,n,m,s),r.add(30,"day");return await this.trajectoryIn30Day(t,r,l,d,n,m,s),m}async trajectoryIn30Day(t,o,i,n,a,s,d={}){var f,j,k,g,v;const r="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",l={headers:{Authorization:`${(f=this.token)==null?void 0:f.tokenType} ${(j=this.token)==null?void 0:j.accessToken}`},json:{mmsi:t,startTime:o.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};M==null||M.info("[%s] fetch trajectory from: %s - %j",d.requestId,r,l);const m=await Y.post(r,l).json();if(m.code)return M==null||M.warn("[%s] fetch trajectory failed: %j",d.requestId,r,{message:m.message,status:m.status,code:m.code}),m;let h=-1;const y=w(`${(g=(k=m.data)==null?void 0:k[0])==null?void 0:g.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(v=m.data)==null||v.forEach(c=>{for(const P in c)!isNaN(c[P])&&Number(c[P])!==1/0&&(c[P]=Number(c[P]));const b=w(`${c.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),p=c.status,{labelCn:u,labelEn:I}=this.parseStatus(p),F={mmsi:c.mmsi,imo:n==null?void 0:n.imo,lat:c.lat,lng:c.lon,sog:c.sog,cog:c.cog,hdg:c.hdg,draught:c.draught,status:p,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(c.eta)?w(`${c.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").utc().format():void 0,destination:c.dest,positionTime:b.unix(),labelCn:u,labelEn:I,method:"trajectory",vendor:"myVessel",utc:b.utc().format()},x=Math.floor(b.diff(y,"minute",!0)/(a||1));x!==h&&(h=x,s.push(F))}),s}}class yt extends U{constructor(t){super();z(this,"token");this.token=t}async realTimePosition(t,o={}){const i="https://api.hifleet.com/position/position/get/token",n={searchParams:{mmsi:t,usertoken:this.token}},a=await Y.post(i,n).json();M==null||M.info("[%s] fetch realtime position from: %s - %j",o.requestId,i,n);const s=a==null?void 0:a.list;if(!s)return M==null||M.warn("[%s] fetch realtime position failed: %j",o.requestId,i,a),a;for(const y in s)!isNaN(s[y])&&Number(s[y])!==1/0&&(s[y]=Number(s[y]));s.status=s.sp>3?0:1;const d=s.status,{labelCn:r,labelEn:l}=this.parseStatus(d),m=w(`${s.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:s.m,name:s.n,imo:s.imonumber,callSign:s.callsign,lat:Math.round(s.la/60*1e5)/1e5,lng:Math.round(s.lo/60*1e5)/1e5,length:s.l,width:s.w,draught:s.draught,sog:s.sp,cog:s.co,hdg:s.h,rot:isNaN(s.rot)?0:s.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta)?w.utc(s.eta).format():void 0,destination:s.destination,positionTime:m.unix(),utc:m.utc().format(),status:d,labelCn:r,labelEn:l,method:"position",vendor:"hifleet"}}async search(t,o={}){let i="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const n={searchParams:{keyword:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let a=await Y.post(i,n).json();M==null||M.info("[%s] fetch vessel props from: %s - %j",o.requestId,i,n),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 s={mmsi:a.m,name:a.n,imo:a.i,callSign:a.c,length:a.l,breadth:a.b,draught:a.dr,type:a.t};return i="https://www.hifleet.com/hifleetapi/sameShipSearch.do",a=await Y.post(i,n).json(),M==null||M.info("[%s] search vessel dead weight from: %s - %j",o.requestId,i,n),a instanceof Array&&(a=a[0]),a&&(s.deadweight=Number(a.dwt)),s}async suggest(t,o={}){const i="https://www.hifleet.com/hifleetapi/getShipSuggest.do",n={searchParams:{q:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}},a=await Y.post(i,n).json();M==null||M.info("[%s] suggest vessel props from: %s - %j",o.requestId,i,n);const s=[];for(const d of a)s.push({mmsi:!d.mmsi||isNaN(d.mmsi)?null:Number(d.mmsi),name:d.name,callSign:d.callsign,imo:!d.imo||isNaN(d.imo)?null:Number(d.imo),score:d._score});return s.sort((d,r)=>r.score-d.score),s}async trajectory(t,o,i,n,a=!0,s={}){var c,b,p;const d=await this.realTimePosition(t,s);let r=w(o);const l=w(i),m=w();if(a){let u=l.diff(r,"d",!0);u<0?r=l.clone().subtract(40,"d"):u<30?r.subtract(10,"d"):u<60?r.subtract(5,"d"):r=l.clone().subtract(80,"d"),u=m.diff(l,"d",!0),l.add(u>10?240:u*24,"h")}const h={searchParams:{endtime:l.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),starttime:r.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),mmsi:t,usertoken:this.token}},y="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",f=await Y.get(y,h).json();M==null||M.info("[%s] fetch trajectory from: %s - %j",s.requestId,y,h);let j;f&&(j=((b=(c=f.ships)==null?void 0:c.offors)==null?void 0:b.ship)||[],j.length||M==null||M.warn("[%s] fetch trajectory failed: %j",s.requestId,f));const k=[];let g=-1;const v=w(`${(p=j==null?void 0:j[0])==null?void 0:p.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const u of j){for(const N in u)!isNaN(u[N])&&Number(u[N])!==1/0&&(u[N]=Number(u[N]));const I=w(`${u.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");u.status=u.sp>4?0:1;const{labelEn:F,labelCn:x}=this.parseStatus(u.status),P={mmsi:u.m,name:u.n,imo:d==null?void 0:d.imo,lat:u.la,lng:u.lo,draught:u.draught,sog:u.sp,cog:u.co,hdg:u.hdg,positionTime:I.unix(),utc:I.utc().format(),status:u.status,labelCn:x,labelEn:F,method:"trajectory",vendor:"hifleet"},E=Math.floor(I.diff(v,"minute",!0)/(n||1));E!==g&&(g=E,k.push(P))}return k}}class pt extends U{constructor(t){super();z(this,"token");this.token=t}async realTimePosition(t,o={}){const i={searchParams:{id:t,k:this.token,enc:1}},n="https://api.shipxy.com/apicall/GetSingleShip",a=await Y.get(n,i).json();if(M==null||M.info("[%s] fetch realtime position from: %s - %j",o.requestId,n,i),(a==null?void 0:a.status)!==0)return a;const s=a.data[0];for(const h in s)!isNaN(s[h])&&Number(s[h])!==1/0&&(s[h]=Number(s[h]));const{labelCn:d,labelEn:r}=await this.parseStatus(s.navistat),l=w.unix(s.lasttime);return{mmsi:s.ShipID,name:s.name,imo:s.imo,callSign:s.callsign,lat:Math.round(s.lat/1e6*1e5)/1e5,lng:Math.round(s.lon/1e6*1e5)/1e5,length:Math.round(s.length/10*100)/100,width:Math.round(s.width/10*100)/100,draught:Math.round(s.draught/1e3*100)/100,sog:Math.round(s.sog*3600/1e3/1852*100)/100,cog:Math.round(s.cog/100*100)/100,hdg:Math.round(s.hdg/100*100)/100,rot:Math.round(s.rot/100*100)/100,positionTime:s.lasttime,utc:l.utc().format(),status:s.navistat,labelEn:r,labelCn:d,method:"position",vendor:"shipxy"}}async trajectory(t,o,i,n,a=!0,s={}){var v;const d=await this.realTimePosition(t,s),r=w(o),l=w(i),m="https://api.shipxy.com/apicall/GetShipTrack",h={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:r.unix(),etm:l.unix()}},y=await Y.get(m,h).json();if(M==null||M.info("[%s] fetch trajectory from: %s - %j",s.requestId,m,h),(y==null?void 0:y.status)!==0)return y;const f=y==null?void 0:y.points,j=[],k=w.unix((v=f[0])==null?void 0:v.utc);let g=-1;for(const c of f){const b=w.unix(c.utc),p={imo:d==null?void 0:d.imo,mmsi:t,sog:Math.round(c.sog*3600/1e3/1852*100)/100,cog:Math.round(c.cog/100*100)/100,lat:Math.round(c.lat/1e6*1e5)/1e5,lng:Math.round(c.lon/1e6*1e5)/1e5,positionTime:b.unix(),utc:b.utc().format(),method:"trajectory",vendor:"shipxy"},u=Math.floor(b.diff(k,"minute",!0)/(n||1));u!==g&&(g=u,j.push(p))}return j}}class Mt extends U{constructor(t){super();z(this,"token");this.token=t}async getShipId(t,o={}){const i={headers:{appKey:this.token},json:{mmsiList:t}},n="https://api3.myships.com/sp/ships/getShipIdByMMSI",a=await Y.post(n,i).json();return M==null||M.info("[%s] fetch ship id from: %s - %j",o.requestId,n,i),a.code!=="0"?a:a.data[0].shipId}async getShipInfo(t,o={}){const i={headers:{appKey:this.token},json:{shipId:t}},n="https://api3.myships.com/sp/ships/aissta",a=await Y.post(n,i).json();if(M==null||M.info("[%s] fetch ship info from: %s - %j",o.requestId,n,i),a.code!=="0")return a;const s=a.data;let d=s.imo;return t==="407170"&&(d="9198379",M==null||M.warn("[%s] ship(%s) imo error: %s, should be %s",o.requestId,t,s.imo,d)),{mmsi:s.mmsi,name:s.shipnameEn,imo:d,callSign:s.callSign,length:s.length,width:s.breadth,draught:(s.draught||100)/10}}async realTimePosition(t,o={}){const i=await this.getShipId(t,o),n=await this.getShipInfo(i,o),a={headers:{appKey:this.token},json:{shipId:i}},s="https://api3.myships.com/sp/ships/position/latest",d=await Y.post(s,a).json();M==null||M.info("[%s] fetch realtime position from: %s - %j",o.requestId,s,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:l,labelEn:m}=await this.parseStatus(r.aisNavStatus),h=w.unix(r.posTime);return{...n,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:h.utc().format(),status:r.aisNavStatus,labelEn:m,labelCn:l,method:"position",vendor:"myship"}}async trajectory(t,o,i,n,a=!0,s={}){const d=w(o),r=w(i),l=await this.getShipId(t),m=await this.getShipInfo(l),h=[];for(;r.diff(d,"day",!0)>30;)await this.trajectoryIn30Day(l,d.unix(),d.add(30,"day").unix(),m,t,n,h);return await this.trajectoryIn30Day(l,d.unix(),r.unix(),m,t,n,h),h}async trajectoryIn30Day(t,o,i,n,a,s,d,r={}){var k;const l={headers:{appKey:this.token},json:{shipId:t,startTime:o,endTime:i}},m="https://api3.myships.com/sp/ships/position/history",h=await Y.post(m,l).json();if(M==null||M.info("[%s] fetch trajectory from: %s - %j",r.requestId,m,l),h.code!=="0")return M==null||M.warn("[%s] invoke myship trajectory failed: %j",r.requestId,h),h;const y=h.data;for(const g in y)!isNaN(y[g])&&Number(y[g])!==1/0&&(y[g]=Number(y[g]));const f=w.unix((k=y[0])==null?void 0:k.posTime);let j=-1;for(const g of y){const v=w.unix(g.posTime),c={imo:n==null?void 0:n.imo,mmsi:a,lat:Math.round(g.lat/1e4/60*1e5)/1e5,lng:Math.round(g.lon/1e4/60*1e5)/1e5,sog:Math.round(g.sog/10*100)/100,cog:Math.round(g.cog/10*100)/100,hdg:Math.round(g.heading*100)/100,rot:Math.round(g.rot*100)/100,positionTime:v.unix(),utc:v.utc().format(),method:"trajectory",vendor:"myship"},b=Math.floor(v.diff(f,"minute",!0)/(s||1));b!==j&&(j=b,d.push(c))}return d}}let _;try{_=G.getLogger("vessel")}catch{}finally{}var ct=(L=>(L.NOTICE="NOTICE",L.WARN="WARN",L.HEAVY="HEAVY",L.SEVERE="SEVERE",L.ERROR="ERROR",L.FATAL="FATAL",L))(ct||{});class dt{parsePrinciple(e,t={}){var s,d,r;_==null||_.info("[%s] parse rule: %s",t.requestId,e);const o=new RegExp("(?<=\\[)(.+)(?=])","g"),i=e.match(o)?(s=e.match(o))==null?void 0:s[0]:void 0,n=i==null?void 0:i.split(";");if(!n)return;const a={};for(let l=0;l<(n==null?void 0:n.length);l++){const m=(r=(d=n[l].match(o))==null?void 0:d[0])==null?void 0:r.split("],");if(l===0&&!m)a.scope=n[0];else if(m)for(let h=0,y=m.length;h<y;h++){const f=this.parseRule(m[h]);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(e,t={}){var a;_==null||_.info("[%s] parse rule: %s",t.requestId,e),e=e.startsWith("[")?e:`[${e}`,e=e.endsWith("]")?e:`${e}]`;const o=new RegExp("(?<=\\[)(.+?)(?=])","g"),i=(a=e==null?void 0:e.match(o))==null?void 0:a[0],n=i==null?void 0:i.split(",");if(n)return{operator:n[0],number:Number.isNaN(Number(n[1]))?n[1]:Number(n[1]),level:n[2],time:Number(n[3]),key:n[4]}}checkWeather(e,t,o={}){var f,j,k,g,v,c,b,p,u,I,F,x,P,E,N;let i=0,n=0,a=0,s=0;const d=Math.round(((j=(f=t==null?void 0:t.SEVERE)==null?void 0:f.sigWave)==null?void 0:j.number)*1.6*100)/100,r=(g=(k=t==null?void 0:t.SEVERE)==null?void 0:k.sigWave)==null?void 0:g.number,l=(c=(v=t==null?void 0:t.HEAVY)==null?void 0:v.sigWave)==null?void 0:c.number,m=Math.round((((p=(b=t==null?void 0:t.SEVERE)==null?void 0:b.wind)==null?void 0:p.number)+2)*100)/100,h=(I=(u=t==null?void 0:t.SEVERE)==null?void 0:u.wind)==null?void 0:I.number,y=(x=(F=t==null?void 0:t.HEAVY)==null?void 0:F.wind)==null?void 0:x.number;for(let T=0;T<(e==null?void 0:e.length);T++){const H=e[T],A=(E=(P=H==null?void 0:H.meteo)==null?void 0:P.wave)==null?void 0:E.sig,V=(N=H==null?void 0:H.meteo)==null?void 0:N.wind,K=T?w(H.eta).diff(w(e[T-1].eta),"hour",!0):0;s=K>s?K:s,_==null||_.info("[%s] check sig.wave: %j",o.requestId,{...A,dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:l}),(A==null?void 0:A.height)>=d?H.isDangerous=!0:(A==null?void 0:A.height)>=r?H.isSevere=!0:(A==null?void 0:A.height)>=l&&(H.isHeavy=!0),_==null||_.info("[%s] check wind: %j",o.requestId,{...V,dgThd4Wd:m,svThd4Wd:h,hvThd4Wd:y}),(V==null?void 0:V.scale)>=m?(H.isDangerous=!0,delete H.isSevere,delete H.isHeavy):(V==null?void 0:V.scale)>h?(H.isDangerous||(H.isSevere=!0),delete H.isHeavy):(V==null?void 0:V.scale)===y&&!H.isDangerous&&!H.isSevere&&(H.isHeavy=!0),i+=H.isDangerous?K:0,n+=H.isSevere?K:0,a+=H.isHeavy?K:0}return i=Math.round(i*100)/100,n=Math.round(n*100)/100,a=Math.round(a*100)/100,s=Math.round(s),{sample:e,dangerous:i,severe:n,heavy:a,step:s<3?3:s,wind:{dgThd4Wd:m,svThd4Wd:h,hvThd4Wd:y},sig:{dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:l}}}}const wt=new dt;let S;try{S=G.getLogger("vessel")}catch{}finally{}const bt=new it.MeteoHelper2("",!0);var ut=(L=>(L.common="common",L.container="container",L.tugs="tugs",L))(ut||{}),lt=(L=>(L.Ballast="Ballast",L.Laden="Laden",L))(lt||{}),ht=(L=>(L.Cp="CP",L.Perf="Basis",L.Instruct="Other",L))(ht||{});class W{static blockCoefficient(e,t,o,i){let n=Math.round(e/(t*o*i)*100)/100;n=n<.55?.55:n>.85?.85:n;const a=[.55,.6,.65,.7,.75,.8,.85],s=a.map(d=>Math.abs(d-n));return a[s.indexOf(Math.min(...s))]}static froudeNumber(e,t,o=9.8){let i=Math.round(Math.sqrt(e*e/(o*t))*100)/100;return i=i<.05?.05:i>.3?.3:i,i}static amendFactor(e,t,o){const i={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.4,-10.6,-9.5],.8:[2.6,-13.1,-15.1],.85:[3.1,-18.7,28]};let 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]}[e];return o==="Laden"&&(a=i[e]),a[0]+a[1]*t+a[2]*Math.pow(t,2)}static directionFactor(e,t=0){let o;return e>30&&e<=60?o=(1.7-.03*Math.pow(t-4,2))/2:e>60&&e<=150?o=(.9-.06*Math.pow(t-6,2))/2:e>150&&e<=180?o=(.4-.03*Math.pow(t-8,2))/2:o=1,Math.round(o*1e5)/1e5}static vesselTagFactor(e,t,o,i=0){i=i>6?i-.9*(i-6):i;let n;return o==="container"?n=.7*i+Math.pow(i,6.5)/(22*Math.pow(e,2/3)):t==="Ballast"?n=.7*i+Math.pow(i,6.5)/(2.7*Math.pow(e,2/3)):n=.5*i+Math.pow(i,6.5)/(2.7*Math.pow(e,2/3)),n}static waveHeightFactor(e,t){e=e<0?.2:e,e=e>6?e-.9*(e-6):e,e=e>9?9:e;let o;return t>30&&t<=60?o=-.6:t>60&&t<=90?o=-.4:t>90&&t<=120?o=e<3?.4:-.3:t>120&&t<=150?o=e<3?.6:-.5:t>150&&t<=180?o=e<3?.7:-.6:o=-.7,Math.round(o*(.144*Math.pow(e,2)+.178*e)*1e4)/1e4}static assembleProperties(e,t,o,i){var h;const n=e.lbp??e.length??e.lengthOverall??198.9642,a=e.draught??8,s=e.breadthMoulded??e.breadth??e.breadthExtreme??32.4572,d=e.deadweight??67035.7773,r=((h=e==null?void 0:e.type)==null?void 0:h.toLowerCase())||"common";return{tag:r.indexOf("container")>-1?"container":r.indexOf("tugs")>-1?"tugs":"common",lbp:n,loadCondition:t,draught:a,breadthMoulded:s,displacement:Math.round((d/1.025+a*s*n*.7)*1e4)/1e4,speed:Math.round((o??14.1382)*1852/3600*1e4)/1e4,bearing:i||90}}static async speedLoseAt(e,t,o,i="",n=2,a=!0,s=!1,d={}){let r;if(t.velocity&&s&&(e.speed=q.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),a){let l;if(d.meteo2)try{const f=await bt.spotForecast(t.lat,t.lng,o.utc().format(),!1,!1,!0,d),[j]=rt.Meteo2Assist.pickHourly(f,o);l=rt.Meteo2Assist.toLegacy(j)}catch(f){S.warn("[%s] meteo2 spot(%j) forecast failed: %s",d.requestId,{...t,eta:o.utc().format()},f)}else l=await it.MeteoHelper.queryPointFactor(t.lng,t.lat,o.valueOf(),"wind,wave,current,watertemp",i,d);const m=W.weatherFactor(e,l),h=W.currentFactor(e.bearing,l==null?void 0:l.current,n),y=Math.round((e.speed*1.943844+m+h)*100)/100;r={meteo:{...l},wxFactor:m,cFactor:h,speed:t.velocity&&s?t.velocity:y<0?1:y,eta:o.utc().format(),etd:o.utc().format()}}else r={wxFactor:0,cFactor:0,speed:t.velocity&&s?t.velocity:Math.round((e.speed*1.943844+0+0)*100)/100,eta:o.utc().format(),etd:o.utc().format()};return delete t.meteo,delete t.wxFactor,delete t.cFactor,delete t.speed,delete t.etd,{...r,...t}}static async speedLoseInHoursStep(e,t,o,i,n,a,s="",d=!0,r=!1,l={}){t.utc();const m=t.clone().add(14,"days"),h=[],y=[];let f=0,j=0,k,g;for(let v=0;v<a.length-1;v++){let c=a[v];c.distanceFromStart=Math.round((n+j)*1e4)/1e4;const b=a[v+1];if(e.bearing=q.LaneHelper.calculateBearing(c,b,!b.gcToPrevious),c.bearing=e.bearing,c.suspend&&r){c.eta=c.eta||t.utc().format(),c.elapsed=c.elapsed??0;const I=c.suspend-c.elapsed;if(i-f>I)i=i-f-I,t.add(I,"hour"),c.elapsed=c.suspend;else{const F=i-f;c.elapsed+=F,t.add(F,"hour"),i=0}if(S==null||S.info(`[%s] suspend ${c.elapsed} hours at %j, and remain ${i} hours need to go...`,l.requestId,c),i===0)return c.distanceFromPrevious=j,{etd:t,from:g||c,to:c,next:a.filter(F=>F),wps:h,days:y}}else c.suspend=0;d=t.isAfter(m)?!1:d,c=await W.speedLoseAt(e,c,t,s,0,d,r,l),g=g||c,c.important&&h.push(c),t.isSameOrAfter(o)&&(y.push(c),o.add(24,"hour"));const p=q.LaneHelper.calculateDistance(c,b,!b.gcToPrevious);let u=Math.round(p/g.speed*1e5)/1e5;if(f+u<i){if(f+=u,t.add(u,"hour"),delete a[v],S==null||S.debug(`[%s] go to %j from %j with ${p}nm, and cost ${u} hours`,l.requestId,{lat:b.lat,lng:b.lng},{lat:g.lat,lng:g.lng,etd:g.etd}),j+=p,a.filter(I=>I).length<=1){k=b,k.eta=t.utc().format(),k.distanceFromPrevious=p,k.distanceFromStart=Math.round((n+j)*1e4)/1e4,h.push(k),delete a[v+1];break}}else{u=i-f,t.add(u,"hour");const I=q.LngLatHelper.roundPrecision(g.speed*u,5);k=q.LaneHelper.calculateCoordinate(c,e.bearing,I,"nauticalmiles",!b.gcToPrevious),k.eta=t.utc().format(),a[v]=k,S==null||S.debug(`[%s] go to %j from %j with ${I}nm, and cost ${u} hours`,l.requestId,{lat:k.lat,lng:k.lng},{lat:c.lat,lng:c.lng,etd:c.etd}),j+=I,k.distanceFromPrevious=Math.round(j*1e4)/1e4,k.distanceFromStart=Math.round((n+j)*1e4)/1e4;break}}return{etd:t,from:g,to:k,next:a.filter(v=>v),wps:h,days:y}}static currentFactor(e,t,o=0){const i=(e-(t==null?void 0:t.degree)||0)/180*Math.PI;if(Math.abs(i)===Math.PI/2)return 0;let n=((t==null?void 0:t.kts)||0)*Math.cos(i);return o&2?n=Math.ceil(n*100)/100:o&1?n=Math.floor(n*100)/100:n=Math.round(n*100)/100,Math.abs(n)>5?0:n}static weatherFactor(e,t){var m,h,y,f,j,k,g;S==null||S.debug("calculate weather factor via: %j",{...e,...t});const o=W.blockCoefficient(e.displacement,e.lbp,e.breadthMoulded,e.draught),i=W.froudeNumber(e.speed,e.lbp),n=W.amendFactor(o,i,e.loadCondition);let a=Math.abs(e.bearing%360-(((m=t==null?void 0:t.wind)==null?void 0:m.degree)%360||0));a=a>180?360-a:a;const s=W.directionFactor(a,(h=t==null?void 0:t.wind)==null?void 0:h.scale),d=W.vesselTagFactor(e.displacement,e.loadCondition,e.tag,(y=t==null?void 0:t.wind)==null?void 0:y.scale);let r=s*n*d/100*e.speed;r=Math.round(r*1.943844*1e4)/1e4*-1,e.tag==="tugs"&&Math.abs(r)>1&&(r=r/(Math.abs(Math.round(r))+1)),S==null||S.debug("wind wx factor = %d",r),a=Math.abs(e.bearing%360-(((j=(f=t==null?void 0:t.wave)==null?void 0:f.sig)==null?void 0:j.degree)%360||0));const l=W.waveHeightFactor(((g=(k=t==null?void 0:t.wave)==null?void 0:k.sig)==null?void 0:g.height)??1,a);return S==null||S.debug("wave wx factor = %d",l),r=r*.4+l,S==null||S.debug("weather factor = %d",r),r=Math.abs(r)>4?4*(Math.abs(r)/r)+Math.abs(r)/r*(Math.abs(r)-4)*.1:r,Math.round((r||0)*100)/100}static async analyseInstant(e,t,o,i,n,a="",s=0,d=!0,r=!1,l={}){var Q,X,Z,$,tt,et;const m=w().valueOf();e.lng=q.LngLatHelper.convertToStdLng(e.lng);const{route:h,waypoints:y}=n.points,f=q.LaneHelper.calculateSubRoute(e,h);if(((Q=f[0])==null?void 0:Q.length)<=1)return;const{v0:j,label:k}=e.sog?{v0:e.sog,label:"Other"}:{v0:i.speed,label:"CP"},g=W.assembleProperties(o,i.loadCondition,j,0),v=y.length?q.LaneHelper.calculateSubWaypoints(e,y):[];v.forEach(O=>O.important=!0);const c={from:{...e},route:f,waypoints:v,v0:j,label:k},b={hours:[],days:[],wps:[]};s||(q.LaneHelper.calculateRouteDistance(f)/i.speed<=72?s=3:s=6);let p=q.LaneHelper.simplifyRouteToCoordinates(f,v,0),u=0,I=0,F=0,x=0;t=w(t).utc();const P=t.clone();for(;p.length>0;){const O=s-t.hour()%s,B=Math.ceil(t.clone().add(O,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,C=await W.speedLoseInHoursStep(g,t,P,B,u,p,a,d,r,l);(X=C.from)!=null&&X.speed&&(b.hours.push(C.from),b.wps.push(...C.wps),b.days.push(...C.days)),p=C==null?void 0:C.next,p.length||b.hours.push(C==null?void 0:C.to),u+=Math.round((((Z=C==null?void 0:C.to)==null?void 0:Z.distanceFromPrevious)??0)*1e4)/1e4}const E=b.hours;for(let O=0;O<E.length-1;O++){const B=w(E[O+1].eta).diff(E[O].etd,"hour",!0)||1;I+=(E[O].wxFactor||0)*B,F+=(E[O].cFactor||0)*B,x+=B}($=b.wps)==null||$.forEach((O,B)=>{if(O.positionTime=w.utc(O.etd||O.eta).unix(),B){const C=b.wps[B-1],J=O.distanceFromStart-C.distanceFromStart,R=w(O.eta).diff(w(C.etd),"h",!0);O.avgSpd=Math.round(J/R*100)/100}}),b.wps=(tt=b.wps)==null?void 0:tt.reduce((O,B)=>(O.some(C=>C.positionTime===B.positionTime)||O.push(B),O),[]),c.sample=b;const N=b.hours.at(0),T=b.hours.at(-1);c.distance=Math.round(T.distanceFromStart*1e4)/1e4,c.etd=w(N.eta).utc().format(),c.eta=w(T.eta).utc().format(),c.wxFactor=Math.round(I/x*1e4)/1e4,c.cFactor=Math.round(F/x*1e4)/1e4,c.avgSpeed=Math.round(T.distanceFromStart/x*1e4)/1e4,c.totalHrs=Math.round(x*1e4)/1e4;const{distanceInECA:H,hoursInECA:A,totalDgoConsInECA:V,eca:K}=await this.calculateECA(c,i,l),at=q.LngLatHelper.roundPrecision(i.fo/24*(x-A),3),nt=q.LngLatHelper.roundPrecision(i.dgo/24*x,3);c.extend={eca:K,distanceInECA:H,hoursInECA:A,totalDgoConsInECA:V},c.totalFoCons=at,c.totalDgoCons=nt;const st=w().valueOf()-m,ot=((et=b==null?void 0:b.hours)==null?void 0:et.length)||1;return S==null||S.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",l==null?void 0:l.requestId,st,ot,Math.round(st/ot*1e3)/1e3),c}static async analyseInstantWithThreshed(e,t,o,i,n,a,s,d="",r=3,l=!0,m=!1,h={}){var Z,$,tt,et,O,B;const y=w().valueOf();e.lng=q.LngLatHelper.convertToStdLng(e.lng);const{v0:f,label:j}=e.sog?{v0:e.sog,label:"Other"}:{v0:n.speed,label:"CP"},k=W.assembleProperties(i,n.loadCondition,f,0),g=q.LaneHelper.calculateSubRoute(e,a);if(((Z=g[0])==null?void 0:Z.length)<=1)return;const v=s.length?q.LaneHelper.calculateSubWaypoints(e,s):[];v.forEach(C=>C.important=!0);let c=q.LaneHelper.simplifyRouteToCoordinates(g,v,0),b=0,p=0,u=0,I=0;const F={hours:[],wps:[],days:[]};t=w(t).utc();const x=t.clone();for(;c.length>0;){const C=r-t.hour()%r;let J=Math.ceil(t.clone().add(C,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;J=t.clone().add(J,"h").isSameOrAfter(o)?o.diff(t,"h",!0)*1e4/1e4:J;const R=await W.speedLoseInHoursStep(k,t,x,J,b,c,d,l,m,h);if(($=R.from)!=null&&$.speed&&(F.hours.push(R.from),R!=null&&R.wps&&F.wps.push(...R.wps),F.days.push(...R.days)),c=R==null?void 0:R.next,c.length||F.hours.push(R==null?void 0:R.to),b+=Math.round((((tt=R==null?void 0:R.to)==null?void 0:tt.distanceFromPrevious)??0)*1e4)/1e4,!J)break}F.wps=(et=F.wps)==null?void 0:et.reduce((C,J)=>(C.some(R=>R.etd===J.etd)||C.push(J),C),[]),(O=F.wps)==null||O.forEach((C,J)=>{if(J){const R=F.wps[J-1],vt=C.distanceFromStart-R.distanceFromStart,gt=w(C.eta).diff(w(R.etd),"h",!0);C.avgSpd=Math.round(vt/gt*100)/100}});const P=F.hours;for(let C=0;C<P.length-1;C++){const J=w(P[C+1].eta).diff(P[C].etd,"hour",!0);p+=P[C].wxFactor*J,u+=P[C].cFactor*J,I+=J}const E=F.hours.at(0),N=F.hours.at(-1),T=await q.LaneHelper.calculateRangeRoute(E,N,g),H=await q.LaneHelper.calculateRangeWaypoints(E,N,g,v),A={sample:F,distance:Math.round(((N==null?void 0:N.distanceFromStart)||0)*1e4)/1e4,etd:w(E.eta).utc().format(),eta:w(N==null?void 0:N.eta).utc().format(),wxFactor:Math.round(p/I*1e4)/1e4,cFactor:Math.round(u/I*1e4)/1e4,avgSpeed:Math.round(((N==null?void 0:N.distanceFromStart)||0)/I*1e4)/1e4,totalHrs:Math.round(I*1e4)/1e4,from:E,to:N,route:T,waypoints:H,v0:f,label:j},{distanceInECA:V,hoursInECA:K,totalDgoConsInECA:at,eca:nt}=await this.calculateECA(A,n,h),ft=q.LngLatHelper.roundPrecision(n.fo/24*(I-K),3),st=q.LngLatHelper.roundPrecision(n.dgo/24*I,3);A.extend={eca:nt,distanceInECA:V,hoursInECA:K,totalDgoConsInECA:at},A.totalDgoCons=st,A.totalFoCons=ft;const Q=w().valueOf()-y,X=((B=F==null?void 0:F.hours)==null?void 0:B.length)||1;return S==null||S.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",h==null?void 0:h.requestId,Q,X,Math.round(Q/X*1e3)/1e3),A}static async analyseCost(e,t,o,i,n={}){var g,v;const a=w().valueOf(),s=[];n.meteo2=n.meteo2||!0,e.speedStep=e.speedStep||3,e.alterStep=e.alterStep??1;const d=q.LaneHelper.calculateRouteDistance(i.route);let r=0;o.forEach(c=>{const b=Math.ceil(d/c.speed/24);r=r<b?b:r}),r=r*1.3;const l=w.utc(e.etd).add(r??14,"day");let m=1;for(const c of o){const b=JSON.parse(JSON.stringify(i.route)),p=JSON.parse(JSON.stringify(i.waypoints)),u=await W.analyseInstantWithThreshed({lat:e.lat,lng:e.lng},e.etd,l,t,c,b,p,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,n);u&&(await W.calculateCost(u,c,e,n),s.push(u),S==null||S.info("[%s][L%d-%d] analyse from %s to %s cost: %j",n.requestId,1,m,e.etd,l.format(),{cost:u.cost.total,distance:u.distance,hours:u.totalHrs,cp:`${c.speed}/${c.fo}/${c.dgo}`})),m++}s.sort((c,b)=>c.cost.total-b.cost.total);const h=s.at(0),y=s.at(1),f=[];if(f.push({combined:!1,speeds:[h],cost:(g=h.cost)==null?void 0:g.total}),y){const c=h.cost.cp,b=y.cost.cp,p=w(h.eta),u=w(h.etd),I=p.diff(u,"days",!0);let F=Math.ceil(I/2);F=F>7?7:F<e.alterStep?e.alterStep:F;let x=2,P={combined:!1,speeds:[y],cost:(v=y.cost)==null?void 0:v.total},E;for(;F>=e.alterStep;){const N=await W.combinedAnalyse(e,t,l,[c,b],i,F,{...n,level:x});if(P.cost>N.cost?E?(E==null?void 0:E.cost)>N.cost&&(E=N):(E=P,P=N):(!E||(E==null?void 0:E.cost)>N.cost)&&(E=N),F<=e.alterStep)break;F=Math.ceil(F/2),x+=1}f.push(P),E&&f.push(E)}const k=w().valueOf()-a;return S==null||S.info("[%s] analyse elapsed: %d ms",n==null?void 0:n.requestId,k),f.sort((c,b)=>c.cost-b.cost)}static async combinedAnalyse(e,t,o,i,n,a,s={}){s.counter=1,S==null||S.info("[%s][L%d] analyse with alternate cp in every %d days",s.requestId,s.level,a);const d=await W.alternateAnalyse(e,t,o,i,0,n,a,s),r=d.reduce((h,y)=>h+y.cost.total,0);S==null||S.info("[%s][L%d] cost with cpa/cpb turn: %d",s.requestId,s.level,r);const l=await W.alternateAnalyse(e,t,o,i,1,n,a,s),m=l.reduce((h,y)=>h+y.cost.total,0);return S==null||S.info("[%s][L%d] cost with cpb/cpa turn: %d",s.requestId,s.level,m),r<m?{combined:!0,cost:Math.round(r*1e3)/1e3,speeds:d,step:a}:{combined:!0,cost:Math.round(m*1e3)/1e3,speeds:l,step:a}}static async alternateAnalyse(e,t,o,i,n,a,s,d={}){var h,y;let r=w.utc(e.etd);const l={lat:e.lat,lng:e.lng},m=[];for(;r.isBefore(o);){const f=r.clone().utc().add(s,"day"),j=JSON.parse(JSON.stringify(a.route)),k=JSON.parse(JSON.stringify(a.waypoints)),g=i[n],v=await W.analyseInstantWithThreshed(l,r.utc().format(),f,t,g,j,k,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,d);v&&(await W.calculateCost(v,g,e,d),S==null||S.info("[%s][L%d-%d] analyse from %s to %s cost: %j",d.requestId,d.level,d.counter,r.utc().format(),f.utc().format(),{cost:v.cost.total,distance:v.distance,hours:v.totalHrs,cp:`${g.speed}/${g.fo}/${g.dgo}`})),d.counter=d.counter+1;const c=(y=(h=v==null?void 0:v.sample)==null?void 0:h.hours)==null?void 0:y.at(-1);if(c)l.lat=c.lat,l.lng=c.lng,r=w(c.eta),m.push(v),n=n?0:1;else break}return m}static async calculateCost(e,t,o,i={}){var n;if(e){const a=Math.round(e.totalHrs/24*(o.dailyHire||0)*(1-(o.addComm||0))*1e3)/1e3,s=Math.round(e.totalFoCons*(o.priceFO||0)*1e3)/1e3,d=Math.round((e.totalDgoCons+(((n=e.extend)==null?void 0:n.totalDgoConsInECA)||0))*(o.priceDGO||0)*1e3)/1e3;e.cost={total:Math.round((a+s+d)*1e3)/1e3,hire:a,bunker:Math.round((s+d)*1e3)/1e3,cp:t}}return e}static async calculateECA(e,t,o={}){var d,r;const i=await q.LaneHelper.intersectInECA(e.route);let n=0,a=0,s=0;e.sample.wps.forEach(l=>{l.positionTime=w.utc(l.etd||l.eta).unix()});for(const l of i){n+=l.distance;const m=await q.LaneHelper.deadReckoningTime((d=l.waypoints)==null?void 0:d.at(0),e.sample.wps),h=await q.LaneHelper.deadReckoningTime((r=l.waypoints)==null?void 0:r.at(-1),e.sample.wps);l.in=m,l.out=h,l.totalHrs=q.LngLatHelper.roundPrecision((h.positionTime-m.positionTime)/3600,2),l.totalDgoCons=q.LngLatHelper.roundPrecision(t.fo/24*l.totalHrs,3),a+=l.totalHrs,s+=l.totalDgoCons}return n=q.LngLatHelper.roundPrecision(n,3),a=q.LngLatHelper.roundPrecision(a,3),s=q.LngLatHelper.roundPrecision(s,3),{distanceInECA:n,hoursInECA:a,totalDgoConsInECA:s,eca:i}}static async mergeSpeeds(e,t={}){var c,b;const o={hours:[],wps:[],days:[]},i=e.reduce((p,u)=>p+u.distance,0),n=e.reduce((p,u)=>{var I;return p+(((I=u.extend)==null?void 0:I.distanceInECA)||0)},0),a=e.reduce((p,u)=>p+u.totalHrs,0),s=e.reduce((p,u)=>{var I;return p+(((I=u.extend)==null?void 0:I.hoursInECA)||0)},0),d=e.reduce((p,u)=>{var I;return p+(((I=u.extend)==null?void 0:I.totalDgoConsInECA)||0)},0),r=e.reduce((p,u)=>p+u.wxFactor*u.totalHrs/a,0),l=e.reduce((p,u)=>p+u.cFactor*u.totalHrs/a,0),m=e.reduce((p,u)=>p+u.totalFoCons,0),h=e.reduce((p,u)=>p+u.totalDgoCons,0),y=e.reduce((p,u)=>p+u.cost.total,0),f=e.reduce((p,u)=>p+u.cost.hire,0),j=e.reduce((p,u)=>p+u.cost.bunker,0),k=[],g=[];let v;for(const p of e){g.push(...((c=p.extend)==null?void 0:c.eca)||[]);const u=p.sample.hours,I=p.sample.wps,F=p.sample.days,x=u.at(0);v&&(x.distanceFromPrevious=v.distanceFromPrevious,x.distanceFromStart=v.distanceFromStart,u.forEach((T,H)=>{H&&(T.distanceFromStart=T.distanceFromStart+v.distanceFromStart)}),I.at(0).distanceFromPrevious=v.distanceFromPrevious,I.at(0).distanceFromStart=v.distanceFromStart,I.forEach((T,H)=>{H&&(T.distanceFromStart=T.distanceFromStart+v.distanceFromStart)}),F.at(0).distanceFromPrevious=v.distanceFromPrevious,F.at(0).distanceFromStart=v.distanceFromStart,F.forEach((T,H)=>{H&&(T.distanceFromStart=T.distanceFromStart+v.distanceFromStart)})),x.cp=p.cost.cp;const P=[p.etd,p.eta],E=k.findIndex(T=>T.id===x.cp.id);E===-1?(x.cp.segment=[P],k.push(x.cp)):k[E].segment.push(P),u.forEach(T=>{var A;((A=o.hours)==null?void 0:A.findIndex(V=>V.eta===T.eta))===-1&&o.hours.push(T)}),I.forEach(T=>{var A;((A=o.wps)==null?void 0:A.findIndex(V=>V.eta===T.eta))===-1&&o.wps.push(T)}),F.forEach(T=>{var A;((A=o==null?void 0:o.days)==null?void 0:A.findIndex(V=>V.eta===T.eta))===-1&&o.days.push(T)});const N=(b=o.wps)==null?void 0:b.findIndex(T=>T.eta===x.eta);N===-1?o.wps.push(x):o.wps[N]=x,v=u.at(-1)}return o.wps.sort((p,u)=>{w(p.etd).unix()-w(u.etd).unix()}),o.wps.forEach((p,u)=>{if(!p.avgSpd){let I;if(u===0?I=o.wps.at(1):I=o.wps.at(u+1),I){const F=I.distanceFromStart-(p.distanceFromStart||0),x=w(I.etd||I.eta).diff(w(p.etd||I.eta),"hour",!0),P=Math.round(F/x*100)/100;p.avgSpd=P}}}),{sample:o,etd:e.at(0).etd,eta:e.at(-1).eta,from:e.at(0).from,to:e.at(-1).to,v0:e.at(0).v0,label:"Combined",distance:Math.round(i*1e4)/1e4,totalHrs:Math.round(a*1e3)/1e3,avgSpeed:Math.round(i/a*1e3)/1e3,wxFactor:Math.round(r/a*1e3)/1e3,cFactor:Math.round(l/a*1e3)/1e3,totalFoCons:Math.round(m*1e3)/1e3,totalDgoCons:Math.round(h*1e3)/1e3,cost:{total:Math.round(y*1e3)/1e3,hire:Math.round(f*1e3)/1e3,bunker:Math.round(j*1e3)/1e3},extend:{cps:k,eca:g,distanceInECA:Math.round(n*1e4)/1e4,hoursInECA:Math.round(s*1e3)/1e3,totalDgoConsInECA:Math.round(d*1e3)/1e3,speeds:e}}}}D.AISImpl=U,D.AlertHelper=dt,D.AlertLevel=ct,D.HifleetImpl=yt,D.LoadCondition=lt,D.MyShipImpl=Mt,D.MyVesselImpl=mt,D.ShipxyImpl=pt,D.SpeedHelper=W,D.SpeedLabel=ht,D.VesselTag=ut,D.alertHelper=wt,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(D,Y){typeof exports=="object"&&typeof module<"u"?Y(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"],Y):(D=typeof globalThis<"u"?globalThis:D||self,Y(D["idm-plugin-rabbitmq"]={},D.got,D["@log4js-node/log4js-api"],D.moment,D["@idm-plugin/geo2"],D["@idm-plugin/meteo2"],D["@idm-plugin/meteo"]))})(this,function(D,Y,G,w,q,it,rt){"use strict";var It=Object.defineProperty;var St=(D,Y,G)=>Y in D?It(D,Y,{enumerable:!0,configurable:!0,writable:!0,value:G}):D[Y]=G;var z=(D,Y,G)=>(St(D,typeof Y!="symbol"?Y+"":Y,G),G);let M;try{M=G.getLogger("vessel")}catch{}finally{}class U{parseStatus(e){let t,o;switch(e){case 0:t="在航(主机推动)",o="The engine is in use";break;case 1:t="锚泊",o="Anchored";break;case 2:t="失控",o="Not operated";break;case 3:t="操纵受限",o="Limited airworthiness";break;case 4:t="吃水受限",o="Limited by ship's draft";break;case 5:t="靠泊",o="Mooring";break;case 6:t="搁浅",o="Stranded";break;case 7:t="捕捞作业",o="Engaged in fishing";break;case 8:t="靠帆船提供动力",o="Sailing";break;default:t="未定义",o="Undefined"}return{labelCn:t,labelEn:o}}}class mt extends U{constructor(t,o){super();z(this,"clientId");z(this,"clientSecret");z(this,"token");this.clientId=t,this.clientSecret=o}async authToken(t={}){const o="https://svc.data.myvessel.cn/ada/oauth/token",i={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},n=await Y.post(o,i).json();M==null||M.info("[%s] fetch access token from: %s - %j",t.requestId,o,n),n.error||(this.token={accessToken:n.access_token,tokenType:n.token_type,expiresIn:n.expires_in,scope:n.scope,jti:n.jti,issuedAt:w().utc().format()})}async realTimePosition(t,o={}){var u,m,h;(!this.token||w().diff(w(this.token.issuedAt),"seconds")>((u=this.token)==null?void 0:u.expiresIn)-300)&&await this.authToken(o);const i="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",n={headers:{Authorization:`${(m=this.token)==null?void 0:m.tokenType} ${(h=this.token)==null?void 0:h.accessToken}`},searchParams:{mmsi:t}};M==null||M.info("[%s] fetch realtime position from: %s - %j",o.requestId,i,n);const a=await Y.get(i,n).json();if(a.code)return M==null||M.warn("[%s] fetch realtime position failed: %j",o.requestId,i,{message:a.message,status:a.status,code:a.code}),a;const s=a.data;for(const y in s)!isNaN(s[y])&&Number(s[y])!==1/0&&(s[y]=Number(s[y]));const d=w(`${s.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:s.mmsi,name:s.vesselName,imo:s.imo,callSign:s.callsign,lat:s.lat,lng:s.lon,length:s.length,width:s.width,draught:s.currDraught,sog:s.sog,cog:s.cog,hdg:s.hdg,rot:s.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta)?w.utc(s.eta).format():void 0,destination:s.dest,positionTime:d.unix(),status:s.status,labelCn:s.statusNameCn,labelEn:s.statusNameEn,method:"position",vendor:"myVessel",utc:d.utc().format()}}async trajectory(t,o,i,n,a=!0,s={}){(!this.token||w().diff(w(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(s);const d=await this.realTimePosition(t,s),r=w(o),u=w(i),m=[];for(;u.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(t,r,r.clone().add(30,"day"),d,n,m,s),r.add(30,"day");return await this.trajectoryIn30Day(t,r,u,d,n,m,s),m}async trajectoryIn30Day(t,o,i,n,a,s,d={}){var f,j,k,g,v;const r="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",u={headers:{Authorization:`${(f=this.token)==null?void 0:f.tokenType} ${(j=this.token)==null?void 0:j.accessToken}`},json:{mmsi:t,startTime:o.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};M==null||M.info("[%s] fetch trajectory from: %s - %j",d.requestId,r,u);const m=await Y.post(r,u).json();if(m.code)return M==null||M.warn("[%s] fetch trajectory failed: %j",d.requestId,r,{message:m.message,status:m.status,code:m.code}),m;let h=-1;const y=w(`${(g=(k=m.data)==null?void 0:k[0])==null?void 0:g.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(v=m.data)==null||v.forEach(c=>{for(const P in c)!isNaN(c[P])&&Number(c[P])!==1/0&&(c[P]=Number(c[P]));const b=w(`${c.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),p=c.status,{labelCn:l,labelEn:I}=this.parseStatus(p),F={mmsi:c.mmsi,imo:n==null?void 0:n.imo,lat:c.lat,lng:c.lon,sog:c.sog,cog:c.cog,hdg:c.hdg,draught:c.draught,status:p,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(c.eta)?w(`${c.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").utc().format():void 0,destination:c.dest,positionTime:b.unix(),labelCn:l,labelEn:I,method:"trajectory",vendor:"myVessel",utc:b.utc().format()},T=Math.floor(b.diff(y,"minute",!0)/(a||1));T!==h&&(h=T,s.push(F))}),s}}class yt extends U{constructor(t){super();z(this,"token");this.token=t}async realTimePosition(t,o={}){const i="https://api.hifleet.com/position/position/get/token",n={searchParams:{mmsi:t,usertoken:this.token}},a=await Y.post(i,n).json();M==null||M.info("[%s] fetch realtime position from: %s - %j",o.requestId,i,n);const s=a==null?void 0:a.list;if(!s)return M==null||M.warn("[%s] fetch realtime position failed: %j",o.requestId,i,a),a;for(const y in s)!isNaN(s[y])&&Number(s[y])!==1/0&&(s[y]=Number(s[y]));s.status=s.sp>3?0:1;const d=s.status,{labelCn:r,labelEn:u}=this.parseStatus(d),m=w(`${s.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:s.m,name:s.n,imo:s.imonumber,callSign:s.callsign,lat:Math.round(s.la/60*1e5)/1e5,lng:Math.round(s.lo/60*1e5)/1e5,length:s.l,width:s.w,draught:s.draught,sog:s.sp,cog:s.co,hdg:s.h,rot:isNaN(s.rot)?0:s.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta)?w.utc(s.eta).format():void 0,destination:s.destination,positionTime:m.unix(),utc:m.utc().format(),status:d,labelCn:r,labelEn:u,method:"position",vendor:"hifleet"}}async search(t,o={}){let i="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const n={searchParams:{keyword:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let a=await Y.post(i,n).json();M==null||M.info("[%s] fetch vessel props from: %s - %j",o.requestId,i,n),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 s={mmsi:a.m,name:a.n,imo:a.i,callSign:a.c,length:a.l,breadth:a.b,draught:a.dr,type:a.t};return i="https://www.hifleet.com/hifleetapi/sameShipSearch.do",a=await Y.post(i,n).json(),M==null||M.info("[%s] search vessel dead weight from: %s - %j",o.requestId,i,n),a instanceof Array&&(a=a[0]),a&&(s.deadweight=Number(a.dwt)),s}async suggest(t,o={}){const i="https://www.hifleet.com/hifleetapi/getShipSuggest.do",n={searchParams:{q:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}},a=await Y.post(i,n).json();M==null||M.info("[%s] suggest vessel props from: %s - %j",o.requestId,i,n);const s=[];for(const d of a)s.push({mmsi:!d.mmsi||isNaN(d.mmsi)?null:Number(d.mmsi),name:d.name,callSign:d.callsign,imo:!d.imo||isNaN(d.imo)?null:Number(d.imo),score:d._score});return s.sort((d,r)=>r.score-d.score),s}async trajectory(t,o,i,n,a=!0,s={}){var c,b,p;const d=await this.realTimePosition(t,s);let r=w(o);const u=w(i),m=w();if(a){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=m.diff(u,"d",!0),u.add(l>10?240:l*24,"h")}const h={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}},y="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",f=await Y.get(y,h).json();M==null||M.info("[%s] fetch trajectory from: %s - %j",s.requestId,y,h);let j;f&&(j=((b=(c=f.ships)==null?void 0:c.offors)==null?void 0:b.ship)||[],j.length||M==null||M.warn("[%s] fetch trajectory failed: %j",s.requestId,f));const k=[];let g=-1;const v=w(`${(p=j==null?void 0:j[0])==null?void 0:p.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const l of j){for(const N in l)!isNaN(l[N])&&Number(l[N])!==1/0&&(l[N]=Number(l[N]));const I=w(`${l.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");l.status=l.sp>4?0:1;const{labelEn:F,labelCn:T}=this.parseStatus(l.status),P={mmsi:l.m,name:l.n,imo:d==null?void 0:d.imo,lat:l.la,lng:l.lo,draught:l.draught,sog:l.sp,cog:l.co,hdg:l.hdg,positionTime:I.unix(),utc:I.utc().format(),status:l.status,labelCn:T,labelEn:F,method:"trajectory",vendor:"hifleet"},E=Math.floor(I.diff(v,"minute",!0)/(n||1));E!==g&&(g=E,k.push(P))}return k}}class pt extends U{constructor(t){super();z(this,"token");this.token=t}async realTimePosition(t,o={}){const i={searchParams:{id:t,k:this.token,enc:1}},n="https://api.shipxy.com/apicall/GetSingleShip",a=await Y.get(n,i).json();if(M==null||M.info("[%s] fetch realtime position from: %s - %j",o.requestId,n,i),(a==null?void 0:a.status)!==0)return a;const s=a.data[0];for(const h in s)!isNaN(s[h])&&Number(s[h])!==1/0&&(s[h]=Number(s[h]));const{labelCn:d,labelEn:r}=await this.parseStatus(s.navistat),u=w.unix(s.lasttime);return{mmsi:s.ShipID,name:s.name,imo:s.imo,callSign:s.callsign,lat:Math.round(s.lat/1e6*1e5)/1e5,lng:Math.round(s.lon/1e6*1e5)/1e5,length:Math.round(s.length/10*100)/100,width:Math.round(s.width/10*100)/100,draught:Math.round(s.draught/1e3*100)/100,sog:Math.round(s.sog*3600/1e3/1852*100)/100,cog:Math.round(s.cog/100*100)/100,hdg:Math.round(s.hdg/100*100)/100,rot:Math.round(s.rot/100*100)/100,positionTime:s.lasttime,utc:u.utc().format(),status:s.navistat,labelEn:r,labelCn:d,method:"position",vendor:"shipxy"}}async trajectory(t,o,i,n,a=!0,s={}){var v;const d=await this.realTimePosition(t,s),r=w(o),u=w(i),m="https://api.shipxy.com/apicall/GetShipTrack",h={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:r.unix(),etm:u.unix()}},y=await Y.get(m,h).json();if(M==null||M.info("[%s] fetch trajectory from: %s - %j",s.requestId,m,h),(y==null?void 0:y.status)!==0)return y;const f=y==null?void 0:y.points,j=[],k=w.unix((v=f[0])==null?void 0:v.utc);let g=-1;for(const c of f){const b=w.unix(c.utc),p={imo:d==null?void 0:d.imo,mmsi:t,sog:Math.round(c.sog*3600/1e3/1852*100)/100,cog:Math.round(c.cog/100*100)/100,lat:Math.round(c.lat/1e6*1e5)/1e5,lng:Math.round(c.lon/1e6*1e5)/1e5,positionTime:b.unix(),utc:b.utc().format(),method:"trajectory",vendor:"shipxy"},l=Math.floor(b.diff(k,"minute",!0)/(n||1));l!==g&&(g=l,j.push(p))}return j}}class Mt extends U{constructor(t){super();z(this,"token");this.token=t}async getShipId(t,o={}){const i={headers:{appKey:this.token},json:{mmsiList:t}},n="https://api3.myships.com/sp/ships/getShipIdByMMSI",a=await Y.post(n,i).json();return M==null||M.info("[%s] fetch ship id from: %s - %j",o.requestId,n,i),a.code!=="0"?a:a.data[0].shipId}async getShipInfo(t,o={}){const i={headers:{appKey:this.token},json:{shipId:t}},n="https://api3.myships.com/sp/ships/aissta",a=await Y.post(n,i).json();if(M==null||M.info("[%s] fetch ship info from: %s - %j",o.requestId,n,i),a.code!=="0")return a;const s=a.data;let d=s.imo;return t==="407170"&&(d="9198379",M==null||M.warn("[%s] ship(%s) imo error: %s, should be %s",o.requestId,t,s.imo,d)),{mmsi:s.mmsi,name:s.shipnameEn,imo:d,callSign:s.callSign,length:s.length,width:s.breadth,draught:(s.draught||100)/10}}async realTimePosition(t,o={}){const i=await this.getShipId(t,o),n=await this.getShipInfo(i,o),a={headers:{appKey:this.token},json:{shipId:i}},s="https://api3.myships.com/sp/ships/position/latest",d=await Y.post(s,a).json();M==null||M.info("[%s] fetch realtime position from: %s - %j",o.requestId,s,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:u,labelEn:m}=await this.parseStatus(r.aisNavStatus),h=w.unix(r.posTime);return{...n,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:h.utc().format(),status:r.aisNavStatus,labelEn:m,labelCn:u,method:"position",vendor:"myship"}}async trajectory(t,o,i,n,a=!0,s={}){const d=w(o),r=w(i),u=await this.getShipId(t),m=await this.getShipInfo(u),h=[];for(;r.diff(d,"day",!0)>30;)await this.trajectoryIn30Day(u,d.unix(),d.add(30,"day").unix(),m,t,n,h);return await this.trajectoryIn30Day(u,d.unix(),r.unix(),m,t,n,h),h}async trajectoryIn30Day(t,o,i,n,a,s,d,r={}){var k;const u={headers:{appKey:this.token},json:{shipId:t,startTime:o,endTime:i}},m="https://api3.myships.com/sp/ships/position/history",h=await Y.post(m,u).json();if(M==null||M.info("[%s] fetch trajectory from: %s - %j",r.requestId,m,u),h.code!=="0")return M==null||M.warn("[%s] invoke myship trajectory failed: %j",r.requestId,h),h;const y=h.data;for(const g in y)!isNaN(y[g])&&Number(y[g])!==1/0&&(y[g]=Number(y[g]));const f=w.unix((k=y[0])==null?void 0:k.posTime);let j=-1;for(const g of y){const v=w.unix(g.posTime),c={imo:n==null?void 0:n.imo,mmsi:a,lat:Math.round(g.lat/1e4/60*1e5)/1e5,lng:Math.round(g.lon/1e4/60*1e5)/1e5,sog:Math.round(g.sog/10*100)/100,cog:Math.round(g.cog/10*100)/100,hdg:Math.round(g.heading*100)/100,rot:Math.round(g.rot*100)/100,positionTime:v.unix(),utc:v.utc().format(),method:"trajectory",vendor:"myship"},b=Math.floor(v.diff(f,"minute",!0)/(s||1));b!==j&&(j=b,d.push(c))}return d}}let _;try{_=G.getLogger("vessel")}catch{}finally{}var ct=(L=>(L.NOTICE="NOTICE",L.WARN="WARN",L.HEAVY="HEAVY",L.SEVERE="SEVERE",L.ERROR="ERROR",L.FATAL="FATAL",L))(ct||{});class dt{parsePrinciple(e,t={}){var s,d,r;_==null||_.info("[%s] parse rule: %s",t.requestId,e);const o=new RegExp("(?<=\\[)(.+)(?=])","g"),i=e.match(o)?(s=e.match(o))==null?void 0:s[0]:void 0,n=i==null?void 0:i.split(";");if(!n)return;const a={};for(let u=0;u<(n==null?void 0:n.length);u++){const m=(r=(d=n[u].match(o))==null?void 0:d[0])==null?void 0:r.split("],");if(u===0&&!m)a.scope=n[0];else if(m)for(let h=0,y=m.length;h<y;h++){const f=this.parseRule(m[h]);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(e,t={}){var a;_==null||_.info("[%s] parse rule: %s",t.requestId,e),e=e.startsWith("[")?e:`[${e}`,e=e.endsWith("]")?e:`${e}]`;const o=new RegExp("(?<=\\[)(.+?)(?=])","g"),i=(a=e==null?void 0:e.match(o))==null?void 0:a[0],n=i==null?void 0:i.split(",");if(n)return{operator:n[0],number:Number.isNaN(Number(n[1]))?n[1]:Number(n[1]),level:n[2],time:Number(n[3]),key:n[4]}}checkWeather(e,t,o={}){var f,j,k,g,v,c,b,p,l,I,F,T,P,E,N;let i=0,n=0,a=0,s=0;const d=Math.round(((j=(f=t==null?void 0:t.SEVERE)==null?void 0:f.sigWave)==null?void 0:j.number)*1.6*100)/100,r=(g=(k=t==null?void 0:t.SEVERE)==null?void 0:k.sigWave)==null?void 0:g.number,u=(c=(v=t==null?void 0:t.HEAVY)==null?void 0:v.sigWave)==null?void 0:c.number,m=Math.round((((p=(b=t==null?void 0:t.SEVERE)==null?void 0:b.wind)==null?void 0:p.number)+2)*100)/100,h=(I=(l=t==null?void 0:t.SEVERE)==null?void 0:l.wind)==null?void 0:I.number,y=(T=(F=t==null?void 0:t.HEAVY)==null?void 0:F.wind)==null?void 0:T.number;for(let x=0;x<(e==null?void 0:e.length);x++){const H=e[x],A=(E=(P=H==null?void 0:H.meteo)==null?void 0:P.wave)==null?void 0:E.sig,V=(N=H==null?void 0:H.meteo)==null?void 0:N.wind,K=x?w(H.eta).diff(w(e[x-1].eta),"hour",!0):0;s=K>s?K:s,_==null||_.info("[%s] check sig.wave: %j",o.requestId,{...A,dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:u}),(A==null?void 0:A.height)>=d?H.isDangerous=!0:(A==null?void 0:A.height)>=r?H.isSevere=!0:(A==null?void 0:A.height)>=u&&(H.isHeavy=!0),_==null||_.info("[%s] check wind: %j",o.requestId,{...V,dgThd4Wd:m,svThd4Wd:h,hvThd4Wd:y}),(V==null?void 0:V.scale)>=m?(H.isDangerous=!0,delete H.isSevere,delete H.isHeavy):(V==null?void 0:V.scale)>h?(H.isDangerous||(H.isSevere=!0),delete H.isHeavy):(V==null?void 0:V.scale)===y&&!H.isDangerous&&!H.isSevere&&(H.isHeavy=!0),i+=H.isDangerous?K:0,n+=H.isSevere?K:0,a+=H.isHeavy?K:0}return i=Math.round(i*100)/100,n=Math.round(n*100)/100,a=Math.round(a*100)/100,s=Math.round(s),{sample:e,dangerous:i,severe:n,heavy:a,step:s<3?3:s,wind:{dgThd4Wd:m,svThd4Wd:h,hvThd4Wd:y},sig:{dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:u}}}}const wt=new dt;let S;try{S=G.getLogger("vessel")}catch{}finally{}const bt=new it.MeteoHelper2("",!0);var ut=(L=>(L.common="common",L.container="container",L.tugs="tugs",L))(ut||{}),lt=(L=>(L.Ballast="Ballast",L.Laden="Laden",L))(lt||{}),ht=(L=>(L.Cp="CP",L.Perf="Basis",L.Instruct="Other",L))(ht||{});class W{static blockCoefficient(e,t,o,i){let n=Math.round(e/(t*o*i)*100)/100;n=n<.55?.55:n>.85?.85:n;const a=[.55,.6,.65,.7,.75,.8,.85],s=a.map(d=>Math.abs(d-n));return a[s.indexOf(Math.min(...s))]}static froudeNumber(e,t,o=9.8){let i=Math.round(Math.sqrt(e*e/(o*t))*100)/100;return i=i<.05?.05:i>.3?.3:i,i}static amendFactor(e,t,o){const i={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.4,-10.6,-9.5],.8:[2.6,-13.1,-15.1],.85:[3.1,-18.7,28]};let 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]}[e];return o==="Laden"&&(a=i[e]),a[0]+a[1]*t+a[2]*Math.pow(t,2)}static directionFactor(e,t=0){let o;return e>30&&e<=60?o=(1.7-.03*Math.pow(t-4,2))/2:e>60&&e<=150?o=(.9-.06*Math.pow(t-6,2))/2:e>150&&e<=180?o=(.4-.03*Math.pow(t-8,2))/2:o=1,Math.round(o*1e5)/1e5}static vesselTagFactor(e,t,o,i=0){i=i>6?i-.9*(i-6):i;let n;return o==="container"?n=.7*i+Math.pow(i,6.5)/(22*Math.pow(e,2/3)):t==="Ballast"?n=.7*i+Math.pow(i,6.5)/(2.7*Math.pow(e,2/3)):n=.5*i+Math.pow(i,6.5)/(2.7*Math.pow(e,2/3)),n}static waveHeightFactor(e,t){e=e<0?.2:e,e=e>6?e-.9*(e-6):e,e=e>9?9:e;let o;return t>30&&t<=60?o=-.6:t>60&&t<=90?o=-.4:t>90&&t<=120?o=e<3?.4:-.3:t>120&&t<=150?o=e<3?.6:-.5:t>150&&t<=180?o=e<3?.7:-.6:o=-.7,Math.round(o*(.144*Math.pow(e,2)+.178*e)*1e4)/1e4}static assembleProperties(e,t,o,i){var h;const n=e.lbp??e.length??e.lengthOverall??198.9642,a=e.draught??8,s=e.breadthMoulded??e.breadth??e.breadthExtreme??32.4572,d=e.deadweight??67035.7773,r=((h=e==null?void 0:e.type)==null?void 0:h.toLowerCase())||"common";return{tag:r.indexOf("container")>-1?"container":r.indexOf("tugs")>-1?"tugs":"common",lbp:n,loadCondition:t,draught:a,breadthMoulded:s,displacement:Math.round((d/1.025+a*s*n*.7)*1e4)/1e4,speed:Math.round((o??14.1382)*1852/3600*1e4)/1e4,bearing:i||90}}static async speedLoseAt(e,t,o,i="",n=2,a=!0,s=!1,d={}){let r;if(t.velocity&&s&&(e.speed=q.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),a){let u;if(d.meteo2)try{const f=await bt.spotForecast(t.lat,t.lng,o.utc().format(),!1,!1,!0,d),[j]=rt.Meteo2Assist.pickHourly(f,o);u=rt.Meteo2Assist.toLegacy(j)}catch(f){S.warn("[%s] meteo2 spot(%j) forecast failed: %s",d.requestId,{...t,eta:o.utc().format()},f)}else u=await it.MeteoHelper.queryPointFactor(t.lng,t.lat,o.valueOf(),"wind,wave,current,watertemp",i,d);const m=W.weatherFactor(e,u),h=W.currentFactor(e.bearing,u==null?void 0:u.current,n),y=Math.round((e.speed*1.943844+m+h)*100)/100;r={meteo:{...u},wxFactor:m,cFactor:h,speed:t.velocity&&s?t.velocity:y<0?1:y,eta:o.utc().format(),etd:o.utc().format()}}else r={wxFactor:0,cFactor:0,speed:t.velocity&&s?t.velocity:Math.round((e.speed*1.943844+0+0)*100)/100,eta:o.utc().format(),etd:o.utc().format()};return delete t.meteo,delete t.wxFactor,delete t.cFactor,delete t.speed,delete t.etd,{...r,...t}}static async speedLoseInHoursStep(e,t,o,i,n,a,s="",d=!0,r=!1,u={}){t.utc();const m=t.clone().add(14,"days"),h=[],y=[];let f=0,j=0,k,g;for(let v=0;v<a.length-1;v++){let c=a[v];c.distanceFromStart=Math.round((n+j)*1e4)/1e4;const b=a[v+1];if(e.bearing=q.LaneHelper.calculateBearing(c,b,!b.gcToPrevious),c.bearing=e.bearing,c.suspend&&r){c.eta=c.eta||t.utc().format(),c.elapsed=c.elapsed??0;const I=c.suspend-c.elapsed;if(i-f>I)i=i-f-I,t.add(I,"hour"),c.elapsed=c.suspend;else{const F=i-f;c.elapsed+=F,t.add(F,"hour"),i=0}if(S==null||S.info(`[%s] suspend ${c.elapsed} hours at %j, and remain ${i} hours need to go...`,u.requestId,c),i===0)return c.distanceFromPrevious=j,{etd:t,from:g||c,to:c,next:a.filter(F=>F),wps:h,days:y}}else c.suspend=0;d=t.isAfter(m)?!1:d,c=await W.speedLoseAt(e,c,t,s,0,d,r,u),g=g||c,c.important&&h.push(c),t.isSameOrAfter(o)&&(y.push(c),o.add(24,"hour"));const p=q.LaneHelper.calculateDistance(c,b,!b.gcToPrevious);let l=Math.round(p/g.speed*1e5)/1e5;if(f+l<i){if(f+=l,t.add(l,"hour"),delete a[v],S==null||S.debug(`[%s] go to %j from %j with ${p}nm, and cost ${l} hours`,u.requestId,{lat:b.lat,lng:b.lng},{lat:g.lat,lng:g.lng,etd:g.etd}),j+=p,a.filter(I=>I).length<=1){k=b,k.eta=t.utc().format(),k.distanceFromPrevious=p,k.distanceFromStart=Math.round((n+j)*1e4)/1e4,h.push(k),delete a[v+1];break}}else{l=i-f,t.add(l,"hour");const I=q.LngLatHelper.roundPrecision(g.speed*l,5);k=q.LaneHelper.calculateCoordinate(c,e.bearing,I,"nauticalmiles",!b.gcToPrevious),k.eta=t.utc().format(),a[v]=k,S==null||S.debug(`[%s] go to %j from %j with ${I}nm, and cost ${l} hours`,u.requestId,{lat:k.lat,lng:k.lng},{lat:c.lat,lng:c.lng,etd:c.etd}),j+=I,k.distanceFromPrevious=Math.round(j*1e4)/1e4,k.distanceFromStart=Math.round((n+j)*1e4)/1e4;break}}return{etd:t,from:g,to:k,next:a.filter(v=>v),wps:h,days:y}}static currentFactor(e,t,o=0){const i=(e-(t==null?void 0:t.degree)||0)/180*Math.PI;if(Math.abs(i)===Math.PI/2)return 0;let n=((t==null?void 0:t.kts)||0)*Math.cos(i);return o&2?n=Math.ceil(n*100)/100:o&1?n=Math.floor(n*100)/100:n=Math.round(n*100)/100,Math.abs(n)>5?0:n}static weatherFactor(e,t){var m,h,y,f,j,k,g;S==null||S.debug("calculate weather factor via: %j",{...e,...t});const o=W.blockCoefficient(e.displacement,e.lbp,e.breadthMoulded,e.draught),i=W.froudeNumber(e.speed,e.lbp),n=W.amendFactor(o,i,e.loadCondition);let a=Math.abs(e.bearing%360-(((m=t==null?void 0:t.wind)==null?void 0:m.degree)%360||0));a=a>180?360-a:a;const s=W.directionFactor(a,(h=t==null?void 0:t.wind)==null?void 0:h.scale),d=W.vesselTagFactor(e.displacement,e.loadCondition,e.tag,(y=t==null?void 0:t.wind)==null?void 0:y.scale);let r=s*n*d/100*e.speed;r=Math.round(r*1.943844*1e4)/1e4*-1,e.tag==="tugs"&&Math.abs(r)>1&&(r=r/(Math.abs(Math.round(r))+1)),S==null||S.debug("wind wx factor = %d",r),a=Math.abs(e.bearing%360-(((j=(f=t==null?void 0:t.wave)==null?void 0:f.sig)==null?void 0:j.degree)%360||0));const u=W.waveHeightFactor(((g=(k=t==null?void 0:t.wave)==null?void 0:k.sig)==null?void 0:g.height)??1,a);return S==null||S.debug("wave wx factor = %d",u),r=r*.4+u,S==null||S.debug("weather factor = %d",r),r=Math.abs(r)>4?4*(Math.abs(r)/r)+Math.abs(r)/r*(Math.abs(r)-4)*.1:r,Math.round((r||0)*100)/100}static async analyseInstant(e,t,o,i,n,a="",s=0,d=!0,r=!1,u={}){var Q,X,Z,$,tt,et;const m=w().valueOf();e.lng=q.LngLatHelper.convertToStdLng(e.lng);const{route:h,waypoints:y}=n.points,f=q.LaneHelper.calculateSubRoute(e,h);if(((Q=f[0])==null?void 0:Q.length)<=1)return;const{v0:j,label:k}=e.sog?{v0:e.sog,label:"Other"}:{v0:i.speed,label:"CP"},g=W.assembleProperties(o,i.loadCondition,j,0),v=y.length?q.LaneHelper.calculateSubWaypoints(e,y):[];v.forEach(O=>O.important=!0);const c={from:{...e},route:f,waypoints:v,v0:j,label:k},b={hours:[],days:[],wps:[]};s||(q.LaneHelper.calculateRouteDistance(f)/i.speed<=72?s=3:s=6);let p=q.LaneHelper.simplifyRouteToCoordinates(f,v,0),l=0,I=0,F=0,T=0;t=w(t).utc();const P=t.clone();for(;p.length>0;){const O=s-t.hour()%s,B=Math.ceil(t.clone().add(O,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,C=await W.speedLoseInHoursStep(g,t,P,B,l,p,a,d,r,u);(X=C.from)!=null&&X.speed&&(b.hours.push(C.from),b.wps.push(...C.wps),b.days.push(...C.days)),p=C==null?void 0:C.next,p.length||b.hours.push(C==null?void 0:C.to),l+=Math.round((((Z=C==null?void 0:C.to)==null?void 0:Z.distanceFromPrevious)??0)*1e4)/1e4}const E=b.hours;for(let O=0;O<E.length-1;O++){const B=w(E[O+1].eta).diff(E[O].etd,"hour",!0)||1;I+=(E[O].wxFactor||0)*B,F+=(E[O].cFactor||0)*B,T+=B}($=b.wps)==null||$.forEach((O,B)=>{if(O.positionTime=w.utc(O.etd||O.eta).unix(),B){const C=b.wps[B-1],J=O.distanceFromStart-C.distanceFromStart,R=w(O.eta).diff(w(C.etd),"h",!0);O.avgSpd=Math.round(J/R*100)/100}}),b.wps=(tt=b.wps)==null?void 0:tt.reduce((O,B)=>(O.some(C=>C.positionTime===B.positionTime)||O.push(B),O),[]),c.sample=b;const N=b.hours.at(0),x=b.hours.at(-1);c.distance=Math.round(x.distanceFromStart*1e4)/1e4,c.etd=w(N.eta).utc().format(),c.eta=w(x.eta).utc().format(),c.wxFactor=Math.round(I/T*1e4)/1e4,c.cFactor=Math.round(F/T*1e4)/1e4,c.avgSpeed=Math.round(x.distanceFromStart/T*1e4)/1e4,c.totalHrs=Math.round(T*1e4)/1e4;const{distanceInECA:H,hoursInECA:A,totalDgoConsInECA:V,eca:K}=await this.calculateECA(c,i,u),at=q.LngLatHelper.roundPrecision(i.fo/24*(T-A),3),nt=q.LngLatHelper.roundPrecision(i.dgo/24*T,3);c.extend={eca:K,distanceInECA:H,hoursInECA:A,totalDgoConsInECA:V},c.totalFoCons=at,c.totalDgoCons=nt;const st=w().valueOf()-m,ot=((et=b==null?void 0:b.hours)==null?void 0:et.length)||1;return S==null||S.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",u==null?void 0:u.requestId,st,ot,Math.round(st/ot*1e3)/1e3),c}static async analyseInstantWithThreshed(e,t,o,i,n,a,s,d="",r=3,u=!0,m=!1,h={}){var Z,$,tt,et,O,B;const y=w().valueOf();e.lng=q.LngLatHelper.convertToStdLng(e.lng);const{v0:f,label:j}=e.sog?{v0:e.sog,label:"Other"}:{v0:n.speed,label:"CP"},k=W.assembleProperties(i,n.loadCondition,f,0),g=q.LaneHelper.calculateSubRoute(e,a);if(((Z=g[0])==null?void 0:Z.length)<=1)return;const v=s.length?q.LaneHelper.calculateSubWaypoints(e,s):[];v.forEach(C=>C.important=!0);let c=q.LaneHelper.simplifyRouteToCoordinates(g,v,0),b=0,p=0,l=0,I=0;const F={hours:[],wps:[],days:[]};t=w(t).utc();const T=t.clone();for(;c.length>0;){const C=r-t.hour()%r;let J=Math.ceil(t.clone().add(C,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;J=t.clone().add(J,"h").isSameOrAfter(o)?o.diff(t,"h",!0)*1e4/1e4:J;const R=await W.speedLoseInHoursStep(k,t,T,J,b,c,d,u,m,h);if(($=R.from)!=null&&$.speed&&(F.hours.push(R.from),R!=null&&R.wps&&F.wps.push(...R.wps),F.days.push(...R.days)),c=R==null?void 0:R.next,c.length||F.hours.push(R==null?void 0:R.to),b+=Math.round((((tt=R==null?void 0:R.to)==null?void 0:tt.distanceFromPrevious)??0)*1e4)/1e4,!J)break}F.wps=(et=F.wps)==null?void 0:et.reduce((C,J)=>(C.some(R=>R.etd===J.etd)||C.push(J),C),[]),(O=F.wps)==null||O.forEach((C,J)=>{if(J){const R=F.wps[J-1],vt=C.distanceFromStart-R.distanceFromStart,gt=w(C.eta).diff(w(R.etd),"h",!0);C.avgSpd=Math.round(vt/gt*100)/100}});const P=F.hours;for(let C=0;C<P.length-1;C++){const J=w(P[C+1].eta).diff(P[C].etd,"hour",!0);p+=P[C].wxFactor*J,l+=P[C].cFactor*J,I+=J}const E=F.hours.at(0),N=F.hours.at(-1),x=await q.LaneHelper.calculateRangeRoute(E,N,g),H=await q.LaneHelper.calculateRangeWaypoints(E,N,g,v),A={sample:F,distance:Math.round(((N==null?void 0:N.distanceFromStart)||0)*1e4)/1e4,etd:w(E.eta).utc().format(),eta:w(N==null?void 0:N.eta).utc().format(),wxFactor:Math.round(p/I*1e4)/1e4,cFactor:Math.round(l/I*1e4)/1e4,avgSpeed:Math.round(((N==null?void 0:N.distanceFromStart)||0)/I*1e4)/1e4,totalHrs:Math.round(I*1e4)/1e4,from:E,to:N,route:x,waypoints:H,v0:f,label:j},{distanceInECA:V,hoursInECA:K,totalDgoConsInECA:at,eca:nt}=await this.calculateECA(A,n,h),ft=q.LngLatHelper.roundPrecision(n.fo/24*(I-K),3),st=q.LngLatHelper.roundPrecision(n.dgo/24*I,3);A.extend={eca:nt,distanceInECA:V,hoursInECA:K,totalDgoConsInECA:at},A.totalDgoCons=st,A.totalFoCons=ft;const Q=w().valueOf()-y,X=((B=F==null?void 0:F.hours)==null?void 0:B.length)||1;return S==null||S.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",h==null?void 0:h.requestId,Q,X,Math.round(Q/X*1e3)/1e3),A}static async analyseCost(e,t,o,i,n={}){var g,v;const a=w().valueOf(),s=[];n.meteo2=n.meteo2||!0,e.speedStep=e.speedStep||3,e.alterStep=e.alterStep??1;const d=q.LaneHelper.calculateRouteDistance(i.route);let r=0;o.forEach(c=>{const b=Math.ceil(d/c.speed/24);r=r<b?b:r}),r=r*1.3;const u=w.utc(e.etd).add(r??14,"day");let m=1;for(const c of o){const b=JSON.parse(JSON.stringify(i.route)),p=JSON.parse(JSON.stringify(i.waypoints)),l=await W.analyseInstantWithThreshed({lat:e.lat,lng:e.lng},e.etd,u,t,c,b,p,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,n);l&&(await W.calculateCost(l,c,e,n),s.push(l),S==null||S.info("[%s][L%d-%d] analyse from %s to %s cost: %j",n.requestId,1,m,e.etd,u.format(),{cost:l.cost.total,distance:l.distance,hours:l.totalHrs,cp:`${c.speed}/${c.fo}/${c.dgo}`})),m++}s.sort((c,b)=>c.cost.total-b.cost.total);const h=s.at(0),y=s.at(1),f=[];if(f.push({combined:!1,speeds:[h],cost:(g=h.cost)==null?void 0:g.total}),y){const c=h.cost.cp,b=y.cost.cp,p=w(h.eta),l=w(h.etd),I=p.diff(l,"days",!0);let F=Math.ceil(I/2);F=F>7?7:F<e.alterStep?e.alterStep:F;let T=2,P={combined:!1,speeds:[y],cost:(v=y.cost)==null?void 0:v.total},E;for(;F>=e.alterStep;){const N=await W.combinedAnalyse(e,t,u,[c,b],i,F,{...n,level:T});if(P.cost>N.cost?E?(E==null?void 0:E.cost)>N.cost&&(E=N):(E=P,P=N):(!E||(E==null?void 0:E.cost)>N.cost)&&(E=N),F<=e.alterStep)break;F=Math.ceil(F/2),T+=1}f.push(P),E&&f.push(E)}const k=w().valueOf()-a;return S==null||S.info("[%s] analyse elapsed: %d ms",n==null?void 0:n.requestId,k),f.sort((c,b)=>c.cost-b.cost)}static async combinedAnalyse(e,t,o,i,n,a,s={}){s.counter=1,S==null||S.info("[%s][L%d] analyse with alternate cp in every %d days",s.requestId,s.level,a);const d=await W.alternateAnalyse(e,t,o,i,0,n,a,s),r=d.reduce((h,y)=>h+y.cost.total,0);S==null||S.info("[%s][L%d] cost with cpa/cpb turn: %d",s.requestId,s.level,r);const u=await W.alternateAnalyse(e,t,o,i,1,n,a,s),m=u.reduce((h,y)=>h+y.cost.total,0);return S==null||S.info("[%s][L%d] cost with cpb/cpa turn: %d",s.requestId,s.level,m),r<m?{combined:!0,cost:Math.round(r*1e3)/1e3,speeds:d,step:a}:{combined:!0,cost:Math.round(m*1e3)/1e3,speeds:u,step:a}}static async alternateAnalyse(e,t,o,i,n,a,s,d={}){var h,y;let r=w.utc(e.etd);const u={lat:e.lat,lng:e.lng},m=[];for(;r.isBefore(o);){const f=r.clone().utc().add(s,"day"),j=JSON.parse(JSON.stringify(a.route)),k=JSON.parse(JSON.stringify(a.waypoints)),g=i[n],v=await W.analyseInstantWithThreshed(u,r.utc().format(),f,t,g,j,k,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,d);v&&(await W.calculateCost(v,g,e,d),S==null||S.info("[%s][L%d-%d] analyse from %s to %s cost: %j",d.requestId,d.level,d.counter,r.utc().format(),f.utc().format(),{cost:v.cost.total,distance:v.distance,hours:v.totalHrs,cp:`${g.speed}/${g.fo}/${g.dgo}`})),d.counter=d.counter+1;const c=(y=(h=v==null?void 0:v.sample)==null?void 0:h.hours)==null?void 0:y.at(-1);if(c)u.lat=c.lat,u.lng=c.lng,r=w(c.eta),m.push(v),n=n?0:1;else break}return m}static async calculateCost(e,t,o,i={}){var n;if(e){const a=Math.round(e.totalHrs/24*(o.dailyHire||0)*(1-(o.addComm||0))*1e3)/1e3,s=Math.round(e.totalFoCons*(o.priceFO||0)*1e3)/1e3,d=Math.round((e.totalDgoCons+(((n=e.extend)==null?void 0:n.totalDgoConsInECA)||0))*(o.priceDGO||0)*1e3)/1e3;e.cost={total:Math.round((a+s+d)*1e3)/1e3,hire:a,bunker:Math.round((s+d)*1e3)/1e3,cp:t}}return e}static async calculateECA(e,t,o={}){var d,r;const i=await q.LaneHelper.intersectInECA(e.route);let n=0,a=0,s=0;e.sample.wps.forEach(u=>{u.positionTime=w.utc(u.etd||u.eta).unix()});for(const u of i){n+=u.distance;const m=await q.LaneHelper.deadReckoningTime((d=u.waypoints)==null?void 0:d.at(0),e.sample.wps),h=await q.LaneHelper.deadReckoningTime((r=u.waypoints)==null?void 0:r.at(-1),e.sample.wps);u.in=m,u.out=h,u.totalHrs=q.LngLatHelper.roundPrecision((h.positionTime-m.positionTime)/3600,2),u.totalDgoCons=q.LngLatHelper.roundPrecision(t.fo/24*u.totalHrs,3),a+=u.totalHrs,s+=u.totalDgoCons}return n=q.LngLatHelper.roundPrecision(n,3),a=q.LngLatHelper.roundPrecision(a,3),s=q.LngLatHelper.roundPrecision(s,3),{distanceInECA:n,hoursInECA:a,totalDgoConsInECA:s,eca:i}}static async mergeSpeeds(e,t={}){var c,b;const o={hours:[],wps:[],days:[]},i=e.reduce((p,l)=>p+l.distance,0),n=e.reduce((p,l)=>{var I;return p+(((I=l.extend)==null?void 0:I.distanceInECA)||0)},0),a=e.reduce((p,l)=>p+l.totalHrs,0),s=e.reduce((p,l)=>{var I;return p+(((I=l.extend)==null?void 0:I.hoursInECA)||0)},0),d=e.reduce((p,l)=>{var I;return p+(((I=l.extend)==null?void 0:I.totalDgoConsInECA)||0)},0),r=e.reduce((p,l)=>p+l.wxFactor*l.totalHrs/a,0),u=e.reduce((p,l)=>p+l.cFactor*l.totalHrs/a,0),m=e.reduce((p,l)=>p+l.totalFoCons,0),h=e.reduce((p,l)=>p+l.totalDgoCons,0),y=e.reduce((p,l)=>p+l.cost.total,0),f=e.reduce((p,l)=>p+l.cost.hire,0),j=e.reduce((p,l)=>p+l.cost.bunker,0),k=[],g=[];let v;for(const p of e){g.push(...((c=p.extend)==null?void 0:c.eca)||[]);const l=p.sample.hours,I=p.sample.wps,F=p.sample.days,T=l.at(0);v&&(T.distanceFromPrevious=v.distanceFromPrevious,T.distanceFromStart=v.distanceFromStart,l.forEach((x,H)=>{H&&(x.distanceFromStart=x.distanceFromStart+v.distanceFromStart)}),I.at(0).distanceFromPrevious=v.distanceFromPrevious,I.at(0).distanceFromStart=v.distanceFromStart,I.forEach((x,H)=>{H&&(x.distanceFromStart=x.distanceFromStart+v.distanceFromStart)}),F.at(0).distanceFromPrevious=v.distanceFromPrevious,F.at(0).distanceFromStart=v.distanceFromStart,F.forEach((x,H)=>{H&&(x.distanceFromStart=x.distanceFromStart+v.distanceFromStart)})),T.cp=p.cost.cp;const P=[p.etd,p.eta],E=k.findIndex(x=>x.id===T.cp.id);E===-1?(T.cp.segment=[P],k.push(T.cp)):k[E].segment.push(P),l.forEach(x=>{var A;((A=o.hours)==null?void 0:A.findIndex(V=>V.eta===x.eta))===-1&&o.hours.push(x)}),I.forEach(x=>{var A;((A=o.wps)==null?void 0:A.findIndex(V=>V.eta===x.eta))===-1&&o.wps.push(x)}),F.forEach(x=>{var A;((A=o==null?void 0:o.days)==null?void 0:A.findIndex(V=>V.eta===x.eta))===-1&&o.days.push(x)});const N=(b=o.wps)==null?void 0:b.findIndex(x=>x.eta===T.eta);N===-1?o.wps.push(T):o.wps[N]=T,v=l.at(-1)}return o.wps.sort((p,l)=>{w(p.etd).unix()-w(l.etd).unix()}),o.wps.forEach((p,l)=>{const I=o.wps.at(l+1);if(I){const F=I.distanceFromStart-(p.distanceFromStart||0),T=w(I.etd||I.eta).diff(w(p.etd||p.eta),"hour",!0),P=Math.round(F/T*100)/100;p.avgSpd=P}}),{sample:o,etd:e.at(0).etd,eta:e.at(-1).eta,from:e.at(0).from,to:e.at(-1).to,v0:e.at(0).v0,label:"Combined",distance:Math.round(i*1e4)/1e4,totalHrs:Math.round(a*1e3)/1e3,avgSpeed:Math.round(i/a*1e3)/1e3,wxFactor:Math.round(r/a*1e3)/1e3,cFactor:Math.round(u/a*1e3)/1e3,totalFoCons:Math.round(m*1e3)/1e3,totalDgoCons:Math.round(h*1e3)/1e3,cost:{total:Math.round(y*1e3)/1e3,hire:Math.round(f*1e3)/1e3,bunker:Math.round(j*1e3)/1e3},extend:{cps:k,eca:g,distanceInECA:Math.round(n*1e4)/1e4,hoursInECA:Math.round(s*1e3)/1e3,totalDgoConsInECA:Math.round(d*1e3)/1e3,speeds:e}}}}D.AISImpl=U,D.AlertHelper=dt,D.AlertLevel=ct,D.HifleetImpl=yt,D.LoadCondition=lt,D.MyShipImpl=Mt,D.MyVesselImpl=mt,D.ShipxyImpl=pt,D.SpeedHelper=W,D.SpeedLabel=ht,D.VesselTag=ut,D.alertHelper=wt,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
|