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