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