@idm-plugin/vessel 1.8.4 → 1.8.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 +336 -327
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
var ht = Object.defineProperty;
|
|
2
|
-
var lt = (
|
|
3
|
-
var G = (
|
|
2
|
+
var lt = (C, e, t) => e in C ? ht(C, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : C[e] = t;
|
|
3
|
+
var G = (C, e, t) => (lt(C, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
4
|
import B from "got";
|
|
5
5
|
import it from "@log4js-node/log4js-api";
|
|
6
|
-
import
|
|
6
|
+
import b from "moment";
|
|
7
7
|
import { LngLatHelper as J, LaneHelper as W } from "@idm-plugin/geo2";
|
|
8
8
|
import { MeteoHelper2 as ft, MeteoHelper as mt } from "@idm-plugin/meteo2";
|
|
9
9
|
import { Meteo2Assist as ct } from "@idm-plugin/meteo";
|
|
10
|
-
let
|
|
10
|
+
let p;
|
|
11
11
|
try {
|
|
12
|
-
|
|
12
|
+
p = it.getLogger("vessel");
|
|
13
13
|
} catch {
|
|
14
14
|
} finally {
|
|
15
15
|
}
|
|
@@ -54,7 +54,7 @@ class et {
|
|
|
54
54
|
return { labelCn: t, labelEn: n };
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
class
|
|
57
|
+
class Ct extends et {
|
|
58
58
|
constructor(t, n) {
|
|
59
59
|
super();
|
|
60
60
|
G(this, "clientId");
|
|
@@ -70,32 +70,32 @@ class jt extends et {
|
|
|
70
70
|
grant_type: "client_credentials"
|
|
71
71
|
}
|
|
72
72
|
}, o = await B.post(n, i).json();
|
|
73
|
-
|
|
73
|
+
p == null || p.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: b().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 || b().diff(b(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
|
-
Authorization: `${(
|
|
87
|
+
Authorization: `${(M = this.token) == null ? void 0 : M.tokenType} ${(l = this.token) == null ? void 0 : l.accessToken}`
|
|
88
88
|
},
|
|
89
89
|
searchParams: { mmsi: t }
|
|
90
90
|
};
|
|
91
|
-
|
|
91
|
+
p == null || p.info("[%s] fetch realtime position from: %s - %j", n.requestId, i, o);
|
|
92
92
|
const a = await B.get(i, o).json();
|
|
93
93
|
if (a.code)
|
|
94
|
-
return
|
|
94
|
+
return p == null || p.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
|
-
for (const
|
|
97
|
-
!isNaN(s[
|
|
98
|
-
const d =
|
|
96
|
+
for (const g in s)
|
|
97
|
+
!isNaN(s[g]) && Number(s[g]) !== 1 / 0 && (s[g] = Number(s[g]));
|
|
98
|
+
const d = b(`${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 jt extends et {
|
|
|
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) ? b.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 jt extends et {
|
|
|
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), r =
|
|
127
|
-
for (;
|
|
128
|
-
await this.trajectoryIn30Day(t, r, r.clone().add(30, "day"), d, o,
|
|
129
|
-
return await this.trajectoryIn30Day(t, r,
|
|
125
|
+
(!this.token || b().diff(b(this.token.issuedAt), "seconds") > this.token.expiresIn - 300) && await this.authToken(s);
|
|
126
|
+
const d = await this.realTimePosition(t, s), r = b(n), h = b(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 r = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",
|
|
132
|
+
var f, x, I, m, v;
|
|
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} ${(x = this.token) == null ? void 0 : x.accessToken}`
|
|
136
136
|
},
|
|
137
137
|
json: {
|
|
138
138
|
mmsi: t,
|
|
@@ -140,16 +140,16 @@ class jt extends et {
|
|
|
140
140
|
endTime: i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
if (
|
|
146
|
-
return
|
|
143
|
+
p == null || p.info("[%s] fetch trajectory from: %s - %j", d.requestId, r, h);
|
|
144
|
+
const M = await B.post(r, h).json();
|
|
145
|
+
if (M.code)
|
|
146
|
+
return p == null || p.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
|
|
149
|
-
return (v =
|
|
148
|
+
const g = b(`${(m = (I = M.data) == null ? void 0 : I[0]) == null ? void 0 : m.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
149
|
+
return (v = M.data) == null || v.forEach((c) => {
|
|
150
150
|
for (const Y in c)
|
|
151
151
|
!isNaN(c[Y]) && Number(c[Y]) !== 1 / 0 && (c[Y] = Number(c[Y]));
|
|
152
|
-
const
|
|
152
|
+
const w = b(`${c.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), y = c.status, { labelCn: u, labelEn: k } = this.parseStatus(y), S = {
|
|
153
153
|
mmsi: c.mmsi,
|
|
154
154
|
imo: o == null ? void 0 : o.imo,
|
|
155
155
|
lat: c.lat,
|
|
@@ -159,15 +159,15 @@ class jt extends et {
|
|
|
159
159
|
hdg: c.hdg,
|
|
160
160
|
draught: c.draught,
|
|
161
161
|
status: y,
|
|
162
|
-
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(c.eta) ?
|
|
162
|
+
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(c.eta) ? b(`${c.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00").utc().format() : void 0,
|
|
163
163
|
destination: c.dest,
|
|
164
|
-
positionTime:
|
|
165
|
-
labelCn:
|
|
166
|
-
labelEn:
|
|
164
|
+
positionTime: w.unix(),
|
|
165
|
+
labelCn: u,
|
|
166
|
+
labelEn: k,
|
|
167
167
|
method: "trajectory",
|
|
168
168
|
vendor: "myVessel",
|
|
169
|
-
utc:
|
|
170
|
-
}, D = Math.floor(
|
|
169
|
+
utc: w.utc().format()
|
|
170
|
+
}, D = Math.floor(w.diff(g, "minute", !0) / (a || 1));
|
|
171
171
|
D !== l && (l = D, s.push(S));
|
|
172
172
|
}), s;
|
|
173
173
|
}
|
|
@@ -185,14 +185,14 @@ class Et extends et {
|
|
|
185
185
|
usertoken: this.token
|
|
186
186
|
}
|
|
187
187
|
}, a = await B.post(i, o).json();
|
|
188
|
-
|
|
188
|
+
p == null || p.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)
|
|
191
|
-
return
|
|
192
|
-
for (const
|
|
193
|
-
!isNaN(s[
|
|
191
|
+
return p == null || p.warn("[%s] fetch realtime position failed: %j", n.requestId, i, a), a;
|
|
192
|
+
for (const g in s)
|
|
193
|
+
!isNaN(s[g]) && Number(s[g]) !== 1 / 0 && (s[g] = Number(s[g]));
|
|
194
194
|
s.status = s.sp > 3 ? 0 : 1;
|
|
195
|
-
const d = s.status, { labelCn: r, labelEn:
|
|
195
|
+
const d = s.status, { labelCn: r, labelEn: h } = this.parseStatus(d), M = b(`${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 Et extends et {
|
|
|
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) ? b.utc(s.eta).format() : void 0,
|
|
211
211
|
destination: s.destination,
|
|
212
|
-
positionTime:
|
|
213
|
-
utc:
|
|
212
|
+
positionTime: M.unix(),
|
|
213
|
+
utc: M.utc().format(),
|
|
214
214
|
status: d,
|
|
215
215
|
labelCn: r,
|
|
216
|
-
labelEn:
|
|
216
|
+
labelEn: h,
|
|
217
217
|
method: "position",
|
|
218
218
|
vendor: "hifleet"
|
|
219
219
|
};
|
|
@@ -231,7 +231,7 @@ class Et extends et {
|
|
|
231
231
|
}
|
|
232
232
|
};
|
|
233
233
|
let a = await B.post(i, o).json();
|
|
234
|
-
|
|
234
|
+
p == null || p.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]));
|
|
237
237
|
const s = {
|
|
@@ -244,7 +244,7 @@ class Et extends et {
|
|
|
244
244
|
draught: a.dr,
|
|
245
245
|
type: a.t
|
|
246
246
|
};
|
|
247
|
-
return i = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", a = await B.post(i, o).json(),
|
|
247
|
+
return i = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", a = await B.post(i, o).json(), p == null || p.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 = {
|
|
@@ -257,7 +257,7 @@ class Et extends et {
|
|
|
257
257
|
Host: "www.hifleet.com"
|
|
258
258
|
}
|
|
259
259
|
}, a = await B.post(i, o).json();
|
|
260
|
-
|
|
260
|
+
p == null || p.info("[%s] suggest vessel props from: %s - %j", n.requestId, i, o);
|
|
261
261
|
const s = [];
|
|
262
262
|
for (const d of a)
|
|
263
263
|
s.push({
|
|
@@ -270,54 +270,54 @@ class Et extends et {
|
|
|
270
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 c,
|
|
273
|
+
var c, w, y;
|
|
274
274
|
const d = await this.realTimePosition(t, s);
|
|
275
|
-
let r =
|
|
276
|
-
const
|
|
275
|
+
let r = b(n);
|
|
276
|
+
const h = b(i), M = b();
|
|
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:
|
|
283
|
+
endtime: h.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
|
|
284
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
|
-
},
|
|
289
|
-
|
|
290
|
-
let
|
|
291
|
-
f && (
|
|
292
|
-
const
|
|
293
|
-
let
|
|
294
|
-
const v =
|
|
295
|
-
for (const
|
|
296
|
-
for (const P in
|
|
297
|
-
!isNaN(
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
const { labelEn: S, labelCn: D } = this.parseStatus(
|
|
301
|
-
mmsi:
|
|
302
|
-
name:
|
|
288
|
+
}, g = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", f = await B.get(g, l).json();
|
|
289
|
+
p == null || p.info("[%s] fetch trajectory from: %s - %j", s.requestId, g, l);
|
|
290
|
+
let x;
|
|
291
|
+
f && (x = ((w = (c = f.ships) == null ? void 0 : c.offors) == null ? void 0 : w.ship) || [], x.length || p == null || p.warn("[%s] fetch trajectory failed: %j", s.requestId, f));
|
|
292
|
+
const I = [];
|
|
293
|
+
let m = -1;
|
|
294
|
+
const v = b(`${(y = x == null ? void 0 : x[0]) == null ? void 0 : y.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
295
|
+
for (const u of x) {
|
|
296
|
+
for (const P in u)
|
|
297
|
+
!isNaN(u[P]) && Number(u[P]) !== 1 / 0 && (u[P] = Number(u[P]));
|
|
298
|
+
const k = b(`${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:
|
|
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: k.unix(),
|
|
311
|
+
utc: k.utc().format(),
|
|
312
|
+
status: u.status,
|
|
313
313
|
labelCn: D,
|
|
314
314
|
labelEn: S,
|
|
315
315
|
method: "trajectory",
|
|
316
316
|
vendor: "hifleet"
|
|
317
|
-
}, E = Math.floor(
|
|
318
|
-
E !==
|
|
317
|
+
}, E = Math.floor(k.diff(v, "minute", !0) / (o || 1));
|
|
318
|
+
E !== m && (m = E, I.push(Y));
|
|
319
319
|
}
|
|
320
|
-
return
|
|
320
|
+
return I;
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
323
|
class Nt extends et {
|
|
@@ -334,12 +334,12 @@ class Nt extends et {
|
|
|
334
334
|
enc: 1
|
|
335
335
|
}
|
|
336
336
|
}, o = "https://api.shipxy.com/apicall/GetSingleShip", a = await B.get(o, i).json();
|
|
337
|
-
if (
|
|
337
|
+
if (p == null || p.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: r } = await this.parseStatus(s.navistat),
|
|
342
|
+
const { labelCn: d, labelEn: r } = await this.parseStatus(s.navistat), h = b.unix(s.lasttime);
|
|
343
343
|
return {
|
|
344
344
|
mmsi: s.ShipID,
|
|
345
345
|
name: s.name,
|
|
@@ -355,7 +355,7 @@ class Nt extends et {
|
|
|
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
360
|
labelEn: r,
|
|
361
361
|
labelCn: d,
|
|
@@ -365,36 +365,36 @@ class Nt extends et {
|
|
|
365
365
|
}
|
|
366
366
|
async trajectory(t, n, i, o, a = !0, s = {}) {
|
|
367
367
|
var v;
|
|
368
|
-
const d = await this.realTimePosition(t, s), r =
|
|
368
|
+
const d = await this.realTimePosition(t, s), r = b(n), h = b(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
374
|
btm: r.unix(),
|
|
375
|
-
etm:
|
|
375
|
+
etm: h.unix()
|
|
376
376
|
}
|
|
377
|
-
},
|
|
378
|
-
if (
|
|
379
|
-
return
|
|
380
|
-
const f =
|
|
381
|
-
let
|
|
377
|
+
}, g = await B.get(M, l).json();
|
|
378
|
+
if (p == null || p.info("[%s] fetch trajectory from: %s - %j", s.requestId, M, l), (g == null ? void 0 : g.status) !== 0)
|
|
379
|
+
return g;
|
|
380
|
+
const f = g == null ? void 0 : g.points, x = [], I = b.unix((v = f[0]) == null ? void 0 : v.utc);
|
|
381
|
+
let m = -1;
|
|
382
382
|
for (const c of f) {
|
|
383
|
-
const
|
|
383
|
+
const w = b.unix(c.utc), y = {
|
|
384
384
|
imo: d == null ? void 0 : d.imo,
|
|
385
385
|
mmsi: t,
|
|
386
386
|
sog: Math.round(c.sog * 3600 / 1e3 / 1852 * 100) / 100,
|
|
387
387
|
cog: Math.round(c.cog / 100 * 100) / 100,
|
|
388
388
|
lat: Math.round(c.lat / 1e6 * 1e5) / 1e5,
|
|
389
389
|
lng: Math.round(c.lon / 1e6 * 1e5) / 1e5,
|
|
390
|
-
positionTime:
|
|
391
|
-
utc:
|
|
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(I, "minute", !0) / (o || 1));
|
|
395
|
+
u !== m && (m = u, x.push(y));
|
|
396
396
|
}
|
|
397
|
-
return
|
|
397
|
+
return x;
|
|
398
398
|
}
|
|
399
399
|
}
|
|
400
400
|
class Tt extends et {
|
|
@@ -412,7 +412,7 @@ class Tt extends et {
|
|
|
412
412
|
mmsiList: t
|
|
413
413
|
}
|
|
414
414
|
}, o = "https://api3.myships.com/sp/ships/getShipIdByMMSI", a = await B.post(o, i).json();
|
|
415
|
-
return
|
|
415
|
+
return p == null || p.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 = {}) {
|
|
418
418
|
const i = {
|
|
@@ -423,11 +423,11 @@ class Tt extends et {
|
|
|
423
423
|
shipId: t
|
|
424
424
|
}
|
|
425
425
|
}, o = "https://api3.myships.com/sp/ships/aissta", a = await B.post(o, i).json();
|
|
426
|
-
if (
|
|
426
|
+
if (p == null || p.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;
|
|
429
429
|
let d = s.imo;
|
|
430
|
-
return t === "407170" && (d = "9198379",
|
|
430
|
+
return t === "407170" && (d = "9198379", p == null || p.warn("[%s] ship(%s) imo error: %s, should be %s", n.requestId, t, s.imo, d)), {
|
|
431
431
|
mmsi: s.mmsi,
|
|
432
432
|
name: s.shipnameEn,
|
|
433
433
|
imo: d,
|
|
@@ -446,11 +446,11 @@ class Tt extends et {
|
|
|
446
446
|
shipId: i
|
|
447
447
|
}
|
|
448
448
|
}, s = "https://api3.myships.com/sp/ships/position/latest", d = await B.post(s, a).json();
|
|
449
|
-
|
|
449
|
+
p == null || p.info("[%s] fetch realtime position from: %s - %j", n.requestId, s, a);
|
|
450
450
|
const r = d.data[0];
|
|
451
451
|
for (const f in r)
|
|
452
452
|
!isNaN(r[f]) && Number(r[f]) !== 1 / 0 && (r[f] = Number(r[f]));
|
|
453
|
-
const { labelCn:
|
|
453
|
+
const { labelCn: h, labelEn: M } = await this.parseStatus(r.aisNavStatus), l = b.unix(r.posTime);
|
|
454
454
|
return {
|
|
455
455
|
...o,
|
|
456
456
|
mmsi: t,
|
|
@@ -463,21 +463,21 @@ class Tt extends et {
|
|
|
463
463
|
positionTime: r.posTime,
|
|
464
464
|
utc: l.utc().format(),
|
|
465
465
|
status: r.aisNavStatus,
|
|
466
|
-
labelEn:
|
|
467
|
-
labelCn:
|
|
466
|
+
labelEn: M,
|
|
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 =
|
|
473
|
+
const d = b(n), r = b(i), h = await this.getShipId(t), M = await this.getShipInfo(h), l = [];
|
|
474
474
|
for (; r.diff(d, "day", !0) > 30; )
|
|
475
|
-
await this.trajectoryIn30Day(
|
|
476
|
-
return await this.trajectoryIn30Day(
|
|
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
478
|
async trajectoryIn30Day(t, n, i, o, a, s, d, r = {}) {
|
|
479
|
-
var
|
|
480
|
-
const
|
|
479
|
+
var I;
|
|
480
|
+
const h = {
|
|
481
481
|
headers: {
|
|
482
482
|
appKey: this.token
|
|
483
483
|
},
|
|
@@ -486,30 +486,30 @@ class Tt extends et {
|
|
|
486
486
|
startTime: n,
|
|
487
487
|
endTime: i
|
|
488
488
|
}
|
|
489
|
-
},
|
|
490
|
-
if (
|
|
491
|
-
return
|
|
492
|
-
const
|
|
493
|
-
for (const
|
|
494
|
-
!isNaN(
|
|
495
|
-
const f =
|
|
496
|
-
let
|
|
497
|
-
for (const
|
|
498
|
-
const v =
|
|
489
|
+
}, M = "https://api3.myships.com/sp/ships/position/history", l = await B.post(M, h).json();
|
|
490
|
+
if (p == null || p.info("[%s] fetch trajectory from: %s - %j", r.requestId, M, h), l.code !== "0")
|
|
491
|
+
return p == null || p.warn("[%s] invoke myship trajectory failed: %j", r.requestId, l), l;
|
|
492
|
+
const g = l.data;
|
|
493
|
+
for (const m in g)
|
|
494
|
+
!isNaN(g[m]) && Number(g[m]) !== 1 / 0 && (g[m] = Number(g[m]));
|
|
495
|
+
const f = b.unix((I = g[0]) == null ? void 0 : I.posTime);
|
|
496
|
+
let x = -1;
|
|
497
|
+
for (const m of g) {
|
|
498
|
+
const v = b.unix(m.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(
|
|
501
|
+
lat: Math.round(m.lat / 1e4 / 60 * 1e5) / 1e5,
|
|
502
|
+
lng: Math.round(m.lon / 1e4 / 60 * 1e5) / 1e5,
|
|
503
|
+
sog: Math.round(m.sog / 10 * 100) / 100,
|
|
504
|
+
cog: Math.round(m.cog / 10 * 100) / 100,
|
|
505
|
+
hdg: Math.round(m.heading * 100) / 100,
|
|
506
|
+
rot: Math.round(m.rot * 100) / 100,
|
|
507
507
|
positionTime: v.unix(),
|
|
508
508
|
utc: v.utc().format(),
|
|
509
509
|
method: "trajectory",
|
|
510
510
|
vendor: "myship"
|
|
511
|
-
},
|
|
512
|
-
|
|
511
|
+
}, w = Math.floor(v.diff(f, "minute", !0) / (s || 1));
|
|
512
|
+
w !== x && (x = w, d.push(c));
|
|
513
513
|
}
|
|
514
514
|
return d;
|
|
515
515
|
}
|
|
@@ -520,7 +520,7 @@ try {
|
|
|
520
520
|
} catch {
|
|
521
521
|
} finally {
|
|
522
522
|
}
|
|
523
|
-
var yt = /* @__PURE__ */ ((
|
|
523
|
+
var yt = /* @__PURE__ */ ((C) => (C.NOTICE = "NOTICE", C.WARN = "WARN", C.HEAVY = "HEAVY", C.SEVERE = "SEVERE", C.ERROR = "ERROR", C.FATAL = "FATAL", C))(yt || {});
|
|
524
524
|
class Mt {
|
|
525
525
|
/**
|
|
526
526
|
* 解析告警规则, 多规则场景
|
|
@@ -537,13 +537,13 @@ class Mt {
|
|
|
537
537
|
if (!o)
|
|
538
538
|
return;
|
|
539
539
|
const a = {};
|
|
540
|
-
for (let
|
|
541
|
-
const
|
|
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
|
-
else if (
|
|
545
|
-
for (let l = 0,
|
|
546
|
-
const f = this.parseRule(
|
|
544
|
+
else if (M)
|
|
545
|
+
for (let l = 0, g = M.length; l < g; l++) {
|
|
546
|
+
const f = this.parseRule(M[l]);
|
|
547
547
|
f && (a[f.level] ? f.key ? a[f.level][f == null ? void 0 : f.key] = f : a[f.level] = f : f.key ? a[f.level] = { [f == null ? void 0 : f.key]: f } : a[f.level] = f);
|
|
548
548
|
}
|
|
549
549
|
}
|
|
@@ -575,14 +575,14 @@ class Mt {
|
|
|
575
575
|
* @param options
|
|
576
576
|
*/
|
|
577
577
|
checkWeather(e, t, n = {}) {
|
|
578
|
-
var f,
|
|
578
|
+
var f, x, I, m, v, c, w, y, u, k, S, D, Y, E, P;
|
|
579
579
|
let i = 0, o = 0, a = 0, s = 0;
|
|
580
|
-
const d = Math.round(((
|
|
580
|
+
const d = Math.round(((x = (f = t == null ? void 0 : t.SEVERE) == null ? void 0 : f.sigWave) == null ? void 0 : x.number) * 1.6 * 100) / 100, r = (m = (I = t == null ? void 0 : t.SEVERE) == null ? void 0 : I.sigWave) == null ? void 0 : m.number, h = (c = (v = t == null ? void 0 : t.HEAVY) == null ? void 0 : v.sigWave) == null ? void 0 : c.number, M = Math.round((((y = (w = t == null ? void 0 : t.SEVERE) == null ? void 0 : w.wind) == null ? void 0 : y.number) + 2) * 100) / 100, l = (k = (u = t == null ? void 0 : t.SEVERE) == null ? void 0 : u.wind) == null ? void 0 : k.number, g = (D = (S = t == null ? void 0 : t.HEAVY) == null ? void 0 : S.wind) == null ? void 0 : D.number;
|
|
581
581
|
for (let T = 0; T < (e == null ? void 0 : e.length); T++) {
|
|
582
|
-
const N = e[T], A = (E = (Y = N == null ? void 0 : N.meteo) == null ? void 0 : Y.wave) == null ? void 0 : E.sig, R = (P = N == null ? void 0 : N.meteo) == null ? void 0 : P.wind, K = T ?
|
|
583
|
-
s = K > s ? K : s, _ == null || _.info("[%s] check sig.wave: %j", n.requestId, { ...A, dgThd4Wv: d, svThd4Wv: r, hvThd4Wv:
|
|
582
|
+
const N = e[T], A = (E = (Y = N == null ? void 0 : N.meteo) == null ? void 0 : Y.wave) == null ? void 0 : E.sig, R = (P = N == null ? void 0 : N.meteo) == null ? void 0 : P.wind, K = T ? b(N.eta).diff(b(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 ? N.isDangerous = !0 : (A == null ? void 0 : A.height) >= r ? N.isSevere = !0 : (A == null ? void 0 : A.height) >= h && (N.isHeavy = !0), _ == null || _.info("[%s] check wind: %j", n.requestId, { ...R, dgThd4Wd: M, svThd4Wd: l, hvThd4Wd: g }), (R == null ? void 0 : R.scale) >= M ? (N.isDangerous = !0, delete N.isSevere, delete N.isHeavy) : (R == null ? void 0 : R.scale) > l ? (N.isDangerous || (N.isSevere = !0), delete N.isHeavy) : (R == null ? void 0 : R.scale) === g && !N.isDangerous && !N.isSevere && (N.isHeavy = !0), i += N.isDangerous ? K : 0, o += N.isSevere ? K : 0, a += N.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:
|
|
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: g }, sig: { dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: h } };
|
|
586
586
|
}
|
|
587
587
|
}
|
|
588
588
|
const Dt = new Mt();
|
|
@@ -593,7 +593,7 @@ try {
|
|
|
593
593
|
} finally {
|
|
594
594
|
}
|
|
595
595
|
const gt = new ft("", !0);
|
|
596
|
-
var bt = /* @__PURE__ */ ((
|
|
596
|
+
var bt = /* @__PURE__ */ ((C) => (C.common = "common", C.container = "container", C.tugs = "tugs", C))(bt || {}), pt = /* @__PURE__ */ ((C) => (C.Ballast = "Ballast", C.Laden = "Laden", C))(pt || {}), vt = /* @__PURE__ */ ((C) => (C.Cp = "CP", C.Perf = "Basis", C.Instruct = "Other", C))(vt || {});
|
|
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
|
|
@@ -735,22 +735,22 @@ class O {
|
|
|
735
735
|
static async speedLoseAt(e, t, n, i = "", o = 2, a = !0, s = !1, d = {}) {
|
|
736
736
|
let r;
|
|
737
737
|
if (t.velocity && s && (e.speed = J.roundPrecision(t.velocity * 1852 / 3600, 6)), a) {
|
|
738
|
-
let
|
|
738
|
+
let h;
|
|
739
739
|
if (d.meteo2)
|
|
740
740
|
try {
|
|
741
|
-
const f = await gt.spotForecast(t.lat, t.lng, n.utc().format(), !1, !1, !0, d), [
|
|
742
|
-
|
|
741
|
+
const f = await gt.spotForecast(t.lat, t.lng, n.utc().format(), !1, !1, !0, d), [x] = ct.pickHourly(f, n);
|
|
742
|
+
h = ct.toLegacy(x);
|
|
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
|
|
747
|
+
h = await mt.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), g = Math.round((e.speed * 1.943844 + M + l) * 100) / 100;
|
|
749
749
|
r = {
|
|
750
|
-
meteo: { ...
|
|
751
|
-
wxFactor:
|
|
750
|
+
meteo: { ...h },
|
|
751
|
+
wxFactor: M,
|
|
752
752
|
cFactor: l,
|
|
753
|
-
speed: t.velocity && s ? t.velocity :
|
|
753
|
+
speed: t.velocity && s ? t.velocity : g < 0 ? 1 : g,
|
|
754
754
|
eta: n.utc().format(),
|
|
755
755
|
etd: n.utc().format()
|
|
756
756
|
};
|
|
@@ -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, r = !1,
|
|
780
|
+
static async speedLoseInHoursStep(e, t, n, i, o, a, s = "", d = !0, r = !1, h = {}) {
|
|
781
781
|
t.utc();
|
|
782
|
-
const
|
|
783
|
-
let f = 0,
|
|
782
|
+
const M = t.clone().add(14, "days"), l = [], g = [];
|
|
783
|
+
let f = 0, x = 0, I, m;
|
|
784
784
|
for (let v = 0; v < a.length - 1; v++) {
|
|
785
785
|
let c = a[v];
|
|
786
|
-
c.distanceFromStart = Math.round((o +
|
|
787
|
-
const
|
|
788
|
-
if (e.bearing = W.calculateBearing(c,
|
|
786
|
+
c.distanceFromStart = Math.round((o + x) * 1e4) / 1e4;
|
|
787
|
+
const w = a[v + 1];
|
|
788
|
+
if (e.bearing = W.calculateBearing(c, w, !w.gcToPrevious), c.bearing = e.bearing, c.suspend && r) {
|
|
789
789
|
c.eta = c.eta || t.utc().format(), c.elapsed = c.elapsed ?? 0;
|
|
790
|
-
const
|
|
791
|
-
if (i - f >
|
|
792
|
-
i = i - f -
|
|
790
|
+
const k = c.suspend - c.elapsed;
|
|
791
|
+
if (i - f > k)
|
|
792
|
+
i = i - f - k, t.add(k, "hour"), c.elapsed = c.suspend;
|
|
793
793
|
else {
|
|
794
794
|
const S = i - f;
|
|
795
795
|
c.elapsed += S, t.add(S, "hour"), i = 0;
|
|
796
796
|
}
|
|
797
|
-
if (F == null || F.info(`[%s] suspend ${c.elapsed} hours at %j, and remain ${i} hours need to go...`,
|
|
798
|
-
return c.distanceFromPrevious =
|
|
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 = x, { etd: t, from: m || c, to: c, next: a.filter((S) => S), wps: l, days: g };
|
|
799
799
|
} else
|
|
800
800
|
c.suspend = 0;
|
|
801
|
-
d = t.isAfter(
|
|
802
|
-
const y = W.calculateDistance(c,
|
|
803
|
-
let
|
|
804
|
-
if (f +
|
|
805
|
-
if (f +=
|
|
806
|
-
`[%s] go to %j from %j with ${y}nm, and cost ${
|
|
807
|
-
|
|
808
|
-
{ lat:
|
|
809
|
-
{ lat:
|
|
810
|
-
),
|
|
811
|
-
|
|
801
|
+
d = t.isAfter(M) ? !1 : d, c = await O.speedLoseAt(e, c, t, s, 0, d, r, h), m = m || c, c.important && l.push(c), t.isSameOrAfter(n) && (g.push(c), n.add(24, "hour"));
|
|
802
|
+
const y = W.calculateDistance(c, w, !w.gcToPrevious);
|
|
803
|
+
let u = Math.round(y / m.speed * 1e5) / 1e5;
|
|
804
|
+
if (f + u < i) {
|
|
805
|
+
if (f += u, t.add(u, "hour"), delete a[v], F == null || F.debug(
|
|
806
|
+
`[%s] go to %j from %j with ${y}nm, and cost ${u} hours`,
|
|
807
|
+
h.requestId,
|
|
808
|
+
{ lat: w.lat, lng: w.lng },
|
|
809
|
+
{ lat: m.lat, lng: m.lng, etd: m.etd }
|
|
810
|
+
), x += y, a.filter((k) => k).length <= 1) {
|
|
811
|
+
I = w, I.eta = t.utc().format(), I.distanceFromPrevious = y, I.distanceFromStart = Math.round((o + x) * 1e4) / 1e4, l.push(I), delete a[v + 1];
|
|
812
812
|
break;
|
|
813
813
|
}
|
|
814
814
|
} else {
|
|
815
|
-
|
|
816
|
-
const
|
|
817
|
-
|
|
818
|
-
`[%s] go to %j from %j with ${
|
|
819
|
-
|
|
820
|
-
{ lat:
|
|
815
|
+
u = i - f, t.add(u, "hour");
|
|
816
|
+
const k = J.roundPrecision(m.speed * u, 5);
|
|
817
|
+
I = W.calculateCoordinate(c, e.bearing, k, "nauticalmiles", !w.gcToPrevious), I.eta = t.utc().format(), a[v] = I, F == null || F.debug(
|
|
818
|
+
`[%s] go to %j from %j with ${k}nm, and cost ${u} hours`,
|
|
819
|
+
h.requestId,
|
|
820
|
+
{ lat: I.lat, lng: I.lng },
|
|
821
821
|
{ lat: c.lat, lng: c.lng, etd: c.etd }
|
|
822
|
-
),
|
|
822
|
+
), x += k, I.distanceFromPrevious = Math.round(x * 1e4) / 1e4, I.distanceFromStart = Math.round((o + x) * 1e4) / 1e4;
|
|
823
823
|
break;
|
|
824
824
|
}
|
|
825
825
|
}
|
|
826
|
-
return { etd: t, from:
|
|
826
|
+
return { etd: t, from: m, to: I, next: a.filter((v) => v), wps: l, days: g };
|
|
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
|
|
847
|
+
var M, l, g, f, x, I, m;
|
|
848
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
|
-
let a = Math.abs(e.bearing % 360 - (((
|
|
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
|
-
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, (
|
|
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, (g = t == null ? void 0 : t.wind) == null ? void 0 : g.scale);
|
|
853
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 - (((
|
|
855
|
-
const
|
|
856
|
-
return F == null || F.debug("wave wx factor = %d",
|
|
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 - (((x = (f = t == null ? void 0 : t.wave) == null ? void 0 : f.sig) == null ? void 0 : x.degree) % 360 || 0));
|
|
855
|
+
const h = O.waveHeightFactor(((m = (I = t == null ? void 0 : t.wave) == null ? void 0 : I.sig) == null ? void 0 : m.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, r = !1,
|
|
870
|
+
static async analyseInstant(e, t, n, i, o, a = "", s = 0, d = !0, r = !1, h = {}) {
|
|
871
871
|
var z, U, Q, X, Z, $;
|
|
872
|
-
const
|
|
872
|
+
const M = b().valueOf();
|
|
873
873
|
e.lng = J.convertToStdLng(e.lng);
|
|
874
|
-
const { route: l, waypoints:
|
|
874
|
+
const { route: l, waypoints: g } = o.points, f = W.calculateSubRoute(e, l);
|
|
875
875
|
if (((z = f[0]) == null ? void 0 : z.length) <= 1)
|
|
876
876
|
return;
|
|
877
|
-
const { v0:
|
|
877
|
+
const { v0: x, label: I } = e.sog ? {
|
|
878
878
|
v0: e.sog,
|
|
879
879
|
label: "Other"
|
|
880
880
|
/* Instruct */
|
|
@@ -882,64 +882,64 @@ class O {
|
|
|
882
882
|
v0: i.speed,
|
|
883
883
|
label: "CP"
|
|
884
884
|
/* Cp */
|
|
885
|
-
},
|
|
885
|
+
}, m = O.assembleProperties(n, i.loadCondition, x, 0), v = g.length ? W.calculateSubWaypoints(e, g) : [];
|
|
886
886
|
v.forEach((q) => q.important = !0);
|
|
887
887
|
const c = {
|
|
888
888
|
from: { ...e },
|
|
889
889
|
route: f,
|
|
890
890
|
waypoints: v,
|
|
891
|
-
v0:
|
|
892
|
-
label:
|
|
893
|
-
},
|
|
891
|
+
v0: x,
|
|
892
|
+
label: I
|
|
893
|
+
}, w = {
|
|
894
894
|
hours: [],
|
|
895
895
|
days: [],
|
|
896
896
|
wps: []
|
|
897
897
|
};
|
|
898
898
|
s || (W.calculateRouteDistance(f) / i.speed <= 72 ? s = 3 : s = 6);
|
|
899
|
-
let y = W.simplifyRouteToCoordinates(f, v, 0),
|
|
900
|
-
t =
|
|
899
|
+
let y = W.simplifyRouteToCoordinates(f, v, 0), u = 0, k = 0, S = 0, D = 0;
|
|
900
|
+
t = b(t).utc();
|
|
901
901
|
const Y = t.clone();
|
|
902
902
|
for (; y.length > 0; ) {
|
|
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,
|
|
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, j = await O.speedLoseInHoursStep(
|
|
904
|
+
m,
|
|
905
905
|
t,
|
|
906
906
|
Y,
|
|
907
907
|
V,
|
|
908
|
-
|
|
908
|
+
u,
|
|
909
909
|
y,
|
|
910
910
|
a,
|
|
911
911
|
d,
|
|
912
912
|
r,
|
|
913
|
-
|
|
913
|
+
h
|
|
914
914
|
);
|
|
915
|
-
(U =
|
|
915
|
+
(U = j.from) != null && U.speed && (w.hours.push(j.from), w.wps.push(...j.wps), w.days.push(...j.days)), y = j == null ? void 0 : j.next, y.length || w.hours.push(j == null ? void 0 : j.to), u += Math.round((((Q = j == null ? void 0 : j.to) == null ? void 0 : Q.distanceFromPrevious) ?? 0) * 1e4) / 1e4;
|
|
916
916
|
}
|
|
917
|
-
const E =
|
|
917
|
+
const E = w.hours;
|
|
918
918
|
for (let q = 0; q < E.length - 1; q++) {
|
|
919
|
-
const V =
|
|
920
|
-
|
|
919
|
+
const V = b(E[q + 1].eta).diff(E[q].etd, "hour", !0) || 1;
|
|
920
|
+
k += (E[q].wxFactor || 0) * V, S += (E[q].cFactor || 0) * V, D += V;
|
|
921
921
|
}
|
|
922
|
-
(X =
|
|
923
|
-
q.positionTime =
|
|
924
|
-
const
|
|
925
|
-
if (
|
|
926
|
-
const L = q.distanceFromStart -
|
|
922
|
+
(X = w.wps) == null || X.forEach((q, V) => {
|
|
923
|
+
q.positionTime = b.utc(q.etd || q.eta).unix();
|
|
924
|
+
const j = w.wps[V - 1];
|
|
925
|
+
if (j) {
|
|
926
|
+
const L = q.distanceFromStart - j.distanceFromStart, H = b(q.eta || q.etd).diff(b(j.etd || j.eta), "h", !0);
|
|
927
927
|
q.avgSpd = Math.round(L / H * 100) / 100;
|
|
928
|
-
const nt = W.calculateBearing(
|
|
929
|
-
|
|
928
|
+
const nt = W.calculateBearing(j, q);
|
|
929
|
+
j.bearing = nt;
|
|
930
930
|
}
|
|
931
|
-
}),
|
|
932
|
-
const P =
|
|
933
|
-
c.distance = Math.round(T.distanceFromStart * 1e4) / 1e4, c.etd =
|
|
934
|
-
const { distanceInECA: N, hoursInECA: A, totalDgoConsInECA: R, eca: K } = await this.calculateECA(c, i,
|
|
931
|
+
}), w.wps = (Z = w.wps) == null ? void 0 : Z.reduce((q, V) => (q.some((j) => Math.round(j.positionTime / 60) === Math.round(V.positionTime / 60)) || q.push(V), q), []), c.sample = w;
|
|
932
|
+
const P = w.hours.at(0), T = w.hours.at(-1);
|
|
933
|
+
c.distance = Math.round(T.distanceFromStart * 1e4) / 1e4, c.etd = b(P.eta).utc().format(), c.eta = b(T.eta).utc().format(), c.wxFactor = Math.round(k / 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;
|
|
934
|
+
const { distanceInECA: N, hoursInECA: A, totalDgoConsInECA: R, eca: K } = await this.calculateECA(c, i, h), st = J.roundPrecision(i.fo / 24 * (D - A), 3), at = J.roundPrecision(i.dgo / 24 * D, 3);
|
|
935
935
|
c.extend = {
|
|
936
936
|
eca: K,
|
|
937
937
|
distanceInECA: N,
|
|
938
938
|
hoursInECA: A,
|
|
939
939
|
totalDgoConsInECA: R
|
|
940
940
|
}, c.totalFoCons = st, c.totalDgoCons = at;
|
|
941
|
-
const tt =
|
|
942
|
-
return F == null || F.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",
|
|
941
|
+
const tt = b().valueOf() - M, ot = (($ = w == null ? void 0 : w.hours) == null ? void 0 : $.length) || 1;
|
|
942
|
+
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;
|
|
943
943
|
}
|
|
944
944
|
/**
|
|
945
945
|
* 分段失速分析(最多走hours 小时)
|
|
@@ -954,11 +954,11 @@ class O {
|
|
|
954
954
|
* @param useMeteo true 启用气象分析
|
|
955
955
|
* @param useRouteParam
|
|
956
956
|
*/
|
|
957
|
-
static async analyseInstantWithThreshed(e, t, n, i, o, a, s, d = "", r = 3,
|
|
957
|
+
static async analyseInstantWithThreshed(e, t, n, i, o, a, s, d = "", r = 3, h = !0, M = !1, l = {}) {
|
|
958
958
|
var Q, X, Z, $, q, V;
|
|
959
|
-
const
|
|
959
|
+
const g = b().valueOf();
|
|
960
960
|
e.lng = J.convertToStdLng(e.lng);
|
|
961
|
-
const { v0: f, label:
|
|
961
|
+
const { v0: f, label: x } = e.sog ? {
|
|
962
962
|
v0: e.sog,
|
|
963
963
|
label: "Other"
|
|
964
964
|
/* Instruct */
|
|
@@ -966,65 +966,65 @@ class O {
|
|
|
966
966
|
v0: o.speed,
|
|
967
967
|
label: "CP"
|
|
968
968
|
/* Cp */
|
|
969
|
-
},
|
|
970
|
-
if (((Q =
|
|
969
|
+
}, I = O.assembleProperties(i, o.loadCondition, f, 0), m = W.calculateSubRoute(e, a);
|
|
970
|
+
if (((Q = m[0]) == null ? void 0 : Q.length) <= 1)
|
|
971
971
|
return;
|
|
972
972
|
const v = s.length ? W.calculateSubWaypoints(e, s) : [];
|
|
973
|
-
v.forEach((
|
|
974
|
-
let c = W.simplifyRouteToCoordinates(
|
|
973
|
+
v.forEach((j) => j.important = !0);
|
|
974
|
+
let c = W.simplifyRouteToCoordinates(m, v, 0), w = 0, y = 0, u = 0, k = 0;
|
|
975
975
|
const S = {
|
|
976
976
|
hours: [],
|
|
977
977
|
wps: [],
|
|
978
978
|
days: []
|
|
979
979
|
};
|
|
980
|
-
t =
|
|
980
|
+
t = b(t).utc();
|
|
981
981
|
const D = t.clone();
|
|
982
982
|
for (; c.length > 0; ) {
|
|
983
|
-
const
|
|
984
|
-
let L = Math.ceil(t.clone().add(
|
|
983
|
+
const j = r - t.hour() % r;
|
|
984
|
+
let L = Math.ceil(t.clone().add(j, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4;
|
|
985
985
|
L = t.clone().add(L, "h").isSameOrAfter(n) ? n.diff(t, "h", !0) * 1e4 / 1e4 : L;
|
|
986
|
-
const H = await O.speedLoseInHoursStep(
|
|
987
|
-
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),
|
|
986
|
+
const H = await O.speedLoseInHoursStep(I, t, D, L, w, c, d, h, M, l);
|
|
987
|
+
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, !L)
|
|
988
988
|
break;
|
|
989
989
|
}
|
|
990
|
-
S.wps = ($ = S.wps) == null ? void 0 : $.reduce((
|
|
990
|
+
S.wps = ($ = S.wps) == null ? void 0 : $.reduce((j, L) => (j.some((H) => Math.round(b(H.etd).unix() / 60) === Math.round(b(L.etd).unix() / 60)) || j.push(L), j), []), (q = S.wps) == null || q.forEach((j, L) => {
|
|
991
991
|
const H = S.wps[L - 1];
|
|
992
992
|
if (H) {
|
|
993
|
-
const nt =
|
|
994
|
-
|
|
995
|
-
const ut = W.calculateBearing(H,
|
|
993
|
+
const nt = j.distanceFromStart - H.distanceFromStart, dt = b(j.eta || j.etd).diff(b(H.etd || H.eta), "h", !0);
|
|
994
|
+
j.avgSpd = Math.round(nt / dt * 100) / 100;
|
|
995
|
+
const ut = W.calculateBearing(H, j);
|
|
996
996
|
H.bearing = ut;
|
|
997
997
|
}
|
|
998
998
|
});
|
|
999
999
|
const Y = S.hours;
|
|
1000
|
-
for (let
|
|
1001
|
-
const L =
|
|
1002
|
-
y += Y[
|
|
1000
|
+
for (let j = 0; j < Y.length - 1; j++) {
|
|
1001
|
+
const L = b(Y[j + 1].eta).diff(Y[j].etd, "hour", !0);
|
|
1002
|
+
y += Y[j].wxFactor * L, u += Y[j].cFactor * L, k += L;
|
|
1003
1003
|
}
|
|
1004
|
-
const E = S.hours.at(0), P = S.hours.at(-1), T = await W.calculateRangeRoute(E, P,
|
|
1004
|
+
const E = S.hours.at(0), P = S.hours.at(-1), T = await W.calculateRangeRoute(E, P, m), N = await W.calculateRangeWaypoints(E, P, m, v), A = {
|
|
1005
1005
|
sample: S,
|
|
1006
1006
|
distance: Math.round(((P == null ? void 0 : P.distanceFromStart) || 0) * 1e4) / 1e4,
|
|
1007
1007
|
// 注意,可能会在first节点Drift,所有采用eta做为初始出发时间
|
|
1008
|
-
etd:
|
|
1009
|
-
eta:
|
|
1010
|
-
wxFactor: Math.round(y /
|
|
1011
|
-
cFactor: Math.round(
|
|
1012
|
-
avgSpeed: Math.round(((P == null ? void 0 : P.distanceFromStart) || 0) /
|
|
1013
|
-
totalHrs: Math.round(
|
|
1008
|
+
etd: b(E.eta).utc().format(),
|
|
1009
|
+
eta: b(P == null ? void 0 : P.eta).utc().format(),
|
|
1010
|
+
wxFactor: Math.round(y / k * 1e4) / 1e4,
|
|
1011
|
+
cFactor: Math.round(u / k * 1e4) / 1e4,
|
|
1012
|
+
avgSpeed: Math.round(((P == null ? void 0 : P.distanceFromStart) || 0) / k * 1e4) / 1e4,
|
|
1013
|
+
totalHrs: Math.round(k * 1e4) / 1e4,
|
|
1014
1014
|
from: E,
|
|
1015
1015
|
to: P,
|
|
1016
1016
|
route: T,
|
|
1017
1017
|
waypoints: N,
|
|
1018
1018
|
v0: f,
|
|
1019
|
-
label:
|
|
1020
|
-
}, { distanceInECA: R, hoursInECA: K, totalDgoConsInECA: st, eca: at } = await this.calculateECA(A, o, l), rt = J.roundPrecision(o.fo / 24 * (
|
|
1019
|
+
label: x
|
|
1020
|
+
}, { distanceInECA: R, hoursInECA: K, totalDgoConsInECA: st, eca: at } = await this.calculateECA(A, o, l), rt = J.roundPrecision(o.fo / 24 * (k - K), 3), tt = J.roundPrecision(o.dgo / 24 * k, 3);
|
|
1021
1021
|
A.extend = {
|
|
1022
1022
|
eca: at,
|
|
1023
1023
|
distanceInECA: R,
|
|
1024
1024
|
hoursInECA: K,
|
|
1025
1025
|
totalDgoConsInECA: st
|
|
1026
1026
|
}, A.totalDgoCons = tt, A.totalFoCons = rt;
|
|
1027
|
-
const z =
|
|
1027
|
+
const z = b().valueOf() - g, U = ((V = S == null ? void 0 : S.hours) == null ? void 0 : V.length) || 1;
|
|
1028
1028
|
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;
|
|
1029
1029
|
}
|
|
1030
1030
|
/**
|
|
@@ -1043,25 +1043,25 @@ class O {
|
|
|
1043
1043
|
* @param options
|
|
1044
1044
|
*/
|
|
1045
1045
|
static async analyseCost(e, t, n, i, o = {}) {
|
|
1046
|
-
var
|
|
1047
|
-
const a =
|
|
1046
|
+
var m, v;
|
|
1047
|
+
const a = b().valueOf(), s = [];
|
|
1048
1048
|
o.meteo2 = o.meteo2 || !0, e.speedStep = e.speedStep || 3, e.alterStep = e.alterStep ?? 1;
|
|
1049
1049
|
const d = W.calculateRouteDistance(i.route);
|
|
1050
1050
|
let r = 0;
|
|
1051
1051
|
n.forEach((c) => {
|
|
1052
|
-
const
|
|
1053
|
-
r = r <
|
|
1052
|
+
const w = Math.ceil(d / c.speed / 24);
|
|
1053
|
+
r = r < w ? w : r;
|
|
1054
1054
|
}), r = r * 1.3;
|
|
1055
|
-
const
|
|
1056
|
-
let
|
|
1055
|
+
const h = b.utc(e.etd).add(r ?? 14, "day");
|
|
1056
|
+
let M = 1;
|
|
1057
1057
|
for (const c of n) {
|
|
1058
|
-
const
|
|
1058
|
+
const w = JSON.parse(JSON.stringify(i.route)), y = JSON.parse(JSON.stringify(i.waypoints)), u = await O.analyseInstantWithThreshed(
|
|
1059
1059
|
{ lat: e.lat, lng: e.lng },
|
|
1060
1060
|
e.etd,
|
|
1061
|
-
|
|
1061
|
+
h,
|
|
1062
1062
|
t,
|
|
1063
1063
|
c,
|
|
1064
|
-
|
|
1064
|
+
w,
|
|
1065
1065
|
y,
|
|
1066
1066
|
e.meteoVendor,
|
|
1067
1067
|
e.speedStep,
|
|
@@ -1069,30 +1069,32 @@ class O {
|
|
|
1069
1069
|
e.useRouteParam,
|
|
1070
1070
|
o
|
|
1071
1071
|
);
|
|
1072
|
-
|
|
1073
|
-
cost:
|
|
1074
|
-
|
|
1075
|
-
|
|
1072
|
+
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(), {
|
|
1073
|
+
cost: u.cost.total,
|
|
1074
|
+
hire: u.cost.hire,
|
|
1075
|
+
bunker: u.cost.bunker,
|
|
1076
|
+
distance: u.distance,
|
|
1077
|
+
hours: u.totalHrs,
|
|
1076
1078
|
cp: `${c.speed}/${c.fo}/${c.dgo}`
|
|
1077
|
-
})),
|
|
1079
|
+
})), M++;
|
|
1078
1080
|
}
|
|
1079
|
-
s.sort((c,
|
|
1080
|
-
const l = s.at(0),
|
|
1081
|
-
if (f.push({ combined: !1, speeds: [l], cost: (
|
|
1082
|
-
const c = l.cost.cp,
|
|
1083
|
-
let S = Math.ceil(
|
|
1081
|
+
s.sort((c, w) => c.cost.total - w.cost.total);
|
|
1082
|
+
const l = s.at(0), g = s.at(1), f = [];
|
|
1083
|
+
if (f.push({ combined: !1, speeds: [l], cost: (m = l.cost) == null ? void 0 : m.total }), g) {
|
|
1084
|
+
const c = l.cost.cp, w = g.cost.cp, y = b(l.eta), u = b(l.etd), k = y.diff(u, "days", !0);
|
|
1085
|
+
let S = Math.ceil(k / 2);
|
|
1084
1086
|
S = S > 7 ? 7 : S < e.alterStep ? e.alterStep : S;
|
|
1085
|
-
let D = 2, Y = { combined: !1, speeds: [
|
|
1087
|
+
let D = 2, Y = { combined: !1, speeds: [g], cost: (v = g.cost) == null ? void 0 : v.total }, E;
|
|
1086
1088
|
for (; S >= e.alterStep; ) {
|
|
1087
|
-
const P = await O.combinedAnalyse(e, t,
|
|
1089
|
+
const P = await O.combinedAnalyse(e, t, h, [c, w], i, S, { ...o, level: D });
|
|
1088
1090
|
if (Y.cost > P.cost ? E ? (E == null ? void 0 : E.cost) > P.cost && (E = P) : (E = Y, Y = P) : (!E || (E == null ? void 0 : E.cost) > P.cost) && (E = P), S <= e.alterStep)
|
|
1089
1091
|
break;
|
|
1090
1092
|
S = Math.ceil(S / 2), D += 1;
|
|
1091
1093
|
}
|
|
1092
1094
|
f.push(Y), E && f.push(E);
|
|
1093
1095
|
}
|
|
1094
|
-
const
|
|
1095
|
-
return F == null || F.info("[%s] analyse elapsed: %d ms", o == null ? void 0 : o.requestId,
|
|
1096
|
+
const I = b().valueOf() - a;
|
|
1097
|
+
return F == null || F.info("[%s] analyse elapsed: %d ms", o == null ? void 0 : o.requestId, I), f.sort((c, w) => c.cost - w.cost);
|
|
1096
1098
|
}
|
|
1097
1099
|
/**
|
|
1098
1100
|
* 按步长多次减半,分别用7,4,2,1天步长及cpa,cpb交替计算各种组合下的成本
|
|
@@ -1106,10 +1108,10 @@ class O {
|
|
|
1106
1108
|
*/
|
|
1107
1109
|
static async combinedAnalyse(e, t, n, i, o, a, s = {}) {
|
|
1108
1110
|
s.counter = 1, F == null || F.info("[%s][L%d] analyse with alternate cp in every %d days", s.requestId, s.level, a);
|
|
1109
|
-
const d = await O.alternateAnalyse(e, t, n, i, 0, o, a, s), r = d.reduce((
|
|
1110
|
-
F == null || F.info("[%s][L%d] cost with cpa/cpb turn: %
|
|
1111
|
-
const
|
|
1112
|
-
return F == null || F.info("[%s][L%d] cost with cpb/cpa turn: %
|
|
1111
|
+
const d = await O.alternateAnalyse(e, t, n, i, 0, o, a, s), r = d.reduce((I, m) => I + m.cost.total, 0), h = d.reduce((I, m) => I + m.cost.hire, 0), M = d.reduce((I, m) => I + m.cost.bunker, 0);
|
|
1112
|
+
F == null || F.info("[%s][L%d] cost with cpa/cpb turn: %j", s.requestId, s.level, { cost: r, hire: h, bunker: M });
|
|
1113
|
+
const l = await O.alternateAnalyse(e, t, n, i, 1, o, a, s), g = l.reduce((I, m) => I + m.cost.total, 0), f = l.reduce((I, m) => I + m.cost.hire, 0), x = l.reduce((I, m) => I + m.cost.bunker, 0);
|
|
1114
|
+
return F == null || F.info("[%s][L%d] cost with cpb/cpa turn: %j", s.requestId, s.level, { cost: g, hire: f, bunker: x }), r < g ? { combined: !0, cost: Math.round(r * 1e3) / 1e3, speeds: d, step: a } : { combined: !0, cost: Math.round(g * 1e3) / 1e3, speeds: l, step: a };
|
|
1113
1115
|
}
|
|
1114
1116
|
/**
|
|
1115
1117
|
* 基于cp索引,交替计算指定步长下的成本
|
|
@@ -1123,40 +1125,47 @@ class O {
|
|
|
1123
1125
|
* @param options
|
|
1124
1126
|
*/
|
|
1125
1127
|
static async alternateAnalyse(e, t, n, i, o, a, s, d = {}) {
|
|
1126
|
-
var l,
|
|
1127
|
-
let r =
|
|
1128
|
-
const
|
|
1128
|
+
var l, g;
|
|
1129
|
+
let r = b.utc(e.etd);
|
|
1130
|
+
const h = { lat: e.lat, lng: e.lng }, M = [];
|
|
1129
1131
|
for (; r.isBefore(n); ) {
|
|
1130
|
-
const f = r.clone().utc().add(s, "day"),
|
|
1131
|
-
|
|
1132
|
+
const f = r.clone().utc().add(s, "day"), x = JSON.parse(JSON.stringify(a.route)), I = JSON.parse(JSON.stringify(a.waypoints)), m = i[o], v = await O.analyseInstantWithThreshed(
|
|
1133
|
+
h,
|
|
1132
1134
|
r.utc().format(),
|
|
1133
1135
|
f,
|
|
1134
1136
|
t,
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1137
|
+
m,
|
|
1138
|
+
x,
|
|
1139
|
+
I,
|
|
1138
1140
|
e.meteoVendor,
|
|
1139
1141
|
e.speedStep,
|
|
1140
1142
|
e.useMeteo,
|
|
1141
1143
|
e.useRouteParam,
|
|
1142
1144
|
d
|
|
1143
1145
|
);
|
|
1144
|
-
v && (await O.calculateCost(v,
|
|
1146
|
+
v && (await O.calculateCost(v, m, e, d), F == null || F.info(
|
|
1145
1147
|
"[%s][L%d-%d] analyse from %s to %s cost: %j",
|
|
1146
1148
|
d.requestId,
|
|
1147
1149
|
d.level,
|
|
1148
1150
|
d.counter,
|
|
1149
1151
|
r.utc().format(),
|
|
1150
1152
|
f.utc().format(),
|
|
1151
|
-
{
|
|
1153
|
+
{
|
|
1154
|
+
cost: v.cost.total,
|
|
1155
|
+
hire: v.cost.hire,
|
|
1156
|
+
bunker: v.cost.bunker,
|
|
1157
|
+
distance: v.distance,
|
|
1158
|
+
hours: v.totalHrs,
|
|
1159
|
+
cp: `${m.speed}/${m.fo}/${m.dgo}`
|
|
1160
|
+
}
|
|
1152
1161
|
)), d.counter = d.counter + 1;
|
|
1153
|
-
const c = (
|
|
1162
|
+
const c = (g = (l = v == null ? void 0 : v.sample) == null ? void 0 : l.hours) == null ? void 0 : g.at(-1);
|
|
1154
1163
|
if (c)
|
|
1155
|
-
|
|
1164
|
+
h.lat = c.lat, h.lng = c.lng, r = b(c.eta), M.push(v), o = o ? 0 : 1;
|
|
1156
1165
|
else
|
|
1157
1166
|
break;
|
|
1158
1167
|
}
|
|
1159
|
-
return
|
|
1168
|
+
return M;
|
|
1160
1169
|
}
|
|
1161
1170
|
/**
|
|
1162
1171
|
* 计算Speed的cost
|
|
@@ -1185,13 +1194,13 @@ class O {
|
|
|
1185
1194
|
var d, r;
|
|
1186
1195
|
const i = await W.intersectInECA(e.route);
|
|
1187
1196
|
let o = 0, a = 0, s = 0;
|
|
1188
|
-
e.sample.wps.forEach((
|
|
1189
|
-
|
|
1197
|
+
e.sample.wps.forEach((h) => {
|
|
1198
|
+
h.positionTime = b.utc(h.etd || h.eta).unix();
|
|
1190
1199
|
});
|
|
1191
|
-
for (const
|
|
1192
|
-
o +=
|
|
1193
|
-
const
|
|
1194
|
-
|
|
1200
|
+
for (const h of i) {
|
|
1201
|
+
o += h.distance;
|
|
1202
|
+
const M = await W.deadReckoningTime((d = h.waypoints) == null ? void 0 : d.at(0), e.sample.wps), l = await W.deadReckoningTime((r = h.waypoints) == null ? void 0 : r.at(-1), e.sample.wps);
|
|
1203
|
+
h.in = M, h.out = l, h.totalHrs = J.roundPrecision((l.positionTime - M.positionTime) / 3600, 2), h.totalDgoCons = J.roundPrecision(t.fo / 24 * h.totalHrs, 3), a += h.totalHrs, s += h.totalDgoCons;
|
|
1195
1204
|
}
|
|
1196
1205
|
return o = J.roundPrecision(o, 3), a = J.roundPrecision(a, 3), s = J.roundPrecision(s, 3), {
|
|
1197
1206
|
distanceInECA: o,
|
|
@@ -1206,55 +1215,55 @@ class O {
|
|
|
1206
1215
|
* @param options
|
|
1207
1216
|
*/
|
|
1208
1217
|
static async mergeSpeeds(e, t = {}) {
|
|
1209
|
-
var c,
|
|
1218
|
+
var c, w;
|
|
1210
1219
|
const n = {
|
|
1211
1220
|
hours: [],
|
|
1212
1221
|
wps: [],
|
|
1213
1222
|
days: []
|
|
1214
|
-
}, i = e.reduce((y,
|
|
1215
|
-
var
|
|
1216
|
-
return y + (((
|
|
1217
|
-
}, 0), a = e.reduce((y,
|
|
1218
|
-
var
|
|
1219
|
-
return y + (((
|
|
1220
|
-
}, 0), d = e.reduce((y,
|
|
1221
|
-
var
|
|
1222
|
-
return y + (((
|
|
1223
|
-
}, 0), r = e.reduce((y,
|
|
1223
|
+
}, i = e.reduce((y, u) => y + u.distance, 0), o = e.reduce((y, u) => {
|
|
1224
|
+
var k;
|
|
1225
|
+
return y + (((k = u.extend) == null ? void 0 : k.distanceInECA) || 0);
|
|
1226
|
+
}, 0), a = e.reduce((y, u) => y + u.totalHrs, 0), s = e.reduce((y, u) => {
|
|
1227
|
+
var k;
|
|
1228
|
+
return y + (((k = u.extend) == null ? void 0 : k.hoursInECA) || 0);
|
|
1229
|
+
}, 0), d = e.reduce((y, u) => {
|
|
1230
|
+
var k;
|
|
1231
|
+
return y + (((k = u.extend) == null ? void 0 : k.totalDgoConsInECA) || 0);
|
|
1232
|
+
}, 0), r = e.reduce((y, u) => y + u.wxFactor * u.totalHrs / a, 0), h = e.reduce((y, u) => y + u.cFactor * u.totalHrs / a, 0), M = e.reduce((y, u) => y + u.totalFoCons, 0), l = e.reduce((y, u) => y + u.totalDgoCons, 0), g = e.reduce((y, u) => y + u.cost.total, 0), f = e.reduce((y, u) => y + u.cost.hire, 0), x = e.reduce((y, u) => y + u.cost.bunker, 0), I = [], m = [];
|
|
1224
1233
|
let v;
|
|
1225
1234
|
for (const y of e) {
|
|
1226
|
-
|
|
1227
|
-
const
|
|
1228
|
-
v && (D.distanceFromPrevious = v.distanceFromPrevious, D.distanceFromStart = v.distanceFromStart,
|
|
1235
|
+
m.push(...((c = y.extend) == null ? void 0 : c.eca) || []);
|
|
1236
|
+
const u = y.sample.hours, k = y.sample.wps, S = y.sample.days, D = u.at(0);
|
|
1237
|
+
v && (D.distanceFromPrevious = v.distanceFromPrevious, D.distanceFromStart = v.distanceFromStart, u.forEach((T, N) => {
|
|
1229
1238
|
N && (T.distanceFromStart = T.distanceFromStart + v.distanceFromStart);
|
|
1230
|
-
}),
|
|
1239
|
+
}), k.at(0).distanceFromPrevious = v.distanceFromPrevious, k.at(0).distanceFromStart = v.distanceFromStart, k.forEach((T, N) => {
|
|
1231
1240
|
N && (T.distanceFromStart = T.distanceFromStart + v.distanceFromStart);
|
|
1232
1241
|
}), S.at(0).distanceFromPrevious = v.distanceFromPrevious, S.at(0).distanceFromStart = v.distanceFromStart, S.forEach((T, N) => {
|
|
1233
1242
|
N && (T.distanceFromStart = T.distanceFromStart + v.distanceFromStart);
|
|
1234
1243
|
})), D.cp = y.cost.cp;
|
|
1235
|
-
const Y = [y.etd, y.eta], E =
|
|
1236
|
-
E === -1 ? (D.cp.segment = [Y],
|
|
1244
|
+
const Y = [y.etd, y.eta], E = I.findIndex((T) => T.id === D.cp.id);
|
|
1245
|
+
E === -1 ? (D.cp.segment = [Y], I.push(D.cp)) : I[E].segment.push(Y), u.forEach((T) => {
|
|
1237
1246
|
var A;
|
|
1238
1247
|
((A = n.hours) == null ? void 0 : A.findIndex((R) => R.eta === T.eta)) === -1 && n.hours.push(T);
|
|
1239
|
-
}),
|
|
1248
|
+
}), k.forEach((T) => {
|
|
1240
1249
|
var A;
|
|
1241
1250
|
((A = n.wps) == null ? void 0 : A.findIndex((R) => R.eta === T.eta)) === -1 && n.wps.push(T);
|
|
1242
1251
|
}), S.forEach((T) => {
|
|
1243
1252
|
var A;
|
|
1244
1253
|
((A = n == null ? void 0 : n.days) == null ? void 0 : A.findIndex((R) => R.eta === T.eta)) === -1 && n.days.push(T);
|
|
1245
1254
|
});
|
|
1246
|
-
const P = (
|
|
1247
|
-
P === -1 ? n.wps.push(D) : n.wps[P] = D, v =
|
|
1255
|
+
const P = (w = n.wps) == null ? void 0 : w.findIndex((T) => T.eta === D.eta);
|
|
1256
|
+
P === -1 ? n.wps.push(D) : n.wps[P] = D, v = u.at(-1);
|
|
1248
1257
|
}
|
|
1249
|
-
return n.wps.sort((y,
|
|
1250
|
-
|
|
1251
|
-
}), n.wps.forEach((y,
|
|
1252
|
-
const
|
|
1253
|
-
if (
|
|
1254
|
-
const S = y.distanceFromStart - (
|
|
1258
|
+
return n.wps.sort((y, u) => {
|
|
1259
|
+
b(y.etd).unix() - b(u.etd).unix();
|
|
1260
|
+
}), n.wps.forEach((y, u) => {
|
|
1261
|
+
const k = n.wps[u - 1];
|
|
1262
|
+
if (k) {
|
|
1263
|
+
const S = y.distanceFromStart - (k.distanceFromStart || 0), D = b(y.eta || y.etd).diff(b(k.etd || k.eta), "hour", !0), Y = Math.round(S / D * 100) / 100;
|
|
1255
1264
|
y.avgSpd = Y;
|
|
1256
|
-
const E = W.calculateBearing(
|
|
1257
|
-
|
|
1265
|
+
const E = W.calculateBearing(k, y);
|
|
1266
|
+
k.bearing = E;
|
|
1258
1267
|
}
|
|
1259
1268
|
}), {
|
|
1260
1269
|
sample: n,
|
|
@@ -1268,17 +1277,17 @@ class O {
|
|
|
1268
1277
|
totalHrs: Math.round(a * 1e3) / 1e3,
|
|
1269
1278
|
avgSpeed: Math.round(i / a * 1e3) / 1e3,
|
|
1270
1279
|
wxFactor: Math.round(r / a * 1e3) / 1e3,
|
|
1271
|
-
cFactor: Math.round(
|
|
1272
|
-
totalFoCons: Math.round(
|
|
1280
|
+
cFactor: Math.round(h / a * 1e3) / 1e3,
|
|
1281
|
+
totalFoCons: Math.round(M * 1e3) / 1e3,
|
|
1273
1282
|
totalDgoCons: Math.round(l * 1e3) / 1e3,
|
|
1274
1283
|
cost: {
|
|
1275
|
-
total: Math.round(
|
|
1284
|
+
total: Math.round(g * 1e3) / 1e3,
|
|
1276
1285
|
hire: Math.round(f * 1e3) / 1e3,
|
|
1277
|
-
bunker: Math.round(
|
|
1286
|
+
bunker: Math.round(x * 1e3) / 1e3
|
|
1278
1287
|
},
|
|
1279
1288
|
extend: {
|
|
1280
|
-
cps:
|
|
1281
|
-
eca:
|
|
1289
|
+
cps: I,
|
|
1290
|
+
eca: m,
|
|
1282
1291
|
distanceInECA: Math.round(o * 1e4) / 1e4,
|
|
1283
1292
|
hoursInECA: Math.round(s * 1e3) / 1e3,
|
|
1284
1293
|
totalDgoConsInECA: Math.round(d * 1e3) / 1e3,
|
|
@@ -1294,7 +1303,7 @@ export {
|
|
|
1294
1303
|
Et as HifleetImpl,
|
|
1295
1304
|
pt as LoadCondition,
|
|
1296
1305
|
Tt as MyShipImpl,
|
|
1297
|
-
|
|
1306
|
+
Ct as MyVesselImpl,
|
|
1298
1307
|
Nt as ShipxyImpl,
|
|
1299
1308
|
O as SpeedHelper,
|
|
1300
1309
|
vt as SpeedLabel,
|