@idm-plugin/vessel 1.3.5 → 1.3.6

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 O from "got";
4
+ import R from "got";
5
5
  import z from "@log4js-node/log4js-api";
6
6
  import g from "moment";
7
7
  import { LngLatHelper as B, LaneHelper as V } from "@idm-plugin/geo";
8
8
  import { MeteoHelper as st } from "@idm-plugin/meteo";
9
- let h;
9
+ let d;
10
10
  try {
11
- h = z.getLogger("vessel");
11
+ d = z.getLogger("vessel");
12
12
  } catch {
13
13
  } finally {
14
14
  }
@@ -68,8 +68,8 @@ class mt extends K {
68
68
  client_secret: this.clientSecret,
69
69
  grant_type: "client_credentials"
70
70
  }
71
- }, n = await O.post(i, o).json();
72
- h == null || h.info("[%s] fetch access token from: %s - %j", t.requestId, i, n), n.error || (this.token = {
71
+ }, n = await R.post(i, o).json();
72
+ d == null || d.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,
@@ -79,22 +79,22 @@ class mt extends K {
79
79
  });
80
80
  }
81
81
  async realTimePosition(t, 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);
82
+ var u, l, p;
83
+ (!this.token || g().diff(g(this.token.issuedAt), "seconds") > ((u = this.token) == null ? void 0 : u.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: `${(u = this.token) == null ? void 0 : u.tokenType} ${(y = this.token) == null ? void 0 : y.accessToken}`
86
+ Authorization: `${(l = this.token) == null ? void 0 : l.tokenType} ${(p = this.token) == null ? void 0 : p.accessToken}`
87
87
  },
88
88
  searchParams: { mmsi: t }
89
89
  };
90
- h == null || h.info("[%s] fetch realtime position from: %s - %j", i.requestId, o, n);
91
- const a = await O.get(o, n).json();
90
+ d == null || d.info("[%s] fetch realtime position from: %s - %j", i.requestId, o, n);
91
+ const a = await R.get(o, n).json();
92
92
  if (a.code)
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;
93
+ return d == null || d.warn("[%s] fetch realtime position failed: %j", i.requestId, o, { message: a.message, status: a.status, code: a.code }), a;
94
94
  const e = a.data;
95
95
  for (const f in e)
96
96
  !isNaN(e[f]) && Number(e[f]) !== 1 / 0 && (e[f] = Number(e[f]));
97
- const d = g(`${e.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
97
+ const c = 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,
@@ -111,25 +111,25 @@ class mt extends K {
111
111
  rot: e.rot,
112
112
  eta: e.eta,
113
113
  destination: e.dest,
114
- positionTime: d.unix(),
114
+ positionTime: c.unix(),
115
115
  status: e.status,
116
116
  labelCn: e.statusNameCn,
117
117
  labelEn: e.statusNameEn,
118
118
  method: "position",
119
119
  vendor: "myVessel",
120
- utc: d.utc().format()
120
+ utc: c.utc().format()
121
121
  };
122
122
  }
123
123
  async trajectory(t, i, o, n, a = !0, e = {}) {
124
124
  (!this.token || g().diff(g(this.token.issuedAt), "seconds") > this.token.expiresIn - 300) && await this.authToken(e);
125
- const d = await this.realTimePosition(t, e), r = g(i), c = g(o), u = [];
126
- for (; c.diff(r, "day", !0) > 30; )
127
- await this.trajectoryIn30Day(t, r, r.clone().add(30, "day"), d, n, u, e), r.add(30, "day");
128
- return await this.trajectoryIn30Day(t, r, c, d, n, u, e), u;
129
- }
130
- async trajectoryIn30Day(t, i, o, n, a, e, d = {}) {
131
- var m, v, I, Y, p;
132
- const r = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", c = {
125
+ const c = await this.realTimePosition(t, e), r = g(i), u = g(o), l = [];
126
+ for (; u.diff(r, "day", !0) > 30; )
127
+ await this.trajectoryIn30Day(t, r, r.clone().add(30, "day"), c, n, l, e), r.add(30, "day");
128
+ return await this.trajectoryIn30Day(t, r, u, c, n, l, e), l;
129
+ }
130
+ async trajectoryIn30Day(t, i, o, n, a, e, c = {}) {
131
+ var m, v, I, Y, M;
132
+ const r = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", u = {
133
133
  headers: {
134
134
  Authorization: `${(m = this.token) == null ? void 0 : m.tokenType} ${(v = this.token) == null ? void 0 : v.accessToken}`
135
135
  },
@@ -139,27 +139,27 @@ class mt extends K {
139
139
  endTime: o.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")
140
140
  }
141
141
  };
142
- h == null || h.info("[%s] fetch trajectory from: %s - %j", d.requestId, r, c);
143
- const u = await O.post(r, c).json();
144
- if (u.code)
145
- return h == null || h.warn("[%s] fetch trajectory failed: %j", d.requestId, r, { message: u.message, status: u.status, code: u.code }), u;
146
- let y = -1;
147
- const f = 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,
142
+ d == null || d.info("[%s] fetch trajectory from: %s - %j", c.requestId, r, u);
143
+ const l = await R.post(r, u).json();
144
+ if (l.code)
145
+ return d == null || d.warn("[%s] fetch trajectory failed: %j", c.requestId, r, { message: l.message, status: l.status, code: l.code }), l;
146
+ let p = -1;
147
+ const f = g(`${(Y = (I = l.data) == null ? void 0 : I[0]) == null ? void 0 : Y.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
148
+ return (M = l.data) == null || M.forEach((h) => {
149
+ for (const T in h)
150
+ !isNaN(h[T]) && Number(h[T]) !== 1 / 0 && (h[T] = Number(h[T]));
151
+ const w = g(`${h.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), j = h.eta ? g(`${h.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00") : void 0, y = h.status, { labelCn: b, labelEn: N } = this.parseStatus(y), x = {
152
+ mmsi: h.mmsi,
153
153
  imo: n == null ? void 0 : n.imo,
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,
154
+ lat: h.lat,
155
+ lng: h.lon,
156
+ sog: h.sog,
157
+ cog: h.cog,
158
+ hdg: h.hdg,
159
+ draught: h.draught,
160
+ status: y,
161
161
  eta: j == null ? void 0 : j.unix(),
162
- destination: l.dest,
162
+ destination: h.dest,
163
163
  positionTime: w.unix(),
164
164
  labelCn: b,
165
165
  labelEn: N,
@@ -167,7 +167,7 @@ class mt extends K {
167
167
  vendor: "myVessel",
168
168
  utc: w.utc().format()
169
169
  }, W = Math.floor(w.diff(f, "minute", !0) / (a || 1));
170
- W !== y && (y = W, e.push(x));
170
+ W !== p && (p = 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 O.post(o, n).json();
187
- h == null || h.info("[%s] fetch realtime position from: %s - %j", i.requestId, o, n);
186
+ }, a = await R.post(o, n).json();
187
+ d == null || d.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 h == null || h.warn("[%s] fetch realtime position failed: %j", i.requestId, o, a), a;
190
+ return d == null || d.warn("[%s] fetch realtime position failed: %j", i.requestId, o, a), a;
191
191
  for (const f in e)
192
192
  !isNaN(e[f]) && Number(e[f]) !== 1 / 0 && (e[f] = Number(e[f]));
193
193
  e.status = e.sp > 3 ? 0 : 1;
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");
194
+ const c = e.status, { labelCn: r, labelEn: u } = this.parseStatus(c), l = 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,
@@ -208,11 +208,11 @@ class pt extends K {
208
208
  rot: isNaN(e.rot) ? 0 : e.rot,
209
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: u.unix(),
212
- utc: u.utc().format(),
213
- status: d,
211
+ positionTime: l.unix(),
212
+ utc: l.utc().format(),
213
+ status: c,
214
214
  labelCn: r,
215
- labelEn: c,
215
+ labelEn: u,
216
216
  method: "position",
217
217
  vendor: "hifleet"
218
218
  };
@@ -229,10 +229,10 @@ class pt extends K {
229
229
  Host: "www.hifleet.com"
230
230
  }
231
231
  };
232
- let a = await O.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
- for (const d in a)
235
- !isNaN(a[d]) && Number(a[d]) !== 1 / 0 && (a[d] = Number(a[d]));
232
+ let a = await R.post(o, n).json();
233
+ d == null || d.info("[%s] fetch vessel props from: %s - %j", i.requestId, o, n), a instanceof Array && (a = a[0]);
234
+ for (const c in a)
235
+ !isNaN(a[c]) && Number(a[c]) !== 1 / 0 && (a[c] = Number(a[c]));
236
236
  const e = {
237
237
  mmsi: a.m,
238
238
  name: a.n,
@@ -242,54 +242,54 @@ 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 O.post(o, n).json(), h == null || h.info("[%s] fetch vessel dead weight from: %s - %j", i.requestId, o, n), a instanceof Array && (a = a[0]), a && (e.deadweight = Number(a.dwt)), e;
245
+ return o = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", a = await R.post(o, n).json(), d == null || d.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 l, w, j;
249
- const d = await this.realTimePosition(t, e);
248
+ var h, w, j;
249
+ const c = await this.realTimePosition(t, e);
250
250
  let r = g(i);
251
- const c = g(o), u = g();
251
+ const u = g(o), l = g();
252
252
  if (a) {
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");
253
+ let y = u.diff(r, "d", !0);
254
+ y < 0 ? r = u.clone().subtract(40, "d") : y < 30 ? r.subtract(10, "d") : y < 60 ? r.subtract(5, "d") : r = u.clone().subtract(80, "d"), y = l.diff(u, "d", !0), u.add(y > 10 ? 240 : y * 24, "h");
255
255
  }
256
- const y = {
256
+ const p = {
257
257
  searchParams: {
258
- endtime: c.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
258
+ endtime: u.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
259
259
  starttime: r.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
260
260
  mmsi: t,
261
261
  usertoken: this.token
262
262
  }
263
- }, f = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", m = await O.get(f, y).json();
264
- h == null || h.info("[%s] fetch trajectory from: %s - %j", e.requestId, f, y);
263
+ }, f = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", m = await R.get(f, p).json();
264
+ d == null || d.info("[%s] fetch trajectory from: %s - %j", e.requestId, f, p);
265
265
  let v;
266
- m && (v = ((w = (l = m.ships) == null ? void 0 : l.offors) == null ? void 0 : w.ship) || [], v.length || h == null || h.warn("[%s] fetch trajectory failed: %j", e.requestId, m));
266
+ m && (v = ((w = (h = m.ships) == null ? void 0 : h.offors) == null ? void 0 : w.ship) || [], v.length || d == null || d.warn("[%s] fetch trajectory failed: %j", e.requestId, m));
267
267
  const I = [];
268
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 L in M)
272
- !isNaN(M[L]) && Number(M[L]) !== 1 / 0 && (M[L] = Number(M[L]));
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
- imo: d == null ? void 0 : d.imo,
279
- lat: M.la,
280
- lng: M.lo,
281
- draught: M.draught,
282
- sog: M.sp,
283
- cog: M.co,
284
- hdg: M.hdg,
269
+ const M = 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 y of v) {
271
+ for (const L in y)
272
+ !isNaN(y[L]) && Number(y[L]) !== 1 / 0 && (y[L] = Number(y[L]));
273
+ const b = g(`${y.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
274
+ y.status = y.sp > 4 ? 0 : 1;
275
+ const { labelEn: N, labelCn: x } = this.parseStatus(y.status), W = {
276
+ mmsi: y.m,
277
+ name: y.n,
278
+ imo: c == null ? void 0 : c.imo,
279
+ lat: y.la,
280
+ lng: y.lo,
281
+ draught: y.draught,
282
+ sog: y.sp,
283
+ cog: y.co,
284
+ hdg: y.hdg,
285
285
  positionTime: b.unix(),
286
286
  utc: b.utc().format(),
287
- status: M.status,
287
+ status: y.status,
288
288
  labelCn: x,
289
289
  labelEn: N,
290
290
  method: "trajectory",
291
291
  vendor: "hifleet"
292
- }, T = Math.floor(b.diff(p, "minute", !0) / (n || 1));
292
+ }, T = Math.floor(b.diff(M, "minute", !0) / (n || 1));
293
293
  T !== Y && (Y = T, I.push(W));
294
294
  }
295
295
  return I;
@@ -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 O.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)
311
+ }, n = "https://api.shipxy.com/apicall/GetSingleShip", a = await R.get(n, o).json();
312
+ if (d == null || d.info("[%s] fetch realtime position from: %s - %j", i.requestId, n, o), (a == null ? void 0 : a.status) !== 0)
313
313
  return a;
314
314
  const e = a.data[0];
315
- for (const y in e)
316
- !isNaN(e[y]) && Number(e[y]) !== 1 / 0 && (e[y] = Number(e[y]));
317
- const { labelCn: d, labelEn: r } = await this.parseStatus(e.navistat), c = g.unix(e.lasttime);
315
+ for (const p in e)
316
+ !isNaN(e[p]) && Number(e[p]) !== 1 / 0 && (e[p] = Number(e[p]));
317
+ const { labelCn: c, labelEn: r } = await this.parseStatus(e.navistat), u = g.unix(e.lasttime);
318
318
  return {
319
319
  mmsi: e.ShipID,
320
320
  name: e.name,
@@ -330,44 +330,44 @@ class Mt extends K {
330
330
  hdg: Math.round(e.hdg / 100 * 100) / 100,
331
331
  rot: Math.round(e.rot / 100 * 100) / 100,
332
332
  positionTime: e.lasttime,
333
- utc: c.utc().format(),
333
+ utc: u.utc().format(),
334
334
  status: e.navistat,
335
335
  labelEn: r,
336
- labelCn: d,
336
+ labelCn: c,
337
337
  method: "position",
338
338
  vendor: "shipxy"
339
339
  };
340
340
  }
341
341
  async trajectory(t, i, o, n, a = !0, e = {}) {
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 = {
342
+ var M;
343
+ const c = await this.realTimePosition(t, e), r = g(i), u = g(o), l = "https://api.shipxy.com/apicall/GetShipTrack", p = {
344
344
  searchParams: {
345
345
  id: t,
346
346
  k: this.token,
347
347
  enc: 1,
348
348
  cut: 0,
349
349
  btm: r.unix(),
350
- etm: c.unix()
350
+ etm: u.unix()
351
351
  }
352
- }, f = await O.get(u, y).json();
353
- if (h == null || h.info("[%s] fetch trajectory from: %s - %j", e.requestId, u, y), (f == null ? void 0 : f.status) !== 0)
352
+ }, f = await R.get(l, p).json();
353
+ if (d == null || d.info("[%s] fetch trajectory from: %s - %j", e.requestId, l, p), (f == null ? void 0 : f.status) !== 0)
354
354
  return f;
355
- const m = f == null ? void 0 : f.points, v = [], I = g.unix((p = m[0]) == null ? void 0 : p.utc);
355
+ const m = f == null ? void 0 : f.points, v = [], I = g.unix((M = m[0]) == null ? void 0 : M.utc);
356
356
  let Y = -1;
357
- for (const l of m) {
358
- const w = g.unix(l.utc), j = {
359
- imo: d == null ? void 0 : d.imo,
357
+ for (const h of m) {
358
+ const w = g.unix(h.utc), j = {
359
+ imo: c == null ? void 0 : c.imo,
360
360
  mmsi: t,
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,
361
+ sog: Math.round(h.sog * 3600 / 1e3 / 1852 * 100) / 100,
362
+ cog: Math.round(h.cog / 100 * 100) / 100,
363
+ lat: Math.round(h.lat / 1e6 * 1e5) / 1e5,
364
+ lng: Math.round(h.lon / 1e6 * 1e5) / 1e5,
365
365
  positionTime: w.unix(),
366
366
  utc: w.utc().format(),
367
367
  method: "trajectory",
368
368
  vendor: "shipxy"
369
- }, M = Math.floor(w.diff(I, "minute", !0) / (n || 1));
370
- M !== Y && (Y = M, v.push(j));
369
+ }, y = Math.floor(w.diff(I, "minute", !0) / (n || 1));
370
+ y !== Y && (Y = y, v.push(j));
371
371
  }
372
372
  return v;
373
373
  }
@@ -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 O.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;
389
+ }, n = "https://api3.myships.com/sp/ships/getShipIdByMMSI", a = await R.post(n, o).json();
390
+ return d == null || d.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,15 +397,15 @@ class yt extends K {
397
397
  json: {
398
398
  shipId: t
399
399
  }
400
- }, n = "https://api3.myships.com/sp/ships/aissta", a = await O.post(n, o).json();
401
- if (h == null || h.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 R.post(n, o).json();
401
+ if (d == null || d.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
- let d = e.imo;
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)), {
404
+ let c = e.imo;
405
+ return t === "407170" && (c = "9198379", d == null || d.warn("[%s] ship(%s) imo error: %s, should be %s", i.requestId, t, e.imo, c)), {
406
406
  mmsi: e.mmsi,
407
407
  name: e.shipnameEn,
408
- imo: d,
408
+ imo: c,
409
409
  callSign: e.callSign,
410
410
  length: e.length,
411
411
  width: e.breadth,
@@ -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 O.post(e, a).json();
424
- h == null || h.info("[%s] fetch realtime position from: %s - %j", i.requestId, e, a);
425
- const r = d.data[0];
423
+ }, e = "https://api3.myships.com/sp/ships/position/latest", c = await R.post(e, a).json();
424
+ d == null || d.info("[%s] fetch realtime position from: %s - %j", i.requestId, e, a);
425
+ const r = c.data[0];
426
426
  for (const m in r)
427
427
  !isNaN(r[m]) && Number(r[m]) !== 1 / 0 && (r[m] = Number(r[m]));
428
- const { labelCn: c, labelEn: u } = await this.parseStatus(r.aisNavStatus), y = g.unix(r.posTime);
428
+ const { labelCn: u, labelEn: l } = await this.parseStatus(r.aisNavStatus), p = g.unix(r.posTime);
429
429
  return {
430
430
  ...n,
431
431
  mmsi: t,
@@ -436,23 +436,23 @@ class yt extends K {
436
436
  hdg: Math.round(r.heading * 100) / 100,
437
437
  rot: Math.round(r.rot * 100) / 100,
438
438
  positionTime: r.posTime,
439
- utc: y.utc().format(),
439
+ utc: p.utc().format(),
440
440
  status: r.aisNavStatus,
441
- labelEn: u,
442
- labelCn: c,
441
+ labelEn: l,
442
+ labelCn: u,
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 = g(i), r = g(o), c = await this.getShipId(t), u = await this.getShipInfo(c), y = [];
449
- for (; r.diff(d, "day", !0) > 30; )
450
- await this.trajectoryIn30Day(c, d.unix(), d.add(30, "day").unix(), u, t, n, y);
451
- return await this.trajectoryIn30Day(c, d.unix(), r.unix(), u, t, n, y), y;
448
+ const c = g(i), r = g(o), u = await this.getShipId(t), l = await this.getShipInfo(u), p = [];
449
+ for (; r.diff(c, "day", !0) > 30; )
450
+ await this.trajectoryIn30Day(u, c.unix(), c.add(30, "day").unix(), l, t, n, p);
451
+ return await this.trajectoryIn30Day(u, c.unix(), r.unix(), l, t, n, p), p;
452
452
  }
453
- async trajectoryIn30Day(t, i, o, n, a, e, d, r = {}) {
453
+ async trajectoryIn30Day(t, i, o, n, a, e, c, r = {}) {
454
454
  var I;
455
- const c = {
455
+ const u = {
456
456
  headers: {
457
457
  appKey: this.token
458
458
  },
@@ -461,16 +461,16 @@ class yt extends K {
461
461
  startTime: i,
462
462
  endTime: o
463
463
  }
464
- }, u = "https://api3.myships.com/sp/ships/position/history", y = await O.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 f = y.data;
464
+ }, l = "https://api3.myships.com/sp/ships/position/history", p = await R.post(l, u).json();
465
+ if (d == null || d.info("[%s] fetch trajectory from: %s - %j", r.requestId, l, u), p.code !== "0")
466
+ return d == null || d.warn("[%s] invoke myship trajectory failed: %j", r.requestId, p), p;
467
+ const f = p.data;
468
468
  for (const Y in f)
469
469
  !isNaN(f[Y]) && Number(f[Y]) !== 1 / 0 && (f[Y] = Number(f[Y]));
470
470
  const m = g.unix((I = f[0]) == null ? void 0 : I.posTime);
471
471
  let v = -1;
472
472
  for (const Y of f) {
473
- const p = g.unix(Y.posTime), l = {
473
+ const M = g.unix(Y.posTime), h = {
474
474
  imo: n == null ? void 0 : n.imo,
475
475
  mmsi: a,
476
476
  lat: Math.round(Y.lat / 1e4 / 60 * 1e5) / 1e5,
@@ -479,19 +479,19 @@ class yt extends K {
479
479
  cog: Math.round(Y.cog / 10 * 100) / 100,
480
480
  hdg: Math.round(Y.heading * 100) / 100,
481
481
  rot: Math.round(Y.rot * 100) / 100,
482
- positionTime: p.unix(),
483
- utc: p.utc().format(),
482
+ positionTime: M.unix(),
483
+ utc: M.utc().format(),
484
484
  method: "trajectory",
485
485
  vendor: "myship"
486
- }, w = Math.floor(p.diff(m, "minute", !0) / (e || 1));
487
- w !== v && (v = w, d.push(l));
486
+ }, w = Math.floor(M.diff(m, "minute", !0) / (e || 1));
487
+ w !== v && (v = w, c.push(h));
488
488
  }
489
- return d;
489
+ return c;
490
490
  }
491
491
  }
492
- let R;
492
+ let O;
493
493
  try {
494
- R = z.getLogger("vessel");
494
+ O = z.getLogger("vessel");
495
495
  } catch {
496
496
  } finally {
497
497
  }
@@ -506,19 +506,19 @@ class ot {
506
506
  * @param options
507
507
  */
508
508
  parsePrinciple(s, t = {}) {
509
- var e, d, r;
510
- R == null || R.info("[%s] parse rule: %s", t.requestId, s);
509
+ var e, c, r;
510
+ O == null || O.info("[%s] parse rule: %s", t.requestId, s);
511
511
  const i = new RegExp("(?<=\\[)(.+)(?=])", "g"), o = s.match(i) ? (e = s.match(i)) == null ? void 0 : e[0] : void 0, n = o == null ? void 0 : o.split(";");
512
512
  if (!n)
513
513
  return;
514
514
  const a = {};
515
- for (let c = 0; c < (n == null ? void 0 : n.length); c++) {
516
- const u = (r = (d = n[c].match(i)) == null ? void 0 : d[0]) == null ? void 0 : r.split("],");
517
- if (c === 0 && !u)
515
+ for (let u = 0; u < (n == null ? void 0 : n.length); u++) {
516
+ const l = (r = (c = n[u].match(i)) == null ? void 0 : c[0]) == null ? void 0 : r.split("],");
517
+ if (u === 0 && !l)
518
518
  a.scope = n[0];
519
- else if (u)
520
- for (let y = 0, f = u.length; y < f; y++) {
521
- const m = this.parseRule(u[y]);
519
+ else if (l)
520
+ for (let p = 0, f = l.length; p < f; p++) {
521
+ const m = this.parseRule(l[p]);
522
522
  m && (a[m.level] ? m.key ? a[m.level][m == null ? void 0 : m.key] = m : a[m.level] = m : m.key ? a[m.level] = { [m == null ? void 0 : m.key]: m } : a[m.level] = m);
523
523
  }
524
524
  }
@@ -532,7 +532,7 @@ class ot {
532
532
  */
533
533
  parseRule(s, t = {}) {
534
534
  var a;
535
- R == null || R.info("[%s] parse rule: %s", t.requestId, s), s = s.startsWith("[") ? s : `[${s}`, s = s.endsWith("]") ? s : `${s}]`;
535
+ O == null || O.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,14 +550,14 @@ class ot {
550
550
  * @param options
551
551
  */
552
552
  checkWeather(s, t, i = {}) {
553
- var m, v, I, Y, p, l, w, j, M, b, N, x, W, T, L;
553
+ var m, v, I, Y, M, h, w, j, y, b, N, x, W, T, L;
554
554
  let o = 0, n = 0, a = 0, e = 0;
555
- const d = Math.round(((v = (m = t == null ? void 0 : t.SEVERE) == null ? void 0 : m.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, f = (x = (N = t == null ? void 0 : t.HEAVY) == null ? void 0 : N.wind) == null ? void 0 : x.number;
555
+ const c = Math.round(((v = (m = t == null ? void 0 : t.SEVERE) == null ? void 0 : m.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, u = (h = (M = t == null ? void 0 : t.HEAVY) == null ? void 0 : M.sigWave) == null ? void 0 : h.number, l = Math.round((((j = (w = t == null ? void 0 : t.SEVERE) == null ? void 0 : w.wind) == null ? void 0 : j.number) + 2) * 100) / 100, p = (b = (y = t == null ? void 0 : t.SEVERE) == null ? void 0 : y.wind) == null ? void 0 : b.number, f = (x = (N = t == null ? void 0 : t.HEAVY) == null ? void 0 : N.wind) == null ? void 0 : x.number;
556
556
  for (let A = 0; A < (s == null ? void 0 : s.length); A++) {
557
557
  const D = s[A], q = (T = (W = D == null ? void 0 : D.meteo) == null ? void 0 : W.wave) == null ? void 0 : T.sig, S = (L = D == null ? void 0 : D.meteo) == null ? void 0 : L.wind, F = A ? g(D.eta).diff(g(s[A - 1].eta), "hour", !0) : 0;
558
- e = F > e ? F : e, R == null || R.info("[%s] check sig.wave: %j", i.requestId, { ...q, dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: c }), (q == null ? void 0 : q.height) >= d ? D.isDangerous = !0 : (q == null ? void 0 : q.height) >= r ? D.isSevere = !0 : (q == null ? void 0 : q.height) >= c && (D.isHeavy = !0), R == null || R.info("[%s] check wind: %j", i.requestId, { ...S, dgThd4Wd: u, svThd4Wd: y, hvThd4Wd: f }), (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) === f && !D.isDangerous && !D.isSevere && (D.isHeavy = !0), o += D.isDangerous ? F : 0, n += D.isSevere ? F : 0, a += D.isHeavy ? F : 0;
558
+ e = F > e ? F : e, O == null || O.info("[%s] check sig.wave: %j", i.requestId, { ...q, dgThd4Wv: c, svThd4Wv: r, hvThd4Wv: u }), (q == null ? void 0 : q.height) >= c ? D.isDangerous = !0 : (q == null ? void 0 : q.height) >= r ? D.isSevere = !0 : (q == null ? void 0 : q.height) >= u && (D.isHeavy = !0), O == null || O.info("[%s] check wind: %j", i.requestId, { ...S, dgThd4Wd: l, svThd4Wd: p, hvThd4Wd: f }), (S == null ? void 0 : S.scale) >= l ? (D.isDangerous = !0, delete D.isSevere, delete D.isHeavy) : (S == null ? void 0 : S.scale) > p ? (D.isDangerous || (D.isSevere = !0), delete D.isHeavy) : (S == null ? void 0 : S.scale) === f && !D.isDangerous && !D.isSevere && (D.isHeavy = !0), o += D.isDangerous ? F : 0, n += D.isSevere ? F : 0, a += D.isHeavy ? F : 0;
559
559
  }
560
- return o = Math.round(o * 100) / 100, n = Math.round(n * 100) / 100, a = Math.round(a * 100) / 100, e = Math.round(e), { sample: s, dangerous: o, severe: n, heavy: a, step: e < 3 ? 3 : e, wind: { dgThd4Wd: u, svThd4Wd: y, hvThd4Wd: f }, 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: l, svThd4Wd: p, hvThd4Wd: f }, sig: { dgThd4Wv: c, svThd4Wv: r, hvThd4Wv: u } };
561
561
  }
562
562
  }
563
563
  const bt = new ot();
@@ -567,7 +567,7 @@ try {
567
567
  } catch {
568
568
  } finally {
569
569
  }
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 || {});
570
+ var nt = /* @__PURE__ */ ((k) => (k.common = "common", k.container = "container", k.tugs = "tugs", 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
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
@@ -584,7 +584,7 @@ class C {
584
584
  static blockCoefficient(s, t, i, o) {
585
585
  let n = Math.round(s / (t * i * o) * 100) / 100;
586
586
  n = n < 0.55 ? 0.55 : n > 0.85 ? 0.85 : n;
587
- const a = [0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85], e = a.map((d) => Math.abs(d - n));
587
+ const a = [0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85], e = a.map((c) => Math.abs(c - n));
588
588
  return a[e.indexOf(Math.min(...e))];
589
589
  }
590
590
  /**
@@ -678,18 +678,17 @@ class C {
678
678
  * @private
679
679
  */
680
680
  static assembleProperties(s, t, i, o) {
681
- var c, u;
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;
681
+ var p;
682
+ const n = s.lbp ?? s.length ?? s.lengthOverall ?? 198.9642, a = s.draught ?? 8, e = s.breadthMoulded ?? s.breadth ?? s.breadthExtreme ?? 32.4572, c = s.deadweight ?? 67035.7773, r = ((p = s == null ? void 0 : s.type) == null ? void 0 : p.toLowerCase()) || "common";
683
683
  return {
684
- // @ts-ignore
685
- tag: ((u = (c = s == null ? void 0 : s.type) == null ? void 0 : c.toLowerCase()) == null ? void 0 : u.indexOf("container")) > -1 ? "container" : "common",
684
+ tag: r.indexOf("container") > -1 ? "container" : r.indexOf("tugs") > -1 ? "tugs" : "common",
686
685
  lbp: n,
687
686
  loadCondition: t,
688
687
  draught: a,
689
688
  breadthMoulded: e,
690
689
  // 排水量(吨)= 载重量(吨)/ 1.025 + 吃水(米)× 船舶型宽(米)× 船舶型长(米)× 0.7
691
690
  // 其中,1.025是指海水的密度,吨是指公吨,吃水是指船舶的最大吃水深度。船舶型宽是指船舶的最大型宽,船舶型长是指船舶的设计型长。上述公式是针对常规船舶适用的,不同类型的船舶可能会有一些差异。
692
- displacement: Math.round((d / 1.025 + a * e * n * 0.7) * 1e4) / 1e4,
691
+ displacement: Math.round((c / 1.025 + a * e * n * 0.7) * 1e4) / 1e4,
693
692
  // 换算为m/s
694
693
  speed: Math.round((i ?? 14.1382) * 1852 / 3600 * 1e4) / 1e4,
695
694
  bearing: o || 90
@@ -705,14 +704,14 @@ class C {
705
704
  * @param useMeteo true 启用气象分析
706
705
  * @param useRouteParam true 启用设置速度
707
706
  */
708
- static async speedLoseAt(s, t, i, o = "", n = 2, a = !0, e = !1, d = {}) {
707
+ static async speedLoseAt(s, t, i, o = "", n = 2, a = !0, e = !1, c = {}) {
709
708
  let r;
710
709
  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), u = C.weatherFactor(s, c), y = C.currentFactor(s.bearing, c == null ? void 0 : c.current, n), f = Math.round((s.speed * 1.943844 + u + y) * 100) / 100;
710
+ const u = await st.queryPointFactor(t.lng, t.lat, i.valueOf(), "wind,wave,current,watertemp", o, c), l = C.weatherFactor(s, u), p = C.currentFactor(s.bearing, u == null ? void 0 : u.current, n), f = Math.round((s.speed * 1.943844 + l + p) * 100) / 100;
712
711
  r = {
713
- meteo: { ...c },
714
- wxFactor: u,
715
- cFactor: y,
712
+ meteo: { ...u },
713
+ wxFactor: l,
714
+ cFactor: p,
716
715
  speed: t.velocity && e ? t.velocity : f < 0 ? 1 : f,
717
716
  eta: i.utc().format("YYYY-MM-DDTHH:mm[Z]"),
718
717
  etd: i.utc().format("YYYY-MM-DDTHH:mm[Z]")
@@ -740,52 +739,52 @@ class C {
740
739
  * @param useRouteParam true 启用航线上设置的参数 { suspend: 停留时长(小时), velocity: 速度(kts)}
741
740
  * @private
742
741
  */
743
- static async speedLoseInHoursStep(s, t, i, o, n, a, e = "", d = !0, r = !1, c = {}) {
742
+ static async speedLoseInHoursStep(s, t, i, o, n, a, e = "", c = !0, r = !1, u = {}) {
744
743
  t.utc();
745
- const u = [], y = [];
744
+ const l = [], p = [];
746
745
  let f = 0, m = 0, v, I;
747
746
  for (let Y = 0; Y < a.length - 1; Y++) {
748
- let p = a[Y];
749
- p.distanceFromStart = n + m;
750
- const l = a[Y + 1];
751
- if (s.bearing = V.calculateBearing(p, l, !l.gcToPrevious), p.bearing = s.bearing, p.suspend && r) {
752
- p.eta = p.eta || t.format("YYYY-MM-DDTHH:mm[Z]"), p.elapsed = p.elapsed ?? 0;
753
- const M = p.suspend - p.elapsed;
754
- if (o - f > M)
755
- o = o - f - M, t.add(M, "hour"), p.elapsed = p.suspend;
747
+ let M = a[Y];
748
+ M.distanceFromStart = n + m;
749
+ const h = a[Y + 1];
750
+ if (s.bearing = V.calculateBearing(M, h, !h.gcToPrevious), M.bearing = s.bearing, M.suspend && r) {
751
+ M.eta = M.eta || t.format("YYYY-MM-DDTHH:mm[Z]"), M.elapsed = M.elapsed ?? 0;
752
+ const y = M.suspend - M.elapsed;
753
+ if (o - f > y)
754
+ o = o - f - y, t.add(y, "hour"), M.elapsed = M.suspend;
756
755
  else {
757
756
  const b = o - f;
758
- p.elapsed += b, t.add(b, "hour"), o = 0;
757
+ M.elapsed += b, t.add(b, "hour"), o = 0;
759
758
  }
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 = m, { etd: t, from: I || p, to: p, next: a.filter((b) => b), wps: u, days: y };
759
+ if (H == null || H.info(`[%s] suspend ${M.elapsed} hours at %j, and remain ${o} hours need to go...`, u.requestId, M), o === 0)
760
+ return M.distanceFromPrevious = m, { etd: t, from: I || M, to: M, next: a.filter((b) => b), wps: l, days: p };
762
761
  }
763
- p = await C.speedLoseAt(s, p, t, e, 0, d, r, c), I = I || p, p.important && u.push(p), t.isSameOrAfter(i) && (y.push(p), i.add(24, "hour"));
764
- const w = V.calculateDistance(p, l, !l.gcToPrevious);
762
+ M = await C.speedLoseAt(s, M, t, e, 0, c, r, u), I = I || M, M.important && l.push(M), t.isSameOrAfter(i) && (p.push(M), i.add(24, "hour"));
763
+ const w = V.calculateDistance(M, h, !h.gcToPrevious);
765
764
  let j = Math.ceil(w / I.speed * 1e4) / 1e4;
766
765
  if (f + j < o) {
767
766
  if (f += j, t.add(j, "hour"), delete a[Y], H == null || H.info(
768
767
  `[%s] go to %j from %j with ${w}nm, and cost ${j} hours`,
769
- c.requestId,
770
- { lat: l.lat, lng: l.lng },
768
+ u.requestId,
769
+ { lat: h.lat, lng: h.lng },
771
770
  { lat: I.lat, lng: I.lng, etd: I.etd }
772
- ), m += 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 + m, u.push(v), delete a[Y + 1];
771
+ ), m += w, a.filter((y) => y).length <= 1) {
772
+ v = h, v.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), v.distanceFromPrevious = w, v.distanceFromStart = n + m, l.push(v), delete a[Y + 1];
774
773
  break;
775
774
  }
776
775
  } else {
777
776
  j = o - f, t.add(j, "hour");
778
- const M = B.roundPrecision(I.speed * j, 4);
779
- v = V.calculateCoordinate(p, s.bearing, M, "nauticalmiles", !l.gcToPrevious), v.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), a[Y] = v, H == null || H.info(
780
- `[%s] go to %j from %j with ${M}nm, and cost ${j} hours`,
781
- c.requestId,
777
+ const y = B.roundPrecision(I.speed * j, 4);
778
+ v = V.calculateCoordinate(M, s.bearing, y, "nauticalmiles", !h.gcToPrevious), v.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), a[Y] = v, H == null || H.info(
779
+ `[%s] go to %j from %j with ${y}nm, and cost ${j} hours`,
780
+ u.requestId,
782
781
  { lat: v.lat, lng: v.lng },
783
- { lat: p.lat, lng: p.lng, etd: p.etd }
784
- ), m += M, v.distanceFromPrevious = m, v.distanceFromStart = n + m;
782
+ { lat: M.lat, lng: M.lng, etd: M.etd }
783
+ ), m += y, v.distanceFromPrevious = m, v.distanceFromStart = n + m;
785
784
  break;
786
785
  }
787
786
  }
788
- return { etd: t, from: I, to: v, next: a.filter((Y) => Y), wps: u, days: y };
787
+ return { etd: t, from: I, to: v, next: a.filter((Y) => Y), wps: l, days: p };
789
788
  }
790
789
  /**
791
790
  * 洋流影响因子
@@ -806,16 +805,16 @@ class C {
806
805
  * @param wwc 气象要素
807
806
  */
808
807
  static weatherFactor(s, t) {
809
- var u, y, f, m, v;
808
+ var l, p, f, m, v;
810
809
  H == null || H.debug("calculate weather factor via: %j", { ...s, ...t });
811
810
  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));
811
+ let a = Math.abs(s.bearing % 360 - (((l = t == null ? void 0 : t.wind) == null ? void 0 : l.degree) % 360 || 0));
813
812
  a = a > 180 ? 360 - a : a;
814
- const e = C.directionFactor(a, (y = t == null ? void 0 : t.wind) == null ? void 0 : y.scale), d = C.vesselTagFactor(s.displacement, s.loadCondition, s.tag, (f = t == null ? void 0 : t.wind) == null ? void 0 : f.scale);
815
- let r = e * n * d / 100 * s.speed;
816
- r = Math.round(r * 1.943844 * 1e4) / 1e4 * -1;
817
- const c = C.waveHeightFactor(((v = (m = t == null ? void 0 : t.wave) == null ? void 0 : m.sig) == null ? void 0 : v.height) ?? 1);
818
- return r = r + c, H == null || H.debug("weather factor = %s", r), r = Math.abs(r) > 5 ? 5 * (Math.abs(r) / r) + Math.abs(r) / r * (Math.abs(r) - 5) * 0.4 : r, Math.round(r * 100) / 100;
813
+ const e = C.directionFactor(a, (p = t == null ? void 0 : t.wind) == null ? void 0 : p.scale), c = C.vesselTagFactor(s.displacement, s.loadCondition, s.tag, (f = t == null ? void 0 : t.wind) == null ? void 0 : f.scale);
814
+ let r = e * n * c / 100 * s.speed;
815
+ r = Math.round(r * 1.943844 * 1e4) / 1e4 * -1, s.tag === "tugs" && Math.abs(r) > 1 && (r = r / (Math.abs(Math.round(r)) + 1));
816
+ const u = C.waveHeightFactor(((v = (m = t == null ? void 0 : t.wave) == null ? void 0 : m.sig) == null ? void 0 : v.height) ?? 1);
817
+ return r = r + u, H == null || H.debug("weather factor = %s", r), r = Math.abs(r) > 5 ? 5 * (Math.abs(r) / r) + Math.abs(r) / r * (Math.abs(r) - 5) * 0.4 : r, Math.round(r * 100) / 100;
819
818
  }
820
819
  /**
821
820
  * 全程失速分析(走完航程)
@@ -829,11 +828,11 @@ class C {
829
828
  * @param useMeteo true 启用气象分析
830
829
  * @param useRouteParam
831
830
  */
832
- static async analyseInstant(s, t, i, o, n, a = "", e = 0, d = !0, r = !1, c = {}) {
831
+ static async analyseInstant(s, t, i, o, n, a = "", e = 0, c = !0, r = !1, u = {}) {
833
832
  var F, G, U, J, Q;
834
- const u = g().valueOf();
833
+ const l = g().valueOf();
835
834
  s.lng = B.convertToStdLng(s.lng);
836
- const { route: y, waypoints: f } = n.points, m = V.calculateSubRoute(s, y);
835
+ const { route: p, waypoints: f } = n.points, m = V.calculateSubRoute(s, p);
837
836
  if (((F = m[0]) == null ? void 0 : F.length) <= 1)
838
837
  return;
839
838
  const { v0: v, label: I } = s.sog ? {
@@ -844,12 +843,12 @@ class C {
844
843
  v0: o.speed,
845
844
  label: "CP"
846
845
  /* Cp */
847
- }, Y = C.assembleProperties(i, o.loadCondition, v, 0), p = f.length ? V.calculateSubWaypoints(s, f) : [];
848
- p.forEach((P) => P.important = !0);
849
- const l = {
846
+ }, Y = C.assembleProperties(i, o.loadCondition, v, 0), M = f.length ? V.calculateSubWaypoints(s, f) : [];
847
+ M.forEach((P) => P.important = !0);
848
+ const h = {
850
849
  from: { ...s },
851
850
  route: m,
852
- waypoints: p,
851
+ waypoints: M,
853
852
  v0: v,
854
853
  label: I
855
854
  }, w = {
@@ -858,7 +857,7 @@ class C {
858
857
  wps: []
859
858
  };
860
859
  e || (V.calculateRouteDistance(m) / o.speed <= 72 ? e = 3 : e = 6);
861
- let j = V.simplifyRouteToCoordinates(m, p, 0), M = 0, b = 0, N = 0, x = 0;
860
+ let j = V.simplifyRouteToCoordinates(m, M, 0), y = 0, b = 0, N = 0, x = 0;
862
861
  t = g(t).utc();
863
862
  const W = t.clone();
864
863
  for (; j.length > 0; ) {
@@ -867,14 +866,14 @@ class C {
867
866
  t,
868
867
  W,
869
868
  _,
870
- M,
869
+ y,
871
870
  j,
872
871
  a,
873
- d,
872
+ c,
874
873
  r,
875
- c
874
+ u
876
875
  );
877
- (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
+ (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), y += ((U = E == null ? void 0 : E.to) == null ? void 0 : U.distanceFromPrevious) ?? 0;
878
877
  }
879
878
  const T = w.hours;
880
879
  for (let P = 0; P < T.length - 1; P++) {
@@ -886,11 +885,11 @@ class C {
886
885
  const E = w.wps[_ - 1], $ = P.distanceFromStart - E.distanceFromStart, X = g(P.eta).diff(g(E.etd), "h", !0);
887
886
  X < 1 ? P.avgSpd = E.speed : P.avgSpd = Math.round($ / X * 100) / 100;
888
887
  }
889
- }), l.sample = w;
888
+ }), h.sample = w;
890
889
  const L = w.hours.at(0), A = w.hours.at(-1);
891
- l.distance = Math.round(A.distanceFromStart * 1e4) / 1e4, l.etd = g(L.eta).utc().format(), l.eta = g(A.eta).utc().format(), l.wxFactor = Math.round(b / x * 1e4) / 1e4, l.cFactor = Math.round(N / x * 1e4) / 1e4, l.avgSpeed = Math.round(A.distanceFromStart / x * 1e4) / 1e4, l.totalHrs = Math.round(x * 1e4) / 1e4, l.totalFoCons = Math.round((o == null ? void 0 : o.fo) / 24 * l.totalHrs * 1e3) / 1e3, l.totalDgoCons = Math.round((o == null ? void 0 : o.dgo) / 24 * l.totalHrs * 1e3) / 1e3;
892
- const q = g().valueOf() - u, S = ((Q = w == null ? void 0 : w.hours) == null ? void 0 : Q.length) || 1;
893
- return H == null || H.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", c == null ? void 0 : c.requestId, q, S, Math.round(q / S * 1e3) / 1e3), l;
890
+ h.distance = Math.round(A.distanceFromStart * 1e4) / 1e4, h.etd = g(L.eta).utc().format(), h.eta = g(A.eta).utc().format(), h.wxFactor = Math.round(b / x * 1e4) / 1e4, h.cFactor = Math.round(N / x * 1e4) / 1e4, h.avgSpeed = Math.round(A.distanceFromStart / x * 1e4) / 1e4, h.totalHrs = Math.round(x * 1e4) / 1e4, h.totalFoCons = Math.round((o == null ? void 0 : o.fo) / 24 * h.totalHrs * 1e3) / 1e3, h.totalDgoCons = Math.round((o == null ? void 0 : o.dgo) / 24 * h.totalHrs * 1e3) / 1e3;
891
+ const q = g().valueOf() - l, S = ((Q = w == null ? void 0 : w.hours) == null ? void 0 : Q.length) || 1;
892
+ return H == null || H.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", u == null ? void 0 : u.requestId, q, S, Math.round(q / S * 1e3) / 1e3), h;
894
893
  }
895
894
  /**
896
895
  * 分段失速分析(最多走hours 小时)
@@ -905,7 +904,7 @@ class C {
905
904
  * @param useMeteo true 启用气象分析
906
905
  * @param useRouteParam
907
906
  */
908
- static async analyseInstantWithThreshed(s, t, i, o, n, a, e, d = "", r = 3, c = !0, u = !1, y = {}) {
907
+ static async analyseInstantWithThreshed(s, t, i, o, n, a, e, c = "", r = 3, u = !0, l = !1, p = {}) {
909
908
  var A, D, q;
910
909
  s.lng = B.convertToStdLng(s.lng);
911
910
  const { v0: f, label: m } = s.sog ? {
@@ -921,13 +920,13 @@ class C {
921
920
  return;
922
921
  const Y = e.length ? V.calculateSubWaypoints(s, e) : [];
923
922
  Y.forEach((S) => S.important = !0);
924
- let p = V.simplifyRouteToCoordinates(I, Y, 0), l = 0, w = 0, j = 0, M = 0, b;
923
+ let M = V.simplifyRouteToCoordinates(I, Y, 0), h = 0, w = 0, j = 0, y = 0, b;
925
924
  const N = {
926
925
  hours: [],
927
926
  wps: [],
928
927
  days: []
929
928
  };
930
- for (t = g(t).utc(); p.length > 0; ) {
929
+ for (t = g(t).utc(); M.length > 0; ) {
931
930
  const S = r - t.hour() % r;
932
931
  let F = Math.ceil(t.clone().add(S, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4;
933
932
  if (F = t.clone().add(F, "h").isAfter(i) ? i.diff(t, "h", !0) * 1e4 / 1e4 : F, F)
@@ -936,13 +935,13 @@ class C {
936
935
  t,
937
936
  i.clone(),
938
937
  F,
939
- l,
940
- p,
941
- d,
938
+ h,
939
+ M,
942
940
  c,
943
941
  u,
944
- y
945
- ), (D = b.from) != null && D.speed && (N.hours.push(b.from), b != null && b.wps && N.wps.push(...b.wps), N.days.push(...b.days)), 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;
942
+ l,
943
+ p
944
+ ), (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)), M = b == null ? void 0 : b.next, M.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)), h += ((q = b == null ? void 0 : b.to) == null ? void 0 : q.distanceFromPrevious) ?? 0;
946
945
  else {
947
946
  b && (N.hours.push(b.to), b != null && b.wps && N.wps.push(...b.wps), N.days.push(b.to));
948
947
  break;
@@ -951,7 +950,7 @@ class C {
951
950
  const x = N.hours;
952
951
  for (let S = 0; S < x.length - 1; S++) {
953
952
  const F = g(x[S + 1].eta).diff(x[S].etd, "hour", !0);
954
- w += x[S].wxFactor * F, j += x[S].cFactor * F, M += F;
953
+ w += x[S].wxFactor * F, j += x[S].cFactor * F, y += F;
955
954
  }
956
955
  const W = N.hours.at(0), T = N.hours.at(-1);
957
956
  return {
@@ -960,10 +959,10 @@ class C {
960
959
  // 注意,可能会在first节点Drift,所有采用eta做为初始出发时间
961
960
  etd: g(W.eta).utc().format(),
962
961
  eta: g(T == null ? void 0 : T.eta).utc().format(),
963
- wxFactor: Math.round(w / M * 1e4) / 1e4,
964
- cFactor: Math.round(j / M * 1e4) / 1e4,
965
- avgSpeed: Math.round(((T == null ? void 0 : T.distanceFromStart) || 0) / M * 1e4) / 1e4,
966
- totalHrs: Math.round(M * 1e4) / 1e4,
962
+ wxFactor: Math.round(w / y * 1e4) / 1e4,
963
+ cFactor: Math.round(j / y * 1e4) / 1e4,
964
+ avgSpeed: Math.round(((T == null ? void 0 : T.distanceFromStart) || 0) / y * 1e4) / 1e4,
965
+ totalHrs: Math.round(y * 1e4) / 1e4,
967
966
  from: s,
968
967
  to: T,
969
968
  route: I,
@@ -1 +1 @@
1
- (function(k,D){typeof exports=="object"&&typeof module<"u"?D(exports,require("got"),require("@log4js-node/log4js-api"),require("moment"),require("@idm-plugin/geo"),require("@idm-plugin/meteo")):typeof define=="function"&&define.amd?define(["exports","got","@log4js-node/log4js-api","moment","@idm-plugin/geo","@idm-plugin/meteo"],D):(k=typeof globalThis<"u"?globalThis:k||self,D(k["idm-plugin-rabbitmq"]={},k.got,k["@log4js-node/log4js-api"],k.moment,k["@idm-plugin/geo"],k["@idm-plugin/meteo"]))})(this,function(k,D,Z,v,O,nt){"use strict";var ht=Object.defineProperty;var lt=(k,D,Z)=>D in k?ht(k,D,{enumerable:!0,configurable:!0,writable:!0,value:Z}):k[D]=Z;var K=(k,D,Z)=>(lt(k,typeof D!="symbol"?D+"":D,Z),Z);let u;try{u=Z.getLogger("vessel")}catch{}finally{}class z{parseStatus(s){let t,i;switch(s){case 0:t="在航(主机推动)",i="The engine is in use";break;case 1:t="锚泊",i="Anchored";break;case 2:t="失控",i="Not operated";break;case 3:t="操纵受限",i="Limited airworthiness";break;case 4:t="吃水受限",i="Limited by ship's draft";break;case 5:t="靠泊",i="Mooring";break;case 6:t="搁浅",i="Stranded";break;case 7:t="捕捞作业",i="Engaged in fishing";break;case 8:t="靠帆船提供动力",i="Sailing";break;default:t="未定义",i="Undefined"}return{labelCn:t,labelEn:i}}}class ot extends z{constructor(t,i){super();K(this,"clientId");K(this,"clientSecret");K(this,"token");this.clientId=t,this.clientSecret=i}async authToken(t={}){const i="https://svc.data.myvessel.cn/ada/oauth/token",n={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},o=await D.post(i,n).json();u==null||u.info("[%s] fetch access token from: %s - %j",t.requestId,i,o),o.error||(this.token={accessToken:o.access_token,tokenType:o.token_type,expiresIn:o.expires_in,scope:o.scope,jti:o.jti,issuedAt:v().utc().format()})}async realTimePosition(t,i={}){var c,h,y;(!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} ${(y=this.token)==null?void 0:y.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 f in e)!isNaN(e[f])&&Number(e[f])!==1/0&&(e[f]=Number(e[f]));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 m,g,j,Y,p;const r="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",c={headers:{Authorization:`${(m=this.token)==null?void 0:m.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 y=-1;const f=v(`${(Y=(j=h.data)==null?void 0:j[0])==null?void 0:Y.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(p=h.data)==null||p.forEach(l=>{for(const T in l)!isNaN(l[T])&&Number(l[T])!==1/0&&(l[T]=Number(l[T]));const I=v(`${l.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),H=l.eta?v(`${l.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,M=l.status,{labelCn:b,labelEn:F}=this.parseStatus(M),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:M,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(f,"minute",!0)/(a||1));V!==y&&(y=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 f in e)!isNaN(e[f])&&Number(e[f])!==1/0&&(e[f]=Number(e[f]));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 M=c.diff(r,"d",!0);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=h.diff(c,"d",!0),c.add(M>10?240:M*24,"h")}const y={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}},f="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",m=await D.get(f,y).json();u==null||u.info("[%s] fetch trajectory from: %s - %j",e.requestId,f,y);let g;m&&(g=((I=(l=m.ships)==null?void 0:l.offors)==null?void 0:I.ship)||[],g.length||u==null||u.warn("[%s] fetch trajectory failed: %j",e.requestId,m));const j=[];let Y=-1;const p=v(`${(H=g==null?void 0:g[0])==null?void 0:H.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const M of g){for(const _ in M)!isNaN(M[_])&&Number(M[_])!==1/0&&(M[_]=Number(M[_]));const b=v(`${M.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");M.status=M.sp>4?0:1;const{labelEn:F,labelCn:x}=this.parseStatus(M.status),V={mmsi:M.m,name:M.n,imo:d==null?void 0:d.imo,lat:M.la,lng:M.lo,draught:M.draught,sog:M.sp,cog:M.co,hdg:M.hdg,positionTime:b.unix(),utc:b.utc().format(),status:M.status,labelCn:x,labelEn:F,method:"trajectory",vendor:"hifleet"},T=Math.floor(b.diff(p,"minute",!0)/(o||1));T!==Y&&(Y=T,j.push(V))}return j}}class rt extends z{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,i={}){const n={searchParams:{id:t,k:this.token,enc:1}},o="https://api.shipxy.com/apicall/GetSingleShip",a=await D.get(o,n).json();if(u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,o,n),(a==null?void 0:a.status)!==0)return a;const e=a.data[0];for(const y in e)!isNaN(e[y])&&Number(e[y])!==1/0&&(e[y]=Number(e[y]));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",y={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:r.unix(),etm:c.unix()}},f=await D.get(h,y).json();if(u==null||u.info("[%s] fetch trajectory from: %s - %j",e.requestId,h,y),(f==null?void 0:f.status)!==0)return f;const m=f==null?void 0:f.points,g=[],j=v.unix((p=m[0])==null?void 0:p.utc);let Y=-1;for(const l of m){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"},M=Math.floor(I.diff(j,"minute",!0)/(o||1));M!==Y&&(Y=M,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 m in r)!isNaN(r[m])&&Number(r[m])!==1/0&&(r[m]=Number(r[m]));const{labelCn:c,labelEn:h}=await this.parseStatus(r.aisNavStatus),y=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:y.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),y=[];for(;r.diff(d,"day",!0)>30;)await this.trajectoryIn30Day(c,d.unix(),d.add(30,"day").unix(),h,t,o,y);return await this.trajectoryIn30Day(c,d.unix(),r.unix(),h,t,o,y),y}async trajectoryIn30Day(t,i,n,o,a,e,d,r={}){var j;const c={headers:{appKey:this.token},json:{shipId:t,startTime:i,endTime:n}},h="https://api3.myships.com/sp/ships/position/history",y=await D.post(h,c).json();if(u==null||u.info("[%s] fetch trajectory from: %s - %j",r.requestId,h,c),y.code!=="0")return u==null||u.warn("[%s] invoke myship trajectory failed: %j",r.requestId,y),y;const f=y.data;for(const Y in f)!isNaN(f[Y])&&Number(f[Y])!==1/0&&(f[Y]=Number(f[Y]));const m=v.unix((j=f[0])==null?void 0:j.posTime);let g=-1;for(const Y of f){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(m,"minute",!0)/(e||1));I!==g&&(g=I,d.push(l))}return d}}let R;try{R=Z.getLogger("vessel")}catch{}finally{}var G=(w=>(w.NOTICE="NOTICE",w.WARN="WARN",w.HEAVY="HEAVY",w.SEVERE="SEVERE",w.ERROR="ERROR",w.FATAL="FATAL",w))(G||{});class U{parsePrinciple(s,t={}){var e,d,r;R==null||R.info("[%s] parse rule: %s",t.requestId,s);const i=new RegExp("(?<=\\[)(.+)(?=])","g"),n=s.match(i)?(e=s.match(i))==null?void 0:e[0]:void 0,o=n==null?void 0:n.split(";");if(!o)return;const a={};for(let c=0;c<(o==null?void 0:o.length);c++){const h=(r=(d=o[c].match(i))==null?void 0:d[0])==null?void 0:r.split("],");if(c===0&&!h)a.scope=o[0];else if(h)for(let y=0,f=h.length;y<f;y++){const m=this.parseRule(h[y]);m&&(a[m.level]?m.key?a[m.level][m==null?void 0:m.key]=m:a[m.level]=m:m.key?a[m.level]={[m==null?void 0:m.key]:m}:a[m.level]=m)}}return a}parseRule(s,t={}){var a;R==null||R.info("[%s] parse rule: %s",t.requestId,s),s=s.startsWith("[")?s:`[${s}`,s=s.endsWith("]")?s:`${s}]`;const i=new RegExp("(?<=\\[)(.+?)(?=])","g"),n=(a=s==null?void 0:s.match(i))==null?void 0:a[0],o=n==null?void 0:n.split(",");if(o)return{operator:o[0],number:Number.isNaN(Number(o[1]))?o[1]:Number(o[1]),level:o[2],time:Number(o[3]),key:o[4]}}checkWeather(s,t,i={}){var m,g,j,Y,p,l,I,H,M,b,F,x,V,T,_;let n=0,o=0,a=0,e=0;const d=Math.round(((g=(m=t==null?void 0:t.SEVERE)==null?void 0:m.sigWave)==null?void 0:g.number)*1.6*100)/100,r=(Y=(j=t==null?void 0:t.SEVERE)==null?void 0:j.sigWave)==null?void 0:Y.number,c=(l=(p=t==null?void 0:t.HEAVY)==null?void 0:p.sigWave)==null?void 0:l.number,h=Math.round((((H=(I=t==null?void 0:t.SEVERE)==null?void 0:I.wind)==null?void 0:H.number)+2)*100)/100,y=(b=(M=t==null?void 0:t.SEVERE)==null?void 0:M.wind)==null?void 0:b.number,f=(x=(F=t==null?void 0:t.HEAVY)==null?void 0:F.wind)==null?void 0:x.number;for(let W=0;W<(s==null?void 0:s.length);W++){const S=s[W],L=(T=(V=S==null?void 0:S.meteo)==null?void 0:V.wave)==null?void 0:T.sig,N=(_=S==null?void 0:S.meteo)==null?void 0:_.wind,E=W?v(S.eta).diff(v(s[W-1].eta),"hour",!0):0;e=E>e?E:e,R==null||R.info("[%s] check sig.wave: %j",i.requestId,{...L,dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:c}),(L==null?void 0:L.height)>=d?S.isDangerous=!0:(L==null?void 0:L.height)>=r?S.isSevere=!0:(L==null?void 0:L.height)>=c&&(S.isHeavy=!0),R==null||R.info("[%s] check wind: %j",i.requestId,{...N,dgThd4Wd:h,svThd4Wd:y,hvThd4Wd:f}),(N==null?void 0:N.scale)>=h?(S.isDangerous=!0,delete S.isSevere,delete S.isHeavy):(N==null?void 0:N.scale)>y?(S.isDangerous||(S.isSevere=!0),delete S.isHeavy):(N==null?void 0:N.scale)===f&&!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:y,hvThd4Wd:f},sig:{dgThd4Wv:d,svThd4Wv:r,hvThd4Wv:c}}}}const dt=new U;let q;try{q=Z.getLogger("vessel")}catch{}finally{}var J=(w=>(w.common="common",w.container="container",w))(J||{}),Q=(w=>(w.Ballast="Ballast",w.Laden="Laden",w))(Q||{}),X=(w=>(w.Cp="CP",w.Perf="Basis",w.Instruct="Other",w))(X||{});class A{static blockCoefficient(s,t,i,n){let o=Math.round(s/(t*i*n)*100)/100;o=o<.55?.55:o>.85?.85:o;const a=[.55,.6,.65,.7,.75,.8,.85],e=a.map(d=>Math.abs(d-o));return a[e.indexOf(Math.min(...e))]}static froudeNumber(s,t,i=9.8){let n=Math.round(Math.sqrt(s*s/(i*t))*100)/100;return n=n<.05?.05:n>.3?.3:n,n}static amendFactor(s,t,i){const n={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.4,-10.6,-9.5],.8:[2.6,-13.1,-15.1],.85:[3.1,-18.7,28]};let a={.55:[1.7,-1.4,-7.4],.6:[2.2,-2.5,-9.7],.65:[2.6,-3.7,-11.6],.7:[3.1,-5.3,-12.4],.75:[2.6,-12.5,-13.5],.8:[3,-16.3,-21.6],.85:[3.4,-20.9,31.8]}[s];return i==="Laden"&&(a=n[s]),a[0]+a[1]*t+a[2]*Math.pow(t,2)}static directionFactor(s,t=0){let i;return s>30&&s<=60?i=(1.7-.03*Math.pow(t-4,2))/2:s>60&&s<=150?i=(.9-.06*Math.pow(t-6,2))/2:s>150&&s<=180?i=(.4-.03*Math.pow(t-8,2))/2:i=1,Math.round(i*1e5)/1e5}static vesselTagFactor(s,t,i,n=0){n=n>6?n-.9*(n-6):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,s=s>9?9:s,Math.round((-.144*Math.pow(s,2)+.178*s)*1e4)/1e4}static assembleProperties(s,t,i,n){var c,h;const o=s.lbp??s.length??s.lengthOverall??198.9642,a=s.draught??8,e=s.breadthMoulded??s.breadth??s.breadthExtreme??32.4572,d=s.deadweight??67035.7773;return{tag:((h=(c=s==null?void 0:s.type)==null?void 0:c.toLowerCase())==null?void 0:h.indexOf("container"))>-1?"container":"common",lbp:o,loadCondition:t,draught:a,breadthMoulded:e,displacement:Math.round((d/1.025+a*e*o*.7)*1e4)/1e4,speed:Math.round((i??14.1382)*1852/3600*1e4)/1e4,bearing:n||90}}static async speedLoseAt(s,t,i,n="",o=2,a=!0,e=!1,d={}){let r;if(t.velocity&&e&&(s.speed=O.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),a){const c=await nt.MeteoHelper.queryPointFactor(t.lng,t.lat,i.valueOf(),"wind,wave,current,watertemp",n,d),h=A.weatherFactor(s,c),y=A.currentFactor(s.bearing,c==null?void 0:c.current,o),f=Math.round((s.speed*1.943844+h+y)*100)/100;r={meteo:{...c},wxFactor:h,cFactor:y,speed:t.velocity&&e?t.velocity:f<0?1:f,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=[],y=[];let f=0,m=0,g,j;for(let Y=0;Y<a.length-1;Y++){let p=a[Y];p.distanceFromStart=o+m;const l=a[Y+1];if(s.bearing=O.LaneHelper.calculateBearing(p,l,!l.gcToPrevious),p.bearing=s.bearing,p.suspend&&r){p.eta=p.eta||t.format("YYYY-MM-DDTHH:mm[Z]"),p.elapsed=p.elapsed??0;const M=p.suspend-p.elapsed;if(n-f>M)n=n-f-M,t.add(M,"hour"),p.elapsed=p.suspend;else{const b=n-f;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=m,{etd:t,from:j||p,to:p,next:a.filter(b=>b),wps:h,days:y}}p=await A.speedLoseAt(s,p,t,e,0,d,r,c),j=j||p,p.important&&h.push(p),t.isSameOrAfter(i)&&(y.push(p),i.add(24,"hour"));const I=O.LaneHelper.calculateDistance(p,l,!l.gcToPrevious);let H=Math.ceil(I/j.speed*1e4)/1e4;if(f+H<n){if(f+=H,t.add(H,"hour"),delete a[Y],q==null||q.info(`[%s] go to %j from %j with ${I}nm, and cost ${H} hours`,c.requestId,{lat:l.lat,lng:l.lng},{lat:j.lat,lng:j.lng,etd:j.etd}),m+=I,a.filter(M=>M).length<=1){g=l,g.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),g.distanceFromPrevious=I,g.distanceFromStart=o+m,h.push(g),delete a[Y+1];break}}else{H=n-f,t.add(H,"hour");const M=O.LngLatHelper.roundPrecision(j.speed*H,4);g=O.LaneHelper.calculateCoordinate(p,s.bearing,M,"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 ${M}nm, and cost ${H} hours`,c.requestId,{lat:g.lat,lng:g.lng},{lat:p.lat,lng:p.lng,etd:p.etd}),m+=M,g.distanceFromPrevious=m,g.distanceFromStart=o+m;break}}return{etd:t,from:j,to:g,next:a.filter(Y=>Y),wps:h,days:y}}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,y,f,m,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,(y=t==null?void 0:t.wind)==null?void 0:y.scale),d=A.vesselTagFactor(s.displacement,s.loadCondition,s.tag,(f=t==null?void 0:t.wind)==null?void 0:f.scale);let r=e*o*d/100*s.speed;r=Math.round(r*1.943844*1e4)/1e4*-1;const c=A.waveHeightFactor(((g=(m=t==null?void 0:t.wave)==null?void 0:m.sig)==null?void 0:g.height)??1);return r=r+c,q==null||q.debug("weather factor = %s",r),r=Math.abs(r)>5?5*(Math.abs(r)/r)+Math.abs(r)/r*(Math.abs(r)-5)*.4:r,Math.round(r*100)/100}static async analyseInstant(s,t,i,n,o,a="",e=0,d=!0,r=!1,c={}){var E,$,tt,et,st;const h=v().valueOf();s.lng=O.LngLatHelper.convertToStdLng(s.lng);const{route:y,waypoints:f}=o.points,m=O.LaneHelper.calculateSubRoute(s,y);if(((E=m[0])==null?void 0:E.length)<=1)return;const{v0:g,label:j}=s.sog?{v0:s.sog,label:"Other"}:{v0:n.speed,label:"CP"},Y=A.assembleProperties(i,n.loadCondition,g,0),p=f.length?O.LaneHelper.calculateSubWaypoints(s,f):[];p.forEach(C=>C.important=!0);const l={from:{...s},route:m,waypoints:p,v0:g,label:j},I={hours:[],days:[],wps:[]};e||(O.LaneHelper.calculateRouteDistance(m)/n.speed<=72?e=3:e=6);let H=O.LaneHelper.simplifyRouteToCoordinates(m,p,0),M=0,b=0,F=0,x=0;t=v(t).utc();const V=t.clone();for(;H.length>0;){const C=e-t.hour()%e,B=Math.ceil(t.clone().add(C,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,P=await A.speedLoseInHoursStep(Y,t,V,B,M,H,a,d,r,c);($=P.from)!=null&&$.speed&&(I.hours.push(P.from),I.wps.push(...P.wps),I.days.push(...P.days)),H=P==null?void 0:P.next,H.length||I.hours.push(P==null?void 0:P.to),M+=((tt=P==null?void 0:P.to)==null?void 0:tt.distanceFromPrevious)??0}const T=I.hours;for(let C=0;C<T.length-1;C++){const B=v(T[C+1].eta).diff(T[C].etd,"hour",!0)||1;b+=(T[C].wxFactor||0)*B,F+=(T[C].cFactor||0)*B,x+=B}(et=I.wps)==null||et.forEach((C,B)=>{if(B){const P=I.wps[B-1],ut=C.distanceFromStart-P.distanceFromStart,at=v(C.eta).diff(v(P.etd),"h",!0);at<1?C.avgSpd=P.speed:C.avgSpd=Math.round(ut/at*100)/100}}),l.sample=I;const _=I.hours.at(0),W=I.hours.at(-1);l.distance=Math.round(W.distanceFromStart*1e4)/1e4,l.etd=v(_.eta).utc().format(),l.eta=v(W.eta).utc().format(),l.wxFactor=Math.round(b/x*1e4)/1e4,l.cFactor=Math.round(F/x*1e4)/1e4,l.avgSpeed=Math.round(W.distanceFromStart/x*1e4)/1e4,l.totalHrs=Math.round(x*1e4)/1e4,l.totalFoCons=Math.round((n==null?void 0:n.fo)/24*l.totalHrs*1e3)/1e3,l.totalDgoCons=Math.round((n==null?void 0:n.dgo)/24*l.totalHrs*1e3)/1e3;const L=v().valueOf()-h,N=((st=I==null?void 0:I.hours)==null?void 0:st.length)||1;return q==null||q.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",c==null?void 0:c.requestId,L,N,Math.round(L/N*1e3)/1e3),l}static async analyseInstantWithThreshed(s,t,i,n,o,a,e,d="",r=3,c=!0,h=!1,y={}){var W,S,L;s.lng=O.LngLatHelper.convertToStdLng(s.lng);const{v0:f,label:m}=s.sog?{v0:s.sog,label:"Other"}:{v0:o.speed,label:"CP"},g=A.assembleProperties(n,o.loadCondition,f,0),j=O.LaneHelper.calculateSubRoute(s,a);if(((W=j[0])==null?void 0:W.length)<=1)return;const Y=e.length?O.LaneHelper.calculateSubWaypoints(s,e):[];Y.forEach(N=>N.important=!0);let p=O.LaneHelper.simplifyRouteToCoordinates(j,Y,0),l=0,I=0,H=0,M=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,y),(S=b.from)!=null&&S.speed&&(F.hours.push(b.from),b!=null&&b.wps&&F.wps.push(...b.wps),F.days.push(...b.days)),p=b==null?void 0:b.next,p.length||(F.hours.push(b==null?void 0:b.to),b!=null&&b.wps&&F.wps.push(...b.wps),F.days.push(b==null?void 0:b.to)),l+=((L=b==null?void 0:b.to)==null?void 0:L.distanceFromPrevious)??0;else{b&&(F.hours.push(b.to),b!=null&&b.wps&&F.wps.push(...b.wps),F.days.push(b.to));break}}const x=F.hours;for(let N=0;N<x.length-1;N++){const E=v(x[N+1].eta).diff(x[N].etd,"hour",!0);I+=x[N].wxFactor*E,H+=x[N].cFactor*E,M+=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/M*1e4)/1e4,cFactor:Math.round(H/M*1e4)/1e4,avgSpeed:Math.round(((T==null?void 0:T.distanceFromStart)||0)/M*1e4)/1e4,totalHrs:Math.round(M*1e4)/1e4,from:s,to:T,route:j,waypoints:Y,v0:f,label:m}}}k.AISImpl=z,k.AlertHelper=U,k.AlertLevel=G,k.HifleetImpl=it,k.LoadCondition=Q,k.MyShipImpl=ct,k.MyVesselImpl=ot,k.ShipxyImpl=rt,k.SpeedHelper=A,k.SpeedLabel=X,k.VesselTag=J,k.alertHelper=dt,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
1
+ (function(k,D){typeof exports=="object"&&typeof module<"u"?D(exports,require("got"),require("@log4js-node/log4js-api"),require("moment"),require("@idm-plugin/geo"),require("@idm-plugin/meteo")):typeof define=="function"&&define.amd?define(["exports","got","@log4js-node/log4js-api","moment","@idm-plugin/geo","@idm-plugin/meteo"],D):(k=typeof globalThis<"u"?globalThis:k||self,D(k["idm-plugin-rabbitmq"]={},k.got,k["@log4js-node/log4js-api"],k.moment,k["@idm-plugin/geo"],k["@idm-plugin/meteo"]))})(this,function(k,D,Z,g,O,nt){"use strict";var ht=Object.defineProperty;var lt=(k,D,Z)=>D in k?ht(k,D,{enumerable:!0,configurable:!0,writable:!0,value:Z}):k[D]=Z;var K=(k,D,Z)=>(lt(k,typeof D!="symbol"?D+"":D,Z),Z);let u;try{u=Z.getLogger("vessel")}catch{}finally{}class z{parseStatus(s){let t,i;switch(s){case 0:t="在航(主机推动)",i="The engine is in use";break;case 1:t="锚泊",i="Anchored";break;case 2:t="失控",i="Not operated";break;case 3:t="操纵受限",i="Limited airworthiness";break;case 4:t="吃水受限",i="Limited by ship's draft";break;case 5:t="靠泊",i="Mooring";break;case 6:t="搁浅",i="Stranded";break;case 7:t="捕捞作业",i="Engaged in fishing";break;case 8:t="靠帆船提供动力",i="Sailing";break;default:t="未定义",i="Undefined"}return{labelCn:t,labelEn:i}}}class ot extends z{constructor(t,i){super();K(this,"clientId");K(this,"clientSecret");K(this,"token");this.clientId=t,this.clientSecret=i}async authToken(t={}){const i="https://svc.data.myvessel.cn/ada/oauth/token",n={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},o=await D.post(i,n).json();u==null||u.info("[%s] fetch access token from: %s - %j",t.requestId,i,o),o.error||(this.token={accessToken:o.access_token,tokenType:o.token_type,expiresIn:o.expires_in,scope:o.scope,jti:o.jti,issuedAt:g().utc().format()})}async realTimePosition(t,i={}){var d,l,p;(!this.token||g().diff(g(this.token.issuedAt),"seconds")>((d=this.token)==null?void 0:d.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} ${(p=this.token)==null?void 0:p.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 f in e)!isNaN(e[f])&&Number(e[f])!==1/0&&(e[f]=Number(e[f]));const c=g(`${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:c.unix(),status:e.status,labelCn:e.statusNameCn,labelEn:e.statusNameEn,method:"position",vendor:"myVessel",utc:c.utc().format()}}async trajectory(t,i,n,o,a=!0,e={}){(!this.token||g().diff(g(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(e);const c=await this.realTimePosition(t,e),r=g(i),d=g(n),l=[];for(;d.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(t,r,r.clone().add(30,"day"),c,o,l,e),r.add(30,"day");return await this.trajectoryIn30Day(t,r,d,c,o,l,e),l}async trajectoryIn30Day(t,i,n,o,a,e,c={}){var m,v,j,Y,M;const r="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",d={headers:{Authorization:`${(m=this.token)==null?void 0:m.tokenType} ${(v=this.token)==null?void 0:v.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",c.requestId,r,d);const l=await D.post(r,d).json();if(l.code)return u==null||u.warn("[%s] fetch trajectory failed: %j",c.requestId,r,{message:l.message,status:l.status,code:l.code}),l;let p=-1;const f=g(`${(Y=(j=l.data)==null?void 0:j[0])==null?void 0:Y.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(M=l.data)==null||M.forEach(h=>{for(const T in h)!isNaN(h[T])&&Number(h[T])!==1/0&&(h[T]=Number(h[T]));const I=g(`${h.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),H=h.eta?g(`${h.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,y=h.status,{labelCn:b,labelEn:F}=this.parseStatus(y),x={mmsi:h.mmsi,imo:o==null?void 0:o.imo,lat:h.lat,lng:h.lon,sog:h.sog,cog:h.cog,hdg:h.hdg,draught:h.draught,status:y,eta:H==null?void 0:H.unix(),destination:h.dest,positionTime:I.unix(),labelCn:b,labelEn:F,method:"trajectory",vendor:"myVessel",utc:I.utc().format()},V=Math.floor(I.diff(f,"minute",!0)/(a||1));V!==p&&(p=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 f in e)!isNaN(e[f])&&Number(e[f])!==1/0&&(e[f]=Number(e[f]));e.status=e.sp>3?0:1;const c=e.status,{labelCn:r,labelEn:d}=this.parseStatus(c),l=g(`${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)?g(`${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:c,labelCn:r,labelEn:d,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 c in a)!isNaN(a[c])&&Number(a[c])!==1/0&&(a[c]=Number(a[c]));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 h,I,H;const c=await this.realTimePosition(t,e);let r=g(i);const d=g(n),l=g();if(a){let y=d.diff(r,"d",!0);y<0?r=d.clone().subtract(40,"d"):y<30?r.subtract(10,"d"):y<60?r.subtract(5,"d"):r=d.clone().subtract(80,"d"),y=l.diff(d,"d",!0),d.add(y>10?240:y*24,"h")}const p={searchParams:{endtime:d.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}},f="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",m=await D.get(f,p).json();u==null||u.info("[%s] fetch trajectory from: %s - %j",e.requestId,f,p);let v;m&&(v=((I=(h=m.ships)==null?void 0:h.offors)==null?void 0:I.ship)||[],v.length||u==null||u.warn("[%s] fetch trajectory failed: %j",e.requestId,m));const j=[];let Y=-1;const M=g(`${(H=v==null?void 0:v[0])==null?void 0:H.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const y of v){for(const _ in y)!isNaN(y[_])&&Number(y[_])!==1/0&&(y[_]=Number(y[_]));const b=g(`${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:c==null?void 0:c.imo,lat:y.la,lng:y.lo,draught:y.draught,sog:y.sp,cog:y.co,hdg:y.hdg,positionTime:b.unix(),utc:b.utc().format(),status:y.status,labelCn:x,labelEn:F,method:"trajectory",vendor:"hifleet"},T=Math.floor(b.diff(M,"minute",!0)/(o||1));T!==Y&&(Y=T,j.push(V))}return j}}class rt extends z{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,i={}){const n={searchParams:{id:t,k:this.token,enc:1}},o="https://api.shipxy.com/apicall/GetSingleShip",a=await D.get(o,n).json();if(u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,o,n),(a==null?void 0:a.status)!==0)return a;const e=a.data[0];for(const p in e)!isNaN(e[p])&&Number(e[p])!==1/0&&(e[p]=Number(e[p]));const{labelCn:c,labelEn:r}=await this.parseStatus(e.navistat),d=g.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:d.utc().format(),status:e.navistat,labelEn:r,labelCn:c,method:"position",vendor:"shipxy"}}async trajectory(t,i,n,o,a=!0,e={}){var M;const c=await this.realTimePosition(t,e),r=g(i),d=g(n),l="https://api.shipxy.com/apicall/GetShipTrack",p={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:r.unix(),etm:d.unix()}},f=await D.get(l,p).json();if(u==null||u.info("[%s] fetch trajectory from: %s - %j",e.requestId,l,p),(f==null?void 0:f.status)!==0)return f;const m=f==null?void 0:f.points,v=[],j=g.unix((M=m[0])==null?void 0:M.utc);let Y=-1;for(const h of m){const I=g.unix(h.utc),H={imo:c==null?void 0:c.imo,mmsi:t,sog:Math.round(h.sog*3600/1e3/1852*100)/100,cog:Math.round(h.cog/100*100)/100,lat:Math.round(h.lat/1e6*1e5)/1e5,lng:Math.round(h.lon/1e6*1e5)/1e5,positionTime:I.unix(),utc:I.utc().format(),method:"trajectory",vendor:"shipxy"},y=Math.floor(I.diff(j,"minute",!0)/(o||1));y!==Y&&(Y=y,v.push(H))}return v}}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 c=e.imo;return t==="407170"&&(c="9198379",u==null||u.warn("[%s] ship(%s) imo error: %s, should be %s",i.requestId,t,e.imo,c)),{mmsi:e.mmsi,name:e.shipnameEn,imo:c,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",c=await D.post(e,a).json();u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,e,a);const r=c.data[0];for(const m in r)!isNaN(r[m])&&Number(r[m])!==1/0&&(r[m]=Number(r[m]));const{labelCn:d,labelEn:l}=await this.parseStatus(r.aisNavStatus),p=g.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:p.utc().format(),status:r.aisNavStatus,labelEn:l,labelCn:d,method:"position",vendor:"myship"}}async trajectory(t,i,n,o,a=!0,e={}){const c=g(i),r=g(n),d=await this.getShipId(t),l=await this.getShipInfo(d),p=[];for(;r.diff(c,"day",!0)>30;)await this.trajectoryIn30Day(d,c.unix(),c.add(30,"day").unix(),l,t,o,p);return await this.trajectoryIn30Day(d,c.unix(),r.unix(),l,t,o,p),p}async trajectoryIn30Day(t,i,n,o,a,e,c,r={}){var j;const d={headers:{appKey:this.token},json:{shipId:t,startTime:i,endTime:n}},l="https://api3.myships.com/sp/ships/position/history",p=await D.post(l,d).json();if(u==null||u.info("[%s] fetch trajectory from: %s - %j",r.requestId,l,d),p.code!=="0")return u==null||u.warn("[%s] invoke myship trajectory failed: %j",r.requestId,p),p;const f=p.data;for(const Y in f)!isNaN(f[Y])&&Number(f[Y])!==1/0&&(f[Y]=Number(f[Y]));const m=g.unix((j=f[0])==null?void 0:j.posTime);let v=-1;for(const Y of f){const M=g.unix(Y.posTime),h={imo:o==null?void 0:o.imo,mmsi:a,lat:Math.round(Y.lat/1e4/60*1e5)/1e5,lng:Math.round(Y.lon/1e4/60*1e5)/1e5,sog:Math.round(Y.sog/10*100)/100,cog:Math.round(Y.cog/10*100)/100,hdg:Math.round(Y.heading*100)/100,rot:Math.round(Y.rot*100)/100,positionTime:M.unix(),utc:M.utc().format(),method:"trajectory",vendor:"myship"},I=Math.floor(M.diff(m,"minute",!0)/(e||1));I!==v&&(v=I,c.push(h))}return c}}let R;try{R=Z.getLogger("vessel")}catch{}finally{}var G=(w=>(w.NOTICE="NOTICE",w.WARN="WARN",w.HEAVY="HEAVY",w.SEVERE="SEVERE",w.ERROR="ERROR",w.FATAL="FATAL",w))(G||{});class U{parsePrinciple(s,t={}){var e,c,r;R==null||R.info("[%s] parse rule: %s",t.requestId,s);const i=new RegExp("(?<=\\[)(.+)(?=])","g"),n=s.match(i)?(e=s.match(i))==null?void 0:e[0]:void 0,o=n==null?void 0:n.split(";");if(!o)return;const a={};for(let d=0;d<(o==null?void 0:o.length);d++){const l=(r=(c=o[d].match(i))==null?void 0:c[0])==null?void 0:r.split("],");if(d===0&&!l)a.scope=o[0];else if(l)for(let p=0,f=l.length;p<f;p++){const m=this.parseRule(l[p]);m&&(a[m.level]?m.key?a[m.level][m==null?void 0:m.key]=m:a[m.level]=m:m.key?a[m.level]={[m==null?void 0:m.key]:m}:a[m.level]=m)}}return a}parseRule(s,t={}){var a;R==null||R.info("[%s] parse rule: %s",t.requestId,s),s=s.startsWith("[")?s:`[${s}`,s=s.endsWith("]")?s:`${s}]`;const i=new RegExp("(?<=\\[)(.+?)(?=])","g"),n=(a=s==null?void 0:s.match(i))==null?void 0:a[0],o=n==null?void 0:n.split(",");if(o)return{operator:o[0],number:Number.isNaN(Number(o[1]))?o[1]:Number(o[1]),level:o[2],time:Number(o[3]),key:o[4]}}checkWeather(s,t,i={}){var m,v,j,Y,M,h,I,H,y,b,F,x,V,T,_;let n=0,o=0,a=0,e=0;const c=Math.round(((v=(m=t==null?void 0:t.SEVERE)==null?void 0:m.sigWave)==null?void 0:v.number)*1.6*100)/100,r=(Y=(j=t==null?void 0:t.SEVERE)==null?void 0:j.sigWave)==null?void 0:Y.number,d=(h=(M=t==null?void 0:t.HEAVY)==null?void 0:M.sigWave)==null?void 0:h.number,l=Math.round((((H=(I=t==null?void 0:t.SEVERE)==null?void 0:I.wind)==null?void 0:H.number)+2)*100)/100,p=(b=(y=t==null?void 0:t.SEVERE)==null?void 0:y.wind)==null?void 0:b.number,f=(x=(F=t==null?void 0:t.HEAVY)==null?void 0:F.wind)==null?void 0:x.number;for(let W=0;W<(s==null?void 0:s.length);W++){const S=s[W],L=(T=(V=S==null?void 0:S.meteo)==null?void 0:V.wave)==null?void 0:T.sig,N=(_=S==null?void 0:S.meteo)==null?void 0:_.wind,E=W?g(S.eta).diff(g(s[W-1].eta),"hour",!0):0;e=E>e?E:e,R==null||R.info("[%s] check sig.wave: %j",i.requestId,{...L,dgThd4Wv:c,svThd4Wv:r,hvThd4Wv:d}),(L==null?void 0:L.height)>=c?S.isDangerous=!0:(L==null?void 0:L.height)>=r?S.isSevere=!0:(L==null?void 0:L.height)>=d&&(S.isHeavy=!0),R==null||R.info("[%s] check wind: %j",i.requestId,{...N,dgThd4Wd:l,svThd4Wd:p,hvThd4Wd:f}),(N==null?void 0:N.scale)>=l?(S.isDangerous=!0,delete S.isSevere,delete S.isHeavy):(N==null?void 0:N.scale)>p?(S.isDangerous||(S.isSevere=!0),delete S.isHeavy):(N==null?void 0:N.scale)===f&&!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:l,svThd4Wd:p,hvThd4Wd:f},sig:{dgThd4Wv:c,svThd4Wv:r,hvThd4Wv:d}}}}const dt=new U;let q;try{q=Z.getLogger("vessel")}catch{}finally{}var J=(w=>(w.common="common",w.container="container",w.tugs="tugs",w))(J||{}),Q=(w=>(w.Ballast="Ballast",w.Laden="Laden",w))(Q||{}),X=(w=>(w.Cp="CP",w.Perf="Basis",w.Instruct="Other",w))(X||{});class A{static blockCoefficient(s,t,i,n){let o=Math.round(s/(t*i*n)*100)/100;o=o<.55?.55:o>.85?.85:o;const a=[.55,.6,.65,.7,.75,.8,.85],e=a.map(c=>Math.abs(c-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:s>150&&s<=180?i=(.4-.03*Math.pow(t-8,2))/2:i=1,Math.round(i*1e5)/1e5}static vesselTagFactor(s,t,i,n=0){n=n>6?n-.9*(n-6):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,s=s>9?9:s,Math.round((-.144*Math.pow(s,2)+.178*s)*1e4)/1e4}static assembleProperties(s,t,i,n){var p;const o=s.lbp??s.length??s.lengthOverall??198.9642,a=s.draught??8,e=s.breadthMoulded??s.breadth??s.breadthExtreme??32.4572,c=s.deadweight??67035.7773,r=((p=s==null?void 0:s.type)==null?void 0:p.toLowerCase())||"common";return{tag:r.indexOf("container")>-1?"container":r.indexOf("tugs")>-1?"tugs":"common",lbp:o,loadCondition:t,draught:a,breadthMoulded:e,displacement:Math.round((c/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,c={}){let r;if(t.velocity&&e&&(s.speed=O.LngLatHelper.roundPrecision(t.velocity*1852/3600,6)),a){const d=await nt.MeteoHelper.queryPointFactor(t.lng,t.lat,i.valueOf(),"wind,wave,current,watertemp",n,c),l=A.weatherFactor(s,d),p=A.currentFactor(s.bearing,d==null?void 0:d.current,o),f=Math.round((s.speed*1.943844+l+p)*100)/100;r={meteo:{...d},wxFactor:l,cFactor:p,speed:t.velocity&&e?t.velocity:f<0?1:f,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="",c=!0,r=!1,d={}){t.utc();const l=[],p=[];let f=0,m=0,v,j;for(let Y=0;Y<a.length-1;Y++){let M=a[Y];M.distanceFromStart=o+m;const h=a[Y+1];if(s.bearing=O.LaneHelper.calculateBearing(M,h,!h.gcToPrevious),M.bearing=s.bearing,M.suspend&&r){M.eta=M.eta||t.format("YYYY-MM-DDTHH:mm[Z]"),M.elapsed=M.elapsed??0;const y=M.suspend-M.elapsed;if(n-f>y)n=n-f-y,t.add(y,"hour"),M.elapsed=M.suspend;else{const b=n-f;M.elapsed+=b,t.add(b,"hour"),n=0}if(q==null||q.info(`[%s] suspend ${M.elapsed} hours at %j, and remain ${n} hours need to go...`,d.requestId,M),n===0)return M.distanceFromPrevious=m,{etd:t,from:j||M,to:M,next:a.filter(b=>b),wps:l,days:p}}M=await A.speedLoseAt(s,M,t,e,0,c,r,d),j=j||M,M.important&&l.push(M),t.isSameOrAfter(i)&&(p.push(M),i.add(24,"hour"));const I=O.LaneHelper.calculateDistance(M,h,!h.gcToPrevious);let H=Math.ceil(I/j.speed*1e4)/1e4;if(f+H<n){if(f+=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`,d.requestId,{lat:h.lat,lng:h.lng},{lat:j.lat,lng:j.lng,etd:j.etd}),m+=I,a.filter(y=>y).length<=1){v=h,v.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),v.distanceFromPrevious=I,v.distanceFromStart=o+m,l.push(v),delete a[Y+1];break}}else{H=n-f,t.add(H,"hour");const y=O.LngLatHelper.roundPrecision(j.speed*H,4);v=O.LaneHelper.calculateCoordinate(M,s.bearing,y,"nauticalmiles",!h.gcToPrevious),v.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),a[Y]=v,q==null||q.info(`[%s] go to %j from %j with ${y}nm, and cost ${H} hours`,d.requestId,{lat:v.lat,lng:v.lng},{lat:M.lat,lng:M.lng,etd:M.etd}),m+=y,v.distanceFromPrevious=m,v.distanceFromStart=o+m;break}}return{etd:t,from:j,to:v,next:a.filter(Y=>Y),wps:l,days:p}}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,p,f,m,v;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-(((l=t==null?void 0:t.wind)==null?void 0:l.degree)%360||0));a=a>180?360-a:a;const e=A.directionFactor(a,(p=t==null?void 0:t.wind)==null?void 0:p.scale),c=A.vesselTagFactor(s.displacement,s.loadCondition,s.tag,(f=t==null?void 0:t.wind)==null?void 0:f.scale);let r=e*o*c/100*s.speed;r=Math.round(r*1.943844*1e4)/1e4*-1,s.tag==="tugs"&&Math.abs(r)>1&&(r=r/(Math.abs(Math.round(r))+1));const d=A.waveHeightFactor(((v=(m=t==null?void 0:t.wave)==null?void 0:m.sig)==null?void 0:v.height)??1);return r=r+d,q==null||q.debug("weather factor = %s",r),r=Math.abs(r)>5?5*(Math.abs(r)/r)+Math.abs(r)/r*(Math.abs(r)-5)*.4:r,Math.round(r*100)/100}static async analyseInstant(s,t,i,n,o,a="",e=0,c=!0,r=!1,d={}){var E,$,tt,et,st;const l=g().valueOf();s.lng=O.LngLatHelper.convertToStdLng(s.lng);const{route:p,waypoints:f}=o.points,m=O.LaneHelper.calculateSubRoute(s,p);if(((E=m[0])==null?void 0:E.length)<=1)return;const{v0:v,label:j}=s.sog?{v0:s.sog,label:"Other"}:{v0:n.speed,label:"CP"},Y=A.assembleProperties(i,n.loadCondition,v,0),M=f.length?O.LaneHelper.calculateSubWaypoints(s,f):[];M.forEach(C=>C.important=!0);const h={from:{...s},route:m,waypoints:M,v0:v,label:j},I={hours:[],days:[],wps:[]};e||(O.LaneHelper.calculateRouteDistance(m)/n.speed<=72?e=3:e=6);let H=O.LaneHelper.simplifyRouteToCoordinates(m,M,0),y=0,b=0,F=0,x=0;t=g(t).utc();const V=t.clone();for(;H.length>0;){const C=e-t.hour()%e,B=Math.ceil(t.clone().add(C,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,P=await A.speedLoseInHoursStep(Y,t,V,B,y,H,a,c,r,d);($=P.from)!=null&&$.speed&&(I.hours.push(P.from),I.wps.push(...P.wps),I.days.push(...P.days)),H=P==null?void 0:P.next,H.length||I.hours.push(P==null?void 0:P.to),y+=((tt=P==null?void 0:P.to)==null?void 0:tt.distanceFromPrevious)??0}const T=I.hours;for(let C=0;C<T.length-1;C++){const B=g(T[C+1].eta).diff(T[C].etd,"hour",!0)||1;b+=(T[C].wxFactor||0)*B,F+=(T[C].cFactor||0)*B,x+=B}(et=I.wps)==null||et.forEach((C,B)=>{if(B){const P=I.wps[B-1],ut=C.distanceFromStart-P.distanceFromStart,at=g(C.eta).diff(g(P.etd),"h",!0);at<1?C.avgSpd=P.speed:C.avgSpd=Math.round(ut/at*100)/100}}),h.sample=I;const _=I.hours.at(0),W=I.hours.at(-1);h.distance=Math.round(W.distanceFromStart*1e4)/1e4,h.etd=g(_.eta).utc().format(),h.eta=g(W.eta).utc().format(),h.wxFactor=Math.round(b/x*1e4)/1e4,h.cFactor=Math.round(F/x*1e4)/1e4,h.avgSpeed=Math.round(W.distanceFromStart/x*1e4)/1e4,h.totalHrs=Math.round(x*1e4)/1e4,h.totalFoCons=Math.round((n==null?void 0:n.fo)/24*h.totalHrs*1e3)/1e3,h.totalDgoCons=Math.round((n==null?void 0:n.dgo)/24*h.totalHrs*1e3)/1e3;const L=g().valueOf()-l,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",d==null?void 0:d.requestId,L,N,Math.round(L/N*1e3)/1e3),h}static async analyseInstantWithThreshed(s,t,i,n,o,a,e,c="",r=3,d=!0,l=!1,p={}){var W,S,L;s.lng=O.LngLatHelper.convertToStdLng(s.lng);const{v0:f,label:m}=s.sog?{v0:s.sog,label:"Other"}:{v0:o.speed,label:"CP"},v=A.assembleProperties(n,o.loadCondition,f,0),j=O.LaneHelper.calculateSubRoute(s,a);if(((W=j[0])==null?void 0:W.length)<=1)return;const Y=e.length?O.LaneHelper.calculateSubWaypoints(s,e):[];Y.forEach(N=>N.important=!0);let M=O.LaneHelper.simplifyRouteToCoordinates(j,Y,0),h=0,I=0,H=0,y=0,b;const F={hours:[],wps:[],days:[]};for(t=g(t).utc();M.length>0;){const N=r-t.hour()%r;let E=Math.ceil(t.clone().add(N,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;if(E=t.clone().add(E,"h").isAfter(i)?i.diff(t,"h",!0)*1e4/1e4:E,E)b=await A.speedLoseInHoursStep(v,t,i.clone(),E,h,M,c,d,l,p),(S=b.from)!=null&&S.speed&&(F.hours.push(b.from),b!=null&&b.wps&&F.wps.push(...b.wps),F.days.push(...b.days)),M=b==null?void 0:b.next,M.length||(F.hours.push(b==null?void 0:b.to),b!=null&&b.wps&&F.wps.push(...b.wps),F.days.push(b==null?void 0:b.to)),h+=((L=b==null?void 0:b.to)==null?void 0:L.distanceFromPrevious)??0;else{b&&(F.hours.push(b.to),b!=null&&b.wps&&F.wps.push(...b.wps),F.days.push(b.to));break}}const x=F.hours;for(let N=0;N<x.length-1;N++){const E=g(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:g(V.eta).utc().format(),eta:g(T==null?void 0:T.eta).utc().format(),wxFactor:Math.round(I/y*1e4)/1e4,cFactor:Math.round(H/y*1e4)/1e4,avgSpeed:Math.round(((T==null?void 0:T.distanceFromStart)||0)/y*1e4)/1e4,totalHrs:Math.round(y*1e4)/1e4,from:s,to:T,route:j,waypoints:Y,v0:f,label:m}}}k.AISImpl=z,k.AlertHelper=U,k.AlertLevel=G,k.HifleetImpl=it,k.LoadCondition=Q,k.MyShipImpl=ct,k.MyVesselImpl=ot,k.ShipxyImpl=rt,k.SpeedHelper=A,k.SpeedLabel=X,k.VesselTag=J,k.alertHelper=dt,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
@@ -5,7 +5,8 @@ import moment from 'moment';
5
5
  */
6
6
  export declare enum VesselTag {
7
7
  common = "common",
8
- container = "container"
8
+ container = "container",
9
+ tugs = "tugs"
9
10
  }
10
11
  /**
11
12
  * 船舶加载状态,laden/ ballast
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idm-plugin/vessel",
3
3
  "private": false,
4
- "version": "1.3.5",
4
+ "version": "1.3.6",
5
5
  "description": "idm plugin for vessel",
6
6
  "type": "module",
7
7
  "keywords": [