@idm-plugin/vessel 1.4.5 → 1.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,7 +15,7 @@ export interface AISRecord {
15
15
  cog?: number;
16
16
  hdg?: number;
17
17
  rot?: number;
18
- eta?: number;
18
+ eta?: string;
19
19
  destination?: string;
20
20
  positionTime?: number;
21
21
  status?: number;
package/dist/index.js CHANGED
@@ -1,14 +1,15 @@
1
- var et = Object.defineProperty;
2
- var st = (I, s, t) => s in I ? et(I, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : I[s] = t;
3
- var Z = (I, s, t) => (st(I, typeof s != "symbol" ? s + "" : s, t), t);
4
- import R from "got";
1
+ var st = Object.defineProperty;
2
+ var at = (I, s, t) => s in I ? st(I, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : I[s] = t;
3
+ var Z = (I, s, t) => (at(I, typeof s != "symbol" ? s + "" : s, t), t);
4
+ import A from "got";
5
5
  import z from "@log4js-node/log4js-api";
6
6
  import v from "moment";
7
7
  import { LngLatHelper as B, LaneHelper as V } from "@idm-plugin/geo";
8
- import { MeteoHelper as at } from "@idm-plugin/meteo";
9
- let u;
8
+ import { MeteoHelper2 as ot, MeteoHelper as nt } from "@idm-plugin/meteo2";
9
+ import { Meteo2Assist as tt } from "@idm-plugin/meteo";
10
+ let h;
10
11
  try {
11
- u = z.getLogger("vessel");
12
+ h = z.getLogger("vessel");
12
13
  } catch {
13
14
  } finally {
14
15
  }
@@ -53,7 +54,7 @@ class K {
53
54
  return { labelCn: t, labelEn: i };
54
55
  }
55
56
  }
56
- class pt extends K {
57
+ class bt extends K {
57
58
  constructor(t, i) {
58
59
  super();
59
60
  Z(this, "clientId");
@@ -68,8 +69,8 @@ class pt extends K {
68
69
  client_secret: this.clientSecret,
69
70
  grant_type: "client_credentials"
70
71
  }
71
- }, n = await R.post(i, o).json();
72
- u == null || u.info("[%s] fetch access token from: %s - %j", t.requestId, i, n), n.error || (this.token = {
72
+ }, n = await A.post(i, o).json();
73
+ h == null || h.info("[%s] fetch access token from: %s - %j", t.requestId, i, n), n.error || (this.token = {
73
74
  accessToken: n.access_token,
74
75
  tokenType: n.token_type,
75
76
  expiresIn: n.expires_in,
@@ -79,21 +80,21 @@ class pt extends K {
79
80
  });
80
81
  }
81
82
  async realTimePosition(t, i = {}) {
82
- var d, l, M;
83
+ var d, f, M;
83
84
  (!this.token || v().diff(v(this.token.issuedAt), "seconds") > ((d = this.token) == null ? void 0 : d.expiresIn) - 300) && await this.authToken(i);
84
85
  const o = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit", n = {
85
86
  headers: {
86
- Authorization: `${(l = this.token) == null ? void 0 : l.tokenType} ${(M = this.token) == null ? void 0 : M.accessToken}`
87
+ Authorization: `${(f = this.token) == null ? void 0 : f.tokenType} ${(M = this.token) == null ? void 0 : M.accessToken}`
87
88
  },
88
89
  searchParams: { mmsi: t }
89
90
  };
90
- u == null || u.info("[%s] fetch realtime position from: %s - %j", i.requestId, o, n);
91
- const a = await R.get(o, n).json();
91
+ h == null || h.info("[%s] fetch realtime position from: %s - %j", i.requestId, o, n);
92
+ const a = await A.get(o, n).json();
92
93
  if (a.code)
93
- return u == null || u.warn("[%s] fetch realtime position failed: %j", i.requestId, o, { message: a.message, status: a.status, code: a.code }), a;
94
+ return h == null || h.warn("[%s] fetch realtime position failed: %j", i.requestId, o, { message: a.message, status: a.status, code: a.code }), a;
94
95
  const e = a.data;
95
- for (const f in e)
96
- !isNaN(e[f]) && Number(e[f]) !== 1 / 0 && (e[f] = Number(e[f]));
96
+ for (const m in e)
97
+ !isNaN(e[m]) && Number(e[m]) !== 1 / 0 && (e[m] = Number(e[m]));
97
98
  const c = v(`${e.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
98
99
  return {
99
100
  mmsi: e.mmsi,
@@ -109,7 +110,7 @@ class pt extends K {
109
110
  cog: e.cog,
110
111
  hdg: e.hdg,
111
112
  rot: e.rot,
112
- eta: e.eta,
113
+ eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta) ? v.utc(e.eta).format() : void 0,
113
114
  destination: e.dest,
114
115
  positionTime: c.unix(),
115
116
  status: e.status,
@@ -122,16 +123,16 @@ class pt extends K {
122
123
  }
123
124
  async trajectory(t, i, o, n, a = !0, e = {}) {
124
125
  (!this.token || v().diff(v(this.token.issuedAt), "seconds") > this.token.expiresIn - 300) && await this.authToken(e);
125
- const c = await this.realTimePosition(t, e), r = v(i), d = v(o), l = [];
126
+ const c = await this.realTimePosition(t, e), r = v(i), d = v(o), f = [];
126
127
  for (; d.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, d, c, n, l, e), l;
128
+ await this.trajectoryIn30Day(t, r, r.clone().add(30, "day"), c, n, f, e), r.add(30, "day");
129
+ return await this.trajectoryIn30Day(t, r, d, c, n, f, e), f;
129
130
  }
130
131
  async trajectoryIn30Day(t, i, o, n, a, e, c = {}) {
131
- var m, Y, j, b, p;
132
+ var u, Y, j, b, p;
132
133
  const r = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", d = {
133
134
  headers: {
134
- Authorization: `${(m = this.token) == null ? void 0 : m.tokenType} ${(Y = this.token) == null ? void 0 : Y.accessToken}`
135
+ Authorization: `${(u = this.token) == null ? void 0 : u.tokenType} ${(Y = this.token) == null ? void 0 : Y.accessToken}`
135
136
  },
136
137
  json: {
137
138
  mmsi: t,
@@ -139,39 +140,39 @@ class pt extends K {
139
140
  endTime: o.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")
140
141
  }
141
142
  };
142
- u == null || u.info("[%s] fetch trajectory from: %s - %j", c.requestId, r, d);
143
- const l = await R.post(r, d).json();
144
- if (l.code)
145
- return u == null || u.warn("[%s] fetch trajectory failed: %j", c.requestId, r, { message: l.message, status: l.status, code: l.code }), l;
143
+ h == null || h.info("[%s] fetch trajectory from: %s - %j", c.requestId, r, d);
144
+ const f = await A.post(r, d).json();
145
+ if (f.code)
146
+ return h == null || h.warn("[%s] fetch trajectory failed: %j", c.requestId, r, { message: f.message, status: f.status, code: f.code }), f;
146
147
  let M = -1;
147
- const f = v(`${(b = (j = l.data) == null ? void 0 : j[0]) == null ? void 0 : b.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
148
- return (p = l.data) == null || p.forEach((h) => {
149
- for (const T in h)
150
- !isNaN(h[T]) && Number(h[T]) !== 1 / 0 && (h[T] = Number(h[T]));
151
- const k = v(`${h.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), w = h.eta ? v(`${h.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00") : void 0, y = h.status, { labelCn: g, labelEn: N } = this.parseStatus(y), F = {
152
- mmsi: h.mmsi,
148
+ const m = v(`${(b = (j = f.data) == null ? void 0 : j[0]) == null ? void 0 : b.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
149
+ return (p = f.data) == null || p.forEach((l) => {
150
+ for (const O in l)
151
+ !isNaN(l[O]) && Number(l[O]) !== 1 / 0 && (l[O] = Number(l[O]));
152
+ const k = v(`${l.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), w = l.status, { labelCn: y, labelEn: g } = this.parseStatus(w), H = {
153
+ mmsi: l.mmsi,
153
154
  imo: n == null ? void 0 : n.imo,
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
- eta: w == null ? void 0 : w.unix(),
162
- destination: h.dest,
155
+ lat: l.lat,
156
+ lng: l.lon,
157
+ sog: l.sog,
158
+ cog: l.cog,
159
+ hdg: l.hdg,
160
+ draught: l.draught,
161
+ status: w,
162
+ eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(l.eta) ? v(`${l.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00").utc().format() : void 0,
163
+ destination: l.dest,
163
164
  positionTime: k.unix(),
164
- labelCn: g,
165
- labelEn: N,
165
+ labelCn: y,
166
+ labelEn: g,
166
167
  method: "trajectory",
167
168
  vendor: "myVessel",
168
169
  utc: k.utc().format()
169
- }, W = Math.floor(k.diff(f, "minute", !0) / (a || 1));
170
- W !== M && (M = W, e.push(F));
170
+ }, F = Math.floor(k.diff(m, "minute", !0) / (a || 1));
171
+ F !== M && (M = F, e.push(H));
171
172
  }), e;
172
173
  }
173
174
  }
174
- class Mt extends K {
175
+ class vt extends K {
175
176
  constructor(t) {
176
177
  super();
177
178
  Z(this, "token");
@@ -183,15 +184,15 @@ class Mt extends K {
183
184
  mmsi: t,
184
185
  usertoken: this.token
185
186
  }
186
- }, a = await R.post(o, n).json();
187
- u == null || u.info("[%s] fetch realtime position from: %s - %j", i.requestId, o, n);
187
+ }, a = await A.post(o, n).json();
188
+ h == null || h.info("[%s] fetch realtime position from: %s - %j", i.requestId, o, n);
188
189
  const e = a == null ? void 0 : a.list;
189
190
  if (!e)
190
- return u == null || u.warn("[%s] fetch realtime position failed: %j", i.requestId, o, a), a;
191
- for (const f in e)
192
- !isNaN(e[f]) && Number(e[f]) !== 1 / 0 && (e[f] = Number(e[f]));
191
+ return h == null || h.warn("[%s] fetch realtime position failed: %j", i.requestId, o, a), a;
192
+ for (const m in e)
193
+ !isNaN(e[m]) && Number(e[m]) !== 1 / 0 && (e[m] = Number(e[m]));
193
194
  e.status = e.sp > 3 ? 0 : 1;
194
- const c = e.status, { labelCn: r, labelEn: d } = this.parseStatus(c), l = v(`${e.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
195
+ const c = e.status, { labelCn: r, labelEn: d } = this.parseStatus(c), f = v(`${e.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
195
196
  return {
196
197
  mmsi: e.m,
197
198
  name: e.n,
@@ -206,10 +207,10 @@ class Mt extends K {
206
207
  cog: e.co,
207
208
  hdg: e.h,
208
209
  rot: isNaN(e.rot) ? 0 : e.rot,
209
- 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,
210
+ eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta) ? v.utc(e.eta).format() : void 0,
210
211
  destination: e.destination,
211
- positionTime: l.unix(),
212
- utc: l.utc().format(),
212
+ positionTime: f.unix(),
213
+ utc: f.utc().format(),
213
214
  status: c,
214
215
  labelCn: r,
215
216
  labelEn: d,
@@ -229,8 +230,8 @@ class Mt extends K {
229
230
  Host: "www.hifleet.com"
230
231
  }
231
232
  };
232
- let a = await R.post(o, n).json();
233
- u == null || u.info("[%s] fetch vessel props from: %s - %j", i.requestId, o, n), a instanceof Array && (a = a[0]);
233
+ let a = await A.post(o, n).json();
234
+ h == null || h.info("[%s] fetch vessel props from: %s - %j", i.requestId, o, n), a instanceof Array && (a = a[0]);
234
235
  for (const c in a)
235
236
  !isNaN(a[c]) && Number(a[c]) !== 1 / 0 && (a[c] = Number(a[c]));
236
237
  const e = {
@@ -242,16 +243,16 @@ class Mt extends K {
242
243
  breadth: a.b,
243
244
  draught: a.dr
244
245
  };
245
- return o = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", a = await R.post(o, n).json(), u == null || u.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
+ return o = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", a = await A.post(o, n).json(), h == null || h.info("[%s] fetch vessel dead weight from: %s - %j", i.requestId, o, n), a instanceof Array && (a = a[0]), a && (e.deadweight = Number(a.dwt)), e;
246
247
  }
247
248
  async trajectory(t, i, o, n, a = !0, e = {}) {
248
- var h, k, w;
249
+ var l, k, w;
249
250
  const c = await this.realTimePosition(t, e);
250
251
  let r = v(i);
251
- const d = v(o), l = v();
252
+ const d = v(o), f = v();
252
253
  if (a) {
253
254
  let y = d.diff(r, "d", !0);
254
- 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");
255
+ 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 = f.diff(d, "d", !0), d.add(y > 10 ? 240 : y * 24, "h");
255
256
  }
256
257
  const M = {
257
258
  searchParams: {
@@ -260,10 +261,10 @@ class Mt extends K {
260
261
  mmsi: t,
261
262
  usertoken: this.token
262
263
  }
263
- }, f = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", m = await R.get(f, M).json();
264
- u == null || u.info("[%s] fetch trajectory from: %s - %j", e.requestId, f, M);
264
+ }, m = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", u = await A.get(m, M).json();
265
+ h == null || h.info("[%s] fetch trajectory from: %s - %j", e.requestId, m, M);
265
266
  let Y;
266
- m && (Y = ((k = (h = m.ships) == null ? void 0 : h.offors) == null ? void 0 : k.ship) || [], Y.length || u == null || u.warn("[%s] fetch trajectory failed: %j", e.requestId, m));
267
+ u && (Y = ((k = (l = u.ships) == null ? void 0 : l.offors) == null ? void 0 : k.ship) || [], Y.length || h == null || h.warn("[%s] fetch trajectory failed: %j", e.requestId, u));
267
268
  const j = [];
268
269
  let b = -1;
269
270
  const p = v(`${(w = Y == null ? void 0 : Y[0]) == null ? void 0 : w.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
@@ -272,7 +273,7 @@ class Mt extends K {
272
273
  !isNaN(y[L]) && Number(y[L]) !== 1 / 0 && (y[L] = Number(y[L]));
273
274
  const g = v(`${y.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
274
275
  y.status = y.sp > 4 ? 0 : 1;
275
- const { labelEn: N, labelCn: F } = this.parseStatus(y.status), W = {
276
+ const { labelEn: H, labelCn: F } = this.parseStatus(y.status), O = {
276
277
  mmsi: y.m,
277
278
  name: y.n,
278
279
  imo: c == null ? void 0 : c.imo,
@@ -286,16 +287,16 @@ class Mt extends K {
286
287
  utc: g.utc().format(),
287
288
  status: y.status,
288
289
  labelCn: F,
289
- labelEn: N,
290
+ labelEn: H,
290
291
  method: "trajectory",
291
292
  vendor: "hifleet"
292
- }, T = Math.floor(g.diff(p, "minute", !0) / (n || 1));
293
- T !== b && (b = T, j.push(W));
293
+ }, N = Math.floor(g.diff(p, "minute", !0) / (n || 1));
294
+ N !== b && (b = N, j.push(O));
294
295
  }
295
296
  return j;
296
297
  }
297
298
  }
298
- class yt extends K {
299
+ class Yt extends K {
299
300
  constructor(t) {
300
301
  super();
301
302
  Z(this, "token");
@@ -308,8 +309,8 @@ class yt extends K {
308
309
  k: this.token,
309
310
  enc: 1
310
311
  }
311
- }, n = "https://api.shipxy.com/apicall/GetSingleShip", a = await R.get(n, o).json();
312
- if (u == null || u.info("[%s] fetch realtime position from: %s - %j", i.requestId, n, o), (a == null ? void 0 : a.status) !== 0)
312
+ }, n = "https://api.shipxy.com/apicall/GetSingleShip", a = await A.get(n, o).json();
313
+ if (h == null || h.info("[%s] fetch realtime position from: %s - %j", i.requestId, n, o), (a == null ? void 0 : a.status) !== 0)
313
314
  return a;
314
315
  const e = a.data[0];
315
316
  for (const M in e)
@@ -340,7 +341,7 @@ class yt extends K {
340
341
  }
341
342
  async trajectory(t, i, o, n, a = !0, e = {}) {
342
343
  var p;
343
- const c = await this.realTimePosition(t, e), r = v(i), d = v(o), l = "https://api.shipxy.com/apicall/GetShipTrack", M = {
344
+ const c = await this.realTimePosition(t, e), r = v(i), d = v(o), f = "https://api.shipxy.com/apicall/GetShipTrack", M = {
344
345
  searchParams: {
345
346
  id: t,
346
347
  k: this.token,
@@ -349,19 +350,19 @@ class yt extends K {
349
350
  btm: r.unix(),
350
351
  etm: d.unix()
351
352
  }
352
- }, f = await R.get(l, M).json();
353
- if (u == null || u.info("[%s] fetch trajectory from: %s - %j", e.requestId, l, M), (f == null ? void 0 : f.status) !== 0)
354
- return f;
355
- const m = f == null ? void 0 : f.points, Y = [], j = v.unix((p = m[0]) == null ? void 0 : p.utc);
353
+ }, m = await A.get(f, M).json();
354
+ if (h == null || h.info("[%s] fetch trajectory from: %s - %j", e.requestId, f, M), (m == null ? void 0 : m.status) !== 0)
355
+ return m;
356
+ const u = m == null ? void 0 : m.points, Y = [], j = v.unix((p = u[0]) == null ? void 0 : p.utc);
356
357
  let b = -1;
357
- for (const h of m) {
358
- const k = v.unix(h.utc), w = {
358
+ for (const l of u) {
359
+ const k = v.unix(l.utc), w = {
359
360
  imo: c == null ? void 0 : c.imo,
360
361
  mmsi: t,
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,
362
+ sog: Math.round(l.sog * 3600 / 1e3 / 1852 * 100) / 100,
363
+ cog: Math.round(l.cog / 100 * 100) / 100,
364
+ lat: Math.round(l.lat / 1e6 * 1e5) / 1e5,
365
+ lng: Math.round(l.lon / 1e6 * 1e5) / 1e5,
365
366
  positionTime: k.unix(),
366
367
  utc: k.utc().format(),
367
368
  method: "trajectory",
@@ -372,7 +373,7 @@ class yt extends K {
372
373
  return Y;
373
374
  }
374
375
  }
375
- class gt extends K {
376
+ class kt extends K {
376
377
  constructor(t) {
377
378
  super();
378
379
  Z(this, "token");
@@ -386,8 +387,8 @@ class gt extends K {
386
387
  json: {
387
388
  mmsiList: t
388
389
  }
389
- }, n = "https://api3.myships.com/sp/ships/getShipIdByMMSI", a = await R.post(n, o).json();
390
- return u == null || u.info("[%s] fetch ship id from: %s - %j", i.requestId, n, o), a.code !== "0" ? a : a.data[0].shipId;
390
+ }, n = "https://api3.myships.com/sp/ships/getShipIdByMMSI", a = await A.post(n, o).json();
391
+ return h == null || h.info("[%s] fetch ship id from: %s - %j", i.requestId, n, o), a.code !== "0" ? a : a.data[0].shipId;
391
392
  }
392
393
  async getShipInfo(t, i = {}) {
393
394
  const o = {
@@ -397,12 +398,12 @@ class gt extends K {
397
398
  json: {
398
399
  shipId: t
399
400
  }
400
- }, n = "https://api3.myships.com/sp/ships/aissta", a = await R.post(n, o).json();
401
- if (u == null || u.info("[%s] fetch ship info from: %s - %j", i.requestId, n, o), a.code !== "0")
401
+ }, n = "https://api3.myships.com/sp/ships/aissta", a = await A.post(n, o).json();
402
+ if (h == null || h.info("[%s] fetch ship info from: %s - %j", i.requestId, n, o), a.code !== "0")
402
403
  return a;
403
404
  const e = a.data;
404
405
  let c = e.imo;
405
- return t === "407170" && (c = "9198379", u == null || u.warn("[%s] ship(%s) imo error: %s, should be %s", i.requestId, t, e.imo, c)), {
406
+ return t === "407170" && (c = "9198379", h == null || h.warn("[%s] ship(%s) imo error: %s, should be %s", i.requestId, t, e.imo, c)), {
406
407
  mmsi: e.mmsi,
407
408
  name: e.shipnameEn,
408
409
  imo: c,
@@ -420,12 +421,12 @@ class gt extends K {
420
421
  json: {
421
422
  shipId: o
422
423
  }
423
- }, e = "https://api3.myships.com/sp/ships/position/latest", c = await R.post(e, a).json();
424
- u == null || u.info("[%s] fetch realtime position from: %s - %j", i.requestId, e, a);
424
+ }, e = "https://api3.myships.com/sp/ships/position/latest", c = await A.post(e, a).json();
425
+ h == null || h.info("[%s] fetch realtime position from: %s - %j", i.requestId, e, a);
425
426
  const r = c.data[0];
426
- for (const m in r)
427
- !isNaN(r[m]) && Number(r[m]) !== 1 / 0 && (r[m] = Number(r[m]));
428
- const { labelCn: d, labelEn: l } = await this.parseStatus(r.aisNavStatus), M = v.unix(r.posTime);
427
+ for (const u in r)
428
+ !isNaN(r[u]) && Number(r[u]) !== 1 / 0 && (r[u] = Number(r[u]));
429
+ const { labelCn: d, labelEn: f } = await this.parseStatus(r.aisNavStatus), M = v.unix(r.posTime);
429
430
  return {
430
431
  ...n,
431
432
  mmsi: t,
@@ -438,17 +439,17 @@ class gt extends K {
438
439
  positionTime: r.posTime,
439
440
  utc: M.utc().format(),
440
441
  status: r.aisNavStatus,
441
- labelEn: l,
442
+ labelEn: f,
442
443
  labelCn: d,
443
444
  method: "position",
444
445
  vendor: "myship"
445
446
  };
446
447
  }
447
448
  async trajectory(t, i, o, n, a = !0, e = {}) {
448
- const c = v(i), r = v(o), d = await this.getShipId(t), l = await this.getShipInfo(d), M = [];
449
+ const c = v(i), r = v(o), d = await this.getShipId(t), f = await this.getShipInfo(d), M = [];
449
450
  for (; r.diff(c, "day", !0) > 30; )
450
- await this.trajectoryIn30Day(d, c.unix(), c.add(30, "day").unix(), l, t, n, M);
451
- return await this.trajectoryIn30Day(d, c.unix(), r.unix(), l, t, n, M), M;
451
+ await this.trajectoryIn30Day(d, c.unix(), c.add(30, "day").unix(), f, t, n, M);
452
+ return await this.trajectoryIn30Day(d, c.unix(), r.unix(), f, t, n, M), M;
452
453
  }
453
454
  async trajectoryIn30Day(t, i, o, n, a, e, c, r = {}) {
454
455
  var j;
@@ -461,16 +462,16 @@ class gt extends K {
461
462
  startTime: i,
462
463
  endTime: o
463
464
  }
464
- }, l = "https://api3.myships.com/sp/ships/position/history", M = await R.post(l, d).json();
465
- if (u == null || u.info("[%s] fetch trajectory from: %s - %j", r.requestId, l, d), M.code !== "0")
466
- return u == null || u.warn("[%s] invoke myship trajectory failed: %j", r.requestId, M), M;
467
- const f = M.data;
468
- for (const b in f)
469
- !isNaN(f[b]) && Number(f[b]) !== 1 / 0 && (f[b] = Number(f[b]));
470
- const m = v.unix((j = f[0]) == null ? void 0 : j.posTime);
465
+ }, f = "https://api3.myships.com/sp/ships/position/history", M = await A.post(f, d).json();
466
+ if (h == null || h.info("[%s] fetch trajectory from: %s - %j", r.requestId, f, d), M.code !== "0")
467
+ return h == null || h.warn("[%s] invoke myship trajectory failed: %j", r.requestId, M), M;
468
+ const m = M.data;
469
+ for (const b in m)
470
+ !isNaN(m[b]) && Number(m[b]) !== 1 / 0 && (m[b] = Number(m[b]));
471
+ const u = v.unix((j = m[0]) == null ? void 0 : j.posTime);
471
472
  let Y = -1;
472
- for (const b of f) {
473
- const p = v.unix(b.posTime), h = {
473
+ for (const b of m) {
474
+ const p = v.unix(b.posTime), l = {
474
475
  imo: n == null ? void 0 : n.imo,
475
476
  mmsi: a,
476
477
  lat: Math.round(b.lat / 1e4 / 60 * 1e5) / 1e5,
@@ -483,20 +484,20 @@ class gt extends K {
483
484
  utc: p.utc().format(),
484
485
  method: "trajectory",
485
486
  vendor: "myship"
486
- }, k = Math.floor(p.diff(m, "minute", !0) / (e || 1));
487
- k !== Y && (Y = k, c.push(h));
487
+ }, k = Math.floor(p.diff(u, "minute", !0) / (e || 1));
488
+ k !== Y && (Y = k, c.push(l));
488
489
  }
489
490
  return c;
490
491
  }
491
492
  }
492
- let O;
493
+ let R;
493
494
  try {
494
- O = z.getLogger("vessel");
495
+ R = z.getLogger("vessel");
495
496
  } catch {
496
497
  } finally {
497
498
  }
498
- var ot = /* @__PURE__ */ ((I) => (I.NOTICE = "NOTICE", I.WARN = "WARN", I.HEAVY = "HEAVY", I.SEVERE = "SEVERE", I.ERROR = "ERROR", I.FATAL = "FATAL", I))(ot || {});
499
- class nt {
499
+ var it = /* @__PURE__ */ ((I) => (I.NOTICE = "NOTICE", I.WARN = "WARN", I.HEAVY = "HEAVY", I.SEVERE = "SEVERE", I.ERROR = "ERROR", I.FATAL = "FATAL", I))(it || {});
500
+ class rt {
500
501
  /**
501
502
  * 解析告警规则, 多规则场景
502
503
  * @param rule
@@ -507,19 +508,19 @@ class nt {
507
508
  */
508
509
  parsePrinciple(s, t = {}) {
509
510
  var e, c, r;
510
- O == null || O.info("[%s] parse rule: %s", t.requestId, s);
511
+ R == null || R.info("[%s] parse rule: %s", t.requestId, s);
511
512
  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
513
  if (!n)
513
514
  return;
514
515
  const a = {};
515
516
  for (let d = 0; d < (n == null ? void 0 : n.length); d++) {
516
- const l = (r = (c = n[d].match(i)) == null ? void 0 : c[0]) == null ? void 0 : r.split("],");
517
- if (d === 0 && !l)
517
+ const f = (r = (c = n[d].match(i)) == null ? void 0 : c[0]) == null ? void 0 : r.split("],");
518
+ if (d === 0 && !f)
518
519
  a.scope = n[0];
519
- else if (l)
520
- for (let M = 0, f = l.length; M < f; M++) {
521
- const m = this.parseRule(l[M]);
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);
520
+ else if (f)
521
+ for (let M = 0, m = f.length; M < m; M++) {
522
+ const u = this.parseRule(f[M]);
523
+ u && (a[u.level] ? u.key ? a[u.level][u == null ? void 0 : u.key] = u : a[u.level] = u : u.key ? a[u.level] = { [u == null ? void 0 : u.key]: u } : a[u.level] = u);
523
524
  }
524
525
  }
525
526
  return a;
@@ -532,7 +533,7 @@ class nt {
532
533
  */
533
534
  parseRule(s, t = {}) {
534
535
  var a;
535
- O == null || O.info("[%s] parse rule: %s", t.requestId, s), s = s.startsWith("[") ? s : `[${s}`, s = s.endsWith("]") ? s : `${s}]`;
536
+ R == null || R.info("[%s] parse rule: %s", t.requestId, s), s = s.startsWith("[") ? s : `[${s}`, s = s.endsWith("]") ? s : `${s}]`;
536
537
  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
538
  if (n)
538
539
  return {
@@ -550,24 +551,25 @@ class nt {
550
551
  * @param options
551
552
  */
552
553
  checkWeather(s, t, i = {}) {
553
- var m, Y, j, b, p, h, k, w, y, g, N, F, W, T, L;
554
+ var u, Y, j, b, p, l, k, w, y, g, H, F, O, N, L;
554
555
  let o = 0, n = 0, a = 0, e = 0;
555
- const c = Math.round(((Y = (m = t == null ? void 0 : t.SEVERE) == null ? void 0 : m.sigWave) == null ? void 0 : Y.number) * 1.6 * 100) / 100, r = (b = (j = t == null ? void 0 : t.SEVERE) == null ? void 0 : j.sigWave) == null ? void 0 : b.number, d = (h = (p = t == null ? void 0 : t.HEAVY) == null ? void 0 : p.sigWave) == null ? void 0 : h.number, l = Math.round((((w = (k = t == null ? void 0 : t.SEVERE) == null ? void 0 : k.wind) == null ? void 0 : w.number) + 2) * 100) / 100, M = (g = (y = t == null ? void 0 : t.SEVERE) == null ? void 0 : y.wind) == null ? void 0 : g.number, f = (F = (N = t == null ? void 0 : t.HEAVY) == null ? void 0 : N.wind) == null ? void 0 : F.number;
556
- for (let A = 0; A < (s == null ? void 0 : s.length); A++) {
557
- const S = s[A], P = (T = (W = S == null ? void 0 : S.meteo) == null ? void 0 : W.wave) == null ? void 0 : T.sig, x = (L = S == null ? void 0 : S.meteo) == null ? void 0 : L.wind, E = A ? v(S.eta).diff(v(s[A - 1].eta), "hour", !0) : 0;
558
- e = E > e ? E : e, O == null || O.info("[%s] check sig.wave: %j", i.requestId, { ...P, dgThd4Wv: c, svThd4Wv: r, hvThd4Wv: d }), (P == null ? void 0 : P.height) >= c ? S.isDangerous = !0 : (P == null ? void 0 : P.height) >= r ? S.isSevere = !0 : (P == null ? void 0 : P.height) >= d && (S.isHeavy = !0), O == null || O.info("[%s] check wind: %j", i.requestId, { ...x, dgThd4Wd: l, svThd4Wd: M, hvThd4Wd: f }), (x == null ? void 0 : x.scale) >= l ? (S.isDangerous = !0, delete S.isSevere, delete S.isHeavy) : (x == null ? void 0 : x.scale) > M ? (S.isDangerous || (S.isSevere = !0), delete S.isHeavy) : (x == null ? void 0 : x.scale) === f && !S.isDangerous && !S.isSevere && (S.isHeavy = !0), o += S.isDangerous ? E : 0, n += S.isSevere ? E : 0, a += S.isHeavy ? E : 0;
556
+ const c = Math.round(((Y = (u = t == null ? void 0 : t.SEVERE) == null ? void 0 : u.sigWave) == null ? void 0 : Y.number) * 1.6 * 100) / 100, r = (b = (j = t == null ? void 0 : t.SEVERE) == null ? void 0 : j.sigWave) == null ? void 0 : b.number, d = (l = (p = t == null ? void 0 : t.HEAVY) == null ? void 0 : p.sigWave) == null ? void 0 : l.number, f = Math.round((((w = (k = t == null ? void 0 : t.SEVERE) == null ? void 0 : k.wind) == null ? void 0 : w.number) + 2) * 100) / 100, M = (g = (y = t == null ? void 0 : t.SEVERE) == null ? void 0 : y.wind) == null ? void 0 : g.number, m = (F = (H = t == null ? void 0 : t.HEAVY) == null ? void 0 : H.wind) == null ? void 0 : F.number;
557
+ for (let W = 0; W < (s == null ? void 0 : s.length); W++) {
558
+ const T = s[W], P = (N = (O = T == null ? void 0 : T.meteo) == null ? void 0 : O.wave) == null ? void 0 : N.sig, D = (L = T == null ? void 0 : T.meteo) == null ? void 0 : L.wind, E = W ? v(T.eta).diff(v(s[W - 1].eta), "hour", !0) : 0;
559
+ e = E > e ? E : e, R == null || R.info("[%s] check sig.wave: %j", i.requestId, { ...P, dgThd4Wv: c, svThd4Wv: r, hvThd4Wv: d }), (P == null ? void 0 : P.height) >= c ? T.isDangerous = !0 : (P == null ? void 0 : P.height) >= r ? T.isSevere = !0 : (P == null ? void 0 : P.height) >= d && (T.isHeavy = !0), R == null || R.info("[%s] check wind: %j", i.requestId, { ...D, dgThd4Wd: f, svThd4Wd: M, hvThd4Wd: m }), (D == null ? void 0 : D.scale) >= f ? (T.isDangerous = !0, delete T.isSevere, delete T.isHeavy) : (D == null ? void 0 : D.scale) > M ? (T.isDangerous || (T.isSevere = !0), delete T.isHeavy) : (D == null ? void 0 : D.scale) === m && !T.isDangerous && !T.isSevere && (T.isHeavy = !0), o += T.isDangerous ? E : 0, n += T.isSevere ? E : 0, a += T.isHeavy ? E : 0;
559
560
  }
560
- return o = Math.round(o * 100) / 100, n = Math.round(n * 100) / 100, a = Math.round(a * 100) / 100, e = Math.round(e), { sample: s, dangerous: o, severe: n, heavy: a, step: e < 3 ? 3 : e, wind: { dgThd4Wd: l, svThd4Wd: M, hvThd4Wd: f }, sig: { dgThd4Wv: c, svThd4Wv: r, hvThd4Wv: d } };
561
+ 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: f, svThd4Wd: M, hvThd4Wd: m }, sig: { dgThd4Wv: c, svThd4Wv: r, hvThd4Wv: d } };
561
562
  }
562
563
  }
563
- const bt = new nt();
564
- let D;
564
+ const It = new rt();
565
+ let S;
565
566
  try {
566
- D = z.getLogger("vessel");
567
+ S = z.getLogger("vessel");
567
568
  } catch {
568
569
  } finally {
569
570
  }
570
- var it = /* @__PURE__ */ ((I) => (I.common = "common", I.container = "container", I.tugs = "tugs", I))(it || {}), rt = /* @__PURE__ */ ((I) => (I.Ballast = "Ballast", I.Laden = "Laden", I))(rt || {}), ct = /* @__PURE__ */ ((I) => (I.Cp = "CP", I.Perf = "Basis", I.Instruct = "Other", I))(ct || {});
571
+ const ct = new ot("", !0);
572
+ var dt = /* @__PURE__ */ ((I) => (I.common = "common", I.container = "container", I.tugs = "tugs", I))(dt || {}), ut = /* @__PURE__ */ ((I) => (I.Ballast = "Ballast", I.Laden = "Laden", I))(ut || {}), ht = /* @__PURE__ */ ((I) => (I.Cp = "CP", I.Perf = "Basis", I.Instruct = "Other", I))(ht || {});
571
573
  class C {
572
574
  /**
573
575
  * @see https://baike.baidu.com/item/%E6%96%B9%E5%BD%A2%E7%B3%BB%E6%95%B0/4965568?fr=aladdin
@@ -709,12 +711,18 @@ class C {
709
711
  static async speedLoseAt(s, t, i, o = "", n = 2, a = !0, e = !1, c = {}) {
710
712
  let r;
711
713
  if (t.velocity && e && (s.speed = B.roundPrecision(t.velocity * 1852 / 3600, 6)), a) {
712
- const d = await at.queryPointFactor(t.lng, t.lat, i.valueOf(), "wind,wave,current,watertemp", o, c), l = C.weatherFactor(s, d), M = C.currentFactor(s.bearing, d == null ? void 0 : d.current, n), f = Math.round((s.speed * 1.943844 + l + M) * 100) / 100;
714
+ let d;
715
+ if (c.meteo2) {
716
+ const u = await ct.spotForecast(t.lat, t.lng, i.utc().format(), !1, !1, !0, c), [Y] = tt.pickHourly(u, i);
717
+ d = tt.toLegacy(Y);
718
+ } else
719
+ d = await nt.queryPointFactor(t.lng, t.lat, i.valueOf(), "wind,wave,current,watertemp", o, c);
720
+ const f = C.weatherFactor(s, d), M = C.currentFactor(s.bearing, d == null ? void 0 : d.current, n), m = Math.round((s.speed * 1.943844 + f + M) * 100) / 100;
713
721
  r = {
714
722
  meteo: { ...d },
715
- wxFactor: l,
723
+ wxFactor: f,
716
724
  cFactor: M,
717
- speed: t.velocity && e ? t.velocity : f < 0 ? 1 : f,
725
+ speed: t.velocity && e ? t.velocity : m < 0 ? 1 : m,
718
726
  eta: i.utc().format("YYYY-MM-DDTHH:mm[Z]"),
719
727
  etd: i.utc().format("YYYY-MM-DDTHH:mm[Z]")
720
728
  };
@@ -743,51 +751,51 @@ class C {
743
751
  */
744
752
  static async speedLoseInHoursStep(s, t, i, o, n, a, e = "", c = !0, r = !1, d = {}) {
745
753
  t.utc();
746
- const l = [], M = [];
747
- let f = 0, m = 0, Y, j;
754
+ const f = [], M = [];
755
+ let m = 0, u = 0, Y, j;
748
756
  for (let b = 0; b < a.length - 1; b++) {
749
757
  let p = a[b];
750
- p.distanceFromStart = n + m;
751
- const h = a[b + 1];
752
- if (s.bearing = V.calculateBearing(p, h, !h.gcToPrevious), p.bearing = s.bearing, p.suspend && r) {
758
+ p.distanceFromStart = n + u;
759
+ const l = a[b + 1];
760
+ if (s.bearing = V.calculateBearing(p, l, !l.gcToPrevious), p.bearing = s.bearing, p.suspend && r) {
753
761
  p.eta = p.eta || t.format("YYYY-MM-DDTHH:mm[Z]"), p.elapsed = p.elapsed ?? 0;
754
762
  const y = p.suspend - p.elapsed;
755
- if (o - f > y)
756
- o = o - f - y, t.add(y, "hour"), p.elapsed = p.suspend;
763
+ if (o - m > y)
764
+ o = o - m - y, t.add(y, "hour"), p.elapsed = p.suspend;
757
765
  else {
758
- const g = o - f;
766
+ const g = o - m;
759
767
  p.elapsed += g, t.add(g, "hour"), o = 0;
760
768
  }
761
- if (D == null || D.info(`[%s] suspend ${p.elapsed} hours at %j, and remain ${o} hours need to go...`, d.requestId, p), o === 0)
762
- return p.distanceFromPrevious = m, { etd: t, from: j || p, to: p, next: a.filter((g) => g), wps: l, days: M };
769
+ if (S == null || S.info(`[%s] suspend ${p.elapsed} hours at %j, and remain ${o} hours need to go...`, d.requestId, p), o === 0)
770
+ return p.distanceFromPrevious = u, { etd: t, from: j || p, to: p, next: a.filter((g) => g), wps: f, days: M };
763
771
  } else
764
772
  p.suspend = 0;
765
- p = await C.speedLoseAt(s, p, t, e, 0, c, r, d), j = j || p, p.important && l.push(p), t.isSameOrAfter(i) && (M.push(p), i.add(24, "hour"));
766
- const k = V.calculateDistance(p, h, !h.gcToPrevious);
773
+ p = await C.speedLoseAt(s, p, t, e, 0, c, r, d), j = j || p, p.important && f.push(p), t.isSameOrAfter(i) && (M.push(p), i.add(24, "hour"));
774
+ const k = V.calculateDistance(p, l, !l.gcToPrevious);
767
775
  let w = Math.ceil(k / j.speed * 1e4) / 1e4;
768
- if (f + w < o) {
769
- if (f += w, t.add(w, "hour"), delete a[b], D == null || D.info(
776
+ if (m + w < o) {
777
+ if (m += w, t.add(w, "hour"), delete a[b], S == null || S.info(
770
778
  `[%s] go to %j from %j with ${k}nm, and cost ${w} hours`,
771
779
  d.requestId,
772
- { lat: h.lat, lng: h.lng },
780
+ { lat: l.lat, lng: l.lng },
773
781
  { lat: j.lat, lng: j.lng, etd: j.etd }
774
- ), m += k, a.filter((y) => y).length <= 1) {
775
- Y = h, Y.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), Y.distanceFromPrevious = k, Y.distanceFromStart = n + m, l.push(Y), delete a[b + 1];
782
+ ), u += k, a.filter((y) => y).length <= 1) {
783
+ Y = l, Y.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), Y.distanceFromPrevious = k, Y.distanceFromStart = n + u, f.push(Y), delete a[b + 1];
776
784
  break;
777
785
  }
778
786
  } else {
779
- w = o - f, t.add(w, "hour");
787
+ w = o - m, t.add(w, "hour");
780
788
  const y = B.roundPrecision(j.speed * w, 4);
781
- Y = V.calculateCoordinate(p, s.bearing, y, "nauticalmiles", !h.gcToPrevious), Y.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), a[b] = Y, D == null || D.info(
789
+ Y = V.calculateCoordinate(p, s.bearing, y, "nauticalmiles", !l.gcToPrevious), Y.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), a[b] = Y, S == null || S.info(
782
790
  `[%s] go to %j from %j with ${y}nm, and cost ${w} hours`,
783
791
  d.requestId,
784
792
  { lat: Y.lat, lng: Y.lng },
785
793
  { lat: p.lat, lng: p.lng, etd: p.etd }
786
- ), m += y, Y.distanceFromPrevious = m, Y.distanceFromStart = n + m;
794
+ ), u += y, Y.distanceFromPrevious = u, Y.distanceFromStart = n + u;
787
795
  break;
788
796
  }
789
797
  }
790
- return { etd: t, from: j, to: Y, next: a.filter((b) => b), wps: l, days: M };
798
+ return { etd: t, from: j, to: Y, next: a.filter((b) => b), wps: f, days: M };
791
799
  }
792
800
  /**
793
801
  * 洋流影响因子
@@ -808,16 +816,16 @@ class C {
808
816
  * @param wwc 气象要素
809
817
  */
810
818
  static weatherFactor(s, t) {
811
- var l, M, f, m, Y, j, b;
812
- D == null || D.debug("calculate weather factor via: %j", { ...s, ...t });
819
+ var f, M, m, u, Y, j, b;
820
+ S == null || S.debug("calculate weather factor via: %j", { ...s, ...t });
813
821
  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);
814
- let a = Math.abs(s.bearing % 360 - (((l = t == null ? void 0 : t.wind) == null ? void 0 : l.degree) % 360 || 0));
822
+ let a = Math.abs(s.bearing % 360 - (((f = t == null ? void 0 : t.wind) == null ? void 0 : f.degree) % 360 || 0));
815
823
  a = a > 180 ? 360 - a : a;
816
- const e = C.directionFactor(a, (M = t == null ? void 0 : t.wind) == null ? void 0 : M.scale), c = C.vesselTagFactor(s.displacement, s.loadCondition, s.tag, (f = t == null ? void 0 : t.wind) == null ? void 0 : f.scale);
824
+ const e = C.directionFactor(a, (M = t == null ? void 0 : t.wind) == null ? void 0 : M.scale), c = C.vesselTagFactor(s.displacement, s.loadCondition, s.tag, (m = t == null ? void 0 : t.wind) == null ? void 0 : m.scale);
817
825
  let r = e * n * c / 100 * s.speed;
818
- r = Math.round(r * 1.943844 * 1e4) / 1e4 * -1, s.tag === "tugs" && Math.abs(r) > 1 && (r = r / (Math.abs(Math.round(r)) + 1)), D == null || D.debug("wind wx factor = %d", r), a = Math.abs(s.bearing % 360 - (((Y = (m = t == null ? void 0 : t.wave) == null ? void 0 : m.sig) == null ? void 0 : Y.degree) % 360 || 0));
826
+ r = Math.round(r * 1.943844 * 1e4) / 1e4 * -1, s.tag === "tugs" && Math.abs(r) > 1 && (r = r / (Math.abs(Math.round(r)) + 1)), S == null || S.debug("wind wx factor = %d", r), a = Math.abs(s.bearing % 360 - (((Y = (u = t == null ? void 0 : t.wave) == null ? void 0 : u.sig) == null ? void 0 : Y.degree) % 360 || 0));
819
827
  const d = C.waveHeightFactor(((b = (j = t == null ? void 0 : t.wave) == null ? void 0 : j.sig) == null ? void 0 : b.height) ?? 1, a);
820
- return D == null || D.debug("wave wx factor = %d", d), r = r * 0.4 + d, D == null || D.debug("weather factor = %d", r), r = Math.abs(r) > 4 ? 4 * (Math.abs(r) / r) + Math.abs(r) / r * (Math.abs(r) - 4) * 0.1 : r, Math.round(r * 100) / 100;
828
+ return S == null || S.debug("wave wx factor = %d", d), r = r * 0.4 + d, S == null || S.debug("weather factor = %d", r), r = Math.abs(r) > 4 ? 4 * (Math.abs(r) / r) + Math.abs(r) / r * (Math.abs(r) - 4) * 0.1 : r, Math.round(r * 100) / 100;
821
829
  }
822
830
  /**
823
831
  * 全程失速分析(走完航程)
@@ -833,10 +841,10 @@ class C {
833
841
  */
834
842
  static async analyseInstant(s, t, i, o, n, a = "", e = 0, c = !0, r = !1, d = {}) {
835
843
  var E, G, U, J, Q;
836
- const l = v().valueOf();
844
+ const f = v().valueOf();
837
845
  s.lng = B.convertToStdLng(s.lng);
838
- const { route: M, waypoints: f } = n.points, m = V.calculateSubRoute(s, M);
839
- if (((E = m[0]) == null ? void 0 : E.length) <= 1)
846
+ const { route: M, waypoints: m } = n.points, u = V.calculateSubRoute(s, M);
847
+ if (((E = u[0]) == null ? void 0 : E.length) <= 1)
840
848
  return;
841
849
  const { v0: Y, label: j } = s.sog ? {
842
850
  v0: s.sog,
@@ -846,11 +854,11 @@ class C {
846
854
  v0: o.speed,
847
855
  label: "CP"
848
856
  /* Cp */
849
- }, b = C.assembleProperties(i, o.loadCondition, Y, 0), p = f.length ? V.calculateSubWaypoints(s, f) : [];
850
- p.forEach((H) => H.important = !0);
851
- const h = {
857
+ }, b = C.assembleProperties(i, o.loadCondition, Y, 0), p = m.length ? V.calculateSubWaypoints(s, m) : [];
858
+ p.forEach((x) => x.important = !0);
859
+ const l = {
852
860
  from: { ...s },
853
- route: m,
861
+ route: u,
854
862
  waypoints: p,
855
863
  v0: Y,
856
864
  label: j
@@ -859,15 +867,15 @@ class C {
859
867
  days: [],
860
868
  wps: []
861
869
  };
862
- e || (V.calculateRouteDistance(m) / o.speed <= 72 ? e = 3 : e = 6);
863
- let w = V.simplifyRouteToCoordinates(m, p, 0), y = 0, g = 0, N = 0, F = 0;
870
+ e || (V.calculateRouteDistance(u) / o.speed <= 72 ? e = 3 : e = 6);
871
+ let w = V.simplifyRouteToCoordinates(u, p, 0), y = 0, g = 0, H = 0, F = 0;
864
872
  t = v(t).utc();
865
- const W = t.clone();
873
+ const O = t.clone();
866
874
  for (; w.length > 0; ) {
867
- const H = e - t.hour() % e, _ = Math.ceil(t.clone().add(H, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4, q = await C.speedLoseInHoursStep(
875
+ const x = e - t.hour() % e, _ = Math.ceil(t.clone().add(x, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4, q = await C.speedLoseInHoursStep(
868
876
  b,
869
877
  t,
870
- W,
878
+ O,
871
879
  _,
872
880
  y,
873
881
  w,
@@ -878,27 +886,27 @@ class C {
878
886
  );
879
887
  (G = q.from) != null && G.speed && (k.hours.push(q.from), k.wps.push(...q.wps), k.days.push(...q.days)), w = q == null ? void 0 : q.next, w.length || k.hours.push(q == null ? void 0 : q.to), y += ((U = q == null ? void 0 : q.to) == null ? void 0 : U.distanceFromPrevious) ?? 0;
880
888
  }
881
- const T = k.hours;
882
- for (let H = 0; H < T.length - 1; H++) {
883
- const _ = v(T[H + 1].eta).diff(T[H].etd, "hour", !0) || 1;
884
- g += (T[H].wxFactor || 0) * _, N += (T[H].cFactor || 0) * _, F += _;
889
+ const N = k.hours;
890
+ for (let x = 0; x < N.length - 1; x++) {
891
+ const _ = v(N[x + 1].eta).diff(N[x].etd, "hour", !0) || 1;
892
+ g += (N[x].wxFactor || 0) * _, H += (N[x].cFactor || 0) * _, F += _;
885
893
  }
886
- (J = k.wps) == null || J.forEach((H, _) => {
894
+ (J = k.wps) == null || J.forEach((x, _) => {
887
895
  if (_) {
888
- const q = k.wps[_ - 1], tt = H.distanceFromStart - q.distanceFromStart, X = v(H.eta).diff(v(q.etd), "h", !0);
896
+ const q = k.wps[_ - 1], et = x.distanceFromStart - q.distanceFromStart, X = v(x.eta).diff(v(q.etd), "h", !0);
889
897
  if (X < 1)
890
- H.avgSpd = q.speed;
898
+ x.avgSpd = q.speed;
891
899
  else {
892
- H.avgSpd = Math.round(tt / X * 100) / 100;
893
- const $ = Math.round((q.speed + H.speed) / 2 * 100) / 100;
894
- H.avgSpd = H.avgSpd > $ ? $ : H.avgSpd;
900
+ x.avgSpd = Math.round(et / X * 100) / 100;
901
+ const $ = Math.round((q.speed + x.speed) / 2 * 100) / 100;
902
+ x.avgSpd = x.avgSpd > $ ? $ : x.avgSpd;
895
903
  }
896
904
  }
897
- }), h.sample = k;
898
- const L = k.hours.at(0), A = k.hours.at(-1);
899
- h.distance = Math.round(A.distanceFromStart * 1e4) / 1e4, h.etd = v(L.eta).utc().format(), h.eta = v(A.eta).utc().format(), h.wxFactor = Math.round(g / F * 1e4) / 1e4, h.cFactor = Math.round(N / F * 1e4) / 1e4, h.avgSpeed = Math.round(A.distanceFromStart / F * 1e4) / 1e4, h.totalHrs = Math.round(F * 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;
900
- const P = v().valueOf() - l, x = ((Q = k == null ? void 0 : k.hours) == null ? void 0 : Q.length) || 1;
901
- return D == null || D.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", d == null ? void 0 : d.requestId, P, x, Math.round(P / x * 1e3) / 1e3), h;
905
+ }), l.sample = k;
906
+ const L = k.hours.at(0), W = k.hours.at(-1);
907
+ l.distance = Math.round(W.distanceFromStart * 1e4) / 1e4, l.etd = v(L.eta).utc().format(), l.eta = v(W.eta).utc().format(), l.wxFactor = Math.round(g / F * 1e4) / 1e4, l.cFactor = Math.round(H / F * 1e4) / 1e4, l.avgSpeed = Math.round(W.distanceFromStart / F * 1e4) / 1e4, l.totalHrs = Math.round(F * 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;
908
+ const P = v().valueOf() - f, D = ((Q = k == null ? void 0 : k.hours) == null ? void 0 : Q.length) || 1;
909
+ return S == null || S.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", d == null ? void 0 : d.requestId, P, D, Math.round(P / D * 1e3) / 1e3), l;
902
910
  }
903
911
  /**
904
912
  * 分段失速分析(最多走hours 小时)
@@ -913,10 +921,10 @@ class C {
913
921
  * @param useMeteo true 启用气象分析
914
922
  * @param useRouteParam
915
923
  */
916
- static async analyseInstantWithThreshed(s, t, i, o, n, a, e, c = "", r = 3, d = !0, l = !1, M = {}) {
917
- var A, S, P;
924
+ static async analyseInstantWithThreshed(s, t, i, o, n, a, e, c = "", r = 3, d = !0, f = !1, M = {}) {
925
+ var W, T, P;
918
926
  s.lng = B.convertToStdLng(s.lng);
919
- const { v0: f, label: m } = s.sog ? {
927
+ const { v0: m, label: u } = s.sog ? {
920
928
  v0: s.sog,
921
929
  label: "Other"
922
930
  /* Instruct */
@@ -924,74 +932,74 @@ class C {
924
932
  v0: n.speed,
925
933
  label: "CP"
926
934
  /* Cp */
927
- }, Y = C.assembleProperties(o, n.loadCondition, f, 0), j = V.calculateSubRoute(s, a);
928
- if (((A = j[0]) == null ? void 0 : A.length) <= 1)
935
+ }, Y = C.assembleProperties(o, n.loadCondition, m, 0), j = V.calculateSubRoute(s, a);
936
+ if (((W = j[0]) == null ? void 0 : W.length) <= 1)
929
937
  return;
930
938
  const b = e.length ? V.calculateSubWaypoints(s, e) : [];
931
- b.forEach((x) => x.important = !0);
932
- let p = V.simplifyRouteToCoordinates(j, b, 0), h = 0, k = 0, w = 0, y = 0, g;
933
- const N = {
939
+ b.forEach((D) => D.important = !0);
940
+ let p = V.simplifyRouteToCoordinates(j, b, 0), l = 0, k = 0, w = 0, y = 0, g;
941
+ const H = {
934
942
  hours: [],
935
943
  wps: [],
936
944
  days: []
937
945
  };
938
946
  for (t = v(t).utc(); p.length > 0; ) {
939
- const x = r - t.hour() % r;
940
- let E = Math.ceil(t.clone().add(x, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4;
947
+ const D = r - t.hour() % r;
948
+ let E = Math.ceil(t.clone().add(D, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4;
941
949
  if (E = t.clone().add(E, "h").isAfter(i) ? i.diff(t, "h", !0) * 1e4 / 1e4 : E, E)
942
950
  g = await C.speedLoseInHoursStep(
943
951
  Y,
944
952
  t,
945
953
  i.clone(),
946
954
  E,
947
- h,
955
+ l,
948
956
  p,
949
957
  c,
950
958
  d,
951
- l,
959
+ f,
952
960
  M
953
- ), (S = g.from) != null && S.speed && (N.hours.push(g.from), g != null && g.wps && N.wps.push(...g.wps), N.days.push(...g.days)), p = g == null ? void 0 : g.next, p.length || (N.hours.push(g == null ? void 0 : g.to), g != null && g.wps && N.wps.push(...g.wps), N.days.push(g == null ? void 0 : g.to)), h += ((P = g == null ? void 0 : g.to) == null ? void 0 : P.distanceFromPrevious) ?? 0;
961
+ ), (T = g.from) != null && T.speed && (H.hours.push(g.from), g != null && g.wps && H.wps.push(...g.wps), H.days.push(...g.days)), p = g == null ? void 0 : g.next, p.length || (H.hours.push(g == null ? void 0 : g.to), g != null && g.wps && H.wps.push(...g.wps), H.days.push(g == null ? void 0 : g.to)), l += ((P = g == null ? void 0 : g.to) == null ? void 0 : P.distanceFromPrevious) ?? 0;
954
962
  else {
955
- g && (N.hours.push(g.to), g != null && g.wps && N.wps.push(...g.wps), N.days.push(g.to));
963
+ g && (H.hours.push(g.to), g != null && g.wps && H.wps.push(...g.wps), H.days.push(g.to));
956
964
  break;
957
965
  }
958
966
  }
959
- const F = N.hours;
960
- for (let x = 0; x < F.length - 1; x++) {
961
- const E = v(F[x + 1].eta).diff(F[x].etd, "hour", !0);
962
- k += F[x].wxFactor * E, w += F[x].cFactor * E, y += E;
967
+ const F = H.hours;
968
+ for (let D = 0; D < F.length - 1; D++) {
969
+ const E = v(F[D + 1].eta).diff(F[D].etd, "hour", !0);
970
+ k += F[D].wxFactor * E, w += F[D].cFactor * E, y += E;
963
971
  }
964
- const W = N.hours.at(0), T = N.hours.at(-1);
972
+ const O = H.hours.at(0), N = H.hours.at(-1);
965
973
  return {
966
- sample: N,
967
- distance: Math.round(((T == null ? void 0 : T.distanceFromStart) || 0) * 1e4) / 1e4,
974
+ sample: H,
975
+ distance: Math.round(((N == null ? void 0 : N.distanceFromStart) || 0) * 1e4) / 1e4,
968
976
  // 注意,可能会在first节点Drift,所有采用eta做为初始出发时间
969
- etd: v(W.eta).utc().format(),
970
- eta: v(T == null ? void 0 : T.eta).utc().format(),
977
+ etd: v(O.eta).utc().format(),
978
+ eta: v(N == null ? void 0 : N.eta).utc().format(),
971
979
  wxFactor: Math.round(k / y * 1e4) / 1e4,
972
980
  cFactor: Math.round(w / y * 1e4) / 1e4,
973
- avgSpeed: Math.round(((T == null ? void 0 : T.distanceFromStart) || 0) / y * 1e4) / 1e4,
981
+ avgSpeed: Math.round(((N == null ? void 0 : N.distanceFromStart) || 0) / y * 1e4) / 1e4,
974
982
  totalHrs: Math.round(y * 1e4) / 1e4,
975
983
  from: s,
976
- to: T,
984
+ to: N,
977
985
  route: j,
978
986
  waypoints: b,
979
- v0: f,
980
- label: m
987
+ v0: m,
988
+ label: u
981
989
  };
982
990
  }
983
991
  }
984
992
  export {
985
993
  K as AISImpl,
986
- nt as AlertHelper,
987
- ot as AlertLevel,
988
- Mt as HifleetImpl,
989
- rt as LoadCondition,
990
- gt as MyShipImpl,
991
- pt as MyVesselImpl,
992
- yt as ShipxyImpl,
994
+ rt as AlertHelper,
995
+ it as AlertLevel,
996
+ vt as HifleetImpl,
997
+ ut as LoadCondition,
998
+ kt as MyShipImpl,
999
+ bt as MyVesselImpl,
1000
+ Yt as ShipxyImpl,
993
1001
  C as SpeedHelper,
994
- ct as SpeedLabel,
995
- it as VesselTag,
996
- bt as alertHelper
1002
+ ht as SpeedLabel,
1003
+ dt as VesselTag,
1004
+ It as alertHelper
997
1005
  };
@@ -1 +1 @@
1
- (function(H,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):(H=typeof globalThis<"u"?globalThis:H||self,D(H["idm-plugin-rabbitmq"]={},H.got,H["@log4js-node/log4js-api"],H.moment,H["@idm-plugin/geo"],H["@idm-plugin/meteo"]))})(this,function(H,D,Z,g,O,ot){"use strict";var lt=Object.defineProperty;var ft=(H,D,Z)=>D in H?lt(H,D,{enumerable:!0,configurable:!0,writable:!0,value:Z}):H[D]=Z;var K=(H,D,Z)=>(ft(H,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 it 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,M;(!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} ${(M=this.token)==null?void 0:M.accessToken}`},searchParams:{mmsi:t}};u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,n,o);const a=await D.get(n,o).json();if(a.code)return u==null||u.warn("[%s] fetch realtime position failed: %j",i.requestId,n,{message:a.message,status:a.status,code:a.code}),a;const e=a.data;for(const 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,Y,j,v,p;const r="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",d={headers:{Authorization:`${(m=this.token)==null?void 0:m.tokenType} ${(Y=this.token)==null?void 0:Y.accessToken}`},json:{mmsi:t,startTime:i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};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 M=-1;const f=g(`${(v=(j=l.data)==null?void 0:j[0])==null?void 0:v.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(p=l.data)==null||p.forEach(h=>{for(const S in h)!isNaN(h[S])&&Number(h[S])!==1/0&&(h[S]=Number(h[S]));const I=g(`${h.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),w=h.eta?g(`${h.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,y=h.status,{labelCn:b,labelEn:x}=this.parseStatus(y),E={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:w==null?void 0:w.unix(),destination:h.dest,positionTime:I.unix(),labelCn:b,labelEn:x,method:"trajectory",vendor:"myVessel",utc:I.utc().format()},V=Math.floor(I.diff(f,"minute",!0)/(a||1));V!==M&&(M=V,e.push(E))}),e}}class rt 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,w;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 M={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,M).json();u==null||u.info("[%s] fetch trajectory from: %s - %j",e.requestId,f,M);let Y;m&&(Y=((I=(h=m.ships)==null?void 0:h.offors)==null?void 0:I.ship)||[],Y.length||u==null||u.warn("[%s] fetch trajectory failed: %j",e.requestId,m));const j=[];let v=-1;const p=g(`${(w=Y==null?void 0:Y[0])==null?void 0:w.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const y of Y){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:x,labelCn:E}=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:E,labelEn:x,method:"trajectory",vendor:"hifleet"},S=Math.floor(b.diff(p,"minute",!0)/(o||1));S!==v&&(v=S,j.push(V))}return j}}class ct extends z{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,i={}){const n={searchParams:{id:t,k:this.token,enc:1}},o="https://api.shipxy.com/apicall/GetSingleShip",a=await D.get(o,n).json();if(u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,o,n),(a==null?void 0:a.status)!==0)return a;const e=a.data[0];for(const M in e)!isNaN(e[M])&&Number(e[M])!==1/0&&(e[M]=Number(e[M]));const{labelCn: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 p;const c=await this.realTimePosition(t,e),r=g(i),d=g(n),l="https://api.shipxy.com/apicall/GetShipTrack",M={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:r.unix(),etm:d.unix()}},f=await D.get(l,M).json();if(u==null||u.info("[%s] fetch trajectory from: %s - %j",e.requestId,l,M),(f==null?void 0:f.status)!==0)return f;const m=f==null?void 0:f.points,Y=[],j=g.unix((p=m[0])==null?void 0:p.utc);let v=-1;for(const h of m){const I=g.unix(h.utc),w={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!==v&&(v=y,Y.push(w))}return Y}}class dt 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),M=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:M.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),M=[];for(;r.diff(c,"day",!0)>30;)await this.trajectoryIn30Day(d,c.unix(),c.add(30,"day").unix(),l,t,o,M);return await this.trajectoryIn30Day(d,c.unix(),r.unix(),l,t,o,M),M}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",M=await D.post(l,d).json();if(u==null||u.info("[%s] fetch trajectory from: %s - %j",r.requestId,l,d),M.code!=="0")return u==null||u.warn("[%s] invoke myship trajectory failed: %j",r.requestId,M),M;const f=M.data;for(const v in f)!isNaN(f[v])&&Number(f[v])!==1/0&&(f[v]=Number(f[v]));const m=g.unix((j=f[0])==null?void 0:j.posTime);let Y=-1;for(const v of f){const p=g.unix(v.posTime),h={imo:o==null?void 0:o.imo,mmsi:a,lat:Math.round(v.lat/1e4/60*1e5)/1e5,lng:Math.round(v.lon/1e4/60*1e5)/1e5,sog:Math.round(v.sog/10*100)/100,cog:Math.round(v.cog/10*100)/100,hdg:Math.round(v.heading*100)/100,rot:Math.round(v.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!==Y&&(Y=I,c.push(h))}return c}}let R;try{R=Z.getLogger("vessel")}catch{}finally{}var G=(k=>(k.NOTICE="NOTICE",k.WARN="WARN",k.HEAVY="HEAVY",k.SEVERE="SEVERE",k.ERROR="ERROR",k.FATAL="FATAL",k))(G||{});class U{parsePrinciple(s,t={}){var e,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 M=0,f=l.length;M<f;M++){const m=this.parseRule(l[M]);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,Y,j,v,p,h,I,w,y,b,x,E,V,S,_;let n=0,o=0,a=0,e=0;const c=Math.round(((Y=(m=t==null?void 0:t.SEVERE)==null?void 0:m.sigWave)==null?void 0:Y.number)*1.6*100)/100,r=(v=(j=t==null?void 0:t.SEVERE)==null?void 0:j.sigWave)==null?void 0:v.number,d=(h=(p=t==null?void 0:t.HEAVY)==null?void 0:p.sigWave)==null?void 0:h.number,l=Math.round((((w=(I=t==null?void 0:t.SEVERE)==null?void 0:I.wind)==null?void 0:w.number)+2)*100)/100,M=(b=(y=t==null?void 0:t.SEVERE)==null?void 0:y.wind)==null?void 0:b.number,f=(E=(x=t==null?void 0:t.HEAVY)==null?void 0:x.wind)==null?void 0:E.number;for(let W=0;W<(s==null?void 0:s.length);W++){const T=s[W],C=(S=(V=T==null?void 0:T.meteo)==null?void 0:V.wave)==null?void 0:S.sig,F=(_=T==null?void 0:T.meteo)==null?void 0:_.wind,P=W?g(T.eta).diff(g(s[W-1].eta),"hour",!0):0;e=P>e?P:e,R==null||R.info("[%s] check sig.wave: %j",i.requestId,{...C,dgThd4Wv:c,svThd4Wv:r,hvThd4Wv:d}),(C==null?void 0:C.height)>=c?T.isDangerous=!0:(C==null?void 0:C.height)>=r?T.isSevere=!0:(C==null?void 0:C.height)>=d&&(T.isHeavy=!0),R==null||R.info("[%s] check wind: %j",i.requestId,{...F,dgThd4Wd:l,svThd4Wd:M,hvThd4Wd:f}),(F==null?void 0:F.scale)>=l?(T.isDangerous=!0,delete T.isSevere,delete T.isHeavy):(F==null?void 0:F.scale)>M?(T.isDangerous||(T.isSevere=!0),delete T.isHeavy):(F==null?void 0:F.scale)===f&&!T.isDangerous&&!T.isSevere&&(T.isHeavy=!0),n+=T.isDangerous?P:0,o+=T.isSevere?P:0,a+=T.isHeavy?P:0}return n=Math.round(n*100)/100,o=Math.round(o*100)/100,a=Math.round(a*100)/100,e=Math.round(e),{sample:s,dangerous:n,severe:o,heavy:a,step:e<3?3:e,wind:{dgThd4Wd:l,svThd4Wd:M,hvThd4Wd:f},sig:{dgThd4Wv:c,svThd4Wv:r,hvThd4Wv:d}}}}const ut=new U;let N;try{N=Z.getLogger("vessel")}catch{}finally{}var J=(k=>(k.common="common",k.container="container",k.tugs="tugs",k))(J||{}),Q=(k=>(k.Ballast="Ballast",k.Laden="Laden",k))(Q||{}),X=(k=>(k.Cp="CP",k.Perf="Basis",k.Instruct="Other",k))(X||{});class 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,t){s=s<0?.2:s,s=s>6?s-.9*(s-6):s,s=s>9?9:s;let i;return t>30&&t<=60?i=-.6:t>60&&t<=90?i=-.4:t>90&&t<=120?i=s<3?.4:-.3:t>120&&t<=150?i=s<3?.6:-.5:t>150&&t<=180?i=s<3?.7:-.6:i=-.7,Math.round(i*(.144*Math.pow(s,2)+.178*s)*1e4)/1e4}static assembleProperties(s,t,i,n){var M;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=((M=s==null?void 0:s.type)==null?void 0:M.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 ot.MeteoHelper.queryPointFactor(t.lng,t.lat,i.valueOf(),"wind,wave,current,watertemp",n,c),l=A.weatherFactor(s,d),M=A.currentFactor(s.bearing,d==null?void 0:d.current,o),f=Math.round((s.speed*1.943844+l+M)*100)/100;r={meteo:{...d},wxFactor:l,cFactor:M,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=[],M=[];let f=0,m=0,Y,j;for(let v=0;v<a.length-1;v++){let p=a[v];p.distanceFromStart=o+m;const h=a[v+1];if(s.bearing=O.LaneHelper.calculateBearing(p,h,!h.gcToPrevious),p.bearing=s.bearing,p.suspend&&r){p.eta=p.eta||t.format("YYYY-MM-DDTHH:mm[Z]"),p.elapsed=p.elapsed??0;const y=p.suspend-p.elapsed;if(n-f>y)n=n-f-y,t.add(y,"hour"),p.elapsed=p.suspend;else{const b=n-f;p.elapsed+=b,t.add(b,"hour"),n=0}if(N==null||N.info(`[%s] suspend ${p.elapsed} hours at %j, and remain ${n} hours need to go...`,d.requestId,p),n===0)return p.distanceFromPrevious=m,{etd:t,from:j||p,to:p,next:a.filter(b=>b),wps:l,days:M}}else p.suspend=0;p=await A.speedLoseAt(s,p,t,e,0,c,r,d),j=j||p,p.important&&l.push(p),t.isSameOrAfter(i)&&(M.push(p),i.add(24,"hour"));const I=O.LaneHelper.calculateDistance(p,h,!h.gcToPrevious);let w=Math.ceil(I/j.speed*1e4)/1e4;if(f+w<n){if(f+=w,t.add(w,"hour"),delete a[v],N==null||N.info(`[%s] go to %j from %j with ${I}nm, and cost ${w} 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){Y=h,Y.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),Y.distanceFromPrevious=I,Y.distanceFromStart=o+m,l.push(Y),delete a[v+1];break}}else{w=n-f,t.add(w,"hour");const y=O.LngLatHelper.roundPrecision(j.speed*w,4);Y=O.LaneHelper.calculateCoordinate(p,s.bearing,y,"nauticalmiles",!h.gcToPrevious),Y.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),a[v]=Y,N==null||N.info(`[%s] go to %j from %j with ${y}nm, and cost ${w} hours`,d.requestId,{lat:Y.lat,lng:Y.lng},{lat:p.lat,lng:p.lng,etd:p.etd}),m+=y,Y.distanceFromPrevious=m,Y.distanceFromStart=o+m;break}}return{etd:t,from:j,to:Y,next:a.filter(v=>v),wps:l,days:M}}static currentFactor(s,t,i=0){const n=(s-(t==null?void 0:t.degree)||0)/180*Math.PI;if(Math.abs(n)===Math.PI/2)return 0;let o=((t==null?void 0:t.kts)||0)*Math.cos(n);return i&2?o=Math.ceil(o*100)/100:i&1?o=Math.floor(o*100)/100:o=Math.round(o*100)/100,Math.abs(o)>5?0:o}static weatherFactor(s,t){var l,M,f,m,Y,j,v;N==null||N.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,(M=t==null?void 0:t.wind)==null?void 0:M.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)),N==null||N.debug("wind wx factor = %d",r),a=Math.abs(s.bearing%360-(((Y=(m=t==null?void 0:t.wave)==null?void 0:m.sig)==null?void 0:Y.degree)%360||0));const d=A.waveHeightFactor(((v=(j=t==null?void 0:t.wave)==null?void 0:j.sig)==null?void 0:v.height)??1,a);return N==null||N.debug("wave wx factor = %d",d),r=r*.4+d,N==null||N.debug("weather factor = %d",r),r=Math.abs(r)>4?4*(Math.abs(r)/r)+Math.abs(r)/r*(Math.abs(r)-4)*.1:r,Math.round(r*100)/100}static async analyseInstant(s,t,i,n,o,a="",e=0,c=!0,r=!1,d={}){var P,$,tt,et,st;const l=g().valueOf();s.lng=O.LngLatHelper.convertToStdLng(s.lng);const{route:M,waypoints:f}=o.points,m=O.LaneHelper.calculateSubRoute(s,M);if(((P=m[0])==null?void 0:P.length)<=1)return;const{v0:Y,label:j}=s.sog?{v0:s.sog,label:"Other"}:{v0:n.speed,label:"CP"},v=A.assembleProperties(i,n.loadCondition,Y,0),p=f.length?O.LaneHelper.calculateSubWaypoints(s,f):[];p.forEach(q=>q.important=!0);const h={from:{...s},route:m,waypoints:p,v0:Y,label:j},I={hours:[],days:[],wps:[]};e||(O.LaneHelper.calculateRouteDistance(m)/n.speed<=72?e=3:e=6);let w=O.LaneHelper.simplifyRouteToCoordinates(m,p,0),y=0,b=0,x=0,E=0;t=g(t).utc();const V=t.clone();for(;w.length>0;){const q=e-t.hour()%e,B=Math.ceil(t.clone().add(q,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,L=await A.speedLoseInHoursStep(v,t,V,B,y,w,a,c,r,d);($=L.from)!=null&&$.speed&&(I.hours.push(L.from),I.wps.push(...L.wps),I.days.push(...L.days)),w=L==null?void 0:L.next,w.length||I.hours.push(L==null?void 0:L.to),y+=((tt=L==null?void 0:L.to)==null?void 0:tt.distanceFromPrevious)??0}const S=I.hours;for(let q=0;q<S.length-1;q++){const B=g(S[q+1].eta).diff(S[q].etd,"hour",!0)||1;b+=(S[q].wxFactor||0)*B,x+=(S[q].cFactor||0)*B,E+=B}(et=I.wps)==null||et.forEach((q,B)=>{if(B){const L=I.wps[B-1],ht=q.distanceFromStart-L.distanceFromStart,at=g(q.eta).diff(g(L.etd),"h",!0);if(at<1)q.avgSpd=L.speed;else{q.avgSpd=Math.round(ht/at*100)/100;const nt=Math.round((L.speed+q.speed)/2*100)/100;q.avgSpd=q.avgSpd>nt?nt:q.avgSpd}}}),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/E*1e4)/1e4,h.cFactor=Math.round(x/E*1e4)/1e4,h.avgSpeed=Math.round(W.distanceFromStart/E*1e4)/1e4,h.totalHrs=Math.round(E*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 C=g().valueOf()-l,F=((st=I==null?void 0:I.hours)==null?void 0:st.length)||1;return N==null||N.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",d==null?void 0:d.requestId,C,F,Math.round(C/F*1e3)/1e3),h}static async analyseInstantWithThreshed(s,t,i,n,o,a,e,c="",r=3,d=!0,l=!1,M={}){var W,T,C;s.lng=O.LngLatHelper.convertToStdLng(s.lng);const{v0:f,label:m}=s.sog?{v0:s.sog,label:"Other"}:{v0:o.speed,label:"CP"},Y=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 v=e.length?O.LaneHelper.calculateSubWaypoints(s,e):[];v.forEach(F=>F.important=!0);let p=O.LaneHelper.simplifyRouteToCoordinates(j,v,0),h=0,I=0,w=0,y=0,b;const x={hours:[],wps:[],days:[]};for(t=g(t).utc();p.length>0;){const F=r-t.hour()%r;let P=Math.ceil(t.clone().add(F,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;if(P=t.clone().add(P,"h").isAfter(i)?i.diff(t,"h",!0)*1e4/1e4:P,P)b=await A.speedLoseInHoursStep(Y,t,i.clone(),P,h,p,c,d,l,M),(T=b.from)!=null&&T.speed&&(x.hours.push(b.from),b!=null&&b.wps&&x.wps.push(...b.wps),x.days.push(...b.days)),p=b==null?void 0:b.next,p.length||(x.hours.push(b==null?void 0:b.to),b!=null&&b.wps&&x.wps.push(...b.wps),x.days.push(b==null?void 0:b.to)),h+=((C=b==null?void 0:b.to)==null?void 0:C.distanceFromPrevious)??0;else{b&&(x.hours.push(b.to),b!=null&&b.wps&&x.wps.push(...b.wps),x.days.push(b.to));break}}const E=x.hours;for(let F=0;F<E.length-1;F++){const P=g(E[F+1].eta).diff(E[F].etd,"hour",!0);I+=E[F].wxFactor*P,w+=E[F].cFactor*P,y+=P}const V=x.hours.at(0),S=x.hours.at(-1);return{sample:x,distance:Math.round(((S==null?void 0:S.distanceFromStart)||0)*1e4)/1e4,etd:g(V.eta).utc().format(),eta:g(S==null?void 0:S.eta).utc().format(),wxFactor:Math.round(I/y*1e4)/1e4,cFactor:Math.round(w/y*1e4)/1e4,avgSpeed:Math.round(((S==null?void 0:S.distanceFromStart)||0)/y*1e4)/1e4,totalHrs:Math.round(y*1e4)/1e4,from:s,to:S,route:j,waypoints:v,v0:f,label:m}}}H.AISImpl=z,H.AlertHelper=U,H.AlertLevel=G,H.HifleetImpl=rt,H.LoadCondition=Q,H.MyShipImpl=dt,H.MyVesselImpl=it,H.ShipxyImpl=ct,H.SpeedHelper=A,H.SpeedLabel=X,H.VesselTag=J,H.alertHelper=ut,Object.defineProperty(H,Symbol.toStringTag,{value:"Module"})});
1
+ (function(w,T){typeof exports=="object"&&typeof module<"u"?T(exports,require("got"),require("@log4js-node/log4js-api"),require("moment"),require("@idm-plugin/geo"),require("@idm-plugin/meteo2"),require("@idm-plugin/meteo")):typeof define=="function"&&define.amd?define(["exports","got","@log4js-node/log4js-api","moment","@idm-plugin/geo","@idm-plugin/meteo2","@idm-plugin/meteo"],T):(w=typeof globalThis<"u"?globalThis:w||self,T(w["idm-plugin-rabbitmq"]={},w.got,w["@log4js-node/log4js-api"],w.moment,w["@idm-plugin/geo"],w["@idm-plugin/meteo2"],w["@idm-plugin/meteo"]))})(this,function(w,T,Z,v,O,G,U){"use strict";var mt=Object.defineProperty;var pt=(w,T,Z)=>T in w?mt(w,T,{enumerable:!0,configurable:!0,writable:!0,value:Z}):w[T]=Z;var K=(w,T,Z)=>(pt(w,typeof T!="symbol"?T+"":T,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 rt extends z{constructor(t,i){super();K(this,"clientId");K(this,"clientSecret");K(this,"token");this.clientId=t,this.clientSecret=i}async authToken(t={}){const i="https://svc.data.myvessel.cn/ada/oauth/token",n={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},o=await T.post(i,n).json();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 d,f,M;(!this.token||v().diff(v(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:`${(f=this.token)==null?void 0:f.tokenType} ${(M=this.token)==null?void 0:M.accessToken}`},searchParams:{mmsi:t}};u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,n,o);const a=await T.get(n,o).json();if(a.code)return u==null||u.warn("[%s] fetch realtime position failed: %j",i.requestId,n,{message:a.message,status:a.status,code:a.code}),a;const e=a.data;for(const m in e)!isNaN(e[m])&&Number(e[m])!==1/0&&(e[m]=Number(e[m]));const c=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:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta)?v.utc(e.eta).format():void 0,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||v().diff(v(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(e);const c=await this.realTimePosition(t,e),r=v(i),d=v(n),f=[];for(;d.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(t,r,r.clone().add(30,"day"),c,o,f,e),r.add(30,"day");return await this.trajectoryIn30Day(t,r,d,c,o,f,e),f}async trajectoryIn30Day(t,i,n,o,a,e,c={}){var h,I,j,b,p;const r="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",d={headers:{Authorization:`${(h=this.token)==null?void 0:h.tokenType} ${(I=this.token)==null?void 0:I.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 f=await T.post(r,d).json();if(f.code)return u==null||u.warn("[%s] fetch trajectory failed: %j",c.requestId,r,{message:f.message,status:f.status,code:f.code}),f;let M=-1;const m=v(`${(b=(j=f.data)==null?void 0:j[0])==null?void 0:b.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(p=f.data)==null||p.forEach(l=>{for(const W in l)!isNaN(l[W])&&Number(l[W])!==1/0&&(l[W]=Number(l[W]));const Y=v(`${l.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),H=l.status,{labelCn:y,labelEn:g}=this.parseStatus(H),F={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:H,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(l.eta)?v(`${l.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").utc().format():void 0,destination:l.dest,positionTime:Y.unix(),labelCn:y,labelEn:g,method:"trajectory",vendor:"myVessel",utc:Y.utc().format()},E=Math.floor(Y.diff(m,"minute",!0)/(a||1));E!==M&&(M=E,e.push(F))}),e}}class ct extends z{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,i={}){const n="https://api.hifleet.com/position/position/get/token",o={searchParams:{mmsi:t,usertoken:this.token}},a=await T.post(n,o).json();u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,n,o);const e=a==null?void 0:a.list;if(!e)return u==null||u.warn("[%s] fetch realtime position failed: %j",i.requestId,n,a),a;for(const m in e)!isNaN(e[m])&&Number(e[m])!==1/0&&(e[m]=Number(e[m]));e.status=e.sp>3?0:1;const c=e.status,{labelCn:r,labelEn:d}=this.parseStatus(c),f=v(`${e.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:e.m,name:e.n,imo:e.imonumber,callSign:e.callsign,lat:Math.round(e.la/60*1e5)/1e5,lng:Math.round(e.lo/60*1e5)/1e5,length:e.l,width:e.w,draught:e.draught,sog:e.sp,cog:e.co,hdg:e.h,rot:isNaN(e.rot)?0:e.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta)?v.utc(e.eta).format():void 0,destination:e.destination,positionTime:f.unix(),utc:f.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 T.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 T.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,Y,H;const c=await this.realTimePosition(t,e);let r=v(i);const d=v(n),f=v();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=f.diff(d,"d",!0),d.add(y>10?240:y*24,"h")}const M={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}},m="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",h=await T.get(m,M).json();u==null||u.info("[%s] fetch trajectory from: %s - %j",e.requestId,m,M);let I;h&&(I=((Y=(l=h.ships)==null?void 0:l.offors)==null?void 0:Y.ship)||[],I.length||u==null||u.warn("[%s] fetch trajectory failed: %j",e.requestId,h));const j=[];let b=-1;const p=v(`${(H=I==null?void 0:I[0])==null?void 0:H.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const y of I){for(const _ in y)!isNaN(y[_])&&Number(y[_])!==1/0&&(y[_]=Number(y[_]));const g=v(`${y.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");y.status=y.sp>4?0:1;const{labelEn:F,labelCn:E}=this.parseStatus(y.status),W={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:g.unix(),utc:g.utc().format(),status:y.status,labelCn:E,labelEn:F,method:"trajectory",vendor:"hifleet"},q=Math.floor(g.diff(p,"minute",!0)/(o||1));q!==b&&(b=q,j.push(W))}return j}}class dt extends z{constructor(t){super();K(this,"token");this.token=t}async realTimePosition(t,i={}){const n={searchParams:{id:t,k:this.token,enc:1}},o="https://api.shipxy.com/apicall/GetSingleShip",a=await T.get(o,n).json();if(u==null||u.info("[%s] fetch realtime position from: %s - %j",i.requestId,o,n),(a==null?void 0:a.status)!==0)return a;const e=a.data[0];for(const M in e)!isNaN(e[M])&&Number(e[M])!==1/0&&(e[M]=Number(e[M]));const{labelCn:c,labelEn:r}=await this.parseStatus(e.navistat),d=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:d.utc().format(),status:e.navistat,labelEn:r,labelCn:c,method:"position",vendor:"shipxy"}}async trajectory(t,i,n,o,a=!0,e={}){var p;const c=await this.realTimePosition(t,e),r=v(i),d=v(n),f="https://api.shipxy.com/apicall/GetShipTrack",M={searchParams:{id:t,k:this.token,enc:1,cut:0,btm:r.unix(),etm:d.unix()}},m=await T.get(f,M).json();if(u==null||u.info("[%s] fetch trajectory from: %s - %j",e.requestId,f,M),(m==null?void 0:m.status)!==0)return m;const h=m==null?void 0:m.points,I=[],j=v.unix((p=h[0])==null?void 0:p.utc);let b=-1;for(const l of h){const Y=v.unix(l.utc),H={imo:c==null?void 0:c.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:Y.unix(),utc:Y.utc().format(),method:"trajectory",vendor:"shipxy"},y=Math.floor(Y.diff(j,"minute",!0)/(o||1));y!==b&&(b=y,I.push(H))}return I}}class ut extends z{constructor(t){super();K(this,"token");this.token=t}async getShipId(t,i={}){const n={headers:{appKey:this.token},json:{mmsiList:t}},o="https://api3.myships.com/sp/ships/getShipIdByMMSI",a=await T.post(o,n).json();return 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 T.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 T.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 h in r)!isNaN(r[h])&&Number(r[h])!==1/0&&(r[h]=Number(r[h]));const{labelCn:d,labelEn:f}=await this.parseStatus(r.aisNavStatus),M=v.unix(r.posTime);return{...o,mmsi:t,lat:Math.round(r.lat/1e4/60*1e5)/1e5,lng:Math.round(r.lon/1e4/60*1e5)/1e5,sog:Math.round(r.sog/10*100)/100,cog:Math.round(r.cog/10*100)/100,hdg:Math.round(r.heading*100)/100,rot:Math.round(r.rot*100)/100,positionTime:r.posTime,utc:M.utc().format(),status:r.aisNavStatus,labelEn:f,labelCn:d,method:"position",vendor:"myship"}}async trajectory(t,i,n,o,a=!0,e={}){const c=v(i),r=v(n),d=await this.getShipId(t),f=await this.getShipInfo(d),M=[];for(;r.diff(c,"day",!0)>30;)await this.trajectoryIn30Day(d,c.unix(),c.add(30,"day").unix(),f,t,o,M);return await this.trajectoryIn30Day(d,c.unix(),r.unix(),f,t,o,M),M}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}},f="https://api3.myships.com/sp/ships/position/history",M=await T.post(f,d).json();if(u==null||u.info("[%s] fetch trajectory from: %s - %j",r.requestId,f,d),M.code!=="0")return u==null||u.warn("[%s] invoke myship trajectory failed: %j",r.requestId,M),M;const m=M.data;for(const b in m)!isNaN(m[b])&&Number(m[b])!==1/0&&(m[b]=Number(m[b]));const h=v.unix((j=m[0])==null?void 0:j.posTime);let I=-1;for(const b of m){const p=v.unix(b.posTime),l={imo:o==null?void 0:o.imo,mmsi:a,lat:Math.round(b.lat/1e4/60*1e5)/1e5,lng:Math.round(b.lon/1e4/60*1e5)/1e5,sog:Math.round(b.sog/10*100)/100,cog:Math.round(b.cog/10*100)/100,hdg:Math.round(b.heading*100)/100,rot:Math.round(b.rot*100)/100,positionTime:p.unix(),utc:p.utc().format(),method:"trajectory",vendor:"myship"},Y=Math.floor(p.diff(h,"minute",!0)/(e||1));Y!==I&&(I=Y,c.push(l))}return c}}let R;try{R=Z.getLogger("vessel")}catch{}finally{}var J=(k=>(k.NOTICE="NOTICE",k.WARN="WARN",k.HEAVY="HEAVY",k.SEVERE="SEVERE",k.ERROR="ERROR",k.FATAL="FATAL",k))(J||{});class Q{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 f=(r=(c=o[d].match(i))==null?void 0:c[0])==null?void 0:r.split("],");if(d===0&&!f)a.scope=o[0];else if(f)for(let M=0,m=f.length;M<m;M++){const h=this.parseRule(f[M]);h&&(a[h.level]?h.key?a[h.level][h==null?void 0:h.key]=h:a[h.level]=h:h.key?a[h.level]={[h==null?void 0:h.key]:h}:a[h.level]=h)}}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 h,I,j,b,p,l,Y,H,y,g,F,E,W,q,_;let n=0,o=0,a=0,e=0;const c=Math.round(((I=(h=t==null?void 0:t.SEVERE)==null?void 0:h.sigWave)==null?void 0:I.number)*1.6*100)/100,r=(b=(j=t==null?void 0:t.SEVERE)==null?void 0:j.sigWave)==null?void 0:b.number,d=(l=(p=t==null?void 0:t.HEAVY)==null?void 0:p.sigWave)==null?void 0:l.number,f=Math.round((((H=(Y=t==null?void 0:t.SEVERE)==null?void 0:Y.wind)==null?void 0:H.number)+2)*100)/100,M=(g=(y=t==null?void 0:t.SEVERE)==null?void 0:y.wind)==null?void 0:g.number,m=(E=(F=t==null?void 0:t.HEAVY)==null?void 0:F.wind)==null?void 0:E.number;for(let V=0;V<(s==null?void 0:s.length);V++){const S=s[V],C=(q=(W=S==null?void 0:S.meteo)==null?void 0:W.wave)==null?void 0:q.sig,N=(_=S==null?void 0:S.meteo)==null?void 0:_.wind,L=V?v(S.eta).diff(v(s[V-1].eta),"hour",!0):0;e=L>e?L:e,R==null||R.info("[%s] check sig.wave: %j",i.requestId,{...C,dgThd4Wv:c,svThd4Wv:r,hvThd4Wv:d}),(C==null?void 0:C.height)>=c?S.isDangerous=!0:(C==null?void 0:C.height)>=r?S.isSevere=!0:(C==null?void 0:C.height)>=d&&(S.isHeavy=!0),R==null||R.info("[%s] check wind: %j",i.requestId,{...N,dgThd4Wd:f,svThd4Wd:M,hvThd4Wd:m}),(N==null?void 0:N.scale)>=f?(S.isDangerous=!0,delete S.isSevere,delete S.isHeavy):(N==null?void 0:N.scale)>M?(S.isDangerous||(S.isSevere=!0),delete S.isHeavy):(N==null?void 0:N.scale)===m&&!S.isDangerous&&!S.isSevere&&(S.isHeavy=!0),n+=S.isDangerous?L:0,o+=S.isSevere?L:0,a+=S.isHeavy?L: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:f,svThd4Wd:M,hvThd4Wd:m},sig:{dgThd4Wv:c,svThd4Wv:r,hvThd4Wv:d}}}}const ht=new Q;let D;try{D=Z.getLogger("vessel")}catch{}finally{}const lt=new G.MeteoHelper2("",!0);var X=(k=>(k.common="common",k.container="container",k.tugs="tugs",k))(X||{}),$=(k=>(k.Ballast="Ballast",k.Laden="Laden",k))($||{}),tt=(k=>(k.Cp="CP",k.Perf="Basis",k.Instruct="Other",k))(tt||{});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,t){s=s<0?.2:s,s=s>6?s-.9*(s-6):s,s=s>9?9:s;let i;return t>30&&t<=60?i=-.6:t>60&&t<=90?i=-.4:t>90&&t<=120?i=s<3?.4:-.3:t>120&&t<=150?i=s<3?.6:-.5:t>150&&t<=180?i=s<3?.7:-.6:i=-.7,Math.round(i*(.144*Math.pow(s,2)+.178*s)*1e4)/1e4}static assembleProperties(s,t,i,n){var M;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=((M=s==null?void 0:s.type)==null?void 0:M.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){let d;if(c.meteo2){const h=await lt.spotForecast(t.lat,t.lng,i.utc().format(),!1,!1,!0,c),[I]=U.Meteo2Assist.pickHourly(h,i);d=U.Meteo2Assist.toLegacy(I)}else d=await G.MeteoHelper.queryPointFactor(t.lng,t.lat,i.valueOf(),"wind,wave,current,watertemp",n,c);const f=A.weatherFactor(s,d),M=A.currentFactor(s.bearing,d==null?void 0:d.current,o),m=Math.round((s.speed*1.943844+f+M)*100)/100;r={meteo:{...d},wxFactor:f,cFactor:M,speed:t.velocity&&e?t.velocity:m<0?1:m,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 f=[],M=[];let m=0,h=0,I,j;for(let b=0;b<a.length-1;b++){let p=a[b];p.distanceFromStart=o+h;const l=a[b+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 y=p.suspend-p.elapsed;if(n-m>y)n=n-m-y,t.add(y,"hour"),p.elapsed=p.suspend;else{const g=n-m;p.elapsed+=g,t.add(g,"hour"),n=0}if(D==null||D.info(`[%s] suspend ${p.elapsed} hours at %j, and remain ${n} hours need to go...`,d.requestId,p),n===0)return p.distanceFromPrevious=h,{etd:t,from:j||p,to:p,next:a.filter(g=>g),wps:f,days:M}}else p.suspend=0;p=await A.speedLoseAt(s,p,t,e,0,c,r,d),j=j||p,p.important&&f.push(p),t.isSameOrAfter(i)&&(M.push(p),i.add(24,"hour"));const Y=O.LaneHelper.calculateDistance(p,l,!l.gcToPrevious);let H=Math.ceil(Y/j.speed*1e4)/1e4;if(m+H<n){if(m+=H,t.add(H,"hour"),delete a[b],D==null||D.info(`[%s] go to %j from %j with ${Y}nm, and cost ${H} hours`,d.requestId,{lat:l.lat,lng:l.lng},{lat:j.lat,lng:j.lng,etd:j.etd}),h+=Y,a.filter(y=>y).length<=1){I=l,I.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),I.distanceFromPrevious=Y,I.distanceFromStart=o+h,f.push(I),delete a[b+1];break}}else{H=n-m,t.add(H,"hour");const y=O.LngLatHelper.roundPrecision(j.speed*H,4);I=O.LaneHelper.calculateCoordinate(p,s.bearing,y,"nauticalmiles",!l.gcToPrevious),I.eta=t.format("YYYY-MM-DDTHH:mm[Z]"),a[b]=I,D==null||D.info(`[%s] go to %j from %j with ${y}nm, and cost ${H} hours`,d.requestId,{lat:I.lat,lng:I.lng},{lat:p.lat,lng:p.lng,etd:p.etd}),h+=y,I.distanceFromPrevious=h,I.distanceFromStart=o+h;break}}return{etd:t,from:j,to:I,next:a.filter(b=>b),wps:f,days:M}}static currentFactor(s,t,i=0){const n=(s-(t==null?void 0:t.degree)||0)/180*Math.PI;if(Math.abs(n)===Math.PI/2)return 0;let o=((t==null?void 0:t.kts)||0)*Math.cos(n);return i&2?o=Math.ceil(o*100)/100:i&1?o=Math.floor(o*100)/100:o=Math.round(o*100)/100,Math.abs(o)>5?0:o}static weatherFactor(s,t){var f,M,m,h,I,j,b;D==null||D.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-(((f=t==null?void 0:t.wind)==null?void 0:f.degree)%360||0));a=a>180?360-a:a;const e=A.directionFactor(a,(M=t==null?void 0:t.wind)==null?void 0:M.scale),c=A.vesselTagFactor(s.displacement,s.loadCondition,s.tag,(m=t==null?void 0:t.wind)==null?void 0:m.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)),D==null||D.debug("wind wx factor = %d",r),a=Math.abs(s.bearing%360-(((I=(h=t==null?void 0:t.wave)==null?void 0:h.sig)==null?void 0:I.degree)%360||0));const d=A.waveHeightFactor(((b=(j=t==null?void 0:t.wave)==null?void 0:j.sig)==null?void 0:b.height)??1,a);return D==null||D.debug("wave wx factor = %d",d),r=r*.4+d,D==null||D.debug("weather factor = %d",r),r=Math.abs(r)>4?4*(Math.abs(r)/r)+Math.abs(r)/r*(Math.abs(r)-4)*.1:r,Math.round(r*100)/100}static async analyseInstant(s,t,i,n,o,a="",e=0,c=!0,r=!1,d={}){var L,et,st,at,nt;const f=v().valueOf();s.lng=O.LngLatHelper.convertToStdLng(s.lng);const{route:M,waypoints:m}=o.points,h=O.LaneHelper.calculateSubRoute(s,M);if(((L=h[0])==null?void 0:L.length)<=1)return;const{v0:I,label:j}=s.sog?{v0:s.sog,label:"Other"}:{v0:n.speed,label:"CP"},b=A.assembleProperties(i,n.loadCondition,I,0),p=m.length?O.LaneHelper.calculateSubWaypoints(s,m):[];p.forEach(x=>x.important=!0);const l={from:{...s},route:h,waypoints:p,v0:I,label:j},Y={hours:[],days:[],wps:[]};e||(O.LaneHelper.calculateRouteDistance(h)/n.speed<=72?e=3:e=6);let H=O.LaneHelper.simplifyRouteToCoordinates(h,p,0),y=0,g=0,F=0,E=0;t=v(t).utc();const W=t.clone();for(;H.length>0;){const x=e-t.hour()%e,B=Math.ceil(t.clone().add(x,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4,P=await A.speedLoseInHoursStep(b,t,W,B,y,H,a,c,r,d);(et=P.from)!=null&&et.speed&&(Y.hours.push(P.from),Y.wps.push(...P.wps),Y.days.push(...P.days)),H=P==null?void 0:P.next,H.length||Y.hours.push(P==null?void 0:P.to),y+=((st=P==null?void 0:P.to)==null?void 0:st.distanceFromPrevious)??0}const q=Y.hours;for(let x=0;x<q.length-1;x++){const B=v(q[x+1].eta).diff(q[x].etd,"hour",!0)||1;g+=(q[x].wxFactor||0)*B,F+=(q[x].cFactor||0)*B,E+=B}(at=Y.wps)==null||at.forEach((x,B)=>{if(B){const P=Y.wps[B-1],ft=x.distanceFromStart-P.distanceFromStart,ot=v(x.eta).diff(v(P.etd),"h",!0);if(ot<1)x.avgSpd=P.speed;else{x.avgSpd=Math.round(ft/ot*100)/100;const it=Math.round((P.speed+x.speed)/2*100)/100;x.avgSpd=x.avgSpd>it?it:x.avgSpd}}}),l.sample=Y;const _=Y.hours.at(0),V=Y.hours.at(-1);l.distance=Math.round(V.distanceFromStart*1e4)/1e4,l.etd=v(_.eta).utc().format(),l.eta=v(V.eta).utc().format(),l.wxFactor=Math.round(g/E*1e4)/1e4,l.cFactor=Math.round(F/E*1e4)/1e4,l.avgSpeed=Math.round(V.distanceFromStart/E*1e4)/1e4,l.totalHrs=Math.round(E*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 C=v().valueOf()-f,N=((nt=Y==null?void 0:Y.hours)==null?void 0:nt.length)||1;return D==null||D.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",d==null?void 0:d.requestId,C,N,Math.round(C/N*1e3)/1e3),l}static async analyseInstantWithThreshed(s,t,i,n,o,a,e,c="",r=3,d=!0,f=!1,M={}){var V,S,C;s.lng=O.LngLatHelper.convertToStdLng(s.lng);const{v0:m,label:h}=s.sog?{v0:s.sog,label:"Other"}:{v0:o.speed,label:"CP"},I=A.assembleProperties(n,o.loadCondition,m,0),j=O.LaneHelper.calculateSubRoute(s,a);if(((V=j[0])==null?void 0:V.length)<=1)return;const b=e.length?O.LaneHelper.calculateSubWaypoints(s,e):[];b.forEach(N=>N.important=!0);let p=O.LaneHelper.simplifyRouteToCoordinates(j,b,0),l=0,Y=0,H=0,y=0,g;const F={hours:[],wps:[],days:[]};for(t=v(t).utc();p.length>0;){const N=r-t.hour()%r;let L=Math.ceil(t.clone().add(N,"h").set({minute:0,second:0,millisecond:0}).diff(t,"h",!0)*1e4)/1e4;if(L=t.clone().add(L,"h").isAfter(i)?i.diff(t,"h",!0)*1e4/1e4:L,L)g=await A.speedLoseInHoursStep(I,t,i.clone(),L,l,p,c,d,f,M),(S=g.from)!=null&&S.speed&&(F.hours.push(g.from),g!=null&&g.wps&&F.wps.push(...g.wps),F.days.push(...g.days)),p=g==null?void 0:g.next,p.length||(F.hours.push(g==null?void 0:g.to),g!=null&&g.wps&&F.wps.push(...g.wps),F.days.push(g==null?void 0:g.to)),l+=((C=g==null?void 0:g.to)==null?void 0:C.distanceFromPrevious)??0;else{g&&(F.hours.push(g.to),g!=null&&g.wps&&F.wps.push(...g.wps),F.days.push(g.to));break}}const E=F.hours;for(let N=0;N<E.length-1;N++){const L=v(E[N+1].eta).diff(E[N].etd,"hour",!0);Y+=E[N].wxFactor*L,H+=E[N].cFactor*L,y+=L}const W=F.hours.at(0),q=F.hours.at(-1);return{sample:F,distance:Math.round(((q==null?void 0:q.distanceFromStart)||0)*1e4)/1e4,etd:v(W.eta).utc().format(),eta:v(q==null?void 0:q.eta).utc().format(),wxFactor:Math.round(Y/y*1e4)/1e4,cFactor:Math.round(H/y*1e4)/1e4,avgSpeed:Math.round(((q==null?void 0:q.distanceFromStart)||0)/y*1e4)/1e4,totalHrs:Math.round(y*1e4)/1e4,from:s,to:q,route:j,waypoints:b,v0:m,label:h}}}w.AISImpl=z,w.AlertHelper=Q,w.AlertLevel=J,w.HifleetImpl=ct,w.LoadCondition=$,w.MyShipImpl=ut,w.MyVesselImpl=rt,w.ShipxyImpl=dt,w.SpeedHelper=A,w.SpeedLabel=tt,w.VesselTag=X,w.alertHelper=ht,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
@@ -1,4 +1,4 @@
1
- import { Current, Meteo } from '@idm-plugin/meteo';
1
+ import { Current, Meteo } from '@idm-plugin/meteo2';
2
2
  import moment from 'moment';
3
3
  /**
4
4
  * 船舶标签,不同标签适用不同分析模型
@@ -136,6 +136,7 @@ export declare class SpeedHelper {
136
136
  */
137
137
  static speedLoseAt(props: VesselProperties, coordinate: any, eta: moment.Moment, source?: string, role?: number, useMeteo?: boolean, useRouteParam?: boolean, options?: {
138
138
  requestId?: string;
139
+ meteo2?: boolean;
139
140
  }): Promise<any>;
140
141
  /**
141
142
  * 基于步长计算失速样本
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idm-plugin/vessel",
3
3
  "private": false,
4
- "version": "1.4.5",
4
+ "version": "1.4.7",
5
5
  "description": "idm plugin for vessel",
6
6
  "type": "module",
7
7
  "keywords": [
@@ -28,7 +28,8 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@idm-plugin/geo": "^1.5.7",
31
- "@idm-plugin/meteo": "^0.0.2",
31
+ "@idm-plugin/meteo": "^0.1.9",
32
+ "@idm-plugin/meteo2": "^0.0.8",
32
33
  "@log4js-node/log4js-api": "^1.0.2",
33
34
  "got": "11",
34
35
  "moment": "^2.30.1"
@@ -39,6 +40,7 @@
39
40
  "@typescript-eslint/eslint-plugin": "^5.53.0",
40
41
  "@typescript-eslint/parser": "^5.53.0",
41
42
  "@vitejs/plugin-vue": "^4.2.3",
43
+ "cross-fetch": "^4.1.0",
42
44
  "eslint": "^8.35.0",
43
45
  "eslint-config-prettier": "^8.6.0",
44
46
  "eslint-define-config": "^1.15.0",