@idm-plugin/vessel 1.7.0 → 1.7.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,101 +1,101 @@
1
- var st = Object.defineProperty;
2
- var at = (j, e, t) => e in j ? st(j, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : j[e] = t;
3
- var Z = (j, e, t) => (at(j, typeof e != "symbol" ? e + "" : e, t), t);
4
- import R from "got";
5
- import Q from "@log4js-node/log4js-api";
6
- import p from "moment";
7
- import { LngLatHelper as z, LaneHelper as B } from "@idm-plugin/geo";
8
- import { MeteoHelper2 as ot, MeteoHelper as nt } from "@idm-plugin/meteo2";
9
- import { Meteo2Assist as tt } from "@idm-plugin/meteo";
10
- let b;
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);
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";
10
+ let g;
11
11
  try {
12
- b = Q.getLogger("vessel");
12
+ g = at.getLogger("vessel");
13
13
  } catch {
14
14
  } finally {
15
15
  }
16
- class U {
16
+ class $ {
17
17
  /**
18
18
  * 解析AIS状态码
19
19
  * @param status
20
20
  */
21
21
  parseStatus(e) {
22
- let t, o;
22
+ let t, n;
23
23
  switch (e) {
24
24
  case 0:
25
- t = "在航(主机推动)", o = "The engine is in use";
25
+ t = "在航(主机推动)", n = "The engine is in use";
26
26
  break;
27
27
  case 1:
28
- t = "锚泊", o = "Anchored";
28
+ t = "锚泊", n = "Anchored";
29
29
  break;
30
30
  case 2:
31
- t = "失控", o = "Not operated";
31
+ t = "失控", n = "Not operated";
32
32
  break;
33
33
  case 3:
34
- t = "操纵受限", o = "Limited airworthiness";
34
+ t = "操纵受限", n = "Limited airworthiness";
35
35
  break;
36
36
  case 4:
37
- t = "吃水受限", o = "Limited by ship's draft";
37
+ t = "吃水受限", n = "Limited by ship's draft";
38
38
  break;
39
39
  case 5:
40
- t = "靠泊", o = "Mooring";
40
+ t = "靠泊", n = "Mooring";
41
41
  break;
42
42
  case 6:
43
- t = "搁浅", o = "Stranded";
43
+ t = "搁浅", n = "Stranded";
44
44
  break;
45
45
  case 7:
46
- t = "捕捞作业", o = "Engaged in fishing";
46
+ t = "捕捞作业", n = "Engaged in fishing";
47
47
  break;
48
48
  case 8:
49
- t = "靠帆船提供动力", o = "Sailing";
49
+ t = "靠帆船提供动力", n = "Sailing";
50
50
  break;
51
51
  default:
52
- t = "未定义", o = "Undefined";
52
+ t = "未定义", n = "Undefined";
53
53
  }
54
- return { labelCn: t, labelEn: o };
54
+ return { labelCn: t, labelEn: n };
55
55
  }
56
56
  }
57
- class vt extends U {
58
- constructor(t, o) {
57
+ class Ct extends $ {
58
+ constructor(t, n) {
59
59
  super();
60
- Z(this, "clientId");
61
- Z(this, "clientSecret");
62
- Z(this, "token");
63
- this.clientId = t, this.clientSecret = o;
60
+ _(this, "clientId");
61
+ _(this, "clientSecret");
62
+ _(this, "token");
63
+ this.clientId = t, this.clientSecret = n;
64
64
  }
65
65
  async authToken(t = {}) {
66
- const o = "https://svc.data.myvessel.cn/ada/oauth/token", i = {
66
+ const n = "https://svc.data.myvessel.cn/ada/oauth/token", i = {
67
67
  searchParams: {
68
68
  client_id: this.clientId,
69
69
  client_secret: this.clientSecret,
70
70
  grant_type: "client_credentials"
71
71
  }
72
- }, a = await R.post(o, i).json();
73
- b == null || b.info("[%s] fetch access token from: %s - %j", t.requestId, o, a), a.error || (this.token = {
74
- accessToken: a.access_token,
75
- tokenType: a.token_type,
76
- expiresIn: a.expires_in,
77
- scope: a.scope,
78
- jti: a.jti,
79
- issuedAt: p().utc().format()
72
+ }, o = await V.post(n, i).json();
73
+ g == null || g.info("[%s] fetch access token from: %s - %j", t.requestId, n, o), o.error || (this.token = {
74
+ accessToken: o.access_token,
75
+ tokenType: o.token_type,
76
+ expiresIn: o.expires_in,
77
+ scope: o.scope,
78
+ jti: o.jti,
79
+ issuedAt: w().utc().format()
80
80
  });
81
81
  }
82
- async realTimePosition(t, o = {}) {
83
- var u, y, h;
84
- (!this.token || p().diff(p(this.token.issuedAt), "seconds") > ((u = this.token) == null ? void 0 : u.expiresIn) - 300) && await this.authToken(o);
85
- const i = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit", a = {
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);
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} ${(h = this.token) == null ? void 0 : h.accessToken}`
87
+ Authorization: `${(y = this.token) == null ? void 0 : y.tokenType} ${(l = this.token) == null ? void 0 : l.accessToken}`
88
88
  },
89
89
  searchParams: { mmsi: t }
90
90
  };
91
- b == null || b.info("[%s] fetch realtime position from: %s - %j", o.requestId, i, a);
92
- const n = await R.get(i, a).json();
93
- if (n.code)
94
- return b == null || b.warn("[%s] fetch realtime position failed: %j", o.requestId, i, { message: n.message, status: n.status, code: n.code }), n;
95
- const s = n.data;
96
- for (const f in s)
97
- !isNaN(s[f]) && Number(s[f]) !== 1 / 0 && (s[f] = Number(s[f]));
98
- const d = p(`${s.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
91
+ g == null || g.info("[%s] fetch realtime position from: %s - %j", n.requestId, i, o);
92
+ const a = await V.get(i, o).json();
93
+ if (a.code)
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
+ 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");
99
99
  return {
100
100
  mmsi: s.mmsi,
101
101
  name: s.vesselName,
@@ -110,7 +110,7 @@ class vt extends U {
110
110
  cog: s.cog,
111
111
  hdg: s.hdg,
112
112
  rot: s.rot,
113
- eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ? p.utc(s.eta).format() : void 0,
113
+ eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ? w.utc(s.eta).format() : void 0,
114
114
  destination: s.dest,
115
115
  positionTime: d.unix(),
116
116
  status: s.status,
@@ -121,78 +121,78 @@ class vt extends U {
121
121
  utc: d.utc().format()
122
122
  };
123
123
  }
124
- async trajectory(t, o, i, a, n = !0, s = {}) {
125
- (!this.token || p().diff(p(this.token.issuedAt), "seconds") > this.token.expiresIn - 300) && await this.authToken(s);
126
- const d = await this.realTimePosition(t, s), r = p(o), u = p(i), y = [];
127
- for (; u.diff(r, "day", !0) > 30; )
128
- await this.trajectoryIn30Day(t, r, r.clone().add(30, "day"), d, a, y, s), r.add(30, "day");
129
- return await this.trajectoryIn30Day(t, r, u, d, a, y, s), y;
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;
130
130
  }
131
- async trajectoryIn30Day(t, o, i, a, n, s, d = {}) {
132
- var l, m, M, g, I;
133
- const r = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", u = {
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 = {
134
134
  headers: {
135
- Authorization: `${(l = this.token) == null ? void 0 : l.tokenType} ${(m = this.token) == null ? void 0 : m.accessToken}`
135
+ Authorization: `${(m = this.token) == null ? void 0 : m.tokenType} ${(C = this.token) == null ? void 0 : C.accessToken}`
136
136
  },
137
137
  json: {
138
138
  mmsi: t,
139
- startTime: o.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),
139
+ startTime: n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),
140
140
  endTime: i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")
141
141
  }
142
142
  };
143
- b == null || b.info("[%s] fetch trajectory from: %s - %j", d.requestId, r, u);
144
- const y = await R.post(r, u).json();
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
145
  if (y.code)
146
- return b == null || b.warn("[%s] fetch trajectory failed: %j", d.requestId, r, { message: y.message, status: y.status, code: y.code }), y;
147
- let h = -1;
148
- const f = p(`${(g = (M = y.data) == null ? void 0 : M[0]) == null ? void 0 : g.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
149
- return (I = y.data) == null || I.forEach((c) => {
150
- for (const T in c)
151
- !isNaN(c[T]) && Number(c[T]) !== 1 / 0 && (c[T] = Number(c[T]));
152
- const w = p(`${c.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), N = c.status, { labelCn: v, labelEn: S } = this.parseStatus(N), Y = {
153
- mmsi: c.mmsi,
154
- imo: a == null ? void 0 : a.imo,
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: N,
162
- eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(c.eta) ? p(`${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: v,
166
- labelEn: S,
146
+ return g == null || g.warn("[%s] fetch trajectory failed: %j", d.requestId, c, { message: y.message, status: y.status, code: y.code }), y;
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,
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,
167
167
  method: "trajectory",
168
168
  vendor: "myVessel",
169
- utc: w.utc().format()
170
- }, F = Math.floor(w.diff(f, "minute", !0) / (n || 1));
171
- F !== h && (h = F, s.push(Y));
169
+ utc: h.utc().format()
170
+ }, A = Math.floor(h.diff(M, "minute", !0) / (a || 1));
171
+ A !== l && (l = A, s.push(S));
172
172
  }), s;
173
173
  }
174
174
  }
175
- class wt extends U {
175
+ class St extends $ {
176
176
  constructor(t) {
177
177
  super();
178
- Z(this, "token");
178
+ _(this, "token");
179
179
  this.token = t;
180
180
  }
181
- async realTimePosition(t, o = {}) {
182
- const i = "https://api.hifleet.com/position/position/get/token", a = {
181
+ async realTimePosition(t, n = {}) {
182
+ const i = "https://api.hifleet.com/position/position/get/token", o = {
183
183
  searchParams: {
184
184
  mmsi: t,
185
185
  usertoken: this.token
186
186
  }
187
- }, n = await R.post(i, a).json();
188
- b == null || b.info("[%s] fetch realtime position from: %s - %j", o.requestId, i, a);
189
- const s = n == null ? void 0 : n.list;
187
+ }, a = await V.post(i, o).json();
188
+ g == null || g.info("[%s] fetch realtime position from: %s - %j", n.requestId, i, o);
189
+ const s = a == null ? void 0 : a.list;
190
190
  if (!s)
191
- return b == null || b.warn("[%s] fetch realtime position failed: %j", o.requestId, i, n), n;
192
- for (const f in s)
193
- !isNaN(s[f]) && Number(s[f]) !== 1 / 0 && (s[f] = Number(s[f]));
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]));
194
194
  s.status = s.sp > 3 ? 0 : 1;
195
- const d = s.status, { labelCn: r, labelEn: u } = this.parseStatus(d), y = p(`${s.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
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");
196
196
  return {
197
197
  mmsi: s.m,
198
198
  name: s.n,
@@ -207,20 +207,20 @@ class wt extends U {
207
207
  cog: s.co,
208
208
  hdg: s.h,
209
209
  rot: isNaN(s.rot) ? 0 : s.rot,
210
- eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ? p.utc(s.eta).format() : void 0,
210
+ eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ? w.utc(s.eta).format() : void 0,
211
211
  destination: s.destination,
212
212
  positionTime: y.unix(),
213
213
  utc: y.utc().format(),
214
214
  status: d,
215
- labelCn: r,
215
+ labelCn: c,
216
216
  labelEn: u,
217
217
  method: "position",
218
218
  vendor: "hifleet"
219
219
  };
220
220
  }
221
- async search(t, o = {}) {
221
+ async search(t, n = {}) {
222
222
  let i = "https://www.hifleet.com/hifleetapi/searchVesselOL.do";
223
- const a = {
223
+ const o = {
224
224
  searchParams: {
225
225
  keyword: t
226
226
  },
@@ -230,24 +230,24 @@ class wt extends U {
230
230
  Host: "www.hifleet.com"
231
231
  }
232
232
  };
233
- let n = await R.post(i, a).json();
234
- b == null || b.info("[%s] fetch vessel props from: %s - %j", o.requestId, i, a), n instanceof Array && (n = n[0]);
235
- for (const d in n)
236
- !isNaN(n[d]) && Number(n[d]) !== 1 / 0 && (n[d] = Number(n[d]));
233
+ let a = await V.post(i, o).json();
234
+ g == null || g.info("[%s] fetch vessel props from: %s - %j", n.requestId, i, o), a instanceof Array && (a = a[0]);
235
+ for (const d in a)
236
+ !isNaN(a[d]) && Number(a[d]) !== 1 / 0 && (a[d] = Number(a[d]));
237
237
  const s = {
238
- mmsi: n.m,
239
- name: n.n,
240
- imo: n.i,
241
- callSign: n.c,
242
- length: n.l,
243
- breadth: n.b,
244
- draught: n.dr,
245
- type: n.t
238
+ mmsi: a.m,
239
+ name: a.n,
240
+ imo: a.i,
241
+ callSign: a.c,
242
+ length: a.l,
243
+ breadth: a.b,
244
+ draught: a.dr,
245
+ type: a.t
246
246
  };
247
- return i = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", n = await R.post(i, a).json(), b == null || b.info("[%s] search vessel dead weight from: %s - %j", o.requestId, i, a), n instanceof Array && (n = n[0]), n && (s.deadweight = Number(n.dwt)), s;
247
+ return i = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", a = await V.post(i, o).json(), g == null || g.info("[%s] search vessel dead weight from: %s - %j", n.requestId, i, o), a instanceof Array && (a = a[0]), a && (s.deadweight = Number(a.dwt)), s;
248
248
  }
249
- async suggest(t, o = {}) {
250
- const i = "https://www.hifleet.com/hifleetapi/getShipSuggest.do", a = {
249
+ async suggest(t, n = {}) {
250
+ const i = "https://www.hifleet.com/hifleetapi/getShipSuggest.do", o = {
251
251
  searchParams: {
252
252
  q: t
253
253
  },
@@ -256,10 +256,10 @@ class wt extends U {
256
256
  Origin: "https://www.hifleet.com",
257
257
  Host: "www.hifleet.com"
258
258
  }
259
- }, n = await R.post(i, a).json();
260
- b == null || b.info("[%s] suggest vessel props from: %s - %j", o.requestId, i, a);
259
+ }, a = await V.post(i, o).json();
260
+ g == null || g.info("[%s] suggest vessel props from: %s - %j", n.requestId, i, o);
261
261
  const s = [];
262
- for (const d of n)
262
+ for (const d of a)
263
263
  s.push({
264
264
  mmsi: !d.mmsi || isNaN(d.mmsi) ? null : Number(d.mmsi),
265
265
  name: d.name,
@@ -267,79 +267,79 @@ class wt extends U {
267
267
  imo: !d.imo || isNaN(d.imo) ? null : Number(d.imo),
268
268
  score: d._score
269
269
  });
270
- return s.sort((d, r) => r.score - d.score), s;
270
+ return s.sort((d, c) => c.score - d.score), s;
271
271
  }
272
- async trajectory(t, o, i, a, n = !0, s = {}) {
273
- var c, w, N;
272
+ async trajectory(t, n, i, o, a = !0, s = {}) {
273
+ var r, h, b;
274
274
  const d = await this.realTimePosition(t, s);
275
- let r = p(o);
276
- const u = p(i), y = p();
277
- if (n) {
278
- let v = u.diff(r, "d", !0);
279
- v < 0 ? r = u.clone().subtract(40, "d") : v < 30 ? r.subtract(10, "d") : v < 60 ? r.subtract(5, "d") : r = u.clone().subtract(80, "d"), v = y.diff(u, "d", !0), u.add(v > 10 ? 240 : v * 24, "h");
275
+ let c = w(n);
276
+ const u = w(i), y = w();
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");
280
280
  }
281
- const h = {
281
+ const l = {
282
282
  searchParams: {
283
283
  endtime: u.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
284
- starttime: r.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
284
+ starttime: c.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
285
285
  mmsi: t,
286
286
  usertoken: this.token
287
287
  }
288
- }, f = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", l = await R.get(f, h).json();
289
- b == null || b.info("[%s] fetch trajectory from: %s - %j", s.requestId, f, h);
290
- let m;
291
- l && (m = ((w = (c = l.ships) == null ? void 0 : c.offors) == null ? void 0 : w.ship) || [], m.length || b == null || b.warn("[%s] fetch trajectory failed: %j", s.requestId, l));
292
- const M = [];
293
- let g = -1;
294
- const I = p(`${(N = m == null ? void 0 : m[0]) == null ? void 0 : N.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
295
- for (const v of m) {
296
- for (const H in v)
297
- !isNaN(v[H]) && Number(v[H]) !== 1 / 0 && (v[H] = Number(v[H]));
298
- const S = p(`${v.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
299
- v.status = v.sp > 4 ? 0 : 1;
300
- const { labelEn: Y, labelCn: F } = this.parseStatus(v.status), T = {
301
- mmsi: v.m,
302
- name: v.n,
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);
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));
292
+ const k = [];
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,
303
303
  imo: d == null ? void 0 : d.imo,
304
- lat: v.la,
305
- lng: v.lo,
306
- draught: v.draught,
307
- sog: v.sp,
308
- cog: v.co,
309
- hdg: v.hdg,
310
- positionTime: S.unix(),
311
- utc: S.utc().format(),
312
- status: v.status,
313
- labelCn: F,
314
- labelEn: Y,
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,
315
315
  method: "trajectory",
316
316
  vendor: "hifleet"
317
- }, D = Math.floor(S.diff(I, "minute", !0) / (a || 1));
318
- D !== g && (g = D, M.push(T));
317
+ }, T = Math.floor(D.diff(v, "minute", !0) / (o || 1));
318
+ T !== p && (p = T, k.push(H));
319
319
  }
320
- return M;
320
+ return k;
321
321
  }
322
322
  }
323
- class pt extends U {
323
+ class Yt extends $ {
324
324
  constructor(t) {
325
325
  super();
326
- Z(this, "token");
326
+ _(this, "token");
327
327
  this.token = t;
328
328
  }
329
- async realTimePosition(t, o = {}) {
329
+ async realTimePosition(t, n = {}) {
330
330
  const i = {
331
331
  searchParams: {
332
332
  id: t,
333
333
  k: this.token,
334
334
  enc: 1
335
335
  }
336
- }, a = "https://api.shipxy.com/apicall/GetSingleShip", n = await R.get(a, i).json();
337
- if (b == null || b.info("[%s] fetch realtime position from: %s - %j", o.requestId, a, i), (n == null ? void 0 : n.status) !== 0)
338
- return n;
339
- const s = n.data[0];
340
- for (const h in s)
341
- !isNaN(s[h]) && Number(s[h]) !== 1 / 0 && (s[h] = Number(s[h]));
342
- const { labelCn: d, labelEn: r } = await this.parseStatus(s.navistat), u = p.unix(s.lasttime);
336
+ }, o = "https://api.shipxy.com/apicall/GetSingleShip", a = await V.get(o, i).json();
337
+ if (g == null || g.info("[%s] fetch realtime position from: %s - %j", n.requestId, o, i), (a == null ? void 0 : a.status) !== 0)
338
+ return a;
339
+ const s = a.data[0];
340
+ for (const l in s)
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);
343
343
  return {
344
344
  mmsi: s.ShipID,
345
345
  name: s.name,
@@ -357,53 +357,53 @@ class pt extends U {
357
357
  positionTime: s.lasttime,
358
358
  utc: u.utc().format(),
359
359
  status: s.navistat,
360
- labelEn: r,
360
+ labelEn: c,
361
361
  labelCn: d,
362
362
  method: "position",
363
363
  vendor: "shipxy"
364
364
  };
365
365
  }
366
- async trajectory(t, o, i, a, n = !0, s = {}) {
367
- var I;
368
- const d = await this.realTimePosition(t, s), r = p(o), u = p(i), y = "https://api.shipxy.com/apicall/GetShipTrack", h = {
366
+ async trajectory(t, n, i, o, a = !0, s = {}) {
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 = {
369
369
  searchParams: {
370
370
  id: t,
371
371
  k: this.token,
372
372
  enc: 1,
373
373
  cut: 0,
374
- btm: r.unix(),
374
+ btm: c.unix(),
375
375
  etm: u.unix()
376
376
  }
377
- }, f = await R.get(y, h).json();
378
- if (b == null || b.info("[%s] fetch trajectory from: %s - %j", s.requestId, y, h), (f == null ? void 0 : f.status) !== 0)
379
- return f;
380
- const l = f == null ? void 0 : f.points, m = [], M = p.unix((I = l[0]) == null ? void 0 : I.utc);
381
- let g = -1;
382
- for (const c of l) {
383
- const w = p.unix(c.utc), N = {
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);
381
+ let p = -1;
382
+ for (const r of m) {
383
+ const h = w.unix(r.utc), b = {
384
384
  imo: d == null ? void 0 : d.imo,
385
385
  mmsi: t,
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(),
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(),
392
392
  method: "trajectory",
393
393
  vendor: "shipxy"
394
- }, v = Math.floor(w.diff(M, "minute", !0) / (a || 1));
395
- v !== g && (g = v, m.push(N));
394
+ }, f = Math.floor(h.diff(k, "minute", !0) / (o || 1));
395
+ f !== p && (p = f, C.push(b));
396
396
  }
397
- return m;
397
+ return C;
398
398
  }
399
399
  }
400
- class It extends U {
400
+ class jt extends $ {
401
401
  constructor(t) {
402
402
  super();
403
- Z(this, "token");
403
+ _(this, "token");
404
404
  this.token = t;
405
405
  }
406
- async getShipId(t, o = {}) {
406
+ async getShipId(t, n = {}) {
407
407
  const i = {
408
408
  headers: {
409
409
  appKey: this.token
@@ -411,10 +411,10 @@ class It extends U {
411
411
  json: {
412
412
  mmsiList: t
413
413
  }
414
- }, a = "https://api3.myships.com/sp/ships/getShipIdByMMSI", n = await R.post(a, i).json();
415
- return b == null || b.info("[%s] fetch ship id from: %s - %j", o.requestId, a, i), n.code !== "0" ? n : n.data[0].shipId;
414
+ }, o = "https://api3.myships.com/sp/ships/getShipIdByMMSI", a = await V.post(o, i).json();
415
+ return g == null || g.info("[%s] fetch ship id from: %s - %j", n.requestId, o, i), a.code !== "0" ? a : a.data[0].shipId;
416
416
  }
417
- async getShipInfo(t, o = {}) {
417
+ async getShipInfo(t, n = {}) {
418
418
  const i = {
419
419
  headers: {
420
420
  appKey: this.token
@@ -422,12 +422,12 @@ class It extends U {
422
422
  json: {
423
423
  shipId: t
424
424
  }
425
- }, a = "https://api3.myships.com/sp/ships/aissta", n = await R.post(a, i).json();
426
- if (b == null || b.info("[%s] fetch ship info from: %s - %j", o.requestId, a, i), n.code !== "0")
427
- return n;
428
- const s = n.data;
425
+ }, o = "https://api3.myships.com/sp/ships/aissta", a = await V.post(o, i).json();
426
+ if (g == null || g.info("[%s] fetch ship info from: %s - %j", n.requestId, o, i), a.code !== "0")
427
+ return a;
428
+ const s = a.data;
429
429
  let d = s.imo;
430
- return t === "407170" && (d = "9198379", b == null || b.warn("[%s] ship(%s) imo error: %s, should be %s", o.requestId, t, s.imo, d)), {
430
+ return t === "407170" && (d = "9198379", g == null || g.warn("[%s] ship(%s) imo error: %s, should be %s", n.requestId, t, s.imo, d)), {
431
431
  mmsi: s.mmsi,
432
432
  name: s.shipnameEn,
433
433
  imo: d,
@@ -437,91 +437,91 @@ class It extends U {
437
437
  draught: (s.draught || 100) / 10
438
438
  };
439
439
  }
440
- async realTimePosition(t, o = {}) {
441
- const i = await this.getShipId(t, o), a = await this.getShipInfo(i, o), n = {
440
+ async realTimePosition(t, n = {}) {
441
+ const i = await this.getShipId(t, n), o = await this.getShipInfo(i, n), a = {
442
442
  headers: {
443
443
  appKey: this.token
444
444
  },
445
445
  json: {
446
446
  shipId: i
447
447
  }
448
- }, s = "https://api3.myships.com/sp/ships/position/latest", d = await R.post(s, n).json();
449
- b == null || b.info("[%s] fetch realtime position from: %s - %j", o.requestId, s, n);
450
- const r = d.data[0];
451
- for (const l in r)
452
- !isNaN(r[l]) && Number(r[l]) !== 1 / 0 && (r[l] = Number(r[l]));
453
- const { labelCn: u, labelEn: y } = await this.parseStatus(r.aisNavStatus), h = p.unix(r.posTime);
448
+ }, s = "https://api3.myships.com/sp/ships/position/latest", d = await V.post(s, a).json();
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);
454
454
  return {
455
- ...a,
455
+ ...o,
456
456
  mmsi: t,
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
- utc: h.utc().format(),
465
- status: r.aisNavStatus,
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,
464
+ utc: l.utc().format(),
465
+ status: c.aisNavStatus,
466
466
  labelEn: y,
467
467
  labelCn: u,
468
468
  method: "position",
469
469
  vendor: "myship"
470
470
  };
471
471
  }
472
- async trajectory(t, o, i, a, n = !0, s = {}) {
473
- const d = p(o), r = p(i), u = await this.getShipId(t), y = await this.getShipInfo(u), h = [];
474
- for (; r.diff(d, "day", !0) > 30; )
475
- await this.trajectoryIn30Day(u, d.unix(), d.add(30, "day").unix(), y, t, a, h);
476
- return await this.trajectoryIn30Day(u, d.unix(), r.unix(), y, t, a, h), h;
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;
477
477
  }
478
- async trajectoryIn30Day(t, o, i, a, n, s, d, r = {}) {
479
- var M;
478
+ async trajectoryIn30Day(t, n, i, o, a, s, d, c = {}) {
479
+ var k;
480
480
  const u = {
481
481
  headers: {
482
482
  appKey: this.token
483
483
  },
484
484
  json: {
485
485
  shipId: t,
486
- startTime: o,
486
+ startTime: n,
487
487
  endTime: i
488
488
  }
489
- }, y = "https://api3.myships.com/sp/ships/position/history", h = await R.post(y, u).json();
490
- if (b == null || b.info("[%s] fetch trajectory from: %s - %j", r.requestId, y, u), h.code !== "0")
491
- return b == null || b.warn("[%s] invoke myship trajectory failed: %j", r.requestId, h), h;
492
- const f = h.data;
493
- for (const g in f)
494
- !isNaN(f[g]) && Number(f[g]) !== 1 / 0 && (f[g] = Number(f[g]));
495
- const l = p.unix((M = f[0]) == null ? void 0 : M.posTime);
496
- let m = -1;
497
- for (const g of f) {
498
- const I = p.unix(g.posTime), c = {
499
- imo: a == null ? void 0 : a.imo,
500
- mmsi: n,
501
- lat: Math.round(g.lat / 1e4 / 60 * 1e5) / 1e5,
502
- lng: Math.round(g.lon / 1e4 / 60 * 1e5) / 1e5,
503
- sog: Math.round(g.sog / 10 * 100) / 100,
504
- cog: Math.round(g.cog / 10 * 100) / 100,
505
- hdg: Math.round(g.heading * 100) / 100,
506
- rot: Math.round(g.rot * 100) / 100,
507
- positionTime: I.unix(),
508
- utc: I.utc().format(),
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);
496
+ let C = -1;
497
+ for (const p of M) {
498
+ const v = w.unix(p.posTime), r = {
499
+ imo: o == null ? void 0 : o.imo,
500
+ mmsi: a,
501
+ lat: Math.round(p.lat / 1e4 / 60 * 1e5) / 1e5,
502
+ lng: Math.round(p.lon / 1e4 / 60 * 1e5) / 1e5,
503
+ sog: Math.round(p.sog / 10 * 100) / 100,
504
+ cog: Math.round(p.cog / 10 * 100) / 100,
505
+ hdg: Math.round(p.heading * 100) / 100,
506
+ rot: Math.round(p.rot * 100) / 100,
507
+ positionTime: v.unix(),
508
+ utc: v.utc().format(),
509
509
  method: "trajectory",
510
510
  vendor: "myship"
511
- }, w = Math.floor(I.diff(l, "minute", !0) / (s || 1));
512
- w !== m && (m = w, d.push(c));
511
+ }, h = Math.floor(v.diff(m, "minute", !0) / (s || 1));
512
+ h !== C && (C = h, d.push(r));
513
513
  }
514
514
  return d;
515
515
  }
516
516
  }
517
- let W;
517
+ let B;
518
518
  try {
519
- W = Q.getLogger("vessel");
519
+ B = at.getLogger("vessel");
520
520
  } catch {
521
521
  } finally {
522
522
  }
523
- var it = /* @__PURE__ */ ((j) => (j.NOTICE = "NOTICE", j.WARN = "WARN", j.HEAVY = "HEAVY", j.SEVERE = "SEVERE", j.ERROR = "ERROR", j.FATAL = "FATAL", j))(it || {});
524
- class rt {
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 {
525
525
  /**
526
526
  * 解析告警规则, 多规则场景
527
527
  * @param rule
@@ -531,23 +531,23 @@ class rt {
531
531
  * @param options
532
532
  */
533
533
  parsePrinciple(e, t = {}) {
534
- var s, d, r;
535
- W == null || W.info("[%s] parse rule: %s", t.requestId, e);
536
- const o = new RegExp("(?<=\\[)(.+)(?=])", "g"), i = e.match(o) ? (s = e.match(o)) == null ? void 0 : s[0] : void 0, a = i == null ? void 0 : i.split(";");
537
- if (!a)
534
+ var s, d, c;
535
+ B == null || B.info("[%s] parse rule: %s", t.requestId, e);
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
+ if (!o)
538
538
  return;
539
- const n = {};
540
- for (let u = 0; u < (a == null ? void 0 : a.length); u++) {
541
- const y = (r = (d = a[u].match(o)) == null ? void 0 : d[0]) == null ? void 0 : r.split("],");
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
542
  if (u === 0 && !y)
543
- n.scope = a[0];
543
+ a.scope = o[0];
544
544
  else if (y)
545
- for (let h = 0, f = y.length; h < f; h++) {
546
- const l = this.parseRule(y[h]);
547
- l && (n[l.level] ? l.key ? n[l.level][l == null ? void 0 : l.key] = l : n[l.level] = l : l.key ? n[l.level] = { [l == null ? void 0 : l.key]: l } : n[l.level] = l);
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);
548
548
  }
549
549
  }
550
- return n;
550
+ return a;
551
551
  }
552
552
  /**
553
553
  * 解析单一告警规则
@@ -556,16 +556,16 @@ class rt {
556
556
  * @param options
557
557
  */
558
558
  parseRule(e, t = {}) {
559
- var n;
560
- W == null || W.info("[%s] parse rule: %s", t.requestId, e), e = e.startsWith("[") ? e : `[${e}`, e = e.endsWith("]") ? e : `${e}]`;
561
- const o = new RegExp("(?<=\\[)(.+?)(?=])", "g"), i = (n = e == null ? void 0 : e.match(o)) == null ? void 0 : n[0], a = i == null ? void 0 : i.split(",");
562
- if (a)
559
+ var a;
560
+ B == null || B.info("[%s] parse rule: %s", t.requestId, e), e = e.startsWith("[") ? e : `[${e}`, e = e.endsWith("]") ? e : `${e}]`;
561
+ const n = new RegExp("(?<=\\[)(.+?)(?=])", "g"), i = (a = e == null ? void 0 : e.match(n)) == null ? void 0 : a[0], o = i == null ? void 0 : i.split(",");
562
+ if (o)
563
563
  return {
564
- operator: a[0],
565
- number: Number.isNaN(Number(a[1])) ? a[1] : Number(a[1]),
566
- level: a[2],
567
- time: Number(a[3]),
568
- key: a[4]
564
+ operator: o[0],
565
+ number: Number.isNaN(Number(o[1])) ? o[1] : Number(o[1]),
566
+ level: o[2],
567
+ time: Number(o[3]),
568
+ key: o[4]
569
569
  };
570
570
  }
571
571
  /**
@@ -574,27 +574,27 @@ class rt {
574
574
  * @param principle 告警规则
575
575
  * @param options
576
576
  */
577
- checkWeather(e, t, o = {}) {
578
- var l, m, M, g, I, c, w, N, v, S, Y, F, T, D, H;
579
- let i = 0, a = 0, n = 0, s = 0;
580
- const d = Math.round(((m = (l = t == null ? void 0 : t.SEVERE) == null ? void 0 : l.sigWave) == null ? void 0 : m.number) * 1.6 * 100) / 100, r = (g = (M = t == null ? void 0 : t.SEVERE) == null ? void 0 : M.sigWave) == null ? void 0 : g.number, u = (c = (I = t == null ? void 0 : t.HEAVY) == null ? void 0 : I.sigWave) == null ? void 0 : c.number, y = Math.round((((N = (w = t == null ? void 0 : t.SEVERE) == null ? void 0 : w.wind) == null ? void 0 : N.number) + 2) * 100) / 100, h = (S = (v = t == null ? void 0 : t.SEVERE) == null ? void 0 : v.wind) == null ? void 0 : S.number, f = (F = (Y = t == null ? void 0 : t.HEAVY) == null ? void 0 : Y.wind) == null ? void 0 : F.number;
581
- for (let V = 0; V < (e == null ? void 0 : e.length); V++) {
582
- const E = e[V], P = (D = (T = E == null ? void 0 : E.meteo) == null ? void 0 : T.wave) == null ? void 0 : D.sig, A = (H = E == null ? void 0 : E.meteo) == null ? void 0 : H.wind, J = V ? p(E.eta).diff(p(e[V - 1].eta), "hour", !0) : 0;
583
- s = J > s ? J : s, W == null || W.info("[%s] check sig.wave: %j", o.requestId, { ...P, dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: u }), (P == null ? void 0 : P.height) >= d ? E.isDangerous = !0 : (P == null ? void 0 : P.height) >= r ? E.isSevere = !0 : (P == null ? void 0 : P.height) >= u && (E.isHeavy = !0), W == null || W.info("[%s] check wind: %j", o.requestId, { ...A, dgThd4Wd: y, svThd4Wd: h, hvThd4Wd: f }), (A == null ? void 0 : A.scale) >= y ? (E.isDangerous = !0, delete E.isSevere, delete E.isHeavy) : (A == null ? void 0 : A.scale) > h ? (E.isDangerous || (E.isSevere = !0), delete E.isHeavy) : (A == null ? void 0 : A.scale) === f && !E.isDangerous && !E.isSevere && (E.isHeavy = !0), i += E.isDangerous ? J : 0, a += E.isSevere ? J : 0, n += E.isHeavy ? J : 0;
577
+ checkWeather(e, t, n = {}) {
578
+ var m, C, k, p, v, r, h, b, f, D, S, A, H, T, x;
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;
584
584
  }
585
- return i = Math.round(i * 100) / 100, a = Math.round(a * 100) / 100, n = Math.round(n * 100) / 100, s = Math.round(s), { sample: e, dangerous: i, severe: a, heavy: n, step: s < 3 ? 3 : s, wind: { dgThd4Wd: y, svThd4Wd: h, hvThd4Wd: f }, sig: { dgThd4Wv: d, svThd4Wv: r, 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: y, svThd4Wd: l, hvThd4Wd: M }, sig: { dgThd4Wv: d, svThd4Wv: c, hvThd4Wv: u } };
586
586
  }
587
587
  }
588
- const kt = new rt();
589
- let k;
588
+ const Dt = new ft();
589
+ let I;
590
590
  try {
591
- k = Q.getLogger("vessel");
591
+ I = at.getLogger("vessel");
592
592
  } catch {
593
593
  } finally {
594
594
  }
595
- const ct = new ot("", !0);
596
- var dt = /* @__PURE__ */ ((j) => (j.common = "common", j.container = "container", j.tugs = "tugs", j))(dt || {}), ut = /* @__PURE__ */ ((j) => (j.Ballast = "Ballast", j.Laden = "Laden", j))(ut || {}), ht = /* @__PURE__ */ ((j) => (j.Cp = "CP", j.Perf = "Basis", j.Instruct = "Other", j))(ht || {});
597
- class C {
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 {
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)
@@ -607,11 +607,11 @@ class C {
607
607
  * @param draught 吃水 m
608
608
  * @return [0.55, 0.85]
609
609
  */
610
- static blockCoefficient(e, t, o, i) {
611
- let a = Math.round(e / (t * o * i) * 100) / 100;
612
- a = a < 0.55 ? 0.55 : a > 0.85 ? 0.85 : a;
613
- const n = [0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85], s = n.map((d) => Math.abs(d - a));
614
- return n[s.indexOf(Math.min(...s))];
610
+ static blockCoefficient(e, t, n, i) {
611
+ let o = Math.round(e / (t * n * i) * 100) / 100;
612
+ o = o < 0.55 ? 0.55 : o > 0.85 ? 0.85 : o;
613
+ const a = [0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85], s = a.map((d) => Math.abs(d - o));
614
+ return a[s.indexOf(Math.min(...s))];
615
615
  }
616
616
  /**
617
617
  * @see https://baike.baidu.com/item/%E5%BC%97%E5%8A%B3%E5%BE%B7%E6%95%B0/228891?fromModule=search-result_lemma-recommend
@@ -624,8 +624,8 @@ class C {
624
624
  * @param g 重力加速度 9.80 m/s^2
625
625
  * @return [0.05, 0.30]
626
626
  */
627
- static froudeNumber(e, t, o = 9.8) {
628
- let i = Math.round(Math.sqrt(e * e / (o * t)) * 100) / 100;
627
+ static froudeNumber(e, t, n = 9.8) {
628
+ let i = Math.round(Math.sqrt(e * e / (n * t)) * 100) / 100;
629
629
  return i = i < 0.05 ? 0.05 : i > 0.3 ? 0.3 : i, i;
630
630
  }
631
631
  /**
@@ -635,7 +635,7 @@ class C {
635
635
  * @param loadCondition
636
636
  * @private
637
637
  */
638
- static amendFactor(e, t, o) {
638
+ static amendFactor(e, t, n) {
639
639
  const i = {
640
640
  0.55: [1.7, -1.4, -7.4],
641
641
  0.6: [2.2, -2.5, -9.7],
@@ -645,7 +645,7 @@ class C {
645
645
  0.8: [2.6, -13.1, -15.1],
646
646
  0.85: [3.1, -18.7, 28]
647
647
  };
648
- let n = {
648
+ let a = {
649
649
  0.55: [1.7, -1.4, -7.4],
650
650
  0.6: [2.2, -2.5, -9.7],
651
651
  0.65: [2.6, -3.7, -11.6],
@@ -654,7 +654,7 @@ class C {
654
654
  0.8: [3, -16.3, -21.6],
655
655
  0.85: [3.4, -20.9, 31.8]
656
656
  }[e];
657
- return o === "Laden" && (n = i[e]), n[0] + n[1] * t + n[2] * Math.pow(t, 2);
657
+ return n === "Laden" && (a = i[e]), a[0] + a[1] * t + a[2] * Math.pow(t, 2);
658
658
  }
659
659
  /**
660
660
  * 失速方向因子
@@ -668,8 +668,8 @@ class C {
668
668
  * @private
669
669
  */
670
670
  static directionFactor(e, t = 0) {
671
- let o;
672
- return e > 30 && e <= 60 ? o = (1.7 - 0.03 * Math.pow(t - 4, 2)) / 2 : e > 60 && e <= 150 ? o = (0.9 - 0.06 * Math.pow(t - 6, 2)) / 2 : e > 150 && e <= 180 ? o = (0.4 - 0.03 * Math.pow(t - 8, 2)) / 2 : o = 1, Math.round(o * 1e5) / 1e5;
671
+ let n;
672
+ return e > 30 && e <= 60 ? n = (1.7 - 0.03 * Math.pow(t - 4, 2)) / 2 : e > 60 && e <= 150 ? n = (0.9 - 0.06 * Math.pow(t - 6, 2)) / 2 : e > 150 && e <= 180 ? n = (0.4 - 0.03 * Math.pow(t - 8, 2)) / 2 : n = 1, Math.round(n * 1e5) / 1e5;
673
673
  }
674
674
  /**
675
675
  * 失速船型因子
@@ -682,10 +682,10 @@ class C {
682
682
  * @param bn
683
683
  * @private
684
684
  */
685
- static vesselTagFactor(e, t, o, i = 0) {
685
+ static vesselTagFactor(e, t, n, i = 0) {
686
686
  i = i > 6 ? i - 0.9 * (i - 6) : i;
687
- let a;
688
- return o === "container" ? a = 0.7 * i + Math.pow(i, 6.5) / (22 * Math.pow(e, 2 / 3)) : t === "Ballast" ? a = 0.7 * i + Math.pow(i, 6.5) / (2.7 * Math.pow(e, 2 / 3)) : a = 0.5 * i + Math.pow(i, 6.5) / (2.7 * Math.pow(e, 2 / 3)), a;
687
+ let o;
688
+ return n === "container" ? o = 0.7 * i + Math.pow(i, 6.5) / (22 * Math.pow(e, 2 / 3)) : t === "Ballast" ? o = 0.7 * i + Math.pow(i, 6.5) / (2.7 * Math.pow(e, 2 / 3)) : o = 0.5 * i + Math.pow(i, 6.5) / (2.7 * Math.pow(e, 2 / 3)), o;
689
689
  }
690
690
  /**
691
691
  * 浪高影响因子
@@ -694,8 +694,8 @@ class C {
694
694
  */
695
695
  static waveHeightFactor(e, t) {
696
696
  e = e < 0 ? 0.2 : e, e = e > 6 ? e - 0.9 * (e - 6) : e, e = e > 9 ? 9 : e;
697
- let o;
698
- return t > 30 && t <= 60 ? o = -0.6 : t > 60 && t <= 90 ? o = -0.4 : t > 90 && t <= 120 ? o = e < 3 ? 0.4 : -0.3 : t > 120 && t <= 150 ? o = e < 3 ? 0.6 : -0.5 : t > 150 && t <= 180 ? o = e < 3 ? 0.7 : -0.6 : o = -0.7, Math.round(o * (0.144 * Math.pow(e, 2) + 0.178 * e) * 1e4) / 1e4;
697
+ let n;
698
+ return t > 30 && t <= 60 ? n = -0.6 : t > 60 && t <= 90 ? n = -0.4 : t > 90 && t <= 120 ? n = e < 3 ? 0.4 : -0.3 : t > 120 && t <= 150 ? n = e < 3 ? 0.6 : -0.5 : t > 150 && t <= 180 ? n = e < 3 ? 0.7 : -0.6 : n = -0.7, Math.round(n * (0.144 * Math.pow(e, 2) + 0.178 * e) * 1e4) / 1e4;
699
699
  }
700
700
  /**
701
701
  * 组装船舶运行参数
@@ -705,20 +705,20 @@ class C {
705
705
  * @param bearing 方位角
706
706
  * @private
707
707
  */
708
- static assembleProperties(e, t, o, i) {
709
- var h;
710
- const a = e.lbp ?? e.length ?? e.lengthOverall ?? 198.9642, n = e.draught ?? 8, s = e.breadthMoulded ?? e.breadth ?? e.breadthExtreme ?? 32.4572, d = e.deadweight ?? 67035.7773, r = ((h = e == null ? void 0 : e.type) == null ? void 0 : h.toLowerCase()) || "common";
708
+ static assembleProperties(e, t, n, i) {
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";
711
711
  return {
712
- tag: r.indexOf("container") > -1 ? "container" : r.indexOf("tugs") > -1 ? "tugs" : "common",
713
- lbp: a,
712
+ tag: c.indexOf("container") > -1 ? "container" : c.indexOf("tugs") > -1 ? "tugs" : "common",
713
+ lbp: o,
714
714
  loadCondition: t,
715
- draught: n,
715
+ draught: a,
716
716
  breadthMoulded: s,
717
717
  // 排水量(吨)= 载重量(吨)/ 1.025 + 吃水(米)× 船舶型宽(米)× 船舶型长(米)× 0.7
718
718
  // 其中,1.025是指海水的密度,吨是指公吨,吃水是指船舶的最大吃水深度。船舶型宽是指船舶的最大型宽,船舶型长是指船舶的设计型长。上述公式是针对常规船舶适用的,不同类型的船舶可能会有一些差异。
719
- displacement: Math.round((d / 1.025 + n * s * a * 0.7) * 1e4) / 1e4,
719
+ displacement: Math.round((d / 1.025 + a * s * o * 0.7) * 1e4) / 1e4,
720
720
  // 换算为m/s
721
- speed: Math.round((o ?? 14.1382) * 1852 / 3600 * 1e4) / 1e4,
721
+ speed: Math.round((n ?? 14.1382) * 1852 / 3600 * 1e4) / 1e4,
722
722
  bearing: i || 90
723
723
  };
724
724
  }
@@ -732,37 +732,37 @@ class C {
732
732
  * @param useMeteo true 启用气象分析
733
733
  * @param useRouteParam true 启用设置速度
734
734
  */
735
- static async speedLoseAt(e, t, o, i = "", a = 2, n = !0, s = !1, d = {}) {
736
- let r;
737
- if (t.velocity && s && (e.speed = z.roundPrecision(t.velocity * 1852 / 3600, 6)), n) {
735
+ static async speedLoseAt(e, t, n, i = "", o = 2, a = !0, s = !1, d = {}) {
736
+ let c;
737
+ if (t.velocity && s && (e.speed = J.roundPrecision(t.velocity * 1852 / 3600, 6)), a) {
738
738
  let u;
739
739
  if (d.meteo2)
740
740
  try {
741
- const l = await ct.spotForecast(t.lat, t.lng, o.utc().format(), !1, !1, !0, d), [m] = tt.pickHourly(l, o);
742
- u = tt.toLegacy(m);
743
- } catch (l) {
744
- k.warn("[%s] meteo2 spot(%j) forecast failed: %s", d.requestId, { ...t, eta: o.utc().format() }, l);
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);
745
745
  }
746
746
  else
747
- u = await nt.queryPointFactor(t.lng, t.lat, o.valueOf(), "wind,wave,current,watertemp", i, d);
748
- const y = C.weatherFactor(e, u), h = C.currentFactor(e.bearing, u == null ? void 0 : u.current, a), f = Math.round((e.speed * 1.943844 + y + h) * 100) / 100;
749
- r = {
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
750
  meteo: { ...u },
751
751
  wxFactor: y,
752
- cFactor: h,
753
- speed: t.velocity && s ? t.velocity : f < 0 ? 1 : f,
754
- eta: o.utc().format("YYYY-MM-DDTHH:mm[Z]"),
755
- etd: o.utc().format("YYYY-MM-DDTHH:mm[Z]")
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]")
756
756
  };
757
757
  } else
758
- r = {
758
+ c = {
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: o.utc().format("YYYY-MM-DDTHH:mm[Z]"),
763
- etd: o.utc().format("YYYY-MM-DDTHH:mm[Z]")
762
+ eta: n.utc().format("YYYY-MM-DDTHH:mm[Z]"),
763
+ etd: n.utc().format("YYYY-MM-DDTHH:mm[Z]")
764
764
  };
765
- return delete t.meteo, delete t.wxFactor, delete t.cFactor, delete t.speed, delete t.etd, { ...r, ...t };
765
+ return delete t.meteo, delete t.wxFactor, delete t.cFactor, delete t.speed, delete t.etd, { ...c, ...t };
766
766
  }
767
767
  /**
768
768
  * 基于步长计算失速样本
@@ -777,53 +777,53 @@ class C {
777
777
  * @param useRouteParam true 启用航线上设置的参数 { suspend: 停留时长(小时), velocity: 速度(kts)}
778
778
  * @private
779
779
  */
780
- static async speedLoseInHoursStep(e, t, o, i, a, n, s = "", d = !0, r = !1, u = {}) {
780
+ static async speedLoseInHoursStep(e, t, n, i, o, a, s = "", d = !0, c = !1, u = {}) {
781
781
  t.utc();
782
- const y = t.clone().add(14, "days"), h = [], f = [];
783
- let l = 0, m = 0, M, g;
784
- for (let I = 0; I < n.length - 1; I++) {
785
- let c = n[I];
786
- c.distanceFromStart = Math.round((a + m) * 1e4) / 1e4;
787
- const w = n[I + 1];
788
- if (e.bearing = B.calculateBearing(c, w, !w.gcToPrevious), c.bearing = e.bearing, c.suspend && r) {
789
- c.eta = c.eta || t.format("YYYY-MM-DDTHH:mm[Z]"), c.elapsed = c.elapsed ?? 0;
790
- const S = c.suspend - c.elapsed;
791
- if (i - l > S)
792
- i = i - l - S, t.add(S, "hour"), c.elapsed = c.suspend;
782
+ const y = t.clone().add(14, "days"), l = [], M = [];
783
+ let m = 0, C = 0, k, p;
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;
793
793
  else {
794
- const Y = i - l;
795
- c.elapsed += Y, t.add(Y, "hour"), i = 0;
794
+ const S = i - m;
795
+ r.elapsed += S, t.add(S, "hour"), i = 0;
796
796
  }
797
- if (k == null || k.info(`[%s] suspend ${c.elapsed} hours at %j, and remain ${i} hours need to go...`, u.requestId, c), i === 0)
798
- return c.distanceFromPrevious = m, { etd: t, from: g || c, to: c, next: n.filter((Y) => Y), wps: h, days: f };
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 };
799
799
  } else
800
- c.suspend = 0;
801
- d = t.isAfter(y) ? !1 : d, c = await C.speedLoseAt(e, c, t, s, 0, d, r, u), g = g || c, c.important && h.push(c), t.isSameOrAfter(o) && (f.push(c), o.add(24, "hour"));
802
- const N = B.calculateDistance(c, w, !w.gcToPrevious);
803
- let v = Math.ceil(N / g.speed * 1e4) / 1e4;
804
- if (l + v < i) {
805
- if (l += v, t.add(v, "hour"), delete n[I], k == null || k.debug(
806
- `[%s] go to %j from %j with ${N}nm, and cost ${v} hours`,
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
807
  u.requestId,
808
- { lat: w.lat, lng: w.lng },
809
- { lat: g.lat, lng: g.lng, etd: g.etd }
810
- ), m += N, n.filter((S) => S).length <= 1) {
811
- M = w, M.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), M.distanceFromPrevious = N, M.distanceFromStart = Math.round((a + m) * 1e4) / 1e4, h.push(M), delete n[I + 1];
808
+ { lat: h.lat, lng: h.lng },
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];
812
812
  break;
813
813
  }
814
814
  } else {
815
- v = i - l, t.add(v, "hour");
816
- const S = z.roundPrecision(g.speed * v, 4);
817
- M = B.calculateCoordinate(c, e.bearing, S, "nauticalmiles", !w.gcToPrevious), M.eta = t.format("YYYY-MM-DDTHH:mm[Z]"), n[I] = M, k == null || k.debug(
818
- `[%s] go to %j from %j with ${S}nm, and cost ${v} hours`,
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
819
  u.requestId,
820
- { lat: M.lat, lng: M.lng },
821
- { lat: c.lat, lng: c.lng, etd: c.etd }
822
- ), m += S, M.distanceFromPrevious = Math.round(m * 1e4) / 1e4, M.distanceFromStart = Math.round((a + m) * 1e4) / 1e4;
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;
823
823
  break;
824
824
  }
825
825
  }
826
- return { etd: t, from: g, to: M, next: n.filter((I) => I), wps: h, days: f };
826
+ return { etd: t, from: p, to: k, next: a.filter((v) => v), wps: l, days: M };
827
827
  }
828
828
  /**
829
829
  * 洋流影响因子
@@ -831,12 +831,12 @@ class C {
831
831
  * @param current 洋流要素
832
832
  * @param role 1: 船东, 2: 租家, 0: 未知
833
833
  */
834
- static currentFactor(e, t, o = 0) {
834
+ static currentFactor(e, t, n = 0) {
835
835
  const i = (e - (t == null ? void 0 : t.degree) || 0) / 180 * Math.PI;
836
836
  if (Math.abs(i) === Math.PI / 2)
837
837
  return 0;
838
- let a = ((t == null ? void 0 : t.kts) || 0) * Math.cos(i);
839
- return o & 2 ? a = Math.ceil(a * 100) / 100 : o & 1 ? a = Math.floor(a * 100) / 100 : a = Math.round(a * 100) / 100, Math.abs(a) > 5 ? 0 : a;
838
+ let o = ((t == null ? void 0 : t.kts) || 0) * Math.cos(i);
839
+ return n & 2 ? o = Math.ceil(o * 100) / 100 : n & 1 ? o = Math.floor(o * 100) / 100 : o = Math.round(o * 100) / 100, Math.abs(o) > 5 ? 0 : o;
840
840
  }
841
841
  /**
842
842
  * 风浪影响因子
@@ -844,16 +844,16 @@ class C {
844
844
  * @param wwc 气象要素
845
845
  */
846
846
  static weatherFactor(e, t) {
847
- var y, h, f, l, m, M, g;
848
- k == null || k.debug("calculate weather factor via: %j", { ...e, ...t });
849
- const o = C.blockCoefficient(e.displacement, e.lbp, e.breadthMoulded, e.draught), i = C.froudeNumber(e.speed, e.lbp), a = C.amendFactor(o, i, e.loadCondition);
850
- let n = Math.abs(e.bearing % 360 - (((y = t == null ? void 0 : t.wind) == null ? void 0 : y.degree) % 360 || 0));
851
- n = n > 180 ? 360 - n : n;
852
- const s = C.directionFactor(n, (h = t == null ? void 0 : t.wind) == null ? void 0 : h.scale), d = C.vesselTagFactor(e.displacement, e.loadCondition, e.tag, (f = t == null ? void 0 : t.wind) == null ? void 0 : f.scale);
853
- let r = s * a * 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)), k == null || k.debug("wind wx factor = %d", r), n = Math.abs(e.bearing % 360 - (((m = (l = t == null ? void 0 : t.wave) == null ? void 0 : l.sig) == null ? void 0 : m.degree) % 360 || 0));
855
- const u = C.waveHeightFactor(((g = (M = t == null ? void 0 : t.wave) == null ? void 0 : M.sig) == null ? void 0 : g.height) ?? 1, n);
856
- return k == null || k.debug("wave wx factor = %d", u), r = r * 0.4 + u, k == null || k.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;
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));
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;
857
857
  }
858
858
  /**
859
859
  * 全程失速分析(走完航程)
@@ -867,14 +867,14 @@ class C {
867
867
  * @param useMeteo true 启用气象分析
868
868
  * @param useRouteParam
869
869
  */
870
- static async analyseInstant(e, t, o, i, a, n = "", s = 0, d = !0, r = !1, u = {}) {
871
- var J, _, K, G, L;
872
- const y = p().valueOf();
873
- e.lng = z.convertToStdLng(e.lng);
874
- const { route: h, waypoints: f } = a.points, l = B.calculateSubRoute(e, h);
875
- if (((J = l[0]) == null ? void 0 : J.length) <= 1)
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();
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)
876
876
  return;
877
- const { v0: m, label: M } = e.sog ? {
877
+ const { v0: C, label: k } = e.sog ? {
878
878
  v0: e.sog,
879
879
  label: "Other"
880
880
  /* Instruct */
@@ -882,59 +882,66 @@ class C {
882
882
  v0: i.speed,
883
883
  label: "CP"
884
884
  /* Cp */
885
- }, g = C.assembleProperties(o, i.loadCondition, m, 0), I = f.length ? B.calculateSubWaypoints(e, f) : [];
886
- I.forEach((x) => x.important = !0);
887
- const c = {
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 = {
888
888
  from: { ...e },
889
- route: l,
890
- waypoints: I,
891
- v0: m,
892
- label: M
893
- }, w = {
889
+ route: m,
890
+ waypoints: v,
891
+ v0: C,
892
+ label: k
893
+ }, h = {
894
894
  hours: [],
895
895
  days: [],
896
896
  wps: []
897
897
  };
898
- s || (B.calculateRouteDistance(l) / i.speed <= 72 ? s = 3 : s = 6);
899
- let N = B.simplifyRouteToCoordinates(l, I, 0), v = 0, S = 0, Y = 0, F = 0;
900
- t = p(t).utc();
901
- const T = t.clone();
902
- for (; N.length > 0; ) {
903
- const x = s - t.hour() % s, q = Math.ceil(t.clone().add(x, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4, O = await C.speedLoseInHoursStep(
904
- g,
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(
904
+ p,
905
905
  t,
906
- T,
907
- q,
908
- v,
909
- N,
910
- n,
906
+ H,
907
+ P,
908
+ f,
909
+ b,
910
+ a,
911
911
  d,
912
- r,
912
+ c,
913
913
  u
914
914
  );
915
- (_ = O.from) != null && _.speed && (w.hours.push(O.from), w.wps.push(...O.wps), w.days.push(...O.days)), N = O == null ? void 0 : O.next, N.length || w.hours.push(O == null ? void 0 : O.to), v += Math.round((((K = O == null ? void 0 : O.to) == null ? void 0 : K.distanceFromPrevious) ?? 0) * 1e4) / 1e4;
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;
916
916
  }
917
- const D = w.hours;
918
- for (let x = 0; x < D.length - 1; x++) {
919
- const q = p(D[x + 1].eta).diff(D[x].etd, "hour", !0) || 1;
920
- S += (D[x].wxFactor || 0) * q, Y += (D[x].cFactor || 0) * q, F += q;
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;
921
921
  }
922
- (G = w.wps) == null || G.forEach((x, q) => {
923
- if (q) {
924
- const O = w.wps[q - 1], et = x.distanceFromStart - O.distanceFromStart, X = p(x.eta).diff(p(O.etd), "h", !0);
925
- if (X < 1)
926
- x.avgSpd = O.speed;
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
927
  else {
928
- x.avgSpd = Math.round(et / X * 100) / 100;
929
- const $ = Math.round((O.speed + x.speed) / 2 * 100) / 100;
930
- x.avgSpd = x.avgSpd > $ ? $ : x.avgSpd;
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
931
  }
932
932
  }
933
- }), c.sample = w;
934
- const H = w.hours.at(0), V = w.hours.at(-1);
935
- c.distance = Math.round(V.distanceFromStart * 1e4) / 1e4, c.etd = p(H.eta).utc().format(), c.eta = p(V.eta).utc().format(), c.wxFactor = Math.round(S / F * 1e4) / 1e4, c.cFactor = Math.round(Y / F * 1e4) / 1e4, c.avgSpeed = Math.round(V.distanceFromStart / F * 1e4) / 1e4, c.totalHrs = Math.round(F * 1e4) / 1e4, c.totalFoCons = Math.round((i == null ? void 0 : i.fo) / 24 * c.totalHrs * 1e3) / 1e3, c.totalDgoCons = Math.round((i == null ? void 0 : i.dgo) / 24 * c.totalHrs * 1e3) / 1e3;
936
- const P = p().valueOf() - y, A = ((L = w == null ? void 0 : w.hours) == null ? void 0 : L.length) || 1;
937
- return k == null || k.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", u == null ? void 0 : u.requestId, P, A, Math.round(P / A * 1e3) / 1e3), c;
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,
939
+ 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;
938
945
  }
939
946
  /**
940
947
  * 分段失速分析(最多走hours 小时)
@@ -949,64 +956,69 @@ class C {
949
956
  * @param useMeteo true 启用气象分析
950
957
  * @param useRouteParam
951
958
  */
952
- static async analyseInstantWithThreshed(e, t, o, i, a, n, s, d = "", r = 3, u = !0, y = !1, h = {}) {
953
- var J, _, K, G;
954
- const f = p().valueOf();
955
- e.lng = z.convertToStdLng(e.lng);
956
- const { v0: l, label: m } = e.sog ? {
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();
962
+ e.lng = J.convertToStdLng(e.lng);
963
+ const { v0: m, label: C } = e.sog ? {
957
964
  v0: e.sog,
958
965
  label: "Other"
959
966
  /* Instruct */
960
967
  } : {
961
- v0: a.speed,
968
+ v0: o.speed,
962
969
  label: "CP"
963
970
  /* Cp */
964
- }, M = C.assembleProperties(i, a.loadCondition, l, 0), g = B.calculateSubRoute(e, n);
965
- if (((J = g[0]) == null ? void 0 : J.length) <= 1)
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)
966
973
  return;
967
- const I = s.length ? B.calculateSubWaypoints(e, s) : [];
968
- I.forEach((L) => L.important = !0);
969
- let c = B.simplifyRouteToCoordinates(g, I, 0), w = 0, N = 0, v = 0, S = 0;
970
- const Y = {
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 = {
971
978
  hours: [],
972
979
  wps: [],
973
980
  days: []
974
981
  };
975
- t = p(t).utc();
976
- const F = t.clone();
977
- for (; c.length > 0; ) {
978
- const L = r - t.hour() % r;
979
- let x = Math.ceil(t.clone().add(L, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4;
980
- x = t.clone().add(x, "h").isSameOrAfter(o) ? o.diff(t, "h", !0) * 1e4 / 1e4 : x;
981
- const q = await C.speedLoseInHoursStep(M, t, F, x, w, c, d, u, y, h);
982
- if ((_ = q.from) != null && _.speed && (Y.hours.push(q.from), q != null && q.wps && Y.wps.push(...q.wps), Y.days.push(...q.days)), c = q == null ? void 0 : q.next, c.length || Y.hours.push(q == null ? void 0 : q.to), w += Math.round((((K = q == null ? void 0 : q.to) == null ? void 0 : K.distanceFromPrevious) ?? 0) * 1e4) / 1e4, !x)
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)
983
990
  break;
984
991
  }
985
- const T = Y.hours;
986
- for (let L = 0; L < T.length - 1; L++) {
987
- const x = p(T[L + 1].eta).diff(T[L].etd, "hour", !0);
988
- N += T[L].wxFactor * x, v += T[L].cFactor * x, S += x;
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;
989
996
  }
990
- const D = Y.hours.at(0), H = Y.hours.at(-1), V = {
991
- sample: Y,
992
- distance: Math.round(((H == null ? void 0 : H.distanceFromStart) || 0) * 1e4) / 1e4,
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,
993
1000
  // 注意,可能会在first节点Drift,所有采用eta做为初始出发时间
994
- etd: p(D.eta).utc().format(),
995
- eta: p(H == null ? void 0 : H.eta).utc().format(),
996
- wxFactor: Math.round(N / S * 1e4) / 1e4,
997
- cFactor: Math.round(v / S * 1e4) / 1e4,
998
- avgSpeed: Math.round(((H == null ? void 0 : H.distanceFromStart) || 0) / S * 1e4) / 1e4,
999
- totalHrs: Math.round(S * 1e4) / 1e4,
1000
- totalFoCons: Math.round((a == null ? void 0 : a.fo) / 24 * S * 1e3) / 1e3,
1001
- totalDgoCons: Math.round((a == null ? void 0 : a.dgo) / 24 * S * 1e3) / 1e3,
1002
- from: D,
1003
- to: H,
1004
- route: g,
1005
- waypoints: I,
1006
- v0: l,
1007
- label: m
1008
- }, P = p().valueOf() - f, A = ((G = Y == null ? void 0 : Y.hours) == null ? void 0 : G.length) || 1;
1009
- return k == null || k.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", h == null ? void 0 : h.requestId, P, A, Math.round(P / A * 1e3) / 1e3), V;
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,
1010
+ waypoints: j,
1011
+ v0: m,
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;
1010
1022
  }
1011
1023
  /**
1012
1024
  * 在指定航线条件下,基于多CP,动态计算最优成本(租金+油费)方案
@@ -1023,57 +1035,57 @@ class C {
1023
1035
  * @param lane 基础航线(重要转向点)
1024
1036
  * @param options
1025
1037
  */
1026
- static async analyseCost(e, t, o, i, a = {}) {
1027
- var g, I;
1028
- const n = p().valueOf(), s = [];
1029
- a.meteo2 = a.meteo2 || !0, e.speedStep = e.speedStep || 3, e.alterStep = e.alterStep ?? 1;
1030
- const d = B.calculateRouteDistance(i.route);
1031
- let r = 0;
1032
- o.forEach((c) => {
1033
- const w = Math.ceil(d / c.speed / 24);
1034
- r = r < w ? w : r;
1035
- }), r = r * 1.3;
1036
- const u = p.utc(e.etd).add(r ?? 14, "day");
1038
+ static async analyseCost(e, t, n, i, o = {}) {
1039
+ var p, v;
1040
+ const a = w().valueOf(), s = [];
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");
1037
1049
  let y = 1;
1038
- for (const c of o) {
1039
- const w = JSON.parse(JSON.stringify(i.route)), N = JSON.parse(JSON.stringify(i.waypoints)), v = await C.analyseInstantWithThreshed(
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(
1040
1052
  { lat: e.lat, lng: e.lng },
1041
1053
  e.etd,
1042
1054
  u,
1043
1055
  t,
1044
- c,
1045
- w,
1046
- N,
1056
+ r,
1057
+ h,
1058
+ b,
1047
1059
  e.meteoVendor,
1048
1060
  e.speedStep,
1049
1061
  e.useMeteo,
1050
1062
  e.useRouteParam,
1051
- a
1063
+ o
1052
1064
  );
1053
- v && (await C.calculateCost(v, c, e, a), s.push(v), k == null || k.info("[%s][L%d-%d] analyse from %s to %s cost: %j", a.requestId, 1, y, e.etd, u.format(), {
1054
- cost: v.cost.total,
1055
- distance: v.distance,
1056
- hours: v.totalHrs,
1057
- cp: `${c.speed}/${c.fo}/${c.dgo}`
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}`
1058
1070
  })), y++;
1059
1071
  }
1060
- s.sort((c, w) => c.cost.total - w.cost.total);
1061
- const h = s.at(0), f = s.at(1), l = [];
1062
- if (l.push({ combined: !1, speeds: [h], cost: (g = h.cost) == null ? void 0 : g.total }), f) {
1063
- const c = h.cost.cp, w = f.cost.cp, N = p(h.eta), v = p(h.etd), S = N.diff(v, "days", !0);
1064
- let Y = Math.ceil(S / 2);
1065
- Y = Y > 7 ? 7 : Y < e.alterStep ? e.alterStep : Y;
1066
- let F = 2, T = { combined: !1, speeds: [f], cost: (I = f.cost) == null ? void 0 : I.total }, D;
1067
- for (; Y >= e.alterStep; ) {
1068
- const H = await C.combinedAnalyse(e, t, u, [c, w], i, Y, { ...a, level: F });
1069
- if (T.cost > H.cost ? D ? (D == null ? void 0 : D.cost) > H.cost && (D = H) : (D = T, T = H) : (!D || (D == null ? void 0 : D.cost) > H.cost) && (D = H), Y <= e.alterStep)
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)
1070
1082
  break;
1071
- Y = Math.ceil(Y / 2), F += 1;
1083
+ S = Math.ceil(S / 2), A += 1;
1072
1084
  }
1073
- l.push(T), D && l.push(D);
1085
+ m.push(H), T && m.push(T);
1074
1086
  }
1075
- const M = p().valueOf() - n;
1076
- return k == null || k.info("[%s] analyse elapsed: %d ms", a == null ? void 0 : a.requestId, M), l.sort((c, w) => c.cost - w.cost);
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);
1077
1089
  }
1078
1090
  /**
1079
1091
  * 按步长多次减半,分别用7,4,2,1天步长及cpa,cpb交替计算各种组合下的成本
@@ -1085,12 +1097,12 @@ class C {
1085
1097
  * @param step 步长,7,4,2,1
1086
1098
  * @param options
1087
1099
  */
1088
- static async combinedAnalyse(e, t, o, i, a, n, s = {}) {
1089
- s.counter = 1, k == null || k.info("[%s][L%d] analyse with alternate cp in every %d days", s.requestId, s.level, n);
1090
- const d = await C.alternateAnalyse(e, t, o, i, 0, a, n, s), r = d.reduce((h, f) => h + f.cost.total, 0);
1091
- k == null || k.info("[%s][L%d] cost with cpa/cpb turn: %d", s.requestId, s.level, r);
1092
- const u = await C.alternateAnalyse(e, t, o, i, 1, a, n, s), y = u.reduce((h, f) => h + f.cost.total, 0);
1093
- return k == null || k.info("[%s][L%d] cost with cpb/cpa turn: %d", s.requestId, s.level, y), r < y ? { combined: !0, cost: Math.round(r * 1e3) / 1e3, speeds: d, step: n } : { combined: !0, cost: Math.round(y * 1e3) / 1e3, speeds: u, step: n };
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 };
1094
1106
  }
1095
1107
  /**
1096
1108
  * 基于cp索引,交替计算指定步长下的成本
@@ -1103,37 +1115,37 @@ class C {
1103
1115
  * @param step 步长,7,4,2,1
1104
1116
  * @param options
1105
1117
  */
1106
- static async alternateAnalyse(e, t, o, i, a, n, s, d = {}) {
1107
- var h, f;
1108
- let r = p.utc(e.etd);
1118
+ static async alternateAnalyse(e, t, n, i, o, a, s, d = {}) {
1119
+ var l, M;
1120
+ let c = w.utc(e.etd);
1109
1121
  const u = { lat: e.lat, lng: e.lng }, y = [];
1110
- for (; r.isBefore(o); ) {
1111
- const l = r.clone().utc().add(s, "day"), m = JSON.parse(JSON.stringify(n.route)), M = JSON.parse(JSON.stringify(n.waypoints)), g = i[a], I = await C.analyseInstantWithThreshed(
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(
1112
1124
  u,
1113
- r.format(),
1114
- l,
1115
- t,
1116
- g,
1125
+ c.format(),
1117
1126
  m,
1118
- M,
1127
+ t,
1128
+ p,
1129
+ C,
1130
+ k,
1119
1131
  e.meteoVendor,
1120
1132
  e.speedStep,
1121
1133
  e.useMeteo,
1122
1134
  e.useRouteParam,
1123
1135
  d
1124
1136
  );
1125
- I && (await C.calculateCost(I, g, e, d), k == null || k.info(
1137
+ v && (await q.calculateCost(v, p, e, d), I == null || I.info(
1126
1138
  "[%s][L%d-%d] analyse from %s to %s cost: %j",
1127
1139
  d.requestId,
1128
1140
  d.level,
1129
1141
  d.counter,
1130
- r.utc().format(),
1131
- l.utc().format(),
1132
- { cost: I.cost.total, distance: I.distance, hours: I.totalHrs, cp: `${g.speed}/${g.fo}/${g.dgo}` }
1142
+ c.utc().format(),
1143
+ m.utc().format(),
1144
+ { cost: v.cost.total, distance: v.distance, hours: v.totalHrs, cp: `${p.speed}/${p.fo}/${p.dgo}` }
1133
1145
  )), d.counter = d.counter + 1;
1134
- const c = (f = (h = I == null ? void 0 : I.sample) == null ? void 0 : h.hours) == null ? void 0 : f.at(-1);
1135
- if (c)
1136
- u.lat = c.lat, u.lng = c.lng, r = p(c.eta), y.push(I), a = a ? 0 : 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;
1137
1149
  else
1138
1150
  break;
1139
1151
  }
@@ -1146,48 +1158,86 @@ class C {
1146
1158
  * @param props
1147
1159
  * @param options
1148
1160
  */
1149
- static async calculateCost(e, t, o, i = {}) {
1161
+ static async calculateCost(e, t, n, i = {}) {
1162
+ var o;
1150
1163
  if (e) {
1151
- const a = Math.round(e.totalHrs / 24 * (o.dailyHire || 0) * (1 - (o.addComm || 0)) * 1e3) / 1e3, n = Math.round(e.totalFoCons * (o.priceFO || 0) * 1e3) / 1e3, s = Math.round(e.totalDgoCons * (o.priceDGO || 0) * 1e3) / 1e3;
1164
+ const a = Math.round(e.totalHrs / 24 * (n.dailyHire || 0) * (1 - (n.addComm || 0)) * 1e3) / 1e3, s = Math.round(e.totalFoCons * (n.priceFO || 0) * 1e3) / 1e3, d = Math.round((e.totalDgoCons + (((o = e.extend) == null ? void 0 : o.totalDgoConsInECA) || 0)) * (n.priceDGO || 0) * 1e3) / 1e3;
1152
1165
  e.cost = {
1153
- total: Math.round((a + n + s) * 1e3) / 1e3,
1166
+ total: Math.round((a + s + d) * 1e3) / 1e3,
1154
1167
  hire: a,
1155
- bunker: Math.round((n + s) * 1e3) / 1e3,
1168
+ bunker: Math.round((s + d) * 1e3) / 1e3,
1156
1169
  cp: t
1157
1170
  };
1158
1171
  }
1159
1172
  return e;
1160
1173
  }
1174
+ /**
1175
+ * 计算单cp模式下的ECA属性
1176
+ */
1177
+ static async calculateECA(e, t, n = {}) {
1178
+ var d, c;
1179
+ const i = await R.intersectInECA(e.route);
1180
+ let o = 0, a = 0, s = 0;
1181
+ e.sample.wps.forEach((u) => {
1182
+ u.positionTime = w.utc(u.etd || u.eta).unix();
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;
1188
+ }
1189
+ return o = J.roundPrecision(o, 3), a = J.roundPrecision(a, 3), s = J.roundPrecision(s, 3), {
1190
+ distanceInECA: o,
1191
+ hoursInECA: a,
1192
+ totalDgoConsInECA: s,
1193
+ eca: i
1194
+ };
1195
+ }
1196
+ /**
1197
+ * 合并多cp组合模式下的速度集合
1198
+ * @param speeds
1199
+ * @param options
1200
+ */
1161
1201
  static async mergeSpeeds(e, t = {}) {
1162
- var l;
1163
- const o = {
1202
+ var v, r;
1203
+ const n = {
1164
1204
  hours: [],
1165
1205
  wps: [],
1166
1206
  days: []
1167
- }, i = e.reduce((m, M) => m + M.distance, 0), a = e.reduce((m, M) => m + M.totalHrs, 0), n = e.reduce((m, M) => m + M.wxFactor * M.totalHrs / a, 0), s = e.reduce((m, M) => m + M.cFactor * M.totalHrs / a, 0), d = e.reduce((m, M) => m + M.totalFoCons, 0), r = e.reduce((m, M) => m + M.totalDgoCons, 0), u = e.reduce((m, M) => m + M.cost.total, 0), y = e.reduce((m, M) => m + M.cost.hire, 0), h = e.reduce((m, M) => m + M.cost.bunker, 0), f = [];
1168
- for (const m of e) {
1169
- const M = m.sample.hours, g = M.at(0);
1170
- g.cp = m.cost.cp;
1171
- const I = [m.etd, m.eta], c = f.findIndex((S) => S.id === g.cp.id);
1172
- c === -1 ? (g.cp.segment = [I], f.push(g.cp)) : f[c].segment.push(I);
1173
- const w = m.sample.wps, N = m.sample.days;
1174
- M.forEach((S) => {
1175
- var F;
1176
- ((F = o.hours) == null ? void 0 : F.findIndex((T) => T.eta === S.eta)) === -1 && o.hours.push(S);
1177
- }), w.forEach((S) => {
1178
- var F;
1179
- ((F = o.wps) == null ? void 0 : F.findIndex((T) => T.eta === S.eta)) === -1 && o.wps.push(S);
1180
- }), N.forEach((S) => {
1181
- var F;
1182
- ((F = o == null ? void 0 : o.days) == null ? void 0 : F.findIndex((T) => T.eta === S.eta)) === -1 && o.days.push(S);
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);
1183
1233
  });
1184
- const v = (l = o.wps) == null ? void 0 : l.findIndex((S) => S.eta === g.eta);
1185
- v === -1 ? o.wps.push(g) : o.wps[v] = g;
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;
1186
1236
  }
1187
- return o.wps.sort((m, M) => {
1188
- p(m.etd).unix() - p(M.etd).unix();
1237
+ return n.wps.sort((h, b) => {
1238
+ w(h.etd).unix() - w(b.etd).unix();
1189
1239
  }), {
1190
- sample: o,
1240
+ sample: n,
1191
1241
  etd: e.at(0).etd,
1192
1242
  eta: e.at(-1).eta,
1193
1243
  from: e.at(0).from,
@@ -1197,30 +1247,36 @@ class C {
1197
1247
  distance: Math.round(i * 1e4) / 1e4,
1198
1248
  totalHrs: Math.round(a * 1e3) / 1e3,
1199
1249
  avgSpeed: Math.round(i / a * 1e3) / 1e3,
1200
- wxFactor: Math.round(n / a * 1e3) / 1e3,
1201
- cFactor: Math.round(s / a * 1e3) / 1e3,
1202
- totalFoCons: Math.round(d * 1e3) / 1e3,
1203
- totalDgoCons: Math.round(r * 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,
1253
+ totalDgoCons: Math.round(l * 1e3) / 1e3,
1204
1254
  cost: {
1205
- total: Math.round(u * 1e3) / 1e3,
1206
- hire: Math.round(y * 1e3) / 1e3,
1207
- bunker: Math.round(h * 1e3) / 1e3
1255
+ total: Math.round(M * 1e3) / 1e3,
1256
+ hire: Math.round(m * 1e3) / 1e3,
1257
+ bunker: Math.round(C * 1e3) / 1e3
1208
1258
  },
1209
- cps: f
1259
+ extend: {
1260
+ cps: k,
1261
+ eca: p,
1262
+ distanceInECA: Math.round(o * 1e4) / 1e4,
1263
+ hoursInECA: Math.round(s * 1e3) / 1e3,
1264
+ totalDgoConsInECA: Math.round(d * 1e3) / 1e3
1265
+ }
1210
1266
  };
1211
1267
  }
1212
1268
  }
1213
1269
  export {
1214
- U as AISImpl,
1215
- rt as AlertHelper,
1216
- it as AlertLevel,
1217
- wt as HifleetImpl,
1218
- ut as LoadCondition,
1219
- It as MyShipImpl,
1220
- vt as MyVesselImpl,
1221
- pt as ShipxyImpl,
1222
- C as SpeedHelper,
1223
- ht as SpeedLabel,
1224
- dt as VesselTag,
1225
- kt as alertHelper
1270
+ $ as AISImpl,
1271
+ ft as AlertHelper,
1272
+ lt as AlertLevel,
1273
+ St as HifleetImpl,
1274
+ Mt as LoadCondition,
1275
+ jt as MyShipImpl,
1276
+ Ct as MyVesselImpl,
1277
+ Yt as ShipxyImpl,
1278
+ q as SpeedHelper,
1279
+ gt as SpeedLabel,
1280
+ yt as VesselTag,
1281
+ Dt as alertHelper
1226
1282
  };