@idm-plugin/vessel 3.4.1 → 3.4.2

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 CHANGED
@@ -1,19 +1,19 @@
1
1
  var ht = Object.defineProperty;
2
2
  var lt = (E, s, t) => s in E ? ht(E, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : E[s] = t;
3
3
  var U = (E, s, t) => (lt(E, typeof s != "symbol" ? s + "" : s, t), t);
4
- import V from "got";
4
+ import B from "got";
5
5
  import ct from "@log4js-node/log4js-api";
6
- import p from "moment";
7
- import { LngLatHelper as z, LaneHelper as W } from "@idm-plugin/geo2";
6
+ import v from "moment";
7
+ import { LngLatHelper as z, LaneHelper as V } from "@idm-plugin/geo2";
8
8
  import { MeteoHelper2 as mt } from "@idm-plugin/meteo2";
9
- import { Meteo2Assist as it } from "@idm-plugin/meteo";
10
- let f;
9
+ import { Meteo2Assist as rt } from "@idm-plugin/meteo";
10
+ let y;
11
11
  try {
12
- f = ct.getLogger("vessel");
12
+ y = ct.getLogger("vessel");
13
13
  } catch {
14
14
  } finally {
15
15
  }
16
- class st {
16
+ class at {
17
17
  /**
18
18
  * 解析AIS状态码
19
19
  * @param status
@@ -54,7 +54,7 @@ class st {
54
54
  return { labelCn: t, labelEn: a };
55
55
  }
56
56
  }
57
- class Ft extends st {
57
+ class Tt extends at {
58
58
  constructor(t, a) {
59
59
  super();
60
60
  U(this, "clientId");
@@ -69,19 +69,19 @@ class Ft extends st {
69
69
  client_secret: this.clientSecret,
70
70
  grant_type: "client_credentials"
71
71
  }
72
- }, n = await V.post(a, i).json();
73
- f == null || f.info("[%s] fetch access token from: %s - %j", t.requestId, a, n), n.error || (this.token = {
72
+ }, n = await B.post(a, i).json();
73
+ y == null || y.info("[%s] fetch access token from: %s - %j", t.requestId, a, n), n.error || (this.token = {
74
74
  accessToken: n.access_token,
75
75
  tokenType: n.token_type,
76
76
  expiresIn: n.expires_in,
77
77
  scope: n.scope,
78
78
  jti: n.jti,
79
- issuedAt: p().utc().format()
79
+ issuedAt: v().utc().format()
80
80
  });
81
81
  }
82
82
  async checkToken(t = {}) {
83
83
  var a;
84
- return (!this.token || p().diff(p(this.token.issuedAt), "seconds") > (((a = this.token) == null ? void 0 : a.expiresIn) || 0) - 300) && await this.authToken(t), this.token;
84
+ return (!this.token || v().diff(v(this.token.issuedAt), "seconds") > (((a = this.token) == null ? void 0 : a.expiresIn) || 0) - 300) && await this.authToken(t), this.token;
85
85
  }
86
86
  /**
87
87
  * 模糊查询
@@ -89,20 +89,20 @@ class Ft extends st {
89
89
  * @param options
90
90
  */
91
91
  async suggest(t, a = {}) {
92
- var e, c;
92
+ var e, r;
93
93
  await this.checkToken(a);
94
94
  const i = "https://market.myvessel.cn/sdc/v1/mkt/vessels/fuzzy", n = {
95
95
  headers: {
96
- Authorization: `${(e = this.token) == null ? void 0 : e.tokenType} ${(c = this.token) == null ? void 0 : c.accessToken}`
96
+ Authorization: `${(e = this.token) == null ? void 0 : e.tokenType} ${(r = this.token) == null ? void 0 : r.accessToken}`
97
97
  },
98
98
  json: {
99
99
  kw: t,
100
100
  recordNum: a.ps || 10
101
101
  }
102
102
  };
103
- f == null || f.info("[%s] fetch suggest vessels from: %s - %j", a.requestId, i, n);
104
- const o = await V.post(i, n).json();
105
- return o.status !== 200 ? (f == null || f.warn("[%s] fetch suggest vessels failed: %j", a.requestId, { message: o.message, status: o.status, code: o.code }), []) : (o.data || []).map((h) => ({
103
+ y == null || y.info("[%s] fetch suggest vessels from: %s - %j", a.requestId, i, n);
104
+ const o = await B.post(i, n).json();
105
+ return o.status !== 200 ? (y == null || y.warn("[%s] fetch suggest vessels failed: %j", a.requestId, { message: o.message, status: o.status, code: o.code }), []) : (o.data || []).map((h) => ({
106
106
  mmsi: h.mmsi,
107
107
  name: h.nameEn,
108
108
  nameCn: h.nameCn,
@@ -120,80 +120,80 @@ class Ft extends st {
120
120
  * @param options
121
121
  */
122
122
  async search(t, a = {}) {
123
- var u, h;
123
+ var d, h;
124
124
  await this.checkToken(a);
125
125
  const i = /^\d{7}$/.test(t.toString()), n = i ? "https://market.myvessel.cn/sdc/v1/mkt/vessels/detail/imo" : "https://market.myvessel.cn/sdc/v1/mkt/vessels/detail/mmsi", o = i ? { imo: t } : { mmsi: t }, e = {
126
126
  headers: {
127
- Authorization: `${(u = this.token) == null ? void 0 : u.tokenType} ${(h = this.token) == null ? void 0 : h.accessToken}`
127
+ Authorization: `${(d = this.token) == null ? void 0 : d.tokenType} ${(h = this.token) == null ? void 0 : h.accessToken}`
128
128
  },
129
129
  searchParams: o
130
130
  };
131
- f == null || f.info("[%s] fetch vessel from: %s - %j", a.requestId, n, e);
132
- const c = await V.get(n, e).json();
133
- if (c.status !== 200)
134
- return f == null || f.warn("[%s] fetch suggest vessels failed: %j", a.requestId, { message: c.message, status: c.status, code: c.code }), {};
131
+ y == null || y.info("[%s] fetch vessel from: %s - %j", a.requestId, n, e);
132
+ const r = await B.get(n, e).json();
133
+ if (r.status !== 200)
134
+ return y == null || y.warn("[%s] fetch suggest vessels failed: %j", a.requestId, { message: r.message, status: r.status, code: r.code }), {};
135
135
  {
136
- const d = c.data;
137
- if (d)
136
+ const c = r.data;
137
+ if (c)
138
138
  return {
139
- mmsi: d.mmsi,
140
- imo: Number.isNaN(d.imo) ? null : Number(d.imo),
141
- callSign: d.callsign,
142
- name: d.nameEn,
143
- nameCn: d.nameCn,
144
- type: d.vesselTypeNameEn,
145
- flagName: d.flagCtry,
146
- clasz: d.classSociety,
147
- dateOfBuild: d.buildYearMonth,
148
- deadweight: d.dwt,
149
- grossTonnage: d.grt,
150
- netTonnage: d.net,
151
- teu: d.teu,
152
- length: d.length,
153
- breadth: d.width,
154
- height: d.height,
155
- draught: d.draught,
156
- speed: d.speed,
157
- passengerCapacity: d.passengercapacity,
139
+ mmsi: c.mmsi,
140
+ imo: Number.isNaN(c.imo) ? null : Number(c.imo),
141
+ callSign: c.callsign,
142
+ name: c.nameEn,
143
+ nameCn: c.nameCn,
144
+ type: c.vesselTypeNameEn,
145
+ flagName: c.flagCtry,
146
+ clasz: c.classSociety,
147
+ dateOfBuild: c.buildYearMonth,
148
+ deadweight: c.dwt,
149
+ grossTonnage: c.grt,
150
+ netTonnage: c.net,
151
+ teu: c.teu,
152
+ length: c.length,
153
+ breadth: c.width,
154
+ height: c.height,
155
+ draught: c.draught,
156
+ speed: c.speed,
157
+ passengerCapacity: c.passengercapacity,
158
158
  vendor: "myvessel",
159
- raw: d
159
+ raw: c
160
160
  };
161
161
  }
162
162
  return {};
163
163
  }
164
164
  async archives(t, a = {}) {
165
- var e, c;
165
+ var e, r;
166
166
  await this.checkToken(a);
167
167
  const i = "https://svc.data.myvessel.cn/sdc/v1/ship/info/batch", n = {
168
168
  headers: {
169
- Authorization: `${(e = this.token) == null ? void 0 : e.tokenType} ${(c = this.token) == null ? void 0 : c.accessToken}`
169
+ Authorization: `${(e = this.token) == null ? void 0 : e.tokenType} ${(r = this.token) == null ? void 0 : r.accessToken}`
170
170
  },
171
171
  json: {
172
172
  mmsiList: typeof t == "number" ? [t] : t
173
173
  }
174
174
  };
175
- f == null || f.info("[%s] fetch vessel archive from: %s - %j", a.requestId, i, n);
176
- const o = await V.post(i, n).json();
177
- return o.status !== 200 ? (f == null || f.warn("[%s] fetch vessel archive failed: %j", a.requestId, { message: o.message, status: o.status, code: o.code }), {}) : o.data;
175
+ y == null || y.info("[%s] fetch vessel archive from: %s - %j", a.requestId, i, n);
176
+ const o = await B.post(i, n).json();
177
+ return o.status !== 200 ? (y == null || y.warn("[%s] fetch vessel archive failed: %j", a.requestId, { message: o.message, status: o.status, code: o.code }), {}) : o.data;
178
178
  }
179
179
  async realTimePosition(t, a = {}) {
180
- var c, u;
180
+ var r, d;
181
181
  await this.checkToken(a);
182
182
  const i = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit", n = {
183
183
  headers: {
184
- Authorization: `${(c = this.token) == null ? void 0 : c.tokenType} ${(u = this.token) == null ? void 0 : u.accessToken}`
184
+ Authorization: `${(r = this.token) == null ? void 0 : r.tokenType} ${(d = this.token) == null ? void 0 : d.accessToken}`
185
185
  },
186
186
  searchParams: { mmsi: t }
187
187
  };
188
- f == null || f.info("[%s] fetch realtime position from: %s - %j", a.requestId, i, n);
189
- const o = await V.get(i, n).json();
188
+ y == null || y.info("[%s] fetch realtime position from: %s - %j", a.requestId, i, n);
189
+ const o = await B.get(i, n).json();
190
190
  if (o.code)
191
- return f == null || f.warn("[%s] fetch realtime position failed: %j", a.requestId, { message: o.message, status: o.status, code: o.code }), o;
191
+ return y == null || y.warn("[%s] fetch realtime position failed: %j", a.requestId, { message: o.message, status: o.status, code: o.code }), o;
192
192
  const e = o.data;
193
193
  for (const h in e)
194
194
  !isNaN(e[h]) && Number(e[h]) !== 1 / 0 && (e[h] = Number(e[h]));
195
195
  if (e) {
196
- const h = p(`${e.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
196
+ const h = v(`${e.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
197
197
  return {
198
198
  mmsi: e.mmsi,
199
199
  name: e.vesselName || e.aisVesselName,
@@ -208,7 +208,7 @@ class Ft extends st {
208
208
  cog: e.cog,
209
209
  hdg: e.hdg,
210
210
  rot: e.rot,
211
- eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta) ? p.utc(e.eta).format() : void 0,
211
+ eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta) ? v.utc(e.eta).format() : void 0,
212
212
  destination: e.dest,
213
213
  positionTime: h.unix(),
214
214
  status: e.status,
@@ -229,11 +229,11 @@ class Ft extends st {
229
229
  return {};
230
230
  }
231
231
  async calculateRoute(t, a, i = {}) {
232
- var c, u;
232
+ var r, d;
233
233
  await this.checkToken(i);
234
234
  const n = "https://svc.data.myvessel.cn/sdc/v1/routes/routing/nodes", o = {
235
235
  headers: {
236
- Authorization: `${(c = this.token) == null ? void 0 : c.tokenType} ${(u = this.token) == null ? void 0 : u.accessToken}`
236
+ Authorization: `${(r = this.token) == null ? void 0 : r.tokenType} ${(d = this.token) == null ? void 0 : d.accessToken}`
237
237
  },
238
238
  json: {
239
239
  startPoint: {
@@ -249,22 +249,22 @@ class Ft extends st {
249
249
  withECA: i.withECA || !1
250
250
  }
251
251
  };
252
- f == null || f.info("[%s] fetch route from: %s - %j", i.requestId, n, o);
253
- const e = await V.post(n, o).json();
254
- return e.status !== 200 ? (f == null || f.warn("[%s] fetch route failed: %j", i.requestId, { message: e.message, status: e.status, code: e.code }), {}) : e.data;
252
+ y == null || y.info("[%s] fetch route from: %s - %j", i.requestId, n, o);
253
+ const e = await B.post(n, o).json();
254
+ return e.status !== 200 ? (y == null || y.warn("[%s] fetch route failed: %j", i.requestId, { message: e.message, status: e.status, code: e.code }), {}) : e.data;
255
255
  }
256
256
  async trajectory(t, a, i, n, o = !0, e = {}) {
257
257
  await this.checkToken(e);
258
- const c = await this.realTimePosition(t, e), u = p(a), h = p(i), d = [];
259
- for (; h.diff(u, "day", !0) > 30; )
260
- await this.trajectoryIn30Day(t, u, u.clone().add(30, "day"), c, n, d, e), u.add(30, "day");
261
- return await this.trajectoryIn30Day(t, u, h, c, n, d, e), d;
258
+ const r = await this.realTimePosition(t, e), d = v(a), h = v(i), c = [];
259
+ for (; h.diff(d, "day", !0) > 30; )
260
+ await this.trajectoryIn30Day(t, d, d.clone().add(30, "day"), r, n, c, e), d.add(30, "day");
261
+ return await this.trajectoryIn30Day(t, d, h, r, n, c, e), c;
262
262
  }
263
- async trajectoryIn30Day(t, a, i, n, o, e, c = {}) {
264
- var M, j, I, w, g;
265
- const u = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", h = {
263
+ async trajectoryIn30Day(t, a, i, n, o, e, r = {}) {
264
+ var b, j, T, g, p;
265
+ const d = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", h = {
266
266
  headers: {
267
- Authorization: `${(M = this.token) == null ? void 0 : M.tokenType} ${(j = this.token) == null ? void 0 : j.accessToken}`
267
+ Authorization: `${(b = this.token) == null ? void 0 : b.tokenType} ${(j = this.token) == null ? void 0 : j.accessToken}`
268
268
  },
269
269
  json: {
270
270
  mmsi: t,
@@ -272,39 +272,39 @@ class Ft extends st {
272
272
  endTime: i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")
273
273
  }
274
274
  };
275
- f == null || f.info("[%s] fetch trajectory from: %s - %j", c.requestId, u, h);
276
- const d = await V.post(u, h).json();
277
- if (d.code)
278
- return f == null || f.warn("[%s] fetch trajectory failed: %j", c.requestId, u, { message: d.message, status: d.status, code: d.code }), d;
279
- let y = -1;
280
- const v = p(`${(w = (I = d.data) == null ? void 0 : I[0]) == null ? void 0 : w.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
281
- return (g = d.data) == null || g.forEach((r) => {
282
- for (const P in r)
283
- !isNaN(r[P]) && Number(r[P]) !== 1 / 0 && (r[P] = Number(r[P]));
284
- const b = p(`${r.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), m = r.status, { labelCn: l, labelEn: k } = this.parseStatus(m), S = {
285
- mmsi: r.mmsi,
275
+ y == null || y.info("[%s] fetch trajectory from: %s - %j", r.requestId, d, h);
276
+ const c = await B.post(d, h).json();
277
+ if (c.code)
278
+ return y == null || y.warn("[%s] fetch trajectory failed: %j", r.requestId, d, { message: c.message, status: c.status, code: c.code }), c;
279
+ let M = -1;
280
+ const w = v(`${(g = (T = c.data) == null ? void 0 : T[0]) == null ? void 0 : g.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
281
+ return (p = c.data) == null || p.forEach((f) => {
282
+ for (const H in f)
283
+ !isNaN(f[H]) && Number(f[H]) !== 1 / 0 && (f[H] = Number(f[H]));
284
+ const u = v(`${f.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), l = f.status, { labelCn: m, labelEn: I } = this.parseStatus(l), k = {
285
+ mmsi: f.mmsi,
286
286
  imo: n == null ? void 0 : n.imo,
287
- lat: r.lat,
288
- lng: r.lon,
289
- sog: r.sog,
290
- cog: r.cog,
291
- hdg: r.hdg,
292
- draught: r.draught,
293
- status: m,
294
- eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(r.eta) ? p(`${r.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00").utc().format() : void 0,
295
- destination: r.dest,
296
- positionTime: b.unix(),
297
- labelCn: l,
298
- labelEn: k,
287
+ lat: f.lat,
288
+ lng: f.lon,
289
+ sog: f.sog,
290
+ cog: f.cog,
291
+ hdg: f.hdg,
292
+ draught: f.draught,
293
+ status: l,
294
+ eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(f.eta) ? v(`${f.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00").utc().format() : void 0,
295
+ destination: f.dest,
296
+ positionTime: u.unix(),
297
+ labelCn: m,
298
+ labelEn: I,
299
299
  method: "trajectory",
300
300
  vendor: "myVessel",
301
- utc: b.utc().format()
302
- }, D = Math.floor(b.diff(v, "minute", !0) / (o || 1));
303
- D !== y && (y = D, e.push(S));
301
+ utc: u.utc().format()
302
+ }, F = Math.floor(u.diff(w, "minute", !0) / (o || 1));
303
+ F !== M && (M = F, e.push(k));
304
304
  }), e;
305
305
  }
306
306
  }
307
- class Et extends st {
307
+ class Ft extends at {
308
308
  constructor(t) {
309
309
  super();
310
310
  U(this, "token");
@@ -316,15 +316,15 @@ class Et extends st {
316
316
  mmsi: t,
317
317
  usertoken: this.token
318
318
  }
319
- }, o = await V.post(i, n).json();
320
- f == null || f.info("[%s] fetch realtime position from: %s - %j", a.requestId, i, n);
319
+ }, o = await B.post(i, n).json();
320
+ y == null || y.info("[%s] fetch realtime position from: %s - %j", a.requestId, i, n);
321
321
  const e = o == null ? void 0 : o.list;
322
322
  if (!e)
323
- return f == null || f.warn("[%s] fetch realtime position failed: %j", a.requestId, i, o), o;
324
- for (const v in e)
325
- !isNaN(e[v]) && Number(e[v]) !== 1 / 0 && (e[v] = Number(e[v]));
323
+ return y == null || y.warn("[%s] fetch realtime position failed: %j", a.requestId, i, o), o;
324
+ for (const w in e)
325
+ !isNaN(e[w]) && Number(e[w]) !== 1 / 0 && (e[w] = Number(e[w]));
326
326
  e.status = e.sp > 3 ? 0 : 1;
327
- const c = e.status, { labelCn: u, labelEn: h } = this.parseStatus(c), d = p(`${e.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
327
+ const r = e.status, { labelCn: d, labelEn: h } = this.parseStatus(r), c = v(`${e.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
328
328
  return {
329
329
  mmsi: e.m,
330
330
  name: e.n,
@@ -339,16 +339,16 @@ class Et extends st {
339
339
  cog: e.co,
340
340
  hdg: e.h,
341
341
  rot: isNaN(e.rot) ? 0 : e.rot,
342
- eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta) ? p.utc(e.eta).format() : void 0,
342
+ eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(e.eta) ? v.utc(e.eta).format() : void 0,
343
343
  destination: e.destination,
344
344
  vesselType: e.type,
345
345
  dwt: e.dwt,
346
346
  build: e.buildyear,
347
347
  flag: e.fn,
348
- positionTime: d.unix(),
349
- utc: d.utc().format(),
350
- status: c,
351
- labelCn: u,
348
+ positionTime: c.unix(),
349
+ utc: c.utc().format(),
350
+ status: r,
351
+ labelCn: d,
352
352
  labelEn: h,
353
353
  method: "position",
354
354
  vendor: "hifleet"
@@ -366,10 +366,10 @@ class Et extends st {
366
366
  Host: "www.hifleet.com"
367
367
  }
368
368
  };
369
- let o = await V.post(i, n).json();
370
- f == null || f.info("[%s] fetch vessel props from: %s - %j", a.requestId, i, n), o instanceof Array && (o = o[0]);
371
- for (const c in o)
372
- !isNaN(o[c]) && Number(o[c]) !== 1 / 0 && (o[c] = Number(o[c]));
369
+ let o = await B.post(i, n).json();
370
+ y == null || y.info("[%s] fetch vessel props from: %s - %j", a.requestId, i, n), o instanceof Array && (o = o[0]);
371
+ for (const r in o)
372
+ !isNaN(o[r]) && Number(o[r]) !== 1 / 0 && (o[r] = Number(o[r]));
373
373
  const e = {
374
374
  mmsi: o.m,
375
375
  name: o.n,
@@ -380,7 +380,7 @@ class Et extends st {
380
380
  draught: o.dr,
381
381
  type: o.t
382
382
  };
383
- return i = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", o = await V.post(i, n).json(), f == null || f.info("[%s] search vessel dead weight from: %s - %j", a.requestId, i, n), o instanceof Array && (o = o[0]), o && (e.deadweight = Number(o.dwt)), e;
383
+ return i = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", o = await B.post(i, n).json(), y == null || y.info("[%s] search vessel dead weight from: %s - %j", a.requestId, i, n), o instanceof Array && (o = o[0]), o && (e.deadweight = Number(o.dwt)), e;
384
384
  }
385
385
  async suggest(t, a = {}) {
386
386
  const i = "https://www.hifleet.com/hifleetapi/getShipSuggest.do", n = {
@@ -392,71 +392,71 @@ class Et extends st {
392
392
  Origin: "https://www.hifleet.com",
393
393
  Host: "www.hifleet.com"
394
394
  }
395
- }, o = await V.post(i, n).json();
396
- f == null || f.info("[%s] suggest vessel props from: %s - %j", a.requestId, i, n);
395
+ }, o = await B.post(i, n).json();
396
+ y == null || y.info("[%s] suggest vessel props from: %s - %j", a.requestId, i, n);
397
397
  const e = [];
398
- for (const c of o)
398
+ for (const r of o)
399
399
  e.push({
400
- mmsi: !c.mmsi || isNaN(c.mmsi) ? null : Number(c.mmsi),
401
- name: c.name,
402
- callSign: c.callsign,
403
- imo: !c.imo || isNaN(c.imo) ? null : Number(c.imo),
404
- score: c._score
400
+ mmsi: !r.mmsi || isNaN(r.mmsi) ? null : Number(r.mmsi),
401
+ name: r.name,
402
+ callSign: r.callsign,
403
+ imo: !r.imo || isNaN(r.imo) ? null : Number(r.imo),
404
+ score: r._score
405
405
  });
406
- return e.sort((c, u) => u.score - c.score), e;
406
+ return e.sort((r, d) => d.score - r.score), e;
407
407
  }
408
408
  async trajectory(t, a, i, n, o = !0, e = {}) {
409
- var r, b, m;
410
- const c = await this.realTimePosition(t, e);
411
- let u = p(a);
412
- const h = p(i), d = p();
409
+ var f, u, l;
410
+ const r = await this.realTimePosition(t, e);
411
+ let d = v(a);
412
+ const h = v(i), c = v();
413
413
  if (o) {
414
- let l = h.diff(u, "d", !0);
415
- l < 0 ? u = h.clone().subtract(40, "d") : l < 30 ? u.subtract(10, "d") : l < 60 ? u.subtract(5, "d") : u = h.clone().subtract(80, "d"), l = d.diff(h, "d", !0), h.add(l > 10 ? 240 : l * 24, "h");
414
+ let m = h.diff(d, "d", !0);
415
+ m < 0 ? d = h.clone().subtract(40, "d") : m < 30 ? d.subtract(10, "d") : m < 60 ? d.subtract(5, "d") : d = h.clone().subtract(80, "d"), m = c.diff(h, "d", !0), h.add(m > 10 ? 240 : m * 24, "h");
416
416
  }
417
- const y = {
417
+ const M = {
418
418
  searchParams: {
419
419
  endtime: h.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
420
- starttime: u.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
420
+ starttime: d.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
421
421
  mmsi: t,
422
422
  usertoken: this.token
423
423
  }
424
- }, v = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", M = await V.get(v, y).json();
425
- f == null || f.info("[%s] fetch trajectory from: %s - %j", e.requestId, v, y);
424
+ }, w = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", b = await B.get(w, M).json();
425
+ y == null || y.info("[%s] fetch trajectory from: %s - %j", e.requestId, w, M);
426
426
  let j;
427
- M && (j = ((b = (r = M.ships) == null ? void 0 : r.offors) == null ? void 0 : b.ship) || [], j.length || f == null || f.warn("[%s] fetch trajectory failed: %j", e.requestId, M));
428
- const I = [];
429
- let w = -1;
430
- const g = p(`${(m = j == null ? void 0 : j[0]) == null ? void 0 : m.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
431
- for (const l of j) {
432
- for (const A in l)
433
- !isNaN(l[A]) && Number(l[A]) !== 1 / 0 && (l[A] = Number(l[A]));
434
- const k = p(`${l.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
435
- l.status = l.sp > 4 ? 0 : 1;
436
- const { labelEn: S, labelCn: D } = this.parseStatus(l.status), P = {
437
- mmsi: l.m,
438
- name: l.n,
439
- imo: c == null ? void 0 : c.imo,
440
- lat: l.la,
441
- lng: l.lo,
442
- draught: l.draught,
443
- sog: l.sp,
444
- cog: l.co,
445
- hdg: l.hdg,
446
- positionTime: k.unix(),
447
- utc: k.utc().format(),
448
- status: l.status,
449
- labelCn: D,
450
- labelEn: S,
427
+ b && (j = ((u = (f = b.ships) == null ? void 0 : f.offors) == null ? void 0 : u.ship) || [], j.length || y == null || y.warn("[%s] fetch trajectory failed: %j", e.requestId, b));
428
+ const T = [];
429
+ let g = -1;
430
+ const p = v(`${(l = j == null ? void 0 : j[0]) == null ? void 0 : l.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
431
+ for (const m of j) {
432
+ for (const A in m)
433
+ !isNaN(m[A]) && Number(m[A]) !== 1 / 0 && (m[A] = Number(m[A]));
434
+ const I = v(`${m.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
435
+ m.status = m.sp > 4 ? 0 : 1;
436
+ const { labelEn: k, labelCn: F } = this.parseStatus(m.status), H = {
437
+ mmsi: m.m,
438
+ name: m.n,
439
+ imo: r == null ? void 0 : r.imo,
440
+ lat: m.la,
441
+ lng: m.lo,
442
+ draught: m.draught,
443
+ sog: m.sp,
444
+ cog: m.co,
445
+ hdg: m.hdg,
446
+ positionTime: I.unix(),
447
+ utc: I.utc().format(),
448
+ status: m.status,
449
+ labelCn: F,
450
+ labelEn: k,
451
451
  method: "trajectory",
452
452
  vendor: "hifleet"
453
- }, N = Math.floor(k.diff(g, "minute", !0) / (n || 1));
454
- N !== w && (w = N, I.push(P));
453
+ }, x = Math.floor(I.diff(p, "minute", !0) / (n || 1));
454
+ x !== g && (g = x, T.push(H));
455
455
  }
456
- return I;
456
+ return T;
457
457
  }
458
458
  }
459
- class Nt extends st {
459
+ class Et extends at {
460
460
  constructor(t) {
461
461
  super();
462
462
  U(this, "token");
@@ -469,13 +469,13 @@ class Nt extends st {
469
469
  k: this.token,
470
470
  enc: 1
471
471
  }
472
- }, n = "https://api.shipxy.com/apicall/GetSingleShip", o = await V.get(n, i).json();
473
- if (f == null || f.info("[%s] fetch realtime position from: %s - %j", a.requestId, n, i), (o == null ? void 0 : o.status) !== 0)
472
+ }, n = "https://api.shipxy.com/apicall/GetSingleShip", o = await B.get(n, i).json();
473
+ if (y == null || y.info("[%s] fetch realtime position from: %s - %j", a.requestId, n, i), (o == null ? void 0 : o.status) !== 0)
474
474
  return o;
475
475
  const e = o.data[0];
476
- for (const y in e)
477
- !isNaN(e[y]) && Number(e[y]) !== 1 / 0 && (e[y] = Number(e[y]));
478
- const { labelCn: c, labelEn: u } = await this.parseStatus(e.navistat), h = p.unix(e.lasttime);
476
+ for (const M in e)
477
+ !isNaN(e[M]) && Number(e[M]) !== 1 / 0 && (e[M] = Number(e[M]));
478
+ const { labelCn: r, labelEn: d } = await this.parseStatus(e.navistat), h = v.unix(e.lasttime);
479
479
  return {
480
480
  mmsi: e.ShipID,
481
481
  name: e.name,
@@ -493,47 +493,47 @@ class Nt extends st {
493
493
  positionTime: e.lasttime,
494
494
  utc: h.utc().format(),
495
495
  status: e.navistat,
496
- labelEn: u,
497
- labelCn: c,
496
+ labelEn: d,
497
+ labelCn: r,
498
498
  method: "position",
499
499
  vendor: "shipxy"
500
500
  };
501
501
  }
502
502
  async trajectory(t, a, i, n, o = !0, e = {}) {
503
- var g;
504
- const c = await this.realTimePosition(t, e), u = p(a), h = p(i), d = "https://api.shipxy.com/apicall/GetShipTrack", y = {
503
+ var p;
504
+ const r = await this.realTimePosition(t, e), d = v(a), h = v(i), c = "https://api.shipxy.com/apicall/GetShipTrack", M = {
505
505
  searchParams: {
506
506
  id: t,
507
507
  k: this.token,
508
508
  enc: 1,
509
509
  cut: 0,
510
- btm: u.unix(),
510
+ btm: d.unix(),
511
511
  etm: h.unix()
512
512
  }
513
- }, v = await V.get(d, y).json();
514
- if (f == null || f.info("[%s] fetch trajectory from: %s - %j", e.requestId, d, y), (v == null ? void 0 : v.status) !== 0)
515
- return v;
516
- const M = v == null ? void 0 : v.points, j = [], I = p.unix((g = M[0]) == null ? void 0 : g.utc);
517
- let w = -1;
518
- for (const r of M) {
519
- const b = p.unix(r.utc), m = {
520
- imo: c == null ? void 0 : c.imo,
513
+ }, w = await B.get(c, M).json();
514
+ if (y == null || y.info("[%s] fetch trajectory from: %s - %j", e.requestId, c, M), (w == null ? void 0 : w.status) !== 0)
515
+ return w;
516
+ const b = w == null ? void 0 : w.points, j = [], T = v.unix((p = b[0]) == null ? void 0 : p.utc);
517
+ let g = -1;
518
+ for (const f of b) {
519
+ const u = v.unix(f.utc), l = {
520
+ imo: r == null ? void 0 : r.imo,
521
521
  mmsi: t,
522
- sog: Math.round(r.sog * 3600 / 1e3 / 1852 * 100) / 100,
523
- cog: Math.round(r.cog / 100 * 100) / 100,
524
- lat: Math.round(r.lat / 1e6 * 1e5) / 1e5,
525
- lng: Math.round(r.lon / 1e6 * 1e5) / 1e5,
526
- positionTime: b.unix(),
527
- utc: b.utc().format(),
522
+ sog: Math.round(f.sog * 3600 / 1e3 / 1852 * 100) / 100,
523
+ cog: Math.round(f.cog / 100 * 100) / 100,
524
+ lat: Math.round(f.lat / 1e6 * 1e5) / 1e5,
525
+ lng: Math.round(f.lon / 1e6 * 1e5) / 1e5,
526
+ positionTime: u.unix(),
527
+ utc: u.utc().format(),
528
528
  method: "trajectory",
529
529
  vendor: "shipxy"
530
- }, l = Math.floor(b.diff(I, "minute", !0) / (n || 1));
531
- l !== w && (w = l, j.push(m));
530
+ }, m = Math.floor(u.diff(T, "minute", !0) / (n || 1));
531
+ m !== g && (g = m, j.push(l));
532
532
  }
533
533
  return j;
534
534
  }
535
535
  }
536
- class Tt extends st {
536
+ class xt extends at {
537
537
  constructor(t) {
538
538
  super();
539
539
  U(this, "token");
@@ -547,8 +547,8 @@ class Tt extends st {
547
547
  json: {
548
548
  mmsiList: t
549
549
  }
550
- }, n = "https://api3.myships.com/sp/ships/getShipIdByMMSI", o = await V.post(n, i).json();
551
- return f == null || f.info("[%s] fetch ship id from: %s - %j", a.requestId, n, i), o.code !== "0" ? o : o.data[0].shipId;
550
+ }, n = "https://api3.myships.com/sp/ships/getShipIdByMMSI", o = await B.post(n, i).json();
551
+ return y == null || y.info("[%s] fetch ship id from: %s - %j", a.requestId, n, i), o.code !== "0" ? o : o.data[0].shipId;
552
552
  }
553
553
  async getShipInfo(t, a = {}) {
554
554
  const i = {
@@ -558,15 +558,15 @@ class Tt extends st {
558
558
  json: {
559
559
  shipId: t
560
560
  }
561
- }, n = "https://api3.myships.com/sp/ships/aissta", o = await V.post(n, i).json();
562
- if (f == null || f.info("[%s] fetch ship info from: %s - %j", a.requestId, n, i), o.code !== "0")
561
+ }, n = "https://api3.myships.com/sp/ships/aissta", o = await B.post(n, i).json();
562
+ if (y == null || y.info("[%s] fetch ship info from: %s - %j", a.requestId, n, i), o.code !== "0")
563
563
  return o;
564
564
  const e = o.data;
565
- let c = e.imo;
566
- return t === "407170" && (c = "9198379", f == null || f.warn("[%s] ship(%s) imo error: %s, should be %s", a.requestId, t, e.imo, c)), {
565
+ let r = e.imo;
566
+ return t === "407170" && (r = "9198379", y == null || y.warn("[%s] ship(%s) imo error: %s, should be %s", a.requestId, t, e.imo, r)), {
567
567
  mmsi: e.mmsi,
568
568
  name: e.shipnameEn,
569
- imo: c,
569
+ imo: r,
570
570
  callSign: e.callSign,
571
571
  length: e.length,
572
572
  width: e.breadth,
@@ -581,38 +581,38 @@ class Tt extends st {
581
581
  json: {
582
582
  shipId: i
583
583
  }
584
- }, e = "https://api3.myships.com/sp/ships/position/latest", c = await V.post(e, o).json();
585
- f == null || f.info("[%s] fetch realtime position from: %s - %j", a.requestId, e, o);
586
- const u = c.data[0];
587
- for (const M in u)
588
- !isNaN(u[M]) && Number(u[M]) !== 1 / 0 && (u[M] = Number(u[M]));
589
- const { labelCn: h, labelEn: d } = await this.parseStatus(u.aisNavStatus), y = p.unix(u.posTime);
584
+ }, e = "https://api3.myships.com/sp/ships/position/latest", r = await B.post(e, o).json();
585
+ y == null || y.info("[%s] fetch realtime position from: %s - %j", a.requestId, e, o);
586
+ const d = r.data[0];
587
+ for (const b in d)
588
+ !isNaN(d[b]) && Number(d[b]) !== 1 / 0 && (d[b] = Number(d[b]));
589
+ const { labelCn: h, labelEn: c } = await this.parseStatus(d.aisNavStatus), M = v.unix(d.posTime);
590
590
  return {
591
591
  ...n,
592
592
  mmsi: t,
593
- lat: Math.round(u.lat / 1e4 / 60 * 1e5) / 1e5,
594
- lng: Math.round(u.lon / 1e4 / 60 * 1e5) / 1e5,
595
- sog: Math.round(u.sog / 10 * 100) / 100,
596
- cog: Math.round(u.cog / 10 * 100) / 100,
597
- hdg: Math.round(u.heading * 100) / 100,
598
- rot: Math.round(u.rot * 100) / 100,
599
- positionTime: u.posTime,
600
- utc: y.utc().format(),
601
- status: u.aisNavStatus,
602
- labelEn: d,
593
+ lat: Math.round(d.lat / 1e4 / 60 * 1e5) / 1e5,
594
+ lng: Math.round(d.lon / 1e4 / 60 * 1e5) / 1e5,
595
+ sog: Math.round(d.sog / 10 * 100) / 100,
596
+ cog: Math.round(d.cog / 10 * 100) / 100,
597
+ hdg: Math.round(d.heading * 100) / 100,
598
+ rot: Math.round(d.rot * 100) / 100,
599
+ positionTime: d.posTime,
600
+ utc: M.utc().format(),
601
+ status: d.aisNavStatus,
602
+ labelEn: c,
603
603
  labelCn: h,
604
604
  method: "position",
605
605
  vendor: "myship"
606
606
  };
607
607
  }
608
608
  async trajectory(t, a, i, n, o = !0, e = {}) {
609
- const c = p(a), u = p(i), h = await this.getShipId(t), d = await this.getShipInfo(h), y = [];
610
- for (; u.diff(c, "day", !0) > 30; )
611
- await this.trajectoryIn30Day(h, c.unix(), c.add(30, "day").unix(), d, t, n, y);
612
- return await this.trajectoryIn30Day(h, c.unix(), u.unix(), d, t, n, y), y;
609
+ const r = v(a), d = v(i), h = await this.getShipId(t), c = await this.getShipInfo(h), M = [];
610
+ for (; d.diff(r, "day", !0) > 30; )
611
+ await this.trajectoryIn30Day(h, r.unix(), r.add(30, "day").unix(), c, t, n, M);
612
+ return await this.trajectoryIn30Day(h, r.unix(), d.unix(), c, t, n, M), M;
613
613
  }
614
- async trajectoryIn30Day(t, a, i, n, o, e, c, u = {}) {
615
- var I;
614
+ async trajectoryIn30Day(t, a, i, n, o, e, r, d = {}) {
615
+ var T;
616
616
  const h = {
617
617
  headers: {
618
618
  appKey: this.token
@@ -622,32 +622,32 @@ class Tt extends st {
622
622
  startTime: a,
623
623
  endTime: i
624
624
  }
625
- }, d = "https://api3.myships.com/sp/ships/position/history", y = await V.post(d, h).json();
626
- if (f == null || f.info("[%s] fetch trajectory from: %s - %j", u.requestId, d, h), y.code !== "0")
627
- return f == null || f.warn("[%s] invoke myship trajectory failed: %j", u.requestId, y), y;
628
- const v = y.data;
629
- for (const w in v)
630
- !isNaN(v[w]) && Number(v[w]) !== 1 / 0 && (v[w] = Number(v[w]));
631
- const M = p.unix((I = v[0]) == null ? void 0 : I.posTime);
625
+ }, c = "https://api3.myships.com/sp/ships/position/history", M = await B.post(c, h).json();
626
+ if (y == null || y.info("[%s] fetch trajectory from: %s - %j", d.requestId, c, h), M.code !== "0")
627
+ return y == null || y.warn("[%s] invoke myship trajectory failed: %j", d.requestId, M), M;
628
+ const w = M.data;
629
+ for (const g in w)
630
+ !isNaN(w[g]) && Number(w[g]) !== 1 / 0 && (w[g] = Number(w[g]));
631
+ const b = v.unix((T = w[0]) == null ? void 0 : T.posTime);
632
632
  let j = -1;
633
- for (const w of v) {
634
- const g = p.unix(w.posTime), r = {
633
+ for (const g of w) {
634
+ const p = v.unix(g.posTime), f = {
635
635
  imo: n == null ? void 0 : n.imo,
636
636
  mmsi: o,
637
- lat: Math.round(w.lat / 1e4 / 60 * 1e5) / 1e5,
638
- lng: Math.round(w.lon / 1e4 / 60 * 1e5) / 1e5,
639
- sog: Math.round(w.sog / 10 * 100) / 100,
640
- cog: Math.round(w.cog / 10 * 100) / 100,
641
- hdg: Math.round(w.heading * 100) / 100,
642
- rot: Math.round(w.rot * 100) / 100,
643
- positionTime: g.unix(),
644
- utc: g.utc().format(),
637
+ lat: Math.round(g.lat / 1e4 / 60 * 1e5) / 1e5,
638
+ lng: Math.round(g.lon / 1e4 / 60 * 1e5) / 1e5,
639
+ sog: Math.round(g.sog / 10 * 100) / 100,
640
+ cog: Math.round(g.cog / 10 * 100) / 100,
641
+ hdg: Math.round(g.heading * 100) / 100,
642
+ rot: Math.round(g.rot * 100) / 100,
643
+ positionTime: p.unix(),
644
+ utc: p.utc().format(),
645
645
  method: "trajectory",
646
646
  vendor: "myship"
647
- }, b = Math.floor(g.diff(M, "minute", !0) / (e || 1));
648
- b !== j && (j = b, c.push(r));
647
+ }, u = Math.floor(p.diff(b, "minute", !0) / (e || 1));
648
+ u !== j && (j = u, r.push(f));
649
649
  }
650
- return c;
650
+ return r;
651
651
  }
652
652
  }
653
653
  let _;
@@ -667,20 +667,20 @@ class yt {
667
667
  * @param options
668
668
  */
669
669
  parsePrinciple(s, t = {}) {
670
- var e, c, u;
670
+ var e, r, d;
671
671
  _ == null || _.debug("[%s] parse rule: %s", t.requestId, s);
672
672
  const a = new RegExp("(?<=\\[)(.+)(?=])", "g"), i = s.match(a) ? (e = s.match(a)) == null ? void 0 : e[0] : void 0, n = i == null ? void 0 : i.split(";");
673
673
  if (!n)
674
674
  return;
675
675
  const o = {};
676
676
  for (let h = 0; h < (n == null ? void 0 : n.length); h++) {
677
- const d = (u = (c = n[h].match(a)) == null ? void 0 : c[0]) == null ? void 0 : u.split("],");
678
- if (h === 0 && !d)
677
+ const c = (d = (r = n[h].match(a)) == null ? void 0 : r[0]) == null ? void 0 : d.split("],");
678
+ if (h === 0 && !c)
679
679
  o.scope = n[0];
680
- else if (d)
681
- for (let y = 0, v = d.length; y < v; y++) {
682
- const M = this.parseRule(d[y]);
683
- M && (o[M.level] ? M.key ? o[M.level][M == null ? void 0 : M.key] = M : o[M.level] = M : M.key ? o[M.level] = { [M == null ? void 0 : M.key]: M } : o[M.level] = M);
680
+ else if (c)
681
+ for (let M = 0, w = c.length; M < w; M++) {
682
+ const b = this.parseRule(c[M]);
683
+ b && (o[b.level] ? b.key ? o[b.level][b == null ? void 0 : b.key] = b : o[b.level] = b : b.key ? o[b.level] = { [b == null ? void 0 : b.key]: b } : o[b.level] = b);
684
684
  }
685
685
  }
686
686
  return o;
@@ -713,17 +713,17 @@ class yt {
713
713
  * @param options
714
714
  */
715
715
  checkWeather(s, t, a = {}) {
716
- var M, j, I, w, g, r, b, m, l, k, S, D, P, N, A;
716
+ var b, j, T, g, p, f, u, l, m, I, k, F, H, x, A;
717
717
  let i = 0, n = 0, o = 0, e = 0;
718
- const c = Math.round(((j = (M = t == null ? void 0 : t.SEVERE) == null ? void 0 : M.sigWave) == null ? void 0 : j.number) * 1.6 * 100) / 100, u = (w = (I = t == null ? void 0 : t.SEVERE) == null ? void 0 : I.sigWave) == null ? void 0 : w.number, h = (r = (g = t == null ? void 0 : t.HEAVY) == null ? void 0 : g.sigWave) == null ? void 0 : r.number, d = Math.round((((m = (b = t == null ? void 0 : t.SEVERE) == null ? void 0 : b.wind) == null ? void 0 : m.number) + 2) * 100) / 100, y = (k = (l = t == null ? void 0 : t.SEVERE) == null ? void 0 : l.wind) == null ? void 0 : k.number, v = (D = (S = t == null ? void 0 : t.HEAVY) == null ? void 0 : S.wind) == null ? void 0 : D.number;
719
- for (let x = 0; x < (s == null ? void 0 : s.length); x++) {
720
- const T = s[x], q = (N = (P = T == null ? void 0 : T.meteo) == null ? void 0 : P.wave) == null ? void 0 : N.sig, R = (A = T == null ? void 0 : T.meteo) == null ? void 0 : A.wind, J = x ? p(T.eta).diff(p(s[x - 1].eta), "hour", !0) : 0;
721
- e = J > e ? J : e, _ == null || _.debug("[%s] check sig.wave: %j", a.requestId, { ...q, dgThd4Wv: c, svThd4Wv: u, hvThd4Wv: h }), (q == null ? void 0 : q.height) >= c ? T.isDangerous = !0 : (q == null ? void 0 : q.height) >= u ? T.isSevere = !0 : (q == null ? void 0 : q.height) >= h && (T.isHeavy = !0), _ == null || _.debug("[%s] check wind: %j", a.requestId, { ...R, dgThd4Wd: d, svThd4Wd: y, hvThd4Wd: v }), (R == null ? void 0 : R.scale) >= d ? (T.isDangerous = !0, delete T.isSevere, delete T.isHeavy) : (R == null ? void 0 : R.scale) > y ? (T.isDangerous || (T.isSevere = !0), delete T.isHeavy) : (R == null ? void 0 : R.scale) === v && !T.isDangerous && !T.isSevere && (T.isHeavy = !0), i += T.isDangerous ? J : 0, n += T.isSevere ? J : 0, o += T.isHeavy ? J : 0;
718
+ const r = Math.round(((j = (b = t == null ? void 0 : t.SEVERE) == null ? void 0 : b.sigWave) == null ? void 0 : j.number) * 1.6 * 100) / 100, d = (g = (T = t == null ? void 0 : t.SEVERE) == null ? void 0 : T.sigWave) == null ? void 0 : g.number, h = (f = (p = t == null ? void 0 : t.HEAVY) == null ? void 0 : p.sigWave) == null ? void 0 : f.number, c = Math.round((((l = (u = t == null ? void 0 : t.SEVERE) == null ? void 0 : u.wind) == null ? void 0 : l.number) + 2) * 100) / 100, M = (I = (m = t == null ? void 0 : t.SEVERE) == null ? void 0 : m.wind) == null ? void 0 : I.number, w = (F = (k = t == null ? void 0 : t.HEAVY) == null ? void 0 : k.wind) == null ? void 0 : F.number;
719
+ for (let D = 0; D < (s == null ? void 0 : s.length); D++) {
720
+ const N = s[D], Y = (x = (H = N == null ? void 0 : N.meteo) == null ? void 0 : H.wave) == null ? void 0 : x.sig, L = (A = N == null ? void 0 : N.meteo) == null ? void 0 : A.wind, J = D ? v(N.eta).diff(v(s[D - 1].eta), "hour", !0) : 0;
721
+ e = J > e ? J : e, _ == null || _.debug("[%s] check sig.wave: %j", a.requestId, { ...Y, dgThd4Wv: r, svThd4Wv: d, hvThd4Wv: h }), (Y == null ? void 0 : Y.height) >= r ? N.isDangerous = !0 : (Y == null ? void 0 : Y.height) >= d ? N.isSevere = !0 : (Y == null ? void 0 : Y.height) >= h && (N.isHeavy = !0), _ == null || _.debug("[%s] check wind: %j", a.requestId, { ...L, dgThd4Wd: c, svThd4Wd: M, hvThd4Wd: w }), (L == null ? void 0 : L.scale) >= c ? (N.isDangerous = !0, delete N.isSevere, delete N.isHeavy) : (L == null ? void 0 : L.scale) > M ? (N.isDangerous || (N.isSevere = !0), delete N.isHeavy) : (L == null ? void 0 : L.scale) === w && !N.isDangerous && !N.isSevere && (N.isHeavy = !0), i += N.isDangerous ? J : 0, n += N.isSevere ? J : 0, o += N.isHeavy ? J : 0;
722
722
  }
723
- return i = Math.round(i * 100) / 100, n = Math.round(n * 100) / 100, o = Math.round(o * 100) / 100, e = Math.round(e), { sample: s, dangerous: i, severe: n, heavy: o, step: e < 3 ? 3 : e, wind: { dgThd4Wd: d, svThd4Wd: y, hvThd4Wd: v }, sig: { dgThd4Wv: c, svThd4Wv: u, hvThd4Wv: h } };
723
+ return i = Math.round(i * 100) / 100, n = Math.round(n * 100) / 100, o = Math.round(o * 100) / 100, e = Math.round(e), { sample: s, dangerous: i, severe: n, heavy: o, step: e < 3 ? 3 : e, wind: { dgThd4Wd: c, svThd4Wd: M, hvThd4Wd: w }, sig: { dgThd4Wv: r, svThd4Wv: d, hvThd4Wv: h } };
724
724
  }
725
725
  }
726
- const xt = new yt();
726
+ const Nt = new yt();
727
727
  let C;
728
728
  try {
729
729
  C = ct.getLogger("vessel");
@@ -732,7 +732,7 @@ try {
732
732
  }
733
733
  const Mt = new mt("", !0);
734
734
  var bt = /* @__PURE__ */ ((E) => (E.common = "common", E.container = "container", E.tugs = "tugs", E))(bt || {}), gt = /* @__PURE__ */ ((E) => (E.Ballast = "Ballast", E.Laden = "Laden", E))(gt || {}), vt = /* @__PURE__ */ ((E) => (E.Cp = "CP", E.Perf = "Basis", E.Instruct = "Other", E))(vt || {});
735
- class O {
735
+ class R {
736
736
  /**
737
737
  * @see https://baike.baidu.com/item/%E6%96%B9%E5%BD%A2%E7%B3%BB%E6%95%B0/4965568?fr=aladdin
738
738
  * 方形系数(block coefficient)
@@ -748,7 +748,7 @@ class O {
748
748
  static blockCoefficient(s, t, a, i) {
749
749
  let n = Math.round(s / (t * a * i) * 100) / 100;
750
750
  n = n < 0.55 ? 0.55 : n > 0.85 ? 0.85 : n;
751
- const o = [0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85], e = o.map((c) => Math.abs(c - n));
751
+ const o = [0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85], e = o.map((r) => Math.abs(r - n));
752
752
  return o[e.indexOf(Math.min(...e))];
753
753
  }
754
754
  /**
@@ -845,17 +845,17 @@ class O {
845
845
  * @private
846
846
  */
847
847
  static assembleProperties(s, t, a, i) {
848
- var y;
849
- const n = s.lbp ?? s.length ?? s.lengthOverall ?? 198.9642, o = s.draught ?? 8, e = s.breadthMoulded ?? s.breadth ?? s.breadthExtreme ?? 32.4572, c = s.deadweight ?? 67035.7773, u = ((y = s == null ? void 0 : s.type) == null ? void 0 : y.toLowerCase()) || "common";
848
+ var M;
849
+ const n = s.lbp ?? s.length ?? s.lengthOverall ?? 198.9642, o = s.draught ?? 8, e = s.breadthMoulded ?? s.breadth ?? s.breadthExtreme ?? 32.4572, r = s.deadweight ?? 67035.7773, d = ((M = s == null ? void 0 : s.type) == null ? void 0 : M.toLowerCase()) || "common";
850
850
  return {
851
- tag: u.indexOf("container") > -1 ? "container" : u.indexOf("tugs") > -1 ? "tugs" : "common",
851
+ tag: d.indexOf("container") > -1 ? "container" : d.indexOf("tugs") > -1 ? "tugs" : "common",
852
852
  lbp: n,
853
853
  loadCondition: t,
854
854
  draught: o,
855
855
  breadthMoulded: e,
856
856
  // 排水量(吨)= 载重量(吨)/ 1.025 + 吃水(米)× 船舶型宽(米)× 船舶型长(米)× 0.7
857
857
  // 其中,1.025是指海水的密度,吨是指公吨,吃水是指船舶的最大吃水深度。船舶型宽是指船舶的最大型宽,船舶型长是指船舶的设计型长。上述公式是针对常规船舶适用的,不同类型的船舶可能会有一些差异。
858
- displacement: Math.round((c / 1.025 + o * e * n * 0.7) * 1e4) / 1e4,
858
+ displacement: Math.round((r / 1.025 + o * e * n * 0.7) * 1e4) / 1e4,
859
859
  // 换算为m/s
860
860
  speed: Math.round((a ?? 14.1382) * 1852 / 3600 * 1e4) / 1e4,
861
861
  bearing: i || 90
@@ -872,41 +872,41 @@ class O {
872
872
  * @param useRouteParam true 启用设置速度
873
873
  * @param options
874
874
  */
875
- static async speedLoseAt(s, t, a, i = "", n = 2, o = !0, e = !1, c = {}) {
876
- let u;
875
+ static async speedLoseAt(s, t, a, i = "", n = 2, o = !0, e = !1, r = {}) {
876
+ let d;
877
877
  if (t.velocity && e && (s.speed = z.roundPrecision(t.velocity * 1852 / 3600, 6)), o) {
878
878
  let h;
879
879
  try {
880
880
  i = (i == null ? void 0 : i.toUpperCase()) === "CMEMS" ? "ECMWF" : i, i = (i == null ? void 0 : i.toUpperCase()) === "METEO2" ? "best_match" : i;
881
- const { weatherModels: M, marineModels: j } = await it.autoPickMeteoModel(i), I = await Mt.spotForecast(t.lat, t.lng, a.utc().format(), !1, !1, !0, {
882
- ...c,
881
+ const { weatherModels: b, marineModels: j } = await rt.autoPickMeteoModel(i), T = await Mt.spotForecast(t.lat, t.lng, a.utc().format(), !1, !1, !0, {
882
+ ...r,
883
883
  pastDays: 1,
884
884
  forecastDays: 1,
885
- weatherModels: M,
885
+ weatherModels: b,
886
886
  marineModels: j
887
- }), [w] = it.pickHourly(I, a);
888
- h = it.toLegacy(w);
889
- } catch (M) {
890
- C.warn("[%s] meteo2 spot(%j) forecast failed: %s", c.requestId, { ...t, eta: a.utc().format(), source: i }, M);
887
+ }), [g] = rt.pickHourly(T, a);
888
+ h = rt.toLegacy(g);
889
+ } catch (b) {
890
+ C.warn("[%s] meteo2 spot(%j) forecast failed: %s", r.requestId, { ...t, eta: a.utc().format(), source: i }, b);
891
891
  }
892
- const d = O.currentFactor(s.bearing, h == null ? void 0 : h.current, n), y = O.weatherFactor(s, h, d), v = Math.round((s.speed * 1.943844 + y + d) * 100) / 100;
893
- u = {
892
+ const c = R.currentFactor(s.bearing, h == null ? void 0 : h.current, n), M = R.weatherFactor(s, h, c), w = Math.round((s.speed * 1.943844 + M + c) * 100) / 100;
893
+ d = {
894
894
  meteo: { ...h },
895
- wxFactor: y,
896
- cFactor: d,
897
- speed: t.velocity && e ? t.velocity : v < 0 ? 1 : v,
895
+ wxFactor: M,
896
+ cFactor: c,
897
+ speed: t.velocity && e ? t.velocity : w < 0 ? 1 : w,
898
898
  eta: a.utc().format(),
899
899
  etd: a.utc().format()
900
900
  };
901
901
  } else
902
- u = {
902
+ d = {
903
903
  wxFactor: 0,
904
904
  cFactor: 0,
905
905
  speed: t.velocity && e ? t.velocity : Math.round(s.speed * 1.943844 * 100) / 100,
906
906
  eta: a.utc().format(),
907
907
  etd: a.utc().format()
908
908
  };
909
- return delete t.meteo, delete t.wxFactor, delete t.cFactor, delete t.speed, delete t.etd, { ...u, ...t };
909
+ return delete t.meteo, delete t.wxFactor, delete t.cFactor, delete t.speed, delete t.etd, { ...d, ...t };
910
910
  }
911
911
  /**
912
912
  * 基于步长计算失速样本
@@ -922,53 +922,53 @@ class O {
922
922
  * @param options
923
923
  * @private
924
924
  */
925
- static async speedLoseInHoursStep(s, t, a, i, n, o, e = "", c = !0, u = !1, h = {}) {
925
+ static async speedLoseInHoursStep(s, t, a, i, n, o, e = "", r = !0, d = !1, h = {}) {
926
926
  t.utc();
927
- const d = t.clone().add(14, "days"), y = [], v = [];
928
- let M = 0, j = 0, I, w;
929
- for (let g = 0; g < o.length - 1; g++) {
930
- let r = o[g];
931
- r.distanceFromStart = Math.round((n + j) * 1e3) / 1e3;
932
- const b = o[g + 1];
933
- if (s.bearing = W.calculateBearing(r, b, !b.gcToPrevious), r.bearing = s.bearing, r.suspend && u) {
934
- r.eta = r.eta || t.utc().format(), r.elapsed = r.elapsed ?? 0;
935
- const k = r.suspend - r.elapsed;
936
- if (i - M > k)
937
- i = i - M - k, t.add(k, "hour"), r.elapsed = r.suspend;
927
+ const c = t.clone().add(14, "days"), M = [], w = [], b = [];
928
+ let j = 0, T = 0, g, p;
929
+ for (let f = 0; f < o.length - 1; f++) {
930
+ let u = o[f];
931
+ u.distanceFromStart = Math.round((n + T) * 1e3) / 1e3;
932
+ const l = o[f + 1];
933
+ if (s.bearing = V.calculateBearing(u, l, !l.gcToPrevious), u.bearing = s.bearing, u.suspend && d) {
934
+ u.eta = u.eta || t.utc().format(), u.elapsed = u.elapsed ?? 0;
935
+ const k = u.suspend - u.elapsed;
936
+ if (i - j > k)
937
+ i = i - j - k, t.add(k, "hour"), u.elapsed = u.suspend;
938
938
  else {
939
- const S = i - M;
940
- r.elapsed += S, t.add(S, "hour"), i = 0;
939
+ const F = i - j;
940
+ u.elapsed += F, t.add(F, "hour"), i = 0;
941
941
  }
942
- if (C == null || C.info(`[%s] suspend ${r.elapsed} hours at %j, and remain ${i} hours need to go...`, h.requestId, r), i === 0)
943
- return r.distanceFromPrevious = j, { etd: t, from: w || r, to: r, next: o.filter((S) => S), wps: y, days: v };
942
+ if (C == null || C.info(`[%s] suspend ${u.elapsed} hours at %j, and remain ${i} hours need to go...`, h.requestId, u), i === 0)
943
+ return u.distanceFromPrevious = T, { etd: t, from: p || u, to: u, next: o.filter((F) => F), wps: M, days: w, all: b };
944
944
  } else
945
- r.suspend = 0;
946
- c = t.isAfter(d) ? !1 : c, r = await O.speedLoseAt(s, r, t, e, 0, c, u, h), w = w || r, r.important && y.push(r), t.isSameOrAfter(a) && (v.push(r), a.add(24, "hour"));
947
- const m = W.calculateDistance(r, b, !b.gcToPrevious);
948
- let l = Math.round(m / w.speed * 1e5) / 1e5;
949
- if (M + l < i) {
950
- if (M += l, t.add(l, "hour"), delete o[g], C == null || C.debug(
951
- `[%s] go to %j from %j with ${m}nm, and cost ${l} hours`,
945
+ u.suspend = 0;
946
+ r = t.isAfter(c) ? !1 : r, u = await R.speedLoseAt(s, u, t, e, 0, r, d, h), b.push(u), p = p || u, u.important && M.push(u), t.isSameOrAfter(a) && (w.push(u), a.add(24, "hour"));
947
+ const m = V.calculateDistance(u, l, !l.gcToPrevious);
948
+ let I = Math.round(m / p.speed * 1e5) / 1e5;
949
+ if (j + I < i) {
950
+ if (j += I, t.add(I, "hour"), delete o[f], C == null || C.debug(
951
+ `[%s] go to %j from %j with ${m}nm, and cost ${I} hours`,
952
952
  h.requestId,
953
- { lat: b.lat, lng: b.lng },
954
- { lat: w.lat, lng: w.lng, etd: w.etd }
955
- ), j += m, o.filter((k) => k).length <= 1) {
956
- I = b, I.eta = t.utc().format(), I.distanceFromPrevious = m, I.distanceFromStart = Math.round((n + j) * 1e4) / 1e4, y.push(I), delete o[g + 1];
953
+ { lat: l.lat, lng: l.lng },
954
+ { lat: p.lat, lng: p.lng, etd: p.etd }
955
+ ), T += m, o.filter((k) => k).length <= 1) {
956
+ g = l, g.eta = t.utc().format(), g.distanceFromPrevious = m, g.distanceFromStart = Math.round((n + T) * 1e4) / 1e4, M.push(g), b.push(g), delete o[f + 1];
957
957
  break;
958
958
  }
959
959
  } else {
960
- l = i - M, t.add(l, "hour");
961
- const k = z.roundPrecision(w.speed * l, 5);
962
- I = W.calculateCoordinate(r, s.bearing, k, "nauticalmiles", !b.gcToPrevious), I.eta = t.utc().format(), o[g] = I, C == null || C.debug(
963
- `[%s] go to %j from %j with ${k}nm, and cost ${l} hours`,
960
+ I = i - j, t.add(I, "hour");
961
+ const k = z.roundPrecision(p.speed * I, 5);
962
+ g = V.calculateCoordinate(u, s.bearing, k, "nauticalmiles", !l.gcToPrevious), g.eta = t.utc().format(), o[f] = g, C == null || C.debug(
963
+ `[%s] go to %j from %j with ${k}nm, and cost ${I} hours`,
964
964
  h.requestId,
965
- { lat: I.lat, lng: I.lng },
966
- { lat: r.lat, lng: r.lng, etd: r.etd }
967
- ), j += k, I.distanceFromPrevious = Math.round(j * 1e4) / 1e4, I.distanceFromStart = Math.round((n + j) * 1e4) / 1e4;
965
+ { lat: g.lat, lng: g.lng },
966
+ { lat: u.lat, lng: u.lng, etd: u.etd }
967
+ ), T += k, g.distanceFromPrevious = Math.round(T * 1e4) / 1e4, g.distanceFromStart = Math.round((n + T) * 1e4) / 1e4;
968
968
  break;
969
969
  }
970
970
  }
971
- return { etd: t, from: w, to: I, next: o.filter((g) => g), wps: y, days: v };
971
+ return { etd: t, from: p, to: g, next: o.filter((f) => f), wps: M, days: w, all: b };
972
972
  }
973
973
  /**
974
974
  * 洋流影响因子
@@ -990,16 +990,16 @@ class O {
990
990
  * @param cFactor 洋流因子
991
991
  */
992
992
  static weatherFactor(s, t, a = 0) {
993
- var v, M, j, I, w, g, r;
993
+ var w, b, j, T, g, p, f;
994
994
  C == null || C.debug("calculate weather factor via: %j", { ...s, ...t });
995
- const i = O.blockCoefficient(s.displacement, s.lbp, s.breadthMoulded, s.draught), n = z.roundPrecision(a * 1852 / 3600, 6), o = O.froudeNumber(s.speed - n, s.lbp), e = O.amendFactor(i, o, s.loadCondition);
996
- let c = Math.abs(s.bearing % 360 - (((v = t == null ? void 0 : t.wind) == null ? void 0 : v.degree) % 360 || 0));
997
- c = c > 180 ? 360 - c : c;
998
- const u = O.directionFactor(c, (M = t == null ? void 0 : t.wind) == null ? void 0 : M.scale), h = O.vesselTagFactor(s.displacement, s.loadCondition, s.tag, (j = t == null ? void 0 : t.wind) == null ? void 0 : j.kts);
999
- let d = u * e * h / 100 * (s.speed - n);
1000
- d = Math.round(d * 1.943844 * 1e4) / 1e4 * -1, s.tag === "tugs" && Math.abs(d) > 1 && (d = d / (Math.abs(Math.round(d)) + 1)), C == null || C.debug("wind wx factor = %d", d), c = Math.abs(s.bearing % 360 - (((w = (I = t == null ? void 0 : t.wave) == null ? void 0 : I.sig) == null ? void 0 : w.degree) % 360 || 0)), c = c > 180 ? 360 - c : c;
1001
- const y = O.waveHeightFactor(((r = (g = t == null ? void 0 : t.wave) == null ? void 0 : g.sig) == null ? void 0 : r.height) ?? 1, c);
1002
- return C == null || C.debug("wave wx factor = %d", y), d = Math.abs(d) > Math.abs(y) ? d : d * 0.3 + y * 0.7, C == null || C.debug("weather factor = %d", d), d = Math.abs(d) > 3 ? 3 * (Math.abs(d) / d) + Math.abs(d) / d * (Math.abs(d) - 2) * 0.1 : d, Math.round((d || 0) * 100) / 100;
995
+ const i = R.blockCoefficient(s.displacement, s.lbp, s.breadthMoulded, s.draught), n = z.roundPrecision(a * 1852 / 3600, 6), o = R.froudeNumber(s.speed - n, s.lbp), e = R.amendFactor(i, o, s.loadCondition);
996
+ let r = Math.abs(s.bearing % 360 - (((w = t == null ? void 0 : t.wind) == null ? void 0 : w.degree) % 360 || 0));
997
+ r = r > 180 ? 360 - r : r;
998
+ const d = R.directionFactor(r, (b = t == null ? void 0 : t.wind) == null ? void 0 : b.scale), h = R.vesselTagFactor(s.displacement, s.loadCondition, s.tag, (j = t == null ? void 0 : t.wind) == null ? void 0 : j.kts);
999
+ let c = d * e * h / 100 * (s.speed - n);
1000
+ c = Math.round(c * 1.943844 * 1e4) / 1e4 * -1, s.tag === "tugs" && Math.abs(c) > 1 && (c = c / (Math.abs(Math.round(c)) + 1)), C == null || C.debug("wind wx factor = %d", c), r = Math.abs(s.bearing % 360 - (((g = (T = t == null ? void 0 : t.wave) == null ? void 0 : T.sig) == null ? void 0 : g.degree) % 360 || 0)), r = r > 180 ? 360 - r : r;
1001
+ const M = R.waveHeightFactor(((f = (p = t == null ? void 0 : t.wave) == null ? void 0 : p.sig) == null ? void 0 : f.height) ?? 1, r);
1002
+ return C == null || C.debug("wave wx factor = %d", M), c = Math.abs(c) > Math.abs(M) ? c : c * 0.3 + M * 0.7, C == null || C.debug("weather factor = %d", c), c = Math.abs(c) > 3 ? 3 * (Math.abs(c) / c) + Math.abs(c) / c * (Math.abs(c) - 2) * 0.1 : c, Math.round((c || 0) * 100) / 100;
1003
1003
  }
1004
1004
  /**
1005
1005
  * 全程失速分析(走完航程)
@@ -1014,14 +1014,14 @@ class O {
1014
1014
  * @param useRouteParam
1015
1015
  * @param options
1016
1016
  */
1017
- static async analyseInstant(s, t, a, i, n, o = "", e = 0, c = !0, u = !1, h = {}) {
1018
- var K, G, X, Q, Z, $;
1019
- const d = p().valueOf();
1017
+ static async analyseInstant(s, t, a, i, n, o = "", e = 0, r = !0, d = !1, h = {}) {
1018
+ var K, G, X, Q, Z, $, tt;
1019
+ const c = v().valueOf();
1020
1020
  s.lng = z.convertToStdLng(s.lng);
1021
- const { route: y, waypoints: v } = n.points, M = W.calculateSubRoute(s, y);
1022
- if (((K = M[0]) == null ? void 0 : K.length) <= 1)
1021
+ const { route: M, waypoints: w } = n.points, b = V.calculateSubRoute(s, M);
1022
+ if (((K = b[0]) == null ? void 0 : K.length) <= 1)
1023
1023
  return;
1024
- const { v0: j, label: I } = s.sog ? {
1024
+ const { v0: j, label: T } = s.sog ? {
1025
1025
  v0: s.sog,
1026
1026
  label: s.label || "Other"
1027
1027
  /* Instruct */
@@ -1029,66 +1029,67 @@ class O {
1029
1029
  v0: i.speed,
1030
1030
  label: "CP"
1031
1031
  /* Cp */
1032
- }, w = O.assembleProperties(a, i.loadCondition, j, 0), g = v.length ? W.calculateSubWaypoints(s, v) : [];
1033
- g.forEach((Y) => Y.important = !0);
1034
- const r = {
1032
+ }, g = R.assembleProperties(a, i.loadCondition, j, 0), p = w.length ? V.calculateSubWaypoints(s, w) : [];
1033
+ p.forEach((q) => q.important = !0);
1034
+ const f = {
1035
1035
  from: { ...s },
1036
- route: M,
1037
- waypoints: g,
1036
+ route: b,
1037
+ waypoints: p,
1038
1038
  v0: j,
1039
- label: I
1040
- }, b = {
1039
+ label: T
1040
+ }, u = {
1041
1041
  hours: [],
1042
1042
  days: [],
1043
- wps: []
1043
+ wps: [],
1044
+ all: []
1044
1045
  };
1045
- e || (W.calculateRouteDistance(M) / i.speed <= 72 ? e = 3 : e = 6);
1046
- let m = W.simplifyRouteToCoordinates(M, g, 0), l = 0, k = 0, S = 0, D = 0;
1047
- t = p(t).utc();
1048
- const P = t.clone();
1049
- for (; m.length > 0; ) {
1050
- const Y = e - t.hour() % e, B = Math.ceil(t.clone().add(Y, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4, F = await O.speedLoseInHoursStep(
1051
- w,
1046
+ e || (V.calculateRouteDistance(b) / i.speed <= 72 ? e = 3 : e = 6);
1047
+ let l = V.simplifyRouteToCoordinates(b, p, 0), m = 0, I = 0, k = 0, F = 0;
1048
+ t = v(t).utc();
1049
+ const H = t.clone();
1050
+ for (; l.length > 0; ) {
1051
+ const q = e - t.hour() % e, W = Math.ceil(t.clone().add(q, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4, S = await R.speedLoseInHoursStep(
1052
+ g,
1052
1053
  t,
1053
- P,
1054
- B,
1055
- l,
1054
+ H,
1055
+ W,
1056
1056
  m,
1057
+ l,
1057
1058
  o,
1058
- c,
1059
- u,
1059
+ r,
1060
+ d,
1060
1061
  h
1061
1062
  );
1062
- if ((G = F.from) != null && G.speed && (b.hours.push(F.from), b.wps.push(...F.wps), b.days.push(...F.days)), m = F == null ? void 0 : F.next, !m.length) {
1063
- const L = await O.speedLoseAt(w, F.to, p(F.to.eta), o, 0, c, u, h);
1064
- L.bearing = w.bearing, b.hours.push(L);
1063
+ if (u.all.push(...S.all), (G = S.from) != null && G.speed && (u.hours.push(S.from), u.wps.push(...S.wps), u.days.push(...S.days)), l = S == null ? void 0 : S.next, !l.length) {
1064
+ const O = await R.speedLoseAt(g, S.to, v(S.to.eta), o, 0, r, d, h);
1065
+ O.bearing = g.bearing, u.hours.push(O), u.all.push(O);
1065
1066
  }
1066
- l += Math.round((((X = F == null ? void 0 : F.to) == null ? void 0 : X.distanceFromPrevious) ?? 0) * 1e4) / 1e4;
1067
+ m += Math.round((((X = S == null ? void 0 : S.to) == null ? void 0 : X.distanceFromPrevious) ?? 0) * 1e4) / 1e4;
1067
1068
  }
1068
- const N = b.hours;
1069
- for (let Y = 0; Y < N.length - 1; Y++) {
1070
- const B = p(N[Y + 1].eta).diff(N[Y].etd, "hour", !0) || 1;
1071
- k += (N[Y].wxFactor || 0) * B, S += (N[Y].cFactor || 0) * B, D += B;
1069
+ const x = u.hours;
1070
+ for (let q = 0; q < x.length - 1; q++) {
1071
+ const W = v(x[q + 1].eta).diff(x[q].etd, "hour", !0) || 1;
1072
+ I += (x[q].wxFactor || 0) * W, k += (x[q].cFactor || 0) * W, F += W;
1072
1073
  }
1073
- (Q = b.wps) == null || Q.forEach((Y, B) => {
1074
- Y.positionTime = p.utc(Y.etd || Y.eta).unix();
1075
- const F = b.wps[B - 1];
1076
- if (F) {
1077
- const L = Y.distanceFromStart - F.distanceFromStart, H = p(Y.eta || Y.etd).diff(p(F.etd || F.eta), "h", !0);
1078
- Y.avgSpd = Math.round(L / H * 100) / 100, F.bearing = W.calculateBearing(F, Y);
1074
+ (Q = u.wps) == null || Q.forEach((q, W) => {
1075
+ q.positionTime = v.utc(q.etd || q.eta).unix();
1076
+ const S = u.wps[W - 1];
1077
+ if (S) {
1078
+ const O = q.distanceFromStart - S.distanceFromStart, P = v(q.eta || q.etd).diff(v(S.etd || S.eta), "h", !0);
1079
+ q.avgSpd = Math.round(O / P * 100) / 100, S.bearing = V.calculateBearing(S, q);
1079
1080
  }
1080
- }), b.wps = (Z = b.wps) == null ? void 0 : Z.reduce((Y, B) => (Y.some((F) => Math.round(F.positionTime / 60) === Math.round(B.positionTime / 60)) || Y.push(B), Y), []), r.sample = b;
1081
- const A = b.hours.at(0), x = b.hours.at(-1);
1082
- r.distance = Math.round(x.distanceFromStart * 1e3) / 1e3, r.etd = p(A.eta).utc().format(), r.eta = p(x.eta).utc().format(), r.wxFactor = Math.round(k / D * 1e3) / 1e3, r.cFactor = Math.round(S / D * 1e3) / 1e3, r.avgSpeed = Math.round(x.distanceFromStart / D * 1e3) / 1e3, r.totalHrs = Math.round(D * 1e3) / 1e3;
1083
- const { distanceInECA: T, hoursInECA: q, totalDgoConsInECA: R, eca: J } = await this.calculateECA(r, i, h), tt = z.roundPrecision(i.fo / 24 * (D - q), 3), at = z.roundPrecision(i.dgo / 24 * D, 3);
1084
- r.extend = {
1081
+ }), u.wps = (Z = u.wps) == null ? void 0 : Z.reduce((q, W) => (q.some((S) => Math.round(S.positionTime / 60) === Math.round(W.positionTime / 60)) || q.push(W), q), []), u.all = ($ = u.all) == null ? void 0 : $.reduce((q, W) => (W.positionTime = v.utc(W.etd || W.eta).unix(), q.some((S) => Math.round(S.positionTime / 60) === Math.round(W.positionTime / 60)) || q.push(W), q), []), f.sample = u;
1082
+ const A = u.hours.at(0), D = u.hours.at(-1);
1083
+ f.distance = Math.round(D.distanceFromStart * 1e3) / 1e3, f.etd = v(A.eta).utc().format(), f.eta = v(D.eta).utc().format(), f.wxFactor = Math.round(I / F * 1e3) / 1e3, f.cFactor = Math.round(k / F * 1e3) / 1e3, f.avgSpeed = Math.round(D.distanceFromStart / F * 1e3) / 1e3, f.totalHrs = Math.round(F * 1e3) / 1e3;
1084
+ const { distanceInECA: N, hoursInECA: Y, totalDgoConsInECA: L, eca: J } = await this.calculateECA(f, i, h), et = z.roundPrecision(i.fo / 24 * (F - Y), 3), nt = z.roundPrecision(i.dgo / 24 * F, 3);
1085
+ f.extend = {
1085
1086
  eca: J,
1086
- distanceInECA: T,
1087
- hoursInECA: q,
1088
- totalDgoConsInECA: R
1089
- }, r.totalFoCons = tt < 0 ? 0 : tt, r.totalDgoCons = at;
1090
- const et = p().valueOf() - d, ot = (($ = b == null ? void 0 : b.hours) == null ? void 0 : $.length) || 1;
1091
- return C == null || C.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", h == null ? void 0 : h.requestId, et, ot, Math.round(et / ot * 1e3) / 1e3), r;
1087
+ distanceInECA: N,
1088
+ hoursInECA: Y,
1089
+ totalDgoConsInECA: L
1090
+ }, f.totalFoCons = et < 0 ? 0 : et, f.totalDgoCons = nt;
1091
+ const st = v().valueOf() - c, it = ((tt = u == null ? void 0 : u.hours) == null ? void 0 : tt.length) || 1;
1092
+ return C == null || C.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", h == null ? void 0 : h.requestId, st, it, Math.round(st / it * 1e3) / 1e3), f;
1092
1093
  }
1093
1094
  /**
1094
1095
  * 分段失速分析(最多走hours 小时)
@@ -1105,11 +1106,11 @@ class O {
1105
1106
  * @param useRouteParam
1106
1107
  * @param options
1107
1108
  */
1108
- static async analyseInstantWithThreshed(s, t, a, i, n, o, e, c = "", u = 3, h = !0, d = !1, y = {}) {
1109
- var X, Q, Z, $, Y, B;
1110
- const v = p().valueOf();
1109
+ static async analyseInstantWithThreshed(s, t, a, i, n, o, e, r = "", d = 3, h = !0, c = !1, M = {}) {
1110
+ var X, Q, Z, $, tt, q, W;
1111
+ const w = v().valueOf();
1111
1112
  s.lng = z.convertToStdLng(s.lng);
1112
- const { v0: M, label: j } = s.sog ? {
1113
+ const { v0: b, label: j } = s.sog ? {
1113
1114
  v0: s.sog,
1114
1115
  label: s.label || "Other"
1115
1116
  /* Instruct */
@@ -1117,66 +1118,65 @@ class O {
1117
1118
  v0: n.speed,
1118
1119
  label: "CP"
1119
1120
  /* Cp */
1120
- }, I = O.assembleProperties(i, n.loadCondition, M, 0), w = W.calculateSubRoute(s, o);
1121
- if (((X = w[0]) == null ? void 0 : X.length) <= 1)
1121
+ }, T = R.assembleProperties(i, n.loadCondition, b, 0), g = V.calculateSubRoute(s, o);
1122
+ if (((X = g[0]) == null ? void 0 : X.length) <= 1)
1122
1123
  return;
1123
- const g = e.length ? W.calculateSubWaypoints(s, e) : [];
1124
- g.forEach((F) => F.important = !0);
1125
- let r = W.simplifyRouteToCoordinates(w, g, 0), b = 0, m = 0, l = 0, k = 0;
1126
- const S = {
1124
+ const p = e.length ? V.calculateSubWaypoints(s, e) : [];
1125
+ p.forEach((S) => S.important = !0);
1126
+ let f = V.simplifyRouteToCoordinates(g, p, 0), u = 0, l = 0, m = 0, I = 0;
1127
+ const k = {
1127
1128
  hours: [],
1128
1129
  wps: [],
1129
- days: []
1130
+ days: [],
1131
+ all: []
1130
1132
  };
1131
- t = p(t).utc();
1132
- const D = t.clone();
1133
- for (; r.length > 0; ) {
1134
- const F = u - t.hour() % u;
1135
- let L = Math.ceil(t.clone().add(F, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4;
1136
- L = t.clone().add(L, "h").isSameOrAfter(a) ? a.diff(t, "h", !0) * 1e4 / 1e4 : L;
1137
- const H = await O.speedLoseInHoursStep(I, t, D, L, b, r, c, h, d, y);
1138
- if ((Q = H.from) != null && Q.speed && (S.hours.push(H.from), H != null && H.wps && S.wps.push(...H.wps), S.days.push(...H.days)), r = H == null ? void 0 : H.next, r.length || S.hours.push(H == null ? void 0 : H.to), b += Math.round((((Z = H == null ? void 0 : H.to) == null ? void 0 : Z.distanceFromPrevious) ?? 0) * 1e4) / 1e4, !L)
1133
+ t = v(t).utc();
1134
+ const F = t.clone();
1135
+ for (; f.length > 0; ) {
1136
+ const S = d - t.hour() % d;
1137
+ let O = Math.ceil(t.clone().add(S, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4;
1138
+ O = t.clone().add(O, "h").isSameOrAfter(a) ? a.diff(t, "h", !0) * 1e4 / 1e4 : O;
1139
+ const P = await R.speedLoseInHoursStep(T, t, F, O, u, f, r, h, c, M);
1140
+ if (k.all.push(...P.all), (Q = P.from) != null && Q.speed && (k.hours.push(P.from), P != null && P.wps && k.wps.push(...P.wps), k.days.push(...P.days)), f = P == null ? void 0 : P.next, f.length || k.hours.push(P == null ? void 0 : P.to), u += Math.round((((Z = P == null ? void 0 : P.to) == null ? void 0 : Z.distanceFromPrevious) ?? 0) * 1e4) / 1e4, !O)
1139
1141
  break;
1140
1142
  }
1141
- S.wps = ($ = S.wps) == null ? void 0 : $.reduce((F, L) => (F.some((H) => Math.round(p(H.etd).unix() / 60) === Math.round(p(L.etd).unix() / 60)) || F.push(L), F), []), (Y = S.wps) == null || Y.forEach((F, L) => {
1142
- const H = S.wps[L - 1];
1143
- if (H) {
1144
- const rt = F.distanceFromStart - H.distanceFromStart, dt = p(F.eta || F.etd).diff(p(H.etd || H.eta), "h", !0);
1145
- F.avgSpd = Math.round(rt / dt * 100) / 100;
1146
- const ut = W.calculateBearing(H, F);
1147
- H.bearing = ut;
1143
+ k.wps = ($ = k.wps) == null ? void 0 : $.reduce((S, O) => (S.some((P) => Math.round(v(P.etd).unix() / 60) === Math.round(v(O.etd).unix() / 60)) || S.push(O), S), []), k.all = (tt = k.all) == null ? void 0 : tt.reduce((S, O) => (O.positionTime = v.utc(O.etd || O.eta).unix(), S.some((P) => Math.round(v(P.etd).unix() / 60) === Math.round(v(O.etd).unix() / 60)) || S.push(O), S), []), (q = k.wps) == null || q.forEach((S, O) => {
1144
+ const P = k.wps[O - 1];
1145
+ if (P) {
1146
+ const dt = S.distanceFromStart - P.distanceFromStart, ut = v(S.eta || S.etd).diff(v(P.etd || P.eta), "h", !0);
1147
+ S.avgSpd = Math.round(dt / ut * 100) / 100, P.bearing = V.calculateBearing(P, S);
1148
1148
  }
1149
1149
  });
1150
- const P = S.hours;
1151
- for (let F = 0; F < P.length - 1; F++) {
1152
- const L = p(P[F + 1].eta).diff(P[F].etd, "hour", !0);
1153
- m += P[F].wxFactor * L, l += P[F].cFactor * L, k += L;
1150
+ const H = k.hours;
1151
+ for (let S = 0; S < H.length - 1; S++) {
1152
+ const O = v(H[S + 1].eta).diff(H[S].etd, "hour", !0);
1153
+ l += H[S].wxFactor * O, m += H[S].cFactor * O, I += O;
1154
1154
  }
1155
- const N = S.hours.at(0), A = S.hours.at(-1), x = await W.calculateRangeRoute(N, A, w), T = await W.calculateRangeWaypoints(N, A, w, g), q = {
1156
- sample: S,
1155
+ const x = k.hours.at(0), A = k.hours.at(-1), D = await V.calculateRangeRoute(x, A, g), N = await V.calculateRangeWaypoints(x, A, g, p), Y = {
1156
+ sample: k,
1157
1157
  distance: Math.round(((A == null ? void 0 : A.distanceFromStart) || 0) * 1e4) / 1e4,
1158
1158
  // 注意,可能会在first节点Drift,所有采用eta做为初始出发时间
1159
- etd: p(N.eta).utc().format(),
1160
- eta: p(A == null ? void 0 : A.eta).utc().format(),
1161
- wxFactor: Math.round(m / k * 1e3) / 1e3,
1162
- cFactor: Math.round(l / k * 1e3) / 1e3,
1163
- avgSpeed: Math.round(((A == null ? void 0 : A.distanceFromStart) || 0) / k * 1e3) / 1e3,
1164
- totalHrs: Math.round(k * 1e3) / 1e3,
1165
- from: N,
1159
+ etd: v(x.eta).utc().format(),
1160
+ eta: v(A == null ? void 0 : A.eta).utc().format(),
1161
+ wxFactor: Math.round(l / I * 1e3) / 1e3,
1162
+ cFactor: Math.round(m / I * 1e3) / 1e3,
1163
+ avgSpeed: Math.round(((A == null ? void 0 : A.distanceFromStart) || 0) / I * 1e3) / 1e3,
1164
+ totalHrs: Math.round(I * 1e3) / 1e3,
1165
+ from: x,
1166
1166
  to: A,
1167
- route: x,
1168
- waypoints: T,
1169
- v0: M,
1167
+ route: D,
1168
+ waypoints: N,
1169
+ v0: b,
1170
1170
  label: j
1171
- }, { distanceInECA: R, hoursInECA: J, totalDgoConsInECA: tt, eca: at } = await this.calculateECA(q, n, y), nt = z.roundPrecision(n.fo / 24 * (k - J), 3), et = z.roundPrecision(n.dgo / 24 * k, 3);
1172
- q.extend = {
1173
- eca: at,
1174
- distanceInECA: R,
1171
+ }, { distanceInECA: L, hoursInECA: J, totalDgoConsInECA: et, eca: nt } = await this.calculateECA(Y, n, M), ot = z.roundPrecision(n.fo / 24 * (I - J), 3), st = z.roundPrecision(n.dgo / 24 * I, 3);
1172
+ Y.extend = {
1173
+ eca: nt,
1174
+ distanceInECA: L,
1175
1175
  hoursInECA: J,
1176
- totalDgoConsInECA: tt
1177
- }, q.totalDgoCons = et, q.totalFoCons = nt < 0 ? 0 : nt;
1178
- const K = p().valueOf() - v, G = ((B = S == null ? void 0 : S.hours) == null ? void 0 : B.length) || 1;
1179
- return C == null || C.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", y == null ? void 0 : y.requestId, K, G, Math.round(K / G * 1e3) / 1e3), q;
1176
+ totalDgoConsInECA: et
1177
+ }, Y.totalDgoCons = st, Y.totalFoCons = ot < 0 ? 0 : ot;
1178
+ const K = v().valueOf() - w, G = ((W = k == null ? void 0 : k.hours) == null ? void 0 : W.length) || 1;
1179
+ return C == null || C.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", M == null ? void 0 : M.requestId, K, G, Math.round(K / G * 1e3) / 1e3), Y;
1180
1180
  }
1181
1181
  /**
1182
1182
  * 在指定航线条件下,基于多CP,动态计算最优成本(租金+油费)方案
@@ -1194,58 +1194,58 @@ class O {
1194
1194
  * @param options
1195
1195
  */
1196
1196
  static async analyseCost(s, t, a, i, n = {}) {
1197
- var w, g;
1198
- const o = p().valueOf(), e = [];
1197
+ var g, p;
1198
+ const o = v().valueOf(), e = [];
1199
1199
  s.speedStep = s.speedStep || 3, s.alterStep = s.alterStep ?? 1;
1200
- const c = W.calculateRouteDistance(i.route);
1201
- let u = 0;
1202
- a.forEach((r) => {
1203
- const b = Math.ceil(c / r.speed / 24);
1204
- u = u < b ? b : u;
1205
- }), u = u * 1.3;
1206
- const h = p.utc(s.etd).add(u ?? 14, "day");
1207
- let d = 1;
1208
- for (const r of a) {
1209
- const b = JSON.parse(JSON.stringify(i.route)), m = JSON.parse(JSON.stringify(i.waypoints)), l = await O.analyseInstantWithThreshed(
1200
+ const r = V.calculateRouteDistance(i.route);
1201
+ let d = 0;
1202
+ a.forEach((f) => {
1203
+ const u = Math.ceil(r / f.speed / 24);
1204
+ d = d < u ? u : d;
1205
+ }), d = d * 1.3;
1206
+ const h = v.utc(s.etd).add(d ?? 14, "day");
1207
+ let c = 1;
1208
+ for (const f of a) {
1209
+ const u = JSON.parse(JSON.stringify(i.route)), l = JSON.parse(JSON.stringify(i.waypoints)), m = await R.analyseInstantWithThreshed(
1210
1210
  { lat: s.lat, lng: s.lng },
1211
1211
  s.etd,
1212
1212
  h,
1213
1213
  t,
1214
- r,
1215
- b,
1216
- m,
1214
+ f,
1215
+ u,
1216
+ l,
1217
1217
  s.meteoVendor,
1218
1218
  s.speedStep,
1219
1219
  s.useMeteo,
1220
1220
  s.useRouteParam,
1221
1221
  n
1222
1222
  );
1223
- l && (await O.calculateCost(l, r, s, n), e.push(l), C == null || C.info("[%s][L%d-%d] analyse from %s to %s cost: %j", n.requestId, 1, d, s.etd, h.format(), {
1224
- cost: l.cost.total,
1225
- hire: l.cost.hire,
1226
- bunker: l.cost.bunker,
1227
- distance: l.distance,
1228
- hours: l.totalHrs,
1229
- cp: `${r.speed}/${r.fo}/${r.dgo}`
1230
- })), d++;
1223
+ m && (await R.calculateCost(m, f, s, n), e.push(m), C == null || C.info("[%s][L%d-%d] analyse from %s to %s cost: %j", n.requestId, 1, c, s.etd, h.format(), {
1224
+ cost: m.cost.total,
1225
+ hire: m.cost.hire,
1226
+ bunker: m.cost.bunker,
1227
+ distance: m.distance,
1228
+ hours: m.totalHrs,
1229
+ cp: `${f.speed}/${f.fo}/${f.dgo}`
1230
+ })), c++;
1231
1231
  }
1232
- e.sort((r, b) => r.cost.total - b.cost.total);
1233
- const y = e.at(0), v = e.at(1), M = [];
1234
- if (M.push({ combined: !1, speeds: [y], cost: (w = y.cost) == null ? void 0 : w.total }), v) {
1235
- const r = y.cost.cp, b = v.cost.cp, m = p(y.eta), l = p(y.etd), k = m.diff(l, "days", !0);
1236
- let S = Math.ceil(k / 2);
1237
- S = S > 7 ? 7 : S < s.alterStep ? s.alterStep : S;
1238
- let D = 2, P = { combined: !1, speeds: [v], cost: (g = v.cost) == null ? void 0 : g.total }, N;
1239
- for (; S >= s.alterStep; ) {
1240
- const A = await O.combinedAnalyse(s, t, h, [r, b], i, S, { ...n, level: D });
1241
- if (P.cost > A.cost ? N ? (N == null ? void 0 : N.cost) > A.cost && (N = A) : (N = P, P = A) : (!N || (N == null ? void 0 : N.cost) > A.cost) && (N = A), S <= s.alterStep)
1232
+ e.sort((f, u) => f.cost.total - u.cost.total);
1233
+ const M = e.at(0), w = e.at(1), b = [];
1234
+ if (b.push({ combined: !1, speeds: [M], cost: (g = M.cost) == null ? void 0 : g.total }), w) {
1235
+ const f = M.cost.cp, u = w.cost.cp, l = v(M.eta), m = v(M.etd), I = l.diff(m, "days", !0);
1236
+ let k = Math.ceil(I / 2);
1237
+ k = k > 7 ? 7 : k < s.alterStep ? s.alterStep : k;
1238
+ let F = 2, H = { combined: !1, speeds: [w], cost: (p = w.cost) == null ? void 0 : p.total }, x;
1239
+ for (; k >= s.alterStep; ) {
1240
+ const A = await R.combinedAnalyse(s, t, h, [f, u], i, k, { ...n, level: F });
1241
+ if (H.cost > A.cost ? x ? (x == null ? void 0 : x.cost) > A.cost && (x = A) : (x = H, H = A) : (!x || (x == null ? void 0 : x.cost) > A.cost) && (x = A), k <= s.alterStep)
1242
1242
  break;
1243
- S = Math.ceil(S / 2), D += 1;
1243
+ k = Math.ceil(k / 2), F += 1;
1244
1244
  }
1245
- M.push(P), N && M.push(N);
1245
+ b.push(H), x && b.push(x);
1246
1246
  }
1247
- const I = p().valueOf() - o;
1248
- return C == null || C.info("[%s] analyse elapsed: %d ms", n == null ? void 0 : n.requestId, I), M.sort((r, b) => r.cost - b.cost);
1247
+ const T = v().valueOf() - o;
1248
+ return C == null || C.info("[%s] analyse elapsed: %d ms", n == null ? void 0 : n.requestId, T), b.sort((f, u) => f.cost - u.cost);
1249
1249
  }
1250
1250
  /**
1251
1251
  * 按步长多次减半,分别用7,4,2,1天步长及cpa,cpb交替计算各种组合下的成本
@@ -1259,22 +1259,22 @@ class O {
1259
1259
  */
1260
1260
  static async combinedAnalyse(s, t, a, i, n, o, e = {}) {
1261
1261
  e.counter = 1, C == null || C.info("[%s][L%d] analyse with alternate cp in every %d days", e.requestId, e.level, o);
1262
- const c = await O.alternateAnalyse(s, t, a, i, 0, n, o, e), u = c.reduce((b, m) => b + m.cost.total, 0), h = c.reduce((b, m) => b + m.cost.hire, 0), d = c.reduce((b, m) => b + m.cost.bunker, 0), y = c.reduce((b, m) => b + m.distance, 0), v = c.reduce((b, m) => b + m.totalHrs, 0);
1262
+ const r = await R.alternateAnalyse(s, t, a, i, 0, n, o, e), d = r.reduce((u, l) => u + l.cost.total, 0), h = r.reduce((u, l) => u + l.cost.hire, 0), c = r.reduce((u, l) => u + l.cost.bunker, 0), M = r.reduce((u, l) => u + l.distance, 0), w = r.reduce((u, l) => u + l.totalHrs, 0);
1263
1263
  C == null || C.info("[%s][L%d] cost with cpa/cpb turn: %j", e.requestId, e.level, {
1264
- cost: u,
1264
+ cost: d,
1265
1265
  hire: h,
1266
- bunker: d,
1267
- distance: y,
1268
- hours: v
1266
+ bunker: c,
1267
+ distance: M,
1268
+ hours: w
1269
1269
  });
1270
- const M = await O.alternateAnalyse(s, t, a, i, 1, n, o, e), j = M.reduce((b, m) => b + m.cost.total, 0), I = M.reduce((b, m) => b + m.cost.hire, 0), w = M.reduce((b, m) => b + m.cost.bunker, 0), g = M.reduce((b, m) => b + m.distance, 0), r = M.reduce((b, m) => b + m.totalHrs, 0);
1270
+ const b = await R.alternateAnalyse(s, t, a, i, 1, n, o, e), j = b.reduce((u, l) => u + l.cost.total, 0), T = b.reduce((u, l) => u + l.cost.hire, 0), g = b.reduce((u, l) => u + l.cost.bunker, 0), p = b.reduce((u, l) => u + l.distance, 0), f = b.reduce((u, l) => u + l.totalHrs, 0);
1271
1271
  return C == null || C.info("[%s][L%d] cost with cpb/cpa turn: %j", e.requestId, e.level, {
1272
1272
  cost: j,
1273
- hire: I,
1274
- bunker: w,
1275
- distance: g,
1276
- hours: r
1277
- }), u < j ? { combined: !0, cost: Math.round(u * 1e3) / 1e3, speeds: c, step: o } : { combined: !0, cost: Math.round(j * 1e3) / 1e3, speeds: M, step: o };
1273
+ hire: T,
1274
+ bunker: g,
1275
+ distance: p,
1276
+ hours: f
1277
+ }), d < j ? { combined: !0, cost: Math.round(d * 1e3) / 1e3, speeds: r, step: o } : { combined: !0, cost: Math.round(j * 1e3) / 1e3, speeds: b, step: o };
1278
1278
  }
1279
1279
  /**
1280
1280
  * 基于cp索引,交替计算指定步长下的成本
@@ -1287,48 +1287,48 @@ class O {
1287
1287
  * @param step 步长,7,4,2,1
1288
1288
  * @param options
1289
1289
  */
1290
- static async alternateAnalyse(s, t, a, i, n, o, e, c = {}) {
1291
- var y, v;
1292
- let u = p.utc(s.etd);
1293
- const h = { lat: s.lat, lng: s.lng }, d = [];
1294
- for (; u.isBefore(a); ) {
1295
- const M = u.clone().utc().add(e, "day"), j = JSON.parse(JSON.stringify(o.route)), I = JSON.parse(JSON.stringify(o.waypoints)), w = i[n], g = await O.analyseInstantWithThreshed(
1290
+ static async alternateAnalyse(s, t, a, i, n, o, e, r = {}) {
1291
+ var M, w;
1292
+ let d = v.utc(s.etd);
1293
+ const h = { lat: s.lat, lng: s.lng }, c = [];
1294
+ for (; d.isBefore(a); ) {
1295
+ const b = d.clone().utc().add(e, "day"), j = JSON.parse(JSON.stringify(o.route)), T = JSON.parse(JSON.stringify(o.waypoints)), g = i[n], p = await R.analyseInstantWithThreshed(
1296
1296
  h,
1297
- u.utc().format(),
1298
- M,
1297
+ d.utc().format(),
1298
+ b,
1299
1299
  t,
1300
- w,
1300
+ g,
1301
1301
  j,
1302
- I,
1302
+ T,
1303
1303
  s.meteoVendor,
1304
1304
  s.speedStep,
1305
1305
  s.useMeteo,
1306
1306
  s.useRouteParam,
1307
- c
1307
+ r
1308
1308
  );
1309
- g && (await O.calculateCost(g, w, s, c), C == null || C.info(
1309
+ p && (await R.calculateCost(p, g, s, r), C == null || C.info(
1310
1310
  "[%s][L%d-%d] analyse from %s to %s cost: %j",
1311
- c.requestId,
1312
- c.level,
1313
- c.counter,
1314
- u.utc().format(),
1315
- M.utc().format(),
1311
+ r.requestId,
1312
+ r.level,
1313
+ r.counter,
1314
+ d.utc().format(),
1315
+ b.utc().format(),
1316
1316
  {
1317
- cost: g.cost.total,
1318
- hire: g.cost.hire,
1319
- bunker: g.cost.bunker,
1320
- distance: g.distance,
1321
- hours: g.totalHrs,
1322
- cp: `${w.speed}/${w.fo}/${w.dgo}`
1317
+ cost: p.cost.total,
1318
+ hire: p.cost.hire,
1319
+ bunker: p.cost.bunker,
1320
+ distance: p.distance,
1321
+ hours: p.totalHrs,
1322
+ cp: `${g.speed}/${g.fo}/${g.dgo}`
1323
1323
  }
1324
- )), c.counter = c.counter + 1;
1325
- const r = (v = (y = g == null ? void 0 : g.sample) == null ? void 0 : y.hours) == null ? void 0 : v.at(-1);
1326
- if (r)
1327
- h.lat = r.lat, h.lng = r.lng, u = p(r.eta), d.push(g), n = n ? 0 : 1;
1324
+ )), r.counter = r.counter + 1;
1325
+ const f = (w = (M = p == null ? void 0 : p.sample) == null ? void 0 : M.hours) == null ? void 0 : w.at(-1);
1326
+ if (f)
1327
+ h.lat = f.lat, h.lng = f.lng, d = v(f.eta), c.push(p), n = n ? 0 : 1;
1328
1328
  else
1329
1329
  break;
1330
1330
  }
1331
- return d;
1331
+ return c;
1332
1332
  }
1333
1333
  /**
1334
1334
  * 计算Speed的cost
@@ -1340,11 +1340,11 @@ class O {
1340
1340
  static async calculateCost(s, t, a, i = {}) {
1341
1341
  var n;
1342
1342
  if (s) {
1343
- const o = (a.addComm || 0) >= 1 ? (a.addComm || 0) / 100 : a.addComm || 0, e = Math.round(s.totalHrs / 24 * (a.dailyHire || 0) * (1 - o) * 1e3) / 1e3, c = Math.round(s.totalFoCons * (a.priceFO || 0) * 1e3) / 1e3, u = Math.round((s.totalDgoCons + (((n = s.extend) == null ? void 0 : n.totalDgoConsInECA) || 0)) * (a.priceDGO || 0) * 1e3) / 1e3;
1343
+ const o = (a.addComm || 0) >= 1 ? (a.addComm || 0) / 100 : a.addComm || 0, e = Math.round(s.totalHrs / 24 * (a.dailyHire || 0) * (1 - o) * 1e3) / 1e3, r = Math.round(s.totalFoCons * (a.priceFO || 0) * 1e3) / 1e3, d = Math.round((s.totalDgoCons + (((n = s.extend) == null ? void 0 : n.totalDgoConsInECA) || 0)) * (a.priceDGO || 0) * 1e3) / 1e3;
1344
1344
  s.cost = {
1345
- total: Math.round((e + c + u) * 1e3) / 1e3,
1345
+ total: Math.round((e + r + d) * 1e3) / 1e3,
1346
1346
  hire: e,
1347
- bunker: Math.round((c + u) * 1e3) / 1e3,
1347
+ bunker: Math.round((r + d) * 1e3) / 1e3,
1348
1348
  cp: t
1349
1349
  };
1350
1350
  }
@@ -1355,16 +1355,16 @@ class O {
1355
1355
  *
1356
1356
  */
1357
1357
  static async calculateECA(s, t, a = {}) {
1358
- var c, u, h, d;
1359
- const i = await W.intersectInECA((s == null ? void 0 : s.route) || []);
1358
+ var r, d, h, c;
1359
+ const i = await V.intersectInECA((s == null ? void 0 : s.route) || []);
1360
1360
  let n = 0, o = 0, e = 0;
1361
- (u = (c = s == null ? void 0 : s.sample) == null ? void 0 : c.wps) == null || u.forEach((y) => {
1362
- y.positionTime = p.utc(y.etd || y.eta).unix();
1361
+ (d = (r = s == null ? void 0 : s.sample) == null ? void 0 : r.wps) == null || d.forEach((M) => {
1362
+ M.positionTime = v.utc(M.etd || M.eta).unix();
1363
1363
  });
1364
- for (const y of i) {
1365
- n += y.distance;
1366
- const v = await W.deadReckoningTime((h = y.waypoints) == null ? void 0 : h.at(0), s.sample.wps), M = await W.deadReckoningTime((d = y.waypoints) == null ? void 0 : d.at(-1), s.sample.wps);
1367
- y.in = v, y.out = M, y.totalHrs = z.roundPrecision((M.positionTime - v.positionTime) / 3600, 3), y.totalDgoCons = z.roundPrecision(t.fo / 24 * y.totalHrs, 3), o += y.totalHrs, e += y.totalDgoCons;
1364
+ for (const M of i) {
1365
+ n += M.distance;
1366
+ const w = await V.deadReckoningTime((h = M.waypoints) == null ? void 0 : h.at(0), s.sample.all || s.sample.wps), b = await V.deadReckoningTime((c = M.waypoints) == null ? void 0 : c.at(-1), s.sample.all || s.sample.wps);
1367
+ M.in = w, M.out = b, M.totalHrs = z.roundPrecision((b.positionTime - w.positionTime) / 3600, 3), M.totalDgoCons = z.roundPrecision(t.fo / 24 * M.totalHrs, 3), o += M.totalHrs, e += M.totalDgoCons;
1368
1368
  }
1369
1369
  return n = z.roundPrecision(n, 3), o = z.roundPrecision(o, 3), e = z.roundPrecision(e, 3), {
1370
1370
  distanceInECA: n,
@@ -1379,55 +1379,55 @@ class O {
1379
1379
  * @param options
1380
1380
  */
1381
1381
  static async mergeSpeeds(s, t = {}) {
1382
- var r, b;
1382
+ var f, u;
1383
1383
  const a = {
1384
1384
  hours: [],
1385
1385
  wps: [],
1386
1386
  days: []
1387
- }, i = s.reduce((m, l) => m + l.distance, 0), n = s.reduce((m, l) => {
1388
- var k;
1389
- return m + (((k = l.extend) == null ? void 0 : k.distanceInECA) || 0);
1390
- }, 0), o = s.reduce((m, l) => m + l.totalHrs, 0), e = s.reduce((m, l) => {
1391
- var k;
1392
- return m + (((k = l.extend) == null ? void 0 : k.hoursInECA) || 0);
1393
- }, 0), c = s.reduce((m, l) => {
1394
- var k;
1395
- return m + (((k = l.extend) == null ? void 0 : k.totalDgoConsInECA) || 0);
1396
- }, 0), u = s.reduce((m, l) => m + l.wxFactor * l.totalHrs / o, 0), h = s.reduce((m, l) => m + l.cFactor * l.totalHrs / o, 0), d = s.reduce((m, l) => m + l.totalFoCons, 0), y = s.reduce((m, l) => m + l.totalDgoCons, 0), v = s.reduce((m, l) => m + l.cost.total, 0), M = s.reduce((m, l) => m + l.cost.hire, 0), j = s.reduce((m, l) => m + l.cost.bunker, 0), I = [], w = [];
1397
- let g;
1398
- for (const m of s) {
1399
- w.push(...((r = m.extend) == null ? void 0 : r.eca) || []);
1400
- const l = m.sample.hours, k = m.sample.wps, S = m.sample.days, D = l.at(0);
1401
- g && (D.distanceFromPrevious = g.distanceFromPrevious, D.distanceFromStart = g.distanceFromStart, l.forEach((x, T) => {
1402
- T && (x.distanceFromStart = x.distanceFromStart + g.distanceFromStart);
1403
- }), k.at(0).distanceFromPrevious = g.distanceFromPrevious, k.at(0).distanceFromStart = g.distanceFromStart, k.forEach((x, T) => {
1404
- T && (x.distanceFromStart = x.distanceFromStart + g.distanceFromStart);
1405
- }), S.at(0).distanceFromPrevious = g.distanceFromPrevious, S.at(0).distanceFromStart = g.distanceFromStart, S.forEach((x, T) => {
1406
- T && (x.distanceFromStart = x.distanceFromStart + g.distanceFromStart);
1407
- })), D.cp = m.cost.cp;
1408
- const P = [m.etd, m.eta], N = I.findIndex((x) => x.id === D.cp.id);
1409
- N === -1 ? (D.cp.segment = [P], I.push(D.cp)) : I[N].segment.push(P), l.forEach((x) => {
1410
- var q;
1411
- ((q = a.hours) == null ? void 0 : q.findIndex((R) => R.eta === x.eta)) === -1 && a.hours.push(x);
1412
- }), k.forEach((x) => {
1413
- var q;
1414
- ((q = a.wps) == null ? void 0 : q.findIndex((R) => R.eta === x.eta)) === -1 && a.wps.push(x);
1415
- }), S.forEach((x) => {
1416
- var q;
1417
- ((q = a == null ? void 0 : a.days) == null ? void 0 : q.findIndex((R) => R.eta === x.eta)) === -1 && a.days.push(x);
1387
+ }, i = s.reduce((l, m) => l + m.distance, 0), n = s.reduce((l, m) => {
1388
+ var I;
1389
+ return l + (((I = m.extend) == null ? void 0 : I.distanceInECA) || 0);
1390
+ }, 0), o = s.reduce((l, m) => l + m.totalHrs, 0), e = s.reduce((l, m) => {
1391
+ var I;
1392
+ return l + (((I = m.extend) == null ? void 0 : I.hoursInECA) || 0);
1393
+ }, 0), r = s.reduce((l, m) => {
1394
+ var I;
1395
+ return l + (((I = m.extend) == null ? void 0 : I.totalDgoConsInECA) || 0);
1396
+ }, 0), d = s.reduce((l, m) => l + m.wxFactor * m.totalHrs / o, 0), h = s.reduce((l, m) => l + m.cFactor * m.totalHrs / o, 0), c = s.reduce((l, m) => l + m.totalFoCons, 0), M = s.reduce((l, m) => l + m.totalDgoCons, 0), w = s.reduce((l, m) => l + m.cost.total, 0), b = s.reduce((l, m) => l + m.cost.hire, 0), j = s.reduce((l, m) => l + m.cost.bunker, 0), T = [], g = [];
1397
+ let p;
1398
+ for (const l of s) {
1399
+ g.push(...((f = l.extend) == null ? void 0 : f.eca) || []);
1400
+ const m = l.sample.hours, I = l.sample.wps, k = l.sample.days, F = m.at(0);
1401
+ p && (F.distanceFromPrevious = p.distanceFromPrevious, F.distanceFromStart = p.distanceFromStart, m.forEach((D, N) => {
1402
+ N && (D.distanceFromStart = D.distanceFromStart + p.distanceFromStart);
1403
+ }), I.at(0).distanceFromPrevious = p.distanceFromPrevious, I.at(0).distanceFromStart = p.distanceFromStart, I.forEach((D, N) => {
1404
+ N && (D.distanceFromStart = D.distanceFromStart + p.distanceFromStart);
1405
+ }), k.at(0).distanceFromPrevious = p.distanceFromPrevious, k.at(0).distanceFromStart = p.distanceFromStart, k.forEach((D, N) => {
1406
+ N && (D.distanceFromStart = D.distanceFromStart + p.distanceFromStart);
1407
+ })), F.cp = l.cost.cp;
1408
+ const H = [l.etd, l.eta], x = T.findIndex((D) => D.id === F.cp.id);
1409
+ x === -1 ? (F.cp.segment = [H], T.push(F.cp)) : T[x].segment.push(H), m.forEach((D) => {
1410
+ var Y;
1411
+ ((Y = a.hours) == null ? void 0 : Y.findIndex((L) => L.eta === D.eta)) === -1 && a.hours.push(D);
1412
+ }), I.forEach((D) => {
1413
+ var Y;
1414
+ ((Y = a.wps) == null ? void 0 : Y.findIndex((L) => L.eta === D.eta)) === -1 && a.wps.push(D);
1415
+ }), k.forEach((D) => {
1416
+ var Y;
1417
+ ((Y = a == null ? void 0 : a.days) == null ? void 0 : Y.findIndex((L) => L.eta === D.eta)) === -1 && a.days.push(D);
1418
1418
  });
1419
- const A = (b = a.wps) == null ? void 0 : b.findIndex((x) => x.eta === D.eta);
1420
- A === -1 ? a.wps.push(D) : a.wps[A] = D, g = l.at(-1);
1419
+ const A = (u = a.wps) == null ? void 0 : u.findIndex((D) => D.eta === F.eta);
1420
+ A === -1 ? a.wps.push(F) : a.wps[A] = F, p = m.at(-1);
1421
1421
  }
1422
- return a.wps.sort((m, l) => {
1423
- p(m.etd).unix() - p(l.etd).unix();
1424
- }), a.wps.forEach((m, l) => {
1425
- const k = a.wps[l - 1];
1426
- if (k) {
1427
- const S = m.distanceFromStart - (k.distanceFromStart || 0), D = p(m.eta || m.etd).diff(p(k.etd || k.eta), "hour", !0), P = Math.round(S / D * 100) / 100;
1428
- m.avgSpd = P;
1429
- const N = W.calculateBearing(k, m);
1430
- k.bearing = N;
1422
+ return a.wps.sort((l, m) => {
1423
+ v(l.etd).unix() - v(m.etd).unix();
1424
+ }), a.wps.forEach((l, m) => {
1425
+ const I = a.wps[m - 1];
1426
+ if (I) {
1427
+ const k = l.distanceFromStart - (I.distanceFromStart || 0), F = v(l.eta || l.etd).diff(v(I.etd || I.eta), "hour", !0), H = Math.round(k / F * 100) / 100;
1428
+ l.avgSpd = H;
1429
+ const x = V.calculateBearing(I, l);
1430
+ I.bearing = x;
1431
1431
  }
1432
1432
  }), {
1433
1433
  sample: a,
@@ -1440,37 +1440,37 @@ class O {
1440
1440
  distance: Math.round(i * 1e3) / 1e3,
1441
1441
  totalHrs: Math.round(o * 1e3) / 1e3,
1442
1442
  avgSpeed: Math.round(i / o * 1e3) / 1e3,
1443
- wxFactor: Math.round(u * 1e3) / 1e3,
1443
+ wxFactor: Math.round(d * 1e3) / 1e3,
1444
1444
  cFactor: Math.round(h * 1e3) / 1e3,
1445
- totalFoCons: Math.round(d * 1e3) / 1e3,
1446
- totalDgoCons: Math.round(y * 1e3) / 1e3,
1445
+ totalFoCons: Math.round(c * 1e3) / 1e3,
1446
+ totalDgoCons: Math.round(M * 1e3) / 1e3,
1447
1447
  cost: {
1448
- total: Math.round(v * 1e3) / 1e3,
1449
- hire: Math.round(M * 1e3) / 1e3,
1448
+ total: Math.round(w * 1e3) / 1e3,
1449
+ hire: Math.round(b * 1e3) / 1e3,
1450
1450
  bunker: Math.round(j * 1e3) / 1e3
1451
1451
  },
1452
1452
  extend: {
1453
- cps: I,
1454
- eca: w,
1453
+ cps: T,
1454
+ eca: g,
1455
1455
  distanceInECA: Math.round(n * 1e3) / 1e3,
1456
1456
  hoursInECA: Math.round(e * 1e3) / 1e3,
1457
- totalDgoConsInECA: Math.round(c * 1e3) / 1e3,
1457
+ totalDgoConsInECA: Math.round(r * 1e3) / 1e3,
1458
1458
  speeds: s
1459
1459
  }
1460
1460
  };
1461
1461
  }
1462
1462
  }
1463
1463
  export {
1464
- st as AISImpl,
1464
+ at as AISImpl,
1465
1465
  yt as AlertHelper,
1466
1466
  ft as AlertLevel,
1467
- Et as HifleetImpl,
1467
+ Ft as HifleetImpl,
1468
1468
  gt as LoadCondition,
1469
- Tt as MyShipImpl,
1470
- Ft as MyVesselImpl,
1471
- Nt as ShipxyImpl,
1472
- O as SpeedHelper,
1469
+ xt as MyShipImpl,
1470
+ Tt as MyVesselImpl,
1471
+ Et as ShipxyImpl,
1472
+ R as SpeedHelper,
1473
1473
  vt as SpeedLabel,
1474
1474
  bt as VesselTag,
1475
- xt as alertHelper
1475
+ Nt as alertHelper
1476
1476
  };