@idm-plugin/vessel 1.6.4 → 1.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +417 -429
- package/dist/index.umd.cjs +1 -1
- package/dist/speed/src/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
var st = Object.defineProperty;
|
|
2
|
-
var at = (
|
|
3
|
-
var Z = (
|
|
2
|
+
var at = (S, e, t) => e in S ? st(S, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : S[e] = t;
|
|
3
|
+
var Z = (S, e, t) => (at(S, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
4
|
import R from "got";
|
|
5
5
|
import Q from "@log4js-node/log4js-api";
|
|
6
|
-
import
|
|
6
|
+
import v from "moment";
|
|
7
7
|
import { LngLatHelper as z, LaneHelper as B } from "@idm-plugin/geo";
|
|
8
8
|
import { MeteoHelper2 as ot, MeteoHelper as nt } from "@idm-plugin/meteo2";
|
|
9
9
|
import { Meteo2Assist as tt } from "@idm-plugin/meteo";
|
|
10
|
-
let
|
|
10
|
+
let M;
|
|
11
11
|
try {
|
|
12
|
-
|
|
12
|
+
M = Q.getLogger("vessel");
|
|
13
13
|
} catch {
|
|
14
14
|
} finally {
|
|
15
15
|
}
|
|
@@ -54,7 +54,7 @@ class U {
|
|
|
54
54
|
return { labelCn: t, labelEn: o };
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
class
|
|
57
|
+
class vt extends U {
|
|
58
58
|
constructor(t, o) {
|
|
59
59
|
super();
|
|
60
60
|
Z(this, "clientId");
|
|
@@ -70,32 +70,32 @@ class gt extends U {
|
|
|
70
70
|
grant_type: "client_credentials"
|
|
71
71
|
}
|
|
72
72
|
}, a = await R.post(o, i).json();
|
|
73
|
-
|
|
73
|
+
M == null || M.info("[%s] fetch access token from: %s - %j", t.requestId, o, a), a.error || (this.token = {
|
|
74
74
|
accessToken: a.access_token,
|
|
75
75
|
tokenType: a.token_type,
|
|
76
76
|
expiresIn: a.expires_in,
|
|
77
77
|
scope: a.scope,
|
|
78
78
|
jti: a.jti,
|
|
79
|
-
issuedAt:
|
|
79
|
+
issuedAt: v().utc().format()
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
async realTimePosition(t, o = {}) {
|
|
83
|
-
var l,
|
|
84
|
-
(!this.token ||
|
|
83
|
+
var l, m, f;
|
|
84
|
+
(!this.token || v().diff(v(this.token.issuedAt), "seconds") > ((l = this.token) == null ? void 0 : l.expiresIn) - 300) && await this.authToken(o);
|
|
85
85
|
const i = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit", a = {
|
|
86
86
|
headers: {
|
|
87
|
-
Authorization: `${(
|
|
87
|
+
Authorization: `${(m = this.token) == null ? void 0 : m.tokenType} ${(f = this.token) == null ? void 0 : f.accessToken}`
|
|
88
88
|
},
|
|
89
89
|
searchParams: { mmsi: t }
|
|
90
90
|
};
|
|
91
|
-
|
|
91
|
+
M == null || M.info("[%s] fetch realtime position from: %s - %j", o.requestId, i, a);
|
|
92
92
|
const n = await R.get(i, a).json();
|
|
93
93
|
if (n.code)
|
|
94
|
-
return
|
|
94
|
+
return M == null || M.warn("[%s] fetch realtime position failed: %j", o.requestId, i, { message: n.message, status: n.status, code: n.code }), n;
|
|
95
95
|
const s = n.data;
|
|
96
96
|
for (const h in s)
|
|
97
97
|
!isNaN(s[h]) && Number(s[h]) !== 1 / 0 && (s[h] = Number(s[h]));
|
|
98
|
-
const
|
|
98
|
+
const d = v(`${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,29 +110,29 @@ class gt extends U {
|
|
|
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) ? v.utc(s.eta).format() : void 0,
|
|
114
114
|
destination: s.dest,
|
|
115
|
-
positionTime:
|
|
115
|
+
positionTime: d.unix(),
|
|
116
116
|
status: s.status,
|
|
117
117
|
labelCn: s.statusNameCn,
|
|
118
118
|
labelEn: s.statusNameEn,
|
|
119
119
|
method: "position",
|
|
120
120
|
vendor: "myVessel",
|
|
121
|
-
utc:
|
|
121
|
+
utc: d.utc().format()
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
async trajectory(t, o, i, a, n = !0, s = {}) {
|
|
125
|
-
(!this.token ||
|
|
126
|
-
const
|
|
127
|
-
for (; l.diff(
|
|
128
|
-
await this.trajectoryIn30Day(t,
|
|
129
|
-
return await this.trajectoryIn30Day(t,
|
|
125
|
+
(!this.token || v().diff(v(this.token.issuedAt), "seconds") > this.token.expiresIn - 300) && await this.authToken(s);
|
|
126
|
+
const d = await this.realTimePosition(t, s), c = v(o), l = v(i), m = [];
|
|
127
|
+
for (; l.diff(c, "day", !0) > 30; )
|
|
128
|
+
await this.trajectoryIn30Day(t, c, c.clone().add(30, "day"), d, a, m, s), c.add(30, "day");
|
|
129
|
+
return await this.trajectoryIn30Day(t, c, l, d, a, m, s), m;
|
|
130
130
|
}
|
|
131
|
-
async trajectoryIn30Day(t, o, i, a, n, s,
|
|
132
|
-
var u,
|
|
133
|
-
const
|
|
131
|
+
async trajectoryIn30Day(t, o, i, a, n, s, d = {}) {
|
|
132
|
+
var u, I, k, y, w;
|
|
133
|
+
const c = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", l = {
|
|
134
134
|
headers: {
|
|
135
|
-
Authorization: `${(u = this.token) == null ? void 0 : u.tokenType} ${(
|
|
135
|
+
Authorization: `${(u = this.token) == null ? void 0 : u.tokenType} ${(I = this.token) == null ? void 0 : I.accessToken}`
|
|
136
136
|
},
|
|
137
137
|
json: {
|
|
138
138
|
mmsi: t,
|
|
@@ -140,35 +140,35 @@ class gt extends U {
|
|
|
140
140
|
endTime: i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
if (
|
|
146
|
-
return
|
|
147
|
-
let
|
|
148
|
-
const h =
|
|
149
|
-
return (
|
|
150
|
-
for (const
|
|
151
|
-
!isNaN(
|
|
152
|
-
const
|
|
153
|
-
mmsi:
|
|
143
|
+
M == null || M.info("[%s] fetch trajectory from: %s - %j", d.requestId, c, l);
|
|
144
|
+
const m = await R.post(c, l).json();
|
|
145
|
+
if (m.code)
|
|
146
|
+
return M == null || M.warn("[%s] fetch trajectory failed: %j", d.requestId, c, { message: m.message, status: m.status, code: m.code }), m;
|
|
147
|
+
let f = -1;
|
|
148
|
+
const h = v(`${(y = (k = m.data) == null ? void 0 : k[0]) == null ? void 0 : y.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
149
|
+
return (w = m.data) == null || w.forEach((r) => {
|
|
150
|
+
for (const q in r)
|
|
151
|
+
!isNaN(r[q]) && Number(r[q]) !== 1 / 0 && (r[q] = Number(r[q]));
|
|
152
|
+
const b = v(`${r.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), x = r.status, { labelCn: g, labelEn: j } = this.parseStatus(x), Y = {
|
|
153
|
+
mmsi: r.mmsi,
|
|
154
154
|
imo: a == null ? void 0 : a.imo,
|
|
155
|
-
lat:
|
|
156
|
-
lng:
|
|
157
|
-
sog:
|
|
158
|
-
cog:
|
|
159
|
-
hdg:
|
|
160
|
-
draught:
|
|
161
|
-
status:
|
|
162
|
-
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(
|
|
163
|
-
destination:
|
|
164
|
-
positionTime:
|
|
165
|
-
labelCn:
|
|
166
|
-
labelEn:
|
|
155
|
+
lat: r.lat,
|
|
156
|
+
lng: r.lon,
|
|
157
|
+
sog: r.sog,
|
|
158
|
+
cog: r.cog,
|
|
159
|
+
hdg: r.hdg,
|
|
160
|
+
draught: r.draught,
|
|
161
|
+
status: x,
|
|
162
|
+
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(r.eta) ? v(`${r.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00").utc().format() : void 0,
|
|
163
|
+
destination: r.dest,
|
|
164
|
+
positionTime: b.unix(),
|
|
165
|
+
labelCn: g,
|
|
166
|
+
labelEn: j,
|
|
167
167
|
method: "trajectory",
|
|
168
168
|
vendor: "myVessel",
|
|
169
|
-
utc:
|
|
170
|
-
},
|
|
171
|
-
|
|
169
|
+
utc: b.utc().format()
|
|
170
|
+
}, C = Math.floor(b.diff(h, "minute", !0) / (n || 1));
|
|
171
|
+
C !== f && (f = C, s.push(Y));
|
|
172
172
|
}), s;
|
|
173
173
|
}
|
|
174
174
|
}
|
|
@@ -185,14 +185,14 @@ class wt extends U {
|
|
|
185
185
|
usertoken: this.token
|
|
186
186
|
}
|
|
187
187
|
}, n = await R.post(i, a).json();
|
|
188
|
-
|
|
188
|
+
M == null || M.info("[%s] fetch realtime position from: %s - %j", o.requestId, i, a);
|
|
189
189
|
const s = n == null ? void 0 : n.list;
|
|
190
190
|
if (!s)
|
|
191
|
-
return
|
|
191
|
+
return M == null || M.warn("[%s] fetch realtime position failed: %j", o.requestId, i, n), n;
|
|
192
192
|
for (const h in s)
|
|
193
193
|
!isNaN(s[h]) && Number(s[h]) !== 1 / 0 && (s[h] = Number(s[h]));
|
|
194
194
|
s.status = s.sp > 3 ? 0 : 1;
|
|
195
|
-
const
|
|
195
|
+
const d = s.status, { labelCn: c, labelEn: l } = this.parseStatus(d), m = v(`${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,12 +207,12 @@ class wt extends U {
|
|
|
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) ? v.utc(s.eta).format() : void 0,
|
|
211
211
|
destination: s.destination,
|
|
212
|
-
positionTime:
|
|
213
|
-
utc:
|
|
214
|
-
status:
|
|
215
|
-
labelCn:
|
|
212
|
+
positionTime: m.unix(),
|
|
213
|
+
utc: m.utc().format(),
|
|
214
|
+
status: d,
|
|
215
|
+
labelCn: c,
|
|
216
216
|
labelEn: l,
|
|
217
217
|
method: "position",
|
|
218
218
|
vendor: "hifleet"
|
|
@@ -231,9 +231,9 @@ class wt extends U {
|
|
|
231
231
|
}
|
|
232
232
|
};
|
|
233
233
|
let n = await R.post(i, a).json();
|
|
234
|
-
|
|
235
|
-
for (const
|
|
236
|
-
!isNaN(n[
|
|
234
|
+
M == null || M.info("[%s] fetch vessel props from: %s - %j", o.requestId, i, a), n instanceof Array && (n = n[0]);
|
|
235
|
+
for (const d in n)
|
|
236
|
+
!isNaN(n[d]) && Number(n[d]) !== 1 / 0 && (n[d] = Number(n[d]));
|
|
237
237
|
const s = {
|
|
238
238
|
mmsi: n.m,
|
|
239
239
|
name: n.n,
|
|
@@ -244,7 +244,7 @@ class wt extends U {
|
|
|
244
244
|
draught: n.dr,
|
|
245
245
|
type: n.t
|
|
246
246
|
};
|
|
247
|
-
return i = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", n = await R.post(i, a).json(),
|
|
247
|
+
return i = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", n = await R.post(i, a).json(), M == null || M.info("[%s] search vessel dead weight from: %s - %j", o.requestId, i, a), n instanceof Array && (n = n[0]), n && (s.deadweight = Number(n.dwt)), s;
|
|
248
248
|
}
|
|
249
249
|
async suggest(t, o = {}) {
|
|
250
250
|
const i = "https://www.hifleet.com/hifleetapi/getShipSuggest.do", a = {
|
|
@@ -257,70 +257,70 @@ class wt extends U {
|
|
|
257
257
|
Host: "www.hifleet.com"
|
|
258
258
|
}
|
|
259
259
|
}, n = await R.post(i, a).json();
|
|
260
|
-
|
|
260
|
+
M == null || M.info("[%s] suggest vessel props from: %s - %j", o.requestId, i, a);
|
|
261
261
|
const s = [];
|
|
262
|
-
for (const
|
|
262
|
+
for (const d of n)
|
|
263
263
|
s.push({
|
|
264
|
-
mmsi: !
|
|
265
|
-
name:
|
|
266
|
-
callSign:
|
|
267
|
-
imo: !
|
|
268
|
-
score:
|
|
264
|
+
mmsi: !d.mmsi || isNaN(d.mmsi) ? null : Number(d.mmsi),
|
|
265
|
+
name: d.name,
|
|
266
|
+
callSign: d.callsign,
|
|
267
|
+
imo: !d.imo || isNaN(d.imo) ? null : Number(d.imo),
|
|
268
|
+
score: d._score
|
|
269
269
|
});
|
|
270
|
-
return s.sort((
|
|
270
|
+
return s.sort((d, c) => c.score - d.score), s;
|
|
271
271
|
}
|
|
272
272
|
async trajectory(t, o, i, a, n = !0, s = {}) {
|
|
273
|
-
var
|
|
274
|
-
const
|
|
275
|
-
let
|
|
276
|
-
const l =
|
|
273
|
+
var r, b, x;
|
|
274
|
+
const d = await this.realTimePosition(t, s);
|
|
275
|
+
let c = v(o);
|
|
276
|
+
const l = v(i), m = v();
|
|
277
277
|
if (n) {
|
|
278
|
-
let
|
|
279
|
-
|
|
278
|
+
let g = l.diff(c, "d", !0);
|
|
279
|
+
g < 0 ? c = l.clone().subtract(40, "d") : g < 30 ? c.subtract(10, "d") : g < 60 ? c.subtract(5, "d") : c = l.clone().subtract(80, "d"), g = m.diff(l, "d", !0), l.add(g > 10 ? 240 : g * 24, "h");
|
|
280
280
|
}
|
|
281
|
-
const
|
|
281
|
+
const f = {
|
|
282
282
|
searchParams: {
|
|
283
283
|
endtime: l.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
|
|
284
|
-
starttime:
|
|
284
|
+
starttime: c.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
|
|
285
285
|
mmsi: t,
|
|
286
286
|
usertoken: this.token
|
|
287
287
|
}
|
|
288
|
-
}, h = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", u = await R.get(h,
|
|
289
|
-
|
|
290
|
-
let
|
|
291
|
-
u && (
|
|
288
|
+
}, h = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", u = await R.get(h, f).json();
|
|
289
|
+
M == null || M.info("[%s] fetch trajectory from: %s - %j", s.requestId, h, f);
|
|
290
|
+
let I;
|
|
291
|
+
u && (I = ((b = (r = u.ships) == null ? void 0 : r.offors) == null ? void 0 : b.ship) || [], I.length || M == null || M.warn("[%s] fetch trajectory failed: %j", s.requestId, u));
|
|
292
292
|
const k = [];
|
|
293
|
-
let
|
|
294
|
-
const
|
|
295
|
-
for (const
|
|
296
|
-
for (const
|
|
297
|
-
!isNaN(
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
const { labelEn:
|
|
301
|
-
mmsi:
|
|
302
|
-
name:
|
|
303
|
-
imo:
|
|
304
|
-
lat:
|
|
305
|
-
lng:
|
|
306
|
-
draught:
|
|
307
|
-
sog:
|
|
308
|
-
cog:
|
|
309
|
-
hdg:
|
|
310
|
-
positionTime:
|
|
311
|
-
utc:
|
|
312
|
-
status:
|
|
313
|
-
labelCn:
|
|
314
|
-
labelEn:
|
|
293
|
+
let y = -1;
|
|
294
|
+
const w = v(`${(x = I == null ? void 0 : I[0]) == null ? void 0 : x.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
295
|
+
for (const g of I) {
|
|
296
|
+
for (const D in g)
|
|
297
|
+
!isNaN(g[D]) && Number(g[D]) !== 1 / 0 && (g[D] = Number(g[D]));
|
|
298
|
+
const j = v(`${g.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
299
|
+
g.status = g.sp > 4 ? 0 : 1;
|
|
300
|
+
const { labelEn: Y, labelCn: C } = this.parseStatus(g.status), q = {
|
|
301
|
+
mmsi: g.m,
|
|
302
|
+
name: g.n,
|
|
303
|
+
imo: d == null ? void 0 : d.imo,
|
|
304
|
+
lat: g.la,
|
|
305
|
+
lng: g.lo,
|
|
306
|
+
draught: g.draught,
|
|
307
|
+
sog: g.sp,
|
|
308
|
+
cog: g.co,
|
|
309
|
+
hdg: g.hdg,
|
|
310
|
+
positionTime: j.unix(),
|
|
311
|
+
utc: j.utc().format(),
|
|
312
|
+
status: g.status,
|
|
313
|
+
labelCn: C,
|
|
314
|
+
labelEn: Y,
|
|
315
315
|
method: "trajectory",
|
|
316
316
|
vendor: "hifleet"
|
|
317
|
-
},
|
|
318
|
-
|
|
317
|
+
}, T = Math.floor(j.diff(w, "minute", !0) / (a || 1));
|
|
318
|
+
T !== y && (y = T, k.push(q));
|
|
319
319
|
}
|
|
320
320
|
return k;
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
|
-
class
|
|
323
|
+
class pt extends U {
|
|
324
324
|
constructor(t) {
|
|
325
325
|
super();
|
|
326
326
|
Z(this, "token");
|
|
@@ -334,12 +334,12 @@ class It extends U {
|
|
|
334
334
|
enc: 1
|
|
335
335
|
}
|
|
336
336
|
}, a = "https://api.shipxy.com/apicall/GetSingleShip", n = await R.get(a, i).json();
|
|
337
|
-
if (
|
|
337
|
+
if (M == null || M.info("[%s] fetch realtime position from: %s - %j", o.requestId, a, i), (n == null ? void 0 : n.status) !== 0)
|
|
338
338
|
return n;
|
|
339
339
|
const s = n.data[0];
|
|
340
|
-
for (const
|
|
341
|
-
!isNaN(s[
|
|
342
|
-
const { labelCn:
|
|
340
|
+
for (const f in s)
|
|
341
|
+
!isNaN(s[f]) && Number(s[f]) !== 1 / 0 && (s[f] = Number(s[f]));
|
|
342
|
+
const { labelCn: d, labelEn: c } = await this.parseStatus(s.navistat), l = v.unix(s.lasttime);
|
|
343
343
|
return {
|
|
344
344
|
mmsi: s.ShipID,
|
|
345
345
|
name: s.name,
|
|
@@ -357,47 +357,47 @@ class It extends U {
|
|
|
357
357
|
positionTime: s.lasttime,
|
|
358
358
|
utc: l.utc().format(),
|
|
359
359
|
status: s.navistat,
|
|
360
|
-
labelEn:
|
|
361
|
-
labelCn:
|
|
360
|
+
labelEn: c,
|
|
361
|
+
labelCn: d,
|
|
362
362
|
method: "position",
|
|
363
363
|
vendor: "shipxy"
|
|
364
364
|
};
|
|
365
365
|
}
|
|
366
366
|
async trajectory(t, o, i, a, n = !0, s = {}) {
|
|
367
|
-
var
|
|
368
|
-
const
|
|
367
|
+
var w;
|
|
368
|
+
const d = await this.realTimePosition(t, s), c = v(o), l = v(i), m = "https://api.shipxy.com/apicall/GetShipTrack", f = {
|
|
369
369
|
searchParams: {
|
|
370
370
|
id: t,
|
|
371
371
|
k: this.token,
|
|
372
372
|
enc: 1,
|
|
373
373
|
cut: 0,
|
|
374
|
-
btm:
|
|
374
|
+
btm: c.unix(),
|
|
375
375
|
etm: l.unix()
|
|
376
376
|
}
|
|
377
|
-
}, h = await R.get(
|
|
378
|
-
if (
|
|
377
|
+
}, h = await R.get(m, f).json();
|
|
378
|
+
if (M == null || M.info("[%s] fetch trajectory from: %s - %j", s.requestId, m, f), (h == null ? void 0 : h.status) !== 0)
|
|
379
379
|
return h;
|
|
380
|
-
const u = h == null ? void 0 : h.points,
|
|
381
|
-
let
|
|
382
|
-
for (const
|
|
383
|
-
const
|
|
384
|
-
imo:
|
|
380
|
+
const u = h == null ? void 0 : h.points, I = [], k = v.unix((w = u[0]) == null ? void 0 : w.utc);
|
|
381
|
+
let y = -1;
|
|
382
|
+
for (const r of u) {
|
|
383
|
+
const b = v.unix(r.utc), x = {
|
|
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(r.sog * 3600 / 1e3 / 1852 * 100) / 100,
|
|
387
|
+
cog: Math.round(r.cog / 100 * 100) / 100,
|
|
388
|
+
lat: Math.round(r.lat / 1e6 * 1e5) / 1e5,
|
|
389
|
+
lng: Math.round(r.lon / 1e6 * 1e5) / 1e5,
|
|
390
|
+
positionTime: b.unix(),
|
|
391
|
+
utc: b.utc().format(),
|
|
392
392
|
method: "trajectory",
|
|
393
393
|
vendor: "shipxy"
|
|
394
|
-
},
|
|
395
|
-
|
|
394
|
+
}, g = Math.floor(b.diff(k, "minute", !0) / (a || 1));
|
|
395
|
+
g !== y && (y = g, I.push(x));
|
|
396
396
|
}
|
|
397
|
-
return
|
|
397
|
+
return I;
|
|
398
398
|
}
|
|
399
399
|
}
|
|
400
|
-
class
|
|
400
|
+
class It extends U {
|
|
401
401
|
constructor(t) {
|
|
402
402
|
super();
|
|
403
403
|
Z(this, "token");
|
|
@@ -412,7 +412,7 @@ class pt extends U {
|
|
|
412
412
|
mmsiList: t
|
|
413
413
|
}
|
|
414
414
|
}, a = "https://api3.myships.com/sp/ships/getShipIdByMMSI", n = await R.post(a, i).json();
|
|
415
|
-
return
|
|
415
|
+
return M == null || M.info("[%s] fetch ship id from: %s - %j", o.requestId, a, i), n.code !== "0" ? n : n.data[0].shipId;
|
|
416
416
|
}
|
|
417
417
|
async getShipInfo(t, o = {}) {
|
|
418
418
|
const i = {
|
|
@@ -423,14 +423,14 @@ class pt extends U {
|
|
|
423
423
|
shipId: t
|
|
424
424
|
}
|
|
425
425
|
}, a = "https://api3.myships.com/sp/ships/aissta", n = await R.post(a, i).json();
|
|
426
|
-
if (
|
|
426
|
+
if (M == null || M.info("[%s] fetch ship info from: %s - %j", o.requestId, a, i), n.code !== "0")
|
|
427
427
|
return n;
|
|
428
428
|
const s = n.data;
|
|
429
|
-
let
|
|
430
|
-
return t === "407170" && (
|
|
429
|
+
let d = s.imo;
|
|
430
|
+
return t === "407170" && (d = "9198379", M == null || M.warn("[%s] ship(%s) imo error: %s, should be %s", o.requestId, t, s.imo, d)), {
|
|
431
431
|
mmsi: s.mmsi,
|
|
432
432
|
name: s.shipnameEn,
|
|
433
|
-
imo:
|
|
433
|
+
imo: d,
|
|
434
434
|
callSign: s.callSign,
|
|
435
435
|
length: s.length,
|
|
436
436
|
width: s.breadth,
|
|
@@ -445,37 +445,37 @@ class pt extends U {
|
|
|
445
445
|
json: {
|
|
446
446
|
shipId: i
|
|
447
447
|
}
|
|
448
|
-
}, s = "https://api3.myships.com/sp/ships/position/latest",
|
|
449
|
-
|
|
450
|
-
const
|
|
451
|
-
for (const u in
|
|
452
|
-
!isNaN(
|
|
453
|
-
const { labelCn: l, labelEn:
|
|
448
|
+
}, s = "https://api3.myships.com/sp/ships/position/latest", d = await R.post(s, n).json();
|
|
449
|
+
M == null || M.info("[%s] fetch realtime position from: %s - %j", o.requestId, s, n);
|
|
450
|
+
const c = d.data[0];
|
|
451
|
+
for (const u in c)
|
|
452
|
+
!isNaN(c[u]) && Number(c[u]) !== 1 / 0 && (c[u] = Number(c[u]));
|
|
453
|
+
const { labelCn: l, labelEn: m } = await this.parseStatus(c.aisNavStatus), f = v.unix(c.posTime);
|
|
454
454
|
return {
|
|
455
455
|
...a,
|
|
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:
|
|
464
|
-
utc:
|
|
465
|
-
status:
|
|
466
|
-
labelEn:
|
|
457
|
+
lat: Math.round(c.lat / 1e4 / 60 * 1e5) / 1e5,
|
|
458
|
+
lng: Math.round(c.lon / 1e4 / 60 * 1e5) / 1e5,
|
|
459
|
+
sog: Math.round(c.sog / 10 * 100) / 100,
|
|
460
|
+
cog: Math.round(c.cog / 10 * 100) / 100,
|
|
461
|
+
hdg: Math.round(c.heading * 100) / 100,
|
|
462
|
+
rot: Math.round(c.rot * 100) / 100,
|
|
463
|
+
positionTime: c.posTime,
|
|
464
|
+
utc: f.utc().format(),
|
|
465
|
+
status: c.aisNavStatus,
|
|
466
|
+
labelEn: m,
|
|
467
467
|
labelCn: l,
|
|
468
468
|
method: "position",
|
|
469
469
|
vendor: "myship"
|
|
470
470
|
};
|
|
471
471
|
}
|
|
472
472
|
async trajectory(t, o, i, a, n = !0, s = {}) {
|
|
473
|
-
const
|
|
474
|
-
for (;
|
|
475
|
-
await this.trajectoryIn30Day(l,
|
|
476
|
-
return await this.trajectoryIn30Day(l,
|
|
473
|
+
const d = v(o), c = v(i), l = await this.getShipId(t), m = await this.getShipInfo(l), f = [];
|
|
474
|
+
for (; c.diff(d, "day", !0) > 30; )
|
|
475
|
+
await this.trajectoryIn30Day(l, d.unix(), d.add(30, "day").unix(), m, t, a, f);
|
|
476
|
+
return await this.trajectoryIn30Day(l, d.unix(), c.unix(), m, t, a, f), f;
|
|
477
477
|
}
|
|
478
|
-
async trajectoryIn30Day(t, o, i, a, n, s,
|
|
478
|
+
async trajectoryIn30Day(t, o, i, a, n, s, d, c = {}) {
|
|
479
479
|
var k;
|
|
480
480
|
const l = {
|
|
481
481
|
headers: {
|
|
@@ -486,32 +486,32 @@ class pt extends U {
|
|
|
486
486
|
startTime: o,
|
|
487
487
|
endTime: i
|
|
488
488
|
}
|
|
489
|
-
},
|
|
490
|
-
if (
|
|
491
|
-
return
|
|
492
|
-
const h =
|
|
493
|
-
for (const
|
|
494
|
-
!isNaN(h[
|
|
495
|
-
const u =
|
|
496
|
-
let
|
|
497
|
-
for (const
|
|
498
|
-
const
|
|
489
|
+
}, m = "https://api3.myships.com/sp/ships/position/history", f = await R.post(m, l).json();
|
|
490
|
+
if (M == null || M.info("[%s] fetch trajectory from: %s - %j", c.requestId, m, l), f.code !== "0")
|
|
491
|
+
return M == null || M.warn("[%s] invoke myship trajectory failed: %j", c.requestId, f), f;
|
|
492
|
+
const h = f.data;
|
|
493
|
+
for (const y in h)
|
|
494
|
+
!isNaN(h[y]) && Number(h[y]) !== 1 / 0 && (h[y] = Number(h[y]));
|
|
495
|
+
const u = v.unix((k = h[0]) == null ? void 0 : k.posTime);
|
|
496
|
+
let I = -1;
|
|
497
|
+
for (const y of h) {
|
|
498
|
+
const w = v.unix(y.posTime), r = {
|
|
499
499
|
imo: a == null ? void 0 : a.imo,
|
|
500
500
|
mmsi: n,
|
|
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(y.lat / 1e4 / 60 * 1e5) / 1e5,
|
|
502
|
+
lng: Math.round(y.lon / 1e4 / 60 * 1e5) / 1e5,
|
|
503
|
+
sog: Math.round(y.sog / 10 * 100) / 100,
|
|
504
|
+
cog: Math.round(y.cog / 10 * 100) / 100,
|
|
505
|
+
hdg: Math.round(y.heading * 100) / 100,
|
|
506
|
+
rot: Math.round(y.rot * 100) / 100,
|
|
507
|
+
positionTime: w.unix(),
|
|
508
|
+
utc: w.utc().format(),
|
|
509
509
|
method: "trajectory",
|
|
510
510
|
vendor: "myship"
|
|
511
|
-
},
|
|
512
|
-
|
|
511
|
+
}, b = Math.floor(w.diff(u, "minute", !0) / (s || 1));
|
|
512
|
+
b !== I && (I = b, d.push(r));
|
|
513
513
|
}
|
|
514
|
-
return
|
|
514
|
+
return d;
|
|
515
515
|
}
|
|
516
516
|
}
|
|
517
517
|
let W;
|
|
@@ -520,7 +520,7 @@ try {
|
|
|
520
520
|
} catch {
|
|
521
521
|
} finally {
|
|
522
522
|
}
|
|
523
|
-
var it = /* @__PURE__ */ ((
|
|
523
|
+
var it = /* @__PURE__ */ ((S) => (S.NOTICE = "NOTICE", S.WARN = "WARN", S.HEAVY = "HEAVY", S.SEVERE = "SEVERE", S.ERROR = "ERROR", S.FATAL = "FATAL", S))(it || {});
|
|
524
524
|
class rt {
|
|
525
525
|
/**
|
|
526
526
|
* 解析告警规则, 多规则场景
|
|
@@ -531,19 +531,19 @@ class rt {
|
|
|
531
531
|
* @param options
|
|
532
532
|
*/
|
|
533
533
|
parsePrinciple(e, t = {}) {
|
|
534
|
-
var s,
|
|
534
|
+
var s, d, c;
|
|
535
535
|
W == null || W.info("[%s] parse rule: %s", t.requestId, e);
|
|
536
536
|
const o = new RegExp("(?<=\\[)(.+)(?=])", "g"), i = e.match(o) ? (s = e.match(o)) == null ? void 0 : s[0] : void 0, a = i == null ? void 0 : i.split(";");
|
|
537
537
|
if (!a)
|
|
538
538
|
return;
|
|
539
539
|
const n = {};
|
|
540
540
|
for (let l = 0; l < (a == null ? void 0 : a.length); l++) {
|
|
541
|
-
const
|
|
542
|
-
if (l === 0 && !
|
|
541
|
+
const m = (c = (d = a[l].match(o)) == null ? void 0 : d[0]) == null ? void 0 : c.split("],");
|
|
542
|
+
if (l === 0 && !m)
|
|
543
543
|
n.scope = a[0];
|
|
544
|
-
else if (
|
|
545
|
-
for (let
|
|
546
|
-
const u = this.parseRule(
|
|
544
|
+
else if (m)
|
|
545
|
+
for (let f = 0, h = m.length; f < h; f++) {
|
|
546
|
+
const u = this.parseRule(m[f]);
|
|
547
547
|
u && (n[u.level] ? u.key ? n[u.level][u == null ? void 0 : u.key] = u : n[u.level] = u : u.key ? n[u.level] = { [u == null ? void 0 : u.key]: u } : n[u.level] = u);
|
|
548
548
|
}
|
|
549
549
|
}
|
|
@@ -575,26 +575,26 @@ class rt {
|
|
|
575
575
|
* @param options
|
|
576
576
|
*/
|
|
577
577
|
checkWeather(e, t, o = {}) {
|
|
578
|
-
var u,
|
|
578
|
+
var u, I, k, y, w, r, b, x, g, j, Y, C, q, T, D;
|
|
579
579
|
let i = 0, a = 0, n = 0, s = 0;
|
|
580
|
-
const
|
|
580
|
+
const d = Math.round(((I = (u = t == null ? void 0 : t.SEVERE) == null ? void 0 : u.sigWave) == null ? void 0 : I.number) * 1.6 * 100) / 100, c = (y = (k = t == null ? void 0 : t.SEVERE) == null ? void 0 : k.sigWave) == null ? void 0 : y.number, l = (r = (w = t == null ? void 0 : t.HEAVY) == null ? void 0 : w.sigWave) == null ? void 0 : r.number, m = Math.round((((x = (b = t == null ? void 0 : t.SEVERE) == null ? void 0 : b.wind) == null ? void 0 : x.number) + 2) * 100) / 100, f = (j = (g = t == null ? void 0 : t.SEVERE) == null ? void 0 : g.wind) == null ? void 0 : j.number, h = (C = (Y = t == null ? void 0 : t.HEAVY) == null ? void 0 : Y.wind) == null ? void 0 : C.number;
|
|
581
581
|
for (let V = 0; V < (e == null ? void 0 : e.length); V++) {
|
|
582
|
-
const H = e[V],
|
|
583
|
-
s = J > s ? J : s, W == null || W.info("[%s] check sig.wave: %j", o.requestId, { ...
|
|
582
|
+
const H = e[V], P = (T = (q = H == null ? void 0 : H.meteo) == null ? void 0 : q.wave) == null ? void 0 : T.sig, A = (D = H == null ? void 0 : H.meteo) == null ? void 0 : D.wind, J = V ? v(H.eta).diff(v(e[V - 1].eta), "hour", !0) : 0;
|
|
583
|
+
s = J > s ? J : s, W == null || W.info("[%s] check sig.wave: %j", o.requestId, { ...P, dgThd4Wv: d, svThd4Wv: c, hvThd4Wv: l }), (P == null ? void 0 : P.height) >= d ? H.isDangerous = !0 : (P == null ? void 0 : P.height) >= c ? H.isSevere = !0 : (P == null ? void 0 : P.height) >= l && (H.isHeavy = !0), W == null || W.info("[%s] check wind: %j", o.requestId, { ...A, dgThd4Wd: m, svThd4Wd: f, hvThd4Wd: h }), (A == null ? void 0 : A.scale) >= m ? (H.isDangerous = !0, delete H.isSevere, delete H.isHeavy) : (A == null ? void 0 : A.scale) > f ? (H.isDangerous || (H.isSevere = !0), delete H.isHeavy) : (A == null ? void 0 : A.scale) === h && !H.isDangerous && !H.isSevere && (H.isHeavy = !0), i += H.isDangerous ? J : 0, a += H.isSevere ? J : 0, n += H.isHeavy ? J : 0;
|
|
584
584
|
}
|
|
585
|
-
return i = Math.round(i * 100) / 100, a = Math.round(a * 100) / 100, n = Math.round(n * 100) / 100, s = Math.round(s), { sample: e, dangerous: i, severe: a, heavy: n, step: s < 3 ? 3 : s, wind: { dgThd4Wd:
|
|
585
|
+
return i = Math.round(i * 100) / 100, a = Math.round(a * 100) / 100, n = Math.round(n * 100) / 100, s = Math.round(s), { sample: e, dangerous: i, severe: a, heavy: n, step: s < 3 ? 3 : s, wind: { dgThd4Wd: m, svThd4Wd: f, hvThd4Wd: h }, sig: { dgThd4Wv: d, svThd4Wv: c, hvThd4Wv: l } };
|
|
586
586
|
}
|
|
587
587
|
}
|
|
588
588
|
const kt = new rt();
|
|
589
|
-
let
|
|
589
|
+
let p;
|
|
590
590
|
try {
|
|
591
|
-
|
|
591
|
+
p = Q.getLogger("vessel");
|
|
592
592
|
} catch {
|
|
593
593
|
} finally {
|
|
594
594
|
}
|
|
595
595
|
const ct = new ot("", !0);
|
|
596
|
-
var dt = /* @__PURE__ */ ((
|
|
597
|
-
class
|
|
596
|
+
var dt = /* @__PURE__ */ ((S) => (S.common = "common", S.container = "container", S.tugs = "tugs", S))(dt || {}), ut = /* @__PURE__ */ ((S) => (S.Ballast = "Ballast", S.Laden = "Laden", S))(ut || {}), ht = /* @__PURE__ */ ((S) => (S.Cp = "CP", S.Perf = "Basis", S.Instruct = "Other", S))(ht || {});
|
|
597
|
+
class E {
|
|
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
|
|
600
600
|
* 方形系数(block coefficient)
|
|
@@ -610,7 +610,7 @@ class q {
|
|
|
610
610
|
static blockCoefficient(e, t, o, i) {
|
|
611
611
|
let a = Math.round(e / (t * o * i) * 100) / 100;
|
|
612
612
|
a = a < 0.55 ? 0.55 : a > 0.85 ? 0.85 : a;
|
|
613
|
-
const n = [0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85], s = n.map((
|
|
613
|
+
const n = [0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85], s = n.map((d) => Math.abs(d - a));
|
|
614
614
|
return n[s.indexOf(Math.min(...s))];
|
|
615
615
|
}
|
|
616
616
|
/**
|
|
@@ -706,17 +706,17 @@ class q {
|
|
|
706
706
|
* @private
|
|
707
707
|
*/
|
|
708
708
|
static assembleProperties(e, t, o, i) {
|
|
709
|
-
var
|
|
710
|
-
const a = e.lbp ?? e.length ?? e.lengthOverall ?? 198.9642, n = e.draught ?? 8, s = e.breadthMoulded ?? e.breadth ?? e.breadthExtreme ?? 32.4572,
|
|
709
|
+
var f;
|
|
710
|
+
const a = e.lbp ?? e.length ?? e.lengthOverall ?? 198.9642, n = e.draught ?? 8, s = e.breadthMoulded ?? e.breadth ?? e.breadthExtreme ?? 32.4572, d = e.deadweight ?? 67035.7773, c = ((f = e == null ? void 0 : e.type) == null ? void 0 : f.toLowerCase()) || "common";
|
|
711
711
|
return {
|
|
712
|
-
tag:
|
|
712
|
+
tag: c.indexOf("container") > -1 ? "container" : c.indexOf("tugs") > -1 ? "tugs" : "common",
|
|
713
713
|
lbp: a,
|
|
714
714
|
loadCondition: t,
|
|
715
715
|
draught: n,
|
|
716
716
|
breadthMoulded: s,
|
|
717
717
|
// 排水量(吨)= 载重量(吨)/ 1.025 + 吃水(米)× 船舶型宽(米)× 船舶型长(米)× 0.7
|
|
718
718
|
// 其中,1.025是指海水的密度,吨是指公吨,吃水是指船舶的最大吃水深度。船舶型宽是指船舶的最大型宽,船舶型长是指船舶的设计型长。上述公式是针对常规船舶适用的,不同类型的船舶可能会有一些差异。
|
|
719
|
-
displacement: Math.round((
|
|
719
|
+
displacement: Math.round((d / 1.025 + n * s * a * 0.7) * 1e4) / 1e4,
|
|
720
720
|
// 换算为m/s
|
|
721
721
|
speed: Math.round((o ?? 14.1382) * 1852 / 3600 * 1e4) / 1e4,
|
|
722
722
|
bearing: i || 90
|
|
@@ -732,37 +732,37 @@ class q {
|
|
|
732
732
|
* @param useMeteo true 启用气象分析
|
|
733
733
|
* @param useRouteParam true 启用设置速度
|
|
734
734
|
*/
|
|
735
|
-
static async speedLoseAt(e, t, o, i = "", a = 2, n = !0, s = !1,
|
|
736
|
-
let
|
|
735
|
+
static async speedLoseAt(e, t, o, i = "", a = 2, n = !0, s = !1, d = {}) {
|
|
736
|
+
let c;
|
|
737
737
|
if (t.velocity && s && (e.speed = z.roundPrecision(t.velocity * 1852 / 3600, 6)), n) {
|
|
738
738
|
let l;
|
|
739
|
-
if (
|
|
739
|
+
if (d.meteo2)
|
|
740
740
|
try {
|
|
741
|
-
const u = await ct.spotForecast(t.lat, t.lng, o.utc().format(), !1, !1, !0,
|
|
742
|
-
l = tt.toLegacy(
|
|
741
|
+
const u = await ct.spotForecast(t.lat, t.lng, o.utc().format(), !1, !1, !0, d), [I] = tt.pickHourly(u, o);
|
|
742
|
+
l = tt.toLegacy(I);
|
|
743
743
|
} catch (u) {
|
|
744
|
-
|
|
744
|
+
p.warn("[%s] meteo2 spot(%j) forecast failed: %s", d.requestId, { ...t, eta: o.utc().format() }, u);
|
|
745
745
|
}
|
|
746
746
|
else
|
|
747
|
-
l = await nt.queryPointFactor(t.lng, t.lat, o.valueOf(), "wind,wave,current,watertemp", i,
|
|
748
|
-
const
|
|
749
|
-
|
|
747
|
+
l = await nt.queryPointFactor(t.lng, t.lat, o.valueOf(), "wind,wave,current,watertemp", i, d);
|
|
748
|
+
const m = E.weatherFactor(e, l), f = E.currentFactor(e.bearing, l == null ? void 0 : l.current, a), h = Math.round((e.speed * 1.943844 + m + f) * 100) / 100;
|
|
749
|
+
c = {
|
|
750
750
|
meteo: { ...l },
|
|
751
|
-
wxFactor:
|
|
752
|
-
cFactor:
|
|
751
|
+
wxFactor: m,
|
|
752
|
+
cFactor: f,
|
|
753
753
|
speed: t.velocity && s ? t.velocity : h < 0 ? 1 : h,
|
|
754
754
|
eta: o.utc().format("YYYY-MM-DDTHH:mm[Z]"),
|
|
755
755
|
etd: o.utc().format("YYYY-MM-DDTHH:mm[Z]")
|
|
756
756
|
};
|
|
757
757
|
} else
|
|
758
|
-
|
|
758
|
+
c = {
|
|
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: o.utc().format("YYYY-MM-DDTHH:mm[Z]"),
|
|
763
763
|
etd: o.utc().format("YYYY-MM-DDTHH:mm[Z]")
|
|
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, { ...c, ...t };
|
|
766
766
|
}
|
|
767
767
|
/**
|
|
768
768
|
* 基于步长计算失速样本
|
|
@@ -777,53 +777,53 @@ class q {
|
|
|
777
777
|
* @param useRouteParam true 启用航线上设置的参数 { suspend: 停留时长(小时), velocity: 速度(kts)}
|
|
778
778
|
* @private
|
|
779
779
|
*/
|
|
780
|
-
static async speedLoseInHoursStep(e, t, o, i, a, n, s = "",
|
|
780
|
+
static async speedLoseInHoursStep(e, t, o, i, a, n, s = "", d = !0, c = !1, l = {}) {
|
|
781
781
|
t.utc();
|
|
782
|
-
const
|
|
783
|
-
let u = 0,
|
|
784
|
-
for (let
|
|
785
|
-
let
|
|
786
|
-
|
|
787
|
-
const
|
|
788
|
-
if (e.bearing = B.calculateBearing(
|
|
789
|
-
|
|
790
|
-
const
|
|
791
|
-
if (i - u >
|
|
792
|
-
i = i - u -
|
|
782
|
+
const m = t.clone().add(14, "days"), f = [], h = [];
|
|
783
|
+
let u = 0, I = 0, k, y;
|
|
784
|
+
for (let w = 0; w < n.length - 1; w++) {
|
|
785
|
+
let r = n[w];
|
|
786
|
+
r.distanceFromStart = Math.round((a + I) * 1e4) / 1e4;
|
|
787
|
+
const b = n[w + 1];
|
|
788
|
+
if (e.bearing = B.calculateBearing(r, b, !b.gcToPrevious), r.bearing = e.bearing, r.suspend && c) {
|
|
789
|
+
r.eta = r.eta || t.format("YYYY-MM-DDTHH:mm[Z]"), r.elapsed = r.elapsed ?? 0;
|
|
790
|
+
const j = r.suspend - r.elapsed;
|
|
791
|
+
if (i - u > j)
|
|
792
|
+
i = i - u - j, t.add(j, "hour"), r.elapsed = r.suspend;
|
|
793
793
|
else {
|
|
794
|
-
const
|
|
795
|
-
|
|
794
|
+
const Y = i - u;
|
|
795
|
+
r.elapsed += Y, t.add(Y, "hour"), i = 0;
|
|
796
796
|
}
|
|
797
|
-
if (
|
|
798
|
-
return
|
|
797
|
+
if (p == null || p.info(`[%s] suspend ${r.elapsed} hours at %j, and remain ${i} hours need to go...`, l.requestId, r), i === 0)
|
|
798
|
+
return r.distanceFromPrevious = I, { etd: t, from: y || r, to: r, next: n.filter((Y) => Y), wps: f, days: h };
|
|
799
799
|
} else
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
const
|
|
803
|
-
let
|
|
804
|
-
if (u +
|
|
805
|
-
if (u +=
|
|
806
|
-
`[%s] go to %j from %j with ${
|
|
800
|
+
r.suspend = 0;
|
|
801
|
+
d = t.isAfter(m) ? !1 : d, r = await E.speedLoseAt(e, r, t, s, 0, d, c, l), y = y || r, r.important && f.push(r), t.isSameOrAfter(o) && (h.push(r), o.add(24, "hour"));
|
|
802
|
+
const x = B.calculateDistance(r, b, !b.gcToPrevious);
|
|
803
|
+
let g = Math.ceil(x / y.speed * 1e4) / 1e4;
|
|
804
|
+
if (u + g < i) {
|
|
805
|
+
if (u += g, t.add(g, "hour"), delete n[w], p == null || p.debug(
|
|
806
|
+
`[%s] go to %j from %j with ${x}nm, and cost ${g} hours`,
|
|
807
807
|
l.requestId,
|
|
808
|
-
{ lat:
|
|
809
|
-
{ lat:
|
|
810
|
-
),
|
|
811
|
-
k =
|
|
808
|
+
{ lat: b.lat, lng: b.lng },
|
|
809
|
+
{ lat: y.lat, lng: y.lng, etd: y.etd }
|
|
810
|
+
), I += x, n.filter((j) => j).length <= 1) {
|
|
811
|
+
k = b, k.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), k.distanceFromPrevious = x, k.distanceFromStart = Math.round((a + I) * 1e4) / 1e4, f.push(k), delete n[w + 1];
|
|
812
812
|
break;
|
|
813
813
|
}
|
|
814
814
|
} else {
|
|
815
|
-
|
|
816
|
-
const
|
|
817
|
-
k = B.calculateCoordinate(
|
|
818
|
-
`[%s] go to %j from %j with ${
|
|
815
|
+
g = i - u, t.add(g, "hour");
|
|
816
|
+
const j = z.roundPrecision(y.speed * g, 4);
|
|
817
|
+
k = B.calculateCoordinate(r, e.bearing, j, "nauticalmiles", !b.gcToPrevious), k.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), n[w] = k, p == null || p.debug(
|
|
818
|
+
`[%s] go to %j from %j with ${j}nm, and cost ${g} hours`,
|
|
819
819
|
l.requestId,
|
|
820
820
|
{ lat: k.lat, lng: k.lng },
|
|
821
|
-
{ lat:
|
|
822
|
-
),
|
|
821
|
+
{ lat: r.lat, lng: r.lng, etd: r.etd }
|
|
822
|
+
), I += j, k.distanceFromPrevious = Math.round(I * 1e4) / 1e4, k.distanceFromStart = Math.round((a + I) * 1e4) / 1e4;
|
|
823
823
|
break;
|
|
824
824
|
}
|
|
825
825
|
}
|
|
826
|
-
return { etd: t, from:
|
|
826
|
+
return { etd: t, from: y, to: k, next: n.filter((w) => w), wps: f, days: h };
|
|
827
827
|
}
|
|
828
828
|
/**
|
|
829
829
|
* 洋流影响因子
|
|
@@ -844,16 +844,16 @@ class q {
|
|
|
844
844
|
* @param wwc 气象要素
|
|
845
845
|
*/
|
|
846
846
|
static weatherFactor(e, t) {
|
|
847
|
-
var
|
|
848
|
-
|
|
849
|
-
const o =
|
|
850
|
-
let n = Math.abs(e.bearing % 360 - (((
|
|
847
|
+
var m, f, h, u, I, k, y;
|
|
848
|
+
p == null || p.debug("calculate weather factor via: %j", { ...e, ...t });
|
|
849
|
+
const o = E.blockCoefficient(e.displacement, e.lbp, e.breadthMoulded, e.draught), i = E.froudeNumber(e.speed, e.lbp), a = E.amendFactor(o, i, e.loadCondition);
|
|
850
|
+
let n = Math.abs(e.bearing % 360 - (((m = t == null ? void 0 : t.wind) == null ? void 0 : m.degree) % 360 || 0));
|
|
851
851
|
n = n > 180 ? 360 - n : n;
|
|
852
|
-
const s =
|
|
853
|
-
let
|
|
854
|
-
|
|
855
|
-
const l =
|
|
856
|
-
return
|
|
852
|
+
const s = E.directionFactor(n, (f = t == null ? void 0 : t.wind) == null ? void 0 : f.scale), d = E.vesselTagFactor(e.displacement, e.loadCondition, e.tag, (h = t == null ? void 0 : t.wind) == null ? void 0 : h.scale);
|
|
853
|
+
let c = s * a * d / 100 * e.speed;
|
|
854
|
+
c = Math.round(c * 1.943844 * 1e4) / 1e4 * -1, e.tag === "tugs" && Math.abs(c) > 1 && (c = c / (Math.abs(Math.round(c)) + 1)), p == null || p.debug("wind wx factor = %d", c), n = Math.abs(e.bearing % 360 - (((I = (u = t == null ? void 0 : t.wave) == null ? void 0 : u.sig) == null ? void 0 : I.degree) % 360 || 0));
|
|
855
|
+
const l = E.waveHeightFactor(((y = (k = t == null ? void 0 : t.wave) == null ? void 0 : k.sig) == null ? void 0 : y.height) ?? 1, n);
|
|
856
|
+
return p == null || p.debug("wave wx factor = %d", l), c = c * 0.4 + l, p == null || p.debug("weather factor = %d", c), c = Math.abs(c) > 4 ? 4 * (Math.abs(c) / c) + Math.abs(c) / c * (Math.abs(c) - 4) * 0.1 : c, Math.round((c || 0) * 100) / 100;
|
|
857
857
|
}
|
|
858
858
|
/**
|
|
859
859
|
* 全程失速分析(走完航程)
|
|
@@ -867,14 +867,14 @@ class q {
|
|
|
867
867
|
* @param useMeteo true 启用气象分析
|
|
868
868
|
* @param useRouteParam
|
|
869
869
|
*/
|
|
870
|
-
static async analyseInstant(e, t, o, i, a, n = "", s = 0,
|
|
871
|
-
var J,
|
|
872
|
-
const
|
|
870
|
+
static async analyseInstant(e, t, o, i, a, n = "", s = 0, d = !0, c = !1, l = {}) {
|
|
871
|
+
var J, _, K, G, L;
|
|
872
|
+
const m = v().valueOf();
|
|
873
873
|
e.lng = z.convertToStdLng(e.lng);
|
|
874
|
-
const { route:
|
|
874
|
+
const { route: f, waypoints: h } = a.points, u = B.calculateSubRoute(e, f);
|
|
875
875
|
if (((J = u[0]) == null ? void 0 : J.length) <= 1)
|
|
876
876
|
return;
|
|
877
|
-
const { v0:
|
|
877
|
+
const { v0: I, label: k } = e.sog ? {
|
|
878
878
|
v0: e.sog,
|
|
879
879
|
label: "Other"
|
|
880
880
|
/* Instruct */
|
|
@@ -882,59 +882,59 @@ class q {
|
|
|
882
882
|
v0: i.speed,
|
|
883
883
|
label: "CP"
|
|
884
884
|
/* Cp */
|
|
885
|
-
},
|
|
886
|
-
|
|
887
|
-
const
|
|
885
|
+
}, y = E.assembleProperties(o, i.loadCondition, I, 0), w = h.length ? B.calculateSubWaypoints(e, h) : [];
|
|
886
|
+
w.forEach((N) => N.important = !0);
|
|
887
|
+
const r = {
|
|
888
888
|
from: { ...e },
|
|
889
889
|
route: u,
|
|
890
|
-
waypoints:
|
|
891
|
-
v0:
|
|
890
|
+
waypoints: w,
|
|
891
|
+
v0: I,
|
|
892
892
|
label: k
|
|
893
|
-
},
|
|
893
|
+
}, b = {
|
|
894
894
|
hours: [],
|
|
895
895
|
days: [],
|
|
896
896
|
wps: []
|
|
897
897
|
};
|
|
898
898
|
s || (B.calculateRouteDistance(u) / i.speed <= 72 ? s = 3 : s = 6);
|
|
899
|
-
let
|
|
900
|
-
t =
|
|
901
|
-
const
|
|
902
|
-
for (;
|
|
903
|
-
const N = s - t.hour() % s, F = Math.ceil(t.clone().add(N, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4,
|
|
904
|
-
|
|
899
|
+
let x = B.simplifyRouteToCoordinates(u, w, 0), g = 0, j = 0, Y = 0, C = 0;
|
|
900
|
+
t = v(t).utc();
|
|
901
|
+
const q = t.clone();
|
|
902
|
+
for (; x.length > 0; ) {
|
|
903
|
+
const N = s - t.hour() % s, F = Math.ceil(t.clone().add(N, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4, O = await E.speedLoseInHoursStep(
|
|
904
|
+
y,
|
|
905
905
|
t,
|
|
906
|
-
|
|
906
|
+
q,
|
|
907
907
|
F,
|
|
908
|
-
|
|
909
|
-
|
|
908
|
+
g,
|
|
909
|
+
x,
|
|
910
910
|
n,
|
|
911
|
+
d,
|
|
911
912
|
c,
|
|
912
|
-
r,
|
|
913
913
|
l
|
|
914
914
|
);
|
|
915
|
-
(
|
|
915
|
+
(_ = O.from) != null && _.speed && (b.hours.push(O.from), b.wps.push(...O.wps), b.days.push(...O.days)), x = O == null ? void 0 : O.next, x.length || b.hours.push(O == null ? void 0 : O.to), g += Math.round((((K = O == null ? void 0 : O.to) == null ? void 0 : K.distanceFromPrevious) ?? 0) * 1e4) / 1e4;
|
|
916
916
|
}
|
|
917
|
-
const
|
|
918
|
-
for (let N = 0; N <
|
|
919
|
-
const F =
|
|
920
|
-
|
|
917
|
+
const T = b.hours;
|
|
918
|
+
for (let N = 0; N < T.length - 1; N++) {
|
|
919
|
+
const F = v(T[N + 1].eta).diff(T[N].etd, "hour", !0) || 1;
|
|
920
|
+
j += (T[N].wxFactor || 0) * F, Y += (T[N].cFactor || 0) * F, C += F;
|
|
921
921
|
}
|
|
922
|
-
(G =
|
|
922
|
+
(G = b.wps) == null || G.forEach((N, F) => {
|
|
923
923
|
if (F) {
|
|
924
|
-
const
|
|
924
|
+
const O = b.wps[F - 1], et = N.distanceFromStart - O.distanceFromStart, X = v(N.eta).diff(v(O.etd), "h", !0);
|
|
925
925
|
if (X < 1)
|
|
926
|
-
N.avgSpd =
|
|
926
|
+
N.avgSpd = O.speed;
|
|
927
927
|
else {
|
|
928
928
|
N.avgSpd = Math.round(et / X * 100) / 100;
|
|
929
|
-
const $ = Math.round((
|
|
929
|
+
const $ = Math.round((O.speed + N.speed) / 2 * 100) / 100;
|
|
930
930
|
N.avgSpd = N.avgSpd > $ ? $ : N.avgSpd;
|
|
931
931
|
}
|
|
932
932
|
}
|
|
933
|
-
}),
|
|
934
|
-
const
|
|
935
|
-
|
|
936
|
-
const
|
|
937
|
-
return
|
|
933
|
+
}), r.sample = b;
|
|
934
|
+
const D = b.hours.at(0), V = b.hours.at(-1);
|
|
935
|
+
r.distance = Math.round(V.distanceFromStart * 1e4) / 1e4, r.etd = v(D.eta).utc().format(), r.eta = v(V.eta).utc().format(), r.wxFactor = Math.round(j / C * 1e4) / 1e4, r.cFactor = Math.round(Y / C * 1e4) / 1e4, r.avgSpeed = Math.round(V.distanceFromStart / C * 1e4) / 1e4, r.totalHrs = Math.round(C * 1e4) / 1e4, r.totalFoCons = Math.round((i == null ? void 0 : i.fo) / 24 * r.totalHrs * 1e3) / 1e3, r.totalDgoCons = Math.round((i == null ? void 0 : i.dgo) / 24 * r.totalHrs * 1e3) / 1e3;
|
|
936
|
+
const P = v().valueOf() - m, A = ((L = b == null ? void 0 : b.hours) == null ? void 0 : L.length) || 1;
|
|
937
|
+
return p == null || p.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", l == null ? void 0 : l.requestId, P, A, Math.round(P / A * 1e3) / 1e3), r;
|
|
938
938
|
}
|
|
939
939
|
/**
|
|
940
940
|
* 分段失速分析(最多走hours 小时)
|
|
@@ -949,11 +949,11 @@ class q {
|
|
|
949
949
|
* @param useMeteo true 启用气象分析
|
|
950
950
|
* @param useRouteParam
|
|
951
951
|
*/
|
|
952
|
-
static async analyseInstantWithThreshed(e, t, o, i, a, n, s,
|
|
953
|
-
var J,
|
|
954
|
-
const h =
|
|
952
|
+
static async analyseInstantWithThreshed(e, t, o, i, a, n, s, d = "", c = 3, l = !0, m = !1, f = {}) {
|
|
953
|
+
var J, _, K, G;
|
|
954
|
+
const h = v().valueOf();
|
|
955
955
|
e.lng = z.convertToStdLng(e.lng);
|
|
956
|
-
const { v0: u, label:
|
|
956
|
+
const { v0: u, label: I } = e.sog ? {
|
|
957
957
|
v0: e.sog,
|
|
958
958
|
label: "Other"
|
|
959
959
|
/* Instruct */
|
|
@@ -961,64 +961,52 @@ class q {
|
|
|
961
961
|
v0: a.speed,
|
|
962
962
|
label: "CP"
|
|
963
963
|
/* Cp */
|
|
964
|
-
}, k =
|
|
965
|
-
if (((J =
|
|
964
|
+
}, k = E.assembleProperties(i, a.loadCondition, u, 0), y = B.calculateSubRoute(e, n);
|
|
965
|
+
if (((J = y[0]) == null ? void 0 : J.length) <= 1)
|
|
966
966
|
return;
|
|
967
|
-
const
|
|
968
|
-
|
|
969
|
-
let
|
|
970
|
-
const
|
|
967
|
+
const w = s.length ? B.calculateSubWaypoints(e, s) : [];
|
|
968
|
+
w.forEach((L) => L.important = !0);
|
|
969
|
+
let r = B.simplifyRouteToCoordinates(y, w, 0), b = 0, x = 0, g = 0, j = 0;
|
|
970
|
+
const Y = {
|
|
971
971
|
hours: [],
|
|
972
972
|
wps: [],
|
|
973
973
|
days: []
|
|
974
974
|
};
|
|
975
|
-
t =
|
|
976
|
-
const
|
|
977
|
-
for (;
|
|
978
|
-
const L =
|
|
975
|
+
t = v(t).utc();
|
|
976
|
+
const C = t.clone();
|
|
977
|
+
for (; r.length > 0; ) {
|
|
978
|
+
const L = c - t.hour() % c;
|
|
979
979
|
let N = Math.ceil(t.clone().add(L, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4;
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
t,
|
|
984
|
-
D,
|
|
985
|
-
N,
|
|
986
|
-
M,
|
|
987
|
-
d,
|
|
988
|
-
c,
|
|
989
|
-
l,
|
|
990
|
-
y,
|
|
991
|
-
m
|
|
992
|
-
);
|
|
993
|
-
(K = F.from) != null && K.speed && (S.hours.push(F.from), F != null && F.wps && S.wps.push(...F.wps), S.days.push(...F.days)), d = F == null ? void 0 : F.next, d.length || S.hours.push(F == null ? void 0 : F.to), M += Math.round((((_ = F == null ? void 0 : F.to) == null ? void 0 : _.distanceFromPrevious) ?? 0) * 1e4) / 1e4;
|
|
994
|
-
} else
|
|
980
|
+
N = t.clone().add(N, "h").isSameOrAfter(o) ? o.diff(t, "h", !0) * 1e4 / 1e4 : N;
|
|
981
|
+
const F = await E.speedLoseInHoursStep(k, t, C, N, b, r, d, l, m, f);
|
|
982
|
+
if ((_ = F.from) != null && _.speed && (Y.hours.push(F.from), F != null && F.wps && Y.wps.push(...F.wps), Y.days.push(...F.days)), r = F == null ? void 0 : F.next, r.length || Y.hours.push(F == null ? void 0 : F.to), b += Math.round((((K = F == null ? void 0 : F.to) == null ? void 0 : K.distanceFromPrevious) ?? 0) * 1e4) / 1e4, !N)
|
|
995
983
|
break;
|
|
996
984
|
}
|
|
997
|
-
const
|
|
998
|
-
for (let L = 0; L <
|
|
999
|
-
const N =
|
|
1000
|
-
|
|
985
|
+
const q = Y.hours;
|
|
986
|
+
for (let L = 0; L < q.length - 1; L++) {
|
|
987
|
+
const N = v(q[L + 1].eta).diff(q[L].etd, "hour", !0);
|
|
988
|
+
x += q[L].wxFactor * N, g += q[L].cFactor * N, j += N;
|
|
1001
989
|
}
|
|
1002
|
-
const
|
|
1003
|
-
sample:
|
|
1004
|
-
distance: Math.round(((
|
|
990
|
+
const T = Y.hours.at(0), D = Y.hours.at(-1), V = {
|
|
991
|
+
sample: Y,
|
|
992
|
+
distance: Math.round(((D == null ? void 0 : D.distanceFromStart) || 0) * 1e4) / 1e4,
|
|
1005
993
|
// 注意,可能会在first节点Drift,所有采用eta做为初始出发时间
|
|
1006
|
-
etd:
|
|
1007
|
-
eta:
|
|
1008
|
-
wxFactor: Math.round(
|
|
1009
|
-
cFactor: Math.round(
|
|
1010
|
-
avgSpeed: Math.round(((
|
|
1011
|
-
totalHrs: Math.round(
|
|
1012
|
-
totalFoCons: Math.round((a == null ? void 0 : a.fo) / 24 *
|
|
1013
|
-
totalDgoCons: Math.round((a == null ? void 0 : a.dgo) / 24 *
|
|
1014
|
-
from:
|
|
1015
|
-
to:
|
|
1016
|
-
route:
|
|
1017
|
-
waypoints:
|
|
994
|
+
etd: v(T.eta).utc().format(),
|
|
995
|
+
eta: v(D == null ? void 0 : D.eta).utc().format(),
|
|
996
|
+
wxFactor: Math.round(x / j * 1e4) / 1e4,
|
|
997
|
+
cFactor: Math.round(g / j * 1e4) / 1e4,
|
|
998
|
+
avgSpeed: Math.round(((D == null ? void 0 : D.distanceFromStart) || 0) / j * 1e4) / 1e4,
|
|
999
|
+
totalHrs: Math.round(j * 1e4) / 1e4,
|
|
1000
|
+
totalFoCons: Math.round((a == null ? void 0 : a.fo) / 24 * j * 1e3) / 1e3,
|
|
1001
|
+
totalDgoCons: Math.round((a == null ? void 0 : a.dgo) / 24 * j * 1e3) / 1e3,
|
|
1002
|
+
from: T,
|
|
1003
|
+
to: D,
|
|
1004
|
+
route: y,
|
|
1005
|
+
waypoints: w,
|
|
1018
1006
|
v0: u,
|
|
1019
|
-
label:
|
|
1020
|
-
},
|
|
1021
|
-
return
|
|
1007
|
+
label: I
|
|
1008
|
+
}, P = v().valueOf() - h, A = ((G = Y == null ? void 0 : Y.hours) == null ? void 0 : G.length) || 1;
|
|
1009
|
+
return p == null || p.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", f == null ? void 0 : f.requestId, P, A, Math.round(P / A * 1e3) / 1e3), V;
|
|
1022
1010
|
}
|
|
1023
1011
|
/**
|
|
1024
1012
|
* 在指定航线条件下,基于多CP,动态计算最优成本(租金+油费)方案
|
|
@@ -1036,54 +1024,56 @@ class q {
|
|
|
1036
1024
|
* @param options
|
|
1037
1025
|
*/
|
|
1038
1026
|
static async analyseCost(e, t, o, i, a = {}) {
|
|
1039
|
-
var
|
|
1040
|
-
const n =
|
|
1041
|
-
a.meteo2 = !0, e.speedStep = e.speedStep || 3;
|
|
1042
|
-
const
|
|
1043
|
-
let
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1027
|
+
var y, w;
|
|
1028
|
+
const n = v().valueOf(), s = [];
|
|
1029
|
+
a.meteo2 = !0, e.speedStep = e.speedStep || 3, e.alterStep = e.alterStep ?? 1;
|
|
1030
|
+
const d = B.calculateRouteDistance(i.route);
|
|
1031
|
+
let c = 0;
|
|
1032
|
+
o.forEach((r) => {
|
|
1033
|
+
const b = Math.ceil(d / r.speed / 24);
|
|
1034
|
+
c = c < b ? b : c;
|
|
1035
|
+
}), c = c * 1.3;
|
|
1036
|
+
const l = v.utc(e.etd).add(c ?? 14, "day");
|
|
1037
|
+
let m = 1;
|
|
1038
|
+
for (const r of o) {
|
|
1039
|
+
const b = JSON.parse(JSON.stringify(i.route)), x = JSON.parse(JSON.stringify(i.waypoints)), g = await E.analyseInstantWithThreshed(
|
|
1047
1040
|
{ lat: e.lat, lng: e.lng },
|
|
1048
1041
|
e.etd,
|
|
1049
|
-
|
|
1042
|
+
l,
|
|
1050
1043
|
t,
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1044
|
+
r,
|
|
1045
|
+
b,
|
|
1046
|
+
x,
|
|
1054
1047
|
e.meteoVendor,
|
|
1055
1048
|
e.speedStep,
|
|
1056
1049
|
e.useMeteo,
|
|
1057
1050
|
e.useRouteParam,
|
|
1058
1051
|
a
|
|
1059
1052
|
);
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
eta: M.eta,
|
|
1067
|
-
cost: M.cost
|
|
1068
|
-
})), r++;
|
|
1053
|
+
g && (await E.calculateCost(g, r, e, a), s.push(g), p == null || p.info("[%s][L%d-%d] analyse from %s to %s cost: %j", a.requestId, 1, m, e.etd, l.format(), {
|
|
1054
|
+
cost: g.cost.total,
|
|
1055
|
+
distance: g.distance,
|
|
1056
|
+
hours: g.totalHrs,
|
|
1057
|
+
cp: `${r.speed}/${r.fo}/${r.dgo}`
|
|
1058
|
+
})), m++;
|
|
1069
1059
|
}
|
|
1070
|
-
s.sort((
|
|
1071
|
-
const
|
|
1072
|
-
if (
|
|
1073
|
-
const
|
|
1074
|
-
let
|
|
1075
|
-
|
|
1076
|
-
let
|
|
1077
|
-
for (;
|
|
1078
|
-
const
|
|
1079
|
-
if (
|
|
1060
|
+
s.sort((r, b) => r.cost.total - b.cost.total);
|
|
1061
|
+
const f = s.at(0), h = s.at(1), u = [];
|
|
1062
|
+
if (u.push({ combined: !1, speeds: [f], cost: (y = f.cost) == null ? void 0 : y.total }), h) {
|
|
1063
|
+
const r = f.cost.cp, b = h.cost.cp, x = v(f.eta), g = v(f.etd), j = x.diff(g, "days", !0);
|
|
1064
|
+
let Y = Math.ceil(j / 2);
|
|
1065
|
+
Y = Y > 7 ? 7 : Y < e.alterStep ? e.alterStep : Y;
|
|
1066
|
+
let C = 2, q = { combined: !1, speeds: [h], cost: (w = h.cost) == null ? void 0 : w.total }, T;
|
|
1067
|
+
for (; Y >= e.alterStep; ) {
|
|
1068
|
+
const D = await E.combinedAnalyse(e, t, l, [r, b], i, Y, { ...a, level: C });
|
|
1069
|
+
if (q.cost > D.cost ? T ? (T == null ? void 0 : T.cost) > D.cost && (T = D) : (T = q, q = D) : (!T || (T == null ? void 0 : T.cost) > D.cost) && (T = D), Y <= e.alterStep)
|
|
1080
1070
|
break;
|
|
1081
|
-
|
|
1071
|
+
Y = Math.ceil(Y / 2), C += 1;
|
|
1082
1072
|
}
|
|
1083
|
-
|
|
1073
|
+
u.push(q), T && u.push(T);
|
|
1084
1074
|
}
|
|
1085
|
-
const
|
|
1086
|
-
return
|
|
1075
|
+
const k = v().valueOf() - n;
|
|
1076
|
+
return p == null || p.info("[%s] analyse elapsed: %d ms", a == null ? void 0 : a.requestId, k), u.sort((r, b) => r.cost - b.cost);
|
|
1087
1077
|
}
|
|
1088
1078
|
/**
|
|
1089
1079
|
* 按步长多次减半,分别用7,4,2,1天步长及cpa,cpb交替计算各种组合下的成本
|
|
@@ -1096,11 +1086,11 @@ class q {
|
|
|
1096
1086
|
* @param options
|
|
1097
1087
|
*/
|
|
1098
1088
|
static async combinedAnalyse(e, t, o, i, a, n, s = {}) {
|
|
1099
|
-
s.counter = 1,
|
|
1100
|
-
const
|
|
1101
|
-
|
|
1102
|
-
const l = await
|
|
1103
|
-
return
|
|
1089
|
+
s.counter = 1, p == null || p.info("[%s][L%d] analyse with alternate cp in every %d days", s.requestId, s.level, n);
|
|
1090
|
+
const d = await E.alternateAnalyse(e, t, o, i, 0, a, n, s), c = d.reduce((f, h) => f + h.cost.total, 0);
|
|
1091
|
+
p == null || p.info("[%s][L%d] cost with cpa/cpb turn: %d", s.requestId, s.level, c);
|
|
1092
|
+
const l = await E.alternateAnalyse(e, t, o, i, 1, a, n, s), m = l.reduce((f, h) => f + h.cost.total, 0);
|
|
1093
|
+
return p == null || p.info("[%s][L%d] cost with cpb/cpa turn: %d", s.requestId, s.level, m), c < m ? { combined: !0, cost: Math.round(c * 1e3) / 1e3, speeds: d } : { combined: !0, cost: Math.round(m * 1e3) / 1e3, speeds: l };
|
|
1104
1094
|
}
|
|
1105
1095
|
/**
|
|
1106
1096
|
* 基于cp索引,交替计算指定步长下的成本
|
|
@@ -1113,43 +1103,41 @@ class q {
|
|
|
1113
1103
|
* @param step 步长,7,4,2,1
|
|
1114
1104
|
* @param options
|
|
1115
1105
|
*/
|
|
1116
|
-
static async alternateAnalyse(e, t, o, i, a, n, s,
|
|
1117
|
-
var
|
|
1118
|
-
let
|
|
1119
|
-
const l = { lat: e.lat, lng: e.lng },
|
|
1120
|
-
for (;
|
|
1121
|
-
const u =
|
|
1122
|
-
g == null || g.info("[%s][L%d-%d] analyse from %s to %s", c.requestId, c.level, c.counter, r.utc().format(), u.utc().format());
|
|
1123
|
-
const p = JSON.parse(JSON.stringify(n.route)), k = JSON.parse(JSON.stringify(n.waypoints)), f = await q.analyseInstantWithThreshed(
|
|
1106
|
+
static async alternateAnalyse(e, t, o, i, a, n, s, d = {}) {
|
|
1107
|
+
var f, h;
|
|
1108
|
+
let c = v.utc(e.etd);
|
|
1109
|
+
const l = { lat: e.lat, lng: e.lng }, m = [];
|
|
1110
|
+
for (; c.isBefore(o); ) {
|
|
1111
|
+
const u = c.clone().utc().add(s, "day"), I = JSON.parse(JSON.stringify(n.route)), k = JSON.parse(JSON.stringify(n.waypoints)), y = i[a], w = await E.analyseInstantWithThreshed(
|
|
1124
1112
|
l,
|
|
1125
|
-
|
|
1113
|
+
c.format(),
|
|
1126
1114
|
u,
|
|
1127
1115
|
t,
|
|
1128
|
-
|
|
1129
|
-
|
|
1116
|
+
y,
|
|
1117
|
+
I,
|
|
1130
1118
|
k,
|
|
1131
1119
|
e.meteoVendor,
|
|
1132
1120
|
e.speedStep,
|
|
1133
1121
|
e.useMeteo,
|
|
1134
1122
|
e.useRouteParam,
|
|
1135
|
-
|
|
1123
|
+
d
|
|
1136
1124
|
);
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
cost:
|
|
1145
|
-
|
|
1146
|
-
const
|
|
1147
|
-
if (
|
|
1148
|
-
l.lat =
|
|
1125
|
+
w && (await E.calculateCost(w, y, e, d), p == null || p.info(
|
|
1126
|
+
"[%s][L%d-%d] analyse from %s to %s cost: %j",
|
|
1127
|
+
d.requestId,
|
|
1128
|
+
d.level,
|
|
1129
|
+
d.counter,
|
|
1130
|
+
c.utc().format(),
|
|
1131
|
+
u.utc().format(),
|
|
1132
|
+
{ cost: w.cost.total, distance: w.distance, hours: w.totalHrs, cp: `${y.speed}/${y.fo}/${y.dgo}` }
|
|
1133
|
+
)), d.counter = d.counter + 1;
|
|
1134
|
+
const r = (h = (f = w == null ? void 0 : w.sample) == null ? void 0 : f.hours) == null ? void 0 : h.at(-1);
|
|
1135
|
+
if (r)
|
|
1136
|
+
l.lat = r.lat, l.lng = r.lng, c = v(r.eta), m.push(w), a = a ? 0 : 1;
|
|
1149
1137
|
else
|
|
1150
1138
|
break;
|
|
1151
1139
|
}
|
|
1152
|
-
return
|
|
1140
|
+
return m;
|
|
1153
1141
|
}
|
|
1154
1142
|
/**
|
|
1155
1143
|
* 计算Speed的cost
|
|
@@ -1175,18 +1163,18 @@ class q {
|
|
|
1175
1163
|
hours: [],
|
|
1176
1164
|
wps: [],
|
|
1177
1165
|
days: []
|
|
1178
|
-
}, i = e.reduce((h, u) => h + u.distance, 0), a = e.reduce((h, u) => h + u.totalHrs, 0), n = e.reduce((h, u) => h + u.wxFactor * u.totalHrs / a, 0), s = e.reduce((h, u) => h + u.cFactor * u.totalHrs / a, 0),
|
|
1166
|
+
}, i = e.reduce((h, u) => h + u.distance, 0), a = e.reduce((h, u) => h + u.totalHrs, 0), n = e.reduce((h, u) => h + u.wxFactor * u.totalHrs / a, 0), s = e.reduce((h, u) => h + u.cFactor * u.totalHrs / a, 0), d = e.reduce((h, u) => h + u.totalFoCons, 0), c = e.reduce((h, u) => h + u.totalDgoCons, 0), l = e.reduce((h, u) => h + u.cost.total, 0), m = e.reduce((h, u) => h + u.cost.hire, 0), f = e.reduce((h, u) => h + u.cost.bunker, 0);
|
|
1179
1167
|
for (const h of e) {
|
|
1180
|
-
const u = h.sample.hours,
|
|
1181
|
-
u.forEach((
|
|
1182
|
-
var
|
|
1183
|
-
((
|
|
1184
|
-
}),
|
|
1185
|
-
var
|
|
1186
|
-
((
|
|
1187
|
-
}), k.forEach((
|
|
1188
|
-
var
|
|
1189
|
-
((
|
|
1168
|
+
const u = h.sample.hours, I = h.sample.wps, k = h.sample.days;
|
|
1169
|
+
u.forEach((y) => {
|
|
1170
|
+
var r;
|
|
1171
|
+
((r = o.hours) == null ? void 0 : r.findIndex((b) => b.eta === y.eta)) === -1 && o.hours.push(y);
|
|
1172
|
+
}), I.forEach((y) => {
|
|
1173
|
+
var r;
|
|
1174
|
+
((r = o.wps) == null ? void 0 : r.findIndex((b) => b.eta === y.eta)) === -1 && o.wps.push(y);
|
|
1175
|
+
}), k.forEach((y) => {
|
|
1176
|
+
var r;
|
|
1177
|
+
((r = o == null ? void 0 : o.days) == null ? void 0 : r.findIndex((b) => b.eta === y.eta)) === -1 && o.days.push(y);
|
|
1190
1178
|
});
|
|
1191
1179
|
}
|
|
1192
1180
|
return {
|
|
@@ -1201,12 +1189,12 @@ class q {
|
|
|
1201
1189
|
avgSpeed: Math.round(i / a * 1e3) / 1e3,
|
|
1202
1190
|
wxFactor: Math.round(n / a * 1e3) / 1e3,
|
|
1203
1191
|
cFactor: Math.round(s / a * 1e3) / 1e3,
|
|
1204
|
-
totalFoCons: Math.round(
|
|
1205
|
-
totalDgoCons: Math.round(
|
|
1192
|
+
totalFoCons: Math.round(d * 1e3) / 1e3,
|
|
1193
|
+
totalDgoCons: Math.round(c * 1e3) / 1e3,
|
|
1206
1194
|
cost: {
|
|
1207
1195
|
total: Math.round(l * 1e3) / 1e3,
|
|
1208
|
-
hire: Math.round(
|
|
1209
|
-
bunker: Math.round(
|
|
1196
|
+
hire: Math.round(m * 1e3) / 1e3,
|
|
1197
|
+
bunker: Math.round(f * 1e3) / 1e3
|
|
1210
1198
|
}
|
|
1211
1199
|
};
|
|
1212
1200
|
}
|
|
@@ -1217,10 +1205,10 @@ export {
|
|
|
1217
1205
|
it as AlertLevel,
|
|
1218
1206
|
wt as HifleetImpl,
|
|
1219
1207
|
ut as LoadCondition,
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1208
|
+
It as MyShipImpl,
|
|
1209
|
+
vt as MyVesselImpl,
|
|
1210
|
+
pt as ShipxyImpl,
|
|
1211
|
+
E as SpeedHelper,
|
|
1224
1212
|
ht as SpeedLabel,
|
|
1225
1213
|
dt as VesselTag,
|
|
1226
1214
|
kt as alertHelper
|