@idm-plugin/vessel 1.2.6 → 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
2
  var et = (k, s, t) => s in k ? tt(k, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : k[s] = t;
3
3
  var Z = (k, s, t) => (et(k, typeof s != "symbol" ? s + "" : s, t), t);
4
- import C from "got";
4
+ import A from "got";
5
5
  import z from "@log4js-node/log4js-api";
6
- import b from "moment";
7
- import { LngLatHelper as B, LaneHelper as O } from "@idm-plugin/geo";
6
+ import g from "moment";
7
+ import { LngLatHelper as B, LaneHelper as L } from "@idm-plugin/geo";
8
8
  import { MeteoHelper as st } from "@idm-plugin/meteo";
9
- let l;
9
+ let h;
10
10
  try {
11
- l = z.getLogger("vessel");
11
+ h = z.getLogger("vessel");
12
12
  } catch {
13
13
  } finally {
14
14
  }
@@ -68,33 +68,33 @@ class mt extends K {
68
68
  client_secret: this.clientSecret,
69
69
  grant_type: "client_credentials"
70
70
  }
71
- }, n = await C.post(i, o).json();
72
- l == null || l.info("[%s] fetch access token from: %s - %j", t.requestId, i, n), n.error || (this.token = {
71
+ }, n = await A.post(i, o).json();
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 c, h, y;
83
- (!this.token || b().diff(b(this.token.issuedAt), "seconds") > ((c = this.token) == null ? void 0 : c.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: `${(h = this.token) == null ? void 0 : h.tokenType} ${(y = this.token) == null ? void 0 : y.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
- l == null || l.info("[%s] fetch realtime position from: %s - %j", i.requestId, o, n);
91
- const a = await C.get(o, n).json();
90
+ h == null || h.info("[%s] fetch realtime position from: %s - %j", i.requestId, o, n);
91
+ const a = await A.get(o, n).json();
92
92
  if (a.code)
93
- return l == null || l.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
- for (const M in e)
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");
95
+ for (const m in e)
96
+ !isNaN(e[m]) && Number(e[m]) !== 1 / 0 && (e[m] = Number(e[m]));
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), r = b(i), c = b(o), h = [];
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
126
  for (; c.diff(r, "day", !0) > 30; )
127
- await this.trajectoryIn30Day(t, r, r.clone().add(30, "day"), d, n, h, e), r.add(30, "day");
128
- return await this.trajectoryIn30Day(t, r, c, d, n, h, e), h;
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 f, Y, j, w, g;
131
+ var f, v, I, Y, p;
132
132
  const r = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", c = {
133
133
  headers: {
134
- Authorization: `${(f = this.token) == null ? void 0 : f.tokenType} ${(Y = this.token) == null ? void 0 : Y.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
- l == null || l.info("[%s] fetch trajectory from: %s - %j", d.requestId, r, c);
143
- const h = await C.post(r, c).json();
144
- if (h.code)
145
- return l == null || l.warn("[%s] fetch trajectory failed: %j", d.requestId, r, { message: h.message, status: h.status, code: h.code }), h;
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
146
  let y = -1;
147
- const M = b(`${(w = (j = h.data) == null ? void 0 : j[0]) == null ? void 0 : w.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
148
- return (g = h.data) == null || g.forEach((m) => {
149
- for (const N in m)
150
- !isNaN(m[N]) && Number(m[N]) !== 1 / 0 && (m[N] = Number(m[N]));
151
- const v = b(`${m.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), p = m.eta ? b(`${m.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00") : void 0, u = m.status, { labelCn: S, labelEn: W } = this.parseStatus(u), T = {
152
- mmsi: m.mmsi,
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: m.lat,
155
- lng: m.lon,
156
- sog: m.sog,
157
- cog: m.cog,
158
- hdg: m.hdg,
159
- draught: m.draught,
160
- status: u,
161
- eta: p == null ? void 0 : p.unix(),
162
- destination: m.dest,
163
- positionTime: v.unix(),
164
- labelCn: S,
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: v.utc().format()
169
- }, L = Math.floor(v.diff(M, "minute", !0) / (a || 1));
170
- L !== y && (y = L, e.push(T));
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
  }
@@ -183,15 +183,15 @@ class pt extends K {
183
183
  mmsi: t,
184
184
  usertoken: this.token
185
185
  }
186
- }, a = await C.post(o, n).json();
187
- l == null || l.info("[%s] fetch realtime position from: %s - %j", i.requestId, o, n);
186
+ }, a = await A.post(o, n).json();
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 l == null || l.warn("[%s] fetch realtime position failed: %j", i.requestId, o, a), a;
191
- for (const M in e)
192
- !isNaN(e[M]) && Number(e[M]) !== 1 / 0 && (e[M] = Number(e[M]));
190
+ return h == null || h.warn("[%s] fetch realtime position failed: %j", i.requestId, o, a), a;
191
+ for (const m in e)
192
+ !isNaN(e[m]) && Number(e[m]) !== 1 / 0 && (e[m] = Number(e[m]));
193
193
  e.status = e.sp > 3 ? 0 : 1;
194
- const d = e.status, { labelCn: r, labelEn: c } = this.parseStatus(d), h = 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,10 +206,10 @@ 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: h.unix(),
212
- utc: h.utc().format(),
211
+ positionTime: u.unix(),
212
+ utc: u.utc().format(),
213
213
  status: d,
214
214
  labelCn: r,
215
215
  labelEn: c,
@@ -229,8 +229,8 @@ class pt extends K {
229
229
  Host: "www.hifleet.com"
230
230
  }
231
231
  };
232
- let a = await C.post(o, n).json();
233
- l == null || l.info("[%s] fetch vessel props from: %s - %j", i.requestId, o, n), a instanceof Array && (a = a[0]);
232
+ let a = await A.post(o, n).json();
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,16 +242,16 @@ 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 C.post(o, n).json(), l == null || l.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 m, v, p;
248
+ var l, w, j;
249
249
  const d = await this.realTimePosition(t, e);
250
- let r = b(i);
251
- const c = b(o), h = b();
250
+ let r = g(i);
251
+ const c = g(o), u = g();
252
252
  if (a) {
253
- let u = c.diff(r, "d", !0);
254
- u < 0 ? r = c.clone().subtract(40, "d") : u < 30 ? r.subtract(10, "d") : u < 60 ? r.subtract(5, "d") : r = c.clone().subtract(80, "d"), u = h.diff(c, "d", !0), c.add(u > 10 ? 240 : u * 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
256
  const y = {
257
257
  searchParams: {
@@ -260,39 +260,39 @@ class pt extends K {
260
260
  mmsi: t,
261
261
  usertoken: this.token
262
262
  }
263
- }, M = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", f = await C.get(M, y).json();
264
- l == null || l.info("[%s] fetch trajectory from: %s - %j", e.requestId, M, y);
265
- let Y;
266
- f && (Y = ((v = (m = f.ships) == null ? void 0 : m.offors) == null ? void 0 : v.ship) || [], Y.length || l == null || l.warn("[%s] fetch trajectory failed: %j", e.requestId, f));
267
- const j = [];
268
- let w = -1;
269
- const g = b(`${(p = Y == null ? void 0 : Y[0]) == null ? void 0 : p.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
270
- for (const u of Y) {
271
- for (const R in u)
272
- !isNaN(u[R]) && Number(u[R]) !== 1 / 0 && (u[R] = Number(u[R]));
273
- const S = b(`${u.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
274
- u.status = u.sp > 4 ? 0 : 1;
275
- const { labelEn: W, labelCn: T } = this.parseStatus(u.status), L = {
276
- mmsi: u.m,
277
- name: u.n,
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
+ let v;
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
+ const I = [];
268
+ let Y = -1;
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: u.la,
280
- lng: u.lo,
281
- draught: u.draught,
282
- sog: u.sp,
283
- cog: u.co,
284
- hdg: u.hdg,
285
- positionTime: S.unix(),
286
- utc: S.utc().format(),
287
- status: u.status,
288
- labelCn: T,
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
- }, N = Math.floor(S.diff(g, "minute", !0) / (n || 1));
293
- N !== w && (w = N, j.push(L));
292
+ }, T = Math.floor(b.diff(p, "minute", !0) / (n || 1));
293
+ T !== Y && (Y = T, I.push(W));
294
294
  }
295
- return j;
295
+ return I;
296
296
  }
297
297
  }
298
298
  class Mt extends K {
@@ -308,13 +308,13 @@ class Mt extends K {
308
308
  k: this.token,
309
309
  enc: 1
310
310
  }
311
- }, n = "https://api.shipxy.com/apicall/GetSingleShip", a = await C.get(n, o).json();
312
- if (l == null || l.info("[%s] fetch realtime position from: %s - %j", i.requestId, n, o), (a == null ? void 0 : a.status) !== 0)
311
+ }, n = "https://api.shipxy.com/apicall/GetSingleShip", a = await A.get(n, o).json();
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
315
  for (const y in e)
316
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 = b.unix(e.lasttime);
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,
@@ -339,8 +339,8 @@ class Mt extends K {
339
339
  };
340
340
  }
341
341
  async trajectory(t, i, o, n, a = !0, e = {}) {
342
- var g;
343
- const d = await this.realTimePosition(t, e), r = b(i), c = b(o), h = "https://api.shipxy.com/apicall/GetShipTrack", y = {
342
+ var p;
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,
@@ -349,27 +349,27 @@ class Mt extends K {
349
349
  btm: r.unix(),
350
350
  etm: c.unix()
351
351
  }
352
- }, M = await C.get(h, y).json();
353
- if (l == null || l.info("[%s] fetch trajectory from: %s - %j", e.requestId, h, y), (M == null ? void 0 : M.status) !== 0)
354
- return M;
355
- const f = M == null ? void 0 : M.points, Y = [], j = b.unix((g = f[0]) == null ? void 0 : g.utc);
356
- let w = -1;
357
- for (const m of f) {
358
- const v = b.unix(m.utc), p = {
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
+ return m;
355
+ const f = m == null ? void 0 : m.points, v = [], I = g.unix((p = f[0]) == null ? void 0 : p.utc);
356
+ let Y = -1;
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(m.sog * 3600 / 1e3 / 1852 * 100) / 100,
362
- cog: Math.round(m.cog / 100 * 100) / 100,
363
- lat: Math.round(m.lat / 1e6 * 1e5) / 1e5,
364
- lng: Math.round(m.lon / 1e6 * 1e5) / 1e5,
365
- positionTime: v.unix(),
366
- utc: v.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
- }, u = Math.floor(v.diff(j, "minute", !0) / (n || 1));
370
- u !== w && (w = u, Y.push(p));
369
+ }, M = Math.floor(w.diff(I, "minute", !0) / (n || 1));
370
+ M !== Y && (Y = M, v.push(j));
371
371
  }
372
- return Y;
372
+ return v;
373
373
  }
374
374
  }
375
375
  class yt extends K {
@@ -386,8 +386,8 @@ class yt extends K {
386
386
  json: {
387
387
  mmsiList: t
388
388
  }
389
- }, n = "https://api3.myships.com/sp/ships/getShipIdByMMSI", a = await C.post(n, o).json();
390
- return l == null || l.info("[%s] fetch ship id from: %s - %j", i.requestId, n, o), a.code !== "0" ? a : a.data[0].shipId;
389
+ }, n = "https://api3.myships.com/sp/ships/getShipIdByMMSI", a = await A.post(n, o).json();
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 = {
@@ -397,12 +397,12 @@ class yt extends K {
397
397
  json: {
398
398
  shipId: t
399
399
  }
400
- }, n = "https://api3.myships.com/sp/ships/aissta", a = await C.post(n, o).json();
401
- if (l == null || l.info("[%s] fetch ship info from: %s - %j", i.requestId, n, o), a.code !== "0")
400
+ }, n = "https://api3.myships.com/sp/ships/aissta", a = await A.post(n, o).json();
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", l == null || l.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,
@@ -420,12 +420,12 @@ class yt extends K {
420
420
  json: {
421
421
  shipId: o
422
422
  }
423
- }, e = "https://api3.myships.com/sp/ships/position/latest", d = await C.post(e, a).json();
424
- l == null || l.info("[%s] fetch realtime position from: %s - %j", i.requestId, e, a);
423
+ }, e = "https://api3.myships.com/sp/ships/position/latest", d = await A.post(e, a).json();
424
+ h == null || h.info("[%s] fetch realtime position from: %s - %j", i.requestId, e, a);
425
425
  const r = d.data[0];
426
426
  for (const f in r)
427
427
  !isNaN(r[f]) && Number(r[f]) !== 1 / 0 && (r[f] = Number(r[f]));
428
- const { labelCn: c, labelEn: h } = await this.parseStatus(r.aisNavStatus), y = b.unix(r.posTime);
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,
@@ -438,20 +438,20 @@ class yt extends K {
438
438
  positionTime: r.posTime,
439
439
  utc: y.utc().format(),
440
440
  status: r.aisNavStatus,
441
- labelEn: h,
441
+ labelEn: u,
442
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), r = b(o), c = await this.getShipId(t), h = await this.getShipInfo(c), y = [];
448
+ const d = g(i), r = g(o), c = await this.getShipId(t), u = await this.getShipInfo(c), y = [];
449
449
  for (; r.diff(d, "day", !0) > 30; )
450
- await this.trajectoryIn30Day(c, d.unix(), d.add(30, "day").unix(), h, t, n, y);
451
- return await this.trajectoryIn30Day(c, d.unix(), r.unix(), h, t, n, y), y;
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
453
  async trajectoryIn30Day(t, i, o, n, a, e, d, r = {}) {
454
- var j;
454
+ var I;
455
455
  const c = {
456
456
  headers: {
457
457
  appKey: this.token
@@ -461,37 +461,37 @@ class yt extends K {
461
461
  startTime: i,
462
462
  endTime: o
463
463
  }
464
- }, h = "https://api3.myships.com/sp/ships/position/history", y = await C.post(h, c).json();
465
- if (l == null || l.info("[%s] fetch trajectory from: %s - %j", r.requestId, h, c), y.code !== "0")
466
- return l == null || l.warn("[%s] invoke myship trajectory failed: %j", r.requestId, y), y;
467
- const M = y.data;
468
- for (const w in M)
469
- !isNaN(M[w]) && Number(M[w]) !== 1 / 0 && (M[w] = Number(M[w]));
470
- const f = b.unix((j = M[0]) == null ? void 0 : j.posTime);
471
- let Y = -1;
472
- for (const w of M) {
473
- const g = b.unix(w.posTime), m = {
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
+ for (const Y in m)
469
+ !isNaN(m[Y]) && Number(m[Y]) !== 1 / 0 && (m[Y] = Number(m[Y]));
470
+ const f = g.unix((I = m[0]) == null ? void 0 : I.posTime);
471
+ let v = -1;
472
+ for (const Y of m) {
473
+ const p = g.unix(Y.posTime), l = {
474
474
  imo: n == null ? void 0 : n.imo,
475
475
  mmsi: a,
476
- lat: Math.round(w.lat / 1e4 / 60 * 1e5) / 1e5,
477
- lng: Math.round(w.lon / 1e4 / 60 * 1e5) / 1e5,
478
- sog: Math.round(w.sog / 10 * 100) / 100,
479
- cog: Math.round(w.cog / 10 * 100) / 100,
480
- hdg: Math.round(w.heading * 100) / 100,
481
- rot: Math.round(w.rot * 100) / 100,
482
- positionTime: g.unix(),
483
- utc: g.utc().format(),
476
+ lat: Math.round(Y.lat / 1e4 / 60 * 1e5) / 1e5,
477
+ lng: Math.round(Y.lon / 1e4 / 60 * 1e5) / 1e5,
478
+ sog: Math.round(Y.sog / 10 * 100) / 100,
479
+ cog: Math.round(Y.cog / 10 * 100) / 100,
480
+ hdg: Math.round(Y.heading * 100) / 100,
481
+ rot: Math.round(Y.rot * 100) / 100,
482
+ positionTime: p.unix(),
483
+ utc: p.utc().format(),
484
484
  method: "trajectory",
485
485
  vendor: "myship"
486
- }, v = Math.floor(g.diff(f, "minute", !0) / (e || 1));
487
- v !== Y && (Y = v, d.push(m));
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
  }
491
491
  }
492
- let P;
492
+ let R;
493
493
  try {
494
- P = z.getLogger("vessel");
494
+ R = z.getLogger("vessel");
495
495
  } catch {
496
496
  } finally {
497
497
  }
@@ -507,18 +507,18 @@ class ot {
507
507
  */
508
508
  parsePrinciple(s, t = {}) {
509
509
  var e, d, r;
510
- P == null || P.info("[%s] parse rule: %s", t.requestId, s);
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
515
  for (let c = 0; c < (n == null ? void 0 : n.length); c++) {
516
- const h = (r = (d = n[c].match(i)) == null ? void 0 : d[0]) == null ? void 0 : r.split("],");
517
- if (c === 0 && !h)
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 (h)
520
- for (let y = 0, M = h.length; y < M; y++) {
521
- const f = this.parseRule(h[y]);
519
+ else if (u)
520
+ for (let y = 0, m = u.length; y < m; y++) {
521
+ const f = this.parseRule(u[y]);
522
522
  f && (a[f.level] ? f.key ? a[f.level][f == null ? void 0 : f.key] = f : a[f.level] = f : f.key ? a[f.level] = { [f == null ? void 0 : f.key]: f } : a[f.level] = f);
523
523
  }
524
524
  }
@@ -532,7 +532,7 @@ class ot {
532
532
  */
533
533
  parseRule(s, t = {}) {
534
534
  var a;
535
- P == null || P.info("[%s] parse rule: %s", t.requestId, s), s = s.startsWith("[") ? s : `[${s}`, s = s.endsWith("]") ? s : `${s}]`;
535
+ R == null || R.info("[%s] parse rule: %s", t.requestId, s), s = s.startsWith("[") ? s : `[${s}`, s = s.endsWith("]") ? s : `${s}]`;
536
536
  const i = new RegExp("(?<=\\[)(.+?)(?=])", "g"), o = (a = s == null ? void 0 : s.match(i)) == null ? void 0 : a[0], n = o == null ? void 0 : o.split(",");
537
537
  if (n)
538
538
  return {
@@ -550,17 +550,17 @@ class ot {
550
550
  * @param options
551
551
  */
552
552
  checkWeather(s, t, i = {}) {
553
- var f, Y, j, w, g, m, v, p, u, S, W, T, L, N, R;
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(((Y = (f = t == null ? void 0 : t.SEVERE) == null ? void 0 : f.sigWave) == null ? void 0 : Y.number) * 1.6 * 100) / 100, r = (w = (j = t == null ? void 0 : t.SEVERE) == null ? void 0 : j.sigWave) == null ? void 0 : w.number, c = (m = (g = t == null ? void 0 : t.HEAVY) == null ? void 0 : g.sigWave) == null ? void 0 : m.number, h = Math.round((((p = (v = t == null ? void 0 : t.SEVERE) == null ? void 0 : v.wind) == null ? void 0 : p.number) + 2) * 100) / 100, y = (S = (u = t == null ? void 0 : t.SEVERE) == null ? void 0 : u.wind) == null ? void 0 : S.number, M = (T = (W = t == null ? void 0 : t.HEAVY) == null ? void 0 : W.wind) == null ? void 0 : T.number;
556
- for (let A = 0; A < (s == null ? void 0 : s.length); A++) {
557
- const I = s[A], D = (N = (L = I == null ? void 0 : I.meteo) == null ? void 0 : L.wave) == null ? void 0 : N.sig, q = (R = I == null ? void 0 : I.meteo) == null ? void 0 : R.wind, _ = A ? b(I.eta).diff(b(s[A - 1].eta), "hour", !0) : 0;
558
- e = _ > e ? _ : e, P == null || P.info("[%s] check sig.wave: %j", i.requestId, { ...D, dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: c }), (D == null ? void 0 : D.height) >= d ? I.isDangerous = !0 : (D == null ? void 0 : D.height) >= r ? I.isSevere = !0 : (D == null ? void 0 : D.height) >= c && (I.isHeavy = !0), P == null || P.info("[%s] check wind: %j", i.requestId, { ...q, dgThd4Wd: h, svThd4Wd: y, hvThd4Wd: M }), (q == null ? void 0 : q.scale) >= h ? (I.isDangerous = !0, delete I.isSevere, delete I.isHeavy) : (q == null ? void 0 : q.scale) > y ? (I.isDangerous || (I.isSevere = !0), delete I.isHeavy) : (q == null ? void 0 : q.scale) === M && !I.isDangerous && !I.isSevere && (I.isHeavy = !0), o += I.isDangerous ? _ : 0, n += I.isSevere ? _ : 0, a += I.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: h, svThd4Wd: y, hvThd4Wd: M }, sig: { dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: c } };
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");
@@ -568,7 +568,7 @@ try {
568
568
  } finally {
569
569
  }
570
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 E {
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 E {
678
678
  * @private
679
679
  */
680
680
  static assembleProperties(s, t, i, o) {
681
- var c, h;
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: ((h = (c = s == null ? void 0 : s.type) == null ? void 0 : c.toLowerCase()) == null ? void 0 : h.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,
@@ -708,12 +708,12 @@ class E {
708
708
  static async speedLoseAt(s, t, i, o = "", n = 2, a = !0, e = !1, d = {}) {
709
709
  let r;
710
710
  if (t.velocity && e && (s.speed = B.roundPrecision(t.velocity * 1852 / 3600, 6)), a) {
711
- const c = await st.queryPointFactor(t.lng, t.lat, i.valueOf(), "wind,wave,current,watertemp", o, d), h = E.weatherFactor(s, c), y = E.currentFactor(s.bearing, c == null ? void 0 : c.current, n);
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
712
  r = {
713
713
  meteo: { ...c },
714
- wxFactor: h,
714
+ wxFactor: u,
715
715
  cFactor: y,
716
- speed: t.velocity && e ? t.velocity : Math.round((s.speed * 1.943844 + h + y) * 100) / 100,
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
  };
@@ -742,50 +742,50 @@ class E {
742
742
  */
743
743
  static async speedLoseInHoursStep(s, t, i, o, n, a, e = "", d = !0, r = !1, c = {}) {
744
744
  t.utc();
745
- const h = [], y = [];
746
- let M = 0, f = 0, Y, j;
747
- for (let w = 0; w < a.length - 1; w++) {
748
- let g = a[w];
749
- g.distanceFromStart = n + f;
750
- const m = a[w + 1];
751
- if (s.bearing = O.calculateBearing(g, m, !m.gcToPrevious), g.bearing = s.bearing, g.suspend && r) {
752
- g.eta = g.eta || t.format("YYYY-MM-DDTHH:mm[Z]"), g.elapsed = g.elapsed ?? 0;
753
- const u = g.suspend - g.elapsed;
754
- if (o - M > u)
755
- o = o - M - u, t.add(u, "hour"), g.elapsed = g.suspend;
745
+ const u = [], y = [];
746
+ let m = 0, f = 0, v, I;
747
+ for (let Y = 0; Y < a.length - 1; Y++) {
748
+ let p = a[Y];
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
+ p.eta = p.eta || t.format("YYYY-MM-DDTHH:mm[Z]"), p.elapsed = p.elapsed ?? 0;
753
+ const M = p.suspend - p.elapsed;
754
+ if (o - m > M)
755
+ o = o - m - M, t.add(M, "hour"), p.elapsed = p.suspend;
756
756
  else {
757
- const S = o - M;
758
- g.elapsed += S, t.add(S, "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 ${g.elapsed} hours at %j, and remain ${o} hours need to go...`, c.requestId, g), o === 0)
761
- return g.distanceFromPrevious = f, { etd: t, from: j || g, to: g, next: a.filter((S) => S), wps: h, days: y };
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
- g = await E.speedLoseAt(s, g, t, e, 0, d, r, c), j = j || g, g.important && h.push(g), t.isSameOrAfter(i) && (y.push(g), i.add(24, "hour"));
764
- const v = O.calculateDistance(g, m, !m.gcToPrevious);
765
- let p = Math.ceil(v / j.speed * 1e4) / 1e4;
766
- if (M + p < o) {
767
- if (M += p, t.add(p, "hour"), delete a[w], H == null || H.info(
768
- `[%s] go to %j from %j with ${v}nm, and cost ${p} hours`,
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
769
  c.requestId,
770
- { lat: m.lat, lng: m.lng },
771
- { lat: j.lat, lng: j.lng, etd: j.etd }
772
- ), f += v, a.filter((u) => u).length <= 1) {
773
- Y = m, Y.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), Y.distanceFromPrevious = v, Y.distanceFromStart = n + f, h.push(Y), delete a[w + 1];
770
+ { lat: l.lat, lng: l.lng },
771
+ { lat: I.lat, lng: I.lng, etd: I.etd }
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
- p = o - M, t.add(p, "hour");
778
- const u = B.roundPrecision(j.speed * p, 4);
779
- Y = O.calculateCoordinate(g, s.bearing, u, "nauticalmiles", !m.gcToPrevious), Y.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), a[w] = Y, H == null || H.info(
780
- `[%s] go to %j from %j with ${u}nm, and cost ${p} hours`,
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
781
  c.requestId,
782
- { lat: Y.lat, lng: Y.lng },
783
- { lat: g.lat, lng: g.lng, etd: g.etd }
784
- ), f += u, Y.distanceFromPrevious = f, Y.distanceFromStart = n + f;
782
+ { lat: v.lat, lng: v.lng },
783
+ { lat: p.lat, lng: p.lng, etd: p.etd }
784
+ ), f += M, v.distanceFromPrevious = f, v.distanceFromStart = n + f;
785
785
  break;
786
786
  }
787
787
  }
788
- return { etd: t, from: j, to: Y, next: a.filter((w) => w), wps: h, days: y };
788
+ return { etd: t, from: I, to: v, next: a.filter((Y) => Y), wps: u, days: y };
789
789
  }
790
790
  /**
791
791
  * 洋流影响因子
@@ -806,15 +806,15 @@ class E {
806
806
  * @param wwc 气象要素
807
807
  */
808
808
  static weatherFactor(s, t) {
809
- var h, y, M, f, Y;
809
+ var u, y, m, f, v;
810
810
  H == null || H.debug("calculate weather factor via: %j", { ...s, ...t });
811
- const i = E.blockCoefficient(s.displacement, s.lbp, s.breadthMoulded, s.draught), o = E.froudeNumber(s.speed, s.lbp), n = E.amendFactor(i, o, s.loadCondition);
812
- let a = Math.abs(s.bearing % 360 - (((h = t == null ? void 0 : t.wind) == null ? void 0 : h.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 = E.directionFactor(a, (y = t == null ? void 0 : t.wind) == null ? void 0 : y.scale), d = E.vesselTagFactor(s.displacement, s.loadCondition, s.tag, (M = t == null ? void 0 : t.wind) == null ? void 0 : M.scale);
814
+ const e = C.directionFactor(a, (y = t == null ? void 0 : t.wind) == null ? void 0 : y.scale), d = C.vesselTagFactor(s.displacement, s.loadCondition, s.tag, (m = t == null ? void 0 : t.wind) == null ? void 0 : m.scale);
815
815
  let r = e * n * d / 100 * s.speed;
816
816
  r = Math.round(r * 1.943844 * 1e4) / 1e4 * -1;
817
- const c = E.waveHeightFactor(((Y = (f = t == null ? void 0 : t.wave) == null ? void 0 : f.sig) == null ? void 0 : Y.height) ?? 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
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
  /**
@@ -830,13 +830,13 @@ class E {
830
830
  * @param useRouteParam
831
831
  */
832
832
  static async analyseInstant(s, t, i, o, n, a = "", e = 0, d = !0, r = !1, c = {}) {
833
- var _, G, U, J, Q;
834
- const h = b().valueOf();
833
+ var F, G, U, J, Q;
834
+ const u = g().valueOf();
835
835
  s.lng = B.convertToStdLng(s.lng);
836
- const { route: y, waypoints: M } = n.points, f = O.calculateSubRoute(s, y);
837
- if (((_ = f[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
- const { v0: Y, label: j } = s.sog ? {
839
+ const { v0: v, label: I } = s.sog ? {
840
840
  v0: s.sog,
841
841
  label: "Other"
842
842
  /* Instruct */
@@ -844,51 +844,51 @@ class E {
844
844
  v0: o.speed,
845
845
  label: "CP"
846
846
  /* Cp */
847
- }, w = E.assembleProperties(i, o.loadCondition, Y, 0), g = M.length ? O.calculateSubWaypoints(s, M) : [], m = {
847
+ }, Y = C.assembleProperties(i, o.loadCondition, v, 0), p = m.length ? L.calculateSubWaypoints(s, m) : [], l = {
848
848
  from: { ...s },
849
849
  route: f,
850
- waypoints: g,
851
- v0: Y,
852
- label: j
853
- }, v = {
850
+ waypoints: p,
851
+ v0: v,
852
+ label: I
853
+ }, w = {
854
854
  hours: [],
855
855
  days: [],
856
856
  wps: []
857
857
  };
858
- e || (O.calculateRouteDistance(f) / o.speed <= 72 ? e = 3 : e = 6);
859
- let p = O.simplifyRouteToCoordinates(f, g, 0), u = 0, S = 0, W = 0, T = 0;
860
- t = b(t).utc();
861
- const L = t.clone();
862
- for (; p.length > 0; ) {
863
- const F = e - t.hour() % e, V = Math.ceil(t.clone().add(F, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4, x = await E.speedLoseInHoursStep(
864
- w,
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
+ Y,
865
865
  t,
866
- L,
867
- V,
868
- u,
869
- p,
866
+ W,
867
+ _,
868
+ M,
869
+ j,
870
870
  a,
871
871
  d,
872
872
  r,
873
873
  c
874
874
  );
875
- (G = x.from) != null && G.speed && (v.hours.push(x.from), v.wps.push(...x.wps), v.days.push(...x.days)), p = x == null ? void 0 : x.next, p.length || v.hours.push(x == null ? void 0 : x.to), u += ((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 N = v.hours;
878
- for (let F = 0; F < N.length - 1; F++) {
879
- const V = b(N[F + 1].eta).diff(N[F].etd, "hour", !0) || 1;
880
- S += N[F].wxFactor || 0 * V, W += N[F].cFactor || 0 * V, T += 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 = v.wps) == null || J.forEach((F, V) => {
883
- if (V) {
884
- const x = v.wps[V - 1], $ = F.distanceFromStart - x.distanceFromStart, X = b(F.eta).diff(b(x.etd), "h", !0);
885
- X < 1 ? F.avgSpd = x.speed : F.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
- }), m.sample = v;
888
- const R = v.hours.at(0), A = v.hours.at(-1);
889
- m.distance = Math.round(A.distanceFromStart * 1e4) / 1e4, m.etd = b(R.eta).utc().format(), m.eta = b(A.eta).utc().format(), m.wxFactor = Math.round(S / T * 1e4) / 1e4, m.cFactor = Math.round(W / T * 1e4) / 1e4, m.avgSpeed = Math.round(A.distanceFromStart / T * 1e4) / 1e4, m.totalHrs = Math.round(T * 1e4) / 1e4, m.totalFoCons = Math.round((o == null ? void 0 : o.fo) / 24 * m.totalHrs * 1e3) / 1e3, m.totalDgoCons = Math.round((o == null ? void 0 : o.dgo) / 24 * m.totalHrs * 1e3) / 1e3;
890
- const D = b().valueOf() - h, q = ((Q = v == null ? void 0 : v.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, D, q, Math.round(D / q * 1e3) / 1e3), m;
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,60 +903,71 @@ class E {
903
903
  * @param useMeteo true 启用气象分析
904
904
  * @param useRouteParam
905
905
  */
906
- static async analyseInstantWithThreshed(s, t, i, o, n, a, e, d = "", r = 3, c = !0, h = !1, y = {}) {
907
- var N, R, A;
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 = E.assembleProperties(o, n.loadCondition, n.speed, 0), f = O.calculateSubRoute(s, a);
910
- if (((N = f[0]) == null ? void 0 : N.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
- const Y = e.length ? O.calculateSubWaypoints(s, e) : [];
913
- let j = O.simplifyRouteToCoordinates(f, Y, 0);
914
- j.forEach((I) => I.important = !0);
915
- let w = 0, g = 0, m = 0, v = 0, p;
916
- const u = {
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 = {
917
924
  hours: [],
918
925
  wps: [],
919
926
  days: []
920
927
  };
921
- for (t = b(t).utc(); j.length > 0; ) {
922
- const I = r - t.hour() % r;
923
- let D = Math.ceil(t.clone().add(I, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4;
924
- if (D = t.clone().add(D, "h").isAfter(i) ? i.diff(t, "h", !0) * 1e4 / 1e4 : D, D)
925
- p = await E.speedLoseInHoursStep(
926
- 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,
927
934
  t,
928
935
  i.clone(),
929
- D,
930
- w,
931
- j,
936
+ F,
937
+ l,
938
+ p,
932
939
  d,
933
940
  c,
934
- h,
941
+ u,
935
942
  y
936
- ), (R = p.from) != null && R.speed && (u.hours.push(p.from), p != null && p.wps && u.wps.push(...p.wps), u.days.push(...p.days)), j = p == null ? void 0 : p.next, j.length || (u.hours.push(p == null ? void 0 : p.to), p != null && p.wps && u.wps.push(...p.wps), u.days.push(p == null ? void 0 : p.to)), w += ((A = p == null ? void 0 : p.to) == null ? void 0 : A.distanceFromPrevious) ?? 0;
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;
937
944
  else {
938
- p && (u.hours.push(p.to), p != null && p.wps && u.wps.push(...p.wps), u.days.push(p.to));
945
+ b && (N.hours.push(b.to), b != null && b.wps && N.wps.push(...b.wps), N.days.push(b.to));
939
946
  break;
940
947
  }
941
948
  }
942
- const S = u.hours;
943
- for (let I = 0; I < S.length - 1; I++) {
944
- const D = b(S[I + 1].eta).diff(S[I].etd, "hour", !0);
945
- g += S[I].wxFactor * D, m += S[I].cFactor * D, v += D;
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;
946
953
  }
947
- const W = u.hours.at(0), T = u.hours.at(-1);
954
+ const W = N.hours.at(0), T = N.hours.at(-1);
948
955
  return {
949
- sample: u,
956
+ sample: N,
950
957
  distance: Math.round(((T == null ? void 0 : T.distanceFromStart) || 0) * 1e4) / 1e4,
951
958
  // 注意,可能会在first节点Drift,所有采用eta做为初始出发时间
952
- etd: b(W.eta).utc().format(),
953
- eta: b(T == null ? void 0 : T.eta).utc().format(),
954
- wxFactor: Math.round(g / v * 1e4) / 1e4,
955
- cFactor: Math.round(m / v * 1e4) / 1e4,
956
- avgSpeed: Math.round(((T == null ? void 0 : T.distanceFromStart) || 0) / v * 1e4) / 1e4,
957
- totalHrs: Math.round(v * 1e4) / 1e4,
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,
958
966
  to: T,
959
- route: O.generateRouteAccordingToWaypoints(j)
967
+ route: L.generateRouteAccordingToWaypoints(p),
968
+ subWaypoints: Y,
969
+ v0: m,
970
+ label: f
960
971
  };
961
972
  }
962
973
  }
@@ -969,8 +980,8 @@ export {
969
980
  yt as MyShipImpl,
970
981
  mt as MyVesselImpl,
971
982
  Mt as ShipxyImpl,
972
- E as SpeedHelper,
983
+ C as SpeedHelper,
973
984
  rt as SpeedLabel,
974
985
  nt as VesselTag,
975
- gt as alertHelper
986
+ bt as alertHelper
976
987
  };
@@ -1 +1 @@
1
- (function(H,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):(H=typeof globalThis<"u"?globalThis:H||self,T(H["idm-plugin-rabbitmq"]={},H.got,H["@log4js-node/log4js-api"],H.moment,H["@idm-plugin/geo"],H["@idm-plugin/meteo"]))})(this,function(H,T,_,v,E,nt){"use strict";var ht=Object.defineProperty;var lt=(H,T,_)=>T in H?ht(H,T,{enumerable:!0,configurable:!0,writable:!0,value:_}):H[T]=_;var K=(H,T,_)=>(lt(H,typeof T!="symbol"?T+"":T,_),_);let h;try{h=_.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 T.post(i,n).json();h==null||h.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,l,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:`${(l=this.token)==null?void 0:l.tokenType} ${(M=this.token)==null?void 0:M.accessToken}`},searchParams:{mmsi:t}};h==null||h.info("[%s] fetch realtime position from: %s - %j",i.requestId,n,o);const a=await T.get(n,o).json();if(a.code)return h==null||h.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 y in e)!isNaN(e[y])&&Number(e[y])!==1/0&&(e[y]=Number(e[y]));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),l=[];for(;c.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(t,r,r.clone().add(30,"day"),d,o,l,e),r.add(30,"day");return await this.trajectoryIn30Day(t,r,c,d,o,l,e),l}async trajectoryIn30Day(t,i,n,o,a,e,d={}){var f,Y,w,I,b;const r="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",c={headers:{Authorization:`${(f=this.token)==null?void 0:f.tokenType} ${(Y=this.token)==null?void 0:Y.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")}};h==null||h.info("[%s] fetch trajectory from: %s - %j",d.requestId,r,c);const l=await T.post(r,c).json();if(l.code)return h==null||h.warn("[%s] fetch trajectory failed: %j",d.requestId,r,{message:l.message,status:l.status,code:l.code}),l;let M=-1;const y=v(`${(I=(w=l.data)==null?void 0:w[0])==null?void 0:I.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(b=l.data)==null||b.forEach(m=>{for(const q in m)!isNaN(m[q])&&Number(m[q])!==1/0&&(m[q]=Number(m[q]));const g=v(`${m.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),p=m.eta?v(`${m.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,u=m.status,{labelCn:N,labelEn:W}=this.parseStatus(u),S={mmsi:m.mmsi,imo:o==null?void 0:o.imo,lat:m.lat,lng:m.lon,sog:m.sog,cog:m.cog,hdg:m.hdg,draught:m.draught,status:u,eta:p==null?void 0:p.unix(),destination:m.dest,positionTime:g.unix(),labelCn:N,labelEn:W,method:"trajectory",vendor:"myVessel",utc:g.utc().format()},V=Math.floor(g.diff(y,"minute",!0)/(a||1));V!==M&&(M=V,e.push(S))}),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 T.post(n,o).json();h==null||h.info("[%s] fetch realtime position from: %s - %j",i.requestId,n,o);const e=a==null?void 0:a.list;if(!e)return h==null||h.warn("[%s] fetch realtime position failed: %j",i.requestId,n,a),a;for(const y in e)!isNaN(e[y])&&Number(e[y])!==1/0&&(e[y]=Number(e[y]));e.status=e.sp>3?0:1;const d=e.status,{labelCn:r,labelEn:c}=this.parseStatus(d),l=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:l.unix(),utc:l.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 T.post(n,o).json();h==null||h.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 T.post(n,o).json(),h==null||h.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 m,g,p;const d=await this.realTimePosition(t,e);let r=v(i);const c=v(n),l=v();if(a){let u=c.diff(r,"d",!0);u<0?r=c.clone().subtract(40,"d"):u<30?r.subtract(10,"d"):u<60?r.subtract(5,"d"):r=c.clone().subtract(80,"d"),u=l.diff(c,"d",!0),c.add(u>10?240:u*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}},y="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",f=await T.get(y,M).json();h==null||h.info("[%s] fetch trajectory from: %s - %j",e.requestId,y,M);let Y;f&&(Y=((g=(m=f.ships)==null?void 0:m.offors)==null?void 0:g.ship)||[],Y.length||h==null||h.warn("[%s] fetch trajectory failed: %j",e.requestId,f));const w=[];let I=-1;const b=v(`${(p=Y==null?void 0:Y[0])==null?void 0:p.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const u of Y){for(const R in u)!isNaN(u[R])&&Number(u[R])!==1/0&&(u[R]=Number(u[R]));const N=v(`${u.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");u.status=u.sp>4?0:1;const{labelEn:W,labelCn:S}=this.parseStatus(u.status),V={mmsi:u.m,name:u.n,imo:d==null?void 0:d.imo,lat:u.la,lng:u.lo,draught:u.draught,sog:u.sp,cog:u.co,hdg:u.hdg,positionTime:N.unix(),utc:N.utc().format(),status:u.status,labelCn:S,labelEn:W,method:"trajectory",vendor:"hifleet"},q=Math.floor(N.diff(b,"minute",!0)/(o||1));q!==I&&(I=q,w.push(V))}return w}}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 T.get(o,n).json();if(h==null||h.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 b;const d=await this.realTimePosition(t,e),r=v(i),c=v(n),l="https://api.shipxy.com/apicall/GetShipTrack",M={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:r.unix(),etm:c.unix()}},y=await T.get(l,M).json();if(h==null||h.info("[%s] fetch trajectory from: %s - %j",e.requestId,l,M),(y==null?void 0:y.status)!==0)return y;const f=y==null?void 0:y.points,Y=[],w=v.unix((b=f[0])==null?void 0:b.utc);let I=-1;for(const m of f){const g=v.unix(m.utc),p={imo:d==null?void 0:d.imo,mmsi:t,sog:Math.round(m.sog*3600/1e3/1852*100)/100,cog:Math.round(m.cog/100*100)/100,lat:Math.round(m.lat/1e6*1e5)/1e5,lng:Math.round(m.lon/1e6*1e5)/1e5,positionTime:g.unix(),utc:g.utc().format(),method:"trajectory",vendor:"shipxy"},u=Math.floor(g.diff(w,"minute",!0)/(o||1));u!==I&&(I=u,Y.push(p))}return Y}}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 T.post(o,n).json();return h==null||h.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 T.post(o,n).json();if(h==null||h.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",h==null||h.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 T.post(e,a).json();h==null||h.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:l}=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:l,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),l=await this.getShipInfo(c),M=[];for(;r.diff(d,"day",!0)>30;)await this.trajectoryIn30Day(c,d.unix(),d.add(30,"day").unix(),l,t,o,M);return await this.trajectoryIn30Day(c,d.unix(),r.unix(),l,t,o,M),M}async trajectoryIn30Day(t,i,n,o,a,e,d,r={}){var w;const c={headers:{appKey:this.token},json:{shipId:t,startTime:i,endTime:n}},l="https://api3.myships.com/sp/ships/position/history",M=await T.post(l,c).json();if(h==null||h.info("[%s] fetch trajectory from: %s - %j",r.requestId,l,c),M.code!=="0")return h==null||h.warn("[%s] invoke myship trajectory failed: %j",r.requestId,M),M;const y=M.data;for(const I in y)!isNaN(y[I])&&Number(y[I])!==1/0&&(y[I]=Number(y[I]));const f=v.unix((w=y[0])==null?void 0:w.posTime);let Y=-1;for(const I of y){const b=v.unix(I.posTime),m={imo:o==null?void 0:o.imo,mmsi:a,lat:Math.round(I.lat/1e4/60*1e5)/1e5,lng:Math.round(I.lon/1e4/60*1e5)/1e5,sog:Math.round(I.sog/10*100)/100,cog:Math.round(I.cog/10*100)/100,hdg:Math.round(I.heading*100)/100,rot:Math.round(I.rot*100)/100,positionTime:b.unix(),utc:b.utc().format(),method:"trajectory",vendor:"myship"},g=Math.floor(b.diff(f,"minute",!0)/(e||1));g!==Y&&(Y=g,d.push(m))}return d}}let C;try{C=_.getLogger("vessel")}catch{}finally{}var G=(k=>(k.NOTICE="NOTICE",k.WARN="WARN",k.HEAVY="HEAVY",k.SEVERE="SEVERE",k.ERROR="ERROR",k.FATAL="FATAL",k))(G||{});class U{parsePrinciple(s,t={}){var e,d,r;C==null||C.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 l=(r=(d=o[c].match(i))==null?void 0:d[0])==null?void 0:r.split("],");if(c===0&&!l)a.scope=o[0];else if(l)for(let M=0,y=l.length;M<y;M++){const f=this.parseRule(l[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;C==null||C.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,Y,w,I,b,m,g,p,u,N,W,S,V,q,R;let n=0,o=0,a=0,e=0;const d=Math.round(((Y=(f=t==null?void 0:t.SEVERE)==null?void 0:f.sigWave)==null?void 0:Y.number)*1.6*100)/100,r=(I=(w=t==null?void 0:t.SEVERE)==null?void 0:w.sigWave)==null?void 0:I.number,c=(m=(b=t==null?void 0:t.HEAVY)==null?void 0:b.sigWave)==null?void 0:m.number,l=Math.round((((p=(g=t==null?void 0:t.SEVERE)==null?void 0:g.wind)==null?void 0:p.number)+2)*100)/100,M=(N=(u=t==null?void 0:t.SEVERE)==null?void 0:u.wind)==null?void 0:N.number,y=(S=(W=t==null?void 0:t.HEAVY)==null?void 0:W.wind)==null?void 0:S.number;for(let O=0;O<(s==null?void 0:s.length);O++){const j=s[O],D=(q=(V=j==null?void 0:j.meteo)==null?void 0:V.wave)==null?void 0:q.sig,A=(R=j==null?void 0:j.meteo)==null?void 0:R.wind,B=O?v(j.eta).diff(v(s[O-1].eta),"hour",!0):0;e=B>e?B:e,C==null||C.info("[%s] check sig.wave: %j",i.requestId,{...D,dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:c}),(D==null?void 0:D.height)>=d?j.isDangerous=!0:(D==null?void 0:D.height)>=r?j.isSevere=!0:(D==null?void 0:D.height)>=c&&(j.isHeavy=!0),C==null||C.info("[%s] check wind: %j",i.requestId,{...A,dgThd4Wd:l,svThd4Wd:M,hvThd4Wd:y}),(A==null?void 0:A.scale)>=l?(j.isDangerous=!0,delete j.isSevere,delete j.isHeavy):(A==null?void 0:A.scale)>M?(j.isDangerous||(j.isSevere=!0),delete j.isHeavy):(A==null?void 0:A.scale)===y&&!j.isDangerous&&!j.isSevere&&(j.isHeavy=!0),n+=j.isDangerous?B:0,o+=j.isSevere?B:0,a+=j.isHeavy?B: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:l,svThd4Wd:M,hvThd4Wd:y},sig:{dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:c}}}}const dt=new U;let F;try{F=_.getLogger("vessel")}catch{}finally{}var J=(k=>(k.common="common",k.container="container",k))(J||{}),Q=(k=>(k.Ballast="Ballast",k.Laden="Laden",k))(Q||{}),X=(k=>(k.Cp="CP",k.Perf="Basis",k.Instruct="Other",k))(X||{});class L{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,l;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:((l=(c=s==null?void 0:s.type)==null?void 0:c.toLowerCase())==null?void 0:l.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=E.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),l=L.weatherFactor(s,c),M=L.currentFactor(s.bearing,c==null?void 0:c.current,o);r={meteo:{...c},wxFactor:l,cFactor:M,speed:t.velocity&&e?t.velocity:Math.round((s.speed*1.943844+l+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 l=[],M=[];let y=0,f=0,Y,w;for(let I=0;I<a.length-1;I++){let b=a[I];b.distanceFromStart=o+f;const m=a[I+1];if(s.bearing=E.LaneHelper.calculateBearing(b,m,!m.gcToPrevious),b.bearing=s.bearing,b.suspend&&r){b.eta=b.eta||t.format("YYYY-MM-DDTHH:mm[Z]"),b.elapsed=b.elapsed??0;const u=b.suspend-b.elapsed;if(n-y>u)n=n-y-u,t.add(u,"hour"),b.elapsed=b.suspend;else{const N=n-y;b.elapsed+=N,t.add(N,"hour"),n=0}if(F==null||F.info(`[%s] suspend ${b.elapsed} hours at %j, and remain ${n} hours need to go...`,c.requestId,b),n===0)return b.distanceFromPrevious=f,{etd:t,from:w||b,to:b,next:a.filter(N=>N),wps:l,days:M}}b=await L.speedLoseAt(s,b,t,e,0,d,r,c),w=w||b,b.important&&l.push(b),t.isSameOrAfter(i)&&(M.push(b),i.add(24,"hour"));const g=E.LaneHelper.calculateDistance(b,m,!m.gcToPrevious);let p=Math.ceil(g/w.speed*1e4)/1e4;if(y+p<n){if(y+=p,t.add(p,"hour"),delete a[I],F==null||F.info(`[%s] go to %j from %j with ${g}nm, and cost ${p} hours`,c.requestId,{lat:m.lat,lng:m.lng},{lat:w.lat,lng:w.lng,etd:w.etd}),f+=g,a.filter(u=>u).length<=1){Y=m,Y.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),Y.distanceFromPrevious=g,Y.distanceFromStart=o+f,l.push(Y),delete a[I+1];break}}else{p=n-y,t.add(p,"hour");const u=E.LngLatHelper.roundPrecision(w.speed*p,4);Y=E.LaneHelper.calculateCoordinate(b,s.bearing,u,"nauticalmiles",!m.gcToPrevious),Y.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),a[I]=Y,F==null||F.info(`[%s] go to %j from %j with ${u}nm, and cost ${p} hours`,c.requestId,{lat:Y.lat,lng:Y.lng},{lat:b.lat,lng:b.lng,etd:b.etd}),f+=u,Y.distanceFromPrevious=f,Y.distanceFromStart=o+f;break}}return{etd:t,from:w,to:Y,next:a.filter(I=>I),wps:l,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 l,M,y,f,Y;F==null||F.debug("calculate weather factor via: %j",{...s,...t});const i=L.blockCoefficient(s.displacement,s.lbp,s.breadthMoulded,s.draught),n=L.froudeNumber(s.speed,s.lbp),o=L.amendFactor(i,n,s.loadCondition);let a=Math.abs(s.bearing%360-(((l=t==null?void 0:t.wind)==null?void 0:l.degree)%360||0));a=a>180?360-a:a;const e=L.directionFactor(a,(M=t==null?void 0:t.wind)==null?void 0:M.scale),d=L.vesselTagFactor(s.displacement,s.loadCondition,s.tag,(y=t==null?void 0:t.wind)==null?void 0:y.scale);let r=e*o*d/100*s.speed;r=Math.round(r*1.943844*1e4)/1e4*-1;const c=L.waveHeightFactor(((Y=(f=t==null?void 0:t.wave)==null?void 0:f.sig)==null?void 0:Y.height)??1);return r=r*.24+c*.76,F==null||F.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 B,$,tt,et,st;const l=v().valueOf();s.lng=E.LngLatHelper.convertToStdLng(s.lng);const{route:M,waypoints:y}=o.points,f=E.LaneHelper.calculateSubRoute(s,M);if(((B=f[0])==null?void 0:B.length)<=1)return;const{v0:Y,label:w}=s.sog?{v0:s.sog,label:"Other"}:{v0:n.speed,label:"CP"},I=L.assembleProperties(i,n.loadCondition,Y,0),b=y.length?E.LaneHelper.calculateSubWaypoints(s,y):[],m={from:{...s},route:f,waypoints:b,v0:Y,label:w},g={hours:[],days:[],wps:[]};e||(E.LaneHelper.calculateRouteDistance(f)/n.speed<=72?e=3:e=6);let p=E.LaneHelper.simplifyRouteToCoordinates(f,b,0),u=0,N=0,W=0,S=0;t=v(t).utc();const V=t.clone();for(;p.length>0;){const P=e-t.hour()%e,Z=Math.ceil(t.clone().add(P,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,x=await L.speedLoseInHoursStep(I,t,V,Z,u,p,a,d,r,c);($=x.from)!=null&&$.speed&&(g.hours.push(x.from),g.wps.push(...x.wps),g.days.push(...x.days)),p=x==null?void 0:x.next,p.length||g.hours.push(x==null?void 0:x.to),u+=((tt=x==null?void 0:x.to)==null?void 0:tt.distanceFromPrevious)??0}const q=g.hours;for(let P=0;P<q.length-1;P++){const Z=v(q[P+1].eta).diff(q[P].etd,"hour",!0)||1;N+=q[P].wxFactor||0*Z,W+=q[P].cFactor||0*Z,S+=Z}(et=g.wps)==null||et.forEach((P,Z)=>{if(Z){const x=g.wps[Z-1],ut=P.distanceFromStart-x.distanceFromStart,at=v(P.eta).diff(v(x.etd),"h",!0);at<1?P.avgSpd=x.speed:P.avgSpd=Math.round(ut/at*100)/100}}),m.sample=g;const R=g.hours.at(0),O=g.hours.at(-1);m.distance=Math.round(O.distanceFromStart*1e4)/1e4,m.etd=v(R.eta).utc().format(),m.eta=v(O.eta).utc().format(),m.wxFactor=Math.round(N/S*1e4)/1e4,m.cFactor=Math.round(W/S*1e4)/1e4,m.avgSpeed=Math.round(O.distanceFromStart/S*1e4)/1e4,m.totalHrs=Math.round(S*1e4)/1e4,m.totalFoCons=Math.round((n==null?void 0:n.fo)/24*m.totalHrs*1e3)/1e3,m.totalDgoCons=Math.round((n==null?void 0:n.dgo)/24*m.totalHrs*1e3)/1e3;const D=v().valueOf()-l,A=((st=g==null?void 0:g.hours)==null?void 0:st.length)||1;return F==null||F.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",c==null?void 0:c.requestId,D,A,Math.round(D/A*1e3)/1e3),m}static async analyseInstantWithThreshed(s,t,i,n,o,a,e,d="",r=3,c=!0,l=!1,M={}){var q,R,O;s.lng=E.LngLatHelper.convertToStdLng(s.lng);const y=L.assembleProperties(n,o.loadCondition,o.speed,0),f=E.LaneHelper.calculateSubRoute(s,a);if(((q=f[0])==null?void 0:q.length)<=1)return;const Y=e.length?E.LaneHelper.calculateSubWaypoints(s,e):[];let w=E.LaneHelper.simplifyRouteToCoordinates(f,Y,0);w.forEach(j=>j.important=!0);let I=0,b=0,m=0,g=0,p;const u={hours:[],wps:[],days:[]};for(t=v(t).utc();w.length>0;){const j=r-t.hour()%r;let D=Math.ceil(t.clone().add(j,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;if(D=t.clone().add(D,"h").isAfter(i)?i.diff(t,"h",!0)*1e4/1e4:D,D)p=await L.speedLoseInHoursStep(y,t,i.clone(),D,I,w,d,c,l,M),(R=p.from)!=null&&R.speed&&(u.hours.push(p.from),p!=null&&p.wps&&u.wps.push(...p.wps),u.days.push(...p.days)),w=p==null?void 0:p.next,w.length||(u.hours.push(p==null?void 0:p.to),p!=null&&p.wps&&u.wps.push(...p.wps),u.days.push(p==null?void 0:p.to)),I+=((O=p==null?void 0:p.to)==null?void 0:O.distanceFromPrevious)??0;else{p&&(u.hours.push(p.to),p!=null&&p.wps&&u.wps.push(...p.wps),u.days.push(p.to));break}}const N=u.hours;for(let j=0;j<N.length-1;j++){const D=v(N[j+1].eta).diff(N[j].etd,"hour",!0);b+=N[j].wxFactor*D,m+=N[j].cFactor*D,g+=D}const W=u.hours.at(0),S=u.hours.at(-1);return{sample:u,distance:Math.round(((S==null?void 0:S.distanceFromStart)||0)*1e4)/1e4,etd:v(W.eta).utc().format(),eta:v(S==null?void 0:S.eta).utc().format(),wxFactor:Math.round(b/g*1e4)/1e4,cFactor:Math.round(m/g*1e4)/1e4,avgSpeed:Math.round(((S==null?void 0:S.distanceFromStart)||0)/g*1e4)/1e4,totalHrs:Math.round(g*1e4)/1e4,to:S,route:E.LaneHelper.generateRouteAccordingToWaypoints(w)}}}H.AISImpl=z,H.AlertHelper=U,H.AlertLevel=G,H.HifleetImpl=it,H.LoadCondition=Q,H.MyShipImpl=ct,H.MyVesselImpl=ot,H.ShipxyImpl=rt,H.SpeedHelper=L,H.SpeedLabel=X,H.VesselTag=J,H.alertHelper=dt,Object.defineProperty(H,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"})});
@@ -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.6",
4
+ "version": "1.2.7",
5
5
  "description": "idm plugin for vessel",
6
6
  "type": "module",
7
7
  "keywords": [