@idm-plugin/vessel 1.7.7 → 1.7.9

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 CHANGED
@@ -3,7 +3,7 @@ var ht = (j, e, t) => e in j ? ut(j, e, { enumerable: !0, configurable: !0, writ
3
3
  var G = (j, e, t) => (ht(j, typeof e != "symbol" ? e + "" : e, t), t);
4
4
  import J from "got";
5
5
  import nt from "@log4js-node/log4js-api";
6
- import p from "moment";
6
+ import b from "moment";
7
7
  import { LngLatHelper as B, LaneHelper as L } from "@idm-plugin/geo2";
8
8
  import { MeteoHelper2 as lt, MeteoHelper as ft } from "@idm-plugin/meteo2";
9
9
  import { Meteo2Assist as rt } from "@idm-plugin/meteo";
@@ -76,12 +76,12 @@ class Ct extends et {
76
76
  expiresIn: o.expires_in,
77
77
  scope: o.scope,
78
78
  jti: o.jti,
79
- issuedAt: p().utc().format()
79
+ issuedAt: b().utc().format()
80
80
  });
81
81
  }
82
82
  async realTimePosition(t, n = {}) {
83
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);
84
+ (!this.token || b().diff(b(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}`
@@ -95,7 +95,7 @@ class Ct extends et {
95
95
  const s = a.data;
96
96
  for (const y in s)
97
97
  !isNaN(s[y]) && Number(s[y]) !== 1 / 0 && (s[y] = Number(s[y]));
98
- const d = p(`${s.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
98
+ const d = b(`${s.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
99
99
  return {
100
100
  mmsi: s.mmsi,
101
101
  name: s.vesselName,
@@ -110,7 +110,7 @@ class Ct extends et {
110
110
  cog: s.cog,
111
111
  hdg: s.hdg,
112
112
  rot: s.rot,
113
- eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ? p.utc(s.eta).format() : void 0,
113
+ eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ? b.utc(s.eta).format() : void 0,
114
114
  destination: s.dest,
115
115
  positionTime: d.unix(),
116
116
  status: s.status,
@@ -122,14 +122,14 @@ class Ct extends et {
122
122
  };
123
123
  }
124
124
  async trajectory(t, n, i, o, a = !0, s = {}) {
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), u = p(i), m = [];
125
+ (!this.token || b().diff(b(this.token.issuedAt), "seconds") > this.token.expiresIn - 300) && await this.authToken(s);
126
+ const d = await this.realTimePosition(t, s), r = b(n), u = b(i), m = [];
127
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
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, x, k, v, b;
132
+ var f, x, k, v, w;
133
133
  const r = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", u = {
134
134
  headers: {
135
135
  Authorization: `${(f = this.token) == null ? void 0 : f.tokenType} ${(x = this.token) == null ? void 0 : x.accessToken}`
@@ -145,11 +145,11 @@ class Ct extends et {
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;
148
- const y = p(`${(v = (k = m.data) == null ? void 0 : k[0]) == null ? void 0 : v.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
149
- return (b = m.data) == null || b.forEach((c) => {
148
+ const y = b(`${(v = (k = m.data) == null ? void 0 : k[0]) == null ? void 0 : v.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
149
+ return (w = m.data) == null || w.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: h, labelEn: I } = this.parseStatus(M), S = {
152
+ const p = b(`${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,
@@ -159,15 +159,15 @@ class Ct extends et {
159
159
  hdg: c.hdg,
160
160
  draught: c.draught,
161
161
  status: M,
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,
162
+ eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(c.eta) ? b(`${c.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00").utc().format() : void 0,
163
163
  destination: c.dest,
164
- positionTime: w.unix(),
164
+ positionTime: p.unix(),
165
165
  labelCn: h,
166
166
  labelEn: I,
167
167
  method: "trajectory",
168
168
  vendor: "myVessel",
169
- utc: w.utc().format()
170
- }, D = Math.floor(w.diff(y, "minute", !0) / (a || 1));
169
+ utc: p.utc().format()
170
+ }, D = Math.floor(p.diff(y, "minute", !0) / (a || 1));
171
171
  D !== l && (l = D, s.push(S));
172
172
  }), s;
173
173
  }
@@ -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: u } = this.parseStatus(d), m = p(`${s.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
195
+ const d = s.status, { labelCn: r, labelEn: u } = this.parseStatus(d), m = b(`${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,
@@ -207,7 +207,7 @@ class jt extends et {
207
207
  cog: s.co,
208
208
  hdg: s.h,
209
209
  rot: isNaN(s.rot) ? 0 : s.rot,
210
- eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ? p.utc(s.eta).format() : void 0,
210
+ eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ? b.utc(s.eta).format() : void 0,
211
211
  destination: s.destination,
212
212
  positionTime: m.unix(),
213
213
  utc: m.utc().format(),
@@ -270,10 +270,10 @@ class jt extends et {
270
270
  return s.sort((d, r) => r.score - d.score), s;
271
271
  }
272
272
  async trajectory(t, n, i, o, a = !0, s = {}) {
273
- var c, w, M;
273
+ var c, p, M;
274
274
  const d = await this.realTimePosition(t, s);
275
- let r = p(n);
276
- const u = p(i), m = p();
275
+ let r = b(n);
276
+ const u = b(i), m = b();
277
277
  if (a) {
278
278
  let h = u.diff(r, "d", !0);
279
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");
@@ -288,14 +288,14 @@ class jt extends et {
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
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));
291
+ f && (x = ((p = (c = f.ships) == null ? void 0 : c.offors) == null ? void 0 : p.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 = x == null ? void 0 : x[0]) == null ? void 0 : M.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
294
+ const w = b(`${(M = x == null ? void 0 : x[0]) == null ? void 0 : M.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
295
295
  for (const h of x) {
296
296
  for (const P in h)
297
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");
298
+ const I = b(`${h.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
299
299
  h.status = h.sp > 4 ? 0 : 1;
300
300
  const { labelEn: S, labelCn: D } = this.parseStatus(h.status), Y = {
301
301
  mmsi: h.m,
@@ -314,7 +314,7 @@ class jt extends et {
314
314
  labelEn: S,
315
315
  method: "trajectory",
316
316
  vendor: "hifleet"
317
- }, N = Math.floor(I.diff(b, "minute", !0) / (o || 1));
317
+ }, N = Math.floor(I.diff(w, "minute", !0) / (o || 1));
318
318
  N !== v && (v = N, k.push(Y));
319
319
  }
320
320
  return k;
@@ -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), u = p.unix(s.lasttime);
342
+ const { labelCn: d, labelEn: r } = await this.parseStatus(s.navistat), u = b.unix(s.lasttime);
343
343
  return {
344
344
  mmsi: s.ShipID,
345
345
  name: s.name,
@@ -364,8 +364,8 @@ class Et extends et {
364
364
  };
365
365
  }
366
366
  async trajectory(t, n, i, o, a = !0, s = {}) {
367
- var b;
368
- const d = await this.realTimePosition(t, s), r = p(n), u = p(i), m = "https://api.shipxy.com/apicall/GetShipTrack", l = {
367
+ var w;
368
+ const d = await this.realTimePosition(t, s), r = b(n), u = b(i), m = "https://api.shipxy.com/apicall/GetShipTrack", l = {
369
369
  searchParams: {
370
370
  id: t,
371
371
  k: this.token,
@@ -377,21 +377,21 @@ class Et extends et {
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, x = [], k = p.unix((b = f[0]) == null ? void 0 : b.utc);
380
+ const f = y == null ? void 0 : y.points, x = [], k = b.unix((w = f[0]) == null ? void 0 : w.utc);
381
381
  let v = -1;
382
382
  for (const c of f) {
383
- const w = p.unix(c.utc), M = {
383
+ const p = b.unix(c.utc), M = {
384
384
  imo: d == null ? void 0 : d.imo,
385
385
  mmsi: t,
386
386
  sog: Math.round(c.sog * 3600 / 1e3 / 1852 * 100) / 100,
387
387
  cog: Math.round(c.cog / 100 * 100) / 100,
388
388
  lat: Math.round(c.lat / 1e6 * 1e5) / 1e5,
389
389
  lng: Math.round(c.lon / 1e6 * 1e5) / 1e5,
390
- positionTime: w.unix(),
391
- utc: w.utc().format(),
390
+ positionTime: p.unix(),
391
+ utc: p.utc().format(),
392
392
  method: "trajectory",
393
393
  vendor: "shipxy"
394
- }, h = Math.floor(w.diff(k, "minute", !0) / (o || 1));
394
+ }, h = Math.floor(p.diff(k, "minute", !0) / (o || 1));
395
395
  h !== v && (v = h, x.push(M));
396
396
  }
397
397
  return x;
@@ -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: u, labelEn: m } = await this.parseStatus(r.aisNavStatus), l = p.unix(r.posTime);
453
+ const { labelCn: u, labelEn: m } = await this.parseStatus(r.aisNavStatus), l = b.unix(r.posTime);
454
454
  return {
455
455
  ...o,
456
456
  mmsi: t,
@@ -470,7 +470,7 @@ class Nt extends et {
470
470
  };
471
471
  }
472
472
  async trajectory(t, n, i, o, a = !0, s = {}) {
473
- const d = p(n), r = p(i), u = await this.getShipId(t), m = await this.getShipInfo(u), l = [];
473
+ const d = b(n), r = b(i), u = await this.getShipId(t), m = await this.getShipInfo(u), l = [];
474
474
  for (; r.diff(d, "day", !0) > 30; )
475
475
  await this.trajectoryIn30Day(u, d.unix(), d.add(30, "day").unix(), m, t, o, l);
476
476
  return await this.trajectoryIn30Day(u, d.unix(), r.unix(), m, t, o, l), l;
@@ -492,10 +492,10 @@ class Nt extends et {
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
- const f = p.unix((k = y[0]) == null ? void 0 : k.posTime);
495
+ const f = b.unix((k = y[0]) == null ? void 0 : k.posTime);
496
496
  let x = -1;
497
497
  for (const v of y) {
498
- const b = p.unix(v.posTime), c = {
498
+ const w = b.unix(v.posTime), c = {
499
499
  imo: o == null ? void 0 : o.imo,
500
500
  mmsi: a,
501
501
  lat: Math.round(v.lat / 1e4 / 60 * 1e5) / 1e5,
@@ -504,12 +504,12 @@ class Nt extends et {
504
504
  cog: Math.round(v.cog / 10 * 100) / 100,
505
505
  hdg: Math.round(v.heading * 100) / 100,
506
506
  rot: Math.round(v.rot * 100) / 100,
507
- positionTime: b.unix(),
508
- utc: b.utc().format(),
507
+ positionTime: w.unix(),
508
+ utc: w.utc().format(),
509
509
  method: "trajectory",
510
510
  vendor: "myship"
511
- }, w = Math.floor(b.diff(f, "minute", !0) / (s || 1));
512
- w !== x && (x = w, d.push(c));
511
+ }, p = Math.floor(w.diff(f, "minute", !0) / (s || 1));
512
+ p !== x && (x = p, d.push(c));
513
513
  }
514
514
  return d;
515
515
  }
@@ -575,11 +575,11 @@ class yt {
575
575
  * @param options
576
576
  */
577
577
  checkWeather(e, t, n = {}) {
578
- var f, x, k, v, b, c, w, M, h, I, S, D, Y, N, P;
578
+ var f, x, k, v, w, c, p, M, h, I, S, D, Y, N, P;
579
579
  let i = 0, o = 0, a = 0, s = 0;
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;
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 = (w = t == null ? void 0 : t.HEAVY) == null ? void 0 : w.sigWave) == null ? void 0 : c.number, m = Math.round((((M = (p = t == null ? void 0 : t.SEVERE) == null ? void 0 : p.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
- 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;
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 ? b(E.eta).diff(b(e[T - 1].eta), "hour", !0) : 0;
583
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
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 } };
@@ -593,7 +593,7 @@ try {
593
593
  } finally {
594
594
  }
595
595
  const Mt = new lt("", !0);
596
- var gt = /* @__PURE__ */ ((j) => (j.common = "common", j.container = "container", j.tugs = "tugs", j))(gt || {}), pt = /* @__PURE__ */ ((j) => (j.Ballast = "Ballast", j.Laden = "Laden", j))(pt || {}), wt = /* @__PURE__ */ ((j) => (j.Cp = "CP", j.Perf = "Basis", j.Instruct = "Other", j))(wt || {});
596
+ var gt = /* @__PURE__ */ ((j) => (j.common = "common", j.container = "container", j.tugs = "tugs", j))(gt || {}), bt = /* @__PURE__ */ ((j) => (j.Ballast = "Ballast", j.Laden = "Laden", j))(bt || {}), pt = /* @__PURE__ */ ((j) => (j.Cp = "CP", j.Perf = "Basis", j.Instruct = "Other", j))(pt || {});
597
597
  class O {
598
598
  /**
599
599
  * @see https://baike.baidu.com/item/%E6%96%B9%E5%BD%A2%E7%B3%BB%E6%95%B0/4965568?fr=aladdin
@@ -781,11 +781,11 @@ class O {
781
781
  t.utc();
782
782
  const m = t.clone().add(14, "days"), l = [], y = [];
783
783
  let f = 0, x = 0, k, v;
784
- for (let b = 0; b < a.length - 1; b++) {
785
- let c = a[b];
784
+ for (let w = 0; w < a.length - 1; w++) {
785
+ let c = a[w];
786
786
  c.distanceFromStart = Math.round((o + x) * 1e4) / 1e4;
787
- const w = a[b + 1];
788
- if (e.bearing = L.calculateBearing(c, w, !w.gcToPrevious), c.bearing = e.bearing, c.suspend && r) {
787
+ const p = a[w + 1];
788
+ if (e.bearing = L.calculateBearing(c, p, !p.gcToPrevious), c.bearing = e.bearing, c.suspend && r) {
789
789
  c.eta = c.eta || t.utc().format(), c.elapsed = c.elapsed ?? 0;
790
790
  const I = c.suspend - c.elapsed;
791
791
  if (i - f > I)
@@ -799,22 +799,22 @@ class O {
799
799
  } else
800
800
  c.suspend = 0;
801
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
- const M = L.calculateDistance(c, w, !w.gcToPrevious);
802
+ const M = L.calculateDistance(c, p, !p.gcToPrevious);
803
803
  let h = Math.round(M / v.speed * 1e5) / 1e5;
804
804
  if (f + h < i) {
805
- if (f += h, t.add(h, "hour"), delete a[b], F == null || F.debug(
805
+ if (f += h, t.add(h, "hour"), delete a[w], F == null || F.debug(
806
806
  `[%s] go to %j from %j with ${M}nm, and cost ${h} hours`,
807
807
  u.requestId,
808
- { lat: w.lat, lng: w.lng },
808
+ { lat: p.lat, lng: p.lng },
809
809
  { lat: v.lat, lng: v.lng, etd: v.etd }
810
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];
811
+ k = p, k.eta = t.utc().format(), k.distanceFromPrevious = M, k.distanceFromStart = Math.round((o + x) * 1e4) / 1e4, l.push(k), delete a[w + 1];
812
812
  break;
813
813
  }
814
814
  } else {
815
815
  h = i - f, t.add(h, "hour");
816
816
  const I = B.roundPrecision(v.speed * h, 5);
817
- k = L.calculateCoordinate(c, e.bearing, I, "nauticalmiles", !w.gcToPrevious), k.eta = t.utc().format(), a[b] = k, F == null || F.debug(
817
+ k = L.calculateCoordinate(c, e.bearing, I, "nauticalmiles", !p.gcToPrevious), k.eta = t.utc().format(), a[w] = k, F == null || F.debug(
818
818
  `[%s] go to %j from %j with ${I}nm, and cost ${h} hours`,
819
819
  u.requestId,
820
820
  { lat: k.lat, lng: k.lng },
@@ -823,7 +823,7 @@ class O {
823
823
  break;
824
824
  }
825
825
  }
826
- return { etd: t, from: v, to: k, next: a.filter((b) => b), wps: l, days: y };
826
+ return { etd: t, from: v, to: k, next: a.filter((w) => w), wps: l, days: y };
827
827
  }
828
828
  /**
829
829
  * 洋流影响因子
@@ -869,7 +869,7 @@ class O {
869
869
  */
870
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
- const m = p().valueOf();
872
+ const m = b().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)
@@ -882,22 +882,22 @@ class O {
882
882
  v0: i.speed,
883
883
  label: "CP"
884
884
  /* Cp */
885
- }, v = O.assembleProperties(n, i.loadCondition, x, 0), b = y.length ? L.calculateSubWaypoints(e, y) : [];
886
- b.forEach((q) => q.important = !0);
885
+ }, v = O.assembleProperties(n, i.loadCondition, x, 0), w = y.length ? L.calculateSubWaypoints(e, y) : [];
886
+ w.forEach((q) => q.important = !0);
887
887
  const c = {
888
888
  from: { ...e },
889
889
  route: f,
890
- waypoints: b,
890
+ waypoints: w,
891
891
  v0: x,
892
892
  label: k
893
- }, w = {
893
+ }, p = {
894
894
  hours: [],
895
895
  days: [],
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), h = 0, I = 0, S = 0, D = 0;
900
- t = p(t).utc();
899
+ let M = L.simplifyRouteToCoordinates(f, w, 0), h = 0, I = 0, S = 0, D = 0;
900
+ t = b(t).utc();
901
901
  const Y = t.clone();
902
902
  for (; M.length > 0; ) {
903
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(
@@ -912,21 +912,23 @@ class O {
912
912
  r,
913
913
  u
914
914
  );
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;
915
+ (U = C.from) != null && U.speed && (p.hours.push(C.from), p.wps.push(...C.wps), p.days.push(...C.days)), M = C == null ? void 0 : C.next, M.length || p.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
- const N = w.hours;
917
+ const N = p.hours;
918
918
  for (let q = 0; q < N.length - 1; q++) {
919
- const V = p(N[q + 1].eta).diff(N[q].etd, "hour", !0) || 1;
919
+ const V = b(N[q + 1].eta).diff(N[q].etd, "hour", !0) || 1;
920
920
  I += (N[q].wxFactor || 0) * V, S += (N[q].cFactor || 0) * V, D += V;
921
921
  }
922
- (X = w.wps) == null || X.forEach((q, V) => {
923
- if (q.positionTime = p.utc(q.etd || q.eta).unix(), V) {
924
- const C = w.wps[V - 1], W = q.distanceFromStart - C.distanceFromStart, H = p(q.eta).diff(p(C.etd), "h", !0);
922
+ (X = p.wps) == null || X.forEach((q, V) => {
923
+ q.positionTime = b.utc(q.etd || q.eta).unix();
924
+ const C = p.wps[V - 1];
925
+ if (C) {
926
+ const W = q.distanceFromStart - C.distanceFromStart, H = b(q.eta || q.etd).diff(b(C.etd || C.eta), "h", !0);
925
927
  q.avgSpd = Math.round(W / H * 100) / 100;
926
928
  }
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
- const P = w.hours.at(0), T = w.hours.at(-1);
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;
929
+ }), p.wps = (Z = p.wps) == null ? void 0 : Z.reduce((q, V) => (q.some((C) => C.positionTime === V.positionTime) || q.push(V), q), []), c.sample = p;
930
+ const P = p.hours.at(0), T = p.hours.at(-1);
931
+ c.distance = Math.round(T.distanceFromStart * 1e4) / 1e4, c.etd = b(P.eta).utc().format(), c.eta = b(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
932
  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
933
  c.extend = {
932
934
  eca: K,
@@ -934,7 +936,7 @@ class O {
934
936
  hoursInECA: A,
935
937
  totalDgoConsInECA: R
936
938
  }, c.totalFoCons = st, c.totalDgoCons = at;
937
- const tt = p().valueOf() - m, ot = (($ = w == null ? void 0 : w.hours) == null ? void 0 : $.length) || 1;
939
+ const tt = b().valueOf() - m, ot = (($ = p == null ? void 0 : p.hours) == null ? void 0 : $.length) || 1;
938
940
  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
941
  }
940
942
  /**
@@ -952,7 +954,7 @@ class O {
952
954
  */
953
955
  static async analyseInstantWithThreshed(e, t, n, i, o, a, s, d = "", r = 3, u = !0, m = !1, l = {}) {
954
956
  var Q, X, Z, $, q, V;
955
- const y = p().valueOf();
957
+ const y = b().valueOf();
956
958
  e.lng = B.convertToStdLng(e.lng);
957
959
  const { v0: f, label: x } = e.sog ? {
958
960
  v0: e.sog,
@@ -965,41 +967,42 @@ class O {
965
967
  }, k = O.assembleProperties(i, o.loadCondition, f, 0), v = L.calculateSubRoute(e, a);
966
968
  if (((Q = v[0]) == null ? void 0 : Q.length) <= 1)
967
969
  return;
968
- const b = s.length ? L.calculateSubWaypoints(e, s) : [];
969
- b.forEach((C) => C.important = !0);
970
- let c = L.simplifyRouteToCoordinates(v, b, 0), w = 0, M = 0, h = 0, I = 0;
970
+ const w = s.length ? L.calculateSubWaypoints(e, s) : [];
971
+ w.forEach((C) => C.important = !0);
972
+ let c = L.simplifyRouteToCoordinates(v, w, 0), p = 0, M = 0, h = 0, I = 0;
971
973
  const S = {
972
974
  hours: [],
973
975
  wps: [],
974
976
  days: []
975
977
  };
976
- t = p(t).utc();
978
+ t = b(t).utc();
977
979
  const D = t.clone();
978
980
  for (; c.length > 0; ) {
979
981
  const C = r - t.hour() % r;
980
982
  let W = Math.ceil(t.clone().add(C, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4;
981
983
  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, u, m, l);
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
+ const H = await O.speedLoseInHoursStep(k, t, D, W, p, c, d, u, m, l);
985
+ 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), p += Math.round((((Z = H == null ? void 0 : H.to) == null ? void 0 : Z.distanceFromPrevious) ?? 0) * 1e4) / 1e4, !W)
984
986
  break;
985
987
  }
986
988
  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
- if (W) {
988
- const H = S.wps[W - 1], ct = C.distanceFromStart - H.distanceFromStart, dt = p(C.eta).diff(p(H.etd), "h", !0);
989
+ const H = S.wps[W - 1];
990
+ if (H) {
991
+ const ct = C.distanceFromStart - H.distanceFromStart, dt = b(C.eta || C.etd).diff(b(H.etd || H.eta), "h", !0);
989
992
  C.avgSpd = Math.round(ct / dt * 100) / 100;
990
993
  }
991
994
  });
992
995
  const Y = S.hours;
993
996
  for (let C = 0; C < Y.length - 1; C++) {
994
- const W = p(Y[C + 1].eta).diff(Y[C].etd, "hour", !0);
997
+ const W = b(Y[C + 1].eta).diff(Y[C].etd, "hour", !0);
995
998
  M += Y[C].wxFactor * W, h += Y[C].cFactor * W, I += W;
996
999
  }
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 = {
1000
+ 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, w), A = {
998
1001
  sample: S,
999
1002
  distance: Math.round(((P == null ? void 0 : P.distanceFromStart) || 0) * 1e4) / 1e4,
1000
1003
  // 注意,可能会在first节点Drift,所有采用eta做为初始出发时间
1001
- etd: p(N.eta).utc().format(),
1002
- eta: p(P == null ? void 0 : P.eta).utc().format(),
1004
+ etd: b(N.eta).utc().format(),
1005
+ eta: b(P == null ? void 0 : P.eta).utc().format(),
1003
1006
  wxFactor: Math.round(M / I * 1e4) / 1e4,
1004
1007
  cFactor: Math.round(h / I * 1e4) / 1e4,
1005
1008
  avgSpeed: Math.round(((P == null ? void 0 : P.distanceFromStart) || 0) / I * 1e4) / 1e4,
@@ -1017,7 +1020,7 @@ class O {
1017
1020
  hoursInECA: K,
1018
1021
  totalDgoConsInECA: st
1019
1022
  }, A.totalDgoCons = tt, A.totalFoCons = it;
1020
- const z = p().valueOf() - y, U = ((V = S == null ? void 0 : S.hours) == null ? void 0 : V.length) || 1;
1023
+ const z = b().valueOf() - y, U = ((V = S == null ? void 0 : S.hours) == null ? void 0 : V.length) || 1;
1021
1024
  return F == null || F.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", l == null ? void 0 : l.requestId, z, U, Math.round(z / U * 1e3) / 1e3), A;
1022
1025
  }
1023
1026
  /**
@@ -1036,25 +1039,25 @@ class O {
1036
1039
  * @param options
1037
1040
  */
1038
1041
  static async analyseCost(e, t, n, i, o = {}) {
1039
- var v, b;
1040
- const a = p().valueOf(), s = [];
1042
+ var v, w;
1043
+ const a = b().valueOf(), s = [];
1041
1044
  o.meteo2 = o.meteo2 || !0, e.speedStep = e.speedStep || 3, e.alterStep = e.alterStep ?? 1;
1042
1045
  const d = L.calculateRouteDistance(i.route);
1043
1046
  let r = 0;
1044
1047
  n.forEach((c) => {
1045
- const w = Math.ceil(d / c.speed / 24);
1046
- r = r < w ? w : r;
1048
+ const p = Math.ceil(d / c.speed / 24);
1049
+ r = r < p ? p : r;
1047
1050
  }), r = r * 1.3;
1048
- const u = p.utc(e.etd).add(r ?? 14, "day");
1051
+ const u = b.utc(e.etd).add(r ?? 14, "day");
1049
1052
  let m = 1;
1050
1053
  for (const c of n) {
1051
- const w = JSON.parse(JSON.stringify(i.route)), M = JSON.parse(JSON.stringify(i.waypoints)), h = await O.analyseInstantWithThreshed(
1054
+ const p = JSON.parse(JSON.stringify(i.route)), M = JSON.parse(JSON.stringify(i.waypoints)), h = await O.analyseInstantWithThreshed(
1052
1055
  { lat: e.lat, lng: e.lng },
1053
1056
  e.etd,
1054
1057
  u,
1055
1058
  t,
1056
1059
  c,
1057
- w,
1060
+ p,
1058
1061
  M,
1059
1062
  e.meteoVendor,
1060
1063
  e.speedStep,
@@ -1069,23 +1072,23 @@ class O {
1069
1072
  cp: `${c.speed}/${c.fo}/${c.dgo}`
1070
1073
  })), m++;
1071
1074
  }
1072
- s.sort((c, w) => c.cost.total - w.cost.total);
1075
+ s.sort((c, p) => c.cost.total - p.cost.total);
1073
1076
  const l = s.at(0), y = s.at(1), f = [];
1074
1077
  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), h = p(l.etd), I = M.diff(h, "days", !0);
1078
+ const c = l.cost.cp, p = y.cost.cp, M = b(l.eta), h = b(l.etd), I = M.diff(h, "days", !0);
1076
1079
  let S = Math.ceil(I / 2);
1077
1080
  S = S > 7 ? 7 : S < e.alterStep ? e.alterStep : S;
1078
- let D = 2, Y = { combined: !1, speeds: [y], cost: (b = y.cost) == null ? void 0 : b.total }, N;
1081
+ let D = 2, Y = { combined: !1, speeds: [y], cost: (w = y.cost) == null ? void 0 : w.total }, N;
1079
1082
  for (; S >= e.alterStep; ) {
1080
- const P = await O.combinedAnalyse(e, t, u, [c, w], i, S, { ...o, level: D });
1083
+ const P = await O.combinedAnalyse(e, t, u, [c, p], i, S, { ...o, level: D });
1081
1084
  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
1085
  break;
1083
1086
  S = Math.ceil(S / 2), D += 1;
1084
1087
  }
1085
1088
  f.push(Y), N && f.push(N);
1086
1089
  }
1087
- const k = p().valueOf() - a;
1088
- return F == null || F.info("[%s] analyse elapsed: %d ms", o == null ? void 0 : o.requestId, k), f.sort((c, w) => c.cost - w.cost);
1090
+ const k = b().valueOf() - a;
1091
+ return F == null || F.info("[%s] analyse elapsed: %d ms", o == null ? void 0 : o.requestId, k), f.sort((c, p) => c.cost - p.cost);
1089
1092
  }
1090
1093
  /**
1091
1094
  * 按步长多次减半,分别用7,4,2,1天步长及cpa,cpb交替计算各种组合下的成本
@@ -1117,10 +1120,10 @@ class O {
1117
1120
  */
1118
1121
  static async alternateAnalyse(e, t, n, i, o, a, s, d = {}) {
1119
1122
  var l, y;
1120
- let r = p.utc(e.etd);
1123
+ let r = b.utc(e.etd);
1121
1124
  const u = { lat: e.lat, lng: e.lng }, m = [];
1122
1125
  for (; r.isBefore(n); ) {
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(
1126
+ 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], w = await O.analyseInstantWithThreshed(
1124
1127
  u,
1125
1128
  r.utc().format(),
1126
1129
  f,
@@ -1134,18 +1137,18 @@ class O {
1134
1137
  e.useRouteParam,
1135
1138
  d
1136
1139
  );
1137
- b && (await O.calculateCost(b, v, e, d), F == null || F.info(
1140
+ w && (await O.calculateCost(w, v, e, d), F == null || F.info(
1138
1141
  "[%s][L%d-%d] analyse from %s to %s cost: %j",
1139
1142
  d.requestId,
1140
1143
  d.level,
1141
1144
  d.counter,
1142
1145
  r.utc().format(),
1143
1146
  f.utc().format(),
1144
- { cost: b.cost.total, distance: b.distance, hours: b.totalHrs, cp: `${v.speed}/${v.fo}/${v.dgo}` }
1147
+ { cost: w.cost.total, distance: w.distance, hours: w.totalHrs, cp: `${v.speed}/${v.fo}/${v.dgo}` }
1145
1148
  )), d.counter = d.counter + 1;
1146
- const c = (y = (l = b == null ? void 0 : b.sample) == null ? void 0 : l.hours) == null ? void 0 : y.at(-1);
1149
+ const c = (y = (l = w == null ? void 0 : w.sample) == null ? void 0 : l.hours) == null ? void 0 : y.at(-1);
1147
1150
  if (c)
1148
- u.lat = c.lat, u.lng = c.lng, r = p(c.eta), m.push(b), o = o ? 0 : 1;
1151
+ u.lat = c.lat, u.lng = c.lng, r = b(c.eta), m.push(w), o = o ? 0 : 1;
1149
1152
  else
1150
1153
  break;
1151
1154
  }
@@ -1179,7 +1182,7 @@ class O {
1179
1182
  const i = await L.intersectInECA(e.route);
1180
1183
  let o = 0, a = 0, s = 0;
1181
1184
  e.sample.wps.forEach((u) => {
1182
- u.positionTime = p.utc(u.etd || u.eta).unix();
1185
+ u.positionTime = b.utc(u.etd || u.eta).unix();
1183
1186
  });
1184
1187
  for (const u of i) {
1185
1188
  o += u.distance;
@@ -1199,7 +1202,7 @@ class O {
1199
1202
  * @param options
1200
1203
  */
1201
1204
  static async mergeSpeeds(e, t = {}) {
1202
- var c, w;
1205
+ var c, p;
1203
1206
  const n = {
1204
1207
  hours: [],
1205
1208
  wps: [],
@@ -1214,16 +1217,16 @@ class O {
1214
1217
  var I;
1215
1218
  return M + (((I = h.extend) == null ? void 0 : I.totalDgoConsInECA) || 0);
1216
1219
  }, 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
- let b;
1220
+ let w;
1218
1221
  for (const M of e) {
1219
1222
  v.push(...((c = M.extend) == null ? void 0 : c.eca) || []);
1220
1223
  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
- E && (T.distanceFromStart = T.distanceFromStart + b.distanceFromStart);
1223
- }), I.at(0).distanceFromPrevious = b.distanceFromPrevious, I.at(0).distanceFromStart = b.distanceFromStart, I.forEach((T, E) => {
1224
- E && (T.distanceFromStart = T.distanceFromStart + b.distanceFromStart);
1225
- }), S.at(0).distanceFromPrevious = b.distanceFromPrevious, S.at(0).distanceFromStart = b.distanceFromStart, S.forEach((T, E) => {
1226
- E && (T.distanceFromStart = T.distanceFromStart + b.distanceFromStart);
1224
+ w && (D.distanceFromPrevious = w.distanceFromPrevious, D.distanceFromStart = w.distanceFromStart, h.forEach((T, E) => {
1225
+ E && (T.distanceFromStart = T.distanceFromStart + w.distanceFromStart);
1226
+ }), I.at(0).distanceFromPrevious = w.distanceFromPrevious, I.at(0).distanceFromStart = w.distanceFromStart, I.forEach((T, E) => {
1227
+ E && (T.distanceFromStart = T.distanceFromStart + w.distanceFromStart);
1228
+ }), S.at(0).distanceFromPrevious = w.distanceFromPrevious, S.at(0).distanceFromStart = w.distanceFromStart, S.forEach((T, E) => {
1229
+ E && (T.distanceFromStart = T.distanceFromStart + w.distanceFromStart);
1227
1230
  })), D.cp = M.cost.cp;
1228
1231
  const Y = [M.etd, M.eta], N = k.findIndex((T) => T.id === D.cp.id);
1229
1232
  N === -1 ? (D.cp.segment = [Y], k.push(D.cp)) : k[N].segment.push(Y), h.forEach((T) => {
@@ -1236,15 +1239,15 @@ class O {
1236
1239
  var A;
1237
1240
  ((A = n == null ? void 0 : n.days) == null ? void 0 : A.findIndex((R) => R.eta === T.eta)) === -1 && n.days.push(T);
1238
1241
  });
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 = h.at(-1);
1242
+ const P = (p = n.wps) == null ? void 0 : p.findIndex((T) => T.eta === D.eta);
1243
+ P === -1 ? n.wps.push(D) : n.wps[P] = D, w = h.at(-1);
1241
1244
  }
1242
1245
  return n.wps.sort((M, h) => {
1243
- p(M.etd).unix() - p(h.etd).unix();
1246
+ b(M.etd).unix() - b(h.etd).unix();
1244
1247
  }), n.wps.forEach((M, h) => {
1245
- const I = n.wps.at(h + 1);
1248
+ const I = n.wps[h - 1];
1246
1249
  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;
1250
+ const S = M.distanceFromStart - (I.distanceFromStart || 0), D = b(M.eta || M.etd).diff(b(I.etd || I.eta), "hour", !0), Y = Math.round(S / D * 100) / 100;
1248
1251
  M.avgSpd = Y;
1249
1252
  }
1250
1253
  }), {
@@ -1283,12 +1286,12 @@ export {
1283
1286
  yt as AlertHelper,
1284
1287
  mt as AlertLevel,
1285
1288
  jt as HifleetImpl,
1286
- pt as LoadCondition,
1289
+ bt as LoadCondition,
1287
1290
  Nt as MyShipImpl,
1288
1291
  Ct as MyVesselImpl,
1289
1292
  Et as ShipxyImpl,
1290
1293
  O as SpeedHelper,
1291
- wt as SpeedLabel,
1294
+ pt as SpeedLabel,
1292
1295
  gt as VesselTag,
1293
1296
  Tt as alertHelper
1294
1297
  };
@@ -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 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"})});
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,b,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 p;try{p=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();p==null||p.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:b().utc().format()})}async realTimePosition(t,o={}){var u,m,h;(!this.token||b().diff(b(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}};p==null||p.info("[%s] fetch realtime position from: %s - %j",o.requestId,i,n);const a=await Y.get(i,n).json();if(a.code)return p==null||p.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=b(`${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)?b.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||b().diff(b(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(s);const d=await this.realTimePosition(t,s),r=b(o),u=b(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,w;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")}};p==null||p.info("[%s] fetch trajectory from: %s - %j",d.requestId,r,u);const m=await Y.post(r,u).json();if(m.code)return p==null||p.warn("[%s] fetch trajectory failed: %j",d.requestId,r,{message:m.message,status:m.status,code:m.code}),m;let h=-1;const y=b(`${(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(w=m.data)==null||w.forEach(c=>{for(const P in c)!isNaN(c[P])&&Number(c[P])!==1/0&&(c[P]=Number(c[P]));const v=b(`${c.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),M=c.status,{labelCn:l,labelEn:I}=this.parseStatus(M),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:M,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(c.eta)?b(`${c.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").utc().format():void 0,destination:c.dest,positionTime:v.unix(),labelCn:l,labelEn:I,method:"trajectory",vendor:"myVessel",utc:v.utc().format()},T=Math.floor(v.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();p==null||p.info("[%s] fetch realtime position from: %s - %j",o.requestId,i,n);const s=a==null?void 0:a.list;if(!s)return p==null||p.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=b(`${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)?b.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();p==null||p.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(),p==null||p.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();p==null||p.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,v,M;const d=await this.realTimePosition(t,s);let r=b(o);const u=b(i),m=b();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();p==null||p.info("[%s] fetch trajectory from: %s - %j",s.requestId,y,h);let j;f&&(j=((v=(c=f.ships)==null?void 0:c.offors)==null?void 0:v.ship)||[],j.length||p==null||p.warn("[%s] fetch trajectory failed: %j",s.requestId,f));const k=[];let g=-1;const w=b(`${(M=j==null?void 0:j[0])==null?void 0:M.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=b(`${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(w,"minute",!0)/(n||1));E!==g&&(g=E,k.push(P))}return k}}class Mt 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(p==null||p.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=b.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 w;const d=await this.realTimePosition(t,s),r=b(o),u=b(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(p==null||p.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=b.unix((w=f[0])==null?void 0:w.utc);let g=-1;for(const c of f){const v=b.unix(c.utc),M={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:v.unix(),utc:v.utc().format(),method:"trajectory",vendor:"shipxy"},l=Math.floor(v.diff(k,"minute",!0)/(n||1));l!==g&&(g=l,j.push(M))}return j}}class pt 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 p==null||p.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(p==null||p.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",p==null||p.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();p==null||p.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=b.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=b(o),r=b(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(p==null||p.info("[%s] fetch trajectory from: %s - %j",r.requestId,m,u),h.code!=="0")return p==null||p.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=b.unix((k=y[0])==null?void 0:k.posTime);let j=-1;for(const g of y){const w=b.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:w.unix(),utc:w.utc().format(),method:"trajectory",vendor:"myship"},v=Math.floor(w.diff(f,"minute",!0)/(s||1));v!==j&&(j=v,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,w,c,v,M,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=(w=t==null?void 0:t.HEAVY)==null?void 0:w.sigWave)==null?void 0:c.number,m=Math.round((((M=(v=t==null?void 0:t.SEVERE)==null?void 0:v.wind)==null?void 0:M.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?b(H.eta).diff(b(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 bt=new dt;let S;try{S=G.getLogger("vessel")}catch{}finally{}const vt=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 vt.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 w=0;w<a.length-1;w++){let c=a[w];c.distanceFromStart=Math.round((n+j)*1e4)/1e4;const v=a[w+1];if(e.bearing=q.LaneHelper.calculateBearing(c,v,!v.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 M=q.LaneHelper.calculateDistance(c,v,!v.gcToPrevious);let l=Math.round(M/g.speed*1e5)/1e5;if(f+l<i){if(f+=l,t.add(l,"hour"),delete a[w],S==null||S.debug(`[%s] go to %j from %j with ${M}nm, and cost ${l} hours`,u.requestId,{lat:v.lat,lng:v.lng},{lat:g.lat,lng:g.lng,etd:g.etd}),j+=M,a.filter(I=>I).length<=1){k=v,k.eta=t.utc().format(),k.distanceFromPrevious=M,k.distanceFromStart=Math.round((n+j)*1e4)/1e4,h.push(k),delete a[w+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",!v.gcToPrevious),k.eta=t.utc().format(),a[w]=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(w=>w),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=b().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),w=y.length?q.LaneHelper.calculateSubWaypoints(e,y):[];w.forEach(O=>O.important=!0);const c={from:{...e},route:f,waypoints:w,v0:j,label:k},v={hours:[],days:[],wps:[]};s||(q.LaneHelper.calculateRouteDistance(f)/i.speed<=72?s=3:s=6);let M=q.LaneHelper.simplifyRouteToCoordinates(f,w,0),l=0,I=0,F=0,T=0;t=b(t).utc();const P=t.clone();for(;M.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,M,a,d,r,u);(X=C.from)!=null&&X.speed&&(v.hours.push(C.from),v.wps.push(...C.wps),v.days.push(...C.days)),M=C==null?void 0:C.next,M.length||v.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=v.hours;for(let O=0;O<E.length-1;O++){const B=b(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}($=v.wps)==null||$.forEach((O,B)=>{O.positionTime=b.utc(O.etd||O.eta).unix();const C=v.wps[B-1];if(C){const J=O.distanceFromStart-C.distanceFromStart,R=b(O.eta||O.etd).diff(b(C.etd||C.eta),"h",!0);O.avgSpd=Math.round(J/R*100)/100}}),v.wps=(tt=v.wps)==null?void 0:tt.reduce((O,B)=>(O.some(C=>C.positionTime===B.positionTime)||O.push(B),O),[]),c.sample=v;const N=v.hours.at(0),x=v.hours.at(-1);c.distance=Math.round(x.distanceFromStart*1e4)/1e4,c.etd=b(N.eta).utc().format(),c.eta=b(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=b().valueOf()-m,ot=((et=v==null?void 0:v.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=b().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 w=s.length?q.LaneHelper.calculateSubWaypoints(e,s):[];w.forEach(C=>C.important=!0);let c=q.LaneHelper.simplifyRouteToCoordinates(g,w,0),v=0,M=0,l=0,I=0;const F={hours:[],wps:[],days:[]};t=b(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,v,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),v+=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)=>{const R=F.wps[J-1];if(R){const wt=C.distanceFromStart-R.distanceFromStart,gt=b(C.eta||C.etd).diff(b(R.etd||R.eta),"h",!0);C.avgSpd=Math.round(wt/gt*100)/100}});const P=F.hours;for(let C=0;C<P.length-1;C++){const J=b(P[C+1].eta).diff(P[C].etd,"hour",!0);M+=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,w),A={sample:F,distance:Math.round(((N==null?void 0:N.distanceFromStart)||0)*1e4)/1e4,etd:b(E.eta).utc().format(),eta:b(N==null?void 0:N.eta).utc().format(),wxFactor:Math.round(M/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=b().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,w;const a=b().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 v=Math.ceil(d/c.speed/24);r=r<v?v:r}),r=r*1.3;const u=b.utc(e.etd).add(r??14,"day");let m=1;for(const c of o){const v=JSON.parse(JSON.stringify(i.route)),M=JSON.parse(JSON.stringify(i.waypoints)),l=await W.analyseInstantWithThreshed({lat:e.lat,lng:e.lng},e.etd,u,t,c,v,M,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,v)=>c.cost.total-v.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,v=y.cost.cp,M=b(h.eta),l=b(h.etd),I=M.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:(w=y.cost)==null?void 0:w.total},E;for(;F>=e.alterStep;){const N=await W.combinedAnalyse(e,t,u,[c,v],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=b().valueOf()-a;return S==null||S.info("[%s] analyse elapsed: %d ms",n==null?void 0:n.requestId,k),f.sort((c,v)=>c.cost-v.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=b.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],w=await W.analyseInstantWithThreshed(u,r.utc().format(),f,t,g,j,k,e.meteoVendor,e.speedStep,e.useMeteo,e.useRouteParam,d);w&&(await W.calculateCost(w,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:w.cost.total,distance:w.distance,hours:w.totalHrs,cp:`${g.speed}/${g.fo}/${g.dgo}`})),d.counter=d.counter+1;const c=(y=(h=w==null?void 0:w.sample)==null?void 0:h.hours)==null?void 0:y.at(-1);if(c)u.lat=c.lat,u.lng=c.lng,r=b(c.eta),m.push(w),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=b.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,v;const o={hours:[],wps:[],days:[]},i=e.reduce((M,l)=>M+l.distance,0),n=e.reduce((M,l)=>{var I;return M+(((I=l.extend)==null?void 0:I.distanceInECA)||0)},0),a=e.reduce((M,l)=>M+l.totalHrs,0),s=e.reduce((M,l)=>{var I;return M+(((I=l.extend)==null?void 0:I.hoursInECA)||0)},0),d=e.reduce((M,l)=>{var I;return M+(((I=l.extend)==null?void 0:I.totalDgoConsInECA)||0)},0),r=e.reduce((M,l)=>M+l.wxFactor*l.totalHrs/a,0),u=e.reduce((M,l)=>M+l.cFactor*l.totalHrs/a,0),m=e.reduce((M,l)=>M+l.totalFoCons,0),h=e.reduce((M,l)=>M+l.totalDgoCons,0),y=e.reduce((M,l)=>M+l.cost.total,0),f=e.reduce((M,l)=>M+l.cost.hire,0),j=e.reduce((M,l)=>M+l.cost.bunker,0),k=[],g=[];let w;for(const M of e){g.push(...((c=M.extend)==null?void 0:c.eca)||[]);const l=M.sample.hours,I=M.sample.wps,F=M.sample.days,T=l.at(0);w&&(T.distanceFromPrevious=w.distanceFromPrevious,T.distanceFromStart=w.distanceFromStart,l.forEach((x,H)=>{H&&(x.distanceFromStart=x.distanceFromStart+w.distanceFromStart)}),I.at(0).distanceFromPrevious=w.distanceFromPrevious,I.at(0).distanceFromStart=w.distanceFromStart,I.forEach((x,H)=>{H&&(x.distanceFromStart=x.distanceFromStart+w.distanceFromStart)}),F.at(0).distanceFromPrevious=w.distanceFromPrevious,F.at(0).distanceFromStart=w.distanceFromStart,F.forEach((x,H)=>{H&&(x.distanceFromStart=x.distanceFromStart+w.distanceFromStart)})),T.cp=M.cost.cp;const P=[M.etd,M.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=(v=o.wps)==null?void 0:v.findIndex(x=>x.eta===T.eta);N===-1?o.wps.push(T):o.wps[N]=T,w=l.at(-1)}return o.wps.sort((M,l)=>{b(M.etd).unix()-b(l.etd).unix()}),o.wps.forEach((M,l)=>{const I=o.wps[l-1];if(I){const F=M.distanceFromStart-(I.distanceFromStart||0),T=b(M.eta||M.etd).diff(b(I.etd||I.eta),"hour",!0),P=Math.round(F/T*100)/100;M.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=pt,D.MyVesselImpl=mt,D.ShipxyImpl=Mt,D.SpeedHelper=W,D.SpeedLabel=ht,D.VesselTag=ut,D.alertHelper=bt,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idm-plugin/vessel",
3
3
  "private": false,
4
- "version": "1.7.7",
4
+ "version": "1.7.9",
5
5
  "description": "idm plugin for vessel",
6
6
  "type": "module",
7
7
  "keywords": [