@idm-plugin/vessel 1.7.3 → 1.7.5
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 +441 -433
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var G = (
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { LngLatHelper as
|
|
8
|
-
import { MeteoHelper2 as
|
|
9
|
-
import { Meteo2Assist as
|
|
1
|
+
var ut = Object.defineProperty;
|
|
2
|
+
var ht = (j, e, t) => e in j ? ut(j, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : j[e] = t;
|
|
3
|
+
var G = (j, e, t) => (ht(j, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import J from "got";
|
|
5
|
+
import nt from "@log4js-node/log4js-api";
|
|
6
|
+
import p from "moment";
|
|
7
|
+
import { LngLatHelper as B, LaneHelper as L } from "@idm-plugin/geo2";
|
|
8
|
+
import { MeteoHelper2 as lt, MeteoHelper as ft } from "@idm-plugin/meteo2";
|
|
9
|
+
import { Meteo2Assist as rt } from "@idm-plugin/meteo";
|
|
10
10
|
let g;
|
|
11
11
|
try {
|
|
12
|
-
g =
|
|
12
|
+
g = nt.getLogger("vessel");
|
|
13
13
|
} catch {
|
|
14
14
|
} finally {
|
|
15
15
|
}
|
|
16
|
-
class
|
|
16
|
+
class et {
|
|
17
17
|
/**
|
|
18
18
|
* 解析AIS状态码
|
|
19
19
|
* @param status
|
|
@@ -54,7 +54,7 @@ class tt {
|
|
|
54
54
|
return { labelCn: t, labelEn: n };
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
class xt extends
|
|
57
|
+
class xt extends et {
|
|
58
58
|
constructor(t, n) {
|
|
59
59
|
super();
|
|
60
60
|
G(this, "clientId");
|
|
@@ -69,19 +69,19 @@ class xt extends tt {
|
|
|
69
69
|
client_secret: this.clientSecret,
|
|
70
70
|
grant_type: "client_credentials"
|
|
71
71
|
}
|
|
72
|
-
}, o = await
|
|
72
|
+
}, o = await J.post(n, i).json();
|
|
73
73
|
g == null || g.info("[%s] fetch access token from: %s - %j", t.requestId, n, o), o.error || (this.token = {
|
|
74
74
|
accessToken: o.access_token,
|
|
75
75
|
tokenType: o.token_type,
|
|
76
76
|
expiresIn: o.expires_in,
|
|
77
77
|
scope: o.scope,
|
|
78
78
|
jti: o.jti,
|
|
79
|
-
issuedAt:
|
|
79
|
+
issuedAt: p().utc().format()
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
async realTimePosition(t, n = {}) {
|
|
83
|
-
var
|
|
84
|
-
(!this.token ||
|
|
83
|
+
var h, m, l;
|
|
84
|
+
(!this.token || p().diff(p(this.token.issuedAt), "seconds") > ((h = this.token) == null ? void 0 : h.expiresIn) - 300) && await this.authToken(n);
|
|
85
85
|
const i = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit", o = {
|
|
86
86
|
headers: {
|
|
87
87
|
Authorization: `${(m = this.token) == null ? void 0 : m.tokenType} ${(l = this.token) == null ? void 0 : l.accessToken}`
|
|
@@ -89,13 +89,13 @@ class xt extends tt {
|
|
|
89
89
|
searchParams: { mmsi: t }
|
|
90
90
|
};
|
|
91
91
|
g == null || g.info("[%s] fetch realtime position from: %s - %j", n.requestId, i, o);
|
|
92
|
-
const a = await
|
|
92
|
+
const a = await J.get(i, o).json();
|
|
93
93
|
if (a.code)
|
|
94
94
|
return g == null || g.warn("[%s] fetch realtime position failed: %j", n.requestId, i, { message: a.message, status: a.status, code: a.code }), a;
|
|
95
95
|
const s = a.data;
|
|
96
96
|
for (const y in s)
|
|
97
97
|
!isNaN(s[y]) && Number(s[y]) !== 1 / 0 && (s[y] = Number(s[y]));
|
|
98
|
-
const d =
|
|
98
|
+
const d = p(`${s.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
99
99
|
return {
|
|
100
100
|
mmsi: s.mmsi,
|
|
101
101
|
name: s.vesselName,
|
|
@@ -110,7 +110,7 @@ class xt extends tt {
|
|
|
110
110
|
cog: s.cog,
|
|
111
111
|
hdg: s.hdg,
|
|
112
112
|
rot: s.rot,
|
|
113
|
-
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ?
|
|
113
|
+
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ? p.utc(s.eta).format() : void 0,
|
|
114
114
|
destination: s.dest,
|
|
115
115
|
positionTime: d.unix(),
|
|
116
116
|
status: s.status,
|
|
@@ -122,17 +122,17 @@ class xt extends tt {
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
async trajectory(t, n, i, o, a = !0, s = {}) {
|
|
125
|
-
(!this.token ||
|
|
126
|
-
const d = await this.realTimePosition(t, s),
|
|
127
|
-
for (;
|
|
128
|
-
await this.trajectoryIn30Day(t,
|
|
129
|
-
return await this.trajectoryIn30Day(t,
|
|
125
|
+
(!this.token || p().diff(p(this.token.issuedAt), "seconds") > this.token.expiresIn - 300) && await this.authToken(s);
|
|
126
|
+
const d = await this.realTimePosition(t, s), r = p(n), h = p(i), m = [];
|
|
127
|
+
for (; h.diff(r, "day", !0) > 30; )
|
|
128
|
+
await this.trajectoryIn30Day(t, r, r.clone().add(30, "day"), d, o, m, s), r.add(30, "day");
|
|
129
|
+
return await this.trajectoryIn30Day(t, r, h, d, o, m, s), m;
|
|
130
130
|
}
|
|
131
131
|
async trajectoryIn30Day(t, n, i, o, a, s, d = {}) {
|
|
132
|
-
var f,
|
|
133
|
-
const
|
|
132
|
+
var f, C, k, v, b;
|
|
133
|
+
const r = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", h = {
|
|
134
134
|
headers: {
|
|
135
|
-
Authorization: `${(f = this.token) == null ? void 0 : f.tokenType} ${(
|
|
135
|
+
Authorization: `${(f = this.token) == null ? void 0 : f.tokenType} ${(C = this.token) == null ? void 0 : C.accessToken}`
|
|
136
136
|
},
|
|
137
137
|
json: {
|
|
138
138
|
mmsi: t,
|
|
@@ -140,39 +140,39 @@ class xt extends tt {
|
|
|
140
140
|
endTime: i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
|
-
g == null || g.info("[%s] fetch trajectory from: %s - %j", d.requestId,
|
|
144
|
-
const m = await
|
|
143
|
+
g == null || g.info("[%s] fetch trajectory from: %s - %j", d.requestId, r, h);
|
|
144
|
+
const m = await J.post(r, h).json();
|
|
145
145
|
if (m.code)
|
|
146
|
-
return g == null || g.warn("[%s] fetch trajectory failed: %j", d.requestId,
|
|
146
|
+
return g == null || g.warn("[%s] fetch trajectory failed: %j", d.requestId, r, { message: m.message, status: m.status, code: m.code }), m;
|
|
147
147
|
let l = -1;
|
|
148
|
-
const y =
|
|
149
|
-
return (
|
|
150
|
-
for (const Y in
|
|
151
|
-
!isNaN(
|
|
152
|
-
const
|
|
153
|
-
mmsi:
|
|
148
|
+
const y = p(`${(v = (k = m.data) == null ? void 0 : k[0]) == null ? void 0 : v.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
149
|
+
return (b = m.data) == null || b.forEach((c) => {
|
|
150
|
+
for (const Y in c)
|
|
151
|
+
!isNaN(c[Y]) && Number(c[Y]) !== 1 / 0 && (c[Y] = Number(c[Y]));
|
|
152
|
+
const w = p(`${c.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), M = c.status, { labelCn: u, labelEn: I } = this.parseStatus(M), S = {
|
|
153
|
+
mmsi: c.mmsi,
|
|
154
154
|
imo: o == null ? void 0 : o.imo,
|
|
155
|
-
lat:
|
|
156
|
-
lng:
|
|
157
|
-
sog:
|
|
158
|
-
cog:
|
|
159
|
-
hdg:
|
|
160
|
-
draught:
|
|
155
|
+
lat: c.lat,
|
|
156
|
+
lng: c.lon,
|
|
157
|
+
sog: c.sog,
|
|
158
|
+
cog: c.cog,
|
|
159
|
+
hdg: c.hdg,
|
|
160
|
+
draught: c.draught,
|
|
161
161
|
status: M,
|
|
162
|
-
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(
|
|
163
|
-
destination:
|
|
164
|
-
positionTime:
|
|
165
|
-
labelCn:
|
|
166
|
-
labelEn:
|
|
162
|
+
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(c.eta) ? p(`${c.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00").utc().format() : void 0,
|
|
163
|
+
destination: c.dest,
|
|
164
|
+
positionTime: w.unix(),
|
|
165
|
+
labelCn: u,
|
|
166
|
+
labelEn: I,
|
|
167
167
|
method: "trajectory",
|
|
168
168
|
vendor: "myVessel",
|
|
169
|
-
utc:
|
|
170
|
-
},
|
|
171
|
-
|
|
169
|
+
utc: w.utc().format()
|
|
170
|
+
}, D = Math.floor(w.diff(y, "minute", !0) / (a || 1));
|
|
171
|
+
D !== l && (l = D, s.push(S));
|
|
172
172
|
}), s;
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
|
-
class
|
|
175
|
+
class jt extends et {
|
|
176
176
|
constructor(t) {
|
|
177
177
|
super();
|
|
178
178
|
G(this, "token");
|
|
@@ -184,7 +184,7 @@ class Ct extends tt {
|
|
|
184
184
|
mmsi: t,
|
|
185
185
|
usertoken: this.token
|
|
186
186
|
}
|
|
187
|
-
}, a = await
|
|
187
|
+
}, a = await J.post(i, o).json();
|
|
188
188
|
g == null || g.info("[%s] fetch realtime position from: %s - %j", n.requestId, i, o);
|
|
189
189
|
const s = a == null ? void 0 : a.list;
|
|
190
190
|
if (!s)
|
|
@@ -192,7 +192,7 @@ class Ct extends tt {
|
|
|
192
192
|
for (const y in s)
|
|
193
193
|
!isNaN(s[y]) && Number(s[y]) !== 1 / 0 && (s[y] = Number(s[y]));
|
|
194
194
|
s.status = s.sp > 3 ? 0 : 1;
|
|
195
|
-
const d = s.status, { labelCn:
|
|
195
|
+
const d = s.status, { labelCn: r, labelEn: h } = this.parseStatus(d), m = p(`${s.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
196
196
|
return {
|
|
197
197
|
mmsi: s.m,
|
|
198
198
|
name: s.n,
|
|
@@ -207,13 +207,13 @@ class Ct extends tt {
|
|
|
207
207
|
cog: s.co,
|
|
208
208
|
hdg: s.h,
|
|
209
209
|
rot: isNaN(s.rot) ? 0 : s.rot,
|
|
210
|
-
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ?
|
|
210
|
+
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ? p.utc(s.eta).format() : void 0,
|
|
211
211
|
destination: s.destination,
|
|
212
212
|
positionTime: m.unix(),
|
|
213
213
|
utc: m.utc().format(),
|
|
214
214
|
status: d,
|
|
215
|
-
labelCn:
|
|
216
|
-
labelEn:
|
|
215
|
+
labelCn: r,
|
|
216
|
+
labelEn: h,
|
|
217
217
|
method: "position",
|
|
218
218
|
vendor: "hifleet"
|
|
219
219
|
};
|
|
@@ -230,7 +230,7 @@ class Ct extends tt {
|
|
|
230
230
|
Host: "www.hifleet.com"
|
|
231
231
|
}
|
|
232
232
|
};
|
|
233
|
-
let a = await
|
|
233
|
+
let a = await J.post(i, o).json();
|
|
234
234
|
g == null || g.info("[%s] fetch vessel props from: %s - %j", n.requestId, i, o), a instanceof Array && (a = a[0]);
|
|
235
235
|
for (const d in a)
|
|
236
236
|
!isNaN(a[d]) && Number(a[d]) !== 1 / 0 && (a[d] = Number(a[d]));
|
|
@@ -244,7 +244,7 @@ class Ct extends tt {
|
|
|
244
244
|
draught: a.dr,
|
|
245
245
|
type: a.t
|
|
246
246
|
};
|
|
247
|
-
return i = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", a = await
|
|
247
|
+
return i = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", a = await J.post(i, o).json(), g == null || g.info("[%s] search vessel dead weight from: %s - %j", n.requestId, i, o), a instanceof Array && (a = a[0]), a && (s.deadweight = Number(a.dwt)), s;
|
|
248
248
|
}
|
|
249
249
|
async suggest(t, n = {}) {
|
|
250
250
|
const i = "https://www.hifleet.com/hifleetapi/getShipSuggest.do", o = {
|
|
@@ -256,7 +256,7 @@ class Ct extends tt {
|
|
|
256
256
|
Origin: "https://www.hifleet.com",
|
|
257
257
|
Host: "www.hifleet.com"
|
|
258
258
|
}
|
|
259
|
-
}, a = await
|
|
259
|
+
}, a = await J.post(i, o).json();
|
|
260
260
|
g == null || g.info("[%s] suggest vessel props from: %s - %j", n.requestId, i, o);
|
|
261
261
|
const s = [];
|
|
262
262
|
for (const d of a)
|
|
@@ -267,60 +267,60 @@ class Ct extends tt {
|
|
|
267
267
|
imo: !d.imo || isNaN(d.imo) ? null : Number(d.imo),
|
|
268
268
|
score: d._score
|
|
269
269
|
});
|
|
270
|
-
return s.sort((d,
|
|
270
|
+
return s.sort((d, r) => r.score - d.score), s;
|
|
271
271
|
}
|
|
272
272
|
async trajectory(t, n, i, o, a = !0, s = {}) {
|
|
273
|
-
var
|
|
273
|
+
var c, w, M;
|
|
274
274
|
const d = await this.realTimePosition(t, s);
|
|
275
|
-
let
|
|
276
|
-
const
|
|
275
|
+
let r = p(n);
|
|
276
|
+
const h = p(i), m = p();
|
|
277
277
|
if (a) {
|
|
278
|
-
let
|
|
279
|
-
|
|
278
|
+
let u = h.diff(r, "d", !0);
|
|
279
|
+
u < 0 ? r = h.clone().subtract(40, "d") : u < 30 ? r.subtract(10, "d") : u < 60 ? r.subtract(5, "d") : r = h.clone().subtract(80, "d"), u = m.diff(h, "d", !0), h.add(u > 10 ? 240 : u * 24, "h");
|
|
280
280
|
}
|
|
281
281
|
const l = {
|
|
282
282
|
searchParams: {
|
|
283
|
-
endtime:
|
|
284
|
-
starttime:
|
|
283
|
+
endtime: h.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
|
|
284
|
+
starttime: r.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
|
|
285
285
|
mmsi: t,
|
|
286
286
|
usertoken: this.token
|
|
287
287
|
}
|
|
288
|
-
}, y = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", f = await
|
|
288
|
+
}, y = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", f = await J.get(y, l).json();
|
|
289
289
|
g == null || g.info("[%s] fetch trajectory from: %s - %j", s.requestId, y, l);
|
|
290
|
-
let
|
|
291
|
-
f && (
|
|
292
|
-
const
|
|
293
|
-
let
|
|
294
|
-
const
|
|
295
|
-
for (const
|
|
296
|
-
for (const
|
|
297
|
-
!isNaN(
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
const { labelEn:
|
|
301
|
-
mmsi:
|
|
302
|
-
name:
|
|
290
|
+
let C;
|
|
291
|
+
f && (C = ((w = (c = f.ships) == null ? void 0 : c.offors) == null ? void 0 : w.ship) || [], C.length || g == null || g.warn("[%s] fetch trajectory failed: %j", s.requestId, f));
|
|
292
|
+
const k = [];
|
|
293
|
+
let v = -1;
|
|
294
|
+
const b = p(`${(M = C == null ? void 0 : C[0]) == null ? void 0 : M.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
295
|
+
for (const u of C) {
|
|
296
|
+
for (const P in u)
|
|
297
|
+
!isNaN(u[P]) && Number(u[P]) !== 1 / 0 && (u[P] = Number(u[P]));
|
|
298
|
+
const I = p(`${u.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
299
|
+
u.status = u.sp > 4 ? 0 : 1;
|
|
300
|
+
const { labelEn: S, labelCn: D } = this.parseStatus(u.status), Y = {
|
|
301
|
+
mmsi: u.m,
|
|
302
|
+
name: u.n,
|
|
303
303
|
imo: d == null ? void 0 : d.imo,
|
|
304
|
-
lat:
|
|
305
|
-
lng:
|
|
306
|
-
draught:
|
|
307
|
-
sog:
|
|
308
|
-
cog:
|
|
309
|
-
hdg:
|
|
310
|
-
positionTime:
|
|
311
|
-
utc:
|
|
312
|
-
status:
|
|
313
|
-
labelCn:
|
|
314
|
-
labelEn:
|
|
304
|
+
lat: u.la,
|
|
305
|
+
lng: u.lo,
|
|
306
|
+
draught: u.draught,
|
|
307
|
+
sog: u.sp,
|
|
308
|
+
cog: u.co,
|
|
309
|
+
hdg: u.hdg,
|
|
310
|
+
positionTime: I.unix(),
|
|
311
|
+
utc: I.utc().format(),
|
|
312
|
+
status: u.status,
|
|
313
|
+
labelCn: D,
|
|
314
|
+
labelEn: S,
|
|
315
315
|
method: "trajectory",
|
|
316
316
|
vendor: "hifleet"
|
|
317
|
-
},
|
|
318
|
-
|
|
317
|
+
}, N = Math.floor(I.diff(b, "minute", !0) / (o || 1));
|
|
318
|
+
N !== v && (v = N, k.push(Y));
|
|
319
319
|
}
|
|
320
|
-
return
|
|
320
|
+
return k;
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
|
-
class
|
|
323
|
+
class Et extends et {
|
|
324
324
|
constructor(t) {
|
|
325
325
|
super();
|
|
326
326
|
G(this, "token");
|
|
@@ -333,13 +333,13 @@ class jt extends tt {
|
|
|
333
333
|
k: this.token,
|
|
334
334
|
enc: 1
|
|
335
335
|
}
|
|
336
|
-
}, o = "https://api.shipxy.com/apicall/GetSingleShip", a = await
|
|
336
|
+
}, o = "https://api.shipxy.com/apicall/GetSingleShip", a = await J.get(o, i).json();
|
|
337
337
|
if (g == null || g.info("[%s] fetch realtime position from: %s - %j", n.requestId, o, i), (a == null ? void 0 : a.status) !== 0)
|
|
338
338
|
return a;
|
|
339
339
|
const s = a.data[0];
|
|
340
340
|
for (const l in s)
|
|
341
341
|
!isNaN(s[l]) && Number(s[l]) !== 1 / 0 && (s[l] = Number(s[l]));
|
|
342
|
-
const { labelCn: d, labelEn:
|
|
342
|
+
const { labelCn: d, labelEn: r } = await this.parseStatus(s.navistat), h = p.unix(s.lasttime);
|
|
343
343
|
return {
|
|
344
344
|
mmsi: s.ShipID,
|
|
345
345
|
name: s.name,
|
|
@@ -355,49 +355,49 @@ class jt extends tt {
|
|
|
355
355
|
hdg: Math.round(s.hdg / 100 * 100) / 100,
|
|
356
356
|
rot: Math.round(s.rot / 100 * 100) / 100,
|
|
357
357
|
positionTime: s.lasttime,
|
|
358
|
-
utc:
|
|
358
|
+
utc: h.utc().format(),
|
|
359
359
|
status: s.navistat,
|
|
360
|
-
labelEn:
|
|
360
|
+
labelEn: r,
|
|
361
361
|
labelCn: d,
|
|
362
362
|
method: "position",
|
|
363
363
|
vendor: "shipxy"
|
|
364
364
|
};
|
|
365
365
|
}
|
|
366
366
|
async trajectory(t, n, i, o, a = !0, s = {}) {
|
|
367
|
-
var
|
|
368
|
-
const d = await this.realTimePosition(t, s),
|
|
367
|
+
var b;
|
|
368
|
+
const d = await this.realTimePosition(t, s), r = p(n), h = p(i), m = "https://api.shipxy.com/apicall/GetShipTrack", l = {
|
|
369
369
|
searchParams: {
|
|
370
370
|
id: t,
|
|
371
371
|
k: this.token,
|
|
372
372
|
enc: 1,
|
|
373
373
|
cut: 0,
|
|
374
|
-
btm:
|
|
375
|
-
etm:
|
|
374
|
+
btm: r.unix(),
|
|
375
|
+
etm: h.unix()
|
|
376
376
|
}
|
|
377
|
-
}, y = await
|
|
377
|
+
}, y = await J.get(m, l).json();
|
|
378
378
|
if (g == null || g.info("[%s] fetch trajectory from: %s - %j", s.requestId, m, l), (y == null ? void 0 : y.status) !== 0)
|
|
379
379
|
return y;
|
|
380
|
-
const f = y == null ? void 0 : y.points,
|
|
381
|
-
let
|
|
382
|
-
for (const
|
|
383
|
-
const
|
|
380
|
+
const f = y == null ? void 0 : y.points, C = [], k = p.unix((b = f[0]) == null ? void 0 : b.utc);
|
|
381
|
+
let v = -1;
|
|
382
|
+
for (const c of f) {
|
|
383
|
+
const w = p.unix(c.utc), M = {
|
|
384
384
|
imo: d == null ? void 0 : d.imo,
|
|
385
385
|
mmsi: t,
|
|
386
|
-
sog: Math.round(
|
|
387
|
-
cog: Math.round(
|
|
388
|
-
lat: Math.round(
|
|
389
|
-
lng: Math.round(
|
|
390
|
-
positionTime:
|
|
391
|
-
utc:
|
|
386
|
+
sog: Math.round(c.sog * 3600 / 1e3 / 1852 * 100) / 100,
|
|
387
|
+
cog: Math.round(c.cog / 100 * 100) / 100,
|
|
388
|
+
lat: Math.round(c.lat / 1e6 * 1e5) / 1e5,
|
|
389
|
+
lng: Math.round(c.lon / 1e6 * 1e5) / 1e5,
|
|
390
|
+
positionTime: w.unix(),
|
|
391
|
+
utc: w.utc().format(),
|
|
392
392
|
method: "trajectory",
|
|
393
393
|
vendor: "shipxy"
|
|
394
|
-
},
|
|
395
|
-
|
|
394
|
+
}, u = Math.floor(w.diff(k, "minute", !0) / (o || 1));
|
|
395
|
+
u !== v && (v = u, C.push(M));
|
|
396
396
|
}
|
|
397
|
-
return
|
|
397
|
+
return C;
|
|
398
398
|
}
|
|
399
399
|
}
|
|
400
|
-
class
|
|
400
|
+
class Nt extends et {
|
|
401
401
|
constructor(t) {
|
|
402
402
|
super();
|
|
403
403
|
G(this, "token");
|
|
@@ -411,7 +411,7 @@ class Et extends tt {
|
|
|
411
411
|
json: {
|
|
412
412
|
mmsiList: t
|
|
413
413
|
}
|
|
414
|
-
}, o = "https://api3.myships.com/sp/ships/getShipIdByMMSI", a = await
|
|
414
|
+
}, o = "https://api3.myships.com/sp/ships/getShipIdByMMSI", a = await J.post(o, i).json();
|
|
415
415
|
return g == null || g.info("[%s] fetch ship id from: %s - %j", n.requestId, o, i), a.code !== "0" ? a : a.data[0].shipId;
|
|
416
416
|
}
|
|
417
417
|
async getShipInfo(t, n = {}) {
|
|
@@ -422,7 +422,7 @@ class Et extends tt {
|
|
|
422
422
|
json: {
|
|
423
423
|
shipId: t
|
|
424
424
|
}
|
|
425
|
-
}, o = "https://api3.myships.com/sp/ships/aissta", a = await
|
|
425
|
+
}, o = "https://api3.myships.com/sp/ships/aissta", a = await J.post(o, i).json();
|
|
426
426
|
if (g == null || g.info("[%s] fetch ship info from: %s - %j", n.requestId, o, i), a.code !== "0")
|
|
427
427
|
return a;
|
|
428
428
|
const s = a.data;
|
|
@@ -445,39 +445,39 @@ class Et extends tt {
|
|
|
445
445
|
json: {
|
|
446
446
|
shipId: i
|
|
447
447
|
}
|
|
448
|
-
}, s = "https://api3.myships.com/sp/ships/position/latest", d = await
|
|
448
|
+
}, s = "https://api3.myships.com/sp/ships/position/latest", d = await J.post(s, a).json();
|
|
449
449
|
g == null || g.info("[%s] fetch realtime position from: %s - %j", n.requestId, s, a);
|
|
450
|
-
const
|
|
451
|
-
for (const f in
|
|
452
|
-
!isNaN(
|
|
453
|
-
const { labelCn:
|
|
450
|
+
const r = d.data[0];
|
|
451
|
+
for (const f in r)
|
|
452
|
+
!isNaN(r[f]) && Number(r[f]) !== 1 / 0 && (r[f] = Number(r[f]));
|
|
453
|
+
const { labelCn: h, labelEn: m } = await this.parseStatus(r.aisNavStatus), l = p.unix(r.posTime);
|
|
454
454
|
return {
|
|
455
455
|
...o,
|
|
456
456
|
mmsi: t,
|
|
457
|
-
lat: Math.round(
|
|
458
|
-
lng: Math.round(
|
|
459
|
-
sog: Math.round(
|
|
460
|
-
cog: Math.round(
|
|
461
|
-
hdg: Math.round(
|
|
462
|
-
rot: Math.round(
|
|
463
|
-
positionTime:
|
|
457
|
+
lat: Math.round(r.lat / 1e4 / 60 * 1e5) / 1e5,
|
|
458
|
+
lng: Math.round(r.lon / 1e4 / 60 * 1e5) / 1e5,
|
|
459
|
+
sog: Math.round(r.sog / 10 * 100) / 100,
|
|
460
|
+
cog: Math.round(r.cog / 10 * 100) / 100,
|
|
461
|
+
hdg: Math.round(r.heading * 100) / 100,
|
|
462
|
+
rot: Math.round(r.rot * 100) / 100,
|
|
463
|
+
positionTime: r.posTime,
|
|
464
464
|
utc: l.utc().format(),
|
|
465
|
-
status:
|
|
465
|
+
status: r.aisNavStatus,
|
|
466
466
|
labelEn: m,
|
|
467
|
-
labelCn:
|
|
467
|
+
labelCn: h,
|
|
468
468
|
method: "position",
|
|
469
469
|
vendor: "myship"
|
|
470
470
|
};
|
|
471
471
|
}
|
|
472
472
|
async trajectory(t, n, i, o, a = !0, s = {}) {
|
|
473
|
-
const d =
|
|
474
|
-
for (;
|
|
475
|
-
await this.trajectoryIn30Day(
|
|
476
|
-
return await this.trajectoryIn30Day(
|
|
473
|
+
const d = p(n), r = p(i), h = await this.getShipId(t), m = await this.getShipInfo(h), l = [];
|
|
474
|
+
for (; r.diff(d, "day", !0) > 30; )
|
|
475
|
+
await this.trajectoryIn30Day(h, d.unix(), d.add(30, "day").unix(), m, t, o, l);
|
|
476
|
+
return await this.trajectoryIn30Day(h, d.unix(), r.unix(), m, t, o, l), l;
|
|
477
477
|
}
|
|
478
|
-
async trajectoryIn30Day(t, n, i, o, a, s, d,
|
|
479
|
-
var
|
|
480
|
-
const
|
|
478
|
+
async trajectoryIn30Day(t, n, i, o, a, s, d, r = {}) {
|
|
479
|
+
var k;
|
|
480
|
+
const h = {
|
|
481
481
|
headers: {
|
|
482
482
|
appKey: this.token
|
|
483
483
|
},
|
|
@@ -486,42 +486,42 @@ class Et extends tt {
|
|
|
486
486
|
startTime: n,
|
|
487
487
|
endTime: i
|
|
488
488
|
}
|
|
489
|
-
}, m = "https://api3.myships.com/sp/ships/position/history", l = await
|
|
490
|
-
if (g == null || g.info("[%s] fetch trajectory from: %s - %j",
|
|
491
|
-
return g == null || g.warn("[%s] invoke myship trajectory failed: %j",
|
|
489
|
+
}, m = "https://api3.myships.com/sp/ships/position/history", l = await J.post(m, h).json();
|
|
490
|
+
if (g == null || g.info("[%s] fetch trajectory from: %s - %j", r.requestId, m, h), l.code !== "0")
|
|
491
|
+
return g == null || g.warn("[%s] invoke myship trajectory failed: %j", r.requestId, l), l;
|
|
492
492
|
const y = l.data;
|
|
493
|
-
for (const
|
|
494
|
-
!isNaN(y[
|
|
495
|
-
const f =
|
|
496
|
-
let
|
|
497
|
-
for (const
|
|
498
|
-
const
|
|
493
|
+
for (const v in y)
|
|
494
|
+
!isNaN(y[v]) && Number(y[v]) !== 1 / 0 && (y[v] = Number(y[v]));
|
|
495
|
+
const f = p.unix((k = y[0]) == null ? void 0 : k.posTime);
|
|
496
|
+
let C = -1;
|
|
497
|
+
for (const v of y) {
|
|
498
|
+
const b = p.unix(v.posTime), c = {
|
|
499
499
|
imo: o == null ? void 0 : o.imo,
|
|
500
500
|
mmsi: a,
|
|
501
|
-
lat: Math.round(
|
|
502
|
-
lng: Math.round(
|
|
503
|
-
sog: Math.round(
|
|
504
|
-
cog: Math.round(
|
|
505
|
-
hdg: Math.round(
|
|
506
|
-
rot: Math.round(
|
|
507
|
-
positionTime:
|
|
508
|
-
utc:
|
|
501
|
+
lat: Math.round(v.lat / 1e4 / 60 * 1e5) / 1e5,
|
|
502
|
+
lng: Math.round(v.lon / 1e4 / 60 * 1e5) / 1e5,
|
|
503
|
+
sog: Math.round(v.sog / 10 * 100) / 100,
|
|
504
|
+
cog: Math.round(v.cog / 10 * 100) / 100,
|
|
505
|
+
hdg: Math.round(v.heading * 100) / 100,
|
|
506
|
+
rot: Math.round(v.rot * 100) / 100,
|
|
507
|
+
positionTime: b.unix(),
|
|
508
|
+
utc: b.utc().format(),
|
|
509
509
|
method: "trajectory",
|
|
510
510
|
vendor: "myship"
|
|
511
|
-
},
|
|
512
|
-
|
|
511
|
+
}, w = Math.floor(b.diff(f, "minute", !0) / (s || 1));
|
|
512
|
+
w !== C && (C = w, d.push(c));
|
|
513
513
|
}
|
|
514
514
|
return d;
|
|
515
515
|
}
|
|
516
516
|
}
|
|
517
|
-
let
|
|
517
|
+
let _;
|
|
518
518
|
try {
|
|
519
|
-
|
|
519
|
+
_ = nt.getLogger("vessel");
|
|
520
520
|
} catch {
|
|
521
521
|
} finally {
|
|
522
522
|
}
|
|
523
|
-
var
|
|
524
|
-
class
|
|
523
|
+
var mt = /* @__PURE__ */ ((j) => (j.NOTICE = "NOTICE", j.WARN = "WARN", j.HEAVY = "HEAVY", j.SEVERE = "SEVERE", j.ERROR = "ERROR", j.FATAL = "FATAL", j))(mt || {});
|
|
524
|
+
class yt {
|
|
525
525
|
/**
|
|
526
526
|
* 解析告警规则, 多规则场景
|
|
527
527
|
* @param rule
|
|
@@ -531,15 +531,15 @@ class mt {
|
|
|
531
531
|
* @param options
|
|
532
532
|
*/
|
|
533
533
|
parsePrinciple(e, t = {}) {
|
|
534
|
-
var s, d,
|
|
535
|
-
|
|
534
|
+
var s, d, r;
|
|
535
|
+
_ == null || _.info("[%s] parse rule: %s", t.requestId, e);
|
|
536
536
|
const n = new RegExp("(?<=\\[)(.+)(?=])", "g"), i = e.match(n) ? (s = e.match(n)) == null ? void 0 : s[0] : void 0, o = i == null ? void 0 : i.split(";");
|
|
537
537
|
if (!o)
|
|
538
538
|
return;
|
|
539
539
|
const a = {};
|
|
540
|
-
for (let
|
|
541
|
-
const m = (
|
|
542
|
-
if (
|
|
540
|
+
for (let h = 0; h < (o == null ? void 0 : o.length); h++) {
|
|
541
|
+
const m = (r = (d = o[h].match(n)) == null ? void 0 : d[0]) == null ? void 0 : r.split("],");
|
|
542
|
+
if (h === 0 && !m)
|
|
543
543
|
a.scope = o[0];
|
|
544
544
|
else if (m)
|
|
545
545
|
for (let l = 0, y = m.length; l < y; l++) {
|
|
@@ -557,7 +557,7 @@ class mt {
|
|
|
557
557
|
*/
|
|
558
558
|
parseRule(e, t = {}) {
|
|
559
559
|
var a;
|
|
560
|
-
|
|
560
|
+
_ == null || _.info("[%s] parse rule: %s", t.requestId, e), e = e.startsWith("[") ? e : `[${e}`, e = e.endsWith("]") ? e : `${e}]`;
|
|
561
561
|
const n = new RegExp("(?<=\\[)(.+?)(?=])", "g"), i = (a = e == null ? void 0 : e.match(n)) == null ? void 0 : a[0], o = i == null ? void 0 : i.split(",");
|
|
562
562
|
if (o)
|
|
563
563
|
return {
|
|
@@ -575,25 +575,25 @@ class mt {
|
|
|
575
575
|
* @param options
|
|
576
576
|
*/
|
|
577
577
|
checkWeather(e, t, n = {}) {
|
|
578
|
-
var f,
|
|
578
|
+
var f, C, k, v, b, c, w, M, u, I, S, D, Y, N, P;
|
|
579
579
|
let i = 0, o = 0, a = 0, s = 0;
|
|
580
|
-
const d = Math.round(((
|
|
581
|
-
for (let
|
|
582
|
-
const
|
|
583
|
-
s = K > s ? K : s,
|
|
580
|
+
const d = Math.round(((C = (f = t == null ? void 0 : t.SEVERE) == null ? void 0 : f.sigWave) == null ? void 0 : C.number) * 1.6 * 100) / 100, r = (v = (k = t == null ? void 0 : t.SEVERE) == null ? void 0 : k.sigWave) == null ? void 0 : v.number, h = (c = (b = t == null ? void 0 : t.HEAVY) == null ? void 0 : b.sigWave) == null ? void 0 : c.number, m = Math.round((((M = (w = t == null ? void 0 : t.SEVERE) == null ? void 0 : w.wind) == null ? void 0 : M.number) + 2) * 100) / 100, l = (I = (u = t == null ? void 0 : t.SEVERE) == null ? void 0 : u.wind) == null ? void 0 : I.number, y = (D = (S = t == null ? void 0 : t.HEAVY) == null ? void 0 : S.wind) == null ? void 0 : D.number;
|
|
581
|
+
for (let T = 0; T < (e == null ? void 0 : e.length); T++) {
|
|
582
|
+
const E = e[T], A = (N = (Y = E == null ? void 0 : E.meteo) == null ? void 0 : Y.wave) == null ? void 0 : N.sig, R = (P = E == null ? void 0 : E.meteo) == null ? void 0 : P.wind, K = T ? p(E.eta).diff(p(e[T - 1].eta), "hour", !0) : 0;
|
|
583
|
+
s = K > s ? K : s, _ == null || _.info("[%s] check sig.wave: %j", n.requestId, { ...A, dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: h }), (A == null ? void 0 : A.height) >= d ? E.isDangerous = !0 : (A == null ? void 0 : A.height) >= r ? E.isSevere = !0 : (A == null ? void 0 : A.height) >= h && (E.isHeavy = !0), _ == null || _.info("[%s] check wind: %j", n.requestId, { ...R, dgThd4Wd: m, svThd4Wd: l, hvThd4Wd: y }), (R == null ? void 0 : R.scale) >= m ? (E.isDangerous = !0, delete E.isSevere, delete E.isHeavy) : (R == null ? void 0 : R.scale) > l ? (E.isDangerous || (E.isSevere = !0), delete E.isHeavy) : (R == null ? void 0 : R.scale) === y && !E.isDangerous && !E.isSevere && (E.isHeavy = !0), i += E.isDangerous ? K : 0, o += E.isSevere ? K : 0, a += E.isHeavy ? K : 0;
|
|
584
584
|
}
|
|
585
|
-
return i = Math.round(i * 100) / 100, o = Math.round(o * 100) / 100, a = Math.round(a * 100) / 100, s = Math.round(s), { sample: e, dangerous: i, severe: o, heavy: a, step: s < 3 ? 3 : s, wind: { dgThd4Wd: m, svThd4Wd: l, hvThd4Wd: y }, sig: { dgThd4Wv: d, svThd4Wv:
|
|
585
|
+
return i = Math.round(i * 100) / 100, o = Math.round(o * 100) / 100, a = Math.round(a * 100) / 100, s = Math.round(s), { sample: e, dangerous: i, severe: o, heavy: a, step: s < 3 ? 3 : s, wind: { dgThd4Wd: m, svThd4Wd: l, hvThd4Wd: y }, sig: { dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: h } };
|
|
586
586
|
}
|
|
587
587
|
}
|
|
588
|
-
const
|
|
589
|
-
let
|
|
588
|
+
const Tt = new yt();
|
|
589
|
+
let F;
|
|
590
590
|
try {
|
|
591
|
-
|
|
591
|
+
F = nt.getLogger("vessel");
|
|
592
592
|
} catch {
|
|
593
593
|
} finally {
|
|
594
594
|
}
|
|
595
|
-
const
|
|
596
|
-
var
|
|
595
|
+
const Mt = new lt("", !0);
|
|
596
|
+
var gt = /* @__PURE__ */ ((j) => (j.common = "common", j.container = "container", j.tugs = "tugs", j))(gt || {}), pt = /* @__PURE__ */ ((j) => (j.Ballast = "Ballast", j.Laden = "Laden", j))(pt || {}), wt = /* @__PURE__ */ ((j) => (j.Cp = "CP", j.Perf = "Basis", j.Instruct = "Other", j))(wt || {});
|
|
597
597
|
class O {
|
|
598
598
|
/**
|
|
599
599
|
* @see https://baike.baidu.com/item/%E6%96%B9%E5%BD%A2%E7%B3%BB%E6%95%B0/4965568?fr=aladdin
|
|
@@ -707,9 +707,9 @@ class O {
|
|
|
707
707
|
*/
|
|
708
708
|
static assembleProperties(e, t, n, i) {
|
|
709
709
|
var l;
|
|
710
|
-
const o = e.lbp ?? e.length ?? e.lengthOverall ?? 198.9642, a = e.draught ?? 8, s = e.breadthMoulded ?? e.breadth ?? e.breadthExtreme ?? 32.4572, d = e.deadweight ?? 67035.7773,
|
|
710
|
+
const o = e.lbp ?? e.length ?? e.lengthOverall ?? 198.9642, a = e.draught ?? 8, s = e.breadthMoulded ?? e.breadth ?? e.breadthExtreme ?? 32.4572, d = e.deadweight ?? 67035.7773, r = ((l = e == null ? void 0 : e.type) == null ? void 0 : l.toLowerCase()) || "common";
|
|
711
711
|
return {
|
|
712
|
-
tag:
|
|
712
|
+
tag: r.indexOf("container") > -1 ? "container" : r.indexOf("tugs") > -1 ? "tugs" : "common",
|
|
713
713
|
lbp: o,
|
|
714
714
|
loadCondition: t,
|
|
715
715
|
draught: a,
|
|
@@ -733,21 +733,21 @@ class O {
|
|
|
733
733
|
* @param useRouteParam true 启用设置速度
|
|
734
734
|
*/
|
|
735
735
|
static async speedLoseAt(e, t, n, i = "", o = 2, a = !0, s = !1, d = {}) {
|
|
736
|
-
let
|
|
737
|
-
if (t.velocity && s && (e.speed =
|
|
738
|
-
let
|
|
736
|
+
let r;
|
|
737
|
+
if (t.velocity && s && (e.speed = B.roundPrecision(t.velocity * 1852 / 3600, 6)), a) {
|
|
738
|
+
let h;
|
|
739
739
|
if (d.meteo2)
|
|
740
740
|
try {
|
|
741
|
-
const f = await
|
|
742
|
-
|
|
741
|
+
const f = await Mt.spotForecast(t.lat, t.lng, n.utc().format(), !1, !1, !0, d), [C] = rt.pickHourly(f, n);
|
|
742
|
+
h = rt.toLegacy(C);
|
|
743
743
|
} catch (f) {
|
|
744
|
-
|
|
744
|
+
F.warn("[%s] meteo2 spot(%j) forecast failed: %s", d.requestId, { ...t, eta: n.utc().format() }, f);
|
|
745
745
|
}
|
|
746
746
|
else
|
|
747
|
-
|
|
748
|
-
const m = O.weatherFactor(e,
|
|
749
|
-
|
|
750
|
-
meteo: { ...
|
|
747
|
+
h = await ft.queryPointFactor(t.lng, t.lat, n.valueOf(), "wind,wave,current,watertemp", i, d);
|
|
748
|
+
const m = O.weatherFactor(e, h), l = O.currentFactor(e.bearing, h == null ? void 0 : h.current, o), y = Math.round((e.speed * 1.943844 + m + l) * 100) / 100;
|
|
749
|
+
r = {
|
|
750
|
+
meteo: { ...h },
|
|
751
751
|
wxFactor: m,
|
|
752
752
|
cFactor: l,
|
|
753
753
|
speed: t.velocity && s ? t.velocity : y < 0 ? 1 : y,
|
|
@@ -755,14 +755,14 @@ class O {
|
|
|
755
755
|
etd: n.utc().format()
|
|
756
756
|
};
|
|
757
757
|
} else
|
|
758
|
-
|
|
758
|
+
r = {
|
|
759
759
|
wxFactor: 0,
|
|
760
760
|
cFactor: 0,
|
|
761
761
|
speed: t.velocity && s ? t.velocity : Math.round((e.speed * 1.943844 + 0 + 0) * 100) / 100,
|
|
762
762
|
eta: n.utc().format(),
|
|
763
763
|
etd: n.utc().format()
|
|
764
764
|
};
|
|
765
|
-
return delete t.meteo, delete t.wxFactor, delete t.cFactor, delete t.speed, delete t.etd, { ...
|
|
765
|
+
return delete t.meteo, delete t.wxFactor, delete t.cFactor, delete t.speed, delete t.etd, { ...r, ...t };
|
|
766
766
|
}
|
|
767
767
|
/**
|
|
768
768
|
* 基于步长计算失速样本
|
|
@@ -777,53 +777,53 @@ class O {
|
|
|
777
777
|
* @param useRouteParam true 启用航线上设置的参数 { suspend: 停留时长(小时), velocity: 速度(kts)}
|
|
778
778
|
* @private
|
|
779
779
|
*/
|
|
780
|
-
static async speedLoseInHoursStep(e, t, n, i, o, a, s = "", d = !0,
|
|
780
|
+
static async speedLoseInHoursStep(e, t, n, i, o, a, s = "", d = !0, r = !1, h = {}) {
|
|
781
781
|
t.utc();
|
|
782
782
|
const m = t.clone().add(14, "days"), l = [], y = [];
|
|
783
|
-
let f = 0,
|
|
784
|
-
for (let
|
|
785
|
-
let
|
|
786
|
-
|
|
787
|
-
const
|
|
788
|
-
if (e.bearing =
|
|
789
|
-
|
|
790
|
-
const
|
|
791
|
-
if (i - f >
|
|
792
|
-
i = i - f -
|
|
783
|
+
let f = 0, C = 0, k, v;
|
|
784
|
+
for (let b = 0; b < a.length - 1; b++) {
|
|
785
|
+
let c = a[b];
|
|
786
|
+
c.distanceFromStart = Math.round((o + C) * 1e4) / 1e4;
|
|
787
|
+
const w = a[b + 1];
|
|
788
|
+
if (e.bearing = L.calculateBearing(c, w, !w.gcToPrevious), c.bearing = e.bearing, c.suspend && r) {
|
|
789
|
+
c.eta = c.eta || t.utc().format(), c.elapsed = c.elapsed ?? 0;
|
|
790
|
+
const I = c.suspend - c.elapsed;
|
|
791
|
+
if (i - f > I)
|
|
792
|
+
i = i - f - I, t.add(I, "hour"), c.elapsed = c.suspend;
|
|
793
793
|
else {
|
|
794
|
-
const
|
|
795
|
-
|
|
794
|
+
const S = i - f;
|
|
795
|
+
c.elapsed += S, t.add(S, "hour"), i = 0;
|
|
796
796
|
}
|
|
797
|
-
if (
|
|
798
|
-
return
|
|
797
|
+
if (F == null || F.info(`[%s] suspend ${c.elapsed} hours at %j, and remain ${i} hours need to go...`, h.requestId, c), i === 0)
|
|
798
|
+
return c.distanceFromPrevious = C, { etd: t, from: v || c, to: c, next: a.filter((S) => S), wps: l, days: y };
|
|
799
799
|
} else
|
|
800
|
-
|
|
801
|
-
d = t.isAfter(m) ? !1 : d,
|
|
802
|
-
const M =
|
|
803
|
-
let
|
|
804
|
-
if (f +
|
|
805
|
-
if (f +=
|
|
806
|
-
`[%s] go to %j from %j with ${M}nm, and cost ${
|
|
807
|
-
|
|
808
|
-
{ lat:
|
|
809
|
-
{ lat:
|
|
810
|
-
),
|
|
811
|
-
|
|
800
|
+
c.suspend = 0;
|
|
801
|
+
d = t.isAfter(m) ? !1 : d, c = await O.speedLoseAt(e, c, t, s, 0, d, r, h), v = v || c, c.important && l.push(c), t.isSameOrAfter(n) && (y.push(c), n.add(24, "hour"));
|
|
802
|
+
const M = L.calculateDistance(c, w, !w.gcToPrevious);
|
|
803
|
+
let u = Math.round(M / v.speed * 1e5) / 1e5;
|
|
804
|
+
if (f + u < i) {
|
|
805
|
+
if (f += u, t.add(u, "hour"), delete a[b], F == null || F.debug(
|
|
806
|
+
`[%s] go to %j from %j with ${M}nm, and cost ${u} hours`,
|
|
807
|
+
h.requestId,
|
|
808
|
+
{ lat: w.lat, lng: w.lng },
|
|
809
|
+
{ lat: v.lat, lng: v.lng, etd: v.etd }
|
|
810
|
+
), C += M, a.filter((I) => I).length <= 1) {
|
|
811
|
+
k = w, k.eta = t.utc().format(), k.distanceFromPrevious = M, k.distanceFromStart = Math.round((o + C) * 1e4) / 1e4, l.push(k), delete a[b + 1];
|
|
812
812
|
break;
|
|
813
813
|
}
|
|
814
814
|
} else {
|
|
815
|
-
|
|
816
|
-
const
|
|
817
|
-
|
|
818
|
-
`[%s] go to %j from %j with ${
|
|
819
|
-
|
|
820
|
-
{ lat:
|
|
821
|
-
{ lat:
|
|
822
|
-
),
|
|
815
|
+
u = i - f, t.add(u, "hour");
|
|
816
|
+
const I = B.roundPrecision(v.speed * u, 5);
|
|
817
|
+
k = L.calculateCoordinate(c, e.bearing, I, "nauticalmiles", !w.gcToPrevious), k.eta = t.utc().format(), a[b] = k, F == null || F.debug(
|
|
818
|
+
`[%s] go to %j from %j with ${I}nm, and cost ${u} hours`,
|
|
819
|
+
h.requestId,
|
|
820
|
+
{ lat: k.lat, lng: k.lng },
|
|
821
|
+
{ lat: c.lat, lng: c.lng, etd: c.etd }
|
|
822
|
+
), C += I, k.distanceFromPrevious = Math.round(C * 1e4) / 1e4, k.distanceFromStart = Math.round((o + C) * 1e4) / 1e4;
|
|
823
823
|
break;
|
|
824
824
|
}
|
|
825
825
|
}
|
|
826
|
-
return { etd: t, from:
|
|
826
|
+
return { etd: t, from: v, to: k, next: a.filter((b) => b), wps: l, days: y };
|
|
827
827
|
}
|
|
828
828
|
/**
|
|
829
829
|
* 洋流影响因子
|
|
@@ -844,16 +844,16 @@ class O {
|
|
|
844
844
|
* @param wwc 气象要素
|
|
845
845
|
*/
|
|
846
846
|
static weatherFactor(e, t) {
|
|
847
|
-
var m, l, y, f,
|
|
848
|
-
|
|
847
|
+
var m, l, y, f, C, k, v;
|
|
848
|
+
F == null || F.debug("calculate weather factor via: %j", { ...e, ...t });
|
|
849
849
|
const n = O.blockCoefficient(e.displacement, e.lbp, e.breadthMoulded, e.draught), i = O.froudeNumber(e.speed, e.lbp), o = O.amendFactor(n, i, e.loadCondition);
|
|
850
850
|
let a = Math.abs(e.bearing % 360 - (((m = t == null ? void 0 : t.wind) == null ? void 0 : m.degree) % 360 || 0));
|
|
851
851
|
a = a > 180 ? 360 - a : a;
|
|
852
852
|
const s = O.directionFactor(a, (l = t == null ? void 0 : t.wind) == null ? void 0 : l.scale), d = O.vesselTagFactor(e.displacement, e.loadCondition, e.tag, (y = t == null ? void 0 : t.wind) == null ? void 0 : y.scale);
|
|
853
|
-
let
|
|
854
|
-
|
|
855
|
-
const
|
|
856
|
-
return
|
|
853
|
+
let r = s * o * d / 100 * e.speed;
|
|
854
|
+
r = Math.round(r * 1.943844 * 1e4) / 1e4 * -1, e.tag === "tugs" && Math.abs(r) > 1 && (r = r / (Math.abs(Math.round(r)) + 1)), F == null || F.debug("wind wx factor = %d", r), a = Math.abs(e.bearing % 360 - (((C = (f = t == null ? void 0 : t.wave) == null ? void 0 : f.sig) == null ? void 0 : C.degree) % 360 || 0));
|
|
855
|
+
const h = O.waveHeightFactor(((v = (k = t == null ? void 0 : t.wave) == null ? void 0 : k.sig) == null ? void 0 : v.height) ?? 1, a);
|
|
856
|
+
return F == null || F.debug("wave wx factor = %d", h), r = r * 0.4 + h, F == null || F.debug("weather factor = %d", r), r = Math.abs(r) > 4 ? 4 * (Math.abs(r) / r) + Math.abs(r) / r * (Math.abs(r) - 4) * 0.1 : r, Math.round((r || 0) * 100) / 100;
|
|
857
857
|
}
|
|
858
858
|
/**
|
|
859
859
|
* 全程失速分析(走完航程)
|
|
@@ -867,14 +867,14 @@ class O {
|
|
|
867
867
|
* @param useMeteo true 启用气象分析
|
|
868
868
|
* @param useRouteParam
|
|
869
869
|
*/
|
|
870
|
-
static async analyseInstant(e, t, n, i, o, a = "", s = 0, d = !0,
|
|
871
|
-
var z, U, Q, X, Z
|
|
872
|
-
const m =
|
|
873
|
-
e.lng =
|
|
874
|
-
const { route: l, waypoints: y } = o.points, f =
|
|
870
|
+
static async analyseInstant(e, t, n, i, o, a = "", s = 0, d = !0, r = !1, h = {}) {
|
|
871
|
+
var z, U, Q, X, Z, $;
|
|
872
|
+
const m = p().valueOf();
|
|
873
|
+
e.lng = B.convertToStdLng(e.lng);
|
|
874
|
+
const { route: l, waypoints: y } = o.points, f = L.calculateSubRoute(e, l);
|
|
875
875
|
if (((z = f[0]) == null ? void 0 : z.length) <= 1)
|
|
876
876
|
return;
|
|
877
|
-
const { v0:
|
|
877
|
+
const { v0: C, label: k } = e.sog ? {
|
|
878
878
|
v0: e.sog,
|
|
879
879
|
label: "Other"
|
|
880
880
|
/* Instruct */
|
|
@@ -882,60 +882,60 @@ class O {
|
|
|
882
882
|
v0: i.speed,
|
|
883
883
|
label: "CP"
|
|
884
884
|
/* Cp */
|
|
885
|
-
},
|
|
886
|
-
|
|
887
|
-
const
|
|
885
|
+
}, v = O.assembleProperties(n, i.loadCondition, C, 0), b = y.length ? L.calculateSubWaypoints(e, y) : [];
|
|
886
|
+
b.forEach((q) => q.important = !0);
|
|
887
|
+
const c = {
|
|
888
888
|
from: { ...e },
|
|
889
889
|
route: f,
|
|
890
|
-
waypoints:
|
|
891
|
-
v0:
|
|
892
|
-
label:
|
|
893
|
-
},
|
|
890
|
+
waypoints: b,
|
|
891
|
+
v0: C,
|
|
892
|
+
label: k
|
|
893
|
+
}, w = {
|
|
894
894
|
hours: [],
|
|
895
895
|
days: [],
|
|
896
896
|
wps: []
|
|
897
897
|
};
|
|
898
|
-
s || (
|
|
899
|
-
let M =
|
|
900
|
-
t =
|
|
898
|
+
s || (L.calculateRouteDistance(f) / i.speed <= 72 ? s = 3 : s = 6);
|
|
899
|
+
let M = L.simplifyRouteToCoordinates(f, b, 0), u = 0, I = 0, S = 0, D = 0;
|
|
900
|
+
t = p(t).utc();
|
|
901
901
|
const Y = t.clone();
|
|
902
902
|
for (; M.length > 0; ) {
|
|
903
|
-
const
|
|
904
|
-
|
|
903
|
+
const q = s - t.hour() % s, V = Math.ceil(t.clone().add(q, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4, x = await O.speedLoseInHoursStep(
|
|
904
|
+
v,
|
|
905
905
|
t,
|
|
906
906
|
Y,
|
|
907
|
-
|
|
908
|
-
|
|
907
|
+
V,
|
|
908
|
+
u,
|
|
909
909
|
M,
|
|
910
910
|
a,
|
|
911
911
|
d,
|
|
912
|
-
|
|
913
|
-
|
|
912
|
+
r,
|
|
913
|
+
h
|
|
914
914
|
);
|
|
915
|
-
(U =
|
|
915
|
+
(U = x.from) != null && U.speed && (w.hours.push(x.from), w.wps.push(...x.wps), w.days.push(...x.days)), M = x == null ? void 0 : x.next, M.length || w.hours.push(x == null ? void 0 : x.to), u += Math.round((((Q = x == null ? void 0 : x.to) == null ? void 0 : Q.distanceFromPrevious) ?? 0) * 1e4) / 1e4;
|
|
916
916
|
}
|
|
917
|
-
const
|
|
918
|
-
for (let
|
|
919
|
-
const
|
|
920
|
-
|
|
917
|
+
const N = w.hours;
|
|
918
|
+
for (let q = 0; q < N.length - 1; q++) {
|
|
919
|
+
const V = p(N[q + 1].eta).diff(N[q].etd, "hour", !0) || 1;
|
|
920
|
+
I += (N[q].wxFactor || 0) * V, S += (N[q].cFactor || 0) * V, D += V;
|
|
921
921
|
}
|
|
922
|
-
(X =
|
|
923
|
-
if (
|
|
924
|
-
const
|
|
925
|
-
q
|
|
922
|
+
(X = w.wps) == null || X.forEach((q, V) => {
|
|
923
|
+
if (q.positionTime = p.utc(q.etd || q.eta).unix(), V) {
|
|
924
|
+
const x = w.wps[V - 1], W = q.distanceFromStart - x.distanceFromStart, H = p(q.eta).diff(p(x.etd), "h", !0);
|
|
925
|
+
q.avgSpd = Math.round(W / H * 100) / 100;
|
|
926
926
|
}
|
|
927
|
-
}),
|
|
928
|
-
const
|
|
929
|
-
|
|
930
|
-
const { distanceInECA:
|
|
931
|
-
|
|
927
|
+
}), w.wps = (Z = w.wps) == null ? void 0 : Z.reduce((q, V) => (q.some((x) => x.positionTime === V.positionTime) || q.push(V), q), []), c.sample = w;
|
|
928
|
+
const P = w.hours.at(0), T = w.hours.at(-1);
|
|
929
|
+
c.distance = Math.round(T.distanceFromStart * 1e4) / 1e4, c.etd = p(P.eta).utc().format(), c.eta = p(T.eta).utc().format(), c.wxFactor = Math.round(I / D * 1e4) / 1e4, c.cFactor = Math.round(S / D * 1e4) / 1e4, c.avgSpeed = Math.round(T.distanceFromStart / D * 1e4) / 1e4, c.totalHrs = Math.round(D * 1e4) / 1e4;
|
|
930
|
+
const { distanceInECA: E, hoursInECA: A, totalDgoConsInECA: R, eca: K } = await this.calculateECA(c, i, h), st = B.roundPrecision(i.fo / 24 * (D - A), 3), at = B.roundPrecision(i.dgo / 24 * D, 3);
|
|
931
|
+
c.extend = {
|
|
932
932
|
eca: K,
|
|
933
|
-
distanceInECA:
|
|
933
|
+
distanceInECA: E,
|
|
934
934
|
hoursInECA: A,
|
|
935
935
|
totalDgoConsInECA: R
|
|
936
|
-
},
|
|
937
|
-
const
|
|
938
|
-
return
|
|
936
|
+
}, c.totalFoCons = st, c.totalDgoCons = at;
|
|
937
|
+
const tt = p().valueOf() - m, ot = (($ = w == null ? void 0 : w.hours) == null ? void 0 : $.length) || 1;
|
|
938
|
+
return F == null || F.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", h == null ? void 0 : h.requestId, tt, ot, Math.round(tt / ot * 1e3) / 1e3), c;
|
|
939
939
|
}
|
|
940
940
|
/**
|
|
941
941
|
* 分段失速分析(最多走hours 小时)
|
|
@@ -950,11 +950,11 @@ class O {
|
|
|
950
950
|
* @param useMeteo true 启用气象分析
|
|
951
951
|
* @param useRouteParam
|
|
952
952
|
*/
|
|
953
|
-
static async analyseInstantWithThreshed(e, t, n, i, o, a, s, d = "",
|
|
954
|
-
var Q, X, Z,
|
|
955
|
-
const y =
|
|
956
|
-
e.lng =
|
|
957
|
-
const { v0: f, label:
|
|
953
|
+
static async analyseInstantWithThreshed(e, t, n, i, o, a, s, d = "", r = 3, h = !0, m = !1, l = {}) {
|
|
954
|
+
var Q, X, Z, $, q, V;
|
|
955
|
+
const y = p().valueOf();
|
|
956
|
+
e.lng = B.convertToStdLng(e.lng);
|
|
957
|
+
const { v0: f, label: C } = e.sog ? {
|
|
958
958
|
v0: e.sog,
|
|
959
959
|
label: "Other"
|
|
960
960
|
/* Instruct */
|
|
@@ -962,63 +962,63 @@ class O {
|
|
|
962
962
|
v0: o.speed,
|
|
963
963
|
label: "CP"
|
|
964
964
|
/* Cp */
|
|
965
|
-
},
|
|
966
|
-
if (((Q =
|
|
965
|
+
}, k = O.assembleProperties(i, o.loadCondition, f, 0), v = L.calculateSubRoute(e, a);
|
|
966
|
+
if (((Q = v[0]) == null ? void 0 : Q.length) <= 1)
|
|
967
967
|
return;
|
|
968
|
-
const
|
|
969
|
-
|
|
970
|
-
let
|
|
971
|
-
const
|
|
968
|
+
const b = s.length ? L.calculateSubWaypoints(e, s) : [];
|
|
969
|
+
b.forEach((x) => x.important = !0);
|
|
970
|
+
let c = L.simplifyRouteToCoordinates(v, b, 0), w = 0, M = 0, u = 0, I = 0;
|
|
971
|
+
const S = {
|
|
972
972
|
hours: [],
|
|
973
973
|
wps: [],
|
|
974
974
|
days: []
|
|
975
975
|
};
|
|
976
|
-
t =
|
|
977
|
-
const
|
|
978
|
-
for (;
|
|
979
|
-
const
|
|
980
|
-
let
|
|
981
|
-
|
|
982
|
-
const
|
|
983
|
-
if ((X =
|
|
976
|
+
t = p(t).utc();
|
|
977
|
+
const D = t.clone();
|
|
978
|
+
for (; c.length > 0; ) {
|
|
979
|
+
const x = r - t.hour() % r;
|
|
980
|
+
let W = Math.ceil(t.clone().add(x, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4;
|
|
981
|
+
W = t.clone().add(W, "h").isSameOrAfter(n) ? n.diff(t, "h", !0) * 1e4 / 1e4 : W;
|
|
982
|
+
const H = await O.speedLoseInHoursStep(k, t, D, W, w, c, d, h, m, l);
|
|
983
|
+
if ((X = H.from) != null && X.speed && (S.hours.push(H.from), H != null && H.wps && S.wps.push(...H.wps), S.days.push(...H.days)), c = H == null ? void 0 : H.next, c.length || S.hours.push(H == null ? void 0 : H.to), w += Math.round((((Z = H == null ? void 0 : H.to) == null ? void 0 : Z.distanceFromPrevious) ?? 0) * 1e4) / 1e4, !W)
|
|
984
984
|
break;
|
|
985
985
|
}
|
|
986
|
-
(H =
|
|
987
|
-
if (
|
|
988
|
-
const
|
|
989
|
-
|
|
986
|
+
S.wps = ($ = S.wps) == null ? void 0 : $.reduce((x, W) => (x.some((H) => H.etd === W.etd) || x.push(W), x), []), (q = S.wps) == null || q.forEach((x, W) => {
|
|
987
|
+
if (W) {
|
|
988
|
+
const H = S.wps[W - 1], ct = x.distanceFromStart - H.distanceFromStart, dt = p(x.eta).diff(p(H.etd), "h", !0);
|
|
989
|
+
x.avgSpd = Math.round(ct / dt * 100) / 100;
|
|
990
990
|
}
|
|
991
991
|
});
|
|
992
|
-
const Y =
|
|
993
|
-
for (let
|
|
994
|
-
const
|
|
995
|
-
M += Y[
|
|
992
|
+
const Y = S.hours;
|
|
993
|
+
for (let x = 0; x < Y.length - 1; x++) {
|
|
994
|
+
const W = p(Y[x + 1].eta).diff(Y[x].etd, "hour", !0);
|
|
995
|
+
M += Y[x].wxFactor * W, u += Y[x].cFactor * W, I += W;
|
|
996
996
|
}
|
|
997
|
-
const
|
|
998
|
-
sample:
|
|
999
|
-
distance: Math.round(((
|
|
997
|
+
const N = S.hours.at(0), P = S.hours.at(-1), T = await L.calculateRangeRoute(N, P, v), E = await L.calculateRangeWaypoints(N, P, v, b), A = {
|
|
998
|
+
sample: S,
|
|
999
|
+
distance: Math.round(((P == null ? void 0 : P.distanceFromStart) || 0) * 1e4) / 1e4,
|
|
1000
1000
|
// 注意,可能会在first节点Drift,所有采用eta做为初始出发时间
|
|
1001
|
-
etd:
|
|
1002
|
-
eta:
|
|
1003
|
-
wxFactor: Math.round(M /
|
|
1004
|
-
cFactor: Math.round(
|
|
1005
|
-
avgSpeed: Math.round(((
|
|
1006
|
-
totalHrs: Math.round(
|
|
1007
|
-
from:
|
|
1008
|
-
to:
|
|
1009
|
-
route:
|
|
1010
|
-
waypoints:
|
|
1001
|
+
etd: p(N.eta).utc().format(),
|
|
1002
|
+
eta: p(P == null ? void 0 : P.eta).utc().format(),
|
|
1003
|
+
wxFactor: Math.round(M / I * 1e4) / 1e4,
|
|
1004
|
+
cFactor: Math.round(u / I * 1e4) / 1e4,
|
|
1005
|
+
avgSpeed: Math.round(((P == null ? void 0 : P.distanceFromStart) || 0) / I * 1e4) / 1e4,
|
|
1006
|
+
totalHrs: Math.round(I * 1e4) / 1e4,
|
|
1007
|
+
from: N,
|
|
1008
|
+
to: P,
|
|
1009
|
+
route: T,
|
|
1010
|
+
waypoints: E,
|
|
1011
1011
|
v0: f,
|
|
1012
|
-
label:
|
|
1013
|
-
}, { distanceInECA: R, hoursInECA: K, totalDgoConsInECA:
|
|
1012
|
+
label: C
|
|
1013
|
+
}, { distanceInECA: R, hoursInECA: K, totalDgoConsInECA: st, eca: at } = await this.calculateECA(A, o, l), it = B.roundPrecision(o.fo / 24 * (I - K), 3), tt = B.roundPrecision(o.dgo / 24 * I, 3);
|
|
1014
1014
|
A.extend = {
|
|
1015
|
-
eca:
|
|
1015
|
+
eca: at,
|
|
1016
1016
|
distanceInECA: R,
|
|
1017
1017
|
hoursInECA: K,
|
|
1018
|
-
totalDgoConsInECA:
|
|
1019
|
-
}, A.totalDgoCons =
|
|
1020
|
-
const z =
|
|
1021
|
-
return
|
|
1018
|
+
totalDgoConsInECA: st
|
|
1019
|
+
}, A.totalDgoCons = tt, A.totalFoCons = it;
|
|
1020
|
+
const z = p().valueOf() - y, U = ((V = S == null ? void 0 : S.hours) == null ? void 0 : V.length) || 1;
|
|
1021
|
+
return F == null || F.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", l == null ? void 0 : l.requestId, z, U, Math.round(z / U * 1e3) / 1e3), A;
|
|
1022
1022
|
}
|
|
1023
1023
|
/**
|
|
1024
1024
|
* 在指定航线条件下,基于多CP,动态计算最优成本(租金+油费)方案
|
|
@@ -1036,25 +1036,25 @@ class O {
|
|
|
1036
1036
|
* @param options
|
|
1037
1037
|
*/
|
|
1038
1038
|
static async analyseCost(e, t, n, i, o = {}) {
|
|
1039
|
-
var
|
|
1040
|
-
const a =
|
|
1039
|
+
var v, b;
|
|
1040
|
+
const a = p().valueOf(), s = [];
|
|
1041
1041
|
o.meteo2 = o.meteo2 || !0, e.speedStep = e.speedStep || 3, e.alterStep = e.alterStep ?? 1;
|
|
1042
|
-
const d =
|
|
1043
|
-
let
|
|
1044
|
-
n.forEach((
|
|
1045
|
-
const
|
|
1046
|
-
|
|
1047
|
-
}),
|
|
1048
|
-
const
|
|
1042
|
+
const d = L.calculateRouteDistance(i.route);
|
|
1043
|
+
let r = 0;
|
|
1044
|
+
n.forEach((c) => {
|
|
1045
|
+
const w = Math.ceil(d / c.speed / 24);
|
|
1046
|
+
r = r < w ? w : r;
|
|
1047
|
+
}), r = r * 1.3;
|
|
1048
|
+
const h = p.utc(e.etd).add(r ?? 14, "day");
|
|
1049
1049
|
let m = 1;
|
|
1050
|
-
for (const
|
|
1051
|
-
const
|
|
1050
|
+
for (const c of n) {
|
|
1051
|
+
const w = JSON.parse(JSON.stringify(i.route)), M = JSON.parse(JSON.stringify(i.waypoints)), u = await O.analyseInstantWithThreshed(
|
|
1052
1052
|
{ lat: e.lat, lng: e.lng },
|
|
1053
1053
|
e.etd,
|
|
1054
|
-
|
|
1054
|
+
h,
|
|
1055
1055
|
t,
|
|
1056
|
-
|
|
1057
|
-
|
|
1056
|
+
c,
|
|
1057
|
+
w,
|
|
1058
1058
|
M,
|
|
1059
1059
|
e.meteoVendor,
|
|
1060
1060
|
e.speedStep,
|
|
@@ -1062,30 +1062,30 @@ class O {
|
|
|
1062
1062
|
e.useRouteParam,
|
|
1063
1063
|
o
|
|
1064
1064
|
);
|
|
1065
|
-
|
|
1066
|
-
cost:
|
|
1067
|
-
distance:
|
|
1068
|
-
hours:
|
|
1069
|
-
cp: `${
|
|
1065
|
+
u && (await O.calculateCost(u, c, e, o), s.push(u), F == null || F.info("[%s][L%d-%d] analyse from %s to %s cost: %j", o.requestId, 1, m, e.etd, h.format(), {
|
|
1066
|
+
cost: u.cost.total,
|
|
1067
|
+
distance: u.distance,
|
|
1068
|
+
hours: u.totalHrs,
|
|
1069
|
+
cp: `${c.speed}/${c.fo}/${c.dgo}`
|
|
1070
1070
|
})), m++;
|
|
1071
1071
|
}
|
|
1072
|
-
s.sort((
|
|
1072
|
+
s.sort((c, w) => c.cost.total - w.cost.total);
|
|
1073
1073
|
const l = s.at(0), y = s.at(1), f = [];
|
|
1074
|
-
if (f.push({ combined: !1, speeds: [l], cost: (
|
|
1075
|
-
const
|
|
1076
|
-
let
|
|
1077
|
-
|
|
1078
|
-
let
|
|
1079
|
-
for (;
|
|
1080
|
-
const
|
|
1081
|
-
if (Y.cost >
|
|
1074
|
+
if (f.push({ combined: !1, speeds: [l], cost: (v = l.cost) == null ? void 0 : v.total }), y) {
|
|
1075
|
+
const c = l.cost.cp, w = y.cost.cp, M = p(l.eta), u = p(l.etd), I = M.diff(u, "days", !0);
|
|
1076
|
+
let S = Math.ceil(I / 2);
|
|
1077
|
+
S = S > 7 ? 7 : S < e.alterStep ? e.alterStep : S;
|
|
1078
|
+
let D = 2, Y = { combined: !1, speeds: [y], cost: (b = y.cost) == null ? void 0 : b.total }, N;
|
|
1079
|
+
for (; S >= e.alterStep; ) {
|
|
1080
|
+
const P = await O.combinedAnalyse(e, t, h, [c, w], i, S, { ...o, level: D });
|
|
1081
|
+
if (Y.cost > P.cost ? N ? (N == null ? void 0 : N.cost) > P.cost && (N = P) : (N = Y, Y = P) : (!N || (N == null ? void 0 : N.cost) > P.cost) && (N = P), S <= e.alterStep)
|
|
1082
1082
|
break;
|
|
1083
|
-
|
|
1083
|
+
S = Math.ceil(S / 2), D += 1;
|
|
1084
1084
|
}
|
|
1085
|
-
f.push(Y),
|
|
1085
|
+
f.push(Y), N && f.push(N);
|
|
1086
1086
|
}
|
|
1087
|
-
const
|
|
1088
|
-
return
|
|
1087
|
+
const k = p().valueOf() - a;
|
|
1088
|
+
return F == null || F.info("[%s] analyse elapsed: %d ms", o == null ? void 0 : o.requestId, k), f.sort((c, w) => c.cost - w.cost);
|
|
1089
1089
|
}
|
|
1090
1090
|
/**
|
|
1091
1091
|
* 按步长多次减半,分别用7,4,2,1天步长及cpa,cpb交替计算各种组合下的成本
|
|
@@ -1098,11 +1098,11 @@ class O {
|
|
|
1098
1098
|
* @param options
|
|
1099
1099
|
*/
|
|
1100
1100
|
static async combinedAnalyse(e, t, n, i, o, a, s = {}) {
|
|
1101
|
-
s.counter = 1,
|
|
1102
|
-
const d = await O.alternateAnalyse(e, t, n, i, 0, o, a, s),
|
|
1103
|
-
|
|
1104
|
-
const
|
|
1105
|
-
return
|
|
1101
|
+
s.counter = 1, F == null || F.info("[%s][L%d] analyse with alternate cp in every %d days", s.requestId, s.level, a);
|
|
1102
|
+
const d = await O.alternateAnalyse(e, t, n, i, 0, o, a, s), r = d.reduce((l, y) => l + y.cost.total, 0);
|
|
1103
|
+
F == null || F.info("[%s][L%d] cost with cpa/cpb turn: %d", s.requestId, s.level, r);
|
|
1104
|
+
const h = await O.alternateAnalyse(e, t, n, i, 1, o, a, s), m = h.reduce((l, y) => l + y.cost.total, 0);
|
|
1105
|
+
return F == null || F.info("[%s][L%d] cost with cpb/cpa turn: %d", s.requestId, s.level, m), r < m ? { combined: !0, cost: Math.round(r * 1e3) / 1e3, speeds: d, step: a } : { combined: !0, cost: Math.round(m * 1e3) / 1e3, speeds: h, step: a };
|
|
1106
1106
|
}
|
|
1107
1107
|
/**
|
|
1108
1108
|
* 基于cp索引,交替计算指定步长下的成本
|
|
@@ -1117,35 +1117,35 @@ class O {
|
|
|
1117
1117
|
*/
|
|
1118
1118
|
static async alternateAnalyse(e, t, n, i, o, a, s, d = {}) {
|
|
1119
1119
|
var l, y;
|
|
1120
|
-
let
|
|
1121
|
-
const
|
|
1122
|
-
for (;
|
|
1123
|
-
const f =
|
|
1124
|
-
|
|
1125
|
-
|
|
1120
|
+
let r = p.utc(e.etd);
|
|
1121
|
+
const h = { lat: e.lat, lng: e.lng }, m = [];
|
|
1122
|
+
for (; r.isBefore(n); ) {
|
|
1123
|
+
const f = r.clone().utc().add(s, "day"), C = JSON.parse(JSON.stringify(a.route)), k = JSON.parse(JSON.stringify(a.waypoints)), v = i[o], b = await O.analyseInstantWithThreshed(
|
|
1124
|
+
h,
|
|
1125
|
+
r.utc().format(),
|
|
1126
1126
|
f,
|
|
1127
1127
|
t,
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1128
|
+
v,
|
|
1129
|
+
C,
|
|
1130
|
+
k,
|
|
1131
1131
|
e.meteoVendor,
|
|
1132
1132
|
e.speedStep,
|
|
1133
1133
|
e.useMeteo,
|
|
1134
1134
|
e.useRouteParam,
|
|
1135
1135
|
d
|
|
1136
1136
|
);
|
|
1137
|
-
|
|
1137
|
+
b && (await O.calculateCost(b, v, e, d), F == null || F.info(
|
|
1138
1138
|
"[%s][L%d-%d] analyse from %s to %s cost: %j",
|
|
1139
1139
|
d.requestId,
|
|
1140
1140
|
d.level,
|
|
1141
1141
|
d.counter,
|
|
1142
|
-
|
|
1142
|
+
r.utc().format(),
|
|
1143
1143
|
f.utc().format(),
|
|
1144
|
-
{ cost:
|
|
1144
|
+
{ cost: b.cost.total, distance: b.distance, hours: b.totalHrs, cp: `${v.speed}/${v.fo}/${v.dgo}` }
|
|
1145
1145
|
)), d.counter = d.counter + 1;
|
|
1146
|
-
const
|
|
1147
|
-
if (
|
|
1148
|
-
|
|
1146
|
+
const c = (y = (l = b == null ? void 0 : b.sample) == null ? void 0 : l.hours) == null ? void 0 : y.at(-1);
|
|
1147
|
+
if (c)
|
|
1148
|
+
h.lat = c.lat, h.lng = c.lng, r = p(c.eta), m.push(b), o = o ? 0 : 1;
|
|
1149
1149
|
else
|
|
1150
1150
|
break;
|
|
1151
1151
|
}
|
|
@@ -1175,18 +1175,18 @@ class O {
|
|
|
1175
1175
|
* 计算单cp模式下的ECA属性
|
|
1176
1176
|
*/
|
|
1177
1177
|
static async calculateECA(e, t, n = {}) {
|
|
1178
|
-
var d,
|
|
1179
|
-
const i = await
|
|
1178
|
+
var d, r;
|
|
1179
|
+
const i = await L.intersectInECA(e.route);
|
|
1180
1180
|
let o = 0, a = 0, s = 0;
|
|
1181
|
-
e.sample.wps.forEach((
|
|
1182
|
-
|
|
1181
|
+
e.sample.wps.forEach((h) => {
|
|
1182
|
+
h.positionTime = p.utc(h.etd || h.eta).unix();
|
|
1183
1183
|
});
|
|
1184
|
-
for (const
|
|
1185
|
-
o +=
|
|
1186
|
-
const m = await
|
|
1187
|
-
|
|
1184
|
+
for (const h of i) {
|
|
1185
|
+
o += h.distance;
|
|
1186
|
+
const m = await L.deadReckoningTime((d = h.waypoints) == null ? void 0 : d.at(0), e.sample.wps), l = await L.deadReckoningTime((r = h.waypoints) == null ? void 0 : r.at(-1), e.sample.wps);
|
|
1187
|
+
h.in = m, h.out = l, h.totalHrs = B.roundPrecision((l.positionTime - m.positionTime) / 3600, 2), h.totalDgoCons = B.roundPrecision(t.fo / 24 * h.totalHrs, 3), a += h.totalHrs, s += h.totalDgoCons;
|
|
1188
1188
|
}
|
|
1189
|
-
return o =
|
|
1189
|
+
return o = B.roundPrecision(o, 3), a = B.roundPrecision(a, 3), s = B.roundPrecision(s, 3), {
|
|
1190
1190
|
distanceInECA: o,
|
|
1191
1191
|
hoursInECA: a,
|
|
1192
1192
|
totalDgoConsInECA: s,
|
|
@@ -1199,48 +1199,56 @@ class O {
|
|
|
1199
1199
|
* @param options
|
|
1200
1200
|
*/
|
|
1201
1201
|
static async mergeSpeeds(e, t = {}) {
|
|
1202
|
-
var
|
|
1202
|
+
var c, w;
|
|
1203
1203
|
const n = {
|
|
1204
1204
|
hours: [],
|
|
1205
1205
|
wps: [],
|
|
1206
1206
|
days: []
|
|
1207
|
-
}, i = e.reduce((M,
|
|
1208
|
-
var
|
|
1209
|
-
return M + (((
|
|
1210
|
-
}, 0), a = e.reduce((M,
|
|
1211
|
-
var
|
|
1212
|
-
return M + (((
|
|
1213
|
-
}, 0), d = e.reduce((M,
|
|
1214
|
-
var
|
|
1215
|
-
return M + (((
|
|
1216
|
-
}, 0),
|
|
1217
|
-
let
|
|
1207
|
+
}, i = e.reduce((M, u) => M + u.distance, 0), o = e.reduce((M, u) => {
|
|
1208
|
+
var I;
|
|
1209
|
+
return M + (((I = u.extend) == null ? void 0 : I.distanceInECA) || 0);
|
|
1210
|
+
}, 0), a = e.reduce((M, u) => M + u.totalHrs, 0), s = e.reduce((M, u) => {
|
|
1211
|
+
var I;
|
|
1212
|
+
return M + (((I = u.extend) == null ? void 0 : I.hoursInECA) || 0);
|
|
1213
|
+
}, 0), d = e.reduce((M, u) => {
|
|
1214
|
+
var I;
|
|
1215
|
+
return M + (((I = u.extend) == null ? void 0 : I.totalDgoConsInECA) || 0);
|
|
1216
|
+
}, 0), r = e.reduce((M, u) => M + u.wxFactor * u.totalHrs / a, 0), h = e.reduce((M, u) => M + u.cFactor * u.totalHrs / a, 0), m = e.reduce((M, u) => M + u.totalFoCons, 0), l = e.reduce((M, u) => M + u.totalDgoCons, 0), y = e.reduce((M, u) => M + u.cost.total, 0), f = e.reduce((M, u) => M + u.cost.hire, 0), C = e.reduce((M, u) => M + u.cost.bunker, 0), k = [], v = [];
|
|
1217
|
+
let b;
|
|
1218
1218
|
for (const M of e) {
|
|
1219
|
-
|
|
1220
|
-
const
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
}),
|
|
1224
|
-
|
|
1225
|
-
}),
|
|
1226
|
-
|
|
1227
|
-
})),
|
|
1228
|
-
const Y = [M.etd, M.eta],
|
|
1229
|
-
|
|
1219
|
+
v.push(...((c = M.extend) == null ? void 0 : c.eca) || []);
|
|
1220
|
+
const u = M.sample.hours, I = M.sample.wps, S = M.sample.days, D = u.at(0);
|
|
1221
|
+
b && (D.distanceFromPrevious = b.distanceFromPrevious, D.distanceFromStart = b.distanceFromStart, u.forEach((T, E) => {
|
|
1222
|
+
E && (T.distanceFromStart = T.distanceFromStart + b.distanceFromStart);
|
|
1223
|
+
}), I.at(0).distanceFromPrevious = b.distanceFromPrevious, I.at(0).distanceFromStart = b.distanceFromStart, I.forEach((T, E) => {
|
|
1224
|
+
E && (T.distanceFromStart = T.distanceFromStart + b.distanceFromStart);
|
|
1225
|
+
}), S.at(0).distanceFromPrevious = b.distanceFromPrevious, S.at(0).distanceFromStart = b.distanceFromStart, S.forEach((T, E) => {
|
|
1226
|
+
E && (T.distanceFromStart = T.distanceFromStart + b.distanceFromStart);
|
|
1227
|
+
})), D.cp = M.cost.cp;
|
|
1228
|
+
const Y = [M.etd, M.eta], N = k.findIndex((T) => T.id === D.cp.id);
|
|
1229
|
+
N === -1 ? (D.cp.segment = [Y], k.push(D.cp)) : k[N].segment.push(Y), u.forEach((T) => {
|
|
1230
1230
|
var A;
|
|
1231
|
-
((A = n.hours) == null ? void 0 : A.findIndex((R) => R.eta ===
|
|
1232
|
-
}),
|
|
1231
|
+
((A = n.hours) == null ? void 0 : A.findIndex((R) => R.eta === T.eta)) === -1 && n.hours.push(T);
|
|
1232
|
+
}), I.forEach((T) => {
|
|
1233
1233
|
var A;
|
|
1234
|
-
((A = n.wps) == null ? void 0 : A.findIndex((R) => R.eta ===
|
|
1235
|
-
}),
|
|
1234
|
+
((A = n.wps) == null ? void 0 : A.findIndex((R) => R.eta === T.eta)) === -1 && n.wps.push(T);
|
|
1235
|
+
}), S.forEach((T) => {
|
|
1236
1236
|
var A;
|
|
1237
|
-
((A = n == null ? void 0 : n.days) == null ? void 0 : A.findIndex((R) => R.eta ===
|
|
1237
|
+
((A = n == null ? void 0 : n.days) == null ? void 0 : A.findIndex((R) => R.eta === T.eta)) === -1 && n.days.push(T);
|
|
1238
1238
|
});
|
|
1239
|
-
const
|
|
1240
|
-
|
|
1239
|
+
const P = (w = n.wps) == null ? void 0 : w.findIndex((T) => T.eta === D.eta);
|
|
1240
|
+
P === -1 ? n.wps.push(D) : n.wps[P] = D, b = u.at(-1);
|
|
1241
1241
|
}
|
|
1242
|
-
return n.wps.sort((M,
|
|
1243
|
-
|
|
1242
|
+
return n.wps.sort((M, u) => {
|
|
1243
|
+
p(M.etd).unix() - p(u.etd).unix();
|
|
1244
|
+
}), n.wps.forEach((M, u) => {
|
|
1245
|
+
if (!M.avgSpd) {
|
|
1246
|
+
let I;
|
|
1247
|
+
if (u === 0 ? I = n.wps.at(1) : I = n.wps.at(u + 1), I) {
|
|
1248
|
+
const S = I.distanceFromStart - (M.distanceFromStart || 0), D = p(I.etd || I.eta).diff(p(M.etd || I.eta), "hour", !0), Y = Math.round(S / D * 100) / 100;
|
|
1249
|
+
M.avgSpd = Y;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1244
1252
|
}), {
|
|
1245
1253
|
sample: n,
|
|
1246
1254
|
etd: e.at(0).etd,
|
|
@@ -1252,18 +1260,18 @@ class O {
|
|
|
1252
1260
|
distance: Math.round(i * 1e4) / 1e4,
|
|
1253
1261
|
totalHrs: Math.round(a * 1e3) / 1e3,
|
|
1254
1262
|
avgSpeed: Math.round(i / a * 1e3) / 1e3,
|
|
1255
|
-
wxFactor: Math.round(
|
|
1256
|
-
cFactor: Math.round(
|
|
1263
|
+
wxFactor: Math.round(r / a * 1e3) / 1e3,
|
|
1264
|
+
cFactor: Math.round(h / a * 1e3) / 1e3,
|
|
1257
1265
|
totalFoCons: Math.round(m * 1e3) / 1e3,
|
|
1258
1266
|
totalDgoCons: Math.round(l * 1e3) / 1e3,
|
|
1259
1267
|
cost: {
|
|
1260
1268
|
total: Math.round(y * 1e3) / 1e3,
|
|
1261
1269
|
hire: Math.round(f * 1e3) / 1e3,
|
|
1262
|
-
bunker: Math.round(
|
|
1270
|
+
bunker: Math.round(C * 1e3) / 1e3
|
|
1263
1271
|
},
|
|
1264
1272
|
extend: {
|
|
1265
|
-
cps:
|
|
1266
|
-
eca:
|
|
1273
|
+
cps: k,
|
|
1274
|
+
eca: v,
|
|
1267
1275
|
distanceInECA: Math.round(o * 1e4) / 1e4,
|
|
1268
1276
|
hoursInECA: Math.round(s * 1e3) / 1e3,
|
|
1269
1277
|
totalDgoConsInECA: Math.round(d * 1e3) / 1e3,
|
|
@@ -1273,16 +1281,16 @@ class O {
|
|
|
1273
1281
|
}
|
|
1274
1282
|
}
|
|
1275
1283
|
export {
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1284
|
+
et as AISImpl,
|
|
1285
|
+
yt as AlertHelper,
|
|
1286
|
+
mt as AlertLevel,
|
|
1287
|
+
jt as HifleetImpl,
|
|
1288
|
+
pt as LoadCondition,
|
|
1289
|
+
Nt as MyShipImpl,
|
|
1282
1290
|
xt as MyVesselImpl,
|
|
1283
|
-
|
|
1291
|
+
Et as ShipxyImpl,
|
|
1284
1292
|
O as SpeedHelper,
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1293
|
+
wt as SpeedLabel,
|
|
1294
|
+
gt as VesselTag,
|
|
1295
|
+
Tt as alertHelper
|
|
1288
1296
|
};
|