@idm-plugin/vessel 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +119 -117
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
var C = Object.defineProperty;
|
|
2
|
-
var O = (
|
|
3
|
-
var q = (
|
|
2
|
+
var O = (M, u, e) => u in M ? C(M, u, { enumerable: !0, configurable: !0, writable: !0, value: e }) : M[u] = e;
|
|
3
|
+
var q = (M, u, e) => (O(M, typeof u != "symbol" ? u + "" : u, e), e);
|
|
4
4
|
import Y from "got";
|
|
5
5
|
import * as W from "log4js";
|
|
6
6
|
import p from "moment";
|
|
7
|
-
const
|
|
7
|
+
const j = W.getLogger();
|
|
8
|
+
j.level = "info";
|
|
8
9
|
class V {
|
|
9
10
|
/**
|
|
10
11
|
* 解析AIS状态码
|
|
11
12
|
* @param status
|
|
12
13
|
*/
|
|
13
|
-
parseStatus(
|
|
14
|
+
parseStatus(u) {
|
|
14
15
|
let e, n;
|
|
15
|
-
switch (
|
|
16
|
+
switch (u) {
|
|
16
17
|
case 0:
|
|
17
18
|
e = "在航(主机推动)", n = "The engine is in use";
|
|
18
19
|
break;
|
|
@@ -62,7 +63,7 @@ class B extends V {
|
|
|
62
63
|
grant_type: "client_credentials"
|
|
63
64
|
}
|
|
64
65
|
}, o = await Y.post(n, a).json();
|
|
65
|
-
|
|
66
|
+
j.info("[%s] fetch access token from: %s - %j", e.requestId, n, o), o.error || (this.token = {
|
|
66
67
|
accessToken: o.access_token,
|
|
67
68
|
tokenType: o.token_type,
|
|
68
69
|
expiresIn: o.expires_in,
|
|
@@ -72,18 +73,18 @@ class B extends V {
|
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
75
|
async realTimePosition(e, n = {}) {
|
|
75
|
-
var
|
|
76
|
-
(!this.token || p().diff(p(this.token.issuedAt), "seconds") > ((
|
|
76
|
+
var h, c, f;
|
|
77
|
+
(!this.token || p().diff(p(this.token.issuedAt), "seconds") > ((h = this.token) == null ? void 0 : h.expiresIn) - 300) && await this.authToken(n);
|
|
77
78
|
const a = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit", o = {
|
|
78
79
|
headers: {
|
|
79
|
-
Authorization: `${(
|
|
80
|
+
Authorization: `${(c = this.token) == null ? void 0 : c.tokenType} ${(f = this.token) == null ? void 0 : f.accessToken}`
|
|
80
81
|
},
|
|
81
82
|
searchParams: { mmsi: e }
|
|
82
83
|
};
|
|
83
|
-
|
|
84
|
+
j.info("[%s] fetch realtime position from: %s - %j", n.requestId, a, o);
|
|
84
85
|
const s = await Y.get(a, o).json();
|
|
85
86
|
if (s.code)
|
|
86
|
-
return
|
|
87
|
+
return j.warn("[%s] fetch realtime position failed: %j", n.requestId, a, { message: s.message, status: s.status, code: s.code }), s;
|
|
87
88
|
const t = s.data;
|
|
88
89
|
for (const m in t)
|
|
89
90
|
!isNaN(t[m]) && Number(t[m]) !== 1 / 0 && (t[m] = Number(t[m]));
|
|
@@ -115,16 +116,16 @@ class B extends V {
|
|
|
115
116
|
}
|
|
116
117
|
async trajectory(e, n, a, o, s = !0, t = {}) {
|
|
117
118
|
(!this.token || p().diff(p(this.token.issuedAt), "seconds") > this.token.expiresIn - 300) && await this.authToken(t);
|
|
118
|
-
const r = await this.realTimePosition(e, t), i = p(n),
|
|
119
|
-
for (;
|
|
120
|
-
await this.trajectoryIn30Day(e, i, i.clone().add(30, "day"), r, o,
|
|
121
|
-
return await this.trajectoryIn30Day(e, i,
|
|
119
|
+
const r = await this.realTimePosition(e, t), i = p(n), h = p(a), c = [];
|
|
120
|
+
for (; h.diff(i, "day", !0) > 30; )
|
|
121
|
+
await this.trajectoryIn30Day(e, i, i.clone().add(30, "day"), r, o, c, t), i.add(30, "day");
|
|
122
|
+
return await this.trajectoryIn30Day(e, i, h, r, o, c, t), c;
|
|
122
123
|
}
|
|
123
124
|
async trajectoryIn30Day(e, n, a, o, s, t, r = {}) {
|
|
124
|
-
var
|
|
125
|
-
const i = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",
|
|
125
|
+
var d, b, w, y, v;
|
|
126
|
+
const i = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", h = {
|
|
126
127
|
headers: {
|
|
127
|
-
Authorization: `${(
|
|
128
|
+
Authorization: `${(d = this.token) == null ? void 0 : d.tokenType} ${(b = this.token) == null ? void 0 : b.accessToken}`
|
|
128
129
|
},
|
|
129
130
|
json: {
|
|
130
131
|
mmsi: e,
|
|
@@ -132,16 +133,16 @@ class B extends V {
|
|
|
132
133
|
endTime: a.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")
|
|
133
134
|
}
|
|
134
135
|
};
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
if (
|
|
138
|
-
return
|
|
136
|
+
j.info("[%s] fetch trajectory from: %s - %j", r.requestId, i, h);
|
|
137
|
+
const c = await Y.post(i, h).json();
|
|
138
|
+
if (c.code)
|
|
139
|
+
return j.warn("[%s] fetch trajectory failed: %j", r.requestId, i, { message: c.message, status: c.status, code: c.code }), c;
|
|
139
140
|
let f = -1;
|
|
140
|
-
const m = p(`${(
|
|
141
|
-
return (v =
|
|
142
|
-
for (const
|
|
143
|
-
!isNaN(g[
|
|
144
|
-
const I = p(`${g.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"),
|
|
141
|
+
const m = p(`${(y = (w = c.data) == null ? void 0 : w[0]) == null ? void 0 : y.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
142
|
+
return (v = c.data) == null || v.forEach((g) => {
|
|
143
|
+
for (const S in g)
|
|
144
|
+
!isNaN(g[S]) && Number(g[S]) !== 1 / 0 && (g[S] = Number(g[S]));
|
|
145
|
+
const I = p(`${g.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), N = g.eta ? p(`${g.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00") : void 0, l = g.status, { labelCn: E, labelEn: _ } = this.parseStatus(l), R = {
|
|
145
146
|
mmsi: g.mmsi,
|
|
146
147
|
imo: o == null ? void 0 : o.imo,
|
|
147
148
|
lat: g.lat,
|
|
@@ -151,16 +152,16 @@ class B extends V {
|
|
|
151
152
|
hdg: g.hdg,
|
|
152
153
|
draught: g.draught,
|
|
153
154
|
status: l,
|
|
154
|
-
eta:
|
|
155
|
+
eta: N == null ? void 0 : N.unix(),
|
|
155
156
|
destination: g.dest,
|
|
156
157
|
positionTime: I.unix(),
|
|
157
|
-
labelCn:
|
|
158
|
+
labelCn: E,
|
|
158
159
|
labelEn: _,
|
|
159
160
|
method: "trajectory",
|
|
160
161
|
vendor: "myVessel",
|
|
161
162
|
utc: I.utc().format()
|
|
162
|
-
},
|
|
163
|
-
|
|
163
|
+
}, H = Math.floor(I.diff(m, "minute", !0) / (s || 1));
|
|
164
|
+
H !== f && (f = H, t.push(R));
|
|
164
165
|
}), t;
|
|
165
166
|
}
|
|
166
167
|
}
|
|
@@ -177,14 +178,14 @@ class U extends V {
|
|
|
177
178
|
usertoken: this.token
|
|
178
179
|
}
|
|
179
180
|
}, s = await Y.post(a, o).json();
|
|
180
|
-
|
|
181
|
+
j.info("[%s] fetch realtime position from: %s - %j", n.requestId, a, o);
|
|
181
182
|
const t = s == null ? void 0 : s.list;
|
|
182
183
|
if (!t)
|
|
183
|
-
return
|
|
184
|
+
return j.warn("[%s] fetch realtime position failed: %j", n.requestId, a, s), s;
|
|
184
185
|
for (const m in t)
|
|
185
186
|
!isNaN(t[m]) && Number(t[m]) !== 1 / 0 && (t[m] = Number(t[m]));
|
|
186
187
|
t.status = t.sp > 3 ? 0 : 1;
|
|
187
|
-
const r = t.status, { labelCn: i, labelEn:
|
|
188
|
+
const r = t.status, { labelCn: i, labelEn: h } = this.parseStatus(r), c = p(`${t.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
188
189
|
return {
|
|
189
190
|
mmsi: t.m,
|
|
190
191
|
name: t.n,
|
|
@@ -201,11 +202,11 @@ class U extends V {
|
|
|
201
202
|
rot: isNaN(t.rot) ? 0 : t.rot,
|
|
202
203
|
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(t.eta) ? p(`${t.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00").unix() : void 0,
|
|
203
204
|
destination: t.destination,
|
|
204
|
-
positionTime:
|
|
205
|
-
utc:
|
|
205
|
+
positionTime: c.unix(),
|
|
206
|
+
utc: c.utc().format(),
|
|
206
207
|
status: r,
|
|
207
208
|
labelCn: i,
|
|
208
|
-
labelEn:
|
|
209
|
+
labelEn: h,
|
|
209
210
|
method: "position",
|
|
210
211
|
vendor: "hifleet"
|
|
211
212
|
};
|
|
@@ -223,7 +224,7 @@ class U extends V {
|
|
|
223
224
|
}
|
|
224
225
|
};
|
|
225
226
|
let s = await Y.post(a, o).json();
|
|
226
|
-
|
|
227
|
+
j.info("[%s] fetch vessel props from: %s - %j", n.requestId, a, o), s instanceof Array && (s = s[0]);
|
|
227
228
|
for (const r in s)
|
|
228
229
|
!isNaN(s[r]) && Number(s[r]) !== 1 / 0 && (s[r] = Number(s[r]));
|
|
229
230
|
const t = {
|
|
@@ -235,37 +236,37 @@ class U extends V {
|
|
|
235
236
|
breadth: s.b,
|
|
236
237
|
draught: s.dr
|
|
237
238
|
};
|
|
238
|
-
return a = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", s = await Y.post(a, o).json(),
|
|
239
|
+
return a = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", s = await Y.post(a, o).json(), j.info("[%s] fetch vessel dead weight from: %s - %j", n.requestId, a, o), s instanceof Array && (s = s[0]), s && (t.deadweight = Number(s.dwt)), t;
|
|
239
240
|
}
|
|
240
241
|
async trajectory(e, n, a, o, s = !0, t = {}) {
|
|
241
|
-
var g, I,
|
|
242
|
+
var g, I, N;
|
|
242
243
|
const r = await this.realTimePosition(e, t);
|
|
243
244
|
let i = p(n);
|
|
244
|
-
const
|
|
245
|
+
const h = p(a), c = p();
|
|
245
246
|
if (s) {
|
|
246
|
-
let l =
|
|
247
|
-
l < 0 ? i =
|
|
247
|
+
let l = h.diff(i, "d", !0);
|
|
248
|
+
l < 0 ? i = h.clone().subtract(40, "d") : l < 30 ? i.subtract(10, "d") : l < 60 ? i.subtract(5, "d") : i = h.clone().subtract(80, "d"), l = c.diff(h, "d", !0), h.add(l > 10 ? 240 : l * 24, "h");
|
|
248
249
|
}
|
|
249
250
|
const f = {
|
|
250
251
|
searchParams: {
|
|
251
|
-
endtime:
|
|
252
|
+
endtime: h.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
|
|
252
253
|
starttime: i.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
|
|
253
254
|
mmsi: e,
|
|
254
255
|
usertoken: this.token
|
|
255
256
|
}
|
|
256
|
-
}, m = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",
|
|
257
|
-
|
|
257
|
+
}, m = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", d = await Y.get(m, f).json();
|
|
258
|
+
j.info("[%s] fetch trajectory from: %s - %j", t.requestId, m, f);
|
|
258
259
|
let b;
|
|
259
|
-
|
|
260
|
+
d && (b = ((I = (g = d.ships) == null ? void 0 : g.offors) == null ? void 0 : I.ship) || [], b.length || j.warn("[%s] fetch trajectory failed: %j", t.requestId, d));
|
|
260
261
|
const w = [];
|
|
261
|
-
let
|
|
262
|
-
const v = p(`${(
|
|
262
|
+
let y = -1;
|
|
263
|
+
const v = p(`${(N = b == null ? void 0 : b[0]) == null ? void 0 : N.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
263
264
|
for (const l of b) {
|
|
264
265
|
for (const x in l)
|
|
265
266
|
!isNaN(l[x]) && Number(l[x]) !== 1 / 0 && (l[x] = Number(l[x]));
|
|
266
|
-
const
|
|
267
|
+
const E = p(`${l.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
267
268
|
l.status = l.sp > 4 ? 0 : 1;
|
|
268
|
-
const { labelEn: _, labelCn: R } = this.parseStatus(l.status),
|
|
269
|
+
const { labelEn: _, labelCn: R } = this.parseStatus(l.status), H = {
|
|
269
270
|
mmsi: l.m,
|
|
270
271
|
name: l.n,
|
|
271
272
|
imo: r == null ? void 0 : r.imo,
|
|
@@ -275,15 +276,15 @@ class U extends V {
|
|
|
275
276
|
sog: l.sp,
|
|
276
277
|
cog: l.co,
|
|
277
278
|
hdg: l.hdg,
|
|
278
|
-
positionTime:
|
|
279
|
-
utc:
|
|
279
|
+
positionTime: E.unix(),
|
|
280
|
+
utc: E.utc().format(),
|
|
280
281
|
status: l.status,
|
|
281
282
|
labelCn: R,
|
|
282
283
|
labelEn: _,
|
|
283
284
|
method: "trajectory",
|
|
284
285
|
vendor: "hifleet"
|
|
285
|
-
},
|
|
286
|
-
|
|
286
|
+
}, S = Math.floor(E.diff(v, "minute", !0) / (o || 1));
|
|
287
|
+
S !== y && (y = S, w.push(H));
|
|
287
288
|
}
|
|
288
289
|
return w;
|
|
289
290
|
}
|
|
@@ -302,12 +303,12 @@ class J extends V {
|
|
|
302
303
|
enc: 1
|
|
303
304
|
}
|
|
304
305
|
}, o = "https://api.shipxy.com/apicall/GetSingleShip", s = await Y.get(o, a).json();
|
|
305
|
-
if (
|
|
306
|
+
if (j.info("[%s] fetch realtime position from: %s - %j", n.requestId, o, a), (s == null ? void 0 : s.status) !== 0)
|
|
306
307
|
return s;
|
|
307
308
|
const t = s.data[0];
|
|
308
309
|
for (const f in t)
|
|
309
310
|
!isNaN(t[f]) && Number(t[f]) !== 1 / 0 && (t[f] = Number(t[f]));
|
|
310
|
-
const { labelCn: r, labelEn: i } = await this.parseStatus(t.navistat),
|
|
311
|
+
const { labelCn: r, labelEn: i } = await this.parseStatus(t.navistat), h = p.unix(t.lasttime);
|
|
311
312
|
return {
|
|
312
313
|
mmsi: t.ShipID,
|
|
313
314
|
name: t.name,
|
|
@@ -323,7 +324,7 @@ class J extends V {
|
|
|
323
324
|
hdg: Math.round(t.hdg / 100 * 100) / 100,
|
|
324
325
|
rot: Math.round(t.rot / 100 * 100) / 100,
|
|
325
326
|
positionTime: t.lasttime,
|
|
326
|
-
utc:
|
|
327
|
+
utc: h.utc().format(),
|
|
327
328
|
status: t.navistat,
|
|
328
329
|
labelEn: i,
|
|
329
330
|
labelCn: r,
|
|
@@ -333,22 +334,22 @@ class J extends V {
|
|
|
333
334
|
}
|
|
334
335
|
async trajectory(e, n, a, o, s = !0, t = {}) {
|
|
335
336
|
var v;
|
|
336
|
-
const r = await this.realTimePosition(e, t), i = p(n),
|
|
337
|
+
const r = await this.realTimePosition(e, t), i = p(n), h = p(a), c = "https://api.shipxy.com/apicall/GetShipTrack", f = {
|
|
337
338
|
searchParams: {
|
|
338
339
|
id: e,
|
|
339
340
|
k: this.token,
|
|
340
341
|
enc: 1,
|
|
341
342
|
cut: 0,
|
|
342
343
|
btm: i.unix(),
|
|
343
|
-
etm:
|
|
344
|
+
etm: h.unix()
|
|
344
345
|
}
|
|
345
|
-
}, m = await Y.get(
|
|
346
|
-
if (
|
|
346
|
+
}, m = await Y.get(c, f).json();
|
|
347
|
+
if (j.info("[%s] fetch trajectory from: %s - %j", t.requestId, c, f), (m == null ? void 0 : m.status) !== 0)
|
|
347
348
|
return m;
|
|
348
|
-
const
|
|
349
|
-
let
|
|
350
|
-
for (const g of
|
|
351
|
-
const I = p.unix(g.utc),
|
|
349
|
+
const d = m == null ? void 0 : m.points, b = [], w = p.unix((v = d[0]) == null ? void 0 : v.utc);
|
|
350
|
+
let y = -1;
|
|
351
|
+
for (const g of d) {
|
|
352
|
+
const I = p.unix(g.utc), N = {
|
|
352
353
|
imo: r == null ? void 0 : r.imo,
|
|
353
354
|
mmsi: e,
|
|
354
355
|
sog: Math.round(g.sog * 3600 / 1e3 / 1852 * 100) / 100,
|
|
@@ -360,7 +361,7 @@ class J extends V {
|
|
|
360
361
|
method: "trajectory",
|
|
361
362
|
vendor: "shipxy"
|
|
362
363
|
}, l = Math.floor(I.diff(w, "minute", !0) / (o || 1));
|
|
363
|
-
l !==
|
|
364
|
+
l !== y && (y = l, b.push(N));
|
|
364
365
|
}
|
|
365
366
|
return b;
|
|
366
367
|
}
|
|
@@ -380,7 +381,7 @@ class Q extends V {
|
|
|
380
381
|
mmsiList: e
|
|
381
382
|
}
|
|
382
383
|
}, o = "https://api3.myships.com/sp/ships/getShipIdByMMSI", s = await Y.post(o, a).json();
|
|
383
|
-
return
|
|
384
|
+
return j.info("[%s] fetch ship id from: %s - %j", n.requestId, o, a), s.code !== "0" ? s : s.data[0].shipId;
|
|
384
385
|
}
|
|
385
386
|
async getShipInfo(e, n = {}) {
|
|
386
387
|
const a = {
|
|
@@ -391,11 +392,11 @@ class Q extends V {
|
|
|
391
392
|
shipId: e
|
|
392
393
|
}
|
|
393
394
|
}, o = "https://api3.myships.com/sp/ships/aissta", s = await Y.post(o, a).json();
|
|
394
|
-
if (
|
|
395
|
+
if (j.info("[%s] fetch ship info from: %s - %j", n.requestId, o, a), s.code !== "0")
|
|
395
396
|
return s;
|
|
396
397
|
const t = s.data;
|
|
397
398
|
let r = t.imo;
|
|
398
|
-
return e === "407170" && (r = "9198379",
|
|
399
|
+
return e === "407170" && (r = "9198379", j.warn("[%s] ship(%s) imo error: %s, should be %s", n.requestId, e, t.imo, r)), {
|
|
399
400
|
mmsi: t.mmsi,
|
|
400
401
|
name: t.shipnameEn,
|
|
401
402
|
imo: r,
|
|
@@ -414,11 +415,11 @@ class Q extends V {
|
|
|
414
415
|
shipId: a
|
|
415
416
|
}
|
|
416
417
|
}, t = "https://api3.myships.com/sp/ships/position/latest", r = await Y.post(t, s).json();
|
|
417
|
-
|
|
418
|
+
j.info("[%s] fetch realtime position from: %s - %j", n.requestId, t, s);
|
|
418
419
|
const i = r.data[0];
|
|
419
|
-
for (const
|
|
420
|
-
!isNaN(i[
|
|
421
|
-
const { labelCn:
|
|
420
|
+
for (const d in i)
|
|
421
|
+
!isNaN(i[d]) && Number(i[d]) !== 1 / 0 && (i[d] = Number(i[d]));
|
|
422
|
+
const { labelCn: h, labelEn: c } = await this.parseStatus(i.aisNavStatus), f = p.unix(i.posTime);
|
|
422
423
|
return {
|
|
423
424
|
...o,
|
|
424
425
|
mmsi: e,
|
|
@@ -431,21 +432,21 @@ class Q extends V {
|
|
|
431
432
|
positionTime: i.posTime,
|
|
432
433
|
utc: f.utc().format(),
|
|
433
434
|
status: i.aisNavStatus,
|
|
434
|
-
labelEn:
|
|
435
|
-
labelCn:
|
|
435
|
+
labelEn: c,
|
|
436
|
+
labelCn: h,
|
|
436
437
|
method: "position",
|
|
437
438
|
vendor: "myship"
|
|
438
439
|
};
|
|
439
440
|
}
|
|
440
441
|
async trajectory(e, n, a, o, s = !0, t = {}) {
|
|
441
|
-
const r = p(n), i = p(a),
|
|
442
|
+
const r = p(n), i = p(a), h = await this.getShipId(e), c = await this.getShipInfo(h), f = [];
|
|
442
443
|
for (; i.diff(r, "day", !0) > 30; )
|
|
443
|
-
await this.trajectoryIn30Day(
|
|
444
|
-
return await this.trajectoryIn30Day(
|
|
444
|
+
await this.trajectoryIn30Day(h, r.unix(), r.add(30, "day").unix(), c, e, o, f);
|
|
445
|
+
return await this.trajectoryIn30Day(h, r.unix(), i.unix(), c, e, o, f), f;
|
|
445
446
|
}
|
|
446
447
|
async trajectoryIn30Day(e, n, a, o, s, t, r, i = {}) {
|
|
447
448
|
var w;
|
|
448
|
-
const
|
|
449
|
+
const h = {
|
|
449
450
|
headers: {
|
|
450
451
|
appKey: this.token
|
|
451
452
|
},
|
|
@@ -454,36 +455,37 @@ class Q extends V {
|
|
|
454
455
|
startTime: n,
|
|
455
456
|
endTime: a
|
|
456
457
|
}
|
|
457
|
-
},
|
|
458
|
-
if (
|
|
459
|
-
return
|
|
458
|
+
}, c = "https://api3.myships.com/sp/ships/position/history", f = await Y.post(c, h).json();
|
|
459
|
+
if (j.info("[%s] fetch trajectory from: %s - %j", i.requestId, c, h), f.code !== "0")
|
|
460
|
+
return j.warn("[%s] invoke myship trajectory failed: %j", i.requestId, f), f;
|
|
460
461
|
const m = f.data;
|
|
461
|
-
for (const
|
|
462
|
-
!isNaN(m[
|
|
463
|
-
const
|
|
462
|
+
for (const y in m)
|
|
463
|
+
!isNaN(m[y]) && Number(m[y]) !== 1 / 0 && (m[y] = Number(m[y]));
|
|
464
|
+
const d = p.unix((w = m[0]) == null ? void 0 : w.posTime);
|
|
464
465
|
let b = -1;
|
|
465
|
-
for (const
|
|
466
|
-
const v = p.unix(
|
|
466
|
+
for (const y of m) {
|
|
467
|
+
const v = p.unix(y.posTime), g = {
|
|
467
468
|
imo: o == null ? void 0 : o.imo,
|
|
468
469
|
mmsi: s,
|
|
469
|
-
lat: Math.round(
|
|
470
|
-
lng: Math.round(
|
|
471
|
-
sog: Math.round(
|
|
472
|
-
cog: Math.round(
|
|
473
|
-
hdg: Math.round(
|
|
474
|
-
rot: Math.round(
|
|
470
|
+
lat: Math.round(y.lat / 1e4 / 60 * 1e5) / 1e5,
|
|
471
|
+
lng: Math.round(y.lon / 1e4 / 60 * 1e5) / 1e5,
|
|
472
|
+
sog: Math.round(y.sog / 10 * 100) / 100,
|
|
473
|
+
cog: Math.round(y.cog / 10 * 100) / 100,
|
|
474
|
+
hdg: Math.round(y.heading * 100) / 100,
|
|
475
|
+
rot: Math.round(y.rot * 100) / 100,
|
|
475
476
|
positionTime: v.unix(),
|
|
476
477
|
utc: v.utc().format(),
|
|
477
478
|
method: "trajectory",
|
|
478
479
|
vendor: "myship"
|
|
479
|
-
}, I = Math.floor(v.diff(
|
|
480
|
+
}, I = Math.floor(v.diff(d, "minute", !0) / (t || 1));
|
|
480
481
|
I !== b && (b = I, r.push(g));
|
|
481
482
|
}
|
|
482
483
|
return r;
|
|
483
484
|
}
|
|
484
485
|
}
|
|
485
|
-
const
|
|
486
|
-
|
|
486
|
+
const P = W.getLogger();
|
|
487
|
+
P.level = "info";
|
|
488
|
+
var K = /* @__PURE__ */ ((M) => (M.NOTICE = "NOTICE", M.WARN = "WARN", M.HEAVY = "HEAVY", M.SEVERE = "SEVERE", M.ERROR = "ERROR", M.FATAL = "FATAL", M))(K || {});
|
|
487
489
|
class L {
|
|
488
490
|
/**
|
|
489
491
|
* 解析告警规则, 多规则场景
|
|
@@ -493,21 +495,21 @@ class L {
|
|
|
493
495
|
*
|
|
494
496
|
* @param options
|
|
495
497
|
*/
|
|
496
|
-
parsePrinciple(
|
|
498
|
+
parsePrinciple(u, e = {}) {
|
|
497
499
|
var t, r, i;
|
|
498
|
-
|
|
499
|
-
const n = new RegExp("(?<=\\[)(.+)(?=\\])", "g"), a =
|
|
500
|
+
P.info("[%s] parse rule: %s", e.requestId, u);
|
|
501
|
+
const n = new RegExp("(?<=\\[)(.+)(?=\\])", "g"), a = u.match(n) ? (t = u.match(n)) == null ? void 0 : t[0] : void 0, o = a == null ? void 0 : a.split(";");
|
|
500
502
|
if (!o)
|
|
501
503
|
return;
|
|
502
504
|
const s = {};
|
|
503
|
-
for (let
|
|
504
|
-
const
|
|
505
|
-
if (
|
|
505
|
+
for (let h = 0; h < (o == null ? void 0 : o.length); h++) {
|
|
506
|
+
const c = (i = (r = o[h].match(n)) == null ? void 0 : r[0]) == null ? void 0 : i.split("],");
|
|
507
|
+
if (h === 0 && !c)
|
|
506
508
|
s.scope = o[0];
|
|
507
|
-
else if (
|
|
508
|
-
for (let f = 0, m =
|
|
509
|
-
const
|
|
510
|
-
|
|
509
|
+
else if (c)
|
|
510
|
+
for (let f = 0, m = c.length; f < m; f++) {
|
|
511
|
+
const d = this.parseRule(c[f]);
|
|
512
|
+
d && (s[d.level] ? d.key ? s[d.level][d == null ? void 0 : d.key] = d : s[d.level] = d : d.key ? s[d.level] = { [d == null ? void 0 : d.key]: d } : s[d.level] = d);
|
|
511
513
|
}
|
|
512
514
|
}
|
|
513
515
|
return s;
|
|
@@ -518,10 +520,10 @@ class L {
|
|
|
518
520
|
* @param rule
|
|
519
521
|
* @param options
|
|
520
522
|
*/
|
|
521
|
-
parseRule(
|
|
523
|
+
parseRule(u, e = {}) {
|
|
522
524
|
var s;
|
|
523
|
-
|
|
524
|
-
const n = new RegExp("(?<=\\[)(.+?)(?=\\])", "g"), a = (s =
|
|
525
|
+
P.info("[%s] parse rule: %s", e.requestId, u), u = u.startsWith("[") ? u : `[${u}`, u = u.endsWith("]") ? u : `${u}]`;
|
|
526
|
+
const n = new RegExp("(?<=\\[)(.+?)(?=\\])", "g"), a = (s = u == null ? void 0 : u.match(n)) == null ? void 0 : s[0], o = a == null ? void 0 : a.split(",");
|
|
525
527
|
if (o)
|
|
526
528
|
return { operator: o[0], number: Number(o[1]), level: o[2], time: Number(o[3]), key: o[4] };
|
|
527
529
|
}
|
|
@@ -531,15 +533,15 @@ class L {
|
|
|
531
533
|
* @param principle 告警规则
|
|
532
534
|
* @param options
|
|
533
535
|
*/
|
|
534
|
-
checkWeather(
|
|
535
|
-
var
|
|
536
|
+
checkWeather(u, e, n = {}) {
|
|
537
|
+
var d, b, w, y, v, g, I, N, l, E, _, R, H, S, x;
|
|
536
538
|
let a = 0, o = 0, s = 0, t = 0;
|
|
537
|
-
const r = ((b = (
|
|
538
|
-
for (let
|
|
539
|
-
const
|
|
540
|
-
t =
|
|
539
|
+
const r = ((b = (d = e == null ? void 0 : e.SEVERE) == null ? void 0 : d.sigWave) == null ? void 0 : b.number) * 1.6, i = (y = (w = e == null ? void 0 : e.SEVERE) == null ? void 0 : w.sigWave) == null ? void 0 : y.number, h = (g = (v = e == null ? void 0 : e.HEAVY) == null ? void 0 : v.sigWave) == null ? void 0 : g.number, c = ((N = (I = e == null ? void 0 : e.SEVERE) == null ? void 0 : I.wind) == null ? void 0 : N.number) + 2, f = (E = (l = e == null ? void 0 : e.SEVERE) == null ? void 0 : l.wind) == null ? void 0 : E.number, m = (R = (_ = e == null ? void 0 : e.HEAVY) == null ? void 0 : _.wind) == null ? void 0 : R.number;
|
|
540
|
+
for (let $ = 1; $ < (u == null ? void 0 : u.length); $++) {
|
|
541
|
+
const k = u[$], T = (S = (H = k == null ? void 0 : k.meteo) == null ? void 0 : H.wave) == null ? void 0 : S.sig, D = (x = k == null ? void 0 : k.meteo) == null ? void 0 : x.wind, A = p(k.eta).diff(p(u[$ - 1].eta), "hour", !0);
|
|
542
|
+
t = A > t ? A : t, P.info("[%s] check sig.wave: %j", n.requestId, { ...T, dgThd4Wv: r, svThd4Wv: i, hvThd4Wv: h }), (T == null ? void 0 : T.height) >= r ? k.isDangerous = !0 : (T == null ? void 0 : T.height) >= i ? k.isSevere = !0 : (T == null ? void 0 : T.height) >= h && (k.isHeavy = !0), P.info("[%s] check wind: %j", n.requestId, { ...D, dgThd4Wd: c, svThd4Wd: f, hvThd4Wd: m }), (D == null ? void 0 : D.scale) >= c ? (k.isDangerous = !0, delete k.isSevere, delete k.isHeavy) : (D == null ? void 0 : D.scale) > f ? (k.isDangerous || (k.isSevere = !0), delete k.isHeavy) : (D == null ? void 0 : D.scale) === m && !k.isDangerous && !k.isSevere && (k.isHeavy = !0), a += k.isDangerous ? A : 0, o += k.isSevere ? A : 0, s += k.isHeavy ? A : 0;
|
|
541
543
|
}
|
|
542
|
-
return a = Math.round(a * 100) / 100, o = Math.round(o * 100) / 100, s = Math.round(s * 100) / 100, t = Math.round(t), { sample:
|
|
544
|
+
return a = Math.round(a * 100) / 100, o = Math.round(o * 100) / 100, s = Math.round(s * 100) / 100, t = Math.round(t), { sample: u, dangerous: a, severe: o, heavy: s, step: t < 3 ? 3 : t, wind: { dgThd4Wd: c, svThd4Wd: f, hvThd4Wd: m }, sig: { dgThd4Wv: r, svThd4Wv: i, hvThd4Wv: h } };
|
|
543
545
|
}
|
|
544
546
|
}
|
|
545
547
|
const X = new L();
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(b,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("got"),require("log4js"),require("moment")):typeof define=="function"&&define.amd?define(["exports","got","log4js","moment"],y):(b=typeof globalThis<"u"?globalThis:b||self,y(b["idm-plugin-rabbitmq"]={},b.got,b.log4js,b.moment))})(this,function(b,y,q,p){"use strict";var Q=Object.defineProperty;var X=(b,y,q)=>y in b?Q(b,y,{enumerable:!0,configurable:!0,writable:!0,value:q}):b[y]=q;var A=(b,y,q)=>(X(b,typeof y!="symbol"?y+"":y,q),q);function z(I){const f=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(I){for(const e in I)if(e!=="default"){const a=Object.getOwnPropertyDescriptor(I,e);Object.defineProperty(f,e,a.get?a:{enumerable:!0,get:()=>I[e]})}}return f.default=I,Object.freeze(f)}const C=z(q),M=C.getLogger();class O{parseStatus(f){let e,a;switch(f){case 0:e="在航(主机推动)",a="The engine is in use";break;case 1:e="锚泊",a="Anchored";break;case 2:e="失控",a="Not operated";break;case 3:e="操纵受限",a="Limited airworthiness";break;case 4:e="吃水受限",a="Limited by ship's draft";break;case 5:e="靠泊",a="Mooring";break;case 6:e="搁浅",a="Stranded";break;case 7:e="捕捞作业",a="Engaged in fishing";break;case 8:e="靠帆船提供动力",a="Sailing";break;default:e="未定义",a="Undefined"}return{labelCn:e,labelEn:a}}}class F extends O{constructor(e,a){super();A(this,"clientId");A(this,"clientSecret");A(this,"token");this.clientId=e,this.clientSecret=a}async authToken(e={}){const a="https://svc.data.myvessel.cn/ada/oauth/token",n={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},o=await y.post(a,n).json();M.info("[%s] fetch access token from: %s - %j",e.requestId,a,o),o.error||(this.token={accessToken:o.access_token,tokenType:o.token_type,expiresIn:o.expires_in,scope:o.scope,jti:o.jti,issuedAt:p().utc().format()})}async realTimePosition(e,a={}){var d,c,l;(!this.token||p().diff(p(this.token.issuedAt),"seconds")>((d=this.token)==null?void 0:d.expiresIn)-300)&&await this.authToken(a);const n="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",o={headers:{Authorization:`${(c=this.token)==null?void 0:c.tokenType} ${(l=this.token)==null?void 0:l.accessToken}`},searchParams:{mmsi:e}};M.info("[%s] fetch realtime position from: %s - %j",a.requestId,n,o);const s=await y.get(n,o).json();if(s.code)return M.warn("[%s] fetch realtime position failed: %j",a.requestId,n,{message:s.message,status:s.status,code:s.code}),s;const t=s.data;for(const h in t)!isNaN(t[h])&&Number(t[h])!==1/0&&(t[h]=Number(t[h]));const r=p(`${t.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:t.mmsi,name:t.vesselName,imo:t.imo,callSign:t.callsign,lat:t.lat,lng:t.lon,length:t.length,width:t.width,draught:t.currDraught,sog:t.sog,cog:t.cog,hdg:t.hdg,rot:t.rot,eta:t.eta,destination:t.dest,positionTime:r.unix(),status:t.status,labelCn:t.statusNameCn,labelEn:t.statusNameEn,method:"position",vendor:"myVessel",utc:r.utc().format()}}async trajectory(e,a,n,o,s=!0,t={}){(!this.token||p().diff(p(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(t);const r=await this.realTimePosition(e,t),i=p(a),d=p(n),c=[];for(;d.diff(i,"day",!0)>30;)await this.trajectoryIn30Day(e,i,i.clone().add(30,"day"),r,o,c,t),i.add(30,"day");return await this.trajectoryIn30Day(e,i,d,r,o,c,t),c}async trajectoryIn30Day(e,a,n,o,s,t,r={}){var u,v,Y,j,S;const i="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",d={headers:{Authorization:`${(u=this.token)==null?void 0:u.tokenType} ${(v=this.token)==null?void 0:v.accessToken}`},json:{mmsi:e,startTime:a.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};M.info("[%s] fetch trajectory from: %s - %j",r.requestId,i,d);const c=await y.post(i,d).json();if(c.code)return M.warn("[%s] fetch trajectory failed: %j",r.requestId,i,{message:c.message,status:c.status,code:c.code}),c;let l=-1;const h=p(`${(j=(Y=c.data)==null?void 0:Y[0])==null?void 0:j.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(S=c.data)==null||S.forEach(g=>{for(const T in g)!isNaN(g[T])&&Number(g[T])!==1/0&&(g[T]=Number(g[T]));const w=p(`${g.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),N=g.eta?p(`${g.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,m=g.status,{labelCn:E,labelEn:P}=this.parseStatus(m),R={mmsi:g.mmsi,imo:o==null?void 0:o.imo,lat:g.lat,lng:g.lon,sog:g.sog,cog:g.cog,hdg:g.hdg,draught:g.draught,status:m,eta:N==null?void 0:N.unix(),destination:g.dest,positionTime:w.unix(),labelCn:E,labelEn:P,method:"trajectory",vendor:"myVessel",utc:w.utc().format()},x=Math.floor(w.diff(h,"minute",!0)/(s||1));x!==l&&(l=x,t.push(R))}),t}}class G extends O{constructor(e){super();A(this,"token");this.token=e}async realTimePosition(e,a={}){const n="https://api.hifleet.com/position/position/get/token",o={searchParams:{mmsi:e,usertoken:this.token}},s=await y.post(n,o).json();M.info("[%s] fetch realtime position from: %s - %j",a.requestId,n,o);const t=s==null?void 0:s.list;if(!t)return M.warn("[%s] fetch realtime position failed: %j",a.requestId,n,s),s;for(const h in t)!isNaN(t[h])&&Number(t[h])!==1/0&&(t[h]=Number(t[h]));t.status=t.sp>3?0:1;const r=t.status,{labelCn:i,labelEn:d}=this.parseStatus(r),c=p(`${t.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:t.m,name:t.n,imo:t.imonumber,callSign:t.callsign,lat:Math.round(t.la/60*1e5)/1e5,lng:Math.round(t.lo/60*1e5)/1e5,length:t.l,width:t.w,draught:t.draught,sog:t.sp,cog:t.co,hdg:t.h,rot:isNaN(t.rot)?0:t.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(t.eta)?p(`${t.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").unix():void 0,destination:t.destination,positionTime:c.unix(),utc:c.utc().format(),status:r,labelCn:i,labelEn:d,method:"position",vendor:"hifleet"}}async search(e,a={}){let n="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const o={searchParams:{keyword:e},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let s=await y.post(n,o).json();M.info("[%s] fetch vessel props from: %s - %j",a.requestId,n,o),s instanceof Array&&(s=s[0]);for(const r in s)!isNaN(s[r])&&Number(s[r])!==1/0&&(s[r]=Number(s[r]));const t={mmsi:s.m,name:s.n,imo:s.i,callSign:s.c,length:s.l,breadth:s.b,draught:s.dr};return n="https://www.hifleet.com/hifleetapi/sameShipSearch.do",s=await y.post(n,o).json(),M.info("[%s] fetch vessel dead weight from: %s - %j",a.requestId,n,o),s instanceof Array&&(s=s[0]),s&&(t.deadweight=Number(s.dwt)),t}async trajectory(e,a,n,o,s=!0,t={}){var g,w,N;const r=await this.realTimePosition(e,t);let i=p(a);const d=p(n),c=p();if(s){let m=d.diff(i,"d",!0);m<0?i=d.clone().subtract(40,"d"):m<30?i.subtract(10,"d"):m<60?i.subtract(5,"d"):i=d.clone().subtract(80,"d"),m=c.diff(d,"d",!0),d.add(m>10?240:m*24,"h")}const l={searchParams:{endtime:d.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),starttime:i.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),mmsi:e,usertoken:this.token}},h="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",u=await y.get(h,l).json();M.info("[%s] fetch trajectory from: %s - %j",t.requestId,h,l);let v;u&&(v=((w=(g=u.ships)==null?void 0:g.offors)==null?void 0:w.ship)||[],v.length||M.warn("[%s] fetch trajectory failed: %j",t.requestId,u));const Y=[];let j=-1;const S=p(`${(N=v==null?void 0:v[0])==null?void 0:N.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const m of v){for(const _ in m)!isNaN(m[_])&&Number(m[_])!==1/0&&(m[_]=Number(m[_]));const E=p(`${m.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");m.status=m.sp>4?0:1;const{labelEn:P,labelCn:R}=this.parseStatus(m.status),x={mmsi:m.m,name:m.n,imo:r==null?void 0:r.imo,lat:m.la,lng:m.lo,draught:m.draught,sog:m.sp,cog:m.co,hdg:m.hdg,positionTime:E.unix(),utc:E.utc().format(),status:m.status,labelCn:R,labelEn:P,method:"trajectory",vendor:"hifleet"},T=Math.floor(E.diff(S,"minute",!0)/(o||1));T!==j&&(j=T,Y.push(x))}return Y}}class B extends O{constructor(e){super();A(this,"token");this.token=e}async realTimePosition(e,a={}){const n={searchParams:{id:e,k:this.token,enc:1}},o="https://api.shipxy.com/apicall/GetSingleShip",s=await y.get(o,n).json();if(M.info("[%s] fetch realtime position from: %s - %j",a.requestId,o,n),(s==null?void 0:s.status)!==0)return s;const t=s.data[0];for(const l in t)!isNaN(t[l])&&Number(t[l])!==1/0&&(t[l]=Number(t[l]));const{labelCn:r,labelEn:i}=await this.parseStatus(t.navistat),d=p.unix(t.lasttime);return{mmsi:t.ShipID,name:t.name,imo:t.imo,callSign:t.callsign,lat:Math.round(t.lat/1e6*1e5)/1e5,lng:Math.round(t.lon/1e6*1e5)/1e5,length:Math.round(t.length/10*100)/100,width:Math.round(t.width/10*100)/100,draught:Math.round(t.draught/1e3*100)/100,sog:Math.round(t.sog*3600/1e3/1852*100)/100,cog:Math.round(t.cog/100*100)/100,hdg:Math.round(t.hdg/100*100)/100,rot:Math.round(t.rot/100*100)/100,positionTime:t.lasttime,utc:d.utc().format(),status:t.navistat,labelEn:i,labelCn:r,method:"position",vendor:"shipxy"}}async trajectory(e,a,n,o,s=!0,t={}){var S;const r=await this.realTimePosition(e,t),i=p(a),d=p(n),c="https://api.shipxy.com/apicall/GetShipTrack",l={searchParams:{id:e,k:this.token,enc:1,cut:0,btm:i.unix(),etm:d.unix()}},h=await y.get(c,l).json();if(M.info("[%s] fetch trajectory from: %s - %j",t.requestId,c,l),(h==null?void 0:h.status)!==0)return h;const u=h==null?void 0:h.points,v=[],Y=p.unix((S=u[0])==null?void 0:S.utc);let j=-1;for(const g of u){const w=p.unix(g.utc),N={imo:r==null?void 0:r.imo,mmsi:e,sog:Math.round(g.sog*3600/1e3/1852*100)/100,cog:Math.round(g.cog/100*100)/100,lat:Math.round(g.lat/1e6*1e5)/1e5,lng:Math.round(g.lon/1e6*1e5)/1e5,positionTime:w.unix(),utc:w.utc().format(),method:"trajectory",vendor:"shipxy"},m=Math.floor(w.diff(Y,"minute",!0)/(o||1));m!==j&&(j=m,v.push(N))}return v}}class U extends O{constructor(e){super();A(this,"token");this.token=e}async getShipId(e,a={}){const n={headers:{appKey:this.token},json:{mmsiList:e}},o="https://api3.myships.com/sp/ships/getShipIdByMMSI",s=await y.post(o,n).json();return M.info("[%s] fetch ship id from: %s - %j",a.requestId,o,n),s.code!=="0"?s:s.data[0].shipId}async getShipInfo(e,a={}){const n={headers:{appKey:this.token},json:{shipId:e}},o="https://api3.myships.com/sp/ships/aissta",s=await y.post(o,n).json();if(M.info("[%s] fetch ship info from: %s - %j",a.requestId,o,n),s.code!=="0")return s;const t=s.data;let r=t.imo;return e==="407170"&&(r="9198379",M.warn("[%s] ship(%s) imo error: %s, should be %s",a.requestId,e,t.imo,r)),{mmsi:t.mmsi,name:t.shipnameEn,imo:r,callSign:t.callSign,length:t.length,width:t.breadth,draught:(t.draught||100)/10}}async realTimePosition(e,a={}){const n=await this.getShipId(e,a),o=await this.getShipInfo(n,a),s={headers:{appKey:this.token},json:{shipId:n}},t="https://api3.myships.com/sp/ships/position/latest",r=await y.post(t,s).json();M.info("[%s] fetch realtime position from: %s - %j",a.requestId,t,s);const i=r.data[0];for(const u in i)!isNaN(i[u])&&Number(i[u])!==1/0&&(i[u]=Number(i[u]));const{labelCn:d,labelEn:c}=await this.parseStatus(i.aisNavStatus),l=p.unix(i.posTime);return{...o,mmsi:e,lat:Math.round(i.lat/1e4/60*1e5)/1e5,lng:Math.round(i.lon/1e4/60*1e5)/1e5,sog:Math.round(i.sog/10*100)/100,cog:Math.round(i.cog/10*100)/100,hdg:Math.round(i.heading*100)/100,rot:Math.round(i.rot*100)/100,positionTime:i.posTime,utc:l.utc().format(),status:i.aisNavStatus,labelEn:c,labelCn:d,method:"position",vendor:"myship"}}async trajectory(e,a,n,o,s=!0,t={}){const r=p(a),i=p(n),d=await this.getShipId(e),c=await this.getShipInfo(d),l=[];for(;i.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(d,r.unix(),r.add(30,"day").unix(),c,e,o,l);return await this.trajectoryIn30Day(d,r.unix(),i.unix(),c,e,o,l),l}async trajectoryIn30Day(e,a,n,o,s,t,r,i={}){var Y;const d={headers:{appKey:this.token},json:{shipId:e,startTime:a,endTime:n}},c="https://api3.myships.com/sp/ships/position/history",l=await y.post(c,d).json();if(M.info("[%s] fetch trajectory from: %s - %j",i.requestId,c,d),l.code!=="0")return M.warn("[%s] invoke myship trajectory failed: %j",i.requestId,l),l;const h=l.data;for(const j in h)!isNaN(h[j])&&Number(h[j])!==1/0&&(h[j]=Number(h[j]));const u=p.unix((Y=h[0])==null?void 0:Y.posTime);let v=-1;for(const j of h){const S=p.unix(j.posTime),g={imo:o==null?void 0:o.imo,mmsi:s,lat:Math.round(j.lat/1e4/60*1e5)/1e5,lng:Math.round(j.lon/1e4/60*1e5)/1e5,sog:Math.round(j.sog/10*100)/100,cog:Math.round(j.cog/10*100)/100,hdg:Math.round(j.heading*100)/100,rot:Math.round(j.rot*100)/100,positionTime:S.unix(),utc:S.utc().format(),method:"trajectory",vendor:"myship"},w=Math.floor(S.diff(u,"minute",!0)/(t||1));w!==v&&(v=w,r.push(g))}return r}}const W=C.getLogger();var K=(I=>(I.NOTICE="NOTICE",I.WARN="WARN",I.HEAVY="HEAVY",I.SEVERE="SEVERE",I.ERROR="ERROR",I.FATAL="FATAL",I))(K||{});class L{parsePrinciple(f,e={}){var t,r,i;W.info("[%s] parse rule: %s",e.requestId,f);const a=new RegExp("(?<=\\[)(.+)(?=\\])","g"),n=f.match(a)?(t=f.match(a))==null?void 0:t[0]:void 0,o=n==null?void 0:n.split(";");if(!o)return;const s={};for(let d=0;d<(o==null?void 0:o.length);d++){const c=(i=(r=o[d].match(a))==null?void 0:r[0])==null?void 0:i.split("],");if(d===0&&!c)s.scope=o[0];else if(c)for(let l=0,h=c.length;l<h;l++){const u=this.parseRule(c[l]);u&&(s[u.level]?u.key?s[u.level][u==null?void 0:u.key]=u:s[u.level]=u:u.key?s[u.level]={[u==null?void 0:u.key]:u}:s[u.level]=u)}}return s}parseRule(f,e={}){var s;W.info("[%s] parse rule: %s",e.requestId,f),f=f.startsWith("[")?f:`[${f}`,f=f.endsWith("]")?f:`${f}]`;const a=new RegExp("(?<=\\[)(.+?)(?=\\])","g"),n=(s=f==null?void 0:f.match(a))==null?void 0:s[0],o=n==null?void 0:n.split(",");if(o)return{operator:o[0],number:Number(o[1]),level:o[2],time:Number(o[3]),key:o[4]}}checkWeather(f,e,a={}){var u,v,Y,j,S,g,w,N,m,E,P,R,x,T,_;let n=0,o=0,s=0,t=0;const r=((v=(u=e==null?void 0:e.SEVERE)==null?void 0:u.sigWave)==null?void 0:v.number)*1.6,i=(j=(Y=e==null?void 0:e.SEVERE)==null?void 0:Y.sigWave)==null?void 0:j.number,d=(g=(S=e==null?void 0:e.HEAVY)==null?void 0:S.sigWave)==null?void 0:g.number,c=((N=(w=e==null?void 0:e.SEVERE)==null?void 0:w.wind)==null?void 0:N.number)+2,l=(E=(m=e==null?void 0:e.SEVERE)==null?void 0:m.wind)==null?void 0:E.number,h=(R=(P=e==null?void 0:e.HEAVY)==null?void 0:P.wind)==null?void 0:R.number;for(let V=1;V<(f==null?void 0:f.length);V++){const k=f[V],H=(T=(x=k==null?void 0:k.meteo)==null?void 0:x.wave)==null?void 0:T.sig,D=(_=k==null?void 0:k.meteo)==null?void 0:_.wind,$=p(k.eta).diff(p(f[V-1].eta),"hour",!0);t=$>t?$:t,W.info("[%s] check sig.wave: %j",a.requestId,{...H,dgThd4Wv:r,svThd4Wv:i,hvThd4Wv:d}),(H==null?void 0:H.height)>=r?k.isDangerous=!0:(H==null?void 0:H.height)>=i?k.isSevere=!0:(H==null?void 0:H.height)>=d&&(k.isHeavy=!0),W.info("[%s] check wind: %j",a.requestId,{...D,dgThd4Wd:c,svThd4Wd:l,hvThd4Wd:h}),(D==null?void 0:D.scale)>=c?(k.isDangerous=!0,delete k.isSevere,delete k.isHeavy):(D==null?void 0:D.scale)>l?(k.isDangerous||(k.isSevere=!0),delete k.isHeavy):(D==null?void 0:D.scale)===h&&!k.isDangerous&&!k.isSevere&&(k.isHeavy=!0),n+=k.isDangerous?$:0,o+=k.isSevere?$:0,s+=k.isHeavy?$:0,V===1&&(f[0].isDangerous=k.isDangerous,f[0].isSevere=k.isSevere,f[0].isHeavy=k.isHeavy)}return n=Math.round(n*100)/100,o=Math.round(o*100)/100,s=Math.round(s*100)/100,t=Math.round(t),{sample:f,dangerous:n,severe:o,heavy:s,step:t<3?3:t,wind:{dgThd4Wd:c,svThd4Wd:l,hvThd4Wd:h},sig:{dgThd4Wv:r,svThd4Wv:i,hvThd4Wv:d}}}}const J=new L;b.AISImpl=O,b.AlertHelper=L,b.AlertLevel=K,b.HifleetImpl=G,b.MyShipImpl=U,b.MyVesselImpl=F,b.ShipxyImpl=B,b.alertHelper=J,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(j,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("got"),require("log4js"),require("moment")):typeof define=="function"&&define.amd?define(["exports","got","log4js","moment"],y):(j=typeof globalThis<"u"?globalThis:j||self,y(j["idm-plugin-rabbitmq"]={},j.got,j.log4js,j.moment))})(this,function(j,y,q,p){"use strict";var Q=Object.defineProperty;var X=(j,y,q)=>y in j?Q(j,y,{enumerable:!0,configurable:!0,writable:!0,value:q}):j[y]=q;var A=(j,y,q)=>(X(j,typeof y!="symbol"?y+"":y,q),q);function z(I){const m=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(I){for(const e in I)if(e!=="default"){const a=Object.getOwnPropertyDescriptor(I,e);Object.defineProperty(m,e,a.get?a:{enumerable:!0,get:()=>I[e]})}}return m.default=I,Object.freeze(m)}const C=z(q),M=C.getLogger();M.level="info";class O{parseStatus(m){let e,a;switch(m){case 0:e="在航(主机推动)",a="The engine is in use";break;case 1:e="锚泊",a="Anchored";break;case 2:e="失控",a="Not operated";break;case 3:e="操纵受限",a="Limited airworthiness";break;case 4:e="吃水受限",a="Limited by ship's draft";break;case 5:e="靠泊",a="Mooring";break;case 6:e="搁浅",a="Stranded";break;case 7:e="捕捞作业",a="Engaged in fishing";break;case 8:e="靠帆船提供动力",a="Sailing";break;default:e="未定义",a="Undefined"}return{labelCn:e,labelEn:a}}}class F extends O{constructor(e,a){super();A(this,"clientId");A(this,"clientSecret");A(this,"token");this.clientId=e,this.clientSecret=a}async authToken(e={}){const a="https://svc.data.myvessel.cn/ada/oauth/token",n={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},o=await y.post(a,n).json();M.info("[%s] fetch access token from: %s - %j",e.requestId,a,o),o.error||(this.token={accessToken:o.access_token,tokenType:o.token_type,expiresIn:o.expires_in,scope:o.scope,jti:o.jti,issuedAt:p().utc().format()})}async realTimePosition(e,a={}){var d,c,l;(!this.token||p().diff(p(this.token.issuedAt),"seconds")>((d=this.token)==null?void 0:d.expiresIn)-300)&&await this.authToken(a);const n="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",o={headers:{Authorization:`${(c=this.token)==null?void 0:c.tokenType} ${(l=this.token)==null?void 0:l.accessToken}`},searchParams:{mmsi:e}};M.info("[%s] fetch realtime position from: %s - %j",a.requestId,n,o);const s=await y.get(n,o).json();if(s.code)return M.warn("[%s] fetch realtime position failed: %j",a.requestId,n,{message:s.message,status:s.status,code:s.code}),s;const t=s.data;for(const u in t)!isNaN(t[u])&&Number(t[u])!==1/0&&(t[u]=Number(t[u]));const r=p(`${t.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:t.mmsi,name:t.vesselName,imo:t.imo,callSign:t.callsign,lat:t.lat,lng:t.lon,length:t.length,width:t.width,draught:t.currDraught,sog:t.sog,cog:t.cog,hdg:t.hdg,rot:t.rot,eta:t.eta,destination:t.dest,positionTime:r.unix(),status:t.status,labelCn:t.statusNameCn,labelEn:t.statusNameEn,method:"position",vendor:"myVessel",utc:r.utc().format()}}async trajectory(e,a,n,o,s=!0,t={}){(!this.token||p().diff(p(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(t);const r=await this.realTimePosition(e,t),i=p(a),d=p(n),c=[];for(;d.diff(i,"day",!0)>30;)await this.trajectoryIn30Day(e,i,i.clone().add(30,"day"),r,o,c,t),i.add(30,"day");return await this.trajectoryIn30Day(e,i,d,r,o,c,t),c}async trajectoryIn30Day(e,a,n,o,s,t,r={}){var h,v,Y,k,S;const i="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",d={headers:{Authorization:`${(h=this.token)==null?void 0:h.tokenType} ${(v=this.token)==null?void 0:v.accessToken}`},json:{mmsi:e,startTime:a.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};M.info("[%s] fetch trajectory from: %s - %j",r.requestId,i,d);const c=await y.post(i,d).json();if(c.code)return M.warn("[%s] fetch trajectory failed: %j",r.requestId,i,{message:c.message,status:c.status,code:c.code}),c;let l=-1;const u=p(`${(k=(Y=c.data)==null?void 0:Y[0])==null?void 0:k.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(S=c.data)==null||S.forEach(g=>{for(const T in g)!isNaN(g[T])&&Number(g[T])!==1/0&&(g[T]=Number(g[T]));const w=p(`${g.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),N=g.eta?p(`${g.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,f=g.status,{labelCn:E,labelEn:P}=this.parseStatus(f),R={mmsi:g.mmsi,imo:o==null?void 0:o.imo,lat:g.lat,lng:g.lon,sog:g.sog,cog:g.cog,hdg:g.hdg,draught:g.draught,status:f,eta:N==null?void 0:N.unix(),destination:g.dest,positionTime:w.unix(),labelCn:E,labelEn:P,method:"trajectory",vendor:"myVessel",utc:w.utc().format()},x=Math.floor(w.diff(u,"minute",!0)/(s||1));x!==l&&(l=x,t.push(R))}),t}}class G extends O{constructor(e){super();A(this,"token");this.token=e}async realTimePosition(e,a={}){const n="https://api.hifleet.com/position/position/get/token",o={searchParams:{mmsi:e,usertoken:this.token}},s=await y.post(n,o).json();M.info("[%s] fetch realtime position from: %s - %j",a.requestId,n,o);const t=s==null?void 0:s.list;if(!t)return M.warn("[%s] fetch realtime position failed: %j",a.requestId,n,s),s;for(const u in t)!isNaN(t[u])&&Number(t[u])!==1/0&&(t[u]=Number(t[u]));t.status=t.sp>3?0:1;const r=t.status,{labelCn:i,labelEn:d}=this.parseStatus(r),c=p(`${t.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:t.m,name:t.n,imo:t.imonumber,callSign:t.callsign,lat:Math.round(t.la/60*1e5)/1e5,lng:Math.round(t.lo/60*1e5)/1e5,length:t.l,width:t.w,draught:t.draught,sog:t.sp,cog:t.co,hdg:t.h,rot:isNaN(t.rot)?0:t.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(t.eta)?p(`${t.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").unix():void 0,destination:t.destination,positionTime:c.unix(),utc:c.utc().format(),status:r,labelCn:i,labelEn:d,method:"position",vendor:"hifleet"}}async search(e,a={}){let n="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const o={searchParams:{keyword:e},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let s=await y.post(n,o).json();M.info("[%s] fetch vessel props from: %s - %j",a.requestId,n,o),s instanceof Array&&(s=s[0]);for(const r in s)!isNaN(s[r])&&Number(s[r])!==1/0&&(s[r]=Number(s[r]));const t={mmsi:s.m,name:s.n,imo:s.i,callSign:s.c,length:s.l,breadth:s.b,draught:s.dr};return n="https://www.hifleet.com/hifleetapi/sameShipSearch.do",s=await y.post(n,o).json(),M.info("[%s] fetch vessel dead weight from: %s - %j",a.requestId,n,o),s instanceof Array&&(s=s[0]),s&&(t.deadweight=Number(s.dwt)),t}async trajectory(e,a,n,o,s=!0,t={}){var g,w,N;const r=await this.realTimePosition(e,t);let i=p(a);const d=p(n),c=p();if(s){let f=d.diff(i,"d",!0);f<0?i=d.clone().subtract(40,"d"):f<30?i.subtract(10,"d"):f<60?i.subtract(5,"d"):i=d.clone().subtract(80,"d"),f=c.diff(d,"d",!0),d.add(f>10?240:f*24,"h")}const l={searchParams:{endtime:d.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),starttime:i.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),mmsi:e,usertoken:this.token}},u="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",h=await y.get(u,l).json();M.info("[%s] fetch trajectory from: %s - %j",t.requestId,u,l);let v;h&&(v=((w=(g=h.ships)==null?void 0:g.offors)==null?void 0:w.ship)||[],v.length||M.warn("[%s] fetch trajectory failed: %j",t.requestId,h));const Y=[];let k=-1;const S=p(`${(N=v==null?void 0:v[0])==null?void 0:N.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const f of v){for(const _ in f)!isNaN(f[_])&&Number(f[_])!==1/0&&(f[_]=Number(f[_]));const E=p(`${f.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");f.status=f.sp>4?0:1;const{labelEn:P,labelCn:R}=this.parseStatus(f.status),x={mmsi:f.m,name:f.n,imo:r==null?void 0:r.imo,lat:f.la,lng:f.lo,draught:f.draught,sog:f.sp,cog:f.co,hdg:f.hdg,positionTime:E.unix(),utc:E.utc().format(),status:f.status,labelCn:R,labelEn:P,method:"trajectory",vendor:"hifleet"},T=Math.floor(E.diff(S,"minute",!0)/(o||1));T!==k&&(k=T,Y.push(x))}return Y}}class B extends O{constructor(e){super();A(this,"token");this.token=e}async realTimePosition(e,a={}){const n={searchParams:{id:e,k:this.token,enc:1}},o="https://api.shipxy.com/apicall/GetSingleShip",s=await y.get(o,n).json();if(M.info("[%s] fetch realtime position from: %s - %j",a.requestId,o,n),(s==null?void 0:s.status)!==0)return s;const t=s.data[0];for(const l in t)!isNaN(t[l])&&Number(t[l])!==1/0&&(t[l]=Number(t[l]));const{labelCn:r,labelEn:i}=await this.parseStatus(t.navistat),d=p.unix(t.lasttime);return{mmsi:t.ShipID,name:t.name,imo:t.imo,callSign:t.callsign,lat:Math.round(t.lat/1e6*1e5)/1e5,lng:Math.round(t.lon/1e6*1e5)/1e5,length:Math.round(t.length/10*100)/100,width:Math.round(t.width/10*100)/100,draught:Math.round(t.draught/1e3*100)/100,sog:Math.round(t.sog*3600/1e3/1852*100)/100,cog:Math.round(t.cog/100*100)/100,hdg:Math.round(t.hdg/100*100)/100,rot:Math.round(t.rot/100*100)/100,positionTime:t.lasttime,utc:d.utc().format(),status:t.navistat,labelEn:i,labelCn:r,method:"position",vendor:"shipxy"}}async trajectory(e,a,n,o,s=!0,t={}){var S;const r=await this.realTimePosition(e,t),i=p(a),d=p(n),c="https://api.shipxy.com/apicall/GetShipTrack",l={searchParams:{id:e,k:this.token,enc:1,cut:0,btm:i.unix(),etm:d.unix()}},u=await y.get(c,l).json();if(M.info("[%s] fetch trajectory from: %s - %j",t.requestId,c,l),(u==null?void 0:u.status)!==0)return u;const h=u==null?void 0:u.points,v=[],Y=p.unix((S=h[0])==null?void 0:S.utc);let k=-1;for(const g of h){const w=p.unix(g.utc),N={imo:r==null?void 0:r.imo,mmsi:e,sog:Math.round(g.sog*3600/1e3/1852*100)/100,cog:Math.round(g.cog/100*100)/100,lat:Math.round(g.lat/1e6*1e5)/1e5,lng:Math.round(g.lon/1e6*1e5)/1e5,positionTime:w.unix(),utc:w.utc().format(),method:"trajectory",vendor:"shipxy"},f=Math.floor(w.diff(Y,"minute",!0)/(o||1));f!==k&&(k=f,v.push(N))}return v}}class U extends O{constructor(e){super();A(this,"token");this.token=e}async getShipId(e,a={}){const n={headers:{appKey:this.token},json:{mmsiList:e}},o="https://api3.myships.com/sp/ships/getShipIdByMMSI",s=await y.post(o,n).json();return M.info("[%s] fetch ship id from: %s - %j",a.requestId,o,n),s.code!=="0"?s:s.data[0].shipId}async getShipInfo(e,a={}){const n={headers:{appKey:this.token},json:{shipId:e}},o="https://api3.myships.com/sp/ships/aissta",s=await y.post(o,n).json();if(M.info("[%s] fetch ship info from: %s - %j",a.requestId,o,n),s.code!=="0")return s;const t=s.data;let r=t.imo;return e==="407170"&&(r="9198379",M.warn("[%s] ship(%s) imo error: %s, should be %s",a.requestId,e,t.imo,r)),{mmsi:t.mmsi,name:t.shipnameEn,imo:r,callSign:t.callSign,length:t.length,width:t.breadth,draught:(t.draught||100)/10}}async realTimePosition(e,a={}){const n=await this.getShipId(e,a),o=await this.getShipInfo(n,a),s={headers:{appKey:this.token},json:{shipId:n}},t="https://api3.myships.com/sp/ships/position/latest",r=await y.post(t,s).json();M.info("[%s] fetch realtime position from: %s - %j",a.requestId,t,s);const i=r.data[0];for(const h in i)!isNaN(i[h])&&Number(i[h])!==1/0&&(i[h]=Number(i[h]));const{labelCn:d,labelEn:c}=await this.parseStatus(i.aisNavStatus),l=p.unix(i.posTime);return{...o,mmsi:e,lat:Math.round(i.lat/1e4/60*1e5)/1e5,lng:Math.round(i.lon/1e4/60*1e5)/1e5,sog:Math.round(i.sog/10*100)/100,cog:Math.round(i.cog/10*100)/100,hdg:Math.round(i.heading*100)/100,rot:Math.round(i.rot*100)/100,positionTime:i.posTime,utc:l.utc().format(),status:i.aisNavStatus,labelEn:c,labelCn:d,method:"position",vendor:"myship"}}async trajectory(e,a,n,o,s=!0,t={}){const r=p(a),i=p(n),d=await this.getShipId(e),c=await this.getShipInfo(d),l=[];for(;i.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(d,r.unix(),r.add(30,"day").unix(),c,e,o,l);return await this.trajectoryIn30Day(d,r.unix(),i.unix(),c,e,o,l),l}async trajectoryIn30Day(e,a,n,o,s,t,r,i={}){var Y;const d={headers:{appKey:this.token},json:{shipId:e,startTime:a,endTime:n}},c="https://api3.myships.com/sp/ships/position/history",l=await y.post(c,d).json();if(M.info("[%s] fetch trajectory from: %s - %j",i.requestId,c,d),l.code!=="0")return M.warn("[%s] invoke myship trajectory failed: %j",i.requestId,l),l;const u=l.data;for(const k in u)!isNaN(u[k])&&Number(u[k])!==1/0&&(u[k]=Number(u[k]));const h=p.unix((Y=u[0])==null?void 0:Y.posTime);let v=-1;for(const k of u){const S=p.unix(k.posTime),g={imo:o==null?void 0:o.imo,mmsi:s,lat:Math.round(k.lat/1e4/60*1e5)/1e5,lng:Math.round(k.lon/1e4/60*1e5)/1e5,sog:Math.round(k.sog/10*100)/100,cog:Math.round(k.cog/10*100)/100,hdg:Math.round(k.heading*100)/100,rot:Math.round(k.rot*100)/100,positionTime:S.unix(),utc:S.utc().format(),method:"trajectory",vendor:"myship"},w=Math.floor(S.diff(h,"minute",!0)/(t||1));w!==v&&(v=w,r.push(g))}return r}}const V=C.getLogger();V.level="info";var K=(I=>(I.NOTICE="NOTICE",I.WARN="WARN",I.HEAVY="HEAVY",I.SEVERE="SEVERE",I.ERROR="ERROR",I.FATAL="FATAL",I))(K||{});class L{parsePrinciple(m,e={}){var t,r,i;V.info("[%s] parse rule: %s",e.requestId,m);const a=new RegExp("(?<=\\[)(.+)(?=\\])","g"),n=m.match(a)?(t=m.match(a))==null?void 0:t[0]:void 0,o=n==null?void 0:n.split(";");if(!o)return;const s={};for(let d=0;d<(o==null?void 0:o.length);d++){const c=(i=(r=o[d].match(a))==null?void 0:r[0])==null?void 0:i.split("],");if(d===0&&!c)s.scope=o[0];else if(c)for(let l=0,u=c.length;l<u;l++){const h=this.parseRule(c[l]);h&&(s[h.level]?h.key?s[h.level][h==null?void 0:h.key]=h:s[h.level]=h:h.key?s[h.level]={[h==null?void 0:h.key]:h}:s[h.level]=h)}}return s}parseRule(m,e={}){var s;V.info("[%s] parse rule: %s",e.requestId,m),m=m.startsWith("[")?m:`[${m}`,m=m.endsWith("]")?m:`${m}]`;const a=new RegExp("(?<=\\[)(.+?)(?=\\])","g"),n=(s=m==null?void 0:m.match(a))==null?void 0:s[0],o=n==null?void 0:n.split(",");if(o)return{operator:o[0],number:Number(o[1]),level:o[2],time:Number(o[3]),key:o[4]}}checkWeather(m,e,a={}){var h,v,Y,k,S,g,w,N,f,E,P,R,x,T,_;let n=0,o=0,s=0,t=0;const r=((v=(h=e==null?void 0:e.SEVERE)==null?void 0:h.sigWave)==null?void 0:v.number)*1.6,i=(k=(Y=e==null?void 0:e.SEVERE)==null?void 0:Y.sigWave)==null?void 0:k.number,d=(g=(S=e==null?void 0:e.HEAVY)==null?void 0:S.sigWave)==null?void 0:g.number,c=((N=(w=e==null?void 0:e.SEVERE)==null?void 0:w.wind)==null?void 0:N.number)+2,l=(E=(f=e==null?void 0:e.SEVERE)==null?void 0:f.wind)==null?void 0:E.number,u=(R=(P=e==null?void 0:e.HEAVY)==null?void 0:P.wind)==null?void 0:R.number;for(let W=1;W<(m==null?void 0:m.length);W++){const b=m[W],H=(T=(x=b==null?void 0:b.meteo)==null?void 0:x.wave)==null?void 0:T.sig,D=(_=b==null?void 0:b.meteo)==null?void 0:_.wind,$=p(b.eta).diff(p(m[W-1].eta),"hour",!0);t=$>t?$:t,V.info("[%s] check sig.wave: %j",a.requestId,{...H,dgThd4Wv:r,svThd4Wv:i,hvThd4Wv:d}),(H==null?void 0:H.height)>=r?b.isDangerous=!0:(H==null?void 0:H.height)>=i?b.isSevere=!0:(H==null?void 0:H.height)>=d&&(b.isHeavy=!0),V.info("[%s] check wind: %j",a.requestId,{...D,dgThd4Wd:c,svThd4Wd:l,hvThd4Wd:u}),(D==null?void 0:D.scale)>=c?(b.isDangerous=!0,delete b.isSevere,delete b.isHeavy):(D==null?void 0:D.scale)>l?(b.isDangerous||(b.isSevere=!0),delete b.isHeavy):(D==null?void 0:D.scale)===u&&!b.isDangerous&&!b.isSevere&&(b.isHeavy=!0),n+=b.isDangerous?$:0,o+=b.isSevere?$:0,s+=b.isHeavy?$:0}return n=Math.round(n*100)/100,o=Math.round(o*100)/100,s=Math.round(s*100)/100,t=Math.round(t),{sample:m,dangerous:n,severe:o,heavy:s,step:t<3?3:t,wind:{dgThd4Wd:c,svThd4Wd:l,hvThd4Wd:u},sig:{dgThd4Wv:r,svThd4Wv:i,hvThd4Wv:d}}}}const J=new L;j.AISImpl=O,j.AlertHelper=L,j.AlertLevel=K,j.HifleetImpl=G,j.MyShipImpl=U,j.MyVesselImpl=F,j.ShipxyImpl=B,j.alertHelper=J,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"})});
|