@idm-plugin/vessel 1.7.2 → 1.7.4

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
- var rt = Object.defineProperty;
2
- var dt = (Y, e, t) => e in Y ? rt(Y, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : Y[e] = t;
3
- var _ = (Y, e, t) => (dt(Y, typeof e != "symbol" ? e + "" : e, t), t);
1
+ var dt = Object.defineProperty;
2
+ var ut = (x, e, t) => e in x ? dt(x, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : x[e] = t;
3
+ var G = (x, e, t) => (ut(x, typeof e != "symbol" ? e + "" : e, t), t);
4
4
  import V from "got";
5
- import at from "@log4js-node/log4js-api";
6
- import w from "moment";
7
- import { LngLatHelper as J, LaneHelper as R } from "@idm-plugin/geo2";
8
- import { MeteoHelper2 as ut, MeteoHelper as ht } from "@idm-plugin/meteo2";
9
- import { Meteo2Assist as ct } from "@idm-plugin/meteo";
5
+ import ot from "@log4js-node/log4js-api";
6
+ import b from "moment";
7
+ import { LngLatHelper as J, LaneHelper as W } from "@idm-plugin/geo2";
8
+ import { MeteoHelper2 as ht, MeteoHelper as lt } from "@idm-plugin/meteo2";
9
+ import { Meteo2Assist as rt } from "@idm-plugin/meteo";
10
10
  let g;
11
11
  try {
12
- g = at.getLogger("vessel");
12
+ g = ot.getLogger("vessel");
13
13
  } catch {
14
14
  } finally {
15
15
  }
16
- class $ {
16
+ class tt {
17
17
  /**
18
18
  * 解析AIS状态码
19
19
  * @param status
@@ -54,12 +54,12 @@ class $ {
54
54
  return { labelCn: t, labelEn: n };
55
55
  }
56
56
  }
57
- class Ct extends $ {
57
+ class Ct extends tt {
58
58
  constructor(t, n) {
59
59
  super();
60
- _(this, "clientId");
61
- _(this, "clientSecret");
62
- _(this, "token");
60
+ G(this, "clientId");
61
+ G(this, "clientSecret");
62
+ G(this, "token");
63
63
  this.clientId = t, this.clientSecret = n;
64
64
  }
65
65
  async authToken(t = {}) {
@@ -76,15 +76,15 @@ class Ct extends $ {
76
76
  expiresIn: o.expires_in,
77
77
  scope: o.scope,
78
78
  jti: o.jti,
79
- issuedAt: w().utc().format()
79
+ issuedAt: b().utc().format()
80
80
  });
81
81
  }
82
82
  async realTimePosition(t, n = {}) {
83
- var u, y, l;
84
- (!this.token || w().diff(w(this.token.issuedAt), "seconds") > ((u = this.token) == null ? void 0 : u.expiresIn) - 300) && await this.authToken(n);
83
+ var h, m, l;
84
+ (!this.token || b().diff(b(this.token.issuedAt), "seconds") > ((h = this.token) == null ? void 0 : h.expiresIn) - 300) && await this.authToken(n);
85
85
  const i = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit", o = {
86
86
  headers: {
87
- Authorization: `${(y = this.token) == null ? void 0 : y.tokenType} ${(l = this.token) == null ? void 0 : l.accessToken}`
87
+ Authorization: `${(m = this.token) == null ? void 0 : m.tokenType} ${(l = this.token) == null ? void 0 : l.accessToken}`
88
88
  },
89
89
  searchParams: { mmsi: t }
90
90
  };
@@ -93,9 +93,9 @@ class Ct extends $ {
93
93
  if (a.code)
94
94
  return g == null || g.warn("[%s] fetch realtime position failed: %j", n.requestId, i, { message: a.message, status: a.status, code: a.code }), a;
95
95
  const s = a.data;
96
- for (const M in s)
97
- !isNaN(s[M]) && Number(s[M]) !== 1 / 0 && (s[M] = Number(s[M]));
98
- const d = w(`${s.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
96
+ for (const y in s)
97
+ !isNaN(s[y]) && Number(s[y]) !== 1 / 0 && (s[y] = Number(s[y]));
98
+ const d = b(`${s.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
99
99
  return {
100
100
  mmsi: s.mmsi,
101
101
  name: s.vesselName,
@@ -110,7 +110,7 @@ class Ct extends $ {
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) ? w.utc(s.eta).format() : void 0,
113
+ eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ? b.utc(s.eta).format() : void 0,
114
114
  destination: s.dest,
115
115
  positionTime: d.unix(),
116
116
  status: s.status,
@@ -122,17 +122,17 @@ class Ct extends $ {
122
122
  };
123
123
  }
124
124
  async trajectory(t, n, i, o, a = !0, s = {}) {
125
- (!this.token || w().diff(w(this.token.issuedAt), "seconds") > this.token.expiresIn - 300) && await this.authToken(s);
126
- const d = await this.realTimePosition(t, s), c = w(n), u = w(i), y = [];
127
- for (; u.diff(c, "day", !0) > 30; )
128
- await this.trajectoryIn30Day(t, c, c.clone().add(30, "day"), d, o, y, s), c.add(30, "day");
129
- return await this.trajectoryIn30Day(t, c, u, d, o, y, s), y;
125
+ (!this.token || b().diff(b(this.token.issuedAt), "seconds") > this.token.expiresIn - 300) && await this.authToken(s);
126
+ const d = await this.realTimePosition(t, s), r = b(n), h = b(i), m = [];
127
+ for (; h.diff(r, "day", !0) > 30; )
128
+ await this.trajectoryIn30Day(t, r, r.clone().add(30, "day"), d, o, m, s), r.add(30, "day");
129
+ return await this.trajectoryIn30Day(t, r, h, d, o, m, s), m;
130
130
  }
131
131
  async trajectoryIn30Day(t, n, i, o, a, s, d = {}) {
132
- var m, C, k, p, v;
133
- const c = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", u = {
132
+ var f, C, k, p, v;
133
+ const r = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", h = {
134
134
  headers: {
135
- Authorization: `${(m = this.token) == null ? void 0 : m.tokenType} ${(C = this.token) == null ? void 0 : C.accessToken}`
135
+ Authorization: `${(f = this.token) == null ? void 0 : f.tokenType} ${(C = this.token) == null ? void 0 : C.accessToken}`
136
136
  },
137
137
  json: {
138
138
  mmsi: t,
@@ -140,42 +140,42 @@ class Ct extends $ {
140
140
  endTime: i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")
141
141
  }
142
142
  };
143
- g == null || g.info("[%s] fetch trajectory from: %s - %j", d.requestId, c, u);
144
- const y = await V.post(c, u).json();
145
- if (y.code)
146
- return g == null || g.warn("[%s] fetch trajectory failed: %j", d.requestId, c, { message: y.message, status: y.status, code: y.code }), y;
143
+ g == null || g.info("[%s] fetch trajectory from: %s - %j", d.requestId, r, h);
144
+ const m = await V.post(r, h).json();
145
+ if (m.code)
146
+ return g == null || g.warn("[%s] fetch trajectory failed: %j", d.requestId, r, { message: m.message, status: m.status, code: m.code }), m;
147
147
  let l = -1;
148
- const M = w(`${(p = (k = y.data) == null ? void 0 : k[0]) == null ? void 0 : p.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
149
- return (v = y.data) == null || v.forEach((r) => {
150
- for (const H in r)
151
- !isNaN(r[H]) && Number(r[H]) !== 1 / 0 && (r[H] = Number(r[H]));
152
- const h = w(`${r.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), b = r.status, { labelCn: f, labelEn: D } = this.parseStatus(b), S = {
153
- mmsi: r.mmsi,
148
+ const y = b(`${(p = (k = m.data) == null ? void 0 : k[0]) == null ? void 0 : p.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
149
+ return (v = m.data) == null || v.forEach((c) => {
150
+ for (const Y in c)
151
+ !isNaN(c[Y]) && Number(c[Y]) !== 1 / 0 && (c[Y] = Number(c[Y]));
152
+ const w = b(`${c.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), M = c.status, { labelCn: u, labelEn: I } = this.parseStatus(M), F = {
153
+ mmsi: c.mmsi,
154
154
  imo: o == null ? void 0 : o.imo,
155
- lat: r.lat,
156
- lng: r.lon,
157
- sog: r.sog,
158
- cog: r.cog,
159
- hdg: r.hdg,
160
- draught: r.draught,
161
- status: b,
162
- eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(r.eta) ? w(`${r.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00").utc().format() : void 0,
163
- destination: r.dest,
164
- positionTime: h.unix(),
165
- labelCn: f,
166
- labelEn: D,
155
+ lat: c.lat,
156
+ lng: c.lon,
157
+ sog: c.sog,
158
+ cog: c.cog,
159
+ hdg: c.hdg,
160
+ draught: c.draught,
161
+ status: M,
162
+ eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(c.eta) ? b(`${c.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00").utc().format() : void 0,
163
+ destination: c.dest,
164
+ positionTime: w.unix(),
165
+ labelCn: u,
166
+ labelEn: I,
167
167
  method: "trajectory",
168
168
  vendor: "myVessel",
169
- utc: h.utc().format()
170
- }, A = Math.floor(h.diff(M, "minute", !0) / (a || 1));
171
- A !== l && (l = A, s.push(S));
169
+ utc: w.utc().format()
170
+ }, D = Math.floor(w.diff(y, "minute", !0) / (a || 1));
171
+ D !== l && (l = D, s.push(F));
172
172
  }), s;
173
173
  }
174
174
  }
175
- class St extends $ {
175
+ class xt extends tt {
176
176
  constructor(t) {
177
177
  super();
178
- _(this, "token");
178
+ G(this, "token");
179
179
  this.token = t;
180
180
  }
181
181
  async realTimePosition(t, n = {}) {
@@ -189,10 +189,10 @@ class St extends $ {
189
189
  const s = a == null ? void 0 : a.list;
190
190
  if (!s)
191
191
  return g == null || g.warn("[%s] fetch realtime position failed: %j", n.requestId, i, a), a;
192
- for (const M in s)
193
- !isNaN(s[M]) && Number(s[M]) !== 1 / 0 && (s[M] = Number(s[M]));
192
+ for (const y in s)
193
+ !isNaN(s[y]) && Number(s[y]) !== 1 / 0 && (s[y] = Number(s[y]));
194
194
  s.status = s.sp > 3 ? 0 : 1;
195
- const d = s.status, { labelCn: c, labelEn: u } = this.parseStatus(d), y = w(`${s.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
195
+ const d = s.status, { labelCn: r, labelEn: h } = this.parseStatus(d), m = b(`${s.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
196
196
  return {
197
197
  mmsi: s.m,
198
198
  name: s.n,
@@ -207,13 +207,13 @@ class St extends $ {
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) ? w.utc(s.eta).format() : void 0,
210
+ eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ? b.utc(s.eta).format() : void 0,
211
211
  destination: s.destination,
212
- positionTime: y.unix(),
213
- utc: y.utc().format(),
212
+ positionTime: m.unix(),
213
+ utc: m.utc().format(),
214
214
  status: d,
215
- labelCn: c,
216
- labelEn: u,
215
+ labelCn: r,
216
+ labelEn: h,
217
217
  method: "position",
218
218
  vendor: "hifleet"
219
219
  };
@@ -267,63 +267,63 @@ class St extends $ {
267
267
  imo: !d.imo || isNaN(d.imo) ? null : Number(d.imo),
268
268
  score: d._score
269
269
  });
270
- return s.sort((d, c) => c.score - d.score), s;
270
+ return s.sort((d, r) => r.score - d.score), s;
271
271
  }
272
272
  async trajectory(t, n, i, o, a = !0, s = {}) {
273
- var r, h, b;
273
+ var c, w, M;
274
274
  const d = await this.realTimePosition(t, s);
275
- let c = w(n);
276
- const u = w(i), y = w();
275
+ let r = b(n);
276
+ const h = b(i), m = b();
277
277
  if (a) {
278
- let f = u.diff(c, "d", !0);
279
- f < 0 ? c = u.clone().subtract(40, "d") : f < 30 ? c.subtract(10, "d") : f < 60 ? c.subtract(5, "d") : c = u.clone().subtract(80, "d"), f = y.diff(u, "d", !0), u.add(f > 10 ? 240 : f * 24, "h");
278
+ let u = h.diff(r, "d", !0);
279
+ u < 0 ? r = h.clone().subtract(40, "d") : u < 30 ? r.subtract(10, "d") : u < 60 ? r.subtract(5, "d") : r = h.clone().subtract(80, "d"), u = m.diff(h, "d", !0), h.add(u > 10 ? 240 : u * 24, "h");
280
280
  }
281
281
  const l = {
282
282
  searchParams: {
283
- endtime: u.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
284
- starttime: c.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
283
+ endtime: h.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
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
- }, M = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", m = await V.get(M, l).json();
289
- g == null || g.info("[%s] fetch trajectory from: %s - %j", s.requestId, M, l);
288
+ }, y = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", f = await V.get(y, l).json();
289
+ g == null || g.info("[%s] fetch trajectory from: %s - %j", s.requestId, y, l);
290
290
  let C;
291
- m && (C = ((h = (r = m.ships) == null ? void 0 : r.offors) == null ? void 0 : h.ship) || [], C.length || g == null || g.warn("[%s] fetch trajectory failed: %j", s.requestId, m));
291
+ f && (C = ((w = (c = f.ships) == null ? void 0 : c.offors) == null ? void 0 : w.ship) || [], C.length || g == null || g.warn("[%s] fetch trajectory failed: %j", s.requestId, f));
292
292
  const k = [];
293
293
  let p = -1;
294
- const v = w(`${(b = C == null ? void 0 : C[0]) == null ? void 0 : b.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
295
- for (const f of C) {
296
- for (const x in f)
297
- !isNaN(f[x]) && Number(f[x]) !== 1 / 0 && (f[x] = Number(f[x]));
298
- const D = w(`${f.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
299
- f.status = f.sp > 4 ? 0 : 1;
300
- const { labelEn: S, labelCn: A } = this.parseStatus(f.status), H = {
301
- mmsi: f.m,
302
- name: f.n,
294
+ const v = b(`${(M = C == null ? void 0 : C[0]) == null ? void 0 : M.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
295
+ for (const u of C) {
296
+ for (const P in u)
297
+ !isNaN(u[P]) && Number(u[P]) !== 1 / 0 && (u[P] = Number(u[P]));
298
+ const I = b(`${u.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
299
+ u.status = u.sp > 4 ? 0 : 1;
300
+ const { labelEn: F, labelCn: D } = this.parseStatus(u.status), Y = {
301
+ mmsi: u.m,
302
+ name: u.n,
303
303
  imo: d == null ? void 0 : d.imo,
304
- lat: f.la,
305
- lng: f.lo,
306
- draught: f.draught,
307
- sog: f.sp,
308
- cog: f.co,
309
- hdg: f.hdg,
310
- positionTime: D.unix(),
311
- utc: D.utc().format(),
312
- status: f.status,
313
- labelCn: A,
314
- labelEn: S,
304
+ lat: u.la,
305
+ lng: u.lo,
306
+ draught: u.draught,
307
+ sog: u.sp,
308
+ cog: u.co,
309
+ hdg: u.hdg,
310
+ positionTime: I.unix(),
311
+ utc: I.utc().format(),
312
+ status: u.status,
313
+ labelCn: D,
314
+ labelEn: F,
315
315
  method: "trajectory",
316
316
  vendor: "hifleet"
317
- }, T = Math.floor(D.diff(v, "minute", !0) / (o || 1));
318
- T !== p && (p = T, k.push(H));
317
+ }, E = Math.floor(I.diff(v, "minute", !0) / (o || 1));
318
+ E !== p && (p = E, k.push(Y));
319
319
  }
320
320
  return k;
321
321
  }
322
322
  }
323
- class Yt extends $ {
323
+ class jt extends tt {
324
324
  constructor(t) {
325
325
  super();
326
- _(this, "token");
326
+ G(this, "token");
327
327
  this.token = t;
328
328
  }
329
329
  async realTimePosition(t, n = {}) {
@@ -339,7 +339,7 @@ class Yt extends $ {
339
339
  const s = a.data[0];
340
340
  for (const l in s)
341
341
  !isNaN(s[l]) && Number(s[l]) !== 1 / 0 && (s[l] = Number(s[l]));
342
- const { labelCn: d, labelEn: c } = await this.parseStatus(s.navistat), u = w.unix(s.lasttime);
342
+ const { labelCn: d, labelEn: r } = await this.parseStatus(s.navistat), h = b.unix(s.lasttime);
343
343
  return {
344
344
  mmsi: s.ShipID,
345
345
  name: s.name,
@@ -355,9 +355,9 @@ class Yt extends $ {
355
355
  hdg: Math.round(s.hdg / 100 * 100) / 100,
356
356
  rot: Math.round(s.rot / 100 * 100) / 100,
357
357
  positionTime: s.lasttime,
358
- utc: u.utc().format(),
358
+ utc: h.utc().format(),
359
359
  status: s.navistat,
360
- labelEn: c,
360
+ labelEn: r,
361
361
  labelCn: d,
362
362
  method: "position",
363
363
  vendor: "shipxy"
@@ -365,42 +365,42 @@ class Yt extends $ {
365
365
  }
366
366
  async trajectory(t, n, i, o, a = !0, s = {}) {
367
367
  var v;
368
- const d = await this.realTimePosition(t, s), c = w(n), u = w(i), y = "https://api.shipxy.com/apicall/GetShipTrack", l = {
368
+ const d = await this.realTimePosition(t, s), r = b(n), h = b(i), m = "https://api.shipxy.com/apicall/GetShipTrack", l = {
369
369
  searchParams: {
370
370
  id: t,
371
371
  k: this.token,
372
372
  enc: 1,
373
373
  cut: 0,
374
- btm: c.unix(),
375
- etm: u.unix()
374
+ btm: r.unix(),
375
+ etm: h.unix()
376
376
  }
377
- }, M = await V.get(y, l).json();
378
- if (g == null || g.info("[%s] fetch trajectory from: %s - %j", s.requestId, y, l), (M == null ? void 0 : M.status) !== 0)
379
- return M;
380
- const m = M == null ? void 0 : M.points, C = [], k = w.unix((v = m[0]) == null ? void 0 : v.utc);
377
+ }, y = await V.get(m, l).json();
378
+ if (g == null || g.info("[%s] fetch trajectory from: %s - %j", s.requestId, m, l), (y == null ? void 0 : y.status) !== 0)
379
+ return y;
380
+ const f = y == null ? void 0 : y.points, C = [], k = b.unix((v = f[0]) == null ? void 0 : v.utc);
381
381
  let p = -1;
382
- for (const r of m) {
383
- const h = w.unix(r.utc), b = {
382
+ for (const c of f) {
383
+ const w = b.unix(c.utc), M = {
384
384
  imo: d == null ? void 0 : d.imo,
385
385
  mmsi: t,
386
- sog: Math.round(r.sog * 3600 / 1e3 / 1852 * 100) / 100,
387
- cog: Math.round(r.cog / 100 * 100) / 100,
388
- lat: Math.round(r.lat / 1e6 * 1e5) / 1e5,
389
- lng: Math.round(r.lon / 1e6 * 1e5) / 1e5,
390
- positionTime: h.unix(),
391
- utc: h.utc().format(),
386
+ sog: Math.round(c.sog * 3600 / 1e3 / 1852 * 100) / 100,
387
+ cog: Math.round(c.cog / 100 * 100) / 100,
388
+ lat: Math.round(c.lat / 1e6 * 1e5) / 1e5,
389
+ lng: Math.round(c.lon / 1e6 * 1e5) / 1e5,
390
+ positionTime: w.unix(),
391
+ utc: w.utc().format(),
392
392
  method: "trajectory",
393
393
  vendor: "shipxy"
394
- }, f = Math.floor(h.diff(k, "minute", !0) / (o || 1));
395
- f !== p && (p = f, C.push(b));
394
+ }, u = Math.floor(w.diff(k, "minute", !0) / (o || 1));
395
+ u !== p && (p = u, C.push(M));
396
396
  }
397
397
  return C;
398
398
  }
399
399
  }
400
- class jt extends $ {
400
+ class Et extends tt {
401
401
  constructor(t) {
402
402
  super();
403
- _(this, "token");
403
+ G(this, "token");
404
404
  this.token = t;
405
405
  }
406
406
  async getShipId(t, n = {}) {
@@ -447,37 +447,37 @@ class jt extends $ {
447
447
  }
448
448
  }, s = "https://api3.myships.com/sp/ships/position/latest", d = await V.post(s, a).json();
449
449
  g == null || g.info("[%s] fetch realtime position from: %s - %j", n.requestId, s, a);
450
- const c = d.data[0];
451
- for (const m in c)
452
- !isNaN(c[m]) && Number(c[m]) !== 1 / 0 && (c[m] = Number(c[m]));
453
- const { labelCn: u, labelEn: y } = await this.parseStatus(c.aisNavStatus), l = w.unix(c.posTime);
450
+ const r = d.data[0];
451
+ for (const f in r)
452
+ !isNaN(r[f]) && Number(r[f]) !== 1 / 0 && (r[f] = Number(r[f]));
453
+ const { labelCn: h, labelEn: m } = await this.parseStatus(r.aisNavStatus), l = b.unix(r.posTime);
454
454
  return {
455
455
  ...o,
456
456
  mmsi: t,
457
- lat: Math.round(c.lat / 1e4 / 60 * 1e5) / 1e5,
458
- lng: Math.round(c.lon / 1e4 / 60 * 1e5) / 1e5,
459
- sog: Math.round(c.sog / 10 * 100) / 100,
460
- cog: Math.round(c.cog / 10 * 100) / 100,
461
- hdg: Math.round(c.heading * 100) / 100,
462
- rot: Math.round(c.rot * 100) / 100,
463
- positionTime: c.posTime,
457
+ lat: Math.round(r.lat / 1e4 / 60 * 1e5) / 1e5,
458
+ lng: Math.round(r.lon / 1e4 / 60 * 1e5) / 1e5,
459
+ sog: Math.round(r.sog / 10 * 100) / 100,
460
+ cog: Math.round(r.cog / 10 * 100) / 100,
461
+ hdg: Math.round(r.heading * 100) / 100,
462
+ rot: Math.round(r.rot * 100) / 100,
463
+ positionTime: r.posTime,
464
464
  utc: l.utc().format(),
465
- status: c.aisNavStatus,
466
- labelEn: y,
467
- labelCn: u,
465
+ status: r.aisNavStatus,
466
+ labelEn: m,
467
+ labelCn: h,
468
468
  method: "position",
469
469
  vendor: "myship"
470
470
  };
471
471
  }
472
472
  async trajectory(t, n, i, o, a = !0, s = {}) {
473
- const d = w(n), c = w(i), u = await this.getShipId(t), y = await this.getShipInfo(u), l = [];
474
- for (; c.diff(d, "day", !0) > 30; )
475
- await this.trajectoryIn30Day(u, d.unix(), d.add(30, "day").unix(), y, t, o, l);
476
- return await this.trajectoryIn30Day(u, d.unix(), c.unix(), y, t, o, l), l;
473
+ const d = b(n), r = b(i), h = await this.getShipId(t), m = await this.getShipInfo(h), l = [];
474
+ for (; r.diff(d, "day", !0) > 30; )
475
+ await this.trajectoryIn30Day(h, d.unix(), d.add(30, "day").unix(), m, t, o, l);
476
+ return await this.trajectoryIn30Day(h, d.unix(), r.unix(), m, t, o, l), l;
477
477
  }
478
- async trajectoryIn30Day(t, n, i, o, a, s, d, c = {}) {
478
+ async trajectoryIn30Day(t, n, i, o, a, s, d, r = {}) {
479
479
  var k;
480
- const u = {
480
+ const h = {
481
481
  headers: {
482
482
  appKey: this.token
483
483
  },
@@ -486,16 +486,16 @@ class jt extends $ {
486
486
  startTime: n,
487
487
  endTime: i
488
488
  }
489
- }, y = "https://api3.myships.com/sp/ships/position/history", l = await V.post(y, u).json();
490
- if (g == null || g.info("[%s] fetch trajectory from: %s - %j", c.requestId, y, u), l.code !== "0")
491
- return g == null || g.warn("[%s] invoke myship trajectory failed: %j", c.requestId, l), l;
492
- const M = l.data;
493
- for (const p in M)
494
- !isNaN(M[p]) && Number(M[p]) !== 1 / 0 && (M[p] = Number(M[p]));
495
- const m = w.unix((k = M[0]) == null ? void 0 : k.posTime);
489
+ }, m = "https://api3.myships.com/sp/ships/position/history", l = await V.post(m, h).json();
490
+ if (g == null || g.info("[%s] fetch trajectory from: %s - %j", r.requestId, m, h), l.code !== "0")
491
+ return g == null || g.warn("[%s] invoke myship trajectory failed: %j", r.requestId, l), l;
492
+ const y = l.data;
493
+ for (const p in y)
494
+ !isNaN(y[p]) && Number(y[p]) !== 1 / 0 && (y[p] = Number(y[p]));
495
+ const f = b.unix((k = y[0]) == null ? void 0 : k.posTime);
496
496
  let C = -1;
497
- for (const p of M) {
498
- const v = w.unix(p.posTime), r = {
497
+ for (const p of y) {
498
+ const v = b.unix(p.posTime), c = {
499
499
  imo: o == null ? void 0 : o.imo,
500
500
  mmsi: a,
501
501
  lat: Math.round(p.lat / 1e4 / 60 * 1e5) / 1e5,
@@ -508,20 +508,20 @@ class jt extends $ {
508
508
  utc: v.utc().format(),
509
509
  method: "trajectory",
510
510
  vendor: "myship"
511
- }, h = Math.floor(v.diff(m, "minute", !0) / (s || 1));
512
- h !== C && (C = h, d.push(r));
511
+ }, w = Math.floor(v.diff(f, "minute", !0) / (s || 1));
512
+ w !== C && (C = w, d.push(c));
513
513
  }
514
514
  return d;
515
515
  }
516
516
  }
517
517
  let B;
518
518
  try {
519
- B = at.getLogger("vessel");
519
+ B = ot.getLogger("vessel");
520
520
  } catch {
521
521
  } finally {
522
522
  }
523
- var lt = /* @__PURE__ */ ((Y) => (Y.NOTICE = "NOTICE", Y.WARN = "WARN", Y.HEAVY = "HEAVY", Y.SEVERE = "SEVERE", Y.ERROR = "ERROR", Y.FATAL = "FATAL", Y))(lt || {});
524
- class ft {
523
+ var ft = /* @__PURE__ */ ((x) => (x.NOTICE = "NOTICE", x.WARN = "WARN", x.HEAVY = "HEAVY", x.SEVERE = "SEVERE", x.ERROR = "ERROR", x.FATAL = "FATAL", x))(ft || {});
524
+ class mt {
525
525
  /**
526
526
  * 解析告警规则, 多规则场景
527
527
  * @param rule
@@ -531,20 +531,20 @@ class ft {
531
531
  * @param options
532
532
  */
533
533
  parsePrinciple(e, t = {}) {
534
- var s, d, c;
534
+ var s, d, r;
535
535
  B == null || B.info("[%s] parse rule: %s", t.requestId, e);
536
536
  const n = new RegExp("(?<=\\[)(.+)(?=])", "g"), i = e.match(n) ? (s = e.match(n)) == null ? void 0 : s[0] : void 0, o = i == null ? void 0 : i.split(";");
537
537
  if (!o)
538
538
  return;
539
539
  const a = {};
540
- for (let u = 0; u < (o == null ? void 0 : o.length); u++) {
541
- const y = (c = (d = o[u].match(n)) == null ? void 0 : d[0]) == null ? void 0 : c.split("],");
542
- if (u === 0 && !y)
540
+ for (let h = 0; h < (o == null ? void 0 : o.length); h++) {
541
+ const m = (r = (d = o[h].match(n)) == null ? void 0 : d[0]) == null ? void 0 : r.split("],");
542
+ if (h === 0 && !m)
543
543
  a.scope = o[0];
544
- else if (y)
545
- for (let l = 0, M = y.length; l < M; l++) {
546
- const m = this.parseRule(y[l]);
547
- m && (a[m.level] ? m.key ? a[m.level][m == null ? void 0 : m.key] = m : a[m.level] = m : m.key ? a[m.level] = { [m == null ? void 0 : m.key]: m } : a[m.level] = m);
544
+ else if (m)
545
+ for (let l = 0, y = m.length; l < y; l++) {
546
+ const f = this.parseRule(m[l]);
547
+ f && (a[f.level] ? f.key ? a[f.level][f == null ? void 0 : f.key] = f : a[f.level] = f : f.key ? a[f.level] = { [f == null ? void 0 : f.key]: f } : a[f.level] = f);
548
548
  }
549
549
  }
550
550
  return a;
@@ -575,26 +575,26 @@ class ft {
575
575
  * @param options
576
576
  */
577
577
  checkWeather(e, t, n = {}) {
578
- var m, C, k, p, v, r, h, b, f, D, S, A, H, T, x;
578
+ var f, C, k, p, v, c, w, M, u, I, F, D, Y, E, P;
579
579
  let i = 0, o = 0, a = 0, s = 0;
580
- const d = Math.round(((C = (m = t == null ? void 0 : t.SEVERE) == null ? void 0 : m.sigWave) == null ? void 0 : C.number) * 1.6 * 100) / 100, c = (p = (k = t == null ? void 0 : t.SEVERE) == null ? void 0 : k.sigWave) == null ? void 0 : p.number, u = (r = (v = t == null ? void 0 : t.HEAVY) == null ? void 0 : v.sigWave) == null ? void 0 : r.number, y = Math.round((((b = (h = t == null ? void 0 : t.SEVERE) == null ? void 0 : h.wind) == null ? void 0 : b.number) + 2) * 100) / 100, l = (D = (f = t == null ? void 0 : t.SEVERE) == null ? void 0 : f.wind) == null ? void 0 : D.number, M = (A = (S = t == null ? void 0 : t.HEAVY) == null ? void 0 : S.wind) == null ? void 0 : A.number;
581
- for (let W = 0; W < (e == null ? void 0 : e.length); W++) {
582
- const j = e[W], F = (T = (H = j == null ? void 0 : j.meteo) == null ? void 0 : H.wave) == null ? void 0 : T.sig, L = (x = j == null ? void 0 : j.meteo) == null ? void 0 : x.wind, Z = W ? w(j.eta).diff(w(e[W - 1].eta), "hour", !0) : 0;
583
- s = Z > s ? Z : s, B == null || B.info("[%s] check sig.wave: %j", n.requestId, { ...F, dgThd4Wv: d, svThd4Wv: c, hvThd4Wv: u }), (F == null ? void 0 : F.height) >= d ? j.isDangerous = !0 : (F == null ? void 0 : F.height) >= c ? j.isSevere = !0 : (F == null ? void 0 : F.height) >= u && (j.isHeavy = !0), B == null || B.info("[%s] check wind: %j", n.requestId, { ...L, dgThd4Wd: y, svThd4Wd: l, hvThd4Wd: M }), (L == null ? void 0 : L.scale) >= y ? (j.isDangerous = !0, delete j.isSevere, delete j.isHeavy) : (L == null ? void 0 : L.scale) > l ? (j.isDangerous || (j.isSevere = !0), delete j.isHeavy) : (L == null ? void 0 : L.scale) === M && !j.isDangerous && !j.isSevere && (j.isHeavy = !0), i += j.isDangerous ? Z : 0, o += j.isSevere ? Z : 0, a += j.isHeavy ? Z : 0;
580
+ const d = Math.round(((C = (f = t == null ? void 0 : t.SEVERE) == null ? void 0 : f.sigWave) == null ? void 0 : C.number) * 1.6 * 100) / 100, r = (p = (k = t == null ? void 0 : t.SEVERE) == null ? void 0 : k.sigWave) == null ? void 0 : p.number, h = (c = (v = t == null ? void 0 : t.HEAVY) == null ? void 0 : v.sigWave) == null ? void 0 : c.number, m = Math.round((((M = (w = t == null ? void 0 : t.SEVERE) == null ? void 0 : w.wind) == null ? void 0 : M.number) + 2) * 100) / 100, l = (I = (u = t == null ? void 0 : t.SEVERE) == null ? void 0 : u.wind) == null ? void 0 : I.number, y = (D = (F = t == null ? void 0 : t.HEAVY) == null ? void 0 : F.wind) == null ? void 0 : D.number;
581
+ for (let N = 0; N < (e == null ? void 0 : e.length); N++) {
582
+ const j = e[N], A = (E = (Y = j == null ? void 0 : j.meteo) == null ? void 0 : Y.wave) == null ? void 0 : E.sig, R = (P = j == null ? void 0 : j.meteo) == null ? void 0 : P.wind, K = N ? b(j.eta).diff(b(e[N - 1].eta), "hour", !0) : 0;
583
+ s = K > s ? K : s, B == null || B.info("[%s] check sig.wave: %j", n.requestId, { ...A, dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: h }), (A == null ? void 0 : A.height) >= d ? j.isDangerous = !0 : (A == null ? void 0 : A.height) >= r ? j.isSevere = !0 : (A == null ? void 0 : A.height) >= h && (j.isHeavy = !0), B == null || B.info("[%s] check wind: %j", n.requestId, { ...R, dgThd4Wd: m, svThd4Wd: l, hvThd4Wd: y }), (R == null ? void 0 : R.scale) >= m ? (j.isDangerous = !0, delete j.isSevere, delete j.isHeavy) : (R == null ? void 0 : R.scale) > l ? (j.isDangerous || (j.isSevere = !0), delete j.isHeavy) : (R == null ? void 0 : R.scale) === y && !j.isDangerous && !j.isSevere && (j.isHeavy = !0), i += j.isDangerous ? K : 0, o += j.isSevere ? K : 0, a += j.isHeavy ? K : 0;
584
584
  }
585
- return i = Math.round(i * 100) / 100, o = Math.round(o * 100) / 100, a = Math.round(a * 100) / 100, s = Math.round(s), { sample: e, dangerous: i, severe: o, heavy: a, step: s < 3 ? 3 : s, wind: { dgThd4Wd: y, svThd4Wd: l, hvThd4Wd: M }, sig: { dgThd4Wv: d, svThd4Wv: c, hvThd4Wv: u } };
585
+ return i = Math.round(i * 100) / 100, o = Math.round(o * 100) / 100, a = Math.round(a * 100) / 100, s = Math.round(s), { sample: e, dangerous: i, severe: o, heavy: a, step: s < 3 ? 3 : s, wind: { dgThd4Wd: m, svThd4Wd: l, hvThd4Wd: y }, sig: { dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: h } };
586
586
  }
587
587
  }
588
- const Dt = new ft();
589
- let I;
588
+ const Nt = new mt();
589
+ let S;
590
590
  try {
591
- I = at.getLogger("vessel");
591
+ S = ot.getLogger("vessel");
592
592
  } catch {
593
593
  } finally {
594
594
  }
595
- const mt = new ut("", !0);
596
- var yt = /* @__PURE__ */ ((Y) => (Y.common = "common", Y.container = "container", Y.tugs = "tugs", Y))(yt || {}), Mt = /* @__PURE__ */ ((Y) => (Y.Ballast = "Ballast", Y.Laden = "Laden", Y))(Mt || {}), gt = /* @__PURE__ */ ((Y) => (Y.Cp = "CP", Y.Perf = "Basis", Y.Instruct = "Other", Y))(gt || {});
597
- class q {
595
+ const yt = new ht("", !0);
596
+ var Mt = /* @__PURE__ */ ((x) => (x.common = "common", x.container = "container", x.tugs = "tugs", x))(Mt || {}), gt = /* @__PURE__ */ ((x) => (x.Ballast = "Ballast", x.Laden = "Laden", x))(gt || {}), bt = /* @__PURE__ */ ((x) => (x.Cp = "CP", x.Perf = "Basis", x.Instruct = "Other", x))(bt || {});
597
+ class O {
598
598
  /**
599
599
  * @see https://baike.baidu.com/item/%E6%96%B9%E5%BD%A2%E7%B3%BB%E6%95%B0/4965568?fr=aladdin
600
600
  * 方形系数(block coefficient)
@@ -707,9 +707,9 @@ class q {
707
707
  */
708
708
  static assembleProperties(e, t, n, i) {
709
709
  var l;
710
- const o = e.lbp ?? e.length ?? e.lengthOverall ?? 198.9642, a = e.draught ?? 8, s = e.breadthMoulded ?? e.breadth ?? e.breadthExtreme ?? 32.4572, d = e.deadweight ?? 67035.7773, c = ((l = e == null ? void 0 : e.type) == null ? void 0 : l.toLowerCase()) || "common";
710
+ const o = e.lbp ?? e.length ?? e.lengthOverall ?? 198.9642, a = e.draught ?? 8, s = e.breadthMoulded ?? e.breadth ?? e.breadthExtreme ?? 32.4572, d = e.deadweight ?? 67035.7773, r = ((l = e == null ? void 0 : e.type) == null ? void 0 : l.toLowerCase()) || "common";
711
711
  return {
712
- tag: c.indexOf("container") > -1 ? "container" : c.indexOf("tugs") > -1 ? "tugs" : "common",
712
+ tag: r.indexOf("container") > -1 ? "container" : r.indexOf("tugs") > -1 ? "tugs" : "common",
713
713
  lbp: o,
714
714
  loadCondition: t,
715
715
  draught: a,
@@ -733,36 +733,36 @@ class q {
733
733
  * @param useRouteParam true 启用设置速度
734
734
  */
735
735
  static async speedLoseAt(e, t, n, i = "", o = 2, a = !0, s = !1, d = {}) {
736
- let c;
736
+ let r;
737
737
  if (t.velocity && s && (e.speed = J.roundPrecision(t.velocity * 1852 / 3600, 6)), a) {
738
- let u;
738
+ let h;
739
739
  if (d.meteo2)
740
740
  try {
741
- const m = await mt.spotForecast(t.lat, t.lng, n.utc().format(), !1, !1, !0, d), [C] = ct.pickHourly(m, n);
742
- u = ct.toLegacy(C);
743
- } catch (m) {
744
- I.warn("[%s] meteo2 spot(%j) forecast failed: %s", d.requestId, { ...t, eta: n.utc().format() }, m);
741
+ const f = await yt.spotForecast(t.lat, t.lng, n.utc().format(), !1, !1, !0, d), [C] = rt.pickHourly(f, n);
742
+ h = rt.toLegacy(C);
743
+ } catch (f) {
744
+ S.warn("[%s] meteo2 spot(%j) forecast failed: %s", d.requestId, { ...t, eta: n.utc().format() }, f);
745
745
  }
746
746
  else
747
- u = await ht.queryPointFactor(t.lng, t.lat, n.valueOf(), "wind,wave,current,watertemp", i, d);
748
- const y = q.weatherFactor(e, u), l = q.currentFactor(e.bearing, u == null ? void 0 : u.current, o), M = Math.round((e.speed * 1.943844 + y + l) * 100) / 100;
749
- c = {
750
- meteo: { ...u },
751
- wxFactor: y,
747
+ h = await lt.queryPointFactor(t.lng, t.lat, n.valueOf(), "wind,wave,current,watertemp", i, d);
748
+ const m = O.weatherFactor(e, h), l = O.currentFactor(e.bearing, h == null ? void 0 : h.current, o), y = Math.round((e.speed * 1.943844 + m + l) * 100) / 100;
749
+ r = {
750
+ meteo: { ...h },
751
+ wxFactor: m,
752
752
  cFactor: l,
753
- speed: t.velocity && s ? t.velocity : M < 0 ? 1 : M,
754
- eta: n.utc().format("YYYY-MM-DDTHH:mm[Z]"),
755
- etd: n.utc().format("YYYY-MM-DDTHH:mm[Z]")
753
+ speed: t.velocity && s ? t.velocity : y < 0 ? 1 : y,
754
+ eta: n.utc().format(),
755
+ etd: n.utc().format()
756
756
  };
757
757
  } else
758
- c = {
758
+ r = {
759
759
  wxFactor: 0,
760
760
  cFactor: 0,
761
761
  speed: t.velocity && s ? t.velocity : Math.round((e.speed * 1.943844 + 0 + 0) * 100) / 100,
762
- eta: n.utc().format("YYYY-MM-DDTHH:mm[Z]"),
763
- etd: n.utc().format("YYYY-MM-DDTHH:mm[Z]")
762
+ eta: n.utc().format(),
763
+ etd: n.utc().format()
764
764
  };
765
- return delete t.meteo, delete t.wxFactor, delete t.cFactor, delete t.speed, delete t.etd, { ...c, ...t };
765
+ return delete t.meteo, delete t.wxFactor, delete t.cFactor, delete t.speed, delete t.etd, { ...r, ...t };
766
766
  }
767
767
  /**
768
768
  * 基于步长计算失速样本
@@ -777,53 +777,53 @@ class q {
777
777
  * @param useRouteParam true 启用航线上设置的参数 { suspend: 停留时长(小时), velocity: 速度(kts)}
778
778
  * @private
779
779
  */
780
- static async speedLoseInHoursStep(e, t, n, i, o, a, s = "", d = !0, c = !1, u = {}) {
780
+ static async speedLoseInHoursStep(e, t, n, i, o, a, s = "", d = !0, r = !1, h = {}) {
781
781
  t.utc();
782
- const y = t.clone().add(14, "days"), l = [], M = [];
783
- let m = 0, C = 0, k, p;
782
+ const m = t.clone().add(14, "days"), l = [], y = [];
783
+ let f = 0, C = 0, k, p;
784
784
  for (let v = 0; v < a.length - 1; v++) {
785
- let r = a[v];
786
- r.distanceFromStart = Math.round((o + C) * 1e4) / 1e4;
787
- const h = a[v + 1];
788
- if (e.bearing = R.calculateBearing(r, h, !h.gcToPrevious), r.bearing = e.bearing, r.suspend && c) {
789
- r.eta = r.eta || t.format("YYYY-MM-DDTHH:mm[Z]"), r.elapsed = r.elapsed ?? 0;
790
- const D = r.suspend - r.elapsed;
791
- if (i - m > D)
792
- i = i - m - D, t.add(D, "hour"), r.elapsed = r.suspend;
785
+ let c = a[v];
786
+ c.distanceFromStart = Math.round((o + C) * 1e4) / 1e4;
787
+ const w = a[v + 1];
788
+ if (e.bearing = W.calculateBearing(c, w, !w.gcToPrevious), c.bearing = e.bearing, c.suspend && r) {
789
+ c.eta = c.eta || t.utc().format(), c.elapsed = c.elapsed ?? 0;
790
+ const I = c.suspend - c.elapsed;
791
+ if (i - f > I)
792
+ i = i - f - I, t.add(I, "hour"), c.elapsed = c.suspend;
793
793
  else {
794
- const S = i - m;
795
- r.elapsed += S, t.add(S, "hour"), i = 0;
794
+ const F = i - f;
795
+ c.elapsed += F, t.add(F, "hour"), i = 0;
796
796
  }
797
- if (I == null || I.info(`[%s] suspend ${r.elapsed} hours at %j, and remain ${i} hours need to go...`, u.requestId, r), i === 0)
798
- return r.distanceFromPrevious = C, { etd: t, from: p || r, to: r, next: a.filter((S) => S), wps: l, days: M };
797
+ if (S == null || S.info(`[%s] suspend ${c.elapsed} hours at %j, and remain ${i} hours need to go...`, h.requestId, c), i === 0)
798
+ return c.distanceFromPrevious = C, { etd: t, from: p || c, to: c, next: a.filter((F) => F), wps: l, days: y };
799
799
  } else
800
- r.suspend = 0;
801
- d = t.isAfter(y) ? !1 : d, r = await q.speedLoseAt(e, r, t, s, 0, d, c, u), p = p || r, r.important && l.push(r), t.isSameOrAfter(n) && (M.push(r), n.add(24, "hour"));
802
- const b = R.calculateDistance(r, h, !h.gcToPrevious);
803
- let f = Math.ceil(b / p.speed * 1e4) / 1e4;
804
- if (m + f < i) {
805
- if (m += f, t.add(f, "hour"), delete a[v], I == null || I.debug(
806
- `[%s] go to %j from %j with ${b}nm, and cost ${f} hours`,
807
- u.requestId,
808
- { lat: h.lat, lng: h.lng },
800
+ c.suspend = 0;
801
+ d = t.isAfter(m) ? !1 : d, c = await O.speedLoseAt(e, c, t, s, 0, d, r, h), p = p || c, c.important && l.push(c), t.isSameOrAfter(n) && (y.push(c), n.add(24, "hour"));
802
+ const M = W.calculateDistance(c, w, !w.gcToPrevious);
803
+ let u = Math.round(M / p.speed * 1e5) / 1e5;
804
+ if (f + u < i) {
805
+ if (f += u, t.add(u, "hour"), delete a[v], S == null || S.debug(
806
+ `[%s] go to %j from %j with ${M}nm, and cost ${u} hours`,
807
+ h.requestId,
808
+ { lat: w.lat, lng: w.lng },
809
809
  { lat: p.lat, lng: p.lng, etd: p.etd }
810
- ), C += b, a.filter((D) => D).length <= 1) {
811
- k = h, k.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), k.distanceFromPrevious = b, k.distanceFromStart = Math.round((o + C) * 1e4) / 1e4, l.push(k), delete a[v + 1];
810
+ ), C += M, a.filter((I) => I).length <= 1) {
811
+ k = w, k.eta = t.utc().format(), k.distanceFromPrevious = M, k.distanceFromStart = Math.round((o + C) * 1e4) / 1e4, l.push(k), delete a[v + 1];
812
812
  break;
813
813
  }
814
814
  } else {
815
- f = i - m, t.add(f, "hour");
816
- const D = J.roundPrecision(p.speed * f, 4);
817
- k = R.calculateCoordinate(r, e.bearing, D, "nauticalmiles", !h.gcToPrevious), k.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), a[v] = k, I == null || I.debug(
818
- `[%s] go to %j from %j with ${D}nm, and cost ${f} hours`,
819
- u.requestId,
815
+ u = i - f, t.add(u, "hour");
816
+ const I = J.roundPrecision(p.speed * u, 5);
817
+ k = W.calculateCoordinate(c, e.bearing, I, "nauticalmiles", !w.gcToPrevious), k.eta = t.utc().format(), a[v] = k, S == null || S.debug(
818
+ `[%s] go to %j from %j with ${I}nm, and cost ${u} hours`,
819
+ h.requestId,
820
820
  { lat: k.lat, lng: k.lng },
821
- { lat: r.lat, lng: r.lng, etd: r.etd }
822
- ), C += D, k.distanceFromPrevious = Math.round(C * 1e4) / 1e4, k.distanceFromStart = Math.round((o + C) * 1e4) / 1e4;
821
+ { lat: c.lat, lng: c.lng, etd: c.etd }
822
+ ), C += I, k.distanceFromPrevious = Math.round(C * 1e4) / 1e4, k.distanceFromStart = Math.round((o + C) * 1e4) / 1e4;
823
823
  break;
824
824
  }
825
825
  }
826
- return { etd: t, from: p, to: k, next: a.filter((v) => v), wps: l, days: M };
826
+ return { etd: t, from: p, to: k, next: a.filter((v) => v), wps: l, days: y };
827
827
  }
828
828
  /**
829
829
  * 洋流影响因子
@@ -844,16 +844,16 @@ class q {
844
844
  * @param wwc 气象要素
845
845
  */
846
846
  static weatherFactor(e, t) {
847
- var y, l, M, m, C, k, p;
848
- I == null || I.debug("calculate weather factor via: %j", { ...e, ...t });
849
- const n = q.blockCoefficient(e.displacement, e.lbp, e.breadthMoulded, e.draught), i = q.froudeNumber(e.speed, e.lbp), o = q.amendFactor(n, i, e.loadCondition);
850
- let a = Math.abs(e.bearing % 360 - (((y = t == null ? void 0 : t.wind) == null ? void 0 : y.degree) % 360 || 0));
847
+ var m, l, y, f, C, k, p;
848
+ S == null || S.debug("calculate weather factor via: %j", { ...e, ...t });
849
+ const n = O.blockCoefficient(e.displacement, e.lbp, e.breadthMoulded, e.draught), i = O.froudeNumber(e.speed, e.lbp), o = O.amendFactor(n, i, e.loadCondition);
850
+ let a = Math.abs(e.bearing % 360 - (((m = t == null ? void 0 : t.wind) == null ? void 0 : m.degree) % 360 || 0));
851
851
  a = a > 180 ? 360 - a : a;
852
- const s = q.directionFactor(a, (l = t == null ? void 0 : t.wind) == null ? void 0 : l.scale), d = q.vesselTagFactor(e.displacement, e.loadCondition, e.tag, (M = t == null ? void 0 : t.wind) == null ? void 0 : M.scale);
853
- let c = s * o * d / 100 * e.speed;
854
- c = Math.round(c * 1.943844 * 1e4) / 1e4 * -1, e.tag === "tugs" && Math.abs(c) > 1 && (c = c / (Math.abs(Math.round(c)) + 1)), I == null || I.debug("wind wx factor = %d", c), a = Math.abs(e.bearing % 360 - (((C = (m = t == null ? void 0 : t.wave) == null ? void 0 : m.sig) == null ? void 0 : C.degree) % 360 || 0));
855
- const u = q.waveHeightFactor(((p = (k = t == null ? void 0 : t.wave) == null ? void 0 : k.sig) == null ? void 0 : p.height) ?? 1, a);
856
- return I == null || I.debug("wave wx factor = %d", u), c = c * 0.4 + u, I == null || I.debug("weather factor = %d", c), c = Math.abs(c) > 4 ? 4 * (Math.abs(c) / c) + Math.abs(c) / c * (Math.abs(c) - 4) * 0.1 : c, Math.round((c || 0) * 100) / 100;
852
+ const s = O.directionFactor(a, (l = t == null ? void 0 : t.wind) == null ? void 0 : l.scale), d = O.vesselTagFactor(e.displacement, e.loadCondition, e.tag, (y = t == null ? void 0 : t.wind) == null ? void 0 : y.scale);
853
+ let r = s * o * d / 100 * e.speed;
854
+ r = Math.round(r * 1.943844 * 1e4) / 1e4 * -1, e.tag === "tugs" && Math.abs(r) > 1 && (r = r / (Math.abs(Math.round(r)) + 1)), S == null || S.debug("wind wx factor = %d", r), a = Math.abs(e.bearing % 360 - (((C = (f = t == null ? void 0 : t.wave) == null ? void 0 : f.sig) == null ? void 0 : C.degree) % 360 || 0));
855
+ const h = O.waveHeightFactor(((p = (k = t == null ? void 0 : t.wave) == null ? void 0 : k.sig) == null ? void 0 : p.height) ?? 1, a);
856
+ return S == null || S.debug("wave wx factor = %d", h), r = r * 0.4 + h, S == null || S.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,12 +867,12 @@ class q {
867
867
  * @param useMeteo true 启用气象分析
868
868
  * @param useRouteParam
869
869
  */
870
- static async analyseInstant(e, t, n, i, o, a = "", s = 0, d = !0, c = !1, u = {}) {
871
- var K, G, z, U, Q;
872
- const y = w().valueOf();
870
+ static async analyseInstant(e, t, n, i, o, a = "", s = 0, d = !0, r = !1, h = {}) {
871
+ var z, U, Q, X, Z;
872
+ const m = b().valueOf();
873
873
  e.lng = J.convertToStdLng(e.lng);
874
- const { route: l, waypoints: M } = o.points, m = R.calculateSubRoute(e, l);
875
- if (((K = m[0]) == null ? void 0 : K.length) <= 1)
874
+ const { route: l, waypoints: y } = o.points, f = W.calculateSubRoute(e, l);
875
+ if (((z = f[0]) == null ? void 0 : z.length) <= 1)
876
876
  return;
877
877
  const { v0: C, label: k } = e.sog ? {
878
878
  v0: e.sog,
@@ -882,66 +882,60 @@ class q {
882
882
  v0: i.speed,
883
883
  label: "CP"
884
884
  /* Cp */
885
- }, p = q.assembleProperties(n, i.loadCondition, C, 0), v = M.length ? R.calculateSubWaypoints(e, M) : [];
886
- v.forEach((N) => N.important = !0);
887
- const r = {
885
+ }, p = O.assembleProperties(n, i.loadCondition, C, 0), v = y.length ? W.calculateSubWaypoints(e, y) : [];
886
+ v.forEach((H) => H.important = !0);
887
+ const c = {
888
888
  from: { ...e },
889
- route: m,
889
+ route: f,
890
890
  waypoints: v,
891
891
  v0: C,
892
892
  label: k
893
- }, h = {
893
+ }, w = {
894
894
  hours: [],
895
895
  days: [],
896
896
  wps: []
897
897
  };
898
- s || (R.calculateRouteDistance(m) / i.speed <= 72 ? s = 3 : s = 6);
899
- let b = R.simplifyRouteToCoordinates(m, v, 0), f = 0, D = 0, S = 0, A = 0;
900
- t = w(t).utc();
901
- const H = t.clone();
902
- for (; b.length > 0; ) {
903
- const N = s - t.hour() % s, P = Math.ceil(t.clone().add(N, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4, E = await q.speedLoseInHoursStep(
898
+ s || (W.calculateRouteDistance(f) / i.speed <= 72 ? s = 3 : s = 6);
899
+ let M = W.simplifyRouteToCoordinates(f, v, 0), u = 0, I = 0, F = 0, D = 0;
900
+ t = b(t).utc();
901
+ const Y = t.clone();
902
+ for (; M.length > 0; ) {
903
+ const H = s - t.hour() % s, _ = Math.ceil(t.clone().add(H, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4, T = await O.speedLoseInHoursStep(
904
904
  p,
905
905
  t,
906
- H,
907
- P,
908
- f,
909
- b,
906
+ Y,
907
+ _,
908
+ u,
909
+ M,
910
910
  a,
911
911
  d,
912
- c,
913
- u
912
+ r,
913
+ h
914
914
  );
915
- (G = E.from) != null && G.speed && (h.hours.push(E.from), h.wps.push(...E.wps), h.days.push(...E.days)), b = E == null ? void 0 : E.next, b.length || h.hours.push(E == null ? void 0 : E.to), f += Math.round((((z = E == null ? void 0 : E.to) == null ? void 0 : z.distanceFromPrevious) ?? 0) * 1e4) / 1e4;
915
+ (U = T.from) != null && U.speed && (w.hours.push(T.from), w.wps.push(...T.wps), w.days.push(...T.days)), M = T == null ? void 0 : T.next, M.length || w.hours.push(T == null ? void 0 : T.to), u += Math.round((((Q = T == null ? void 0 : T.to) == null ? void 0 : Q.distanceFromPrevious) ?? 0) * 1e4) / 1e4;
916
916
  }
917
- const T = h.hours;
918
- for (let N = 0; N < T.length - 1; N++) {
919
- const P = w(T[N + 1].eta).diff(T[N].etd, "hour", !0) || 1;
920
- D += (T[N].wxFactor || 0) * P, S += (T[N].cFactor || 0) * P, A += P;
917
+ const E = w.hours;
918
+ for (let H = 0; H < E.length - 1; H++) {
919
+ const _ = b(E[H + 1].eta).diff(E[H].etd, "hour", !0) || 1;
920
+ I += (E[H].wxFactor || 0) * _, F += (E[H].cFactor || 0) * _, D += _;
921
921
  }
922
- (U = h.wps) == null || U.forEach((N, P) => {
923
- if (N.positionTime = w.utc(N.etd || N.eta).unix(), P) {
924
- const E = h.wps[P - 1], O = N.distanceFromStart - E.distanceFromStart, nt = w(N.eta).diff(w(E.etd), "h", !0);
925
- if (nt < 1)
926
- N.avgSpd = E.speed;
927
- else {
928
- N.avgSpd = Math.round(O / nt * 100) / 100;
929
- const it = Math.round((E.speed + N.speed) / 2 * 100) / 100;
930
- N.avgSpd = N.avgSpd > it ? it : N.avgSpd;
931
- }
922
+ (X = w.wps) == null || X.forEach((H, _) => {
923
+ if (H.positionTime = b.utc(H.etd || H.eta).unix(), _) {
924
+ const T = w.wps[_ - 1], L = H.distanceFromStart - T.distanceFromStart, q = b(H.eta).diff(b(T.etd), "h", !0);
925
+ q < 0.5 ? H.avgSpd = T.speed : H.avgSpd = Math.round(L / q * 100) / 100;
932
926
  }
933
- }), r.sample = h;
934
- const x = h.hours.at(0), W = h.hours.at(-1);
935
- r.distance = Math.round(W.distanceFromStart * 1e4) / 1e4, r.etd = w(x.eta).utc().format(), r.eta = w(W.eta).utc().format(), r.wxFactor = Math.round(D / A * 1e4) / 1e4, r.cFactor = Math.round(S / A * 1e4) / 1e4, r.avgSpeed = Math.round(W.distanceFromStart / A * 1e4) / 1e4, r.totalHrs = Math.round(A * 1e4) / 1e4;
936
- const { distanceInECA: j, hoursInECA: F, totalDgoConsInECA: L, eca: Z } = await this.calculateECA(r, i, u), tt = J.roundPrecision(i.fo / 24 * (A - F), 3), et = J.roundPrecision(i.dgo / 24 * A, 3);
937
- r.extend = {
938
- eca: Z,
927
+ }), c.sample = w;
928
+ const P = w.hours.at(0), N = w.hours.at(-1);
929
+ c.distance = Math.round(N.distanceFromStart * 1e4) / 1e4, c.etd = b(P.eta).utc().format(), c.eta = b(N.eta).utc().format(), c.wxFactor = Math.round(I / D * 1e4) / 1e4, c.cFactor = Math.round(F / D * 1e4) / 1e4, c.avgSpeed = Math.round(N.distanceFromStart / D * 1e4) / 1e4, c.totalHrs = Math.round(D * 1e4) / 1e4;
930
+ const { distanceInECA: j, hoursInECA: A, totalDgoConsInECA: R, eca: K } = await this.calculateECA(c, i, h), et = J.roundPrecision(i.fo / 24 * (D - A), 3), st = J.roundPrecision(i.dgo / 24 * D, 3);
931
+ c.extend = {
932
+ eca: K,
939
933
  distanceInECA: j,
940
- hoursInECA: F,
941
- totalDgoConsInECA: L
942
- }, r.totalFoCons = tt, r.totalDgoCons = et;
943
- const X = w().valueOf() - y, st = ((Q = h == null ? void 0 : h.hours) == null ? void 0 : Q.length) || 1;
944
- return I == null || I.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", u == null ? void 0 : u.requestId, X, st, Math.round(X / st * 1e3) / 1e3), r;
934
+ hoursInECA: A,
935
+ totalDgoConsInECA: R
936
+ }, c.totalFoCons = et, c.totalDgoCons = st;
937
+ const $ = b().valueOf() - m, at = ((Z = w == null ? void 0 : w.hours) == null ? void 0 : Z.length) || 1;
938
+ return S == null || S.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", h == null ? void 0 : h.requestId, $, at, Math.round($ / at * 1e3) / 1e3), c;
945
939
  }
946
940
  /**
947
941
  * 分段失速分析(最多走hours 小时)
@@ -956,11 +950,11 @@ class q {
956
950
  * @param useMeteo true 启用气象分析
957
951
  * @param useRouteParam
958
952
  */
959
- static async analyseInstantWithThreshed(e, t, n, i, o, a, s, d = "", c = 3, u = !0, y = !1, l = {}) {
960
- var z, U, Q, N;
961
- const M = w().valueOf();
953
+ static async analyseInstantWithThreshed(e, t, n, i, o, a, s, d = "", r = 3, h = !0, m = !1, l = {}) {
954
+ var Q, X, Z, H, _;
955
+ const y = b().valueOf();
962
956
  e.lng = J.convertToStdLng(e.lng);
963
- const { v0: m, label: C } = e.sog ? {
957
+ const { v0: f, label: C } = e.sog ? {
964
958
  v0: e.sog,
965
959
  label: "Other"
966
960
  /* Instruct */
@@ -968,57 +962,63 @@ class q {
968
962
  v0: o.speed,
969
963
  label: "CP"
970
964
  /* Cp */
971
- }, k = q.assembleProperties(i, o.loadCondition, m, 0), p = R.calculateSubRoute(e, a);
972
- if (((z = p[0]) == null ? void 0 : z.length) <= 1)
965
+ }, k = O.assembleProperties(i, o.loadCondition, f, 0), p = W.calculateSubRoute(e, a);
966
+ if (((Q = p[0]) == null ? void 0 : Q.length) <= 1)
973
967
  return;
974
- const v = s.length ? R.calculateSubWaypoints(e, s) : [];
975
- v.forEach((P) => P.important = !0);
976
- let r = R.simplifyRouteToCoordinates(p, v, 0), h = 0, b = 0, f = 0, D = 0;
977
- const S = {
968
+ const v = s.length ? W.calculateSubWaypoints(e, s) : [];
969
+ v.forEach((T) => T.important = !0);
970
+ let c = W.simplifyRouteToCoordinates(p, v, 0), w = 0, M = 0, u = 0, I = 0;
971
+ const F = {
978
972
  hours: [],
979
973
  wps: [],
980
974
  days: []
981
975
  };
982
- t = w(t).utc();
983
- const A = t.clone();
984
- for (; r.length > 0; ) {
985
- const P = c - t.hour() % c;
986
- let E = Math.ceil(t.clone().add(P, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4;
987
- E = t.clone().add(E, "h").isSameOrAfter(n) ? n.diff(t, "h", !0) * 1e4 / 1e4 : E;
988
- const O = await q.speedLoseInHoursStep(k, t, A, E, h, r, d, u, y, l);
989
- if ((U = O.from) != null && U.speed && (S.hours.push(O.from), O != null && O.wps && S.wps.push(...O.wps), S.days.push(...O.days)), r = O == null ? void 0 : O.next, r.length || S.hours.push(O == null ? void 0 : O.to), h += Math.round((((Q = O == null ? void 0 : O.to) == null ? void 0 : Q.distanceFromPrevious) ?? 0) * 1e4) / 1e4, !E)
976
+ t = b(t).utc();
977
+ const D = t.clone();
978
+ for (; c.length > 0; ) {
979
+ const T = r - t.hour() % r;
980
+ let L = Math.ceil(t.clone().add(T, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4;
981
+ L = t.clone().add(L, "h").isSameOrAfter(n) ? n.diff(t, "h", !0) * 1e4 / 1e4 : L;
982
+ const q = await O.speedLoseInHoursStep(k, t, D, L, w, c, d, h, m, l);
983
+ if ((X = q.from) != null && X.speed && (F.hours.push(q.from), q != null && q.wps && F.wps.push(...q.wps), F.days.push(...q.days)), c = q == null ? void 0 : q.next, c.length || F.hours.push(q == null ? void 0 : q.to), w += Math.round((((Z = q == null ? void 0 : q.to) == null ? void 0 : Z.distanceFromPrevious) ?? 0) * 1e4) / 1e4, !L)
990
984
  break;
991
985
  }
992
- const H = S.hours;
993
- for (let P = 0; P < H.length - 1; P++) {
994
- const E = w(H[P + 1].eta).diff(H[P].etd, "hour", !0);
995
- b += H[P].wxFactor * E, f += H[P].cFactor * E, D += E;
986
+ (H = F.wps) == null || H.forEach((T, L) => {
987
+ if (L) {
988
+ const q = F.wps[L - 1], ct = T.distanceFromStart - q.distanceFromStart, it = b(T.eta).diff(b(q.etd), "h", !0);
989
+ it < 0.5 ? T.avgSpd = q.speed : T.avgSpd = Math.round(ct / it * 100) / 100;
990
+ }
991
+ });
992
+ const Y = F.hours;
993
+ for (let T = 0; T < Y.length - 1; T++) {
994
+ const L = b(Y[T + 1].eta).diff(Y[T].etd, "hour", !0);
995
+ M += Y[T].wxFactor * L, u += Y[T].cFactor * L, I += L;
996
996
  }
997
- const T = S.hours.at(0), x = S.hours.at(-1), W = await R.calculateRangeRoute(T, x, p), j = await R.calculateRangeWaypoints(T, x, p, v), F = {
998
- sample: S,
999
- distance: Math.round(((x == null ? void 0 : x.distanceFromStart) || 0) * 1e4) / 1e4,
997
+ const E = F.hours.at(0), P = F.hours.at(-1), N = await W.calculateRangeRoute(E, P, p), j = await W.calculateRangeWaypoints(E, P, p, v), A = {
998
+ sample: F,
999
+ distance: Math.round(((P == null ? void 0 : P.distanceFromStart) || 0) * 1e4) / 1e4,
1000
1000
  // 注意,可能会在first节点Drift,所有采用eta做为初始出发时间
1001
- etd: w(T.eta).utc().format(),
1002
- eta: w(x == null ? void 0 : x.eta).utc().format(),
1003
- wxFactor: Math.round(b / D * 1e4) / 1e4,
1004
- cFactor: Math.round(f / D * 1e4) / 1e4,
1005
- avgSpeed: Math.round(((x == null ? void 0 : x.distanceFromStart) || 0) / D * 1e4) / 1e4,
1006
- totalHrs: Math.round(D * 1e4) / 1e4,
1007
- from: T,
1008
- to: x,
1009
- route: W,
1001
+ etd: b(E.eta).utc().format(),
1002
+ eta: b(P == null ? void 0 : P.eta).utc().format(),
1003
+ wxFactor: Math.round(M / I * 1e4) / 1e4,
1004
+ cFactor: Math.round(u / I * 1e4) / 1e4,
1005
+ avgSpeed: Math.round(((P == null ? void 0 : P.distanceFromStart) || 0) / I * 1e4) / 1e4,
1006
+ totalHrs: Math.round(I * 1e4) / 1e4,
1007
+ from: E,
1008
+ to: P,
1009
+ route: N,
1010
1010
  waypoints: j,
1011
- v0: m,
1011
+ v0: f,
1012
1012
  label: C
1013
- }, { distanceInECA: L, hoursInECA: Z, totalDgoConsInECA: tt, eca: et } = await this.calculateECA(F, o, l), ot = J.roundPrecision(o.fo / 24 * (D - Z), 3), X = J.roundPrecision(o.dgo / 24 * D, 3);
1014
- F.extend = {
1015
- eca: et,
1016
- distanceInECA: L,
1017
- hoursInECA: Z,
1018
- totalDgoConsInECA: tt
1019
- }, F.totalDgoCons = X, F.totalFoCons = ot;
1020
- const K = w().valueOf() - M, G = ((N = S == null ? void 0 : S.hours) == null ? void 0 : N.length) || 1;
1021
- return I == null || I.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", l == null ? void 0 : l.requestId, K, G, Math.round(K / G * 1e3) / 1e3), F;
1013
+ }, { distanceInECA: R, hoursInECA: K, totalDgoConsInECA: et, eca: st } = await this.calculateECA(A, o, l), nt = J.roundPrecision(o.fo / 24 * (I - K), 3), $ = J.roundPrecision(o.dgo / 24 * I, 3);
1014
+ A.extend = {
1015
+ eca: st,
1016
+ distanceInECA: R,
1017
+ hoursInECA: K,
1018
+ totalDgoConsInECA: et
1019
+ }, A.totalDgoCons = $, A.totalFoCons = nt;
1020
+ const z = b().valueOf() - y, U = ((_ = F == null ? void 0 : F.hours) == null ? void 0 : _.length) || 1;
1021
+ return S == null || S.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", l == null ? void 0 : l.requestId, z, U, Math.round(z / U * 1e3) / 1e3), A;
1022
1022
  }
1023
1023
  /**
1024
1024
  * 在指定航线条件下,基于多CP,动态计算最优成本(租金+油费)方案
@@ -1037,55 +1037,55 @@ class q {
1037
1037
  */
1038
1038
  static async analyseCost(e, t, n, i, o = {}) {
1039
1039
  var p, v;
1040
- const a = w().valueOf(), s = [];
1040
+ const a = b().valueOf(), s = [];
1041
1041
  o.meteo2 = o.meteo2 || !0, e.speedStep = e.speedStep || 3, e.alterStep = e.alterStep ?? 1;
1042
- const d = R.calculateRouteDistance(i.route);
1043
- let c = 0;
1044
- n.forEach((r) => {
1045
- const h = Math.ceil(d / r.speed / 24);
1046
- c = c < h ? h : c;
1047
- }), c = c * 1.3;
1048
- const u = w.utc(e.etd).add(c ?? 14, "day");
1049
- let y = 1;
1050
- for (const r of n) {
1051
- const h = JSON.parse(JSON.stringify(i.route)), b = JSON.parse(JSON.stringify(i.waypoints)), f = await q.analyseInstantWithThreshed(
1042
+ const d = W.calculateRouteDistance(i.route);
1043
+ let r = 0;
1044
+ n.forEach((c) => {
1045
+ const w = Math.ceil(d / c.speed / 24);
1046
+ r = r < w ? w : r;
1047
+ }), r = r * 1.3;
1048
+ const h = b.utc(e.etd).add(r ?? 14, "day");
1049
+ let m = 1;
1050
+ for (const c of n) {
1051
+ const w = JSON.parse(JSON.stringify(i.route)), M = JSON.parse(JSON.stringify(i.waypoints)), u = await O.analyseInstantWithThreshed(
1052
1052
  { lat: e.lat, lng: e.lng },
1053
1053
  e.etd,
1054
- u,
1055
- t,
1056
- r,
1057
1054
  h,
1058
- b,
1055
+ t,
1056
+ c,
1057
+ w,
1058
+ M,
1059
1059
  e.meteoVendor,
1060
1060
  e.speedStep,
1061
1061
  e.useMeteo,
1062
1062
  e.useRouteParam,
1063
1063
  o
1064
1064
  );
1065
- f && (await q.calculateCost(f, r, e, o), s.push(f), I == null || I.info("[%s][L%d-%d] analyse from %s to %s cost: %j", o.requestId, 1, y, e.etd, u.format(), {
1066
- cost: f.cost.total,
1067
- distance: f.distance,
1068
- hours: f.totalHrs,
1069
- cp: `${r.speed}/${r.fo}/${r.dgo}`
1070
- })), y++;
1065
+ u && (await O.calculateCost(u, c, e, o), s.push(u), S == null || S.info("[%s][L%d-%d] analyse from %s to %s cost: %j", o.requestId, 1, m, e.etd, h.format(), {
1066
+ cost: u.cost.total,
1067
+ distance: u.distance,
1068
+ hours: u.totalHrs,
1069
+ cp: `${c.speed}/${c.fo}/${c.dgo}`
1070
+ })), m++;
1071
1071
  }
1072
- s.sort((r, h) => r.cost.total - h.cost.total);
1073
- const l = s.at(0), M = s.at(1), m = [];
1074
- if (m.push({ combined: !1, speeds: [l], cost: (p = l.cost) == null ? void 0 : p.total }), M) {
1075
- const r = l.cost.cp, h = M.cost.cp, b = w(l.eta), f = w(l.etd), D = b.diff(f, "days", !0);
1076
- let S = Math.ceil(D / 2);
1077
- S = S > 7 ? 7 : S < e.alterStep ? e.alterStep : S;
1078
- let A = 2, H = { combined: !1, speeds: [M], cost: (v = M.cost) == null ? void 0 : v.total }, T;
1079
- for (; S >= e.alterStep; ) {
1080
- const x = await q.combinedAnalyse(e, t, u, [r, h], i, S, { ...o, level: A });
1081
- if (H.cost > x.cost ? T ? (T == null ? void 0 : T.cost) > x.cost && (T = x) : (T = H, H = x) : (!T || (T == null ? void 0 : T.cost) > x.cost) && (T = x), S <= e.alterStep)
1072
+ s.sort((c, w) => c.cost.total - w.cost.total);
1073
+ const l = s.at(0), y = s.at(1), f = [];
1074
+ if (f.push({ combined: !1, speeds: [l], cost: (p = l.cost) == null ? void 0 : p.total }), y) {
1075
+ const c = l.cost.cp, w = y.cost.cp, M = b(l.eta), u = b(l.etd), I = M.diff(u, "days", !0);
1076
+ let F = Math.ceil(I / 2);
1077
+ F = F > 7 ? 7 : F < e.alterStep ? e.alterStep : F;
1078
+ let D = 2, Y = { combined: !1, speeds: [y], cost: (v = y.cost) == null ? void 0 : v.total }, E;
1079
+ for (; F >= e.alterStep; ) {
1080
+ const P = await O.combinedAnalyse(e, t, h, [c, w], i, F, { ...o, level: D });
1081
+ if (Y.cost > P.cost ? E ? (E == null ? void 0 : E.cost) > P.cost && (E = P) : (E = Y, Y = P) : (!E || (E == null ? void 0 : E.cost) > P.cost) && (E = P), F <= e.alterStep)
1082
1082
  break;
1083
- S = Math.ceil(S / 2), A += 1;
1083
+ F = Math.ceil(F / 2), D += 1;
1084
1084
  }
1085
- m.push(H), T && m.push(T);
1085
+ f.push(Y), E && f.push(E);
1086
1086
  }
1087
- const k = w().valueOf() - a;
1088
- return I == null || I.info("[%s] analyse elapsed: %d ms", o == null ? void 0 : o.requestId, k), m.sort((r, h) => r.cost - h.cost);
1087
+ const k = b().valueOf() - a;
1088
+ return S == null || S.info("[%s] analyse elapsed: %d ms", o == null ? void 0 : o.requestId, k), f.sort((c, w) => c.cost - w.cost);
1089
1089
  }
1090
1090
  /**
1091
1091
  * 按步长多次减半,分别用7,4,2,1天步长及cpa,cpb交替计算各种组合下的成本
@@ -1098,11 +1098,11 @@ class q {
1098
1098
  * @param options
1099
1099
  */
1100
1100
  static async combinedAnalyse(e, t, n, i, o, a, s = {}) {
1101
- s.counter = 1, I == null || I.info("[%s][L%d] analyse with alternate cp in every %d days", s.requestId, s.level, a);
1102
- const d = await q.alternateAnalyse(e, t, n, i, 0, o, a, s), c = d.reduce((l, M) => l + M.cost.total, 0);
1103
- I == null || I.info("[%s][L%d] cost with cpa/cpb turn: %d", s.requestId, s.level, c);
1104
- const u = await q.alternateAnalyse(e, t, n, i, 1, o, a, s), y = u.reduce((l, M) => l + M.cost.total, 0);
1105
- return I == null || I.info("[%s][L%d] cost with cpb/cpa turn: %d", s.requestId, s.level, y), c < y ? { combined: !0, cost: Math.round(c * 1e3) / 1e3, speeds: d, step: a } : { combined: !0, cost: Math.round(y * 1e3) / 1e3, speeds: u, step: a };
1101
+ s.counter = 1, S == null || S.info("[%s][L%d] analyse with alternate cp in every %d days", s.requestId, s.level, a);
1102
+ const d = await O.alternateAnalyse(e, t, n, i, 0, o, a, s), r = d.reduce((l, y) => l + y.cost.total, 0);
1103
+ S == null || S.info("[%s][L%d] cost with cpa/cpb turn: %d", s.requestId, s.level, r);
1104
+ const h = await O.alternateAnalyse(e, t, n, i, 1, o, a, s), m = h.reduce((l, y) => l + y.cost.total, 0);
1105
+ return S == null || S.info("[%s][L%d] cost with cpb/cpa turn: %d", s.requestId, s.level, m), r < m ? { combined: !0, cost: Math.round(r * 1e3) / 1e3, speeds: d, step: a } : { combined: !0, cost: Math.round(m * 1e3) / 1e3, speeds: h, step: a };
1106
1106
  }
1107
1107
  /**
1108
1108
  * 基于cp索引,交替计算指定步长下的成本
@@ -1116,14 +1116,14 @@ class q {
1116
1116
  * @param options
1117
1117
  */
1118
1118
  static async alternateAnalyse(e, t, n, i, o, a, s, d = {}) {
1119
- var l, M;
1120
- let c = w.utc(e.etd);
1121
- const u = { lat: e.lat, lng: e.lng }, y = [];
1122
- for (; c.isBefore(n); ) {
1123
- const m = c.clone().utc().add(s, "day"), C = JSON.parse(JSON.stringify(a.route)), k = JSON.parse(JSON.stringify(a.waypoints)), p = i[o], v = await q.analyseInstantWithThreshed(
1124
- u,
1125
- c.format(),
1126
- m,
1119
+ var l, y;
1120
+ let r = b.utc(e.etd);
1121
+ const h = { lat: e.lat, lng: e.lng }, m = [];
1122
+ for (; r.isBefore(n); ) {
1123
+ const f = r.clone().utc().add(s, "day"), C = JSON.parse(JSON.stringify(a.route)), k = JSON.parse(JSON.stringify(a.waypoints)), p = i[o], v = await O.analyseInstantWithThreshed(
1124
+ h,
1125
+ r.utc().format(),
1126
+ f,
1127
1127
  t,
1128
1128
  p,
1129
1129
  C,
@@ -1134,22 +1134,22 @@ class q {
1134
1134
  e.useRouteParam,
1135
1135
  d
1136
1136
  );
1137
- v && (await q.calculateCost(v, p, e, d), I == null || I.info(
1137
+ v && (await O.calculateCost(v, p, e, d), S == null || S.info(
1138
1138
  "[%s][L%d-%d] analyse from %s to %s cost: %j",
1139
1139
  d.requestId,
1140
1140
  d.level,
1141
1141
  d.counter,
1142
- c.utc().format(),
1143
- m.utc().format(),
1142
+ r.utc().format(),
1143
+ f.utc().format(),
1144
1144
  { cost: v.cost.total, distance: v.distance, hours: v.totalHrs, cp: `${p.speed}/${p.fo}/${p.dgo}` }
1145
1145
  )), d.counter = d.counter + 1;
1146
- const r = (M = (l = v == null ? void 0 : v.sample) == null ? void 0 : l.hours) == null ? void 0 : M.at(-1);
1147
- if (r)
1148
- u.lat = r.lat, u.lng = r.lng, c = w(r.eta), y.push(v), o = o ? 0 : 1;
1146
+ const c = (y = (l = v == null ? void 0 : v.sample) == null ? void 0 : l.hours) == null ? void 0 : y.at(-1);
1147
+ if (c)
1148
+ h.lat = c.lat, h.lng = c.lng, r = b(c.eta), m.push(v), o = o ? 0 : 1;
1149
1149
  else
1150
1150
  break;
1151
1151
  }
1152
- return y;
1152
+ return m;
1153
1153
  }
1154
1154
  /**
1155
1155
  * 计算Speed的cost
@@ -1175,16 +1175,16 @@ class q {
1175
1175
  * 计算单cp模式下的ECA属性
1176
1176
  */
1177
1177
  static async calculateECA(e, t, n = {}) {
1178
- var d, c;
1179
- const i = await R.intersectInECA(e.route);
1178
+ var d, r;
1179
+ const i = await W.intersectInECA(e.route);
1180
1180
  let o = 0, a = 0, s = 0;
1181
- e.sample.wps.forEach((u) => {
1182
- u.positionTime = w.utc(u.etd || u.eta).unix();
1181
+ e.sample.wps.forEach((h) => {
1182
+ h.positionTime = b.utc(h.etd || h.eta).unix();
1183
1183
  });
1184
- for (const u of i) {
1185
- o += u.distance;
1186
- const y = await R.deadReckoningTime((d = u.waypoints) == null ? void 0 : d.at(0), e.sample.wps), l = await R.deadReckoningTime((c = u.waypoints) == null ? void 0 : c.at(-1), e.sample.wps);
1187
- u.in = y, u.out = l, u.totalHrs = J.roundPrecision((l.positionTime - y.positionTime) / 3600, 2), u.totalDgoCons = J.roundPrecision(t.fo / 24 * u.totalHrs, 3), a += u.totalHrs, s += u.totalDgoCons;
1184
+ for (const h of i) {
1185
+ o += h.distance;
1186
+ const m = await W.deadReckoningTime((d = h.waypoints) == null ? void 0 : d.at(0), e.sample.wps), l = await W.deadReckoningTime((r = h.waypoints) == null ? void 0 : r.at(-1), e.sample.wps);
1187
+ h.in = m, h.out = l, h.totalHrs = J.roundPrecision((l.positionTime - m.positionTime) / 3600, 2), h.totalDgoCons = J.roundPrecision(t.fo / 24 * h.totalHrs, 3), a += h.totalHrs, s += h.totalDgoCons;
1188
1188
  }
1189
1189
  return o = J.roundPrecision(o, 3), a = J.roundPrecision(a, 3), s = J.roundPrecision(s, 3), {
1190
1190
  distanceInECA: o,
@@ -1199,43 +1199,56 @@ class q {
1199
1199
  * @param options
1200
1200
  */
1201
1201
  static async mergeSpeeds(e, t = {}) {
1202
- var v, r;
1202
+ var c, w;
1203
1203
  const n = {
1204
1204
  hours: [],
1205
1205
  wps: [],
1206
1206
  days: []
1207
- }, i = e.reduce((h, b) => h + b.distance, 0), o = e.reduce((h, b) => {
1208
- var f;
1209
- return h + (((f = b.extend) == null ? void 0 : f.distanceInECA) || 0);
1210
- }, 0), a = e.reduce((h, b) => h + b.totalHrs, 0), s = e.reduce((h, b) => {
1211
- var f;
1212
- return h + (((f = b.extend) == null ? void 0 : f.hoursInECA) || 0);
1213
- }, 0), d = e.reduce((h, b) => {
1214
- var f;
1215
- return h + (((f = b.extend) == null ? void 0 : f.totalDgoConsInECA) || 0);
1216
- }, 0), c = e.reduce((h, b) => h + b.wxFactor * b.totalHrs / a, 0), u = e.reduce((h, b) => h + b.cFactor * b.totalHrs / a, 0), y = e.reduce((h, b) => h + b.totalFoCons, 0), l = e.reduce((h, b) => h + b.totalDgoCons, 0), M = e.reduce((h, b) => h + b.cost.total, 0), m = e.reduce((h, b) => h + b.cost.hire, 0), C = e.reduce((h, b) => h + b.cost.bunker, 0), k = [], p = [];
1217
- for (const h of e) {
1218
- p.push(...((v = h.extend) == null ? void 0 : v.eca) || []);
1219
- const b = h.sample.hours, f = b.at(0);
1220
- f.cp = h.cost.cp;
1221
- const D = [h.etd, h.eta], S = k.findIndex((x) => x.id === f.cp.id);
1222
- S === -1 ? (f.cp.segment = [D], k.push(f.cp)) : k[S].segment.push(D);
1223
- const A = h.sample.wps, H = h.sample.days;
1224
- b.forEach((x) => {
1225
- var j;
1226
- ((j = n.hours) == null ? void 0 : j.findIndex((F) => F.eta === x.eta)) === -1 && n.hours.push(x);
1227
- }), A.forEach((x) => {
1228
- var j;
1229
- ((j = n.wps) == null ? void 0 : j.findIndex((F) => F.eta === x.eta)) === -1 && n.wps.push(x);
1230
- }), H.forEach((x) => {
1231
- var j;
1232
- ((j = n == null ? void 0 : n.days) == null ? void 0 : j.findIndex((F) => F.eta === x.eta)) === -1 && n.days.push(x);
1207
+ }, i = e.reduce((M, u) => M + u.distance, 0), o = e.reduce((M, u) => {
1208
+ var I;
1209
+ return M + (((I = u.extend) == null ? void 0 : I.distanceInECA) || 0);
1210
+ }, 0), a = e.reduce((M, u) => M + u.totalHrs, 0), s = e.reduce((M, u) => {
1211
+ var I;
1212
+ return M + (((I = u.extend) == null ? void 0 : I.hoursInECA) || 0);
1213
+ }, 0), d = e.reduce((M, u) => {
1214
+ var I;
1215
+ return M + (((I = u.extend) == null ? void 0 : I.totalDgoConsInECA) || 0);
1216
+ }, 0), r = e.reduce((M, u) => M + u.wxFactor * u.totalHrs / a, 0), h = e.reduce((M, u) => M + u.cFactor * u.totalHrs / a, 0), m = e.reduce((M, u) => M + u.totalFoCons, 0), l = e.reduce((M, u) => M + u.totalDgoCons, 0), y = e.reduce((M, u) => M + u.cost.total, 0), f = e.reduce((M, u) => M + u.cost.hire, 0), C = e.reduce((M, u) => M + u.cost.bunker, 0), k = [], p = [];
1217
+ let v;
1218
+ for (const M of e) {
1219
+ p.push(...((c = M.extend) == null ? void 0 : c.eca) || []);
1220
+ const u = M.sample.hours, I = M.sample.wps, F = M.sample.days, D = u.at(0);
1221
+ v && (D.distanceFromPrevious = v.distanceFromPrevious, D.distanceFromStart = v.distanceFromStart, u.forEach((N, j) => {
1222
+ j && (N.distanceFromStart = N.distanceFromStart + v.distanceFromStart);
1223
+ }), I.at(0).distanceFromPrevious = v.distanceFromPrevious, I.at(0).distanceFromStart = v.distanceFromStart, I.forEach((N, j) => {
1224
+ j && (N.distanceFromStart = N.distanceFromStart + v.distanceFromStart);
1225
+ }), F.at(0).distanceFromPrevious = v.distanceFromPrevious, F.at(0).distanceFromStart = v.distanceFromStart, F.forEach((N, j) => {
1226
+ j && (N.distanceFromStart = N.distanceFromStart + v.distanceFromStart);
1227
+ })), D.cp = M.cost.cp;
1228
+ const Y = [M.etd, M.eta], E = k.findIndex((N) => N.id === D.cp.id);
1229
+ E === -1 ? (D.cp.segment = [Y], k.push(D.cp)) : k[E].segment.push(Y), u.forEach((N) => {
1230
+ var A;
1231
+ ((A = n.hours) == null ? void 0 : A.findIndex((R) => R.eta === N.eta)) === -1 && n.hours.push(N);
1232
+ }), I.forEach((N) => {
1233
+ var A;
1234
+ ((A = n.wps) == null ? void 0 : A.findIndex((R) => R.eta === N.eta)) === -1 && n.wps.push(N);
1235
+ }), F.forEach((N) => {
1236
+ var A;
1237
+ ((A = n == null ? void 0 : n.days) == null ? void 0 : A.findIndex((R) => R.eta === N.eta)) === -1 && n.days.push(N);
1233
1238
  });
1234
- const T = (r = n.wps) == null ? void 0 : r.findIndex((x) => x.eta === f.eta);
1235
- T === -1 ? n.wps.push(f) : n.wps[T] = f;
1239
+ const P = (w = n.wps) == null ? void 0 : w.findIndex((N) => N.eta === D.eta);
1240
+ P === -1 ? n.wps.push(D) : n.wps[P] = D, v = u.at(-1);
1236
1241
  }
1237
- return n.wps.sort((h, b) => {
1238
- w(h.etd).unix() - w(b.etd).unix();
1242
+ return n.wps.sort((M, u) => {
1243
+ b(M.etd).unix() - b(u.etd).unix();
1244
+ }), n.wps.forEach((M, u) => {
1245
+ if (!M.avgSpd) {
1246
+ let I;
1247
+ if (u === 0 ? I = n.wps.at(1) : I = n.wps.at(u + 1), I) {
1248
+ const F = I.distanceFromStart - (M.distanceFromStart || 0), D = b(I.etd || I.eta).diff(b(M.etd || I.eta), "hour", !0), Y = Math.round(F / D * 100) / 100;
1249
+ M.avgSpd = Y;
1250
+ }
1251
+ }
1239
1252
  }), {
1240
1253
  sample: n,
1241
1254
  etd: e.at(0).etd,
@@ -1247,13 +1260,13 @@ class q {
1247
1260
  distance: Math.round(i * 1e4) / 1e4,
1248
1261
  totalHrs: Math.round(a * 1e3) / 1e3,
1249
1262
  avgSpeed: Math.round(i / a * 1e3) / 1e3,
1250
- wxFactor: Math.round(c / a * 1e3) / 1e3,
1251
- cFactor: Math.round(u / a * 1e3) / 1e3,
1252
- totalFoCons: Math.round(y * 1e3) / 1e3,
1263
+ wxFactor: Math.round(r / a * 1e3) / 1e3,
1264
+ cFactor: Math.round(h / a * 1e3) / 1e3,
1265
+ totalFoCons: Math.round(m * 1e3) / 1e3,
1253
1266
  totalDgoCons: Math.round(l * 1e3) / 1e3,
1254
1267
  cost: {
1255
- total: Math.round(M * 1e3) / 1e3,
1256
- hire: Math.round(m * 1e3) / 1e3,
1268
+ total: Math.round(y * 1e3) / 1e3,
1269
+ hire: Math.round(f * 1e3) / 1e3,
1257
1270
  bunker: Math.round(C * 1e3) / 1e3
1258
1271
  },
1259
1272
  extend: {
@@ -1261,22 +1274,23 @@ class q {
1261
1274
  eca: p,
1262
1275
  distanceInECA: Math.round(o * 1e4) / 1e4,
1263
1276
  hoursInECA: Math.round(s * 1e3) / 1e3,
1264
- totalDgoConsInECA: Math.round(d * 1e3) / 1e3
1277
+ totalDgoConsInECA: Math.round(d * 1e3) / 1e3,
1278
+ speeds: e
1265
1279
  }
1266
1280
  };
1267
1281
  }
1268
1282
  }
1269
1283
  export {
1270
- $ as AISImpl,
1271
- ft as AlertHelper,
1272
- lt as AlertLevel,
1273
- St as HifleetImpl,
1274
- Mt as LoadCondition,
1275
- jt as MyShipImpl,
1284
+ tt as AISImpl,
1285
+ mt as AlertHelper,
1286
+ ft as AlertLevel,
1287
+ xt as HifleetImpl,
1288
+ gt as LoadCondition,
1289
+ Et as MyShipImpl,
1276
1290
  Ct as MyVesselImpl,
1277
- Yt as ShipxyImpl,
1278
- q as SpeedHelper,
1279
- gt as SpeedLabel,
1280
- yt as VesselTag,
1281
- Dt as alertHelper
1291
+ jt as ShipxyImpl,
1292
+ O as SpeedHelper,
1293
+ bt as SpeedLabel,
1294
+ Mt as VesselTag,
1295
+ Nt as alertHelper
1282
1296
  };