@idm-plugin/vessel 1.2.5 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  var tt = Object.defineProperty;
2
- var et = (w, s, t) => s in w ? tt(w, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : w[s] = t;
3
- var Z = (w, s, t) => (et(w, typeof s != "symbol" ? s + "" : s, t), t);
2
+ var et = (k, s, t) => s in k ? tt(k, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : k[s] = t;
3
+ var Z = (k, s, t) => (et(k, typeof s != "symbol" ? s + "" : s, t), t);
4
4
  import A from "got";
5
5
  import z from "@log4js-node/log4js-api";
6
- import b from "moment";
6
+ import g from "moment";
7
7
  import { LngLatHelper as B, LaneHelper as L } from "@idm-plugin/geo";
8
8
  import { MeteoHelper as st } from "@idm-plugin/meteo";
9
- let f;
9
+ let h;
10
10
  try {
11
- f = z.getLogger("vessel");
11
+ h = z.getLogger("vessel");
12
12
  } catch {
13
13
  } finally {
14
14
  }
@@ -69,32 +69,32 @@ class mt extends K {
69
69
  grant_type: "client_credentials"
70
70
  }
71
71
  }, n = await A.post(i, o).json();
72
- f == null || f.info("[%s] fetch access token from: %s - %j", t.requestId, i, n), n.error || (this.token = {
72
+ h == null || h.info("[%s] fetch access token from: %s - %j", t.requestId, i, n), n.error || (this.token = {
73
73
  accessToken: n.access_token,
74
74
  tokenType: n.token_type,
75
75
  expiresIn: n.expires_in,
76
76
  scope: n.scope,
77
77
  jti: n.jti,
78
- issuedAt: b().utc().format()
78
+ issuedAt: g().utc().format()
79
79
  });
80
80
  }
81
81
  async realTimePosition(t, i = {}) {
82
- var u, l, M;
83
- (!this.token || b().diff(b(this.token.issuedAt), "seconds") > ((u = this.token) == null ? void 0 : u.expiresIn) - 300) && await this.authToken(i);
82
+ var c, u, y;
83
+ (!this.token || g().diff(g(this.token.issuedAt), "seconds") > ((c = this.token) == null ? void 0 : c.expiresIn) - 300) && await this.authToken(i);
84
84
  const o = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit", n = {
85
85
  headers: {
86
- Authorization: `${(l = this.token) == null ? void 0 : l.tokenType} ${(M = this.token) == null ? void 0 : M.accessToken}`
86
+ Authorization: `${(u = this.token) == null ? void 0 : u.tokenType} ${(y = this.token) == null ? void 0 : y.accessToken}`
87
87
  },
88
88
  searchParams: { mmsi: t }
89
89
  };
90
- f == null || f.info("[%s] fetch realtime position from: %s - %j", i.requestId, o, n);
90
+ h == null || h.info("[%s] fetch realtime position from: %s - %j", i.requestId, o, n);
91
91
  const a = await A.get(o, n).json();
92
92
  if (a.code)
93
- return f == null || f.warn("[%s] fetch realtime position failed: %j", i.requestId, o, { message: a.message, status: a.status, code: a.code }), a;
93
+ return h == null || h.warn("[%s] fetch realtime position failed: %j", i.requestId, o, { message: a.message, status: a.status, code: a.code }), a;
94
94
  const e = a.data;
95
95
  for (const m in e)
96
96
  !isNaN(e[m]) && Number(e[m]) !== 1 / 0 && (e[m] = Number(e[m]));
97
- const d = b(`${e.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
97
+ const d = g(`${e.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
98
98
  return {
99
99
  mmsi: e.mmsi,
100
100
  name: e.vesselName,
@@ -121,17 +121,17 @@ class mt extends K {
121
121
  };
122
122
  }
123
123
  async trajectory(t, i, o, n, a = !0, e = {}) {
124
- (!this.token || b().diff(b(this.token.issuedAt), "seconds") > this.token.expiresIn - 300) && await this.authToken(e);
125
- const d = await this.realTimePosition(t, e), c = b(i), u = b(o), l = [];
126
- for (; u.diff(c, "day", !0) > 30; )
127
- await this.trajectoryIn30Day(t, c, c.clone().add(30, "day"), d, n, l, e), c.add(30, "day");
128
- return await this.trajectoryIn30Day(t, c, u, d, n, l, e), l;
124
+ (!this.token || g().diff(g(this.token.issuedAt), "seconds") > this.token.expiresIn - 300) && await this.authToken(e);
125
+ const d = await this.realTimePosition(t, e), r = g(i), c = g(o), u = [];
126
+ for (; c.diff(r, "day", !0) > 30; )
127
+ await this.trajectoryIn30Day(t, r, r.clone().add(30, "day"), d, n, u, e), r.add(30, "day");
128
+ return await this.trajectoryIn30Day(t, r, c, d, n, u, e), u;
129
129
  }
130
130
  async trajectoryIn30Day(t, i, o, n, a, e, d = {}) {
131
- var h, v, I, Y, p;
132
- const c = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", u = {
131
+ var f, v, I, Y, p;
132
+ const r = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", c = {
133
133
  headers: {
134
- Authorization: `${(h = this.token) == null ? void 0 : h.tokenType} ${(v = this.token) == null ? void 0 : v.accessToken}`
134
+ Authorization: `${(f = this.token) == null ? void 0 : f.tokenType} ${(v = this.token) == null ? void 0 : v.accessToken}`
135
135
  },
136
136
  json: {
137
137
  mmsi: t,
@@ -139,35 +139,35 @@ class mt extends K {
139
139
  endTime: o.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")
140
140
  }
141
141
  };
142
- f == null || f.info("[%s] fetch trajectory from: %s - %j", d.requestId, c, u);
143
- const l = await A.post(c, u).json();
144
- if (l.code)
145
- return f == null || f.warn("[%s] fetch trajectory failed: %j", d.requestId, c, { message: l.message, status: l.status, code: l.code }), l;
146
- let M = -1;
147
- const m = b(`${(Y = (I = l.data) == null ? void 0 : I[0]) == null ? void 0 : Y.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
148
- return (p = l.data) == null || p.forEach((r) => {
149
- for (const S in r)
150
- !isNaN(r[S]) && Number(r[S]) !== 1 / 0 && (r[S] = Number(r[S]));
151
- const y = b(`${r.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), k = r.eta ? b(`${r.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00") : void 0, g = r.status, { labelCn: j, labelEn: W } = this.parseStatus(g), F = {
152
- mmsi: r.mmsi,
142
+ h == null || h.info("[%s] fetch trajectory from: %s - %j", d.requestId, r, c);
143
+ const u = await A.post(r, c).json();
144
+ if (u.code)
145
+ return h == null || h.warn("[%s] fetch trajectory failed: %j", d.requestId, r, { message: u.message, status: u.status, code: u.code }), u;
146
+ let y = -1;
147
+ const m = g(`${(Y = (I = u.data) == null ? void 0 : I[0]) == null ? void 0 : Y.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
148
+ return (p = u.data) == null || p.forEach((l) => {
149
+ for (const T in l)
150
+ !isNaN(l[T]) && Number(l[T]) !== 1 / 0 && (l[T] = Number(l[T]));
151
+ const w = g(`${l.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), j = l.eta ? g(`${l.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00") : void 0, M = l.status, { labelCn: b, labelEn: N } = this.parseStatus(M), x = {
152
+ mmsi: l.mmsi,
153
153
  imo: n == null ? void 0 : n.imo,
154
- lat: r.lat,
155
- lng: r.lon,
156
- sog: r.sog,
157
- cog: r.cog,
158
- hdg: r.hdg,
159
- draught: r.draught,
160
- status: g,
161
- eta: k == null ? void 0 : k.unix(),
162
- destination: r.dest,
163
- positionTime: y.unix(),
164
- labelCn: j,
165
- labelEn: W,
154
+ lat: l.lat,
155
+ lng: l.lon,
156
+ sog: l.sog,
157
+ cog: l.cog,
158
+ hdg: l.hdg,
159
+ draught: l.draught,
160
+ status: M,
161
+ eta: j == null ? void 0 : j.unix(),
162
+ destination: l.dest,
163
+ positionTime: w.unix(),
164
+ labelCn: b,
165
+ labelEn: N,
166
166
  method: "trajectory",
167
167
  vendor: "myVessel",
168
- utc: y.utc().format()
169
- }, O = Math.floor(y.diff(m, "minute", !0) / (a || 1));
170
- O !== M && (M = O, e.push(F));
168
+ utc: w.utc().format()
169
+ }, W = Math.floor(w.diff(m, "minute", !0) / (a || 1));
170
+ W !== y && (y = W, e.push(x));
171
171
  }), e;
172
172
  }
173
173
  }
@@ -184,14 +184,14 @@ class pt extends K {
184
184
  usertoken: this.token
185
185
  }
186
186
  }, a = await A.post(o, n).json();
187
- f == null || f.info("[%s] fetch realtime position from: %s - %j", i.requestId, o, n);
187
+ h == null || h.info("[%s] fetch realtime position from: %s - %j", i.requestId, o, n);
188
188
  const e = a == null ? void 0 : a.list;
189
189
  if (!e)
190
- return f == null || f.warn("[%s] fetch realtime position failed: %j", i.requestId, o, a), a;
190
+ return h == null || h.warn("[%s] fetch realtime position failed: %j", i.requestId, o, a), a;
191
191
  for (const m in e)
192
192
  !isNaN(e[m]) && Number(e[m]) !== 1 / 0 && (e[m] = Number(e[m]));
193
193
  e.status = e.sp > 3 ? 0 : 1;
194
- const d = e.status, { labelCn: c, labelEn: u } = this.parseStatus(d), l = b(`${e.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
194
+ const d = e.status, { labelCn: r, labelEn: c } = this.parseStatus(d), u = g(`${e.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
195
195
  return {
196
196
  mmsi: e.m,
197
197
  name: e.n,
@@ -206,13 +206,13 @@ class pt extends K {
206
206
  cog: e.co,
207
207
  hdg: e.h,
208
208
  rot: isNaN(e.rot) ? 0 : e.rot,
209
- eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta) ? b(`${e.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00").unix() : void 0,
209
+ eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta) ? g(`${e.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00").unix() : void 0,
210
210
  destination: e.destination,
211
- positionTime: l.unix(),
212
- utc: l.utc().format(),
211
+ positionTime: u.unix(),
212
+ utc: u.utc().format(),
213
213
  status: d,
214
- labelCn: c,
215
- labelEn: u,
214
+ labelCn: r,
215
+ labelEn: c,
216
216
  method: "position",
217
217
  vendor: "hifleet"
218
218
  };
@@ -230,7 +230,7 @@ class pt extends K {
230
230
  }
231
231
  };
232
232
  let a = await A.post(o, n).json();
233
- f == null || f.info("[%s] fetch vessel props from: %s - %j", i.requestId, o, n), a instanceof Array && (a = a[0]);
233
+ h == null || h.info("[%s] fetch vessel props from: %s - %j", i.requestId, o, n), a instanceof Array && (a = a[0]);
234
234
  for (const d in a)
235
235
  !isNaN(a[d]) && Number(a[d]) !== 1 / 0 && (a[d] = Number(a[d]));
236
236
  const e = {
@@ -242,55 +242,55 @@ class pt extends K {
242
242
  breadth: a.b,
243
243
  draught: a.dr
244
244
  };
245
- return o = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", a = await A.post(o, n).json(), f == null || f.info("[%s] fetch vessel dead weight from: %s - %j", i.requestId, o, n), a instanceof Array && (a = a[0]), a && (e.deadweight = Number(a.dwt)), e;
245
+ return o = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", a = await A.post(o, n).json(), h == null || h.info("[%s] fetch vessel dead weight from: %s - %j", i.requestId, o, n), a instanceof Array && (a = a[0]), a && (e.deadweight = Number(a.dwt)), e;
246
246
  }
247
247
  async trajectory(t, i, o, n, a = !0, e = {}) {
248
- var r, y, k;
248
+ var l, w, j;
249
249
  const d = await this.realTimePosition(t, e);
250
- let c = b(i);
251
- const u = b(o), l = b();
250
+ let r = g(i);
251
+ const c = g(o), u = g();
252
252
  if (a) {
253
- let g = u.diff(c, "d", !0);
254
- g < 0 ? c = u.clone().subtract(40, "d") : g < 30 ? c.subtract(10, "d") : g < 60 ? c.subtract(5, "d") : c = u.clone().subtract(80, "d"), g = l.diff(u, "d", !0), u.add(g > 10 ? 240 : g * 24, "h");
253
+ let M = c.diff(r, "d", !0);
254
+ M < 0 ? r = c.clone().subtract(40, "d") : M < 30 ? r.subtract(10, "d") : M < 60 ? r.subtract(5, "d") : r = c.clone().subtract(80, "d"), M = u.diff(c, "d", !0), c.add(M > 10 ? 240 : M * 24, "h");
255
255
  }
256
- const M = {
256
+ const y = {
257
257
  searchParams: {
258
- endtime: u.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
259
- starttime: c.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
258
+ endtime: c.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
259
+ starttime: r.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
260
260
  mmsi: t,
261
261
  usertoken: this.token
262
262
  }
263
- }, m = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", h = await A.get(m, M).json();
264
- f == null || f.info("[%s] fetch trajectory from: %s - %j", e.requestId, m, M);
263
+ }, m = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", f = await A.get(m, y).json();
264
+ h == null || h.info("[%s] fetch trajectory from: %s - %j", e.requestId, m, y);
265
265
  let v;
266
- h && (v = ((y = (r = h.ships) == null ? void 0 : r.offors) == null ? void 0 : y.ship) || [], v.length || f == null || f.warn("[%s] fetch trajectory failed: %j", e.requestId, h));
266
+ f && (v = ((w = (l = f.ships) == null ? void 0 : l.offors) == null ? void 0 : w.ship) || [], v.length || h == null || h.warn("[%s] fetch trajectory failed: %j", e.requestId, f));
267
267
  const I = [];
268
268
  let Y = -1;
269
- const p = b(`${(k = v == null ? void 0 : v[0]) == null ? void 0 : k.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
270
- for (const g of v) {
271
- for (const D in g)
272
- !isNaN(g[D]) && Number(g[D]) !== 1 / 0 && (g[D] = Number(g[D]));
273
- const j = b(`${g.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
274
- g.status = g.sp > 4 ? 0 : 1;
275
- const { labelEn: W, labelCn: F } = this.parseStatus(g.status), O = {
276
- mmsi: g.m,
277
- name: g.n,
269
+ const p = g(`${(j = v == null ? void 0 : v[0]) == null ? void 0 : j.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
270
+ for (const M of v) {
271
+ for (const V in M)
272
+ !isNaN(M[V]) && Number(M[V]) !== 1 / 0 && (M[V] = Number(M[V]));
273
+ const b = g(`${M.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
274
+ M.status = M.sp > 4 ? 0 : 1;
275
+ const { labelEn: N, labelCn: x } = this.parseStatus(M.status), W = {
276
+ mmsi: M.m,
277
+ name: M.n,
278
278
  imo: d == null ? void 0 : d.imo,
279
- lat: g.la,
280
- lng: g.lo,
281
- draught: g.draught,
282
- sog: g.sp,
283
- cog: g.co,
284
- hdg: g.hdg,
285
- positionTime: j.unix(),
286
- utc: j.utc().format(),
287
- status: g.status,
288
- labelCn: F,
289
- labelEn: W,
279
+ lat: M.la,
280
+ lng: M.lo,
281
+ draught: M.draught,
282
+ sog: M.sp,
283
+ cog: M.co,
284
+ hdg: M.hdg,
285
+ positionTime: b.unix(),
286
+ utc: b.utc().format(),
287
+ status: M.status,
288
+ labelCn: x,
289
+ labelEn: N,
290
290
  method: "trajectory",
291
291
  vendor: "hifleet"
292
- }, S = Math.floor(j.diff(p, "minute", !0) / (n || 1));
293
- S !== Y && (Y = S, I.push(O));
292
+ }, T = Math.floor(b.diff(p, "minute", !0) / (n || 1));
293
+ T !== Y && (Y = T, I.push(W));
294
294
  }
295
295
  return I;
296
296
  }
@@ -309,12 +309,12 @@ class Mt extends K {
309
309
  enc: 1
310
310
  }
311
311
  }, n = "https://api.shipxy.com/apicall/GetSingleShip", a = await A.get(n, o).json();
312
- if (f == null || f.info("[%s] fetch realtime position from: %s - %j", i.requestId, n, o), (a == null ? void 0 : a.status) !== 0)
312
+ if (h == null || h.info("[%s] fetch realtime position from: %s - %j", i.requestId, n, o), (a == null ? void 0 : a.status) !== 0)
313
313
  return a;
314
314
  const e = a.data[0];
315
- for (const M in e)
316
- !isNaN(e[M]) && Number(e[M]) !== 1 / 0 && (e[M] = Number(e[M]));
317
- const { labelCn: d, labelEn: c } = await this.parseStatus(e.navistat), u = b.unix(e.lasttime);
315
+ for (const y in e)
316
+ !isNaN(e[y]) && Number(e[y]) !== 1 / 0 && (e[y] = Number(e[y]));
317
+ const { labelCn: d, labelEn: r } = await this.parseStatus(e.navistat), c = g.unix(e.lasttime);
318
318
  return {
319
319
  mmsi: e.ShipID,
320
320
  name: e.name,
@@ -330,9 +330,9 @@ class Mt extends K {
330
330
  hdg: Math.round(e.hdg / 100 * 100) / 100,
331
331
  rot: Math.round(e.rot / 100 * 100) / 100,
332
332
  positionTime: e.lasttime,
333
- utc: u.utc().format(),
333
+ utc: c.utc().format(),
334
334
  status: e.navistat,
335
- labelEn: c,
335
+ labelEn: r,
336
336
  labelCn: d,
337
337
  method: "position",
338
338
  vendor: "shipxy"
@@ -340,34 +340,34 @@ class Mt extends K {
340
340
  }
341
341
  async trajectory(t, i, o, n, a = !0, e = {}) {
342
342
  var p;
343
- const d = await this.realTimePosition(t, e), c = b(i), u = b(o), l = "https://api.shipxy.com/apicall/GetShipTrack", M = {
343
+ const d = await this.realTimePosition(t, e), r = g(i), c = g(o), u = "https://api.shipxy.com/apicall/GetShipTrack", y = {
344
344
  searchParams: {
345
345
  id: t,
346
346
  k: this.token,
347
347
  enc: 1,
348
348
  cut: 0,
349
- btm: c.unix(),
350
- etm: u.unix()
349
+ btm: r.unix(),
350
+ etm: c.unix()
351
351
  }
352
- }, m = await A.get(l, M).json();
353
- if (f == null || f.info("[%s] fetch trajectory from: %s - %j", e.requestId, l, M), (m == null ? void 0 : m.status) !== 0)
352
+ }, m = await A.get(u, y).json();
353
+ if (h == null || h.info("[%s] fetch trajectory from: %s - %j", e.requestId, u, y), (m == null ? void 0 : m.status) !== 0)
354
354
  return m;
355
- const h = m == null ? void 0 : m.points, v = [], I = b.unix((p = h[0]) == null ? void 0 : p.utc);
355
+ const f = m == null ? void 0 : m.points, v = [], I = g.unix((p = f[0]) == null ? void 0 : p.utc);
356
356
  let Y = -1;
357
- for (const r of h) {
358
- const y = b.unix(r.utc), k = {
357
+ for (const l of f) {
358
+ const w = g.unix(l.utc), j = {
359
359
  imo: d == null ? void 0 : d.imo,
360
360
  mmsi: t,
361
- sog: Math.round(r.sog * 3600 / 1e3 / 1852 * 100) / 100,
362
- cog: Math.round(r.cog / 100 * 100) / 100,
363
- lat: Math.round(r.lat / 1e6 * 1e5) / 1e5,
364
- lng: Math.round(r.lon / 1e6 * 1e5) / 1e5,
365
- positionTime: y.unix(),
366
- utc: y.utc().format(),
361
+ sog: Math.round(l.sog * 3600 / 1e3 / 1852 * 100) / 100,
362
+ cog: Math.round(l.cog / 100 * 100) / 100,
363
+ lat: Math.round(l.lat / 1e6 * 1e5) / 1e5,
364
+ lng: Math.round(l.lon / 1e6 * 1e5) / 1e5,
365
+ positionTime: w.unix(),
366
+ utc: w.utc().format(),
367
367
  method: "trajectory",
368
368
  vendor: "shipxy"
369
- }, g = Math.floor(y.diff(I, "minute", !0) / (n || 1));
370
- g !== Y && (Y = g, v.push(k));
369
+ }, M = Math.floor(w.diff(I, "minute", !0) / (n || 1));
370
+ M !== Y && (Y = M, v.push(j));
371
371
  }
372
372
  return v;
373
373
  }
@@ -387,7 +387,7 @@ class yt extends K {
387
387
  mmsiList: t
388
388
  }
389
389
  }, n = "https://api3.myships.com/sp/ships/getShipIdByMMSI", a = await A.post(n, o).json();
390
- return f == null || f.info("[%s] fetch ship id from: %s - %j", i.requestId, n, o), a.code !== "0" ? a : a.data[0].shipId;
390
+ return h == null || h.info("[%s] fetch ship id from: %s - %j", i.requestId, n, o), a.code !== "0" ? a : a.data[0].shipId;
391
391
  }
392
392
  async getShipInfo(t, i = {}) {
393
393
  const o = {
@@ -398,11 +398,11 @@ class yt extends K {
398
398
  shipId: t
399
399
  }
400
400
  }, n = "https://api3.myships.com/sp/ships/aissta", a = await A.post(n, o).json();
401
- if (f == null || f.info("[%s] fetch ship info from: %s - %j", i.requestId, n, o), a.code !== "0")
401
+ if (h == null || h.info("[%s] fetch ship info from: %s - %j", i.requestId, n, o), a.code !== "0")
402
402
  return a;
403
403
  const e = a.data;
404
404
  let d = e.imo;
405
- return t === "407170" && (d = "9198379", f == null || f.warn("[%s] ship(%s) imo error: %s, should be %s", i.requestId, t, e.imo, d)), {
405
+ return t === "407170" && (d = "9198379", h == null || h.warn("[%s] ship(%s) imo error: %s, should be %s", i.requestId, t, e.imo, d)), {
406
406
  mmsi: e.mmsi,
407
407
  name: e.shipnameEn,
408
408
  imo: d,
@@ -421,38 +421,38 @@ class yt extends K {
421
421
  shipId: o
422
422
  }
423
423
  }, e = "https://api3.myships.com/sp/ships/position/latest", d = await A.post(e, a).json();
424
- f == null || f.info("[%s] fetch realtime position from: %s - %j", i.requestId, e, a);
425
- const c = d.data[0];
426
- for (const h in c)
427
- !isNaN(c[h]) && Number(c[h]) !== 1 / 0 && (c[h] = Number(c[h]));
428
- const { labelCn: u, labelEn: l } = await this.parseStatus(c.aisNavStatus), M = b.unix(c.posTime);
424
+ h == null || h.info("[%s] fetch realtime position from: %s - %j", i.requestId, e, a);
425
+ const r = d.data[0];
426
+ for (const f in r)
427
+ !isNaN(r[f]) && Number(r[f]) !== 1 / 0 && (r[f] = Number(r[f]));
428
+ const { labelCn: c, labelEn: u } = await this.parseStatus(r.aisNavStatus), y = g.unix(r.posTime);
429
429
  return {
430
430
  ...n,
431
431
  mmsi: t,
432
- lat: Math.round(c.lat / 1e4 / 60 * 1e5) / 1e5,
433
- lng: Math.round(c.lon / 1e4 / 60 * 1e5) / 1e5,
434
- sog: Math.round(c.sog / 10 * 100) / 100,
435
- cog: Math.round(c.cog / 10 * 100) / 100,
436
- hdg: Math.round(c.heading * 100) / 100,
437
- rot: Math.round(c.rot * 100) / 100,
438
- positionTime: c.posTime,
439
- utc: M.utc().format(),
440
- status: c.aisNavStatus,
441
- labelEn: l,
442
- labelCn: u,
432
+ lat: Math.round(r.lat / 1e4 / 60 * 1e5) / 1e5,
433
+ lng: Math.round(r.lon / 1e4 / 60 * 1e5) / 1e5,
434
+ sog: Math.round(r.sog / 10 * 100) / 100,
435
+ cog: Math.round(r.cog / 10 * 100) / 100,
436
+ hdg: Math.round(r.heading * 100) / 100,
437
+ rot: Math.round(r.rot * 100) / 100,
438
+ positionTime: r.posTime,
439
+ utc: y.utc().format(),
440
+ status: r.aisNavStatus,
441
+ labelEn: u,
442
+ labelCn: c,
443
443
  method: "position",
444
444
  vendor: "myship"
445
445
  };
446
446
  }
447
447
  async trajectory(t, i, o, n, a = !0, e = {}) {
448
- const d = b(i), c = b(o), u = await this.getShipId(t), l = await this.getShipInfo(u), M = [];
449
- for (; c.diff(d, "day", !0) > 30; )
450
- await this.trajectoryIn30Day(u, d.unix(), d.add(30, "day").unix(), l, t, n, M);
451
- return await this.trajectoryIn30Day(u, d.unix(), c.unix(), l, t, n, M), M;
448
+ const d = g(i), r = g(o), c = await this.getShipId(t), u = await this.getShipInfo(c), y = [];
449
+ for (; r.diff(d, "day", !0) > 30; )
450
+ await this.trajectoryIn30Day(c, d.unix(), d.add(30, "day").unix(), u, t, n, y);
451
+ return await this.trajectoryIn30Day(c, d.unix(), r.unix(), u, t, n, y), y;
452
452
  }
453
- async trajectoryIn30Day(t, i, o, n, a, e, d, c = {}) {
453
+ async trajectoryIn30Day(t, i, o, n, a, e, d, r = {}) {
454
454
  var I;
455
- const u = {
455
+ const c = {
456
456
  headers: {
457
457
  appKey: this.token
458
458
  },
@@ -461,16 +461,16 @@ class yt extends K {
461
461
  startTime: i,
462
462
  endTime: o
463
463
  }
464
- }, l = "https://api3.myships.com/sp/ships/position/history", M = await A.post(l, u).json();
465
- if (f == null || f.info("[%s] fetch trajectory from: %s - %j", c.requestId, l, u), M.code !== "0")
466
- return f == null || f.warn("[%s] invoke myship trajectory failed: %j", c.requestId, M), M;
467
- const m = M.data;
464
+ }, u = "https://api3.myships.com/sp/ships/position/history", y = await A.post(u, c).json();
465
+ if (h == null || h.info("[%s] fetch trajectory from: %s - %j", r.requestId, u, c), y.code !== "0")
466
+ return h == null || h.warn("[%s] invoke myship trajectory failed: %j", r.requestId, y), y;
467
+ const m = y.data;
468
468
  for (const Y in m)
469
469
  !isNaN(m[Y]) && Number(m[Y]) !== 1 / 0 && (m[Y] = Number(m[Y]));
470
- const h = b.unix((I = m[0]) == null ? void 0 : I.posTime);
470
+ const f = g.unix((I = m[0]) == null ? void 0 : I.posTime);
471
471
  let v = -1;
472
472
  for (const Y of m) {
473
- const p = b.unix(Y.posTime), r = {
473
+ const p = g.unix(Y.posTime), l = {
474
474
  imo: n == null ? void 0 : n.imo,
475
475
  mmsi: a,
476
476
  lat: Math.round(Y.lat / 1e4 / 60 * 1e5) / 1e5,
@@ -483,8 +483,8 @@ class yt extends K {
483
483
  utc: p.utc().format(),
484
484
  method: "trajectory",
485
485
  vendor: "myship"
486
- }, y = Math.floor(p.diff(h, "minute", !0) / (e || 1));
487
- y !== v && (v = y, d.push(r));
486
+ }, w = Math.floor(p.diff(f, "minute", !0) / (e || 1));
487
+ w !== v && (v = w, d.push(l));
488
488
  }
489
489
  return d;
490
490
  }
@@ -495,7 +495,7 @@ try {
495
495
  } catch {
496
496
  } finally {
497
497
  }
498
- var at = /* @__PURE__ */ ((w) => (w.NOTICE = "NOTICE", w.WARN = "WARN", w.HEAVY = "HEAVY", w.SEVERE = "SEVERE", w.ERROR = "ERROR", w.FATAL = "FATAL", w))(at || {});
498
+ var at = /* @__PURE__ */ ((k) => (k.NOTICE = "NOTICE", k.WARN = "WARN", k.HEAVY = "HEAVY", k.SEVERE = "SEVERE", k.ERROR = "ERROR", k.FATAL = "FATAL", k))(at || {});
499
499
  class ot {
500
500
  /**
501
501
  * 解析告警规则, 多规则场景
@@ -506,20 +506,20 @@ class ot {
506
506
  * @param options
507
507
  */
508
508
  parsePrinciple(s, t = {}) {
509
- var e, d, c;
509
+ var e, d, r;
510
510
  R == null || R.info("[%s] parse rule: %s", t.requestId, s);
511
511
  const i = new RegExp("(?<=\\[)(.+)(?=])", "g"), o = s.match(i) ? (e = s.match(i)) == null ? void 0 : e[0] : void 0, n = o == null ? void 0 : o.split(";");
512
512
  if (!n)
513
513
  return;
514
514
  const a = {};
515
- for (let u = 0; u < (n == null ? void 0 : n.length); u++) {
516
- const l = (c = (d = n[u].match(i)) == null ? void 0 : d[0]) == null ? void 0 : c.split("],");
517
- if (u === 0 && !l)
515
+ for (let c = 0; c < (n == null ? void 0 : n.length); c++) {
516
+ const u = (r = (d = n[c].match(i)) == null ? void 0 : d[0]) == null ? void 0 : r.split("],");
517
+ if (c === 0 && !u)
518
518
  a.scope = n[0];
519
- else if (l)
520
- for (let M = 0, m = l.length; M < m; M++) {
521
- const h = this.parseRule(l[M]);
522
- h && (a[h.level] ? h.key ? a[h.level][h == null ? void 0 : h.key] = h : a[h.level] = h : h.key ? a[h.level] = { [h == null ? void 0 : h.key]: h } : a[h.level] = h);
519
+ else if (u)
520
+ for (let y = 0, m = u.length; y < m; y++) {
521
+ const f = this.parseRule(u[y]);
522
+ f && (a[f.level] ? f.key ? a[f.level][f == null ? void 0 : f.key] = f : a[f.level] = f : f.key ? a[f.level] = { [f == null ? void 0 : f.key]: f } : a[f.level] = f);
523
523
  }
524
524
  }
525
525
  return a;
@@ -550,25 +550,25 @@ class ot {
550
550
  * @param options
551
551
  */
552
552
  checkWeather(s, t, i = {}) {
553
- var h, v, I, Y, p, r, y, k, g, j, W, F, O, S, D;
553
+ var f, v, I, Y, p, l, w, j, M, b, N, x, W, T, V;
554
554
  let o = 0, n = 0, a = 0, e = 0;
555
- const d = Math.round(((v = (h = t == null ? void 0 : t.SEVERE) == null ? void 0 : h.sigWave) == null ? void 0 : v.number) * 1.6 * 100) / 100, c = (Y = (I = t == null ? void 0 : t.SEVERE) == null ? void 0 : I.sigWave) == null ? void 0 : Y.number, u = (r = (p = t == null ? void 0 : t.HEAVY) == null ? void 0 : p.sigWave) == null ? void 0 : r.number, l = Math.round((((k = (y = t == null ? void 0 : t.SEVERE) == null ? void 0 : y.wind) == null ? void 0 : k.number) + 2) * 100) / 100, M = (j = (g = t == null ? void 0 : t.SEVERE) == null ? void 0 : g.wind) == null ? void 0 : j.number, m = (F = (W = t == null ? void 0 : t.HEAVY) == null ? void 0 : W.wind) == null ? void 0 : F.number;
556
- for (let N = 0; N < (s == null ? void 0 : s.length); N++) {
557
- const T = s[N], P = (S = (O = T == null ? void 0 : T.meteo) == null ? void 0 : O.wave) == null ? void 0 : S.sig, C = (D = T == null ? void 0 : T.meteo) == null ? void 0 : D.wind, _ = N ? b(T.eta).diff(b(s[N - 1].eta), "hour", !0) : 0;
558
- e = _ > e ? _ : e, R == null || R.info("[%s] check sig.wave: %j", i.requestId, { ...P, dgThd4Wv: d, svThd4Wv: c, hvThd4Wv: u }), (P == null ? void 0 : P.height) >= d ? T.isDangerous = !0 : (P == null ? void 0 : P.height) >= c ? T.isSevere = !0 : (P == null ? void 0 : P.height) >= u && (T.isHeavy = !0), R == null || R.info("[%s] check wind: %j", i.requestId, { ...C, dgThd4Wd: l, svThd4Wd: M, hvThd4Wd: m }), (C == null ? void 0 : C.scale) >= l ? (T.isDangerous = !0, delete T.isSevere, delete T.isHeavy) : (C == null ? void 0 : C.scale) > M ? (T.isDangerous || (T.isSevere = !0), delete T.isHeavy) : (C == null ? void 0 : C.scale) === m && !T.isDangerous && !T.isSevere && (T.isHeavy = !0), o += T.isDangerous ? _ : 0, n += T.isSevere ? _ : 0, a += T.isHeavy ? _ : 0;
555
+ const d = Math.round(((v = (f = t == null ? void 0 : t.SEVERE) == null ? void 0 : f.sigWave) == null ? void 0 : v.number) * 1.6 * 100) / 100, r = (Y = (I = t == null ? void 0 : t.SEVERE) == null ? void 0 : I.sigWave) == null ? void 0 : Y.number, c = (l = (p = t == null ? void 0 : t.HEAVY) == null ? void 0 : p.sigWave) == null ? void 0 : l.number, u = Math.round((((j = (w = t == null ? void 0 : t.SEVERE) == null ? void 0 : w.wind) == null ? void 0 : j.number) + 2) * 100) / 100, y = (b = (M = t == null ? void 0 : t.SEVERE) == null ? void 0 : M.wind) == null ? void 0 : b.number, m = (x = (N = t == null ? void 0 : t.HEAVY) == null ? void 0 : N.wind) == null ? void 0 : x.number;
556
+ for (let O = 0; O < (s == null ? void 0 : s.length); O++) {
557
+ const D = s[O], q = (T = (W = D == null ? void 0 : D.meteo) == null ? void 0 : W.wave) == null ? void 0 : T.sig, S = (V = D == null ? void 0 : D.meteo) == null ? void 0 : V.wind, F = O ? g(D.eta).diff(g(s[O - 1].eta), "hour", !0) : 0;
558
+ e = F > e ? F : e, R == null || R.info("[%s] check sig.wave: %j", i.requestId, { ...q, dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: c }), (q == null ? void 0 : q.height) >= d ? D.isDangerous = !0 : (q == null ? void 0 : q.height) >= r ? D.isSevere = !0 : (q == null ? void 0 : q.height) >= c && (D.isHeavy = !0), R == null || R.info("[%s] check wind: %j", i.requestId, { ...S, dgThd4Wd: u, svThd4Wd: y, hvThd4Wd: m }), (S == null ? void 0 : S.scale) >= u ? (D.isDangerous = !0, delete D.isSevere, delete D.isHeavy) : (S == null ? void 0 : S.scale) > y ? (D.isDangerous || (D.isSevere = !0), delete D.isHeavy) : (S == null ? void 0 : S.scale) === m && !D.isDangerous && !D.isSevere && (D.isHeavy = !0), o += D.isDangerous ? F : 0, n += D.isSevere ? F : 0, a += D.isHeavy ? F : 0;
559
559
  }
560
- return o = Math.round(o * 100) / 100, n = Math.round(n * 100) / 100, a = Math.round(a * 100) / 100, e = Math.round(e), { sample: s, dangerous: o, severe: n, heavy: a, step: e < 3 ? 3 : e, wind: { dgThd4Wd: l, svThd4Wd: M, hvThd4Wd: m }, sig: { dgThd4Wv: d, svThd4Wv: c, hvThd4Wv: u } };
560
+ return o = Math.round(o * 100) / 100, n = Math.round(n * 100) / 100, a = Math.round(a * 100) / 100, e = Math.round(e), { sample: s, dangerous: o, severe: n, heavy: a, step: e < 3 ? 3 : e, wind: { dgThd4Wd: u, svThd4Wd: y, hvThd4Wd: m }, sig: { dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: c } };
561
561
  }
562
562
  }
563
- const gt = new ot();
563
+ const bt = new ot();
564
564
  let H;
565
565
  try {
566
566
  H = z.getLogger("vessel");
567
567
  } catch {
568
568
  } finally {
569
569
  }
570
- var nt = /* @__PURE__ */ ((w) => (w.common = "common", w.container = "container", w))(nt || {}), it = /* @__PURE__ */ ((w) => (w.Ballast = "Ballast", w.Laden = "Laden", w))(it || {}), rt = /* @__PURE__ */ ((w) => (w.Cp = "CP", w.Perf = "Basis", w.Instruct = "Other", w))(rt || {});
571
- class q {
570
+ var nt = /* @__PURE__ */ ((k) => (k.common = "common", k.container = "container", k))(nt || {}), it = /* @__PURE__ */ ((k) => (k.Ballast = "Ballast", k.Laden = "Laden", k))(it || {}), rt = /* @__PURE__ */ ((k) => (k.Cp = "CP", k.Perf = "Basis", k.Instruct = "Other", k))(rt || {});
571
+ class C {
572
572
  /**
573
573
  * @see https://baike.baidu.com/item/%E6%96%B9%E5%BD%A2%E7%B3%BB%E6%95%B0/4965568?fr=aladdin
574
574
  * 方形系数(block coefficient)
@@ -678,11 +678,11 @@ class q {
678
678
  * @private
679
679
  */
680
680
  static assembleProperties(s, t, i, o) {
681
- var u, l;
681
+ var c, u;
682
682
  const n = s.lbp ?? s.length ?? s.lengthOverall ?? 198.9642, a = s.draught ?? 8, e = s.breadthMoulded ?? s.breadth ?? s.breadthExtreme ?? 32.4572, d = s.deadweight ?? 67035.7773;
683
683
  return {
684
684
  // @ts-ignore
685
- tag: ((l = (u = s == null ? void 0 : s.type) == null ? void 0 : u.toLowerCase()) == null ? void 0 : l.indexOf("container")) > -1 ? "container" : "common",
685
+ tag: ((u = (c = s == null ? void 0 : s.type) == null ? void 0 : c.toLowerCase()) == null ? void 0 : u.indexOf("container")) > -1 ? "container" : "common",
686
686
  lbp: n,
687
687
  loadCondition: t,
688
688
  draught: a,
@@ -706,26 +706,26 @@ class q {
706
706
  * @param useRouteParam true 启用设置速度
707
707
  */
708
708
  static async speedLoseAt(s, t, i, o = "", n = 2, a = !0, e = !1, d = {}) {
709
- let c;
709
+ let r;
710
710
  if (t.velocity && e && (s.speed = B.roundPrecision(t.velocity * 1852 / 3600, 6)), a) {
711
- const u = await st.queryPointFactor(t.lng, t.lat, i.valueOf(), "wind,wave,current,watertemp", o, d), l = q.weatherFactor(s, u), M = q.currentFactor(s.bearing, u == null ? void 0 : u.current, n);
712
- c = {
713
- meteo: { ...u },
714
- wxFactor: l,
715
- cFactor: M,
716
- speed: t.velocity && e ? t.velocity : Math.round((s.speed * 1.943844 + l + M) * 100) / 100,
711
+ const c = await st.queryPointFactor(t.lng, t.lat, i.valueOf(), "wind,wave,current,watertemp", o, d), u = C.weatherFactor(s, c), y = C.currentFactor(s.bearing, c == null ? void 0 : c.current, n);
712
+ r = {
713
+ meteo: { ...c },
714
+ wxFactor: u,
715
+ cFactor: y,
716
+ speed: t.velocity && e ? t.velocity : Math.round((s.speed * 1.943844 + u + y) * 100) / 100,
717
717
  eta: i.utc().format("YYYY-MM-DDTHH:mm[Z]"),
718
718
  etd: i.utc().format("YYYY-MM-DDTHH:mm[Z]")
719
719
  };
720
720
  } else
721
- c = {
721
+ r = {
722
722
  wxFactor: 0,
723
723
  cFactor: 0,
724
724
  speed: t.velocity && e ? t.velocity : Math.round((s.speed * 1.943844 + 0 + 0) * 100) / 100,
725
725
  eta: i.utc().format("YYYY-MM-DDTHH:mm[Z]"),
726
726
  etd: i.utc().format("YYYY-MM-DDTHH:mm[Z]")
727
727
  };
728
- return delete t.meteo, delete t.wxFactor, delete t.cFactor, delete t.speed, delete t.etd, { ...c, ...t };
728
+ return delete t.meteo, delete t.wxFactor, delete t.cFactor, delete t.speed, delete t.etd, { ...r, ...t };
729
729
  }
730
730
  /**
731
731
  * 基于步长计算失速样本
@@ -740,52 +740,52 @@ class q {
740
740
  * @param useRouteParam true 启用航线上设置的参数 { suspend: 停留时长(小时), velocity: 速度(kts)}
741
741
  * @private
742
742
  */
743
- static async speedLoseInHoursStep(s, t, i, o, n, a, e = "", d = !0, c = !1, u = {}) {
743
+ static async speedLoseInHoursStep(s, t, i, o, n, a, e = "", d = !0, r = !1, c = {}) {
744
744
  t.utc();
745
- const l = [], M = [];
746
- let m = 0, h = 0, v, I;
745
+ const u = [], y = [];
746
+ let m = 0, f = 0, v, I;
747
747
  for (let Y = 0; Y < a.length - 1; Y++) {
748
748
  let p = a[Y];
749
- p.distanceFromStart = n + h;
750
- const r = a[Y + 1];
751
- if (s.bearing = L.calculateBearing(p, r, !r.gcToPrevious), p.bearing = s.bearing, p.suspend && c) {
749
+ p.distanceFromStart = n + f;
750
+ const l = a[Y + 1];
751
+ if (s.bearing = L.calculateBearing(p, l, !l.gcToPrevious), p.bearing = s.bearing, p.suspend && r) {
752
752
  p.eta = p.eta || t.format("YYYY-MM-DDTHH:mm[Z]"), p.elapsed = p.elapsed ?? 0;
753
- const g = p.suspend - p.elapsed;
754
- if (o - m > g)
755
- o = o - m - g, t.add(g, "hour"), p.elapsed = p.suspend;
753
+ const M = p.suspend - p.elapsed;
754
+ if (o - m > M)
755
+ o = o - m - M, t.add(M, "hour"), p.elapsed = p.suspend;
756
756
  else {
757
- const j = o - m;
758
- p.elapsed += j, t.add(j, "hour"), o = 0;
757
+ const b = o - m;
758
+ p.elapsed += b, t.add(b, "hour"), o = 0;
759
759
  }
760
- if (H == null || H.info(`[%s] suspend ${p.elapsed} hours at %j, and remain ${o} hours need to go...`, u.requestId, p), o === 0)
761
- return p.distanceFromPrevious = h, { etd: t, from: I || p, to: p, next: a.filter((j) => j), wps: l, days: M };
760
+ if (H == null || H.info(`[%s] suspend ${p.elapsed} hours at %j, and remain ${o} hours need to go...`, c.requestId, p), o === 0)
761
+ return p.distanceFromPrevious = f, { etd: t, from: I || p, to: p, next: a.filter((b) => b), wps: u, days: y };
762
762
  }
763
- p = await q.speedLoseAt(s, p, t, e, 0, d, c, u), I = I || p, p.important && l.push(p), t.isSameOrAfter(i) && (M.push(p), i.add(24, "hour"));
764
- const y = L.calculateDistance(p, r, !r.gcToPrevious);
765
- let k = Math.ceil(y / I.speed * 1e4) / 1e4;
766
- if (m + k < o) {
767
- if (m += k, t.add(k, "hour"), delete a[Y], H == null || H.info(
768
- `[%s] go to %j from %j with ${y}nm, and cost ${k} hours`,
769
- u.requestId,
770
- { lat: r.lat, lng: r.lng },
763
+ p = await C.speedLoseAt(s, p, t, e, 0, d, r, c), I = I || p, p.important && u.push(p), t.isSameOrAfter(i) && (y.push(p), i.add(24, "hour"));
764
+ const w = L.calculateDistance(p, l, !l.gcToPrevious);
765
+ let j = Math.ceil(w / I.speed * 1e4) / 1e4;
766
+ if (m + j < o) {
767
+ if (m += j, t.add(j, "hour"), delete a[Y], H == null || H.info(
768
+ `[%s] go to %j from %j with ${w}nm, and cost ${j} hours`,
769
+ c.requestId,
770
+ { lat: l.lat, lng: l.lng },
771
771
  { lat: I.lat, lng: I.lng, etd: I.etd }
772
- ), h += y, a.filter((g) => g).length <= 1) {
773
- v = r, v.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), v.distanceFromPrevious = y, v.distanceFromStart = n + h, l.push(v), delete a[Y + 1];
772
+ ), f += w, a.filter((M) => M).length <= 1) {
773
+ v = l, v.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), v.distanceFromPrevious = w, v.distanceFromStart = n + f, u.push(v), delete a[Y + 1];
774
774
  break;
775
775
  }
776
776
  } else {
777
- k = o - m, t.add(k, "hour");
778
- const g = B.roundPrecision(I.speed * k, 4);
779
- v = L.calculateCoordinate(p, s.bearing, g, "nauticalmiles", !r.gcToPrevious), v.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), a[Y] = v, H == null || H.info(
780
- `[%s] go to %j from %j with ${g}nm, and cost ${k} hours`,
781
- u.requestId,
777
+ j = o - m, t.add(j, "hour");
778
+ const M = B.roundPrecision(I.speed * j, 4);
779
+ v = L.calculateCoordinate(p, s.bearing, M, "nauticalmiles", !l.gcToPrevious), v.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), a[Y] = v, H == null || H.info(
780
+ `[%s] go to %j from %j with ${M}nm, and cost ${j} hours`,
781
+ c.requestId,
782
782
  { lat: v.lat, lng: v.lng },
783
783
  { lat: p.lat, lng: p.lng, etd: p.etd }
784
- ), h += g, v.distanceFromPrevious = h, v.distanceFromStart = n + h;
784
+ ), f += M, v.distanceFromPrevious = f, v.distanceFromStart = n + f;
785
785
  break;
786
786
  }
787
787
  }
788
- return { etd: t, from: I, to: v, next: a.filter((Y) => Y), wps: l, days: M };
788
+ return { etd: t, from: I, to: v, next: a.filter((Y) => Y), wps: u, days: y };
789
789
  }
790
790
  /**
791
791
  * 洋流影响因子
@@ -806,16 +806,16 @@ class q {
806
806
  * @param wwc 气象要素
807
807
  */
808
808
  static weatherFactor(s, t) {
809
- var l, M, m, h, v;
809
+ var u, y, m, f, v;
810
810
  H == null || H.debug("calculate weather factor via: %j", { ...s, ...t });
811
- const i = q.blockCoefficient(s.displacement, s.lbp, s.breadthMoulded, s.draught), o = q.froudeNumber(s.speed, s.lbp), n = q.amendFactor(i, o, s.loadCondition);
812
- let a = Math.abs(s.bearing % 360 - (((l = t == null ? void 0 : t.wind) == null ? void 0 : l.degree) % 360 || 0));
811
+ const i = C.blockCoefficient(s.displacement, s.lbp, s.breadthMoulded, s.draught), o = C.froudeNumber(s.speed, s.lbp), n = C.amendFactor(i, o, s.loadCondition);
812
+ let a = Math.abs(s.bearing % 360 - (((u = t == null ? void 0 : t.wind) == null ? void 0 : u.degree) % 360 || 0));
813
813
  a = a > 180 ? 360 - a : a;
814
- const e = q.directionFactor(a, (M = t == null ? void 0 : t.wind) == null ? void 0 : M.scale), d = q.vesselTagFactor(s.displacement, s.loadCondition, s.tag, (m = t == null ? void 0 : t.wind) == null ? void 0 : m.scale);
815
- let c = e * n * d / 100 * s.speed;
816
- c = Math.round(c * 1.943844 * 1e4) / 1e4 * -1;
817
- const u = q.waveHeightFactor(((v = (h = t == null ? void 0 : t.wave) == null ? void 0 : h.sig) == null ? void 0 : v.height) ?? 1);
818
- return c = c * 0.24 + u * 0.76, H == null || H.debug("weather factor = %s", c), Math.round(c * 100) / 100;
814
+ const e = C.directionFactor(a, (y = t == null ? void 0 : t.wind) == null ? void 0 : y.scale), d = C.vesselTagFactor(s.displacement, s.loadCondition, s.tag, (m = t == null ? void 0 : t.wind) == null ? void 0 : m.scale);
815
+ let r = e * n * d / 100 * s.speed;
816
+ r = Math.round(r * 1.943844 * 1e4) / 1e4 * -1;
817
+ const c = C.waveHeightFactor(((v = (f = t == null ? void 0 : t.wave) == null ? void 0 : f.sig) == null ? void 0 : v.height) ?? 1);
818
+ return r = r * 0.24 + c * 0.76, H == null || H.debug("weather factor = %s", r), Math.round(r * 100) / 100;
819
819
  }
820
820
  /**
821
821
  * 全程失速分析(走完航程)
@@ -829,12 +829,12 @@ class q {
829
829
  * @param useMeteo true 启用气象分析
830
830
  * @param useRouteParam
831
831
  */
832
- static async analyseInstant(s, t, i, o, n, a = "", e = 0, d = !0, c = !1, u = {}) {
833
- var _, G, U, J, Q;
834
- const l = b().valueOf();
832
+ static async analyseInstant(s, t, i, o, n, a = "", e = 0, d = !0, r = !1, c = {}) {
833
+ var F, G, U, J, Q;
834
+ const u = g().valueOf();
835
835
  s.lng = B.convertToStdLng(s.lng);
836
- const { route: M, waypoints: m } = n.points, h = L.calculateSubRoute(s, M);
837
- if (((_ = h[0]) == null ? void 0 : _.length) <= 1)
836
+ const { route: y, waypoints: m } = n.points, f = L.calculateSubRoute(s, y);
837
+ if (((F = f[0]) == null ? void 0 : F.length) <= 1)
838
838
  return;
839
839
  const { v0: v, label: I } = s.sog ? {
840
840
  v0: s.sog,
@@ -844,51 +844,51 @@ class q {
844
844
  v0: o.speed,
845
845
  label: "CP"
846
846
  /* Cp */
847
- }, Y = q.assembleProperties(i, o.loadCondition, v, 0), p = m.length ? L.calculateSubWaypoints(s, m) : [], r = {
847
+ }, Y = C.assembleProperties(i, o.loadCondition, v, 0), p = m.length ? L.calculateSubWaypoints(s, m) : [], l = {
848
848
  from: { ...s },
849
- route: h,
849
+ route: f,
850
850
  waypoints: p,
851
851
  v0: v,
852
852
  label: I
853
- }, y = {
853
+ }, w = {
854
854
  hours: [],
855
855
  days: [],
856
856
  wps: []
857
857
  };
858
- e || (L.calculateRouteDistance(h) / o.speed <= 72 ? e = 3 : e = 6);
859
- let k = L.simplifyRouteToCoordinates(h, p, 0), g = 0, j = 0, W = 0, F = 0;
860
- t = b(t).utc();
861
- const O = t.clone();
862
- for (; k.length > 0; ) {
863
- const E = e - t.hour() % e, V = Math.ceil(t.clone().add(E, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4, x = await q.speedLoseInHoursStep(
858
+ e || (L.calculateRouteDistance(f) / o.speed <= 72 ? e = 3 : e = 6);
859
+ let j = L.simplifyRouteToCoordinates(f, p, 0), M = 0, b = 0, N = 0, x = 0;
860
+ t = g(t).utc();
861
+ const W = t.clone();
862
+ for (; j.length > 0; ) {
863
+ const P = e - t.hour() % e, _ = Math.ceil(t.clone().add(P, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4, E = await C.speedLoseInHoursStep(
864
864
  Y,
865
865
  t,
866
- O,
867
- V,
868
- g,
869
- k,
866
+ W,
867
+ _,
868
+ M,
869
+ j,
870
870
  a,
871
871
  d,
872
- c,
873
- u
872
+ r,
873
+ c
874
874
  );
875
- (G = x.from) != null && G.speed && (y.hours.push(x.from), y.wps.push(...x.wps), y.days.push(...x.days)), k = x == null ? void 0 : x.next, k.length || y.hours.push(x == null ? void 0 : x.to), g += ((U = x == null ? void 0 : x.to) == null ? void 0 : U.distanceFromPrevious) ?? 0;
875
+ (G = E.from) != null && G.speed && (w.hours.push(E.from), w.wps.push(...E.wps), w.days.push(...E.days)), j = E == null ? void 0 : E.next, j.length || w.hours.push(E == null ? void 0 : E.to), M += ((U = E == null ? void 0 : E.to) == null ? void 0 : U.distanceFromPrevious) ?? 0;
876
876
  }
877
- const S = y.hours;
878
- for (let E = 0; E < S.length - 1; E++) {
879
- const V = b(S[E + 1].eta).diff(S[E].etd, "hour", !0) || 1;
880
- j += S[E].wxFactor || 0 * V, W += S[E].cFactor || 0 * V, F += V;
877
+ const T = w.hours;
878
+ for (let P = 0; P < T.length - 1; P++) {
879
+ const _ = g(T[P + 1].eta).diff(T[P].etd, "hour", !0) || 1;
880
+ b += T[P].wxFactor || 0 * _, N += T[P].cFactor || 0 * _, x += _;
881
881
  }
882
- (J = y.wps) == null || J.forEach((E, V) => {
883
- if (V) {
884
- const x = y.wps[V - 1], $ = E.distanceFromStart - x.distanceFromStart, X = b(E.eta).diff(b(x.etd), "h", !0);
885
- X < 1 ? E.avgSpd = x.speed : E.avgSpd = Math.round($ / X * 100) / 100;
882
+ (J = w.wps) == null || J.forEach((P, _) => {
883
+ if (_) {
884
+ const E = w.wps[_ - 1], $ = P.distanceFromStart - E.distanceFromStart, X = g(P.eta).diff(g(E.etd), "h", !0);
885
+ X < 1 ? P.avgSpd = E.speed : P.avgSpd = Math.round($ / X * 100) / 100;
886
886
  }
887
- }), r.sample = y;
888
- const D = y.hours.at(0), N = y.hours.at(-1);
889
- r.distance = Math.round(N.distanceFromStart * 1e4) / 1e4, r.etd = b(D.eta).utc().format(), r.eta = b(N.eta).utc().format(), r.wxFactor = Math.round(j / F * 1e4) / 1e4, r.cFactor = Math.round(W / F * 1e4) / 1e4, r.avgSpeed = Math.round(N.distanceFromStart / F * 1e4) / 1e4, r.totalHrs = Math.round(F * 1e4) / 1e4, r.totalFoCons = Math.round((o == null ? void 0 : o.fo) / 24 * r.totalHrs * 1e3) / 1e3, r.totalDgoCons = Math.round((o == null ? void 0 : o.dgo) / 24 * r.totalHrs * 1e3) / 1e3;
890
- const P = b().valueOf() - l, C = ((Q = y == null ? void 0 : y.hours) == null ? void 0 : Q.length) || 1;
891
- return H == null || H.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", u == null ? void 0 : u.requestId, P, C, Math.round(P / C * 1e3) / 1e3), r;
887
+ }), l.sample = w;
888
+ const V = w.hours.at(0), O = w.hours.at(-1);
889
+ l.distance = Math.round(O.distanceFromStart * 1e4) / 1e4, l.etd = g(V.eta).utc().format(), l.eta = g(O.eta).utc().format(), l.wxFactor = Math.round(b / x * 1e4) / 1e4, l.cFactor = Math.round(N / x * 1e4) / 1e4, l.avgSpeed = Math.round(O.distanceFromStart / x * 1e4) / 1e4, l.totalHrs = Math.round(x * 1e4) / 1e4, l.totalFoCons = Math.round((o == null ? void 0 : o.fo) / 24 * l.totalHrs * 1e3) / 1e3, l.totalDgoCons = Math.round((o == null ? void 0 : o.dgo) / 24 * l.totalHrs * 1e3) / 1e3;
890
+ const q = g().valueOf() - u, S = ((Q = w == null ? void 0 : w.hours) == null ? void 0 : Q.length) || 1;
891
+ return H == null || H.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", c == null ? void 0 : c.requestId, q, S, Math.round(q / S * 1e3) / 1e3), l;
892
892
  }
893
893
  /**
894
894
  * 分段失速分析(最多走hours 小时)
@@ -903,59 +903,71 @@ class q {
903
903
  * @param useMeteo true 启用气象分析
904
904
  * @param useRouteParam
905
905
  */
906
- static async analyseInstantWithThreshed(s, t, i, o, n, a, e = "", d = 3, c = !0, u = !1, l = {}) {
907
- var F, O, S;
906
+ static async analyseInstantWithThreshed(s, t, i, o, n, a, e, d = "", r = 3, c = !0, u = !1, y = {}) {
907
+ var O, D, q;
908
908
  s.lng = B.convertToStdLng(s.lng);
909
- const M = q.assembleProperties(o, n.loadCondition, n.speed, 0), m = L.calculateSubRoute(s, a);
910
- if (((F = m[0]) == null ? void 0 : F.length) <= 1)
909
+ const { v0: m, label: f } = s.sog ? {
910
+ v0: s.sog,
911
+ label: "Other"
912
+ /* Instruct */
913
+ } : {
914
+ v0: n.speed,
915
+ label: "CP"
916
+ /* Cp */
917
+ }, v = C.assembleProperties(o, n.loadCondition, m, 0), I = L.calculateSubRoute(s, a);
918
+ if (((O = I[0]) == null ? void 0 : O.length) <= 1)
911
919
  return;
912
- let h = L.simplifyRouteToCoordinates(m, [], 0);
913
- h.forEach((D) => D.important = !0);
914
- let v = 0, I = 0, Y = 0, p = 0, r;
915
- const y = {
920
+ const Y = e.length ? L.calculateSubWaypoints(s, e) : [];
921
+ Y.forEach((S) => S.important = !0);
922
+ let p = L.simplifyRouteToCoordinates(I, Y, 0), l = 0, w = 0, j = 0, M = 0, b;
923
+ const N = {
916
924
  hours: [],
917
925
  wps: [],
918
926
  days: []
919
927
  };
920
- for (t = b(t).utc(); h.length > 0; ) {
921
- const D = d - t.hour() % d;
922
- let N = Math.ceil(t.clone().add(D, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4;
923
- if (N = t.clone().add(N, "h").isAfter(i) ? i.diff(t, "h", !0) * 1e4 / 1e4 : N, N)
924
- r = await q.speedLoseInHoursStep(
925
- M,
928
+ for (t = g(t).utc(); p.length > 0; ) {
929
+ const S = r - t.hour() % r;
930
+ let F = Math.ceil(t.clone().add(S, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4;
931
+ if (F = t.clone().add(F, "h").isAfter(i) ? i.diff(t, "h", !0) * 1e4 / 1e4 : F, F)
932
+ b = await C.speedLoseInHoursStep(
933
+ v,
926
934
  t,
927
935
  i.clone(),
928
- N,
929
- v,
930
- h,
931
- e,
936
+ F,
937
+ l,
938
+ p,
939
+ d,
932
940
  c,
933
941
  u,
934
- l
935
- ), (O = r.from) != null && O.speed && (y.hours.push(r.from), r != null && r.wps && y.wps.push(...r.wps), y.days.push(...r.days)), h = r == null ? void 0 : r.next, h.length || (y.hours.push(r == null ? void 0 : r.to), r != null && r.wps && y.wps.push(...r.wps), y.days.push(r == null ? void 0 : r.to)), v += ((S = r == null ? void 0 : r.to) == null ? void 0 : S.distanceFromPrevious) ?? 0;
942
+ y
943
+ ), (D = b.from) != null && D.speed && (N.hours.push(b.from), b != null && b.wps && N.wps.push(...b.wps), N.days.push(...b.days)), p = b == null ? void 0 : b.next, p.length || (N.hours.push(b == null ? void 0 : b.to), b != null && b.wps && N.wps.push(...b.wps), N.days.push(b == null ? void 0 : b.to)), l += ((q = b == null ? void 0 : b.to) == null ? void 0 : q.distanceFromPrevious) ?? 0;
936
944
  else {
937
- r && (y.hours.push(r.to), r != null && r.wps && y.wps.push(...r.wps), y.days.push(r.to));
945
+ b && (N.hours.push(b.to), b != null && b.wps && N.wps.push(...b.wps), N.days.push(b.to));
938
946
  break;
939
947
  }
940
948
  }
941
- const k = y.hours;
942
- for (let D = 0; D < k.length - 1; D++) {
943
- const N = b(k[D + 1].eta).diff(k[D].etd, "hour", !0);
944
- I += k[D].wxFactor * N, Y += k[D].cFactor * N, p += N;
949
+ const x = N.hours;
950
+ for (let S = 0; S < x.length - 1; S++) {
951
+ const F = g(x[S + 1].eta).diff(x[S].etd, "hour", !0);
952
+ w += x[S].wxFactor * F, j += x[S].cFactor * F, M += F;
945
953
  }
946
- const g = y.hours.at(0), j = y.hours.at(-1);
954
+ const W = N.hours.at(0), T = N.hours.at(-1);
947
955
  return {
948
- sample: y,
949
- distance: Math.round(((j == null ? void 0 : j.distanceFromStart) || 0) * 1e4) / 1e4,
956
+ sample: N,
957
+ distance: Math.round(((T == null ? void 0 : T.distanceFromStart) || 0) * 1e4) / 1e4,
950
958
  // 注意,可能会在first节点Drift,所有采用eta做为初始出发时间
951
- etd: b(g.eta).utc().format(),
952
- eta: b(j == null ? void 0 : j.eta).utc().format(),
953
- wxFactor: Math.round(I / p * 1e4) / 1e4,
954
- cFactor: Math.round(Y / p * 1e4) / 1e4,
955
- avgSpeed: Math.round(((j == null ? void 0 : j.distanceFromStart) || 0) / p * 1e4) / 1e4,
956
- totalHrs: Math.round(p * 1e4) / 1e4,
957
- to: j,
958
- route: L.generateRouteAccordingToWaypoints(h)
959
+ etd: g(W.eta).utc().format(),
960
+ eta: g(T == null ? void 0 : T.eta).utc().format(),
961
+ wxFactor: Math.round(w / M * 1e4) / 1e4,
962
+ cFactor: Math.round(j / M * 1e4) / 1e4,
963
+ avgSpeed: Math.round(((T == null ? void 0 : T.distanceFromStart) || 0) / M * 1e4) / 1e4,
964
+ totalHrs: Math.round(M * 1e4) / 1e4,
965
+ from: s,
966
+ to: T,
967
+ route: L.generateRouteAccordingToWaypoints(p),
968
+ subWaypoints: Y,
969
+ v0: m,
970
+ label: f
959
971
  };
960
972
  }
961
973
  }
@@ -968,8 +980,8 @@ export {
968
980
  yt as MyShipImpl,
969
981
  mt as MyVesselImpl,
970
982
  Mt as ShipxyImpl,
971
- q as SpeedHelper,
983
+ C as SpeedHelper,
972
984
  rt as SpeedLabel,
973
985
  nt as VesselTag,
974
- gt as alertHelper
986
+ bt as alertHelper
975
987
  };
@@ -1 +1 @@
1
- (function(j,T){typeof exports=="object"&&typeof module<"u"?T(exports,require("got"),require("@log4js-node/log4js-api"),require("moment"),require("@idm-plugin/geo"),require("@idm-plugin/meteo")):typeof define=="function"&&define.amd?define(["exports","got","@log4js-node/log4js-api","moment","@idm-plugin/geo","@idm-plugin/meteo"],T):(j=typeof globalThis<"u"?globalThis:j||self,T(j["idm-plugin-rabbitmq"]={},j.got,j["@log4js-node/log4js-api"],j.moment,j["@idm-plugin/geo"],j["@idm-plugin/meteo"]))})(this,function(j,T,_,v,P,nt){"use strict";var ht=Object.defineProperty;var lt=(j,T,_)=>T in j?ht(j,T,{enumerable:!0,configurable:!0,writable:!0,value:_}):j[T]=_;var K=(j,T,_)=>(lt(j,typeof T!="symbol"?T+"":T,_),_);let l;try{l=_.getLogger("vessel")}catch{}finally{}class z{parseStatus(a){let t,i;switch(a){case 0:t="在航(主机推动)",i="The engine is in use";break;case 1:t="锚泊",i="Anchored";break;case 2:t="失控",i="Not operated";break;case 3:t="操纵受限",i="Limited airworthiness";break;case 4:t="吃水受限",i="Limited by ship's draft";break;case 5:t="靠泊",i="Mooring";break;case 6:t="搁浅",i="Stranded";break;case 7:t="捕捞作业",i="Engaged in fishing";break;case 8:t="靠帆船提供动力",i="Sailing";break;default:t="未定义",i="Undefined"}return{labelCn:t,labelEn:i}}}class ot extends z{constructor(t,i){super();K(this,"clientId");K(this,"clientSecret");K(this,"token");this.clientId=t,this.clientSecret=i}async authToken(t={}){const i="https://svc.data.myvessel.cn/ada/oauth/token",n={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},o=await T.post(i,n).json();l==null||l.info("[%s] fetch access token from: %s - %j",t.requestId,i,o),o.error||(this.token={accessToken:o.access_token,tokenType:o.token_type,expiresIn:o.expires_in,scope:o.scope,jti:o.jti,issuedAt:v().utc().format()})}async realTimePosition(t,i={}){var u,f,y;(!this.token||v().diff(v(this.token.issuedAt),"seconds")>((u=this.token)==null?void 0:u.expiresIn)-300)&&await this.authToken(i);const n="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",o={headers:{Authorization:`${(f=this.token)==null?void 0:f.tokenType} ${(y=this.token)==null?void 0:y.accessToken}`},searchParams:{mmsi:t}};l==null||l.info("[%s] fetch realtime position from: %s - %j",i.requestId,n,o);const s=await T.get(n,o).json();if(s.code)return l==null||l.warn("[%s] fetch realtime position failed: %j",i.requestId,n,{message:s.message,status:s.status,code:s.code}),s;const e=s.data;for(const m in e)!isNaN(e[m])&&Number(e[m])!==1/0&&(e[m]=Number(e[m]));const d=v(`${e.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:e.mmsi,name:e.vesselName,imo:e.imo,callSign:e.callsign,lat:e.lat,lng:e.lon,length:e.length,width:e.width,draught:e.currDraught,sog:e.sog,cog:e.cog,hdg:e.hdg,rot:e.rot,eta:e.eta,destination:e.dest,positionTime:d.unix(),status:e.status,labelCn:e.statusNameCn,labelEn:e.statusNameEn,method:"position",vendor:"myVessel",utc:d.utc().format()}}async trajectory(t,i,n,o,s=!0,e={}){(!this.token||v().diff(v(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(e);const d=await this.realTimePosition(t,e),c=v(i),u=v(n),f=[];for(;u.diff(c,"day",!0)>30;)await this.trajectoryIn30Day(t,c,c.clone().add(30,"day"),d,o,f,e),c.add(30,"day");return await this.trajectoryIn30Day(t,c,u,d,o,f,e),f}async trajectoryIn30Day(t,i,n,o,s,e,d={}){var h,g,k,Y,p;const c="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",u={headers:{Authorization:`${(h=this.token)==null?void 0:h.tokenType} ${(g=this.token)==null?void 0:g.accessToken}`},json:{mmsi:t,startTime:i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};l==null||l.info("[%s] fetch trajectory from: %s - %j",d.requestId,c,u);const f=await T.post(c,u).json();if(f.code)return l==null||l.warn("[%s] fetch trajectory failed: %j",d.requestId,c,{message:f.message,status:f.status,code:f.code}),f;let y=-1;const m=v(`${(Y=(k=f.data)==null?void 0:k[0])==null?void 0:Y.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(p=f.data)==null||p.forEach(r=>{for(const F in r)!isNaN(r[F])&&Number(r[F])!==1/0&&(r[F]=Number(r[F]));const M=v(`${r.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),I=r.eta?v(`${r.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,b=r.status,{labelCn:H,labelEn:V}=this.parseStatus(b),L={mmsi:r.mmsi,imo:o==null?void 0:o.imo,lat:r.lat,lng:r.lon,sog:r.sog,cog:r.cog,hdg:r.hdg,draught:r.draught,status:b,eta:I==null?void 0:I.unix(),destination:r.dest,positionTime:M.unix(),labelCn:H,labelEn:V,method:"trajectory",vendor:"myVessel",utc:M.utc().format()},W=Math.floor(M.diff(m,"minute",!0)/(s||1));W!==y&&(y=W,e.push(L))}),e}}class it extends z{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,i={}){const n="https://api.hifleet.com/position/position/get/token",o={searchParams:{mmsi:t,usertoken:this.token}},s=await T.post(n,o).json();l==null||l.info("[%s] fetch realtime position from: %s - %j",i.requestId,n,o);const e=s==null?void 0:s.list;if(!e)return l==null||l.warn("[%s] fetch realtime position failed: %j",i.requestId,n,s),s;for(const m in e)!isNaN(e[m])&&Number(e[m])!==1/0&&(e[m]=Number(e[m]));e.status=e.sp>3?0:1;const d=e.status,{labelCn:c,labelEn:u}=this.parseStatus(d),f=v(`${e.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:e.m,name:e.n,imo:e.imonumber,callSign:e.callsign,lat:Math.round(e.la/60*1e5)/1e5,lng:Math.round(e.lo/60*1e5)/1e5,length:e.l,width:e.w,draught:e.draught,sog:e.sp,cog:e.co,hdg:e.h,rot:isNaN(e.rot)?0:e.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta)?v(`${e.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").unix():void 0,destination:e.destination,positionTime:f.unix(),utc:f.utc().format(),status:d,labelCn:c,labelEn:u,method:"position",vendor:"hifleet"}}async search(t,i={}){let n="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const o={searchParams:{keyword:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let s=await T.post(n,o).json();l==null||l.info("[%s] fetch vessel props from: %s - %j",i.requestId,n,o),s instanceof Array&&(s=s[0]);for(const d in s)!isNaN(s[d])&&Number(s[d])!==1/0&&(s[d]=Number(s[d]));const e={mmsi:s.m,name:s.n,imo:s.i,callSign:s.c,length:s.l,breadth:s.b,draught:s.dr};return n="https://www.hifleet.com/hifleetapi/sameShipSearch.do",s=await T.post(n,o).json(),l==null||l.info("[%s] fetch vessel dead weight from: %s - %j",i.requestId,n,o),s instanceof Array&&(s=s[0]),s&&(e.deadweight=Number(s.dwt)),e}async trajectory(t,i,n,o,s=!0,e={}){var r,M,I;const d=await this.realTimePosition(t,e);let c=v(i);const u=v(n),f=v();if(s){let b=u.diff(c,"d",!0);b<0?c=u.clone().subtract(40,"d"):b<30?c.subtract(10,"d"):b<60?c.subtract(5,"d"):c=u.clone().subtract(80,"d"),b=f.diff(u,"d",!0),u.add(b>10?240:b*24,"h")}const y={searchParams:{endtime:u.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),starttime:c.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),mmsi:t,usertoken:this.token}},m="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",h=await T.get(m,y).json();l==null||l.info("[%s] fetch trajectory from: %s - %j",e.requestId,m,y);let g;h&&(g=((M=(r=h.ships)==null?void 0:r.offors)==null?void 0:M.ship)||[],g.length||l==null||l.warn("[%s] fetch trajectory failed: %j",e.requestId,h));const k=[];let Y=-1;const p=v(`${(I=g==null?void 0:g[0])==null?void 0:I.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const b of g){for(const D in b)!isNaN(b[D])&&Number(b[D])!==1/0&&(b[D]=Number(b[D]));const H=v(`${b.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");b.status=b.sp>4?0:1;const{labelEn:V,labelCn:L}=this.parseStatus(b.status),W={mmsi:b.m,name:b.n,imo:d==null?void 0:d.imo,lat:b.la,lng:b.lo,draught:b.draught,sog:b.sp,cog:b.co,hdg:b.hdg,positionTime:H.unix(),utc:H.utc().format(),status:b.status,labelCn:L,labelEn:V,method:"trajectory",vendor:"hifleet"},F=Math.floor(H.diff(p,"minute",!0)/(o||1));F!==Y&&(Y=F,k.push(W))}return k}}class rt extends z{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,i={}){const n={searchParams:{id:t,k:this.token,enc:1}},o="https://api.shipxy.com/apicall/GetSingleShip",s=await T.get(o,n).json();if(l==null||l.info("[%s] fetch realtime position from: %s - %j",i.requestId,o,n),(s==null?void 0:s.status)!==0)return s;const e=s.data[0];for(const y in e)!isNaN(e[y])&&Number(e[y])!==1/0&&(e[y]=Number(e[y]));const{labelCn:d,labelEn:c}=await this.parseStatus(e.navistat),u=v.unix(e.lasttime);return{mmsi:e.ShipID,name:e.name,imo:e.imo,callSign:e.callsign,lat:Math.round(e.lat/1e6*1e5)/1e5,lng:Math.round(e.lon/1e6*1e5)/1e5,length:Math.round(e.length/10*100)/100,width:Math.round(e.width/10*100)/100,draught:Math.round(e.draught/1e3*100)/100,sog:Math.round(e.sog*3600/1e3/1852*100)/100,cog:Math.round(e.cog/100*100)/100,hdg:Math.round(e.hdg/100*100)/100,rot:Math.round(e.rot/100*100)/100,positionTime:e.lasttime,utc:u.utc().format(),status:e.navistat,labelEn:c,labelCn:d,method:"position",vendor:"shipxy"}}async trajectory(t,i,n,o,s=!0,e={}){var p;const d=await this.realTimePosition(t,e),c=v(i),u=v(n),f="https://api.shipxy.com/apicall/GetShipTrack",y={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:c.unix(),etm:u.unix()}},m=await T.get(f,y).json();if(l==null||l.info("[%s] fetch trajectory from: %s - %j",e.requestId,f,y),(m==null?void 0:m.status)!==0)return m;const h=m==null?void 0:m.points,g=[],k=v.unix((p=h[0])==null?void 0:p.utc);let Y=-1;for(const r of h){const M=v.unix(r.utc),I={imo:d==null?void 0:d.imo,mmsi:t,sog:Math.round(r.sog*3600/1e3/1852*100)/100,cog:Math.round(r.cog/100*100)/100,lat:Math.round(r.lat/1e6*1e5)/1e5,lng:Math.round(r.lon/1e6*1e5)/1e5,positionTime:M.unix(),utc:M.utc().format(),method:"trajectory",vendor:"shipxy"},b=Math.floor(M.diff(k,"minute",!0)/(o||1));b!==Y&&(Y=b,g.push(I))}return g}}class ct extends z{constructor(t){super();K(this,"token");this.token=t}async getShipId(t,i={}){const n={headers:{appKey:this.token},json:{mmsiList:t}},o="https://api3.myships.com/sp/ships/getShipIdByMMSI",s=await T.post(o,n).json();return l==null||l.info("[%s] fetch ship id from: %s - %j",i.requestId,o,n),s.code!=="0"?s:s.data[0].shipId}async getShipInfo(t,i={}){const n={headers:{appKey:this.token},json:{shipId:t}},o="https://api3.myships.com/sp/ships/aissta",s=await T.post(o,n).json();if(l==null||l.info("[%s] fetch ship info from: %s - %j",i.requestId,o,n),s.code!=="0")return s;const e=s.data;let d=e.imo;return t==="407170"&&(d="9198379",l==null||l.warn("[%s] ship(%s) imo error: %s, should be %s",i.requestId,t,e.imo,d)),{mmsi:e.mmsi,name:e.shipnameEn,imo:d,callSign:e.callSign,length:e.length,width:e.breadth,draught:(e.draught||100)/10}}async realTimePosition(t,i={}){const n=await this.getShipId(t,i),o=await this.getShipInfo(n,i),s={headers:{appKey:this.token},json:{shipId:n}},e="https://api3.myships.com/sp/ships/position/latest",d=await T.post(e,s).json();l==null||l.info("[%s] fetch realtime position from: %s - %j",i.requestId,e,s);const c=d.data[0];for(const h in c)!isNaN(c[h])&&Number(c[h])!==1/0&&(c[h]=Number(c[h]));const{labelCn:u,labelEn:f}=await this.parseStatus(c.aisNavStatus),y=v.unix(c.posTime);return{...o,mmsi:t,lat:Math.round(c.lat/1e4/60*1e5)/1e5,lng:Math.round(c.lon/1e4/60*1e5)/1e5,sog:Math.round(c.sog/10*100)/100,cog:Math.round(c.cog/10*100)/100,hdg:Math.round(c.heading*100)/100,rot:Math.round(c.rot*100)/100,positionTime:c.posTime,utc:y.utc().format(),status:c.aisNavStatus,labelEn:f,labelCn:u,method:"position",vendor:"myship"}}async trajectory(t,i,n,o,s=!0,e={}){const d=v(i),c=v(n),u=await this.getShipId(t),f=await this.getShipInfo(u),y=[];for(;c.diff(d,"day",!0)>30;)await this.trajectoryIn30Day(u,d.unix(),d.add(30,"day").unix(),f,t,o,y);return await this.trajectoryIn30Day(u,d.unix(),c.unix(),f,t,o,y),y}async trajectoryIn30Day(t,i,n,o,s,e,d,c={}){var k;const u={headers:{appKey:this.token},json:{shipId:t,startTime:i,endTime:n}},f="https://api3.myships.com/sp/ships/position/history",y=await T.post(f,u).json();if(l==null||l.info("[%s] fetch trajectory from: %s - %j",c.requestId,f,u),y.code!=="0")return l==null||l.warn("[%s] invoke myship trajectory failed: %j",c.requestId,y),y;const m=y.data;for(const Y in m)!isNaN(m[Y])&&Number(m[Y])!==1/0&&(m[Y]=Number(m[Y]));const h=v.unix((k=m[0])==null?void 0:k.posTime);let g=-1;for(const Y of m){const p=v.unix(Y.posTime),r={imo:o==null?void 0:o.imo,mmsi:s,lat:Math.round(Y.lat/1e4/60*1e5)/1e5,lng:Math.round(Y.lon/1e4/60*1e5)/1e5,sog:Math.round(Y.sog/10*100)/100,cog:Math.round(Y.cog/10*100)/100,hdg:Math.round(Y.heading*100)/100,rot:Math.round(Y.rot*100)/100,positionTime:p.unix(),utc:p.utc().format(),method:"trajectory",vendor:"myship"},M=Math.floor(p.diff(h,"minute",!0)/(e||1));M!==g&&(g=M,d.push(r))}return d}}let A;try{A=_.getLogger("vessel")}catch{}finally{}var G=(w=>(w.NOTICE="NOTICE",w.WARN="WARN",w.HEAVY="HEAVY",w.SEVERE="SEVERE",w.ERROR="ERROR",w.FATAL="FATAL",w))(G||{});class U{parsePrinciple(a,t={}){var e,d,c;A==null||A.info("[%s] parse rule: %s",t.requestId,a);const i=new RegExp("(?<=\\[)(.+)(?=])","g"),n=a.match(i)?(e=a.match(i))==null?void 0:e[0]:void 0,o=n==null?void 0:n.split(";");if(!o)return;const s={};for(let u=0;u<(o==null?void 0:o.length);u++){const f=(c=(d=o[u].match(i))==null?void 0:d[0])==null?void 0:c.split("],");if(u===0&&!f)s.scope=o[0];else if(f)for(let y=0,m=f.length;y<m;y++){const h=this.parseRule(f[y]);h&&(s[h.level]?h.key?s[h.level][h==null?void 0:h.key]=h:s[h.level]=h:h.key?s[h.level]={[h==null?void 0:h.key]:h}:s[h.level]=h)}}return s}parseRule(a,t={}){var s;A==null||A.info("[%s] parse rule: %s",t.requestId,a),a=a.startsWith("[")?a:`[${a}`,a=a.endsWith("]")?a:`${a}]`;const i=new RegExp("(?<=\\[)(.+?)(?=])","g"),n=(s=a==null?void 0:a.match(i))==null?void 0:s[0],o=n==null?void 0:n.split(",");if(o)return{operator:o[0],number:Number.isNaN(Number(o[1]))?o[1]:Number(o[1]),level:o[2],time:Number(o[3]),key:o[4]}}checkWeather(a,t,i={}){var h,g,k,Y,p,r,M,I,b,H,V,L,W,F,D;let n=0,o=0,s=0,e=0;const d=Math.round(((g=(h=t==null?void 0:t.SEVERE)==null?void 0:h.sigWave)==null?void 0:g.number)*1.6*100)/100,c=(Y=(k=t==null?void 0:t.SEVERE)==null?void 0:k.sigWave)==null?void 0:Y.number,u=(r=(p=t==null?void 0:t.HEAVY)==null?void 0:p.sigWave)==null?void 0:r.number,f=Math.round((((I=(M=t==null?void 0:t.SEVERE)==null?void 0:M.wind)==null?void 0:I.number)+2)*100)/100,y=(H=(b=t==null?void 0:t.SEVERE)==null?void 0:b.wind)==null?void 0:H.number,m=(L=(V=t==null?void 0:t.HEAVY)==null?void 0:V.wind)==null?void 0:L.number;for(let q=0;q<(a==null?void 0:a.length);q++){const S=a[q],R=(F=(W=S==null?void 0:S.meteo)==null?void 0:W.wave)==null?void 0:F.sig,O=(D=S==null?void 0:S.meteo)==null?void 0:D.wind,B=q?v(S.eta).diff(v(a[q-1].eta),"hour",!0):0;e=B>e?B:e,A==null||A.info("[%s] check sig.wave: %j",i.requestId,{...R,dgThd4Wv:d,svThd4Wv:c,hvThd4Wv:u}),(R==null?void 0:R.height)>=d?S.isDangerous=!0:(R==null?void 0:R.height)>=c?S.isSevere=!0:(R==null?void 0:R.height)>=u&&(S.isHeavy=!0),A==null||A.info("[%s] check wind: %j",i.requestId,{...O,dgThd4Wd:f,svThd4Wd:y,hvThd4Wd:m}),(O==null?void 0:O.scale)>=f?(S.isDangerous=!0,delete S.isSevere,delete S.isHeavy):(O==null?void 0:O.scale)>y?(S.isDangerous||(S.isSevere=!0),delete S.isHeavy):(O==null?void 0:O.scale)===m&&!S.isDangerous&&!S.isSevere&&(S.isHeavy=!0),n+=S.isDangerous?B:0,o+=S.isSevere?B:0,s+=S.isHeavy?B:0}return n=Math.round(n*100)/100,o=Math.round(o*100)/100,s=Math.round(s*100)/100,e=Math.round(e),{sample:a,dangerous:n,severe:o,heavy:s,step:e<3?3:e,wind:{dgThd4Wd:f,svThd4Wd:y,hvThd4Wd:m},sig:{dgThd4Wv:d,svThd4Wv:c,hvThd4Wv:u}}}}const dt=new U;let N;try{N=_.getLogger("vessel")}catch{}finally{}var J=(w=>(w.common="common",w.container="container",w))(J||{}),Q=(w=>(w.Ballast="Ballast",w.Laden="Laden",w))(Q||{}),X=(w=>(w.Cp="CP",w.Perf="Basis",w.Instruct="Other",w))(X||{});class E{static blockCoefficient(a,t,i,n){let o=Math.round(a/(t*i*n)*100)/100;o=o<.55?.55:o>.85?.85:o;const s=[.55,.6,.65,.7,.75,.8,.85],e=s.map(d=>Math.abs(d-o));return s[e.indexOf(Math.min(...e))]}static froudeNumber(a,t,i=9.8){let n=Math.round(Math.sqrt(a*a/(i*t))*100)/100;return n=n<.05?.05:n>.3?.3:n,n}static amendFactor(a,t,i){const n={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.4,-10.6,-9.5],.8:[2.6,-13.1,-15.1],.85:[3.1,-18.7,28]};let s={.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]}[a];return i==="Laden"&&(s=n[a]),s[0]+s[1]*t+s[2]*Math.pow(t,2)}static directionFactor(a,t=0){let i;return a>30&&a<=60?i=(1.7-.03*Math.pow(t-4,2))/2:a>60&&a<=150?i=(.9-.06*Math.pow(t-6,2))/2:i=(.4-.03*Math.pow(t-8,2))/2,Math.round(i*1e5)/1e5}static vesselTagFactor(a,t,i,n=0){n=n>5?n-.9*(n-5):n;let o;return i==="container"?o=.7*n+Math.pow(n,6.5)/(22*Math.pow(a,2/3)):t==="Ballast"?o=.7*n+Math.pow(n,6.5)/(2.7*Math.pow(a,2/3)):o=.5*n+Math.pow(n,6.5)/(2.7*Math.pow(a,2/3)),o}static waveHeightFactor(a){return a=a<1.25?1.25:a,a=a>6?a-.9*(a-6):a,Math.round((-.144*Math.pow(a,2)+.178*a)*1e4)/1e4}static assembleProperties(a,t,i,n){var u,f;const o=a.lbp??a.length??a.lengthOverall??198.9642,s=a.draught??8,e=a.breadthMoulded??a.breadth??a.breadthExtreme??32.4572,d=a.deadweight??67035.7773;return{tag:((f=(u=a==null?void 0:a.type)==null?void 0:u.toLowerCase())==null?void 0:f.indexOf("container"))>-1?"container":"common",lbp:o,loadCondition:t,draught:s,breadthMoulded:e,displacement:Math.round((d/1.025+s*e*o*.7)*1e4)/1e4,speed:Math.round((i??14.1382)*1852/3600*1e4)/1e4,bearing:n||90}}static async speedLoseAt(a,t,i,n="",o=2,s=!0,e=!1,d={}){let c;if(t.velocity&&e&&(a.speed=P.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),s){const u=await nt.MeteoHelper.queryPointFactor(t.lng,t.lat,i.valueOf(),"wind,wave,current,watertemp",n,d),f=E.weatherFactor(a,u),y=E.currentFactor(a.bearing,u==null?void 0:u.current,o);c={meteo:{...u},wxFactor:f,cFactor:y,speed:t.velocity&&e?t.velocity:Math.round((a.speed*1.943844+f+y)*100)/100,eta:i.utc().format("YYYY-MM-DDTHH:mm[Z]"),etd:i.utc().format("YYYY-MM-DDTHH:mm[Z]")}}else c={wxFactor:0,cFactor:0,speed:t.velocity&&e?t.velocity:Math.round((a.speed*1.943844+0+0)*100)/100,eta:i.utc().format("YYYY-MM-DDTHH:mm[Z]"),etd:i.utc().format("YYYY-MM-DDTHH:mm[Z]")};return delete t.meteo,delete t.wxFactor,delete t.cFactor,delete t.speed,delete t.etd,{...c,...t}}static async speedLoseInHoursStep(a,t,i,n,o,s,e="",d=!0,c=!1,u={}){t.utc();const f=[],y=[];let m=0,h=0,g,k;for(let Y=0;Y<s.length-1;Y++){let p=s[Y];p.distanceFromStart=o+h;const r=s[Y+1];if(a.bearing=P.LaneHelper.calculateBearing(p,r,!r.gcToPrevious),p.bearing=a.bearing,p.suspend&&c){p.eta=p.eta||t.format("YYYY-MM-DDTHH:mm[Z]"),p.elapsed=p.elapsed??0;const b=p.suspend-p.elapsed;if(n-m>b)n=n-m-b,t.add(b,"hour"),p.elapsed=p.suspend;else{const H=n-m;p.elapsed+=H,t.add(H,"hour"),n=0}if(N==null||N.info(`[%s] suspend ${p.elapsed} hours at %j, and remain ${n} hours need to go...`,u.requestId,p),n===0)return p.distanceFromPrevious=h,{etd:t,from:k||p,to:p,next:s.filter(H=>H),wps:f,days:y}}p=await E.speedLoseAt(a,p,t,e,0,d,c,u),k=k||p,p.important&&f.push(p),t.isSameOrAfter(i)&&(y.push(p),i.add(24,"hour"));const M=P.LaneHelper.calculateDistance(p,r,!r.gcToPrevious);let I=Math.ceil(M/k.speed*1e4)/1e4;if(m+I<n){if(m+=I,t.add(I,"hour"),delete s[Y],N==null||N.info(`[%s] go to %j from %j with ${M}nm, and cost ${I} hours`,u.requestId,{lat:r.lat,lng:r.lng},{lat:k.lat,lng:k.lng,etd:k.etd}),h+=M,s.filter(b=>b).length<=1){g=r,g.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),g.distanceFromPrevious=M,g.distanceFromStart=o+h,f.push(g),delete s[Y+1];break}}else{I=n-m,t.add(I,"hour");const b=P.LngLatHelper.roundPrecision(k.speed*I,4);g=P.LaneHelper.calculateCoordinate(p,a.bearing,b,"nauticalmiles",!r.gcToPrevious),g.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),s[Y]=g,N==null||N.info(`[%s] go to %j from %j with ${b}nm, and cost ${I} hours`,u.requestId,{lat:g.lat,lng:g.lng},{lat:p.lat,lng:p.lng,etd:p.etd}),h+=b,g.distanceFromPrevious=h,g.distanceFromStart=o+h;break}}return{etd:t,from:k,to:g,next:s.filter(Y=>Y),wps:f,days:y}}static currentFactor(a,t,i=0){const n=(a-(t==null?void 0:t.degree)||0)/180*Math.PI;if(Math.abs(n)===Math.PI/2)return 0;let o=((t==null?void 0:t.kts)||0)*Math.cos(n);return i&2?o=Math.ceil(o*100)/100:i&1?o=Math.floor(o*100)/100:o=Math.round(o*100)/100,Math.abs(o)>5?0:o}static weatherFactor(a,t){var f,y,m,h,g;N==null||N.debug("calculate weather factor via: %j",{...a,...t});const i=E.blockCoefficient(a.displacement,a.lbp,a.breadthMoulded,a.draught),n=E.froudeNumber(a.speed,a.lbp),o=E.amendFactor(i,n,a.loadCondition);let s=Math.abs(a.bearing%360-(((f=t==null?void 0:t.wind)==null?void 0:f.degree)%360||0));s=s>180?360-s:s;const e=E.directionFactor(s,(y=t==null?void 0:t.wind)==null?void 0:y.scale),d=E.vesselTagFactor(a.displacement,a.loadCondition,a.tag,(m=t==null?void 0:t.wind)==null?void 0:m.scale);let c=e*o*d/100*a.speed;c=Math.round(c*1.943844*1e4)/1e4*-1;const u=E.waveHeightFactor(((g=(h=t==null?void 0:t.wave)==null?void 0:h.sig)==null?void 0:g.height)??1);return c=c*.24+u*.76,N==null||N.debug("weather factor = %s",c),Math.round(c*100)/100}static async analyseInstant(a,t,i,n,o,s="",e=0,d=!0,c=!1,u={}){var B,$,tt,et,st;const f=v().valueOf();a.lng=P.LngLatHelper.convertToStdLng(a.lng);const{route:y,waypoints:m}=o.points,h=P.LaneHelper.calculateSubRoute(a,y);if(((B=h[0])==null?void 0:B.length)<=1)return;const{v0:g,label:k}=a.sog?{v0:a.sog,label:"Other"}:{v0:n.speed,label:"CP"},Y=E.assembleProperties(i,n.loadCondition,g,0),p=m.length?P.LaneHelper.calculateSubWaypoints(a,m):[],r={from:{...a},route:h,waypoints:p,v0:g,label:k},M={hours:[],days:[],wps:[]};e||(P.LaneHelper.calculateRouteDistance(h)/n.speed<=72?e=3:e=6);let I=P.LaneHelper.simplifyRouteToCoordinates(h,p,0),b=0,H=0,V=0,L=0;t=v(t).utc();const W=t.clone();for(;I.length>0;){const C=e-t.hour()%e,Z=Math.ceil(t.clone().add(C,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,x=await E.speedLoseInHoursStep(Y,t,W,Z,b,I,s,d,c,u);($=x.from)!=null&&$.speed&&(M.hours.push(x.from),M.wps.push(...x.wps),M.days.push(...x.days)),I=x==null?void 0:x.next,I.length||M.hours.push(x==null?void 0:x.to),b+=((tt=x==null?void 0:x.to)==null?void 0:tt.distanceFromPrevious)??0}const F=M.hours;for(let C=0;C<F.length-1;C++){const Z=v(F[C+1].eta).diff(F[C].etd,"hour",!0)||1;H+=F[C].wxFactor||0*Z,V+=F[C].cFactor||0*Z,L+=Z}(et=M.wps)==null||et.forEach((C,Z)=>{if(Z){const x=M.wps[Z-1],ut=C.distanceFromStart-x.distanceFromStart,at=v(C.eta).diff(v(x.etd),"h",!0);at<1?C.avgSpd=x.speed:C.avgSpd=Math.round(ut/at*100)/100}}),r.sample=M;const D=M.hours.at(0),q=M.hours.at(-1);r.distance=Math.round(q.distanceFromStart*1e4)/1e4,r.etd=v(D.eta).utc().format(),r.eta=v(q.eta).utc().format(),r.wxFactor=Math.round(H/L*1e4)/1e4,r.cFactor=Math.round(V/L*1e4)/1e4,r.avgSpeed=Math.round(q.distanceFromStart/L*1e4)/1e4,r.totalHrs=Math.round(L*1e4)/1e4,r.totalFoCons=Math.round((n==null?void 0:n.fo)/24*r.totalHrs*1e3)/1e3,r.totalDgoCons=Math.round((n==null?void 0:n.dgo)/24*r.totalHrs*1e3)/1e3;const R=v().valueOf()-f,O=((st=M==null?void 0:M.hours)==null?void 0:st.length)||1;return N==null||N.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",u==null?void 0:u.requestId,R,O,Math.round(R/O*1e3)/1e3),r}static async analyseInstantWithThreshed(a,t,i,n,o,s,e="",d=3,c=!0,u=!1,f={}){var L,W,F;a.lng=P.LngLatHelper.convertToStdLng(a.lng);const y=E.assembleProperties(n,o.loadCondition,o.speed,0),m=P.LaneHelper.calculateSubRoute(a,s);if(((L=m[0])==null?void 0:L.length)<=1)return;let h=P.LaneHelper.simplifyRouteToCoordinates(m,[],0);h.forEach(D=>D.important=!0);let g=0,k=0,Y=0,p=0,r;const M={hours:[],wps:[],days:[]};for(t=v(t).utc();h.length>0;){const D=d-t.hour()%d;let q=Math.ceil(t.clone().add(D,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;if(q=t.clone().add(q,"h").isAfter(i)?i.diff(t,"h",!0)*1e4/1e4:q,q)r=await E.speedLoseInHoursStep(y,t,i.clone(),q,g,h,e,c,u,f),(W=r.from)!=null&&W.speed&&(M.hours.push(r.from),r!=null&&r.wps&&M.wps.push(...r.wps),M.days.push(...r.days)),h=r==null?void 0:r.next,h.length||(M.hours.push(r==null?void 0:r.to),r!=null&&r.wps&&M.wps.push(...r.wps),M.days.push(r==null?void 0:r.to)),g+=((F=r==null?void 0:r.to)==null?void 0:F.distanceFromPrevious)??0;else{r&&(M.hours.push(r.to),r!=null&&r.wps&&M.wps.push(...r.wps),M.days.push(r.to));break}}const I=M.hours;for(let D=0;D<I.length-1;D++){const q=v(I[D+1].eta).diff(I[D].etd,"hour",!0);k+=I[D].wxFactor*q,Y+=I[D].cFactor*q,p+=q}const b=M.hours.at(0),H=M.hours.at(-1);return{sample:M,distance:Math.round(((H==null?void 0:H.distanceFromStart)||0)*1e4)/1e4,etd:v(b.eta).utc().format(),eta:v(H==null?void 0:H.eta).utc().format(),wxFactor:Math.round(k/p*1e4)/1e4,cFactor:Math.round(Y/p*1e4)/1e4,avgSpeed:Math.round(((H==null?void 0:H.distanceFromStart)||0)/p*1e4)/1e4,totalHrs:Math.round(p*1e4)/1e4,to:H,route:P.LaneHelper.generateRouteAccordingToWaypoints(h)}}}j.AISImpl=z,j.AlertHelper=U,j.AlertLevel=G,j.HifleetImpl=it,j.LoadCondition=Q,j.MyShipImpl=ct,j.MyVesselImpl=ot,j.ShipxyImpl=rt,j.SpeedHelper=E,j.SpeedLabel=X,j.VesselTag=J,j.alertHelper=dt,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"})});
1
+ (function(w,D){typeof exports=="object"&&typeof module<"u"?D(exports,require("got"),require("@log4js-node/log4js-api"),require("moment"),require("@idm-plugin/geo"),require("@idm-plugin/meteo")):typeof define=="function"&&define.amd?define(["exports","got","@log4js-node/log4js-api","moment","@idm-plugin/geo","@idm-plugin/meteo"],D):(w=typeof globalThis<"u"?globalThis:w||self,D(w["idm-plugin-rabbitmq"]={},w.got,w["@log4js-node/log4js-api"],w.moment,w["@idm-plugin/geo"],w["@idm-plugin/meteo"]))})(this,function(w,D,Z,v,C,nt){"use strict";var ht=Object.defineProperty;var lt=(w,D,Z)=>D in w?ht(w,D,{enumerable:!0,configurable:!0,writable:!0,value:Z}):w[D]=Z;var K=(w,D,Z)=>(lt(w,typeof D!="symbol"?D+"":D,Z),Z);let u;try{u=Z.getLogger("vessel")}catch{}finally{}class z{parseStatus(s){let t,i;switch(s){case 0:t="在航(主机推动)",i="The engine is in use";break;case 1:t="锚泊",i="Anchored";break;case 2:t="失控",i="Not operated";break;case 3:t="操纵受限",i="Limited airworthiness";break;case 4:t="吃水受限",i="Limited by ship's draft";break;case 5:t="靠泊",i="Mooring";break;case 6:t="搁浅",i="Stranded";break;case 7:t="捕捞作业",i="Engaged in fishing";break;case 8:t="靠帆船提供动力",i="Sailing";break;default:t="未定义",i="Undefined"}return{labelCn:t,labelEn:i}}}class ot extends z{constructor(t,i){super();K(this,"clientId");K(this,"clientSecret");K(this,"token");this.clientId=t,this.clientSecret=i}async authToken(t={}){const i="https://svc.data.myvessel.cn/ada/oauth/token",n={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},o=await D.post(i,n).json();u==null||u.info("[%s] fetch access token from: %s - %j",t.requestId,i,o),o.error||(this.token={accessToken:o.access_token,tokenType:o.token_type,expiresIn:o.expires_in,scope:o.scope,jti:o.jti,issuedAt:v().utc().format()})}async realTimePosition(t,i={}){var c,h,M;(!this.token||v().diff(v(this.token.issuedAt),"seconds")>((c=this.token)==null?void 0:c.expiresIn)-300)&&await this.authToken(i);const n="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",o={headers:{Authorization:`${(h=this.token)==null?void 0:h.tokenType} ${(M=this.token)==null?void 0:M.accessToken}`},searchParams:{mmsi:t}};u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,n,o);const a=await D.get(n,o).json();if(a.code)return u==null||u.warn("[%s] fetch realtime position failed: %j",i.requestId,n,{message:a.message,status:a.status,code:a.code}),a;const e=a.data;for(const m in e)!isNaN(e[m])&&Number(e[m])!==1/0&&(e[m]=Number(e[m]));const d=v(`${e.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:e.mmsi,name:e.vesselName,imo:e.imo,callSign:e.callsign,lat:e.lat,lng:e.lon,length:e.length,width:e.width,draught:e.currDraught,sog:e.sog,cog:e.cog,hdg:e.hdg,rot:e.rot,eta:e.eta,destination:e.dest,positionTime:d.unix(),status:e.status,labelCn:e.statusNameCn,labelEn:e.statusNameEn,method:"position",vendor:"myVessel",utc:d.utc().format()}}async trajectory(t,i,n,o,a=!0,e={}){(!this.token||v().diff(v(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(e);const d=await this.realTimePosition(t,e),r=v(i),c=v(n),h=[];for(;c.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(t,r,r.clone().add(30,"day"),d,o,h,e),r.add(30,"day");return await this.trajectoryIn30Day(t,r,c,d,o,h,e),h}async trajectoryIn30Day(t,i,n,o,a,e,d={}){var f,g,k,Y,p;const r="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",c={headers:{Authorization:`${(f=this.token)==null?void 0:f.tokenType} ${(g=this.token)==null?void 0:g.accessToken}`},json:{mmsi:t,startTime:i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};u==null||u.info("[%s] fetch trajectory from: %s - %j",d.requestId,r,c);const h=await D.post(r,c).json();if(h.code)return u==null||u.warn("[%s] fetch trajectory failed: %j",d.requestId,r,{message:h.message,status:h.status,code:h.code}),h;let M=-1;const m=v(`${(Y=(k=h.data)==null?void 0:k[0])==null?void 0:Y.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(p=h.data)==null||p.forEach(l=>{for(const T in l)!isNaN(l[T])&&Number(l[T])!==1/0&&(l[T]=Number(l[T]));const I=v(`${l.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),H=l.eta?v(`${l.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,y=l.status,{labelCn:b,labelEn:F}=this.parseStatus(y),x={mmsi:l.mmsi,imo:o==null?void 0:o.imo,lat:l.lat,lng:l.lon,sog:l.sog,cog:l.cog,hdg:l.hdg,draught:l.draught,status:y,eta:H==null?void 0:H.unix(),destination:l.dest,positionTime:I.unix(),labelCn:b,labelEn:F,method:"trajectory",vendor:"myVessel",utc:I.utc().format()},V=Math.floor(I.diff(m,"minute",!0)/(a||1));V!==M&&(M=V,e.push(x))}),e}}class it extends z{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,i={}){const n="https://api.hifleet.com/position/position/get/token",o={searchParams:{mmsi:t,usertoken:this.token}},a=await D.post(n,o).json();u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,n,o);const e=a==null?void 0:a.list;if(!e)return u==null||u.warn("[%s] fetch realtime position failed: %j",i.requestId,n,a),a;for(const m in e)!isNaN(e[m])&&Number(e[m])!==1/0&&(e[m]=Number(e[m]));e.status=e.sp>3?0:1;const d=e.status,{labelCn:r,labelEn:c}=this.parseStatus(d),h=v(`${e.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:e.m,name:e.n,imo:e.imonumber,callSign:e.callsign,lat:Math.round(e.la/60*1e5)/1e5,lng:Math.round(e.lo/60*1e5)/1e5,length:e.l,width:e.w,draught:e.draught,sog:e.sp,cog:e.co,hdg:e.h,rot:isNaN(e.rot)?0:e.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta)?v(`${e.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").unix():void 0,destination:e.destination,positionTime:h.unix(),utc:h.utc().format(),status:d,labelCn:r,labelEn:c,method:"position",vendor:"hifleet"}}async search(t,i={}){let n="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const o={searchParams:{keyword:t},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let a=await D.post(n,o).json();u==null||u.info("[%s] fetch vessel props from: %s - %j",i.requestId,n,o),a instanceof Array&&(a=a[0]);for(const d in a)!isNaN(a[d])&&Number(a[d])!==1/0&&(a[d]=Number(a[d]));const e={mmsi:a.m,name:a.n,imo:a.i,callSign:a.c,length:a.l,breadth:a.b,draught:a.dr};return n="https://www.hifleet.com/hifleetapi/sameShipSearch.do",a=await D.post(n,o).json(),u==null||u.info("[%s] fetch vessel dead weight from: %s - %j",i.requestId,n,o),a instanceof Array&&(a=a[0]),a&&(e.deadweight=Number(a.dwt)),e}async trajectory(t,i,n,o,a=!0,e={}){var l,I,H;const d=await this.realTimePosition(t,e);let r=v(i);const c=v(n),h=v();if(a){let y=c.diff(r,"d",!0);y<0?r=c.clone().subtract(40,"d"):y<30?r.subtract(10,"d"):y<60?r.subtract(5,"d"):r=c.clone().subtract(80,"d"),y=h.diff(c,"d",!0),c.add(y>10?240:y*24,"h")}const M={searchParams:{endtime:c.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),starttime:r.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),mmsi:t,usertoken:this.token}},m="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",f=await D.get(m,M).json();u==null||u.info("[%s] fetch trajectory from: %s - %j",e.requestId,m,M);let g;f&&(g=((I=(l=f.ships)==null?void 0:l.offors)==null?void 0:I.ship)||[],g.length||u==null||u.warn("[%s] fetch trajectory failed: %j",e.requestId,f));const k=[];let Y=-1;const p=v(`${(H=g==null?void 0:g[0])==null?void 0:H.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const y of g){for(const _ in y)!isNaN(y[_])&&Number(y[_])!==1/0&&(y[_]=Number(y[_]));const b=v(`${y.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");y.status=y.sp>4?0:1;const{labelEn:F,labelCn:x}=this.parseStatus(y.status),V={mmsi:y.m,name:y.n,imo:d==null?void 0:d.imo,lat:y.la,lng:y.lo,draught:y.draught,sog:y.sp,cog:y.co,hdg:y.hdg,positionTime:b.unix(),utc:b.utc().format(),status:y.status,labelCn:x,labelEn:F,method:"trajectory",vendor:"hifleet"},T=Math.floor(b.diff(p,"minute",!0)/(o||1));T!==Y&&(Y=T,k.push(V))}return k}}class rt extends z{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,i={}){const n={searchParams:{id:t,k:this.token,enc:1}},o="https://api.shipxy.com/apicall/GetSingleShip",a=await D.get(o,n).json();if(u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,o,n),(a==null?void 0:a.status)!==0)return a;const e=a.data[0];for(const M in e)!isNaN(e[M])&&Number(e[M])!==1/0&&(e[M]=Number(e[M]));const{labelCn:d,labelEn:r}=await this.parseStatus(e.navistat),c=v.unix(e.lasttime);return{mmsi:e.ShipID,name:e.name,imo:e.imo,callSign:e.callsign,lat:Math.round(e.lat/1e6*1e5)/1e5,lng:Math.round(e.lon/1e6*1e5)/1e5,length:Math.round(e.length/10*100)/100,width:Math.round(e.width/10*100)/100,draught:Math.round(e.draught/1e3*100)/100,sog:Math.round(e.sog*3600/1e3/1852*100)/100,cog:Math.round(e.cog/100*100)/100,hdg:Math.round(e.hdg/100*100)/100,rot:Math.round(e.rot/100*100)/100,positionTime:e.lasttime,utc:c.utc().format(),status:e.navistat,labelEn:r,labelCn:d,method:"position",vendor:"shipxy"}}async trajectory(t,i,n,o,a=!0,e={}){var p;const d=await this.realTimePosition(t,e),r=v(i),c=v(n),h="https://api.shipxy.com/apicall/GetShipTrack",M={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:r.unix(),etm:c.unix()}},m=await D.get(h,M).json();if(u==null||u.info("[%s] fetch trajectory from: %s - %j",e.requestId,h,M),(m==null?void 0:m.status)!==0)return m;const f=m==null?void 0:m.points,g=[],k=v.unix((p=f[0])==null?void 0:p.utc);let Y=-1;for(const l of f){const I=v.unix(l.utc),H={imo:d==null?void 0:d.imo,mmsi:t,sog:Math.round(l.sog*3600/1e3/1852*100)/100,cog:Math.round(l.cog/100*100)/100,lat:Math.round(l.lat/1e6*1e5)/1e5,lng:Math.round(l.lon/1e6*1e5)/1e5,positionTime:I.unix(),utc:I.utc().format(),method:"trajectory",vendor:"shipxy"},y=Math.floor(I.diff(k,"minute",!0)/(o||1));y!==Y&&(Y=y,g.push(H))}return g}}class ct extends z{constructor(t){super();K(this,"token");this.token=t}async getShipId(t,i={}){const n={headers:{appKey:this.token},json:{mmsiList:t}},o="https://api3.myships.com/sp/ships/getShipIdByMMSI",a=await D.post(o,n).json();return u==null||u.info("[%s] fetch ship id from: %s - %j",i.requestId,o,n),a.code!=="0"?a:a.data[0].shipId}async getShipInfo(t,i={}){const n={headers:{appKey:this.token},json:{shipId:t}},o="https://api3.myships.com/sp/ships/aissta",a=await D.post(o,n).json();if(u==null||u.info("[%s] fetch ship info from: %s - %j",i.requestId,o,n),a.code!=="0")return a;const e=a.data;let d=e.imo;return t==="407170"&&(d="9198379",u==null||u.warn("[%s] ship(%s) imo error: %s, should be %s",i.requestId,t,e.imo,d)),{mmsi:e.mmsi,name:e.shipnameEn,imo:d,callSign:e.callSign,length:e.length,width:e.breadth,draught:(e.draught||100)/10}}async realTimePosition(t,i={}){const n=await this.getShipId(t,i),o=await this.getShipInfo(n,i),a={headers:{appKey:this.token},json:{shipId:n}},e="https://api3.myships.com/sp/ships/position/latest",d=await D.post(e,a).json();u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,e,a);const r=d.data[0];for(const f in r)!isNaN(r[f])&&Number(r[f])!==1/0&&(r[f]=Number(r[f]));const{labelCn:c,labelEn:h}=await this.parseStatus(r.aisNavStatus),M=v.unix(r.posTime);return{...o,mmsi:t,lat:Math.round(r.lat/1e4/60*1e5)/1e5,lng:Math.round(r.lon/1e4/60*1e5)/1e5,sog:Math.round(r.sog/10*100)/100,cog:Math.round(r.cog/10*100)/100,hdg:Math.round(r.heading*100)/100,rot:Math.round(r.rot*100)/100,positionTime:r.posTime,utc:M.utc().format(),status:r.aisNavStatus,labelEn:h,labelCn:c,method:"position",vendor:"myship"}}async trajectory(t,i,n,o,a=!0,e={}){const d=v(i),r=v(n),c=await this.getShipId(t),h=await this.getShipInfo(c),M=[];for(;r.diff(d,"day",!0)>30;)await this.trajectoryIn30Day(c,d.unix(),d.add(30,"day").unix(),h,t,o,M);return await this.trajectoryIn30Day(c,d.unix(),r.unix(),h,t,o,M),M}async trajectoryIn30Day(t,i,n,o,a,e,d,r={}){var k;const c={headers:{appKey:this.token},json:{shipId:t,startTime:i,endTime:n}},h="https://api3.myships.com/sp/ships/position/history",M=await D.post(h,c).json();if(u==null||u.info("[%s] fetch trajectory from: %s - %j",r.requestId,h,c),M.code!=="0")return u==null||u.warn("[%s] invoke myship trajectory failed: %j",r.requestId,M),M;const m=M.data;for(const Y in m)!isNaN(m[Y])&&Number(m[Y])!==1/0&&(m[Y]=Number(m[Y]));const f=v.unix((k=m[0])==null?void 0:k.posTime);let g=-1;for(const Y of m){const p=v.unix(Y.posTime),l={imo:o==null?void 0:o.imo,mmsi:a,lat:Math.round(Y.lat/1e4/60*1e5)/1e5,lng:Math.round(Y.lon/1e4/60*1e5)/1e5,sog:Math.round(Y.sog/10*100)/100,cog:Math.round(Y.cog/10*100)/100,hdg:Math.round(Y.heading*100)/100,rot:Math.round(Y.rot*100)/100,positionTime:p.unix(),utc:p.utc().format(),method:"trajectory",vendor:"myship"},I=Math.floor(p.diff(f,"minute",!0)/(e||1));I!==g&&(g=I,d.push(l))}return d}}let O;try{O=Z.getLogger("vessel")}catch{}finally{}var G=(j=>(j.NOTICE="NOTICE",j.WARN="WARN",j.HEAVY="HEAVY",j.SEVERE="SEVERE",j.ERROR="ERROR",j.FATAL="FATAL",j))(G||{});class U{parsePrinciple(s,t={}){var e,d,r;O==null||O.info("[%s] parse rule: %s",t.requestId,s);const i=new RegExp("(?<=\\[)(.+)(?=])","g"),n=s.match(i)?(e=s.match(i))==null?void 0:e[0]:void 0,o=n==null?void 0:n.split(";");if(!o)return;const a={};for(let c=0;c<(o==null?void 0:o.length);c++){const h=(r=(d=o[c].match(i))==null?void 0:d[0])==null?void 0:r.split("],");if(c===0&&!h)a.scope=o[0];else if(h)for(let M=0,m=h.length;M<m;M++){const f=this.parseRule(h[M]);f&&(a[f.level]?f.key?a[f.level][f==null?void 0:f.key]=f:a[f.level]=f:f.key?a[f.level]={[f==null?void 0:f.key]:f}:a[f.level]=f)}}return a}parseRule(s,t={}){var a;O==null||O.info("[%s] parse rule: %s",t.requestId,s),s=s.startsWith("[")?s:`[${s}`,s=s.endsWith("]")?s:`${s}]`;const i=new RegExp("(?<=\\[)(.+?)(?=])","g"),n=(a=s==null?void 0:s.match(i))==null?void 0:a[0],o=n==null?void 0:n.split(",");if(o)return{operator:o[0],number:Number.isNaN(Number(o[1]))?o[1]:Number(o[1]),level:o[2],time:Number(o[3]),key:o[4]}}checkWeather(s,t,i={}){var f,g,k,Y,p,l,I,H,y,b,F,x,V,T,_;let n=0,o=0,a=0,e=0;const d=Math.round(((g=(f=t==null?void 0:t.SEVERE)==null?void 0:f.sigWave)==null?void 0:g.number)*1.6*100)/100,r=(Y=(k=t==null?void 0:t.SEVERE)==null?void 0:k.sigWave)==null?void 0:Y.number,c=(l=(p=t==null?void 0:t.HEAVY)==null?void 0:p.sigWave)==null?void 0:l.number,h=Math.round((((H=(I=t==null?void 0:t.SEVERE)==null?void 0:I.wind)==null?void 0:H.number)+2)*100)/100,M=(b=(y=t==null?void 0:t.SEVERE)==null?void 0:y.wind)==null?void 0:b.number,m=(x=(F=t==null?void 0:t.HEAVY)==null?void 0:F.wind)==null?void 0:x.number;for(let W=0;W<(s==null?void 0:s.length);W++){const S=s[W],P=(T=(V=S==null?void 0:S.meteo)==null?void 0:V.wave)==null?void 0:T.sig,N=(_=S==null?void 0:S.meteo)==null?void 0:_.wind,E=W?v(S.eta).diff(v(s[W-1].eta),"hour",!0):0;e=E>e?E:e,O==null||O.info("[%s] check sig.wave: %j",i.requestId,{...P,dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:c}),(P==null?void 0:P.height)>=d?S.isDangerous=!0:(P==null?void 0:P.height)>=r?S.isSevere=!0:(P==null?void 0:P.height)>=c&&(S.isHeavy=!0),O==null||O.info("[%s] check wind: %j",i.requestId,{...N,dgThd4Wd:h,svThd4Wd:M,hvThd4Wd:m}),(N==null?void 0:N.scale)>=h?(S.isDangerous=!0,delete S.isSevere,delete S.isHeavy):(N==null?void 0:N.scale)>M?(S.isDangerous||(S.isSevere=!0),delete S.isHeavy):(N==null?void 0:N.scale)===m&&!S.isDangerous&&!S.isSevere&&(S.isHeavy=!0),n+=S.isDangerous?E:0,o+=S.isSevere?E:0,a+=S.isHeavy?E:0}return n=Math.round(n*100)/100,o=Math.round(o*100)/100,a=Math.round(a*100)/100,e=Math.round(e),{sample:s,dangerous:n,severe:o,heavy:a,step:e<3?3:e,wind:{dgThd4Wd:h,svThd4Wd:M,hvThd4Wd:m},sig:{dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:c}}}}const dt=new U;let q;try{q=Z.getLogger("vessel")}catch{}finally{}var J=(j=>(j.common="common",j.container="container",j))(J||{}),Q=(j=>(j.Ballast="Ballast",j.Laden="Laden",j))(Q||{}),X=(j=>(j.Cp="CP",j.Perf="Basis",j.Instruct="Other",j))(X||{});class A{static blockCoefficient(s,t,i,n){let o=Math.round(s/(t*i*n)*100)/100;o=o<.55?.55:o>.85?.85:o;const a=[.55,.6,.65,.7,.75,.8,.85],e=a.map(d=>Math.abs(d-o));return a[e.indexOf(Math.min(...e))]}static froudeNumber(s,t,i=9.8){let n=Math.round(Math.sqrt(s*s/(i*t))*100)/100;return n=n<.05?.05:n>.3?.3:n,n}static amendFactor(s,t,i){const n={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.4,-10.6,-9.5],.8:[2.6,-13.1,-15.1],.85:[3.1,-18.7,28]};let a={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.6,-12.5,-13.5],.8:[3,-16.3,-21.6],.85:[3.4,-20.9,31.8]}[s];return i==="Laden"&&(a=n[s]),a[0]+a[1]*t+a[2]*Math.pow(t,2)}static directionFactor(s,t=0){let i;return s>30&&s<=60?i=(1.7-.03*Math.pow(t-4,2))/2:s>60&&s<=150?i=(.9-.06*Math.pow(t-6,2))/2:i=(.4-.03*Math.pow(t-8,2))/2,Math.round(i*1e5)/1e5}static vesselTagFactor(s,t,i,n=0){n=n>5?n-.9*(n-5):n;let o;return i==="container"?o=.7*n+Math.pow(n,6.5)/(22*Math.pow(s,2/3)):t==="Ballast"?o=.7*n+Math.pow(n,6.5)/(2.7*Math.pow(s,2/3)):o=.5*n+Math.pow(n,6.5)/(2.7*Math.pow(s,2/3)),o}static waveHeightFactor(s){return s=s<1.25?1.25:s,s=s>6?s-.9*(s-6):s,Math.round((-.144*Math.pow(s,2)+.178*s)*1e4)/1e4}static assembleProperties(s,t,i,n){var c,h;const o=s.lbp??s.length??s.lengthOverall??198.9642,a=s.draught??8,e=s.breadthMoulded??s.breadth??s.breadthExtreme??32.4572,d=s.deadweight??67035.7773;return{tag:((h=(c=s==null?void 0:s.type)==null?void 0:c.toLowerCase())==null?void 0:h.indexOf("container"))>-1?"container":"common",lbp:o,loadCondition:t,draught:a,breadthMoulded:e,displacement:Math.round((d/1.025+a*e*o*.7)*1e4)/1e4,speed:Math.round((i??14.1382)*1852/3600*1e4)/1e4,bearing:n||90}}static async speedLoseAt(s,t,i,n="",o=2,a=!0,e=!1,d={}){let r;if(t.velocity&&e&&(s.speed=C.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),a){const c=await nt.MeteoHelper.queryPointFactor(t.lng,t.lat,i.valueOf(),"wind,wave,current,watertemp",n,d),h=A.weatherFactor(s,c),M=A.currentFactor(s.bearing,c==null?void 0:c.current,o);r={meteo:{...c},wxFactor:h,cFactor:M,speed:t.velocity&&e?t.velocity:Math.round((s.speed*1.943844+h+M)*100)/100,eta:i.utc().format("YYYY-MM-DDTHH:mm[Z]"),etd:i.utc().format("YYYY-MM-DDTHH:mm[Z]")}}else r={wxFactor:0,cFactor:0,speed:t.velocity&&e?t.velocity:Math.round((s.speed*1.943844+0+0)*100)/100,eta:i.utc().format("YYYY-MM-DDTHH:mm[Z]"),etd:i.utc().format("YYYY-MM-DDTHH:mm[Z]")};return delete t.meteo,delete t.wxFactor,delete t.cFactor,delete t.speed,delete t.etd,{...r,...t}}static async speedLoseInHoursStep(s,t,i,n,o,a,e="",d=!0,r=!1,c={}){t.utc();const h=[],M=[];let m=0,f=0,g,k;for(let Y=0;Y<a.length-1;Y++){let p=a[Y];p.distanceFromStart=o+f;const l=a[Y+1];if(s.bearing=C.LaneHelper.calculateBearing(p,l,!l.gcToPrevious),p.bearing=s.bearing,p.suspend&&r){p.eta=p.eta||t.format("YYYY-MM-DDTHH:mm[Z]"),p.elapsed=p.elapsed??0;const y=p.suspend-p.elapsed;if(n-m>y)n=n-m-y,t.add(y,"hour"),p.elapsed=p.suspend;else{const b=n-m;p.elapsed+=b,t.add(b,"hour"),n=0}if(q==null||q.info(`[%s] suspend ${p.elapsed} hours at %j, and remain ${n} hours need to go...`,c.requestId,p),n===0)return p.distanceFromPrevious=f,{etd:t,from:k||p,to:p,next:a.filter(b=>b),wps:h,days:M}}p=await A.speedLoseAt(s,p,t,e,0,d,r,c),k=k||p,p.important&&h.push(p),t.isSameOrAfter(i)&&(M.push(p),i.add(24,"hour"));const I=C.LaneHelper.calculateDistance(p,l,!l.gcToPrevious);let H=Math.ceil(I/k.speed*1e4)/1e4;if(m+H<n){if(m+=H,t.add(H,"hour"),delete a[Y],q==null||q.info(`[%s] go to %j from %j with ${I}nm, and cost ${H} hours`,c.requestId,{lat:l.lat,lng:l.lng},{lat:k.lat,lng:k.lng,etd:k.etd}),f+=I,a.filter(y=>y).length<=1){g=l,g.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),g.distanceFromPrevious=I,g.distanceFromStart=o+f,h.push(g),delete a[Y+1];break}}else{H=n-m,t.add(H,"hour");const y=C.LngLatHelper.roundPrecision(k.speed*H,4);g=C.LaneHelper.calculateCoordinate(p,s.bearing,y,"nauticalmiles",!l.gcToPrevious),g.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),a[Y]=g,q==null||q.info(`[%s] go to %j from %j with ${y}nm, and cost ${H} hours`,c.requestId,{lat:g.lat,lng:g.lng},{lat:p.lat,lng:p.lng,etd:p.etd}),f+=y,g.distanceFromPrevious=f,g.distanceFromStart=o+f;break}}return{etd:t,from:k,to:g,next:a.filter(Y=>Y),wps:h,days:M}}static currentFactor(s,t,i=0){const n=(s-(t==null?void 0:t.degree)||0)/180*Math.PI;if(Math.abs(n)===Math.PI/2)return 0;let o=((t==null?void 0:t.kts)||0)*Math.cos(n);return i&2?o=Math.ceil(o*100)/100:i&1?o=Math.floor(o*100)/100:o=Math.round(o*100)/100,Math.abs(o)>5?0:o}static weatherFactor(s,t){var h,M,m,f,g;q==null||q.debug("calculate weather factor via: %j",{...s,...t});const i=A.blockCoefficient(s.displacement,s.lbp,s.breadthMoulded,s.draught),n=A.froudeNumber(s.speed,s.lbp),o=A.amendFactor(i,n,s.loadCondition);let a=Math.abs(s.bearing%360-(((h=t==null?void 0:t.wind)==null?void 0:h.degree)%360||0));a=a>180?360-a:a;const e=A.directionFactor(a,(M=t==null?void 0:t.wind)==null?void 0:M.scale),d=A.vesselTagFactor(s.displacement,s.loadCondition,s.tag,(m=t==null?void 0:t.wind)==null?void 0:m.scale);let r=e*o*d/100*s.speed;r=Math.round(r*1.943844*1e4)/1e4*-1;const c=A.waveHeightFactor(((g=(f=t==null?void 0:t.wave)==null?void 0:f.sig)==null?void 0:g.height)??1);return r=r*.24+c*.76,q==null||q.debug("weather factor = %s",r),Math.round(r*100)/100}static async analyseInstant(s,t,i,n,o,a="",e=0,d=!0,r=!1,c={}){var E,$,tt,et,st;const h=v().valueOf();s.lng=C.LngLatHelper.convertToStdLng(s.lng);const{route:M,waypoints:m}=o.points,f=C.LaneHelper.calculateSubRoute(s,M);if(((E=f[0])==null?void 0:E.length)<=1)return;const{v0:g,label:k}=s.sog?{v0:s.sog,label:"Other"}:{v0:n.speed,label:"CP"},Y=A.assembleProperties(i,n.loadCondition,g,0),p=m.length?C.LaneHelper.calculateSubWaypoints(s,m):[],l={from:{...s},route:f,waypoints:p,v0:g,label:k},I={hours:[],days:[],wps:[]};e||(C.LaneHelper.calculateRouteDistance(f)/n.speed<=72?e=3:e=6);let H=C.LaneHelper.simplifyRouteToCoordinates(f,p,0),y=0,b=0,F=0,x=0;t=v(t).utc();const V=t.clone();for(;H.length>0;){const R=e-t.hour()%e,B=Math.ceil(t.clone().add(R,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,L=await A.speedLoseInHoursStep(Y,t,V,B,y,H,a,d,r,c);($=L.from)!=null&&$.speed&&(I.hours.push(L.from),I.wps.push(...L.wps),I.days.push(...L.days)),H=L==null?void 0:L.next,H.length||I.hours.push(L==null?void 0:L.to),y+=((tt=L==null?void 0:L.to)==null?void 0:tt.distanceFromPrevious)??0}const T=I.hours;for(let R=0;R<T.length-1;R++){const B=v(T[R+1].eta).diff(T[R].etd,"hour",!0)||1;b+=T[R].wxFactor||0*B,F+=T[R].cFactor||0*B,x+=B}(et=I.wps)==null||et.forEach((R,B)=>{if(B){const L=I.wps[B-1],ut=R.distanceFromStart-L.distanceFromStart,at=v(R.eta).diff(v(L.etd),"h",!0);at<1?R.avgSpd=L.speed:R.avgSpd=Math.round(ut/at*100)/100}}),l.sample=I;const _=I.hours.at(0),W=I.hours.at(-1);l.distance=Math.round(W.distanceFromStart*1e4)/1e4,l.etd=v(_.eta).utc().format(),l.eta=v(W.eta).utc().format(),l.wxFactor=Math.round(b/x*1e4)/1e4,l.cFactor=Math.round(F/x*1e4)/1e4,l.avgSpeed=Math.round(W.distanceFromStart/x*1e4)/1e4,l.totalHrs=Math.round(x*1e4)/1e4,l.totalFoCons=Math.round((n==null?void 0:n.fo)/24*l.totalHrs*1e3)/1e3,l.totalDgoCons=Math.round((n==null?void 0:n.dgo)/24*l.totalHrs*1e3)/1e3;const P=v().valueOf()-h,N=((st=I==null?void 0:I.hours)==null?void 0:st.length)||1;return q==null||q.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",c==null?void 0:c.requestId,P,N,Math.round(P/N*1e3)/1e3),l}static async analyseInstantWithThreshed(s,t,i,n,o,a,e,d="",r=3,c=!0,h=!1,M={}){var W,S,P;s.lng=C.LngLatHelper.convertToStdLng(s.lng);const{v0:m,label:f}=s.sog?{v0:s.sog,label:"Other"}:{v0:o.speed,label:"CP"},g=A.assembleProperties(n,o.loadCondition,m,0),k=C.LaneHelper.calculateSubRoute(s,a);if(((W=k[0])==null?void 0:W.length)<=1)return;const Y=e.length?C.LaneHelper.calculateSubWaypoints(s,e):[];Y.forEach(N=>N.important=!0);let p=C.LaneHelper.simplifyRouteToCoordinates(k,Y,0),l=0,I=0,H=0,y=0,b;const F={hours:[],wps:[],days:[]};for(t=v(t).utc();p.length>0;){const N=r-t.hour()%r;let E=Math.ceil(t.clone().add(N,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;if(E=t.clone().add(E,"h").isAfter(i)?i.diff(t,"h",!0)*1e4/1e4:E,E)b=await A.speedLoseInHoursStep(g,t,i.clone(),E,l,p,d,c,h,M),(S=b.from)!=null&&S.speed&&(F.hours.push(b.from),b!=null&&b.wps&&F.wps.push(...b.wps),F.days.push(...b.days)),p=b==null?void 0:b.next,p.length||(F.hours.push(b==null?void 0:b.to),b!=null&&b.wps&&F.wps.push(...b.wps),F.days.push(b==null?void 0:b.to)),l+=((P=b==null?void 0:b.to)==null?void 0:P.distanceFromPrevious)??0;else{b&&(F.hours.push(b.to),b!=null&&b.wps&&F.wps.push(...b.wps),F.days.push(b.to));break}}const x=F.hours;for(let N=0;N<x.length-1;N++){const E=v(x[N+1].eta).diff(x[N].etd,"hour",!0);I+=x[N].wxFactor*E,H+=x[N].cFactor*E,y+=E}const V=F.hours.at(0),T=F.hours.at(-1);return{sample:F,distance:Math.round(((T==null?void 0:T.distanceFromStart)||0)*1e4)/1e4,etd:v(V.eta).utc().format(),eta:v(T==null?void 0:T.eta).utc().format(),wxFactor:Math.round(I/y*1e4)/1e4,cFactor:Math.round(H/y*1e4)/1e4,avgSpeed:Math.round(((T==null?void 0:T.distanceFromStart)||0)/y*1e4)/1e4,totalHrs:Math.round(y*1e4)/1e4,from:s,to:T,route:C.LaneHelper.generateRouteAccordingToWaypoints(p),subWaypoints:Y,v0:m,label:f}}}w.AISImpl=z,w.AlertHelper=U,w.AlertLevel=G,w.HifleetImpl=it,w.LoadCondition=Q,w.MyShipImpl=ct,w.MyVesselImpl=ot,w.ShipxyImpl=rt,w.SpeedHelper=A,w.SpeedLabel=X,w.VesselTag=J,w.alertHelper=dt,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
@@ -205,7 +205,7 @@ export declare class SpeedHelper {
205
205
  speed: number;
206
206
  fo: number;
207
207
  dgo: number;
208
- }, route: number[][][], source?: string, stepHrs?: number, useMeteo?: boolean, useRouteParam?: boolean, options?: {
208
+ }, route: number[][][], waypoints: any[], source?: string, stepHrs?: number, useMeteo?: boolean, useRouteParam?: boolean, options?: {
209
209
  requestId?: string;
210
210
  }): Promise<{
211
211
  sample: any;
@@ -216,7 +216,11 @@ export declare class SpeedHelper {
216
216
  cFactor: number;
217
217
  avgSpeed: number;
218
218
  totalHrs: number;
219
+ from: any;
219
220
  to: any;
220
221
  route: any;
222
+ subWaypoints: any;
223
+ v0: any;
224
+ label: SpeedLabel;
221
225
  } | undefined>;
222
226
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idm-plugin/vessel",
3
3
  "private": false,
4
- "version": "1.2.5",
4
+ "version": "1.2.7",
5
5
  "description": "idm plugin for vessel",
6
6
  "type": "module",
7
7
  "keywords": [