@idm-plugin/vessel 2.0.3 → 2.0.9
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 +444 -444
- package/dist/index.umd.cjs +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
var ht = Object.defineProperty;
|
|
2
|
-
var lt = (E,
|
|
3
|
-
var K = (E,
|
|
2
|
+
var lt = (E, t, e) => t in E ? ht(E, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : E[t] = e;
|
|
3
|
+
var K = (E, t, e) => (lt(E, typeof t != "symbol" ? t + "" : t, e), e);
|
|
4
4
|
import B from "got";
|
|
5
5
|
import rt 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 } from "@idm-plugin/meteo2";
|
|
9
9
|
import { Meteo2Assist as it } from "@idm-plugin/meteo";
|
|
10
|
-
let
|
|
10
|
+
let w;
|
|
11
11
|
try {
|
|
12
|
-
|
|
12
|
+
w = rt.getLogger("vessel");
|
|
13
13
|
} catch {
|
|
14
14
|
} finally {
|
|
15
15
|
}
|
|
@@ -18,51 +18,51 @@ class et {
|
|
|
18
18
|
* 解析AIS状态码
|
|
19
19
|
* @param status
|
|
20
20
|
*/
|
|
21
|
-
parseStatus(
|
|
22
|
-
let
|
|
23
|
-
switch (
|
|
21
|
+
parseStatus(t) {
|
|
22
|
+
let e, n;
|
|
23
|
+
switch (t) {
|
|
24
24
|
case 0:
|
|
25
|
-
|
|
25
|
+
e = "在航(主机推动)", n = "Underway Using Engine";
|
|
26
26
|
break;
|
|
27
27
|
case 1:
|
|
28
|
-
|
|
28
|
+
e = "锚泊", n = "Anchored";
|
|
29
29
|
break;
|
|
30
30
|
case 2:
|
|
31
|
-
|
|
31
|
+
e = "失控", n = "Not operated";
|
|
32
32
|
break;
|
|
33
33
|
case 3:
|
|
34
|
-
|
|
34
|
+
e = "操纵受限", n = "Limited airworthiness";
|
|
35
35
|
break;
|
|
36
36
|
case 4:
|
|
37
|
-
|
|
37
|
+
e = "吃水受限", n = "Limited by ship's draft";
|
|
38
38
|
break;
|
|
39
39
|
case 5:
|
|
40
|
-
|
|
40
|
+
e = "靠泊", n = "Mooring";
|
|
41
41
|
break;
|
|
42
42
|
case 6:
|
|
43
|
-
|
|
43
|
+
e = "搁浅", n = "Stranded";
|
|
44
44
|
break;
|
|
45
45
|
case 7:
|
|
46
|
-
|
|
46
|
+
e = "捕捞作业", n = "Engaged in fishing";
|
|
47
47
|
break;
|
|
48
48
|
case 8:
|
|
49
|
-
|
|
49
|
+
e = "靠帆船提供动力", n = "Sailing";
|
|
50
50
|
break;
|
|
51
51
|
default:
|
|
52
|
-
|
|
52
|
+
e = "未定义", n = "Undefined";
|
|
53
53
|
}
|
|
54
|
-
return { labelCn:
|
|
54
|
+
return { labelCn: e, labelEn: n };
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
class xt extends et {
|
|
58
|
-
constructor(
|
|
58
|
+
constructor(e, n) {
|
|
59
59
|
super();
|
|
60
60
|
K(this, "clientId");
|
|
61
61
|
K(this, "clientSecret");
|
|
62
62
|
K(this, "token");
|
|
63
|
-
this.clientId =
|
|
63
|
+
this.clientId = e, this.clientSecret = n;
|
|
64
64
|
}
|
|
65
|
-
async authToken(
|
|
65
|
+
async authToken(e = {}) {
|
|
66
66
|
const n = "https://svc.data.myvessel.cn/ada/oauth/token", i = {
|
|
67
67
|
searchParams: {
|
|
68
68
|
client_id: this.clientId,
|
|
@@ -70,33 +70,33 @@ class xt extends et {
|
|
|
70
70
|
grant_type: "client_credentials"
|
|
71
71
|
}
|
|
72
72
|
}, o = await B.post(n, i).json();
|
|
73
|
-
|
|
73
|
+
w == null || w.info("[%s] fetch access token from: %s - %j", e.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
|
-
async realTimePosition(
|
|
83
|
-
var d, r,
|
|
84
|
-
(!this.token ||
|
|
82
|
+
async realTimePosition(e, n = {}) {
|
|
83
|
+
var d, r, m;
|
|
84
|
+
(!this.token || b().diff(b(this.token.issuedAt), "seconds") > ((d = this.token) == null ? void 0 : d.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: `${(r = this.token) == null ? void 0 : r.tokenType} ${(
|
|
87
|
+
Authorization: `${(r = this.token) == null ? void 0 : r.tokenType} ${(m = this.token) == null ? void 0 : m.accessToken}`
|
|
88
88
|
},
|
|
89
|
-
searchParams: { mmsi:
|
|
89
|
+
searchParams: { mmsi: e }
|
|
90
90
|
};
|
|
91
|
-
|
|
91
|
+
w == null || w.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 w == null || w.warn("[%s] fetch realtime position failed: %j", n.requestId, i, { message: a.message, status: a.status, code: a.code }), a;
|
|
95
95
|
const s = a.data;
|
|
96
96
|
for (const M in s)
|
|
97
97
|
!isNaN(s[M]) && Number(s[M]) !== 1 / 0 && (s[M] = Number(s[M]));
|
|
98
98
|
if (s) {
|
|
99
|
-
const M =
|
|
99
|
+
const M = b(`${s.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
100
100
|
return {
|
|
101
101
|
mmsi: s.mmsi,
|
|
102
102
|
name: s.vesselName || s.aisVesselName,
|
|
@@ -111,7 +111,7 @@ class xt extends et {
|
|
|
111
111
|
cog: s.cog,
|
|
112
112
|
hdg: s.hdg,
|
|
113
113
|
rot: s.rot,
|
|
114
|
-
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ?
|
|
114
|
+
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ? b.utc(s.eta).format() : void 0,
|
|
115
115
|
destination: s.dest,
|
|
116
116
|
positionTime: M.unix(),
|
|
117
117
|
status: s.status,
|
|
@@ -131,35 +131,35 @@ class xt extends et {
|
|
|
131
131
|
} else
|
|
132
132
|
return {};
|
|
133
133
|
}
|
|
134
|
-
async trajectory(
|
|
135
|
-
(!this.token ||
|
|
136
|
-
const d = await this.realTimePosition(
|
|
137
|
-
for (;
|
|
138
|
-
await this.trajectoryIn30Day(
|
|
139
|
-
return await this.trajectoryIn30Day(
|
|
134
|
+
async trajectory(e, n, i, o, a = !0, s = {}) {
|
|
135
|
+
(!this.token || b().diff(b(this.token.issuedAt), "seconds") > this.token.expiresIn - 300) && await this.authToken(s);
|
|
136
|
+
const d = await this.realTimePosition(e, s), r = b(n), m = b(i), M = [];
|
|
137
|
+
for (; m.diff(r, "day", !0) > 30; )
|
|
138
|
+
await this.trajectoryIn30Day(e, r, r.clone().add(30, "day"), d, o, M, s), r.add(30, "day");
|
|
139
|
+
return await this.trajectoryIn30Day(e, r, m, d, o, M, s), M;
|
|
140
140
|
}
|
|
141
|
-
async trajectoryIn30Day(
|
|
142
|
-
var
|
|
143
|
-
const r = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",
|
|
141
|
+
async trajectoryIn30Day(e, n, i, o, a, s, d = {}) {
|
|
142
|
+
var f, C, S, v, p;
|
|
143
|
+
const r = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", m = {
|
|
144
144
|
headers: {
|
|
145
|
-
Authorization: `${(
|
|
145
|
+
Authorization: `${(f = this.token) == null ? void 0 : f.tokenType} ${(C = this.token) == null ? void 0 : C.accessToken}`
|
|
146
146
|
},
|
|
147
147
|
json: {
|
|
148
|
-
mmsi:
|
|
148
|
+
mmsi: e,
|
|
149
149
|
startTime: n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),
|
|
150
150
|
endTime: i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")
|
|
151
151
|
}
|
|
152
152
|
};
|
|
153
|
-
|
|
154
|
-
const M = await B.post(r,
|
|
153
|
+
w == null || w.info("[%s] fetch trajectory from: %s - %j", d.requestId, r, m);
|
|
154
|
+
const M = await B.post(r, m).json();
|
|
155
155
|
if (M.code)
|
|
156
|
-
return
|
|
157
|
-
let
|
|
158
|
-
const
|
|
159
|
-
return (
|
|
156
|
+
return w == null || w.warn("[%s] fetch trajectory failed: %j", d.requestId, r, { message: M.message, status: M.status, code: M.code }), M;
|
|
157
|
+
let l = -1;
|
|
158
|
+
const g = b(`${(v = (S = M.data) == null ? void 0 : S[0]) == null ? void 0 : v.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
159
|
+
return (p = M.data) == null || p.forEach((c) => {
|
|
160
160
|
for (const Y in c)
|
|
161
161
|
!isNaN(c[Y]) && Number(c[Y]) !== 1 / 0 && (c[Y] = Number(c[Y]));
|
|
162
|
-
const
|
|
162
|
+
const y = b(`${c.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), h = c.status, { labelCn: u, labelEn: I } = this.parseStatus(h), k = {
|
|
163
163
|
mmsi: c.mmsi,
|
|
164
164
|
imo: o == null ? void 0 : o.imo,
|
|
165
165
|
lat: c.lat,
|
|
@@ -168,41 +168,41 @@ class xt extends et {
|
|
|
168
168
|
cog: c.cog,
|
|
169
169
|
hdg: c.hdg,
|
|
170
170
|
draught: c.draught,
|
|
171
|
-
status:
|
|
172
|
-
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(c.eta) ?
|
|
171
|
+
status: h,
|
|
172
|
+
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,
|
|
173
173
|
destination: c.dest,
|
|
174
|
-
positionTime:
|
|
174
|
+
positionTime: y.unix(),
|
|
175
175
|
labelCn: u,
|
|
176
176
|
labelEn: I,
|
|
177
177
|
method: "trajectory",
|
|
178
178
|
vendor: "myVessel",
|
|
179
|
-
utc:
|
|
180
|
-
}, D = Math.floor(
|
|
181
|
-
D !==
|
|
179
|
+
utc: y.utc().format()
|
|
180
|
+
}, D = Math.floor(y.diff(g, "minute", !0) / (a || 1));
|
|
181
|
+
D !== l && (l = D, s.push(k));
|
|
182
182
|
}), s;
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
class Et extends et {
|
|
186
|
-
constructor(
|
|
186
|
+
constructor(e) {
|
|
187
187
|
super();
|
|
188
188
|
K(this, "token");
|
|
189
|
-
this.token =
|
|
189
|
+
this.token = e;
|
|
190
190
|
}
|
|
191
|
-
async realTimePosition(
|
|
191
|
+
async realTimePosition(e, n = {}) {
|
|
192
192
|
const i = "https://api.hifleet.com/position/position/get/token", o = {
|
|
193
193
|
searchParams: {
|
|
194
|
-
mmsi:
|
|
194
|
+
mmsi: e,
|
|
195
195
|
usertoken: this.token
|
|
196
196
|
}
|
|
197
197
|
}, a = await B.post(i, o).json();
|
|
198
|
-
|
|
198
|
+
w == null || w.info("[%s] fetch realtime position from: %s - %j", n.requestId, i, o);
|
|
199
199
|
const s = a == null ? void 0 : a.list;
|
|
200
200
|
if (!s)
|
|
201
|
-
return
|
|
202
|
-
for (const
|
|
203
|
-
!isNaN(s[
|
|
201
|
+
return w == null || w.warn("[%s] fetch realtime position failed: %j", n.requestId, i, a), a;
|
|
202
|
+
for (const g in s)
|
|
203
|
+
!isNaN(s[g]) && Number(s[g]) !== 1 / 0 && (s[g] = Number(s[g]));
|
|
204
204
|
s.status = s.sp > 3 ? 0 : 1;
|
|
205
|
-
const d = s.status, { labelCn: r, labelEn:
|
|
205
|
+
const d = s.status, { labelCn: r, labelEn: m } = this.parseStatus(d), M = b(`${s.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
206
206
|
return {
|
|
207
207
|
mmsi: s.m,
|
|
208
208
|
name: s.n,
|
|
@@ -217,7 +217,7 @@ class Et extends et {
|
|
|
217
217
|
cog: s.co,
|
|
218
218
|
hdg: s.h,
|
|
219
219
|
rot: isNaN(s.rot) ? 0 : s.rot,
|
|
220
|
-
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ?
|
|
220
|
+
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ? b.utc(s.eta).format() : void 0,
|
|
221
221
|
destination: s.destination,
|
|
222
222
|
vesselType: s.type,
|
|
223
223
|
dwt: s.dwt,
|
|
@@ -227,16 +227,16 @@ class Et extends et {
|
|
|
227
227
|
utc: M.utc().format(),
|
|
228
228
|
status: d,
|
|
229
229
|
labelCn: r,
|
|
230
|
-
labelEn:
|
|
230
|
+
labelEn: m,
|
|
231
231
|
method: "position",
|
|
232
232
|
vendor: "hifleet"
|
|
233
233
|
};
|
|
234
234
|
}
|
|
235
|
-
async search(
|
|
235
|
+
async search(e, n = {}) {
|
|
236
236
|
let i = "https://www.hifleet.com/hifleetapi/searchVesselOL.do";
|
|
237
237
|
const o = {
|
|
238
238
|
searchParams: {
|
|
239
|
-
keyword:
|
|
239
|
+
keyword: e
|
|
240
240
|
},
|
|
241
241
|
headers: {
|
|
242
242
|
Referer: "https://www.hifleet.com",
|
|
@@ -245,7 +245,7 @@ class Et extends et {
|
|
|
245
245
|
}
|
|
246
246
|
};
|
|
247
247
|
let a = await B.post(i, o).json();
|
|
248
|
-
|
|
248
|
+
w == null || w.info("[%s] fetch vessel props from: %s - %j", n.requestId, i, o), a instanceof Array && (a = a[0]);
|
|
249
249
|
for (const d in a)
|
|
250
250
|
!isNaN(a[d]) && Number(a[d]) !== 1 / 0 && (a[d] = Number(a[d]));
|
|
251
251
|
const s = {
|
|
@@ -258,12 +258,12 @@ class Et extends et {
|
|
|
258
258
|
draught: a.dr,
|
|
259
259
|
type: a.t
|
|
260
260
|
};
|
|
261
|
-
return i = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", a = await B.post(i, o).json(),
|
|
261
|
+
return i = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", a = await B.post(i, o).json(), w == null || w.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;
|
|
262
262
|
}
|
|
263
|
-
async suggest(
|
|
263
|
+
async suggest(e, n = {}) {
|
|
264
264
|
const i = "https://www.hifleet.com/hifleetapi/getShipSuggest.do", o = {
|
|
265
265
|
searchParams: {
|
|
266
|
-
q:
|
|
266
|
+
q: e
|
|
267
267
|
},
|
|
268
268
|
headers: {
|
|
269
269
|
Referer: "https://www.hifleet.com",
|
|
@@ -271,7 +271,7 @@ class Et extends et {
|
|
|
271
271
|
Host: "www.hifleet.com"
|
|
272
272
|
}
|
|
273
273
|
}, a = await B.post(i, o).json();
|
|
274
|
-
|
|
274
|
+
w == null || w.info("[%s] suggest vessel props from: %s - %j", n.requestId, i, o);
|
|
275
275
|
const s = [];
|
|
276
276
|
for (const d of a)
|
|
277
277
|
s.push({
|
|
@@ -283,33 +283,33 @@ class Et extends et {
|
|
|
283
283
|
});
|
|
284
284
|
return s.sort((d, r) => r.score - d.score), s;
|
|
285
285
|
}
|
|
286
|
-
async trajectory(
|
|
287
|
-
var c,
|
|
288
|
-
const d = await this.realTimePosition(
|
|
289
|
-
let r =
|
|
290
|
-
const
|
|
286
|
+
async trajectory(e, n, i, o, a = !0, s = {}) {
|
|
287
|
+
var c, y, h;
|
|
288
|
+
const d = await this.realTimePosition(e, s);
|
|
289
|
+
let r = b(n);
|
|
290
|
+
const m = b(i), M = b();
|
|
291
291
|
if (a) {
|
|
292
|
-
let u =
|
|
293
|
-
u < 0 ? r =
|
|
292
|
+
let u = m.diff(r, "d", !0);
|
|
293
|
+
u < 0 ? r = m.clone().subtract(40, "d") : u < 30 ? r.subtract(10, "d") : u < 60 ? r.subtract(5, "d") : r = m.clone().subtract(80, "d"), u = M.diff(m, "d", !0), m.add(u > 10 ? 240 : u * 24, "h");
|
|
294
294
|
}
|
|
295
|
-
const
|
|
295
|
+
const l = {
|
|
296
296
|
searchParams: {
|
|
297
|
-
endtime:
|
|
297
|
+
endtime: m.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
|
|
298
298
|
starttime: r.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
|
|
299
|
-
mmsi:
|
|
299
|
+
mmsi: e,
|
|
300
300
|
usertoken: this.token
|
|
301
301
|
}
|
|
302
|
-
},
|
|
303
|
-
|
|
302
|
+
}, g = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", f = await B.get(g, l).json();
|
|
303
|
+
w == null || w.info("[%s] fetch trajectory from: %s - %j", s.requestId, g, l);
|
|
304
304
|
let C;
|
|
305
|
-
|
|
305
|
+
f && (C = ((y = (c = f.ships) == null ? void 0 : c.offors) == null ? void 0 : y.ship) || [], C.length || w == null || w.warn("[%s] fetch trajectory failed: %j", s.requestId, f));
|
|
306
306
|
const S = [];
|
|
307
|
-
let
|
|
308
|
-
const
|
|
307
|
+
let v = -1;
|
|
308
|
+
const p = b(`${(h = C == null ? void 0 : C[0]) == null ? void 0 : h.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
309
309
|
for (const u of C) {
|
|
310
310
|
for (const P in u)
|
|
311
311
|
!isNaN(u[P]) && Number(u[P]) !== 1 / 0 && (u[P] = Number(u[P]));
|
|
312
|
-
const I =
|
|
312
|
+
const I = b(`${u.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
313
313
|
u.status = u.sp > 4 ? 0 : 1;
|
|
314
314
|
const { labelEn: k, labelCn: D } = this.parseStatus(u.status), Y = {
|
|
315
315
|
mmsi: u.m,
|
|
@@ -328,32 +328,32 @@ class Et extends et {
|
|
|
328
328
|
labelEn: k,
|
|
329
329
|
method: "trajectory",
|
|
330
330
|
vendor: "hifleet"
|
|
331
|
-
}, j = Math.floor(I.diff(
|
|
332
|
-
j !==
|
|
331
|
+
}, j = Math.floor(I.diff(p, "minute", !0) / (o || 1));
|
|
332
|
+
j !== v && (v = j, S.push(Y));
|
|
333
333
|
}
|
|
334
334
|
return S;
|
|
335
335
|
}
|
|
336
336
|
}
|
|
337
337
|
class jt extends et {
|
|
338
|
-
constructor(
|
|
338
|
+
constructor(e) {
|
|
339
339
|
super();
|
|
340
340
|
K(this, "token");
|
|
341
|
-
this.token =
|
|
341
|
+
this.token = e;
|
|
342
342
|
}
|
|
343
|
-
async realTimePosition(
|
|
343
|
+
async realTimePosition(e, n = {}) {
|
|
344
344
|
const i = {
|
|
345
345
|
searchParams: {
|
|
346
|
-
id:
|
|
346
|
+
id: e,
|
|
347
347
|
k: this.token,
|
|
348
348
|
enc: 1
|
|
349
349
|
}
|
|
350
350
|
}, o = "https://api.shipxy.com/apicall/GetSingleShip", a = await B.get(o, i).json();
|
|
351
|
-
if (
|
|
351
|
+
if (w == null || w.info("[%s] fetch realtime position from: %s - %j", n.requestId, o, i), (a == null ? void 0 : a.status) !== 0)
|
|
352
352
|
return a;
|
|
353
353
|
const s = a.data[0];
|
|
354
|
-
for (const
|
|
355
|
-
!isNaN(s[
|
|
356
|
-
const { labelCn: d, labelEn: r } = await this.parseStatus(s.navistat),
|
|
354
|
+
for (const l in s)
|
|
355
|
+
!isNaN(s[l]) && Number(s[l]) !== 1 / 0 && (s[l] = Number(s[l]));
|
|
356
|
+
const { labelCn: d, labelEn: r } = await this.parseStatus(s.navistat), m = b.unix(s.lasttime);
|
|
357
357
|
return {
|
|
358
358
|
mmsi: s.ShipID,
|
|
359
359
|
name: s.name,
|
|
@@ -369,7 +369,7 @@ class jt extends et {
|
|
|
369
369
|
hdg: Math.round(s.hdg / 100 * 100) / 100,
|
|
370
370
|
rot: Math.round(s.rot / 100 * 100) / 100,
|
|
371
371
|
positionTime: s.lasttime,
|
|
372
|
-
utc:
|
|
372
|
+
utc: m.utc().format(),
|
|
373
373
|
status: s.navistat,
|
|
374
374
|
labelEn: r,
|
|
375
375
|
labelCn: d,
|
|
@@ -377,71 +377,71 @@ class jt extends et {
|
|
|
377
377
|
vendor: "shipxy"
|
|
378
378
|
};
|
|
379
379
|
}
|
|
380
|
-
async trajectory(
|
|
381
|
-
var
|
|
382
|
-
const d = await this.realTimePosition(
|
|
380
|
+
async trajectory(e, n, i, o, a = !0, s = {}) {
|
|
381
|
+
var p;
|
|
382
|
+
const d = await this.realTimePosition(e, s), r = b(n), m = b(i), M = "https://api.shipxy.com/apicall/GetShipTrack", l = {
|
|
383
383
|
searchParams: {
|
|
384
|
-
id:
|
|
384
|
+
id: e,
|
|
385
385
|
k: this.token,
|
|
386
386
|
enc: 1,
|
|
387
387
|
cut: 0,
|
|
388
388
|
btm: r.unix(),
|
|
389
|
-
etm:
|
|
389
|
+
etm: m.unix()
|
|
390
390
|
}
|
|
391
|
-
},
|
|
392
|
-
if (
|
|
393
|
-
return
|
|
394
|
-
const
|
|
395
|
-
let
|
|
396
|
-
for (const c of
|
|
397
|
-
const
|
|
391
|
+
}, g = await B.get(M, l).json();
|
|
392
|
+
if (w == null || w.info("[%s] fetch trajectory from: %s - %j", s.requestId, M, l), (g == null ? void 0 : g.status) !== 0)
|
|
393
|
+
return g;
|
|
394
|
+
const f = g == null ? void 0 : g.points, C = [], S = b.unix((p = f[0]) == null ? void 0 : p.utc);
|
|
395
|
+
let v = -1;
|
|
396
|
+
for (const c of f) {
|
|
397
|
+
const y = b.unix(c.utc), h = {
|
|
398
398
|
imo: d == null ? void 0 : d.imo,
|
|
399
|
-
mmsi:
|
|
399
|
+
mmsi: e,
|
|
400
400
|
sog: Math.round(c.sog * 3600 / 1e3 / 1852 * 100) / 100,
|
|
401
401
|
cog: Math.round(c.cog / 100 * 100) / 100,
|
|
402
402
|
lat: Math.round(c.lat / 1e6 * 1e5) / 1e5,
|
|
403
403
|
lng: Math.round(c.lon / 1e6 * 1e5) / 1e5,
|
|
404
|
-
positionTime:
|
|
405
|
-
utc:
|
|
404
|
+
positionTime: y.unix(),
|
|
405
|
+
utc: y.utc().format(),
|
|
406
406
|
method: "trajectory",
|
|
407
407
|
vendor: "shipxy"
|
|
408
|
-
}, u = Math.floor(
|
|
409
|
-
u !==
|
|
408
|
+
}, u = Math.floor(y.diff(S, "minute", !0) / (o || 1));
|
|
409
|
+
u !== v && (v = u, C.push(h));
|
|
410
410
|
}
|
|
411
411
|
return C;
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
414
|
class Nt extends et {
|
|
415
|
-
constructor(
|
|
415
|
+
constructor(e) {
|
|
416
416
|
super();
|
|
417
417
|
K(this, "token");
|
|
418
|
-
this.token =
|
|
418
|
+
this.token = e;
|
|
419
419
|
}
|
|
420
|
-
async getShipId(
|
|
420
|
+
async getShipId(e, n = {}) {
|
|
421
421
|
const i = {
|
|
422
422
|
headers: {
|
|
423
423
|
appKey: this.token
|
|
424
424
|
},
|
|
425
425
|
json: {
|
|
426
|
-
mmsiList:
|
|
426
|
+
mmsiList: e
|
|
427
427
|
}
|
|
428
428
|
}, o = "https://api3.myships.com/sp/ships/getShipIdByMMSI", a = await B.post(o, i).json();
|
|
429
|
-
return
|
|
429
|
+
return w == null || w.info("[%s] fetch ship id from: %s - %j", n.requestId, o, i), a.code !== "0" ? a : a.data[0].shipId;
|
|
430
430
|
}
|
|
431
|
-
async getShipInfo(
|
|
431
|
+
async getShipInfo(e, n = {}) {
|
|
432
432
|
const i = {
|
|
433
433
|
headers: {
|
|
434
434
|
appKey: this.token
|
|
435
435
|
},
|
|
436
436
|
json: {
|
|
437
|
-
shipId:
|
|
437
|
+
shipId: e
|
|
438
438
|
}
|
|
439
439
|
}, o = "https://api3.myships.com/sp/ships/aissta", a = await B.post(o, i).json();
|
|
440
|
-
if (
|
|
440
|
+
if (w == null || w.info("[%s] fetch ship info from: %s - %j", n.requestId, o, i), a.code !== "0")
|
|
441
441
|
return a;
|
|
442
442
|
const s = a.data;
|
|
443
443
|
let d = s.imo;
|
|
444
|
-
return
|
|
444
|
+
return e === "407170" && (d = "9198379", w == null || w.warn("[%s] ship(%s) imo error: %s, should be %s", n.requestId, e, s.imo, d)), {
|
|
445
445
|
mmsi: s.mmsi,
|
|
446
446
|
name: s.shipnameEn,
|
|
447
447
|
imo: d,
|
|
@@ -451,8 +451,8 @@ class Nt extends et {
|
|
|
451
451
|
draught: (s.draught || 100) / 10
|
|
452
452
|
};
|
|
453
453
|
}
|
|
454
|
-
async realTimePosition(
|
|
455
|
-
const i = await this.getShipId(
|
|
454
|
+
async realTimePosition(e, n = {}) {
|
|
455
|
+
const i = await this.getShipId(e, n), o = await this.getShipInfo(i, n), a = {
|
|
456
456
|
headers: {
|
|
457
457
|
appKey: this.token
|
|
458
458
|
},
|
|
@@ -460,14 +460,14 @@ class Nt extends et {
|
|
|
460
460
|
shipId: i
|
|
461
461
|
}
|
|
462
462
|
}, s = "https://api3.myships.com/sp/ships/position/latest", d = await B.post(s, a).json();
|
|
463
|
-
|
|
463
|
+
w == null || w.info("[%s] fetch realtime position from: %s - %j", n.requestId, s, a);
|
|
464
464
|
const r = d.data[0];
|
|
465
|
-
for (const
|
|
466
|
-
!isNaN(r[
|
|
467
|
-
const { labelCn:
|
|
465
|
+
for (const f in r)
|
|
466
|
+
!isNaN(r[f]) && Number(r[f]) !== 1 / 0 && (r[f] = Number(r[f]));
|
|
467
|
+
const { labelCn: m, labelEn: M } = await this.parseStatus(r.aisNavStatus), l = b.unix(r.posTime);
|
|
468
468
|
return {
|
|
469
469
|
...o,
|
|
470
|
-
mmsi:
|
|
470
|
+
mmsi: e,
|
|
471
471
|
lat: Math.round(r.lat / 1e4 / 60 * 1e5) / 1e5,
|
|
472
472
|
lng: Math.round(r.lon / 1e4 / 60 * 1e5) / 1e5,
|
|
473
473
|
sog: Math.round(r.sog / 10 * 100) / 100,
|
|
@@ -475,55 +475,55 @@ class Nt extends et {
|
|
|
475
475
|
hdg: Math.round(r.heading * 100) / 100,
|
|
476
476
|
rot: Math.round(r.rot * 100) / 100,
|
|
477
477
|
positionTime: r.posTime,
|
|
478
|
-
utc:
|
|
478
|
+
utc: l.utc().format(),
|
|
479
479
|
status: r.aisNavStatus,
|
|
480
480
|
labelEn: M,
|
|
481
|
-
labelCn:
|
|
481
|
+
labelCn: m,
|
|
482
482
|
method: "position",
|
|
483
483
|
vendor: "myship"
|
|
484
484
|
};
|
|
485
485
|
}
|
|
486
|
-
async trajectory(
|
|
487
|
-
const d =
|
|
486
|
+
async trajectory(e, n, i, o, a = !0, s = {}) {
|
|
487
|
+
const d = b(n), r = b(i), m = await this.getShipId(e), M = await this.getShipInfo(m), l = [];
|
|
488
488
|
for (; r.diff(d, "day", !0) > 30; )
|
|
489
|
-
await this.trajectoryIn30Day(
|
|
490
|
-
return await this.trajectoryIn30Day(
|
|
489
|
+
await this.trajectoryIn30Day(m, d.unix(), d.add(30, "day").unix(), M, e, o, l);
|
|
490
|
+
return await this.trajectoryIn30Day(m, d.unix(), r.unix(), M, e, o, l), l;
|
|
491
491
|
}
|
|
492
|
-
async trajectoryIn30Day(
|
|
492
|
+
async trajectoryIn30Day(e, n, i, o, a, s, d, r = {}) {
|
|
493
493
|
var S;
|
|
494
|
-
const
|
|
494
|
+
const m = {
|
|
495
495
|
headers: {
|
|
496
496
|
appKey: this.token
|
|
497
497
|
},
|
|
498
498
|
json: {
|
|
499
|
-
shipId:
|
|
499
|
+
shipId: e,
|
|
500
500
|
startTime: n,
|
|
501
501
|
endTime: i
|
|
502
502
|
}
|
|
503
|
-
}, M = "https://api3.myships.com/sp/ships/position/history",
|
|
504
|
-
if (
|
|
505
|
-
return
|
|
506
|
-
const
|
|
507
|
-
for (const
|
|
508
|
-
!isNaN(v
|
|
509
|
-
const
|
|
503
|
+
}, M = "https://api3.myships.com/sp/ships/position/history", l = await B.post(M, m).json();
|
|
504
|
+
if (w == null || w.info("[%s] fetch trajectory from: %s - %j", r.requestId, M, m), l.code !== "0")
|
|
505
|
+
return w == null || w.warn("[%s] invoke myship trajectory failed: %j", r.requestId, l), l;
|
|
506
|
+
const g = l.data;
|
|
507
|
+
for (const v in g)
|
|
508
|
+
!isNaN(g[v]) && Number(g[v]) !== 1 / 0 && (g[v] = Number(g[v]));
|
|
509
|
+
const f = b.unix((S = g[0]) == null ? void 0 : S.posTime);
|
|
510
510
|
let C = -1;
|
|
511
|
-
for (const
|
|
512
|
-
const
|
|
511
|
+
for (const v of g) {
|
|
512
|
+
const p = b.unix(v.posTime), c = {
|
|
513
513
|
imo: o == null ? void 0 : o.imo,
|
|
514
514
|
mmsi: a,
|
|
515
|
-
lat: Math.round(
|
|
516
|
-
lng: Math.round(
|
|
517
|
-
sog: Math.round(
|
|
518
|
-
cog: Math.round(
|
|
519
|
-
hdg: Math.round(
|
|
520
|
-
rot: Math.round(
|
|
521
|
-
positionTime:
|
|
522
|
-
utc:
|
|
515
|
+
lat: Math.round(v.lat / 1e4 / 60 * 1e5) / 1e5,
|
|
516
|
+
lng: Math.round(v.lon / 1e4 / 60 * 1e5) / 1e5,
|
|
517
|
+
sog: Math.round(v.sog / 10 * 100) / 100,
|
|
518
|
+
cog: Math.round(v.cog / 10 * 100) / 100,
|
|
519
|
+
hdg: Math.round(v.heading * 100) / 100,
|
|
520
|
+
rot: Math.round(v.rot * 100) / 100,
|
|
521
|
+
positionTime: p.unix(),
|
|
522
|
+
utc: p.utc().format(),
|
|
523
523
|
method: "trajectory",
|
|
524
524
|
vendor: "myship"
|
|
525
|
-
},
|
|
526
|
-
|
|
525
|
+
}, y = Math.floor(p.diff(f, "minute", !0) / (s || 1));
|
|
526
|
+
y !== C && (C = y, d.push(c));
|
|
527
527
|
}
|
|
528
528
|
return d;
|
|
529
529
|
}
|
|
@@ -544,21 +544,21 @@ class yt {
|
|
|
544
544
|
*
|
|
545
545
|
* @param options
|
|
546
546
|
*/
|
|
547
|
-
parsePrinciple(
|
|
547
|
+
parsePrinciple(t, e = {}) {
|
|
548
548
|
var s, d, r;
|
|
549
|
-
_ == null || _.info("[%s] parse rule: %s",
|
|
550
|
-
const n = new RegExp("(?<=\\[)(.+)(?=])", "g"), i =
|
|
549
|
+
_ == null || _.info("[%s] parse rule: %s", e.requestId, t);
|
|
550
|
+
const n = new RegExp("(?<=\\[)(.+)(?=])", "g"), i = t.match(n) ? (s = t.match(n)) == null ? void 0 : s[0] : void 0, o = i == null ? void 0 : i.split(";");
|
|
551
551
|
if (!o)
|
|
552
552
|
return;
|
|
553
553
|
const a = {};
|
|
554
|
-
for (let
|
|
555
|
-
const M = (r = (d = o[
|
|
556
|
-
if (
|
|
554
|
+
for (let m = 0; m < (o == null ? void 0 : o.length); m++) {
|
|
555
|
+
const M = (r = (d = o[m].match(n)) == null ? void 0 : d[0]) == null ? void 0 : r.split("],");
|
|
556
|
+
if (m === 0 && !M)
|
|
557
557
|
a.scope = o[0];
|
|
558
558
|
else if (M)
|
|
559
|
-
for (let
|
|
560
|
-
const
|
|
561
|
-
|
|
559
|
+
for (let l = 0, g = M.length; l < g; l++) {
|
|
560
|
+
const f = this.parseRule(M[l]);
|
|
561
|
+
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);
|
|
562
562
|
}
|
|
563
563
|
}
|
|
564
564
|
return a;
|
|
@@ -569,10 +569,10 @@ class yt {
|
|
|
569
569
|
* @param rule
|
|
570
570
|
* @param options
|
|
571
571
|
*/
|
|
572
|
-
parseRule(
|
|
572
|
+
parseRule(t, e = {}) {
|
|
573
573
|
var a;
|
|
574
|
-
_ == null || _.
|
|
575
|
-
const n = new RegExp("(?<=\\[)(.+?)(?=])", "g"), i = (a =
|
|
574
|
+
_ == null || _.debug("[%s] parse rule: %s", e.requestId, t), t = t.startsWith("[") ? t : `[${t}`, t = t.endsWith("]") ? t : `${t}]`;
|
|
575
|
+
const n = new RegExp("(?<=\\[)(.+?)(?=])", "g"), i = (a = t == null ? void 0 : t.match(n)) == null ? void 0 : a[0], o = i == null ? void 0 : i.split(",");
|
|
576
576
|
if (o)
|
|
577
577
|
return {
|
|
578
578
|
operator: o[0],
|
|
@@ -588,15 +588,15 @@ class yt {
|
|
|
588
588
|
* @param principle 告警规则
|
|
589
589
|
* @param options
|
|
590
590
|
*/
|
|
591
|
-
checkWeather(
|
|
592
|
-
var
|
|
591
|
+
checkWeather(t, e, n = {}) {
|
|
592
|
+
var f, C, S, v, p, c, y, h, u, I, k, D, Y, j, P;
|
|
593
593
|
let i = 0, o = 0, a = 0, s = 0;
|
|
594
|
-
const d = Math.round(((C = (
|
|
595
|
-
for (let T = 0; T < (
|
|
596
|
-
const N =
|
|
597
|
-
s = U > s ? U : s, _ == null || _.
|
|
594
|
+
const d = Math.round(((C = (f = e == null ? void 0 : e.SEVERE) == null ? void 0 : f.sigWave) == null ? void 0 : C.number) * 1.6 * 100) / 100, r = (v = (S = e == null ? void 0 : e.SEVERE) == null ? void 0 : S.sigWave) == null ? void 0 : v.number, m = (c = (p = e == null ? void 0 : e.HEAVY) == null ? void 0 : p.sigWave) == null ? void 0 : c.number, M = Math.round((((h = (y = e == null ? void 0 : e.SEVERE) == null ? void 0 : y.wind) == null ? void 0 : h.number) + 2) * 100) / 100, l = (I = (u = e == null ? void 0 : e.SEVERE) == null ? void 0 : u.wind) == null ? void 0 : I.number, g = (D = (k = e == null ? void 0 : e.HEAVY) == null ? void 0 : k.wind) == null ? void 0 : D.number;
|
|
595
|
+
for (let T = 0; T < (t == null ? void 0 : t.length); T++) {
|
|
596
|
+
const N = t[T], A = (j = (Y = N == null ? void 0 : N.meteo) == null ? void 0 : Y.wave) == null ? void 0 : j.sig, R = (P = N == null ? void 0 : N.meteo) == null ? void 0 : P.wind, U = T ? b(N.eta).diff(b(t[T - 1].eta), "hour", !0) : 0;
|
|
597
|
+
s = U > s ? U : s, _ == null || _.debug("[%s] check sig.wave: %j", n.requestId, { ...A, dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: m }), (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) >= m && (N.isHeavy = !0), _ == null || _.debug("[%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 ? U : 0, o += N.isSevere ? U : 0, a += N.isHeavy ? U : 0;
|
|
598
598
|
}
|
|
599
|
-
return i = Math.round(i * 100) / 100, o = Math.round(o * 100) / 100, a = Math.round(a * 100) / 100, s = Math.round(s), { sample:
|
|
599
|
+
return i = Math.round(i * 100) / 100, o = Math.round(o * 100) / 100, a = Math.round(a * 100) / 100, s = Math.round(s), { sample: t, dangerous: i, severe: o, heavy: a, step: s < 3 ? 3 : s, wind: { dgThd4Wd: M, svThd4Wd: l, hvThd4Wd: g }, sig: { dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: m } };
|
|
600
600
|
}
|
|
601
601
|
}
|
|
602
602
|
const Tt = new yt();
|
|
@@ -621,8 +621,8 @@ class O {
|
|
|
621
621
|
* @param draught 吃水 m
|
|
622
622
|
* @return [0.55, 0.85]
|
|
623
623
|
*/
|
|
624
|
-
static blockCoefficient(
|
|
625
|
-
let o = Math.round(
|
|
624
|
+
static blockCoefficient(t, e, n, i) {
|
|
625
|
+
let o = Math.round(t / (e * n * i) * 100) / 100;
|
|
626
626
|
o = o < 0.55 ? 0.55 : o > 0.85 ? 0.85 : o;
|
|
627
627
|
const a = [0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85], s = a.map((d) => Math.abs(d - o));
|
|
628
628
|
return a[s.indexOf(Math.min(...s))];
|
|
@@ -638,8 +638,8 @@ class O {
|
|
|
638
638
|
* @param g 重力加速度 9.80 m/s^2
|
|
639
639
|
* @return [0.05, 0.30]
|
|
640
640
|
*/
|
|
641
|
-
static froudeNumber(
|
|
642
|
-
let i = Math.round(Math.sqrt(
|
|
641
|
+
static froudeNumber(t, e, n = 9.8) {
|
|
642
|
+
let i = Math.round(Math.sqrt(t * t / (n * e)) * 100) / 100;
|
|
643
643
|
return i = i < 0.05 ? 0.05 : i > 0.3 ? 0.3 : i, i;
|
|
644
644
|
}
|
|
645
645
|
/**
|
|
@@ -649,7 +649,7 @@ class O {
|
|
|
649
649
|
* @param loadCondition
|
|
650
650
|
* @private
|
|
651
651
|
*/
|
|
652
|
-
static amendFactor(
|
|
652
|
+
static amendFactor(t, e, n) {
|
|
653
653
|
const i = {
|
|
654
654
|
0.55: [1.7, -1.4, -7.4],
|
|
655
655
|
0.6: [2.2, -2.5, -9.7],
|
|
@@ -667,8 +667,8 @@ class O {
|
|
|
667
667
|
0.75: [2.6, -12.5, -13.5],
|
|
668
668
|
0.8: [3, -16.3, -21.6],
|
|
669
669
|
0.85: [3.4, -20.9, 31.8]
|
|
670
|
-
}[
|
|
671
|
-
return n === "Laden" && (a = i[
|
|
670
|
+
}[t];
|
|
671
|
+
return n === "Laden" && (a = i[t]), a[0] + a[1] * e + a[2] * Math.pow(e, 2);
|
|
672
672
|
}
|
|
673
673
|
/**
|
|
674
674
|
* 失速方向因子
|
|
@@ -681,9 +681,9 @@ class O {
|
|
|
681
681
|
* @param bn
|
|
682
682
|
* @private
|
|
683
683
|
*/
|
|
684
|
-
static directionFactor(
|
|
684
|
+
static directionFactor(t, e = 0) {
|
|
685
685
|
let n;
|
|
686
|
-
return
|
|
686
|
+
return t > 30 && t <= 60 ? n = (1.7 - 0.03 * Math.pow(e - 4, 2)) / 2 : t > 60 && t <= 150 ? n = (0.9 - 0.06 * Math.pow(e - 6, 2)) / 2 : t > 150 && t <= 180 ? n = (0.4 - 0.03 * Math.pow(e - 8, 2)) / 2 : n = 1, Math.round(n * 1e5) / 1e5;
|
|
687
687
|
}
|
|
688
688
|
/**
|
|
689
689
|
* 失速船型因子
|
|
@@ -696,20 +696,20 @@ class O {
|
|
|
696
696
|
* @param bn
|
|
697
697
|
* @private
|
|
698
698
|
*/
|
|
699
|
-
static vesselTagFactor(
|
|
699
|
+
static vesselTagFactor(t, e, n, i = 0) {
|
|
700
700
|
i = i > 6 ? i - 0.9 * (i - 6) : i;
|
|
701
701
|
let o;
|
|
702
|
-
return n === "container" ? o = 0.7 * i + Math.pow(i, 6.5) / (22 * Math.pow(
|
|
702
|
+
return n === "container" ? o = 0.7 * i + Math.pow(i, 6.5) / (22 * Math.pow(t, 2 / 3)) : e === "Ballast" ? o = 0.7 * i + Math.pow(i, 6.5) / (2.7 * Math.pow(t, 2 / 3)) : o = 0.5 * i + Math.pow(i, 6.5) / (2.7 * Math.pow(t, 2 / 3)), o;
|
|
703
703
|
}
|
|
704
704
|
/**
|
|
705
705
|
* 浪高影响因子
|
|
706
706
|
* @param ht 浪高,单位m
|
|
707
707
|
* @private
|
|
708
708
|
*/
|
|
709
|
-
static waveHeightFactor(
|
|
710
|
-
|
|
709
|
+
static waveHeightFactor(t, e) {
|
|
710
|
+
t = t < 0 ? 0.2 : t, t = t > 6 ? t - 0.9 * (t - 6) : t, t = t > 9 ? 9 : t;
|
|
711
711
|
let n;
|
|
712
|
-
return
|
|
712
|
+
return e > 30 && e <= 60 ? n = -0.6 : e > 60 && e <= 90 ? n = -0.4 : e > 90 && e <= 120 ? n = t < 3 ? 0.4 : -0.3 : e > 120 && e <= 150 ? n = t < 3 ? 0.6 : -0.5 : e > 150 && e <= 180 ? n = t < 3 ? 0.7 : -0.6 : n = -0.7, Math.round(n * (0.144 * Math.pow(t, 2) + 0.178 * t) * 1e4) / 1e4;
|
|
713
713
|
}
|
|
714
714
|
/**
|
|
715
715
|
* 组装船舶运行参数
|
|
@@ -719,13 +719,13 @@ class O {
|
|
|
719
719
|
* @param bearing 方位角
|
|
720
720
|
* @private
|
|
721
721
|
*/
|
|
722
|
-
static assembleProperties(
|
|
723
|
-
var
|
|
724
|
-
const o =
|
|
722
|
+
static assembleProperties(t, e, n, i) {
|
|
723
|
+
var l;
|
|
724
|
+
const o = t.lbp ?? t.length ?? t.lengthOverall ?? 198.9642, a = t.draught ?? 8, s = t.breadthMoulded ?? t.breadth ?? t.breadthExtreme ?? 32.4572, d = t.deadweight ?? 67035.7773, r = ((l = t == null ? void 0 : t.type) == null ? void 0 : l.toLowerCase()) || "common";
|
|
725
725
|
return {
|
|
726
726
|
tag: r.indexOf("container") > -1 ? "container" : r.indexOf("tugs") > -1 ? "tugs" : "common",
|
|
727
727
|
lbp: o,
|
|
728
|
-
loadCondition:
|
|
728
|
+
loadCondition: e,
|
|
729
729
|
draught: a,
|
|
730
730
|
breadthMoulded: s,
|
|
731
731
|
// 排水量(吨)= 载重量(吨)/ 1.025 + 吃水(米)× 船舶型宽(米)× 船舶型长(米)× 0.7
|
|
@@ -746,29 +746,29 @@ class O {
|
|
|
746
746
|
* @param useMeteo true 启用气象分析
|
|
747
747
|
* @param useRouteParam true 启用设置速度
|
|
748
748
|
*/
|
|
749
|
-
static async speedLoseAt(
|
|
749
|
+
static async speedLoseAt(t, e, n, i = "", o = 2, a = !0, s = !1, d = {}) {
|
|
750
750
|
let r;
|
|
751
|
-
if (
|
|
752
|
-
let
|
|
751
|
+
if (e.velocity && s && (t.speed = J.roundPrecision(e.velocity * 1852 / 3600, 6)), a) {
|
|
752
|
+
let m;
|
|
753
753
|
try {
|
|
754
754
|
i = (i == null ? void 0 : i.toUpperCase()) === "CMEMS" ? "ECMWF" : i, i = (i == null ? void 0 : i.toUpperCase()) === "METEO2" ? "best_match" : i;
|
|
755
|
-
const { weatherModels:
|
|
755
|
+
const { weatherModels: f, marineModels: C } = await it.autoPickMeteoModel(i), S = await Mt.spotForecast(e.lat, e.lng, n.utc().format(), !1, !1, !0, {
|
|
756
756
|
...d,
|
|
757
757
|
pastDays: 1,
|
|
758
758
|
forecastDays: 1,
|
|
759
|
-
weatherModels:
|
|
759
|
+
weatherModels: f,
|
|
760
760
|
marineModels: C
|
|
761
|
-
}), [
|
|
762
|
-
|
|
763
|
-
} catch (
|
|
764
|
-
F.warn("[%s] meteo2 spot(%j) forecast failed: %s", d.requestId, { ...
|
|
761
|
+
}), [v] = it.pickHourly(S, n);
|
|
762
|
+
m = it.toLegacy(v);
|
|
763
|
+
} catch (f) {
|
|
764
|
+
F.warn("[%s] meteo2 spot(%j) forecast failed: %s", d.requestId, { ...e, eta: n.utc().format(), source: i }, f);
|
|
765
765
|
}
|
|
766
|
-
const M = O.weatherFactor(
|
|
766
|
+
const M = O.weatherFactor(t, m), l = O.currentFactor(t.bearing, m == null ? void 0 : m.current, o), g = Math.round((t.speed * 1.943844 + M + l) * 100) / 100;
|
|
767
767
|
r = {
|
|
768
|
-
meteo: { ...
|
|
768
|
+
meteo: { ...m },
|
|
769
769
|
wxFactor: M,
|
|
770
|
-
cFactor:
|
|
771
|
-
speed:
|
|
770
|
+
cFactor: l,
|
|
771
|
+
speed: e.velocity && s ? e.velocity : g < 0 ? 1 : g,
|
|
772
772
|
eta: n.utc().format(),
|
|
773
773
|
etd: n.utc().format()
|
|
774
774
|
};
|
|
@@ -776,11 +776,11 @@ class O {
|
|
|
776
776
|
r = {
|
|
777
777
|
wxFactor: 0,
|
|
778
778
|
cFactor: 0,
|
|
779
|
-
speed:
|
|
779
|
+
speed: e.velocity && s ? e.velocity : Math.round((t.speed * 1.943844 + 0 + 0) * 100) / 100,
|
|
780
780
|
eta: n.utc().format(),
|
|
781
781
|
etd: n.utc().format()
|
|
782
782
|
};
|
|
783
|
-
return delete
|
|
783
|
+
return delete e.meteo, delete e.wxFactor, delete e.cFactor, delete e.speed, delete e.etd, { ...r, ...e };
|
|
784
784
|
}
|
|
785
785
|
/**
|
|
786
786
|
* 基于步长计算失速样本
|
|
@@ -795,53 +795,53 @@ class O {
|
|
|
795
795
|
* @param useRouteParam true 启用航线上设置的参数 { suspend: 停留时长(小时), velocity: 速度(kts)}
|
|
796
796
|
* @private
|
|
797
797
|
*/
|
|
798
|
-
static async speedLoseInHoursStep(
|
|
799
|
-
|
|
800
|
-
const M =
|
|
801
|
-
let
|
|
802
|
-
for (let
|
|
803
|
-
let c = a[
|
|
798
|
+
static async speedLoseInHoursStep(t, e, n, i, o, a, s = "", d = !0, r = !1, m = {}) {
|
|
799
|
+
e.utc();
|
|
800
|
+
const M = e.clone().add(14, "days"), l = [], g = [];
|
|
801
|
+
let f = 0, C = 0, S, v;
|
|
802
|
+
for (let p = 0; p < a.length - 1; p++) {
|
|
803
|
+
let c = a[p];
|
|
804
804
|
c.distanceFromStart = Math.round((o + C) * 1e4) / 1e4;
|
|
805
|
-
const
|
|
806
|
-
if (
|
|
807
|
-
c.eta = c.eta ||
|
|
805
|
+
const y = a[p + 1];
|
|
806
|
+
if (t.bearing = W.calculateBearing(c, y, !y.gcToPrevious), c.bearing = t.bearing, c.suspend && r) {
|
|
807
|
+
c.eta = c.eta || e.utc().format(), c.elapsed = c.elapsed ?? 0;
|
|
808
808
|
const I = c.suspend - c.elapsed;
|
|
809
|
-
if (i -
|
|
810
|
-
i = i -
|
|
809
|
+
if (i - f > I)
|
|
810
|
+
i = i - f - I, e.add(I, "hour"), c.elapsed = c.suspend;
|
|
811
811
|
else {
|
|
812
|
-
const k = i -
|
|
813
|
-
c.elapsed += k,
|
|
812
|
+
const k = i - f;
|
|
813
|
+
c.elapsed += k, e.add(k, "hour"), i = 0;
|
|
814
814
|
}
|
|
815
|
-
if (F == null || F.info(`[%s] suspend ${c.elapsed} hours at %j, and remain ${i} hours need to go...`,
|
|
816
|
-
return c.distanceFromPrevious = C, { etd:
|
|
815
|
+
if (F == null || F.info(`[%s] suspend ${c.elapsed} hours at %j, and remain ${i} hours need to go...`, m.requestId, c), i === 0)
|
|
816
|
+
return c.distanceFromPrevious = C, { etd: e, from: v || c, to: c, next: a.filter((k) => k), wps: l, days: g };
|
|
817
817
|
} else
|
|
818
818
|
c.suspend = 0;
|
|
819
|
-
d =
|
|
820
|
-
const
|
|
821
|
-
let u = Math.round(
|
|
822
|
-
if (
|
|
823
|
-
if (
|
|
824
|
-
`[%s] go to %j from %j with ${
|
|
825
|
-
|
|
826
|
-
{ lat:
|
|
827
|
-
{ lat:
|
|
828
|
-
), C +=
|
|
829
|
-
S =
|
|
819
|
+
d = e.isAfter(M) ? !1 : d, c = await O.speedLoseAt(t, c, e, s, 0, d, r, m), v = v || c, c.important && l.push(c), e.isSameOrAfter(n) && (g.push(c), n.add(24, "hour"));
|
|
820
|
+
const h = W.calculateDistance(c, y, !y.gcToPrevious);
|
|
821
|
+
let u = Math.round(h / v.speed * 1e5) / 1e5;
|
|
822
|
+
if (f + u < i) {
|
|
823
|
+
if (f += u, e.add(u, "hour"), delete a[p], F == null || F.debug(
|
|
824
|
+
`[%s] go to %j from %j with ${h}nm, and cost ${u} hours`,
|
|
825
|
+
m.requestId,
|
|
826
|
+
{ lat: y.lat, lng: y.lng },
|
|
827
|
+
{ lat: v.lat, lng: v.lng, etd: v.etd }
|
|
828
|
+
), C += h, a.filter((I) => I).length <= 1) {
|
|
829
|
+
S = y, S.eta = e.utc().format(), S.distanceFromPrevious = h, S.distanceFromStart = Math.round((o + C) * 1e4) / 1e4, l.push(S), delete a[p + 1];
|
|
830
830
|
break;
|
|
831
831
|
}
|
|
832
832
|
} else {
|
|
833
|
-
u = i -
|
|
834
|
-
const I = J.roundPrecision(
|
|
835
|
-
S = W.calculateCoordinate(c,
|
|
833
|
+
u = i - f, e.add(u, "hour");
|
|
834
|
+
const I = J.roundPrecision(v.speed * u, 5);
|
|
835
|
+
S = W.calculateCoordinate(c, t.bearing, I, "nauticalmiles", !y.gcToPrevious), S.eta = e.utc().format(), a[p] = S, F == null || F.debug(
|
|
836
836
|
`[%s] go to %j from %j with ${I}nm, and cost ${u} hours`,
|
|
837
|
-
|
|
837
|
+
m.requestId,
|
|
838
838
|
{ lat: S.lat, lng: S.lng },
|
|
839
839
|
{ lat: c.lat, lng: c.lng, etd: c.etd }
|
|
840
840
|
), C += I, S.distanceFromPrevious = Math.round(C * 1e4) / 1e4, S.distanceFromStart = Math.round((o + C) * 1e4) / 1e4;
|
|
841
841
|
break;
|
|
842
842
|
}
|
|
843
843
|
}
|
|
844
|
-
return { etd:
|
|
844
|
+
return { etd: e, from: v, to: S, next: a.filter((p) => p), wps: l, days: g };
|
|
845
845
|
}
|
|
846
846
|
/**
|
|
847
847
|
* 洋流影响因子
|
|
@@ -849,11 +849,11 @@ class O {
|
|
|
849
849
|
* @param current 洋流要素
|
|
850
850
|
* @param role 1: 船东, 2: 租家, 0: 未知
|
|
851
851
|
*/
|
|
852
|
-
static currentFactor(
|
|
853
|
-
const i = (
|
|
852
|
+
static currentFactor(t, e, n = 0) {
|
|
853
|
+
const i = (t - (e == null ? void 0 : e.degree) || 0) / 180 * Math.PI;
|
|
854
854
|
if (Math.abs(i) === Math.PI / 2)
|
|
855
855
|
return 0;
|
|
856
|
-
let o = ((
|
|
856
|
+
let o = ((e == null ? void 0 : e.kts) || 0) * Math.cos(i);
|
|
857
857
|
return n & 2 ? o = Math.ceil(o * 100) / 100 : n & 1 ? o = Math.floor(o * 100) / 100 : o = Math.round(o * 100) / 100, Math.abs(o) > 5 ? 0 : o;
|
|
858
858
|
}
|
|
859
859
|
/**
|
|
@@ -861,17 +861,17 @@ class O {
|
|
|
861
861
|
* @param props 船舶档案
|
|
862
862
|
* @param wwc 气象要素
|
|
863
863
|
*/
|
|
864
|
-
static weatherFactor(
|
|
865
|
-
var M,
|
|
866
|
-
F == null || F.debug("calculate weather factor via: %j", { ...
|
|
867
|
-
const n = O.blockCoefficient(
|
|
868
|
-
let a = Math.abs(
|
|
864
|
+
static weatherFactor(t, e) {
|
|
865
|
+
var M, l, g, f, C, S, v;
|
|
866
|
+
F == null || F.debug("calculate weather factor via: %j", { ...t, ...e });
|
|
867
|
+
const n = O.blockCoefficient(t.displacement, t.lbp, t.breadthMoulded, t.draught), i = O.froudeNumber(t.speed, t.lbp), o = O.amendFactor(n, i, t.loadCondition);
|
|
868
|
+
let a = Math.abs(t.bearing % 360 - (((M = e == null ? void 0 : e.wind) == null ? void 0 : M.degree) % 360 || 0));
|
|
869
869
|
a = a > 180 ? 360 - a : a;
|
|
870
|
-
const s = O.directionFactor(a, (
|
|
871
|
-
let r = s * o * d / 100 *
|
|
872
|
-
r = Math.round(r * 1.943844 * 1e4) / 1e4 * -1,
|
|
873
|
-
const
|
|
874
|
-
return F == null || F.debug("wave wx factor = %d",
|
|
870
|
+
const s = O.directionFactor(a, (l = e == null ? void 0 : e.wind) == null ? void 0 : l.scale), d = O.vesselTagFactor(t.displacement, t.loadCondition, t.tag, (g = e == null ? void 0 : e.wind) == null ? void 0 : g.scale);
|
|
871
|
+
let r = s * o * d / 100 * t.speed;
|
|
872
|
+
r = Math.round(r * 1.943844 * 1e4) / 1e4 * -1, t.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(t.bearing % 360 - (((C = (f = e == null ? void 0 : e.wave) == null ? void 0 : f.sig) == null ? void 0 : C.degree) % 360 || 0));
|
|
873
|
+
const m = O.waveHeightFactor(((v = (S = e == null ? void 0 : e.wave) == null ? void 0 : S.sig) == null ? void 0 : v.height) ?? 1, a);
|
|
874
|
+
return F == null || F.debug("wave wx factor = %d", m), r = r * 0.4 + m, 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;
|
|
875
875
|
}
|
|
876
876
|
/**
|
|
877
877
|
* 全程失速分析(走完航程)
|
|
@@ -885,79 +885,79 @@ class O {
|
|
|
885
885
|
* @param useMeteo true 启用气象分析
|
|
886
886
|
* @param useRouteParam
|
|
887
887
|
*/
|
|
888
|
-
static async analyseInstant(
|
|
888
|
+
static async analyseInstant(t, e, n, i, o, a = "", s = 0, d = !0, r = !1, m = {}) {
|
|
889
889
|
var z, G, Q, X, Z, $;
|
|
890
|
-
const M =
|
|
891
|
-
|
|
892
|
-
const { route:
|
|
893
|
-
if (((z =
|
|
890
|
+
const M = b().valueOf();
|
|
891
|
+
t.lng = J.convertToStdLng(t.lng);
|
|
892
|
+
const { route: l, waypoints: g } = o.points, f = W.calculateSubRoute(t, l);
|
|
893
|
+
if (((z = f[0]) == null ? void 0 : z.length) <= 1)
|
|
894
894
|
return;
|
|
895
|
-
const { v0: C, label: S } =
|
|
896
|
-
v0:
|
|
897
|
-
label:
|
|
895
|
+
const { v0: C, label: S } = t.sog ? {
|
|
896
|
+
v0: t.sog,
|
|
897
|
+
label: t.label || "Other"
|
|
898
898
|
/* Instruct */
|
|
899
899
|
} : {
|
|
900
900
|
v0: i.speed,
|
|
901
901
|
label: "CP"
|
|
902
902
|
/* Cp */
|
|
903
|
-
},
|
|
904
|
-
|
|
903
|
+
}, v = O.assembleProperties(n, i.loadCondition, C, 0), p = g.length ? W.calculateSubWaypoints(t, g) : [];
|
|
904
|
+
p.forEach((q) => q.important = !0);
|
|
905
905
|
const c = {
|
|
906
|
-
from: { ...
|
|
907
|
-
route:
|
|
908
|
-
waypoints:
|
|
906
|
+
from: { ...t },
|
|
907
|
+
route: f,
|
|
908
|
+
waypoints: p,
|
|
909
909
|
v0: C,
|
|
910
910
|
label: S
|
|
911
|
-
},
|
|
911
|
+
}, y = {
|
|
912
912
|
hours: [],
|
|
913
913
|
days: [],
|
|
914
914
|
wps: []
|
|
915
915
|
};
|
|
916
|
-
s || (W.calculateRouteDistance(
|
|
917
|
-
let
|
|
918
|
-
|
|
919
|
-
const Y =
|
|
920
|
-
for (;
|
|
921
|
-
const q = s -
|
|
922
|
-
|
|
923
|
-
|
|
916
|
+
s || (W.calculateRouteDistance(f) / i.speed <= 72 ? s = 3 : s = 6);
|
|
917
|
+
let h = W.simplifyRouteToCoordinates(f, p, 0), u = 0, I = 0, k = 0, D = 0;
|
|
918
|
+
e = b(e).utc();
|
|
919
|
+
const Y = e.clone();
|
|
920
|
+
for (; h.length > 0; ) {
|
|
921
|
+
const q = s - e.hour() % s, V = Math.ceil(e.clone().add(q, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(e, "h", !0) * 1e4) / 1e4, x = await O.speedLoseInHoursStep(
|
|
922
|
+
v,
|
|
923
|
+
e,
|
|
924
924
|
Y,
|
|
925
925
|
V,
|
|
926
926
|
u,
|
|
927
|
-
|
|
927
|
+
h,
|
|
928
928
|
a,
|
|
929
929
|
d,
|
|
930
930
|
r,
|
|
931
|
-
|
|
931
|
+
m
|
|
932
932
|
);
|
|
933
|
-
(G = x.from) != null && G.speed && (
|
|
933
|
+
(G = x.from) != null && G.speed && (y.hours.push(x.from), y.wps.push(...x.wps), y.days.push(...x.days)), h = x == null ? void 0 : x.next, h.length || y.hours.push(x == null ? void 0 : x.to), u += Math.round((((Q = x == null ? void 0 : x.to) == null ? void 0 : Q.distanceFromPrevious) ?? 0) * 1e4) / 1e4;
|
|
934
934
|
}
|
|
935
|
-
const j =
|
|
935
|
+
const j = y.hours;
|
|
936
936
|
for (let q = 0; q < j.length - 1; q++) {
|
|
937
|
-
const V =
|
|
937
|
+
const V = b(j[q + 1].eta).diff(j[q].etd, "hour", !0) || 1;
|
|
938
938
|
I += (j[q].wxFactor || 0) * V, k += (j[q].cFactor || 0) * V, D += V;
|
|
939
939
|
}
|
|
940
|
-
(X =
|
|
941
|
-
q.positionTime =
|
|
942
|
-
const x =
|
|
940
|
+
(X = y.wps) == null || X.forEach((q, V) => {
|
|
941
|
+
q.positionTime = b.utc(q.etd || q.eta).unix();
|
|
942
|
+
const x = y.wps[V - 1];
|
|
943
943
|
if (x) {
|
|
944
|
-
const L = q.distanceFromStart - x.distanceFromStart, H =
|
|
944
|
+
const L = q.distanceFromStart - x.distanceFromStart, H = b(q.eta || q.etd).diff(b(x.etd || x.eta), "h", !0);
|
|
945
945
|
q.avgSpd = Math.round(L / H * 100) / 100;
|
|
946
946
|
const nt = W.calculateBearing(x, q);
|
|
947
947
|
x.bearing = nt;
|
|
948
948
|
}
|
|
949
|
-
}),
|
|
950
|
-
const P =
|
|
951
|
-
c.distance = Math.round(T.distanceFromStart * 1e4) / 1e4, c.etd =
|
|
952
|
-
const { distanceInECA: N, hoursInECA: A, totalDgoConsInECA: R, eca: U } = await this.calculateECA(c, i,
|
|
949
|
+
}), y.wps = (Z = y.wps) == null ? void 0 : Z.reduce((q, V) => (q.some((x) => Math.round(x.positionTime / 60) === Math.round(V.positionTime / 60)) || q.push(V), q), []), c.sample = y;
|
|
950
|
+
const P = y.hours.at(0), T = y.hours.at(-1);
|
|
951
|
+
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(I / D * 1e4) / 1e4, c.cFactor = Math.round(k / D * 1e4) / 1e4, c.avgSpeed = Math.round(T.distanceFromStart / D * 1e4) / 1e4, c.totalHrs = Math.round(D * 1e4) / 1e4;
|
|
952
|
+
const { distanceInECA: N, hoursInECA: A, totalDgoConsInECA: R, eca: U } = await this.calculateECA(c, i, m), st = J.roundPrecision(i.fo / 24 * (D - A), 3), at = J.roundPrecision(i.dgo / 24 * D, 3);
|
|
953
953
|
c.extend = {
|
|
954
954
|
eca: U,
|
|
955
955
|
distanceInECA: N,
|
|
956
956
|
hoursInECA: A,
|
|
957
957
|
totalDgoConsInECA: R
|
|
958
958
|
}, c.totalFoCons = st, c.totalDgoCons = at;
|
|
959
|
-
const tt =
|
|
960
|
-
return F == null || F.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",
|
|
959
|
+
const tt = b().valueOf() - M, ot = (($ = y == null ? void 0 : y.hours) == null ? void 0 : $.length) || 1;
|
|
960
|
+
return F == null || F.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", m == null ? void 0 : m.requestId, tt, ot, Math.round(tt / ot * 1e3) / 1e3), c;
|
|
961
961
|
}
|
|
962
962
|
/**
|
|
963
963
|
* 分段失速分析(最多走hours 小时)
|
|
@@ -972,43 +972,43 @@ class O {
|
|
|
972
972
|
* @param useMeteo true 启用气象分析
|
|
973
973
|
* @param useRouteParam
|
|
974
974
|
*/
|
|
975
|
-
static async analyseInstantWithThreshed(
|
|
975
|
+
static async analyseInstantWithThreshed(t, e, n, i, o, a, s, d = "", r = 3, m = !0, M = !1, l = {}) {
|
|
976
976
|
var Q, X, Z, $, q, V;
|
|
977
|
-
const
|
|
978
|
-
|
|
979
|
-
const { v0:
|
|
980
|
-
v0:
|
|
981
|
-
label:
|
|
977
|
+
const g = b().valueOf();
|
|
978
|
+
t.lng = J.convertToStdLng(t.lng);
|
|
979
|
+
const { v0: f, label: C } = t.sog ? {
|
|
980
|
+
v0: t.sog,
|
|
981
|
+
label: t.label || "Other"
|
|
982
982
|
/* Instruct */
|
|
983
983
|
} : {
|
|
984
984
|
v0: o.speed,
|
|
985
985
|
label: "CP"
|
|
986
986
|
/* Cp */
|
|
987
|
-
}, S = O.assembleProperties(i, o.loadCondition,
|
|
988
|
-
if (((Q =
|
|
987
|
+
}, S = O.assembleProperties(i, o.loadCondition, f, 0), v = W.calculateSubRoute(t, a);
|
|
988
|
+
if (((Q = v[0]) == null ? void 0 : Q.length) <= 1)
|
|
989
989
|
return;
|
|
990
|
-
const
|
|
991
|
-
|
|
992
|
-
let c = W.simplifyRouteToCoordinates(
|
|
990
|
+
const p = s.length ? W.calculateSubWaypoints(t, s) : [];
|
|
991
|
+
p.forEach((x) => x.important = !0);
|
|
992
|
+
let c = W.simplifyRouteToCoordinates(v, p, 0), y = 0, h = 0, u = 0, I = 0;
|
|
993
993
|
const k = {
|
|
994
994
|
hours: [],
|
|
995
995
|
wps: [],
|
|
996
996
|
days: []
|
|
997
997
|
};
|
|
998
|
-
|
|
999
|
-
const D =
|
|
998
|
+
e = b(e).utc();
|
|
999
|
+
const D = e.clone();
|
|
1000
1000
|
for (; c.length > 0; ) {
|
|
1001
|
-
const x = r -
|
|
1002
|
-
let L = Math.ceil(
|
|
1003
|
-
L =
|
|
1004
|
-
const H = await O.speedLoseInHoursStep(S,
|
|
1005
|
-
if ((X = H.from) != null && X.speed && (k.hours.push(H.from), H != null && H.wps && k.wps.push(...H.wps), k.days.push(...H.days)), c = H == null ? void 0 : H.next, c.length || k.hours.push(H == null ? void 0 : H.to),
|
|
1001
|
+
const x = r - e.hour() % r;
|
|
1002
|
+
let L = Math.ceil(e.clone().add(x, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(e, "h", !0) * 1e4) / 1e4;
|
|
1003
|
+
L = e.clone().add(L, "h").isSameOrAfter(n) ? n.diff(e, "h", !0) * 1e4 / 1e4 : L;
|
|
1004
|
+
const H = await O.speedLoseInHoursStep(S, e, D, L, y, c, d, m, M, l);
|
|
1005
|
+
if ((X = H.from) != null && X.speed && (k.hours.push(H.from), H != null && H.wps && k.wps.push(...H.wps), k.days.push(...H.days)), c = H == null ? void 0 : H.next, c.length || k.hours.push(H == null ? void 0 : H.to), y += Math.round((((Z = H == null ? void 0 : H.to) == null ? void 0 : Z.distanceFromPrevious) ?? 0) * 1e4) / 1e4, !L)
|
|
1006
1006
|
break;
|
|
1007
1007
|
}
|
|
1008
|
-
k.wps = ($ = k.wps) == null ? void 0 : $.reduce((x, L) => (x.some((H) => Math.round(
|
|
1008
|
+
k.wps = ($ = k.wps) == null ? void 0 : $.reduce((x, L) => (x.some((H) => Math.round(b(H.etd).unix() / 60) === Math.round(b(L.etd).unix() / 60)) || x.push(L), x), []), (q = k.wps) == null || q.forEach((x, L) => {
|
|
1009
1009
|
const H = k.wps[L - 1];
|
|
1010
1010
|
if (H) {
|
|
1011
|
-
const nt = x.distanceFromStart - H.distanceFromStart, dt =
|
|
1011
|
+
const nt = x.distanceFromStart - H.distanceFromStart, dt = b(x.eta || x.etd).diff(b(H.etd || H.eta), "h", !0);
|
|
1012
1012
|
x.avgSpd = Math.round(nt / dt * 100) / 100;
|
|
1013
1013
|
const ut = W.calculateBearing(H, x);
|
|
1014
1014
|
H.bearing = ut;
|
|
@@ -1016,16 +1016,16 @@ class O {
|
|
|
1016
1016
|
});
|
|
1017
1017
|
const Y = k.hours;
|
|
1018
1018
|
for (let x = 0; x < Y.length - 1; x++) {
|
|
1019
|
-
const L =
|
|
1020
|
-
|
|
1019
|
+
const L = b(Y[x + 1].eta).diff(Y[x].etd, "hour", !0);
|
|
1020
|
+
h += Y[x].wxFactor * L, u += Y[x].cFactor * L, I += L;
|
|
1021
1021
|
}
|
|
1022
|
-
const j = k.hours.at(0), P = k.hours.at(-1), T = await W.calculateRangeRoute(j, P,
|
|
1022
|
+
const j = k.hours.at(0), P = k.hours.at(-1), T = await W.calculateRangeRoute(j, P, v), N = await W.calculateRangeWaypoints(j, P, v, p), A = {
|
|
1023
1023
|
sample: k,
|
|
1024
1024
|
distance: Math.round(((P == null ? void 0 : P.distanceFromStart) || 0) * 1e4) / 1e4,
|
|
1025
1025
|
// 注意,可能会在first节点Drift,所有采用eta做为初始出发时间
|
|
1026
|
-
etd:
|
|
1027
|
-
eta:
|
|
1028
|
-
wxFactor: Math.round(
|
|
1026
|
+
etd: b(j.eta).utc().format(),
|
|
1027
|
+
eta: b(P == null ? void 0 : P.eta).utc().format(),
|
|
1028
|
+
wxFactor: Math.round(h / I * 1e4) / 1e4,
|
|
1029
1029
|
cFactor: Math.round(u / I * 1e4) / 1e4,
|
|
1030
1030
|
avgSpeed: Math.round(((P == null ? void 0 : P.distanceFromStart) || 0) / I * 1e4) / 1e4,
|
|
1031
1031
|
totalHrs: Math.round(I * 1e4) / 1e4,
|
|
@@ -1033,17 +1033,17 @@ class O {
|
|
|
1033
1033
|
to: P,
|
|
1034
1034
|
route: T,
|
|
1035
1035
|
waypoints: N,
|
|
1036
|
-
v0:
|
|
1036
|
+
v0: f,
|
|
1037
1037
|
label: C
|
|
1038
|
-
}, { distanceInECA: R, hoursInECA: U, totalDgoConsInECA: st, eca: at } = await this.calculateECA(A, o,
|
|
1038
|
+
}, { distanceInECA: R, hoursInECA: U, totalDgoConsInECA: st, eca: at } = await this.calculateECA(A, o, l), ct = J.roundPrecision(o.fo / 24 * (I - U), 3), tt = J.roundPrecision(o.dgo / 24 * I, 3);
|
|
1039
1039
|
A.extend = {
|
|
1040
1040
|
eca: at,
|
|
1041
1041
|
distanceInECA: R,
|
|
1042
1042
|
hoursInECA: U,
|
|
1043
1043
|
totalDgoConsInECA: st
|
|
1044
1044
|
}, A.totalDgoCons = tt, A.totalFoCons = ct;
|
|
1045
|
-
const z =
|
|
1046
|
-
return F == null || F.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms",
|
|
1045
|
+
const z = b().valueOf() - g, G = ((V = k == null ? void 0 : k.hours) == null ? void 0 : V.length) || 1;
|
|
1046
|
+
return F == null || F.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", l == null ? void 0 : l.requestId, z, G, Math.round(z / G * 1e3) / 1e3), A;
|
|
1047
1047
|
}
|
|
1048
1048
|
/**
|
|
1049
1049
|
* 在指定航线条件下,基于多CP,动态计算最优成本(租金+油费)方案
|
|
@@ -1060,34 +1060,34 @@ class O {
|
|
|
1060
1060
|
* @param lane 基础航线(重要转向点)
|
|
1061
1061
|
* @param options
|
|
1062
1062
|
*/
|
|
1063
|
-
static async analyseCost(
|
|
1064
|
-
var
|
|
1065
|
-
const a =
|
|
1066
|
-
|
|
1063
|
+
static async analyseCost(t, e, n, i, o = {}) {
|
|
1064
|
+
var v, p;
|
|
1065
|
+
const a = b().valueOf(), s = [];
|
|
1066
|
+
t.speedStep = t.speedStep || 3, t.alterStep = t.alterStep ?? 1;
|
|
1067
1067
|
const d = W.calculateRouteDistance(i.route);
|
|
1068
1068
|
let r = 0;
|
|
1069
1069
|
n.forEach((c) => {
|
|
1070
|
-
const
|
|
1071
|
-
r = r <
|
|
1070
|
+
const y = Math.ceil(d / c.speed / 24);
|
|
1071
|
+
r = r < y ? y : r;
|
|
1072
1072
|
}), r = r * 1.3;
|
|
1073
|
-
const
|
|
1073
|
+
const m = b.utc(t.etd).add(r ?? 14, "day");
|
|
1074
1074
|
let M = 1;
|
|
1075
1075
|
for (const c of n) {
|
|
1076
|
-
const
|
|
1077
|
-
{ lat:
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1076
|
+
const y = JSON.parse(JSON.stringify(i.route)), h = JSON.parse(JSON.stringify(i.waypoints)), u = await O.analyseInstantWithThreshed(
|
|
1077
|
+
{ lat: t.lat, lng: t.lng },
|
|
1078
|
+
t.etd,
|
|
1079
|
+
m,
|
|
1080
|
+
e,
|
|
1081
1081
|
c,
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1082
|
+
y,
|
|
1083
|
+
h,
|
|
1084
|
+
t.meteoVendor,
|
|
1085
|
+
t.speedStep,
|
|
1086
|
+
t.useMeteo,
|
|
1087
|
+
t.useRouteParam,
|
|
1088
1088
|
o
|
|
1089
1089
|
);
|
|
1090
|
-
u && (await O.calculateCost(u, c,
|
|
1090
|
+
u && (await O.calculateCost(u, c, t, o), s.push(u), F == null || F.info("[%s][L%d-%d] analyse from %s to %s cost: %j", o.requestId, 1, M, t.etd, m.format(), {
|
|
1091
1091
|
cost: u.cost.total,
|
|
1092
1092
|
hire: u.cost.hire,
|
|
1093
1093
|
bunker: u.cost.bunker,
|
|
@@ -1096,23 +1096,23 @@ class O {
|
|
|
1096
1096
|
cp: `${c.speed}/${c.fo}/${c.dgo}`
|
|
1097
1097
|
})), M++;
|
|
1098
1098
|
}
|
|
1099
|
-
s.sort((c,
|
|
1100
|
-
const
|
|
1101
|
-
if (
|
|
1102
|
-
const c =
|
|
1099
|
+
s.sort((c, y) => c.cost.total - y.cost.total);
|
|
1100
|
+
const l = s.at(0), g = s.at(1), f = [];
|
|
1101
|
+
if (f.push({ combined: !1, speeds: [l], cost: (v = l.cost) == null ? void 0 : v.total }), g) {
|
|
1102
|
+
const c = l.cost.cp, y = g.cost.cp, h = b(l.eta), u = b(l.etd), I = h.diff(u, "days", !0);
|
|
1103
1103
|
let k = Math.ceil(I / 2);
|
|
1104
|
-
k = k > 7 ? 7 : k <
|
|
1105
|
-
let D = 2, Y = { combined: !1, speeds: [
|
|
1106
|
-
for (; k >=
|
|
1107
|
-
const P = await O.combinedAnalyse(
|
|
1108
|
-
if (Y.cost > P.cost ? j ? (j == null ? void 0 : j.cost) > P.cost && (j = P) : (j = Y, Y = P) : (!j || (j == null ? void 0 : j.cost) > P.cost) && (j = P), k <=
|
|
1104
|
+
k = k > 7 ? 7 : k < t.alterStep ? t.alterStep : k;
|
|
1105
|
+
let D = 2, Y = { combined: !1, speeds: [g], cost: (p = g.cost) == null ? void 0 : p.total }, j;
|
|
1106
|
+
for (; k >= t.alterStep; ) {
|
|
1107
|
+
const P = await O.combinedAnalyse(t, e, m, [c, y], i, k, { ...o, level: D });
|
|
1108
|
+
if (Y.cost > P.cost ? j ? (j == null ? void 0 : j.cost) > P.cost && (j = P) : (j = Y, Y = P) : (!j || (j == null ? void 0 : j.cost) > P.cost) && (j = P), k <= t.alterStep)
|
|
1109
1109
|
break;
|
|
1110
1110
|
k = Math.ceil(k / 2), D += 1;
|
|
1111
1111
|
}
|
|
1112
|
-
|
|
1112
|
+
f.push(Y), j && f.push(j);
|
|
1113
1113
|
}
|
|
1114
|
-
const S =
|
|
1115
|
-
return F == null || F.info("[%s] analyse elapsed: %d ms", o == null ? void 0 : o.requestId, S),
|
|
1114
|
+
const S = b().valueOf() - a;
|
|
1115
|
+
return F == null || F.info("[%s] analyse elapsed: %d ms", o == null ? void 0 : o.requestId, S), f.sort((c, y) => c.cost - y.cost);
|
|
1116
1116
|
}
|
|
1117
1117
|
/**
|
|
1118
1118
|
* 按步长多次减半,分别用7,4,2,1天步长及cpa,cpb交替计算各种组合下的成本
|
|
@@ -1124,24 +1124,24 @@ class O {
|
|
|
1124
1124
|
* @param step 步长,7,4,2,1
|
|
1125
1125
|
* @param options
|
|
1126
1126
|
*/
|
|
1127
|
-
static async combinedAnalyse(
|
|
1127
|
+
static async combinedAnalyse(t, e, n, i, o, a, s = {}) {
|
|
1128
1128
|
s.counter = 1, F == null || F.info("[%s][L%d] analyse with alternate cp in every %d days", s.requestId, s.level, a);
|
|
1129
|
-
const d = await O.alternateAnalyse(
|
|
1129
|
+
const d = await O.alternateAnalyse(t, e, n, i, 0, o, a, s), r = d.reduce((y, h) => y + h.cost.total, 0), m = d.reduce((y, h) => y + h.cost.hire, 0), M = d.reduce((y, h) => y + h.cost.bunker, 0), l = d.reduce((y, h) => y + h.distance, 0), g = d.reduce((y, h) => y + h.totalHrs, 0);
|
|
1130
1130
|
F == null || F.info("[%s][L%d] cost with cpa/cpb turn: %j", s.requestId, s.level, {
|
|
1131
1131
|
cost: r,
|
|
1132
|
-
hire:
|
|
1132
|
+
hire: m,
|
|
1133
1133
|
bunker: M,
|
|
1134
|
-
distance:
|
|
1135
|
-
hours:
|
|
1134
|
+
distance: l,
|
|
1135
|
+
hours: g
|
|
1136
1136
|
});
|
|
1137
|
-
const
|
|
1137
|
+
const f = await O.alternateAnalyse(t, e, n, i, 1, o, a, s), C = f.reduce((y, h) => y + h.cost.total, 0), S = f.reduce((y, h) => y + h.cost.hire, 0), v = f.reduce((y, h) => y + h.cost.bunker, 0), p = f.reduce((y, h) => y + h.distance, 0), c = f.reduce((y, h) => y + h.totalHrs, 0);
|
|
1138
1138
|
return F == null || F.info("[%s][L%d] cost with cpb/cpa turn: %j", s.requestId, s.level, {
|
|
1139
1139
|
cost: C,
|
|
1140
1140
|
hire: S,
|
|
1141
|
-
bunker:
|
|
1142
|
-
distance:
|
|
1141
|
+
bunker: v,
|
|
1142
|
+
distance: p,
|
|
1143
1143
|
hours: c
|
|
1144
|
-
}), r < C ? { combined: !0, cost: Math.round(r * 1e3) / 1e3, speeds: d, step: a } : { combined: !0, cost: Math.round(C * 1e3) / 1e3, speeds:
|
|
1144
|
+
}), r < C ? { combined: !0, cost: Math.round(r * 1e3) / 1e3, speeds: d, step: a } : { combined: !0, cost: Math.round(C * 1e3) / 1e3, speeds: f, step: a };
|
|
1145
1145
|
}
|
|
1146
1146
|
/**
|
|
1147
1147
|
* 基于cp索引,交替计算指定步长下的成本
|
|
@@ -1154,44 +1154,44 @@ class O {
|
|
|
1154
1154
|
* @param step 步长,7,4,2,1
|
|
1155
1155
|
* @param options
|
|
1156
1156
|
*/
|
|
1157
|
-
static async alternateAnalyse(
|
|
1158
|
-
var
|
|
1159
|
-
let r =
|
|
1160
|
-
const
|
|
1157
|
+
static async alternateAnalyse(t, e, n, i, o, a, s, d = {}) {
|
|
1158
|
+
var l, g;
|
|
1159
|
+
let r = b.utc(t.etd);
|
|
1160
|
+
const m = { lat: t.lat, lng: t.lng }, M = [];
|
|
1161
1161
|
for (; r.isBefore(n); ) {
|
|
1162
|
-
const
|
|
1163
|
-
h,
|
|
1164
|
-
r.utc().format(),
|
|
1162
|
+
const f = r.clone().utc().add(s, "day"), C = JSON.parse(JSON.stringify(a.route)), S = JSON.parse(JSON.stringify(a.waypoints)), v = i[o], p = await O.analyseInstantWithThreshed(
|
|
1165
1163
|
m,
|
|
1166
|
-
|
|
1167
|
-
|
|
1164
|
+
r.utc().format(),
|
|
1165
|
+
f,
|
|
1166
|
+
e,
|
|
1167
|
+
v,
|
|
1168
1168
|
C,
|
|
1169
1169
|
S,
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1170
|
+
t.meteoVendor,
|
|
1171
|
+
t.speedStep,
|
|
1172
|
+
t.useMeteo,
|
|
1173
|
+
t.useRouteParam,
|
|
1174
1174
|
d
|
|
1175
1175
|
);
|
|
1176
|
-
|
|
1176
|
+
p && (await O.calculateCost(p, v, t, d), F == null || F.info(
|
|
1177
1177
|
"[%s][L%d-%d] analyse from %s to %s cost: %j",
|
|
1178
1178
|
d.requestId,
|
|
1179
1179
|
d.level,
|
|
1180
1180
|
d.counter,
|
|
1181
1181
|
r.utc().format(),
|
|
1182
|
-
|
|
1182
|
+
f.utc().format(),
|
|
1183
1183
|
{
|
|
1184
|
-
cost:
|
|
1185
|
-
hire:
|
|
1186
|
-
bunker:
|
|
1187
|
-
distance:
|
|
1188
|
-
hours:
|
|
1189
|
-
cp: `${
|
|
1184
|
+
cost: p.cost.total,
|
|
1185
|
+
hire: p.cost.hire,
|
|
1186
|
+
bunker: p.cost.bunker,
|
|
1187
|
+
distance: p.distance,
|
|
1188
|
+
hours: p.totalHrs,
|
|
1189
|
+
cp: `${v.speed}/${v.fo}/${v.dgo}`
|
|
1190
1190
|
}
|
|
1191
1191
|
)), d.counter = d.counter + 1;
|
|
1192
|
-
const c = (
|
|
1192
|
+
const c = (g = (l = p == null ? void 0 : p.sample) == null ? void 0 : l.hours) == null ? void 0 : g.at(-1);
|
|
1193
1193
|
if (c)
|
|
1194
|
-
|
|
1194
|
+
m.lat = c.lat, m.lng = c.lng, r = b(c.eta), M.push(p), o = o ? 0 : 1;
|
|
1195
1195
|
else
|
|
1196
1196
|
break;
|
|
1197
1197
|
}
|
|
@@ -1204,33 +1204,33 @@ class O {
|
|
|
1204
1204
|
* @param props
|
|
1205
1205
|
* @param options
|
|
1206
1206
|
*/
|
|
1207
|
-
static async calculateCost(
|
|
1207
|
+
static async calculateCost(t, e, n, i = {}) {
|
|
1208
1208
|
var o;
|
|
1209
|
-
if (
|
|
1210
|
-
const a = Math.round(
|
|
1211
|
-
|
|
1209
|
+
if (t) {
|
|
1210
|
+
const a = Math.round(t.totalHrs / 24 * (n.dailyHire || 0) * (1 - (n.addComm || 0)) * 1e3) / 1e3, s = Math.round(t.totalFoCons * (n.priceFO || 0) * 1e3) / 1e3, d = Math.round((t.totalDgoCons + (((o = t.extend) == null ? void 0 : o.totalDgoConsInECA) || 0)) * (n.priceDGO || 0) * 1e3) / 1e3;
|
|
1211
|
+
t.cost = {
|
|
1212
1212
|
total: Math.round((a + s + d) * 1e3) / 1e3,
|
|
1213
1213
|
hire: a,
|
|
1214
1214
|
bunker: Math.round((s + d) * 1e3) / 1e3,
|
|
1215
|
-
cp:
|
|
1215
|
+
cp: e
|
|
1216
1216
|
};
|
|
1217
1217
|
}
|
|
1218
|
-
return
|
|
1218
|
+
return t;
|
|
1219
1219
|
}
|
|
1220
1220
|
/**
|
|
1221
1221
|
* 计算单cp模式下的ECA属性
|
|
1222
1222
|
*/
|
|
1223
|
-
static async calculateECA(
|
|
1224
|
-
var d, r;
|
|
1225
|
-
const i = await W.intersectInECA(
|
|
1223
|
+
static async calculateECA(t, e, n = {}) {
|
|
1224
|
+
var d, r, m, M;
|
|
1225
|
+
const i = await W.intersectInECA((t == null ? void 0 : t.route) || []);
|
|
1226
1226
|
let o = 0, a = 0, s = 0;
|
|
1227
|
-
|
|
1228
|
-
|
|
1227
|
+
(r = (d = t == null ? void 0 : t.sample) == null ? void 0 : d.wps) == null || r.forEach((l) => {
|
|
1228
|
+
l.positionTime = b.utc(l.etd || l.eta).unix();
|
|
1229
1229
|
});
|
|
1230
|
-
for (const
|
|
1231
|
-
o +=
|
|
1232
|
-
const
|
|
1233
|
-
|
|
1230
|
+
for (const l of i) {
|
|
1231
|
+
o += l.distance;
|
|
1232
|
+
const g = await W.deadReckoningTime((m = l.waypoints) == null ? void 0 : m.at(0), t.sample.wps), f = await W.deadReckoningTime((M = l.waypoints) == null ? void 0 : M.at(-1), t.sample.wps);
|
|
1233
|
+
l.in = g, l.out = f, l.totalHrs = J.roundPrecision((f.positionTime - g.positionTime) / 3600, 2), l.totalDgoCons = J.roundPrecision(e.fo / 24 * l.totalHrs, 3), a += l.totalHrs, s += l.totalDgoCons;
|
|
1234
1234
|
}
|
|
1235
1235
|
return o = J.roundPrecision(o, 3), a = J.roundPrecision(a, 3), s = J.roundPrecision(s, 3), {
|
|
1236
1236
|
distanceInECA: o,
|
|
@@ -1244,34 +1244,34 @@ class O {
|
|
|
1244
1244
|
* @param speeds
|
|
1245
1245
|
* @param options
|
|
1246
1246
|
*/
|
|
1247
|
-
static async mergeSpeeds(
|
|
1248
|
-
var c,
|
|
1247
|
+
static async mergeSpeeds(t, e = {}) {
|
|
1248
|
+
var c, y;
|
|
1249
1249
|
const n = {
|
|
1250
1250
|
hours: [],
|
|
1251
1251
|
wps: [],
|
|
1252
1252
|
days: []
|
|
1253
|
-
}, i =
|
|
1253
|
+
}, i = t.reduce((h, u) => h + u.distance, 0), o = t.reduce((h, u) => {
|
|
1254
1254
|
var I;
|
|
1255
|
-
return
|
|
1256
|
-
}, 0), a =
|
|
1255
|
+
return h + (((I = u.extend) == null ? void 0 : I.distanceInECA) || 0);
|
|
1256
|
+
}, 0), a = t.reduce((h, u) => h + u.totalHrs, 0), s = t.reduce((h, u) => {
|
|
1257
1257
|
var I;
|
|
1258
|
-
return
|
|
1259
|
-
}, 0), d =
|
|
1258
|
+
return h + (((I = u.extend) == null ? void 0 : I.hoursInECA) || 0);
|
|
1259
|
+
}, 0), d = t.reduce((h, u) => {
|
|
1260
1260
|
var I;
|
|
1261
|
-
return
|
|
1262
|
-
}, 0), r =
|
|
1263
|
-
let
|
|
1264
|
-
for (const
|
|
1265
|
-
|
|
1266
|
-
const u =
|
|
1267
|
-
|
|
1268
|
-
N && (T.distanceFromStart = T.distanceFromStart +
|
|
1269
|
-
}), I.at(0).distanceFromPrevious =
|
|
1270
|
-
N && (T.distanceFromStart = T.distanceFromStart +
|
|
1271
|
-
}), k.at(0).distanceFromPrevious =
|
|
1272
|
-
N && (T.distanceFromStart = T.distanceFromStart +
|
|
1273
|
-
})), D.cp =
|
|
1274
|
-
const Y = [
|
|
1261
|
+
return h + (((I = u.extend) == null ? void 0 : I.totalDgoConsInECA) || 0);
|
|
1262
|
+
}, 0), r = t.reduce((h, u) => h + u.wxFactor * u.totalHrs / a, 0), m = t.reduce((h, u) => h + u.cFactor * u.totalHrs / a, 0), M = t.reduce((h, u) => h + u.totalFoCons, 0), l = t.reduce((h, u) => h + u.totalDgoCons, 0), g = t.reduce((h, u) => h + u.cost.total, 0), f = t.reduce((h, u) => h + u.cost.hire, 0), C = t.reduce((h, u) => h + u.cost.bunker, 0), S = [], v = [];
|
|
1263
|
+
let p;
|
|
1264
|
+
for (const h of t) {
|
|
1265
|
+
v.push(...((c = h.extend) == null ? void 0 : c.eca) || []);
|
|
1266
|
+
const u = h.sample.hours, I = h.sample.wps, k = h.sample.days, D = u.at(0);
|
|
1267
|
+
p && (D.distanceFromPrevious = p.distanceFromPrevious, D.distanceFromStart = p.distanceFromStart, u.forEach((T, N) => {
|
|
1268
|
+
N && (T.distanceFromStart = T.distanceFromStart + p.distanceFromStart);
|
|
1269
|
+
}), I.at(0).distanceFromPrevious = p.distanceFromPrevious, I.at(0).distanceFromStart = p.distanceFromStart, I.forEach((T, N) => {
|
|
1270
|
+
N && (T.distanceFromStart = T.distanceFromStart + p.distanceFromStart);
|
|
1271
|
+
}), k.at(0).distanceFromPrevious = p.distanceFromPrevious, k.at(0).distanceFromStart = p.distanceFromStart, k.forEach((T, N) => {
|
|
1272
|
+
N && (T.distanceFromStart = T.distanceFromStart + p.distanceFromStart);
|
|
1273
|
+
})), D.cp = h.cost.cp;
|
|
1274
|
+
const Y = [h.etd, h.eta], j = S.findIndex((T) => T.id === D.cp.id);
|
|
1275
1275
|
j === -1 ? (D.cp.segment = [Y], S.push(D.cp)) : S[j].segment.push(Y), u.forEach((T) => {
|
|
1276
1276
|
var A;
|
|
1277
1277
|
((A = n.hours) == null ? void 0 : A.findIndex((R) => R.eta === T.eta)) === -1 && n.hours.push(T);
|
|
@@ -1282,46 +1282,46 @@ class O {
|
|
|
1282
1282
|
var A;
|
|
1283
1283
|
((A = n == null ? void 0 : n.days) == null ? void 0 : A.findIndex((R) => R.eta === T.eta)) === -1 && n.days.push(T);
|
|
1284
1284
|
});
|
|
1285
|
-
const P = (
|
|
1286
|
-
P === -1 ? n.wps.push(D) : n.wps[P] = D,
|
|
1285
|
+
const P = (y = n.wps) == null ? void 0 : y.findIndex((T) => T.eta === D.eta);
|
|
1286
|
+
P === -1 ? n.wps.push(D) : n.wps[P] = D, p = u.at(-1);
|
|
1287
1287
|
}
|
|
1288
|
-
return n.wps.sort((
|
|
1289
|
-
|
|
1290
|
-
}), n.wps.forEach((
|
|
1288
|
+
return n.wps.sort((h, u) => {
|
|
1289
|
+
b(h.etd).unix() - b(u.etd).unix();
|
|
1290
|
+
}), n.wps.forEach((h, u) => {
|
|
1291
1291
|
const I = n.wps[u - 1];
|
|
1292
1292
|
if (I) {
|
|
1293
|
-
const k =
|
|
1294
|
-
|
|
1295
|
-
const j = W.calculateBearing(I,
|
|
1293
|
+
const k = h.distanceFromStart - (I.distanceFromStart || 0), D = b(h.eta || h.etd).diff(b(I.etd || I.eta), "hour", !0), Y = Math.round(k / D * 100) / 100;
|
|
1294
|
+
h.avgSpd = Y;
|
|
1295
|
+
const j = W.calculateBearing(I, h);
|
|
1296
1296
|
I.bearing = j;
|
|
1297
1297
|
}
|
|
1298
1298
|
}), {
|
|
1299
1299
|
sample: n,
|
|
1300
|
-
etd:
|
|
1301
|
-
eta:
|
|
1302
|
-
from:
|
|
1303
|
-
to:
|
|
1304
|
-
v0:
|
|
1300
|
+
etd: t.at(0).etd,
|
|
1301
|
+
eta: t.at(-1).eta,
|
|
1302
|
+
from: t.at(0).from,
|
|
1303
|
+
to: t.at(-1).to,
|
|
1304
|
+
v0: t.at(0).v0,
|
|
1305
1305
|
label: "Combined",
|
|
1306
1306
|
distance: Math.round(i * 1e4) / 1e4,
|
|
1307
1307
|
totalHrs: Math.round(a * 1e3) / 1e3,
|
|
1308
1308
|
avgSpeed: Math.round(i / a * 1e3) / 1e3,
|
|
1309
1309
|
wxFactor: Math.round(r * 1e3) / 1e3,
|
|
1310
|
-
cFactor: Math.round(
|
|
1310
|
+
cFactor: Math.round(m * 1e3) / 1e3,
|
|
1311
1311
|
totalFoCons: Math.round(M * 1e3) / 1e3,
|
|
1312
|
-
totalDgoCons: Math.round(
|
|
1312
|
+
totalDgoCons: Math.round(l * 1e3) / 1e3,
|
|
1313
1313
|
cost: {
|
|
1314
|
-
total: Math.round(
|
|
1315
|
-
hire: Math.round(
|
|
1314
|
+
total: Math.round(g * 1e3) / 1e3,
|
|
1315
|
+
hire: Math.round(f * 1e3) / 1e3,
|
|
1316
1316
|
bunker: Math.round(C * 1e3) / 1e3
|
|
1317
1317
|
},
|
|
1318
1318
|
extend: {
|
|
1319
1319
|
cps: S,
|
|
1320
|
-
eca:
|
|
1320
|
+
eca: v,
|
|
1321
1321
|
distanceInECA: Math.round(o * 1e4) / 1e4,
|
|
1322
1322
|
hoursInECA: Math.round(s * 1e3) / 1e3,
|
|
1323
1323
|
totalDgoConsInECA: Math.round(d * 1e3) / 1e3,
|
|
1324
|
-
speeds:
|
|
1324
|
+
speeds: t
|
|
1325
1325
|
}
|
|
1326
1326
|
};
|
|
1327
1327
|
}
|