@idm-plugin/vessel 2.2.9 → 2.3.0

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,15 +1,15 @@
1
1
  var ht = Object.defineProperty;
2
- var lt = (x, t, e) => t in x ? ht(x, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : x[t] = e;
3
- var K = (x, t, e) => (lt(x, typeof t != "symbol" ? t + "" : t, e), e);
4
- import B from "got";
5
- import rt from "@log4js-node/log4js-api";
6
- import g from "moment";
7
- import { LngLatHelper as J, LaneHelper as W } from "@idm-plugin/geo2";
8
- import { MeteoHelper2 as ft } from "@idm-plugin/meteo2";
2
+ var lt = (E, e, t) => e in E ? ht(E, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : E[e] = t;
3
+ var U = (E, e, t) => (lt(E, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import L from "got";
5
+ import ct from "@log4js-node/log4js-api";
6
+ import w from "moment";
7
+ import { LngLatHelper as _, LaneHelper as W } from "@idm-plugin/geo2";
8
+ import { MeteoHelper2 as mt } from "@idm-plugin/meteo2";
9
9
  import { Meteo2Assist as it } from "@idm-plugin/meteo";
10
- let v;
10
+ let M;
11
11
  try {
12
- v = rt.getLogger("vessel");
12
+ M = ct.getLogger("vessel");
13
13
  } catch {
14
14
  } finally {
15
15
  }
@@ -18,85 +18,180 @@ class st {
18
18
  * 解析AIS状态码
19
19
  * @param status
20
20
  */
21
- parseStatus(t) {
22
- let e, a;
23
- switch (t) {
21
+ parseStatus(e) {
22
+ let t, a;
23
+ switch (e) {
24
24
  case 0:
25
- e = "在航(主机推动)", a = "Underway Using Engine";
25
+ t = "在航(主机推动)", a = "Underway Using Engine";
26
26
  break;
27
27
  case 1:
28
- e = "锚泊", a = "Anchored";
28
+ t = "锚泊", a = "Anchored";
29
29
  break;
30
30
  case 2:
31
- e = "失控", a = "Not under command";
31
+ t = "失控", a = "Not under command";
32
32
  break;
33
33
  case 3:
34
- e = "操纵受限", a = "Limited airworthiness";
34
+ t = "操纵受限", a = "Limited airworthiness";
35
35
  break;
36
36
  case 4:
37
- e = "吃水受限", a = "Limited by ship's draft";
37
+ t = "吃水受限", a = "Limited by ship's draft";
38
38
  break;
39
39
  case 5:
40
- e = "靠泊", a = "Mooring";
40
+ t = "靠泊", a = "Mooring";
41
41
  break;
42
42
  case 6:
43
- e = "搁浅", a = "Stranded";
43
+ t = "搁浅", a = "Stranded";
44
44
  break;
45
45
  case 7:
46
- e = "捕捞作业", a = "Engaged in fishing";
46
+ t = "捕捞作业", a = "Engaged in fishing";
47
47
  break;
48
48
  case 8:
49
- e = "靠帆船提供动力", a = "Sailing";
49
+ t = "靠帆船提供动力", a = "Sailing";
50
50
  break;
51
51
  default:
52
- e = "未定义", a = "Undefined";
52
+ t = "未定义", a = "Undefined";
53
53
  }
54
- return { labelCn: e, labelEn: a };
54
+ return { labelCn: t, labelEn: a };
55
55
  }
56
56
  }
57
- class Et extends st {
58
- constructor(e, a) {
57
+ class jt extends st {
58
+ constructor(t, a) {
59
59
  super();
60
- K(this, "clientId");
61
- K(this, "clientSecret");
62
- K(this, "token");
63
- this.clientId = e, this.clientSecret = a;
60
+ U(this, "clientId");
61
+ U(this, "clientSecret");
62
+ U(this, "token");
63
+ this.clientId = t, this.clientSecret = a;
64
64
  }
65
- async authToken(e = {}) {
65
+ async authToken(t = {}) {
66
66
  const a = "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
- }, o = await B.post(a, i).json();
73
- v == null || v.info("[%s] fetch access token from: %s - %j", e.requestId, a, o), o.error || (this.token = {
72
+ }, o = await L.post(a, i).json();
73
+ M == null || M.info("[%s] fetch access token from: %s - %j", t.requestId, a, o), o.error || (this.token = {
74
74
  accessToken: o.access_token,
75
75
  tokenType: o.token_type,
76
76
  expiresIn: o.expires_in,
77
77
  scope: o.scope,
78
78
  jti: o.jti,
79
- issuedAt: g().utc().format()
79
+ issuedAt: w().utc().format()
80
80
  });
81
81
  }
82
- async realTimePosition(e, a = {}) {
83
- var d, r, m;
84
- (!this.token || g().diff(g(this.token.issuedAt), "seconds") > ((d = this.token) == null ? void 0 : d.expiresIn) - 300) && await this.authToken(a);
82
+ async checkToken(t = {}) {
83
+ var a;
84
+ return (!this.token || w().diff(w(this.token.issuedAt), "seconds") > (((a = this.token) == null ? void 0 : a.expiresIn) || 0) - 300) && await this.authToken(t), this.token;
85
+ }
86
+ /**
87
+ * 模糊查询
88
+ * @param kw
89
+ * @param options
90
+ */
91
+ async suggest(t, a = {}) {
92
+ var s, r;
93
+ await this.checkToken(a);
94
+ const i = "https://market.myvessel.cn/sdc/v1/mkt/vessels/fuzzy", o = {
95
+ headers: {
96
+ Authorization: `${(s = this.token) == null ? void 0 : s.tokenType} ${(r = this.token) == null ? void 0 : r.accessToken}`
97
+ },
98
+ json: {
99
+ kw: t,
100
+ recordNum: a.ps || 10
101
+ }
102
+ };
103
+ M == null || M.info("[%s] fetch suggest vessels from: %s - %j", a.requestId, i, o);
104
+ const n = await L.post(i, o).json();
105
+ return n.code ? (M == null || M.warn("[%s] fetch suggest vessels failed: %j", a.requestId, { message: n.message, status: n.status, code: n.code }), []) : n.data.map((u) => ({
106
+ mmsi: u.mmsi,
107
+ name: u.nameEn,
108
+ nameCn: u.nameCn,
109
+ imo: Number.isNaN(u.imo) ? null : Number(u.imo),
110
+ callSign: u.callsign,
111
+ type: u.vesselTypeNameEn,
112
+ flagName: u.flagCtry,
113
+ vendor: "myvessel",
114
+ raw: u
115
+ }));
116
+ }
117
+ /**
118
+ * imo/mmsi 精确查询
119
+ * @param imo
120
+ * @param options
121
+ */
122
+ async search(t, a = {}) {
123
+ var c, u;
124
+ await this.checkToken(a);
125
+ const i = /^\d{7}$/.test(t.toString()), o = i ? "https://market.myvessel.cn/sdc/v1/mkt/vessels/detail/imo" : "https://market.myvessel.cn/sdc/v1/mkt/vessels/detail/mmsi", n = i ? { imo: t } : { mmsi: t }, s = {
126
+ headers: {
127
+ Authorization: `${(c = this.token) == null ? void 0 : c.tokenType} ${(u = this.token) == null ? void 0 : u.accessToken}`
128
+ },
129
+ searchParams: n
130
+ };
131
+ M == null || M.info("[%s] fetch vessel from: %s - %j", a.requestId, o, s);
132
+ const r = await L.get(o, s).json();
133
+ if (r.status !== 200)
134
+ return M == null || M.warn("[%s] fetch suggest vessels failed: %j", a.requestId, { message: r.message, status: r.status, code: r.code }), {};
135
+ {
136
+ const m = r.data;
137
+ return {
138
+ mmsi: m.mmsi,
139
+ imo: Number.isNaN(m.imo) ? null : Number(m.imo),
140
+ callSign: m.callsign,
141
+ name: m.nameEn,
142
+ nameCn: m.nameCn,
143
+ type: m.vesselTypeNameEn,
144
+ flagName: m.flagCtry,
145
+ clasz: m.classSociety,
146
+ dateOfBuild: m.buildYearMonth,
147
+ deadweight: m.dwt,
148
+ grossTonnage: m.grt,
149
+ netTonnage: m.net,
150
+ teu: m.teu,
151
+ length: m.length,
152
+ breadth: m.width,
153
+ height: m.height,
154
+ draught: m.draught,
155
+ speed: m.speed,
156
+ passengerCapacity: m.passengercapacity,
157
+ vendor: "myvessel",
158
+ raw: m
159
+ };
160
+ }
161
+ }
162
+ async archives(t, a = {}) {
163
+ var s, r;
164
+ await this.checkToken(a);
165
+ const i = "https://svc.data.myvessel.cn/sdc/v1/ship/info/batch", o = {
166
+ headers: {
167
+ Authorization: `${(s = this.token) == null ? void 0 : s.tokenType} ${(r = this.token) == null ? void 0 : r.accessToken}`
168
+ },
169
+ json: {
170
+ mmsiList: typeof t == "number" ? [t] : t
171
+ }
172
+ };
173
+ M == null || M.info("[%s] fetch vessel archive from: %s - %j", a.requestId, i, o);
174
+ const n = await L.post(i, o).json();
175
+ return n.status !== 200 ? (M == null || M.warn("[%s] fetch vessel archive failed: %j", a.requestId, { message: n.message, status: n.status, code: n.code }), {}) : n.data;
176
+ }
177
+ async realTimePosition(t, a = {}) {
178
+ var r, c;
179
+ await this.checkToken(a);
85
180
  const i = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit", o = {
86
181
  headers: {
87
- Authorization: `${(r = this.token) == null ? void 0 : r.tokenType} ${(m = this.token) == null ? void 0 : m.accessToken}`
182
+ Authorization: `${(r = this.token) == null ? void 0 : r.tokenType} ${(c = this.token) == null ? void 0 : c.accessToken}`
88
183
  },
89
- searchParams: { mmsi: e }
184
+ searchParams: { mmsi: t }
90
185
  };
91
- v == null || v.info("[%s] fetch realtime position from: %s - %j", a.requestId, i, o);
92
- const n = await B.get(i, o).json();
186
+ M == null || M.info("[%s] fetch realtime position from: %s - %j", a.requestId, i, o);
187
+ const n = await L.get(i, o).json();
93
188
  if (n.code)
94
- return v == null || v.warn("[%s] fetch realtime position failed: %j", a.requestId, i, { message: n.message, status: n.status, code: n.code }), n;
189
+ return M == null || M.warn("[%s] fetch realtime position failed: %j", a.requestId, { message: n.message, status: n.status, code: n.code }), n;
95
190
  const s = n.data;
96
- for (const M in s)
97
- !isNaN(s[M]) && Number(s[M]) !== 1 / 0 && (s[M] = Number(s[M]));
191
+ for (const u in s)
192
+ !isNaN(s[u]) && Number(s[u]) !== 1 / 0 && (s[u] = Number(s[u]));
98
193
  if (s) {
99
- const M = g(`${s.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
194
+ const u = w(`${s.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
100
195
  return {
101
196
  mmsi: s.mmsi,
102
197
  name: s.vesselName || s.aisVesselName,
@@ -111,9 +206,9 @@ class Et extends st {
111
206
  cog: s.cog,
112
207
  hdg: s.hdg,
113
208
  rot: s.rot,
114
- eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ? g.utc(s.eta).format() : void 0,
209
+ eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ? w.utc(s.eta).format() : void 0,
115
210
  destination: s.dest,
116
- positionTime: M.unix(),
211
+ positionTime: u.unix(),
117
212
  status: s.status,
118
213
  labelCn: s.statusNameCn,
119
214
  labelEn: s.statusNameEn,
@@ -126,83 +221,83 @@ class Et extends st {
126
221
  net: s.net,
127
222
  method: "position",
128
223
  vendor: "myVessel",
129
- utc: M.utc().format()
224
+ utc: u.utc().format()
130
225
  };
131
226
  } else
132
227
  return {};
133
228
  }
134
- async trajectory(e, a, i, o, n = !0, s = {}) {
135
- (!this.token || g().diff(g(this.token.issuedAt), "seconds") > this.token.expiresIn - 300) && await this.authToken(s);
136
- const d = await this.realTimePosition(e, s), r = g(a), m = g(i), M = [];
137
- for (; m.diff(r, "day", !0) > 30; )
138
- await this.trajectoryIn30Day(e, r, r.clone().add(30, "day"), d, o, M, s), r.add(30, "day");
139
- return await this.trajectoryIn30Day(e, r, m, d, o, M, s), M;
229
+ async trajectory(t, a, i, o, n = !0, s = {}) {
230
+ await this.checkToken(s);
231
+ const r = await this.realTimePosition(t, s), c = w(a), u = w(i), m = [];
232
+ for (; u.diff(c, "day", !0) > 30; )
233
+ await this.trajectoryIn30Day(t, c, c.clone().add(30, "day"), r, o, m, s), c.add(30, "day");
234
+ return await this.trajectoryIn30Day(t, c, u, r, o, m, s), m;
140
235
  }
141
- async trajectoryIn30Day(e, a, i, o, n, s, d = {}) {
142
- var f, C, S, p, w;
143
- const r = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", m = {
236
+ async trajectoryIn30Day(t, a, i, o, n, s, r = {}) {
237
+ var y, F, I, p, v;
238
+ const c = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", u = {
144
239
  headers: {
145
- Authorization: `${(f = this.token) == null ? void 0 : f.tokenType} ${(C = this.token) == null ? void 0 : C.accessToken}`
240
+ Authorization: `${(y = this.token) == null ? void 0 : y.tokenType} ${(F = this.token) == null ? void 0 : F.accessToken}`
146
241
  },
147
242
  json: {
148
- mmsi: e,
243
+ mmsi: t,
149
244
  startTime: a.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),
150
245
  endTime: i.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")
151
246
  }
152
247
  };
153
- v == null || v.info("[%s] fetch trajectory from: %s - %j", d.requestId, r, m);
154
- const M = await B.post(r, m).json();
155
- if (M.code)
156
- return v == null || v.warn("[%s] fetch trajectory failed: %j", d.requestId, r, { message: M.message, status: M.status, code: M.code }), M;
157
- let l = -1;
158
- const b = g(`${(p = (S = M.data) == null ? void 0 : S[0]) == null ? void 0 : p.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
159
- return (w = M.data) == null || w.forEach((c) => {
160
- for (const Y in c)
161
- !isNaN(c[Y]) && Number(c[Y]) !== 1 / 0 && (c[Y] = Number(c[Y]));
162
- const y = g(`${c.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), h = c.status, { labelCn: u, labelEn: I } = this.parseStatus(h), k = {
163
- mmsi: c.mmsi,
248
+ M == null || M.info("[%s] fetch trajectory from: %s - %j", r.requestId, c, u);
249
+ const m = await L.post(c, u).json();
250
+ if (m.code)
251
+ return M == null || M.warn("[%s] fetch trajectory failed: %j", r.requestId, c, { message: m.message, status: m.status, code: m.code }), m;
252
+ let f = -1;
253
+ const b = w(`${(p = (I = m.data) == null ? void 0 : I[0]) == null ? void 0 : p.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
254
+ return (v = m.data) == null || v.forEach((d) => {
255
+ for (const P in d)
256
+ !isNaN(d[P]) && Number(d[P]) !== 1 / 0 && (d[P] = Number(d[P]));
257
+ const g = w(`${d.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), l = d.status, { labelCn: h, labelEn: k } = this.parseStatus(l), S = {
258
+ mmsi: d.mmsi,
164
259
  imo: o == null ? void 0 : o.imo,
165
- lat: c.lat,
166
- lng: c.lon,
167
- sog: c.sog,
168
- cog: c.cog,
169
- hdg: c.hdg,
170
- draught: c.draught,
171
- status: h,
172
- eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(c.eta) ? g(`${c.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00").utc().format() : void 0,
173
- destination: c.dest,
174
- positionTime: y.unix(),
175
- labelCn: u,
176
- labelEn: I,
260
+ lat: d.lat,
261
+ lng: d.lon,
262
+ sog: d.sog,
263
+ cog: d.cog,
264
+ hdg: d.hdg,
265
+ draught: d.draught,
266
+ status: l,
267
+ eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(d.eta) ? w(`${d.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00").utc().format() : void 0,
268
+ destination: d.dest,
269
+ positionTime: g.unix(),
270
+ labelCn: h,
271
+ labelEn: k,
177
272
  method: "trajectory",
178
273
  vendor: "myVessel",
179
- utc: y.utc().format()
180
- }, D = Math.floor(y.diff(b, "minute", !0) / (n || 1));
181
- D !== l && (l = D, s.push(k));
274
+ utc: g.utc().format()
275
+ }, D = Math.floor(g.diff(b, "minute", !0) / (n || 1));
276
+ D !== f && (f = D, s.push(S));
182
277
  }), s;
183
278
  }
184
279
  }
185
- class xt extends st {
186
- constructor(e) {
280
+ class Et extends st {
281
+ constructor(t) {
187
282
  super();
188
- K(this, "token");
189
- this.token = e;
283
+ U(this, "token");
284
+ this.token = t;
190
285
  }
191
- async realTimePosition(e, a = {}) {
286
+ async realTimePosition(t, a = {}) {
192
287
  const i = "https://api.hifleet.com/position/position/get/token", o = {
193
288
  searchParams: {
194
- mmsi: e,
289
+ mmsi: t,
195
290
  usertoken: this.token
196
291
  }
197
- }, n = await B.post(i, o).json();
198
- v == null || v.info("[%s] fetch realtime position from: %s - %j", a.requestId, i, o);
292
+ }, n = await L.post(i, o).json();
293
+ M == null || M.info("[%s] fetch realtime position from: %s - %j", a.requestId, i, o);
199
294
  const s = n == null ? void 0 : n.list;
200
295
  if (!s)
201
- return v == null || v.warn("[%s] fetch realtime position failed: %j", a.requestId, i, n), n;
296
+ return M == null || M.warn("[%s] fetch realtime position failed: %j", a.requestId, i, n), n;
202
297
  for (const b in s)
203
298
  !isNaN(s[b]) && Number(s[b]) !== 1 / 0 && (s[b] = Number(s[b]));
204
299
  s.status = s.sp > 3 ? 0 : 1;
205
- const d = s.status, { labelCn: r, labelEn: m } = this.parseStatus(d), M = g(`${s.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
300
+ const r = s.status, { labelCn: c, labelEn: u } = this.parseStatus(r), m = w(`${s.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
206
301
  return {
207
302
  mmsi: s.m,
208
303
  name: s.n,
@@ -217,26 +312,26 @@ class xt extends st {
217
312
  cog: s.co,
218
313
  hdg: s.h,
219
314
  rot: isNaN(s.rot) ? 0 : s.rot,
220
- eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ? g.utc(s.eta).format() : void 0,
315
+ eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(s.eta) ? w.utc(s.eta).format() : void 0,
221
316
  destination: s.destination,
222
317
  vesselType: s.type,
223
318
  dwt: s.dwt,
224
319
  build: s.buildyear,
225
320
  flag: s.fn,
226
- positionTime: M.unix(),
227
- utc: M.utc().format(),
228
- status: d,
229
- labelCn: r,
230
- labelEn: m,
321
+ positionTime: m.unix(),
322
+ utc: m.utc().format(),
323
+ status: r,
324
+ labelCn: c,
325
+ labelEn: u,
231
326
  method: "position",
232
327
  vendor: "hifleet"
233
328
  };
234
329
  }
235
- async search(e, a = {}) {
330
+ async search(t, a = {}) {
236
331
  let i = "https://www.hifleet.com/hifleetapi/searchVesselOL.do";
237
332
  const o = {
238
333
  searchParams: {
239
- keyword: e
334
+ keyword: t
240
335
  },
241
336
  headers: {
242
337
  Referer: "https://www.hifleet.com",
@@ -244,10 +339,10 @@ class xt extends st {
244
339
  Host: "www.hifleet.com"
245
340
  }
246
341
  };
247
- let n = await B.post(i, o).json();
248
- v == null || v.info("[%s] fetch vessel props from: %s - %j", a.requestId, i, o), n instanceof Array && (n = n[0]);
249
- for (const d in n)
250
- !isNaN(n[d]) && Number(n[d]) !== 1 / 0 && (n[d] = Number(n[d]));
342
+ let n = await L.post(i, o).json();
343
+ M == null || M.info("[%s] fetch vessel props from: %s - %j", a.requestId, i, o), n instanceof Array && (n = n[0]);
344
+ for (const r in n)
345
+ !isNaN(n[r]) && Number(n[r]) !== 1 / 0 && (n[r] = Number(n[r]));
251
346
  const s = {
252
347
  mmsi: n.m,
253
348
  name: n.n,
@@ -258,102 +353,102 @@ class xt extends st {
258
353
  draught: n.dr,
259
354
  type: n.t
260
355
  };
261
- return i = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", n = await B.post(i, o).json(), v == null || v.info("[%s] search vessel dead weight from: %s - %j", a.requestId, i, o), n instanceof Array && (n = n[0]), n && (s.deadweight = Number(n.dwt)), s;
356
+ return i = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", n = await L.post(i, o).json(), M == null || M.info("[%s] search vessel dead weight from: %s - %j", a.requestId, i, o), n instanceof Array && (n = n[0]), n && (s.deadweight = Number(n.dwt)), s;
262
357
  }
263
- async suggest(e, a = {}) {
358
+ async suggest(t, a = {}) {
264
359
  const i = "https://www.hifleet.com/hifleetapi/getShipSuggest.do", o = {
265
360
  searchParams: {
266
- q: e
361
+ q: t
267
362
  },
268
363
  headers: {
269
364
  Referer: "https://www.hifleet.com",
270
365
  Origin: "https://www.hifleet.com",
271
366
  Host: "www.hifleet.com"
272
367
  }
273
- }, n = await B.post(i, o).json();
274
- v == null || v.info("[%s] suggest vessel props from: %s - %j", a.requestId, i, o);
368
+ }, n = await L.post(i, o).json();
369
+ M == null || M.info("[%s] suggest vessel props from: %s - %j", a.requestId, i, o);
275
370
  const s = [];
276
- for (const d of n)
371
+ for (const r of n)
277
372
  s.push({
278
- mmsi: !d.mmsi || isNaN(d.mmsi) ? null : Number(d.mmsi),
279
- name: d.name,
280
- callSign: d.callsign,
281
- imo: !d.imo || isNaN(d.imo) ? null : Number(d.imo),
282
- score: d._score
373
+ mmsi: !r.mmsi || isNaN(r.mmsi) ? null : Number(r.mmsi),
374
+ name: r.name,
375
+ callSign: r.callsign,
376
+ imo: !r.imo || isNaN(r.imo) ? null : Number(r.imo),
377
+ score: r._score
283
378
  });
284
- return s.sort((d, r) => r.score - d.score), s;
379
+ return s.sort((r, c) => c.score - r.score), s;
285
380
  }
286
- async trajectory(e, a, i, o, n = !0, s = {}) {
287
- var c, y, h;
288
- const d = await this.realTimePosition(e, s);
289
- let r = g(a);
290
- const m = g(i), M = g();
381
+ async trajectory(t, a, i, o, n = !0, s = {}) {
382
+ var d, g, l;
383
+ const r = await this.realTimePosition(t, s);
384
+ let c = w(a);
385
+ const u = w(i), m = w();
291
386
  if (n) {
292
- let u = m.diff(r, "d", !0);
293
- u < 0 ? r = m.clone().subtract(40, "d") : u < 30 ? r.subtract(10, "d") : u < 60 ? r.subtract(5, "d") : r = m.clone().subtract(80, "d"), u = M.diff(m, "d", !0), m.add(u > 10 ? 240 : u * 24, "h");
387
+ let h = u.diff(c, "d", !0);
388
+ h < 0 ? c = u.clone().subtract(40, "d") : h < 30 ? c.subtract(10, "d") : h < 60 ? c.subtract(5, "d") : c = u.clone().subtract(80, "d"), h = m.diff(u, "d", !0), u.add(h > 10 ? 240 : h * 24, "h");
294
389
  }
295
- const l = {
390
+ const f = {
296
391
  searchParams: {
297
- endtime: m.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
298
- starttime: r.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
299
- mmsi: e,
392
+ endtime: u.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
393
+ starttime: c.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
394
+ mmsi: t,
300
395
  usertoken: this.token
301
396
  }
302
- }, b = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", f = await B.get(b, l).json();
303
- v == null || v.info("[%s] fetch trajectory from: %s - %j", s.requestId, b, l);
304
- let C;
305
- f && (C = ((y = (c = f.ships) == null ? void 0 : c.offors) == null ? void 0 : y.ship) || [], C.length || v == null || v.warn("[%s] fetch trajectory failed: %j", s.requestId, f));
306
- const S = [];
397
+ }, b = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", y = await L.get(b, f).json();
398
+ M == null || M.info("[%s] fetch trajectory from: %s - %j", s.requestId, b, f);
399
+ let F;
400
+ y && (F = ((g = (d = y.ships) == null ? void 0 : d.offors) == null ? void 0 : g.ship) || [], F.length || M == null || M.warn("[%s] fetch trajectory failed: %j", s.requestId, y));
401
+ const I = [];
307
402
  let p = -1;
308
- const w = g(`${(h = C == null ? void 0 : C[0]) == null ? void 0 : h.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
309
- for (const u of C) {
310
- for (const A in u)
311
- !isNaN(u[A]) && Number(u[A]) !== 1 / 0 && (u[A] = Number(u[A]));
312
- const I = g(`${u.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
313
- u.status = u.sp > 4 ? 0 : 1;
314
- const { labelEn: k, labelCn: D } = this.parseStatus(u.status), Y = {
315
- mmsi: u.m,
316
- name: u.n,
317
- imo: d == null ? void 0 : d.imo,
318
- lat: u.la,
319
- lng: u.lo,
320
- draught: u.draught,
321
- sog: u.sp,
322
- cog: u.co,
323
- hdg: u.hdg,
324
- positionTime: I.unix(),
325
- utc: I.utc().format(),
326
- status: u.status,
403
+ const v = w(`${(l = F == null ? void 0 : F[0]) == null ? void 0 : l.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
404
+ for (const h of F) {
405
+ for (const A in h)
406
+ !isNaN(h[A]) && Number(h[A]) !== 1 / 0 && (h[A] = Number(h[A]));
407
+ const k = w(`${h.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
408
+ h.status = h.sp > 4 ? 0 : 1;
409
+ const { labelEn: S, labelCn: D } = this.parseStatus(h.status), P = {
410
+ mmsi: h.m,
411
+ name: h.n,
412
+ imo: r == null ? void 0 : r.imo,
413
+ lat: h.la,
414
+ lng: h.lo,
415
+ draught: h.draught,
416
+ sog: h.sp,
417
+ cog: h.co,
418
+ hdg: h.hdg,
419
+ positionTime: k.unix(),
420
+ utc: k.utc().format(),
421
+ status: h.status,
327
422
  labelCn: D,
328
- labelEn: k,
423
+ labelEn: S,
329
424
  method: "trajectory",
330
425
  vendor: "hifleet"
331
- }, j = Math.floor(I.diff(w, "minute", !0) / (o || 1));
332
- j !== p && (p = j, S.push(Y));
426
+ }, N = Math.floor(k.diff(v, "minute", !0) / (o || 1));
427
+ N !== p && (p = N, I.push(P));
333
428
  }
334
- return S;
429
+ return I;
335
430
  }
336
431
  }
337
- class jt extends st {
338
- constructor(e) {
432
+ class Nt extends st {
433
+ constructor(t) {
339
434
  super();
340
- K(this, "token");
341
- this.token = e;
435
+ U(this, "token");
436
+ this.token = t;
342
437
  }
343
- async realTimePosition(e, a = {}) {
438
+ async realTimePosition(t, a = {}) {
344
439
  const i = {
345
440
  searchParams: {
346
- id: e,
441
+ id: t,
347
442
  k: this.token,
348
443
  enc: 1
349
444
  }
350
- }, o = "https://api.shipxy.com/apicall/GetSingleShip", n = await B.get(o, i).json();
351
- if (v == null || v.info("[%s] fetch realtime position from: %s - %j", a.requestId, o, i), (n == null ? void 0 : n.status) !== 0)
445
+ }, o = "https://api.shipxy.com/apicall/GetSingleShip", n = await L.get(o, i).json();
446
+ if (M == null || M.info("[%s] fetch realtime position from: %s - %j", a.requestId, o, i), (n == null ? void 0 : n.status) !== 0)
352
447
  return n;
353
448
  const s = n.data[0];
354
- for (const l in s)
355
- !isNaN(s[l]) && Number(s[l]) !== 1 / 0 && (s[l] = Number(s[l]));
356
- const { labelCn: d, labelEn: r } = await this.parseStatus(s.navistat), m = g.unix(s.lasttime);
449
+ for (const f in s)
450
+ !isNaN(s[f]) && Number(s[f]) !== 1 / 0 && (s[f] = Number(s[f]));
451
+ const { labelCn: r, labelEn: c } = await this.parseStatus(s.navistat), u = w.unix(s.lasttime);
357
452
  return {
358
453
  mmsi: s.ShipID,
359
454
  name: s.name,
@@ -369,147 +464,147 @@ class jt extends st {
369
464
  hdg: Math.round(s.hdg / 100 * 100) / 100,
370
465
  rot: Math.round(s.rot / 100 * 100) / 100,
371
466
  positionTime: s.lasttime,
372
- utc: m.utc().format(),
467
+ utc: u.utc().format(),
373
468
  status: s.navistat,
374
- labelEn: r,
375
- labelCn: d,
469
+ labelEn: c,
470
+ labelCn: r,
376
471
  method: "position",
377
472
  vendor: "shipxy"
378
473
  };
379
474
  }
380
- async trajectory(e, a, i, o, n = !0, s = {}) {
381
- var w;
382
- const d = await this.realTimePosition(e, s), r = g(a), m = g(i), M = "https://api.shipxy.com/apicall/GetShipTrack", l = {
475
+ async trajectory(t, a, i, o, n = !0, s = {}) {
476
+ var v;
477
+ const r = await this.realTimePosition(t, s), c = w(a), u = w(i), m = "https://api.shipxy.com/apicall/GetShipTrack", f = {
383
478
  searchParams: {
384
- id: e,
479
+ id: t,
385
480
  k: this.token,
386
481
  enc: 1,
387
482
  cut: 0,
388
- btm: r.unix(),
389
- etm: m.unix()
483
+ btm: c.unix(),
484
+ etm: u.unix()
390
485
  }
391
- }, b = await B.get(M, l).json();
392
- if (v == null || v.info("[%s] fetch trajectory from: %s - %j", s.requestId, M, l), (b == null ? void 0 : b.status) !== 0)
486
+ }, b = await L.get(m, f).json();
487
+ if (M == null || M.info("[%s] fetch trajectory from: %s - %j", s.requestId, m, f), (b == null ? void 0 : b.status) !== 0)
393
488
  return b;
394
- const f = b == null ? void 0 : b.points, C = [], S = g.unix((w = f[0]) == null ? void 0 : w.utc);
489
+ const y = b == null ? void 0 : b.points, F = [], I = w.unix((v = y[0]) == null ? void 0 : v.utc);
395
490
  let p = -1;
396
- for (const c of f) {
397
- const y = g.unix(c.utc), h = {
398
- imo: d == null ? void 0 : d.imo,
399
- mmsi: e,
400
- sog: Math.round(c.sog * 3600 / 1e3 / 1852 * 100) / 100,
401
- cog: Math.round(c.cog / 100 * 100) / 100,
402
- lat: Math.round(c.lat / 1e6 * 1e5) / 1e5,
403
- lng: Math.round(c.lon / 1e6 * 1e5) / 1e5,
404
- positionTime: y.unix(),
405
- utc: y.utc().format(),
491
+ for (const d of y) {
492
+ const g = w.unix(d.utc), l = {
493
+ imo: r == null ? void 0 : r.imo,
494
+ mmsi: t,
495
+ sog: Math.round(d.sog * 3600 / 1e3 / 1852 * 100) / 100,
496
+ cog: Math.round(d.cog / 100 * 100) / 100,
497
+ lat: Math.round(d.lat / 1e6 * 1e5) / 1e5,
498
+ lng: Math.round(d.lon / 1e6 * 1e5) / 1e5,
499
+ positionTime: g.unix(),
500
+ utc: g.utc().format(),
406
501
  method: "trajectory",
407
502
  vendor: "shipxy"
408
- }, u = Math.floor(y.diff(S, "minute", !0) / (o || 1));
409
- u !== p && (p = u, C.push(h));
503
+ }, h = Math.floor(g.diff(I, "minute", !0) / (o || 1));
504
+ h !== p && (p = h, F.push(l));
410
505
  }
411
- return C;
506
+ return F;
412
507
  }
413
508
  }
414
- class Nt extends st {
415
- constructor(e) {
509
+ class Tt extends st {
510
+ constructor(t) {
416
511
  super();
417
- K(this, "token");
418
- this.token = e;
512
+ U(this, "token");
513
+ this.token = t;
419
514
  }
420
- async getShipId(e, a = {}) {
515
+ async getShipId(t, a = {}) {
421
516
  const i = {
422
517
  headers: {
423
518
  appKey: this.token
424
519
  },
425
520
  json: {
426
- mmsiList: e
521
+ mmsiList: t
427
522
  }
428
- }, o = "https://api3.myships.com/sp/ships/getShipIdByMMSI", n = await B.post(o, i).json();
429
- return v == null || v.info("[%s] fetch ship id from: %s - %j", a.requestId, o, i), n.code !== "0" ? n : n.data[0].shipId;
523
+ }, o = "https://api3.myships.com/sp/ships/getShipIdByMMSI", n = await L.post(o, i).json();
524
+ return M == null || M.info("[%s] fetch ship id from: %s - %j", a.requestId, o, i), n.code !== "0" ? n : n.data[0].shipId;
430
525
  }
431
- async getShipInfo(e, a = {}) {
526
+ async getShipInfo(t, a = {}) {
432
527
  const i = {
433
528
  headers: {
434
529
  appKey: this.token
435
530
  },
436
531
  json: {
437
- shipId: e
532
+ shipId: t
438
533
  }
439
- }, o = "https://api3.myships.com/sp/ships/aissta", n = await B.post(o, i).json();
440
- if (v == null || v.info("[%s] fetch ship info from: %s - %j", a.requestId, o, i), n.code !== "0")
534
+ }, o = "https://api3.myships.com/sp/ships/aissta", n = await L.post(o, i).json();
535
+ if (M == null || M.info("[%s] fetch ship info from: %s - %j", a.requestId, o, i), n.code !== "0")
441
536
  return n;
442
537
  const s = n.data;
443
- let d = s.imo;
444
- return e === "407170" && (d = "9198379", v == null || v.warn("[%s] ship(%s) imo error: %s, should be %s", a.requestId, e, s.imo, d)), {
538
+ let r = s.imo;
539
+ return t === "407170" && (r = "9198379", M == null || M.warn("[%s] ship(%s) imo error: %s, should be %s", a.requestId, t, s.imo, r)), {
445
540
  mmsi: s.mmsi,
446
541
  name: s.shipnameEn,
447
- imo: d,
542
+ imo: r,
448
543
  callSign: s.callSign,
449
544
  length: s.length,
450
545
  width: s.breadth,
451
546
  draught: (s.draught || 100) / 10
452
547
  };
453
548
  }
454
- async realTimePosition(e, a = {}) {
455
- const i = await this.getShipId(e, a), o = await this.getShipInfo(i, a), n = {
549
+ async realTimePosition(t, a = {}) {
550
+ const i = await this.getShipId(t, a), o = await this.getShipInfo(i, a), n = {
456
551
  headers: {
457
552
  appKey: this.token
458
553
  },
459
554
  json: {
460
555
  shipId: i
461
556
  }
462
- }, s = "https://api3.myships.com/sp/ships/position/latest", d = await B.post(s, n).json();
463
- v == null || v.info("[%s] fetch realtime position from: %s - %j", a.requestId, s, n);
464
- const r = d.data[0];
465
- for (const f in r)
466
- !isNaN(r[f]) && Number(r[f]) !== 1 / 0 && (r[f] = Number(r[f]));
467
- const { labelCn: m, labelEn: M } = await this.parseStatus(r.aisNavStatus), l = g.unix(r.posTime);
557
+ }, s = "https://api3.myships.com/sp/ships/position/latest", r = await L.post(s, n).json();
558
+ M == null || M.info("[%s] fetch realtime position from: %s - %j", a.requestId, s, n);
559
+ const c = r.data[0];
560
+ for (const y in c)
561
+ !isNaN(c[y]) && Number(c[y]) !== 1 / 0 && (c[y] = Number(c[y]));
562
+ const { labelCn: u, labelEn: m } = await this.parseStatus(c.aisNavStatus), f = w.unix(c.posTime);
468
563
  return {
469
564
  ...o,
470
- mmsi: e,
471
- lat: Math.round(r.lat / 1e4 / 60 * 1e5) / 1e5,
472
- lng: Math.round(r.lon / 1e4 / 60 * 1e5) / 1e5,
473
- sog: Math.round(r.sog / 10 * 100) / 100,
474
- cog: Math.round(r.cog / 10 * 100) / 100,
475
- hdg: Math.round(r.heading * 100) / 100,
476
- rot: Math.round(r.rot * 100) / 100,
477
- positionTime: r.posTime,
478
- utc: l.utc().format(),
479
- status: r.aisNavStatus,
480
- labelEn: M,
481
- labelCn: m,
565
+ mmsi: t,
566
+ lat: Math.round(c.lat / 1e4 / 60 * 1e5) / 1e5,
567
+ lng: Math.round(c.lon / 1e4 / 60 * 1e5) / 1e5,
568
+ sog: Math.round(c.sog / 10 * 100) / 100,
569
+ cog: Math.round(c.cog / 10 * 100) / 100,
570
+ hdg: Math.round(c.heading * 100) / 100,
571
+ rot: Math.round(c.rot * 100) / 100,
572
+ positionTime: c.posTime,
573
+ utc: f.utc().format(),
574
+ status: c.aisNavStatus,
575
+ labelEn: m,
576
+ labelCn: u,
482
577
  method: "position",
483
578
  vendor: "myship"
484
579
  };
485
580
  }
486
- async trajectory(e, a, i, o, n = !0, s = {}) {
487
- const d = g(a), r = g(i), m = await this.getShipId(e), M = await this.getShipInfo(m), l = [];
488
- for (; r.diff(d, "day", !0) > 30; )
489
- await this.trajectoryIn30Day(m, d.unix(), d.add(30, "day").unix(), M, e, o, l);
490
- return await this.trajectoryIn30Day(m, d.unix(), r.unix(), M, e, o, l), l;
581
+ async trajectory(t, a, i, o, n = !0, s = {}) {
582
+ const r = w(a), c = w(i), u = await this.getShipId(t), m = await this.getShipInfo(u), f = [];
583
+ for (; c.diff(r, "day", !0) > 30; )
584
+ await this.trajectoryIn30Day(u, r.unix(), r.add(30, "day").unix(), m, t, o, f);
585
+ return await this.trajectoryIn30Day(u, r.unix(), c.unix(), m, t, o, f), f;
491
586
  }
492
- async trajectoryIn30Day(e, a, i, o, n, s, d, r = {}) {
493
- var S;
494
- const m = {
587
+ async trajectoryIn30Day(t, a, i, o, n, s, r, c = {}) {
588
+ var I;
589
+ const u = {
495
590
  headers: {
496
591
  appKey: this.token
497
592
  },
498
593
  json: {
499
- shipId: e,
594
+ shipId: t,
500
595
  startTime: a,
501
596
  endTime: i
502
597
  }
503
- }, M = "https://api3.myships.com/sp/ships/position/history", l = await B.post(M, m).json();
504
- if (v == null || v.info("[%s] fetch trajectory from: %s - %j", r.requestId, M, m), l.code !== "0")
505
- return v == null || v.warn("[%s] invoke myship trajectory failed: %j", r.requestId, l), l;
506
- const b = l.data;
598
+ }, m = "https://api3.myships.com/sp/ships/position/history", f = await L.post(m, u).json();
599
+ if (M == null || M.info("[%s] fetch trajectory from: %s - %j", c.requestId, m, u), f.code !== "0")
600
+ return M == null || M.warn("[%s] invoke myship trajectory failed: %j", c.requestId, f), f;
601
+ const b = f.data;
507
602
  for (const p in b)
508
603
  !isNaN(b[p]) && Number(b[p]) !== 1 / 0 && (b[p] = Number(b[p]));
509
- const f = g.unix((S = b[0]) == null ? void 0 : S.posTime);
510
- let C = -1;
604
+ const y = w.unix((I = b[0]) == null ? void 0 : I.posTime);
605
+ let F = -1;
511
606
  for (const p of b) {
512
- const w = g.unix(p.posTime), c = {
607
+ const v = w.unix(p.posTime), d = {
513
608
  imo: o == null ? void 0 : o.imo,
514
609
  mmsi: n,
515
610
  lat: Math.round(p.lat / 1e4 / 60 * 1e5) / 1e5,
@@ -518,23 +613,23 @@ class Nt extends st {
518
613
  cog: Math.round(p.cog / 10 * 100) / 100,
519
614
  hdg: Math.round(p.heading * 100) / 100,
520
615
  rot: Math.round(p.rot * 100) / 100,
521
- positionTime: w.unix(),
522
- utc: w.utc().format(),
616
+ positionTime: v.unix(),
617
+ utc: v.utc().format(),
523
618
  method: "trajectory",
524
619
  vendor: "myship"
525
- }, y = Math.floor(w.diff(f, "minute", !0) / (s || 1));
526
- y !== C && (C = y, d.push(c));
620
+ }, g = Math.floor(v.diff(y, "minute", !0) / (s || 1));
621
+ g !== F && (F = g, r.push(d));
527
622
  }
528
- return d;
623
+ return r;
529
624
  }
530
625
  }
531
- let _;
626
+ let z;
532
627
  try {
533
- _ = rt.getLogger("vessel");
628
+ z = ct.getLogger("vessel");
534
629
  } catch {
535
630
  } finally {
536
631
  }
537
- var mt = /* @__PURE__ */ ((x) => (x.NOTICE = "NOTICE", x.WARN = "WARN", x.HEAVY = "HEAVY", x.SEVERE = "SEVERE", x.ERROR = "ERROR", x.FATAL = "FATAL", x))(mt || {});
632
+ var ft = /* @__PURE__ */ ((E) => (E.NOTICE = "NOTICE", E.WARN = "WARN", E.HEAVY = "HEAVY", E.SEVERE = "SEVERE", E.ERROR = "ERROR", E.FATAL = "FATAL", E))(ft || {});
538
633
  class yt {
539
634
  /**
540
635
  * 解析告警规则, 多规则场景
@@ -544,21 +639,21 @@ class yt {
544
639
  *
545
640
  * @param options
546
641
  */
547
- parsePrinciple(t, e = {}) {
548
- var s, d, r;
549
- _ == null || _.debug("[%s] parse rule: %s", e.requestId, t);
550
- const a = new RegExp("(?<=\\[)(.+)(?=])", "g"), i = t.match(a) ? (s = t.match(a)) == null ? void 0 : s[0] : void 0, o = i == null ? void 0 : i.split(";");
642
+ parsePrinciple(e, t = {}) {
643
+ var s, r, c;
644
+ z == null || z.debug("[%s] parse rule: %s", t.requestId, e);
645
+ const a = new RegExp("(?<=\\[)(.+)(?=])", "g"), i = e.match(a) ? (s = e.match(a)) == null ? void 0 : s[0] : void 0, o = i == null ? void 0 : i.split(";");
551
646
  if (!o)
552
647
  return;
553
648
  const n = {};
554
- for (let m = 0; m < (o == null ? void 0 : o.length); m++) {
555
- const M = (r = (d = o[m].match(a)) == null ? void 0 : d[0]) == null ? void 0 : r.split("],");
556
- if (m === 0 && !M)
649
+ for (let u = 0; u < (o == null ? void 0 : o.length); u++) {
650
+ const m = (c = (r = o[u].match(a)) == null ? void 0 : r[0]) == null ? void 0 : c.split("],");
651
+ if (u === 0 && !m)
557
652
  n.scope = o[0];
558
- else if (M)
559
- for (let l = 0, b = M.length; l < b; l++) {
560
- const f = this.parseRule(M[l]);
561
- f && (n[f.level] ? f.key ? n[f.level][f == null ? void 0 : f.key] = f : n[f.level] = f : f.key ? n[f.level] = { [f == null ? void 0 : f.key]: f } : n[f.level] = f);
653
+ else if (m)
654
+ for (let f = 0, b = m.length; f < b; f++) {
655
+ const y = this.parseRule(m[f]);
656
+ y && (n[y.level] ? y.key ? n[y.level][y == null ? void 0 : y.key] = y : n[y.level] = y : y.key ? n[y.level] = { [y == null ? void 0 : y.key]: y } : n[y.level] = y);
562
657
  }
563
658
  }
564
659
  return n;
@@ -569,10 +664,10 @@ class yt {
569
664
  * @param rule
570
665
  * @param options
571
666
  */
572
- parseRule(t, e = {}) {
667
+ parseRule(e, t = {}) {
573
668
  var n;
574
- _ == null || _.debug("[%s] parse rule: %s", e.requestId, t), t = t.startsWith("[") ? t : `[${t}`, t = t.endsWith("]") ? t : `${t}]`;
575
- const a = new RegExp("(?<=\\[)(.+?)(?=])", "g"), i = (n = t == null ? void 0 : t.match(a)) == null ? void 0 : n[0], o = i == null ? void 0 : i.split(",");
669
+ z == null || z.debug("[%s] parse rule: %s", t.requestId, e), e = e.startsWith("[") ? e : `[${e}`, e = e.endsWith("]") ? e : `${e}]`;
670
+ const a = new RegExp("(?<=\\[)(.+?)(?=])", "g"), i = (n = e == null ? void 0 : e.match(a)) == null ? void 0 : n[0], o = i == null ? void 0 : i.split(",");
576
671
  if (o) {
577
672
  let s = o[3] === "Number.MAX_VALUE" ? 100 : Number(o[3]);
578
673
  return s = isNaN(s) ? 1 : s, {
@@ -590,26 +685,26 @@ class yt {
590
685
  * @param principle 告警规则
591
686
  * @param options
592
687
  */
593
- checkWeather(t, e, a = {}) {
594
- var f, C, S, p, w, c, y, h, u, I, k, D, Y, j, A;
688
+ checkWeather(e, t, a = {}) {
689
+ var y, F, I, p, v, d, g, l, h, k, S, D, P, N, A;
595
690
  let i = 0, o = 0, n = 0, s = 0;
596
- const d = Math.round(((C = (f = e == null ? void 0 : e.SEVERE) == null ? void 0 : f.sigWave) == null ? void 0 : C.number) * 1.6 * 100) / 100, r = (p = (S = e == null ? void 0 : e.SEVERE) == null ? void 0 : S.sigWave) == null ? void 0 : p.number, m = (c = (w = e == null ? void 0 : e.HEAVY) == null ? void 0 : w.sigWave) == null ? void 0 : c.number, M = Math.round((((h = (y = e == null ? void 0 : e.SEVERE) == null ? void 0 : y.wind) == null ? void 0 : h.number) + 2) * 100) / 100, l = (I = (u = e == null ? void 0 : e.SEVERE) == null ? void 0 : u.wind) == null ? void 0 : I.number, b = (D = (k = e == null ? void 0 : e.HEAVY) == null ? void 0 : k.wind) == null ? void 0 : D.number;
597
- for (let T = 0; T < (t == null ? void 0 : t.length); T++) {
598
- const N = t[T], P = (j = (Y = N == null ? void 0 : N.meteo) == null ? void 0 : Y.wave) == null ? void 0 : j.sig, R = (A = N == null ? void 0 : N.meteo) == null ? void 0 : A.wind, U = T ? g(N.eta).diff(g(t[T - 1].eta), "hour", !0) : 0;
599
- s = U > s ? U : s, _ == null || _.debug("[%s] check sig.wave: %j", a.requestId, { ...P, dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: m }), (P == null ? void 0 : P.height) >= d ? N.isDangerous = !0 : (P == null ? void 0 : P.height) >= r ? N.isSevere = !0 : (P == null ? void 0 : P.height) >= m && (N.isHeavy = !0), _ == null || _.debug("[%s] check wind: %j", a.requestId, { ...R, dgThd4Wd: M, svThd4Wd: l, hvThd4Wd: b }), (R == null ? void 0 : R.scale) >= M ? (N.isDangerous = !0, delete N.isSevere, delete N.isHeavy) : (R == null ? void 0 : R.scale) > l ? (N.isDangerous || (N.isSevere = !0), delete N.isHeavy) : (R == null ? void 0 : R.scale) === b && !N.isDangerous && !N.isSevere && (N.isHeavy = !0), i += N.isDangerous ? U : 0, o += N.isSevere ? U : 0, n += N.isHeavy ? U : 0;
691
+ const r = Math.round(((F = (y = t == null ? void 0 : t.SEVERE) == null ? void 0 : y.sigWave) == null ? void 0 : F.number) * 1.6 * 100) / 100, c = (p = (I = t == null ? void 0 : t.SEVERE) == null ? void 0 : I.sigWave) == null ? void 0 : p.number, u = (d = (v = t == null ? void 0 : t.HEAVY) == null ? void 0 : v.sigWave) == null ? void 0 : d.number, m = Math.round((((l = (g = t == null ? void 0 : t.SEVERE) == null ? void 0 : g.wind) == null ? void 0 : l.number) + 2) * 100) / 100, f = (k = (h = t == null ? void 0 : t.SEVERE) == null ? void 0 : h.wind) == null ? void 0 : k.number, b = (D = (S = t == null ? void 0 : t.HEAVY) == null ? void 0 : S.wind) == null ? void 0 : D.number;
692
+ for (let x = 0; x < (e == null ? void 0 : e.length); x++) {
693
+ const T = e[x], q = (N = (P = T == null ? void 0 : T.meteo) == null ? void 0 : P.wave) == null ? void 0 : N.sig, R = (A = T == null ? void 0 : T.meteo) == null ? void 0 : A.wind, J = x ? w(T.eta).diff(w(e[x - 1].eta), "hour", !0) : 0;
694
+ s = J > s ? J : s, z == null || z.debug("[%s] check sig.wave: %j", a.requestId, { ...q, dgThd4Wv: r, svThd4Wv: c, hvThd4Wv: u }), (q == null ? void 0 : q.height) >= r ? T.isDangerous = !0 : (q == null ? void 0 : q.height) >= c ? T.isSevere = !0 : (q == null ? void 0 : q.height) >= u && (T.isHeavy = !0), z == null || z.debug("[%s] check wind: %j", a.requestId, { ...R, dgThd4Wd: m, svThd4Wd: f, hvThd4Wd: b }), (R == null ? void 0 : R.scale) >= m ? (T.isDangerous = !0, delete T.isSevere, delete T.isHeavy) : (R == null ? void 0 : R.scale) > f ? (T.isDangerous || (T.isSevere = !0), delete T.isHeavy) : (R == null ? void 0 : R.scale) === b && !T.isDangerous && !T.isSevere && (T.isHeavy = !0), i += T.isDangerous ? J : 0, o += T.isSevere ? J : 0, n += T.isHeavy ? J : 0;
600
695
  }
601
- return i = Math.round(i * 100) / 100, o = Math.round(o * 100) / 100, n = Math.round(n * 100) / 100, s = Math.round(s), { sample: t, dangerous: i, severe: o, heavy: n, step: s < 3 ? 3 : s, wind: { dgThd4Wd: M, svThd4Wd: l, hvThd4Wd: b }, sig: { dgThd4Wv: d, svThd4Wv: r, hvThd4Wv: m } };
696
+ return i = Math.round(i * 100) / 100, o = Math.round(o * 100) / 100, n = Math.round(n * 100) / 100, s = Math.round(s), { sample: e, dangerous: i, severe: o, heavy: n, step: s < 3 ? 3 : s, wind: { dgThd4Wd: m, svThd4Wd: f, hvThd4Wd: b }, sig: { dgThd4Wv: r, svThd4Wv: c, hvThd4Wv: u } };
602
697
  }
603
698
  }
604
- const Tt = new yt();
605
- let F;
699
+ const xt = new yt();
700
+ let C;
606
701
  try {
607
- F = rt.getLogger("vessel");
702
+ C = ct.getLogger("vessel");
608
703
  } catch {
609
704
  } finally {
610
705
  }
611
- const Mt = new ft("", !0);
612
- var bt = /* @__PURE__ */ ((x) => (x.common = "common", x.container = "container", x.tugs = "tugs", x))(bt || {}), gt = /* @__PURE__ */ ((x) => (x.Ballast = "Ballast", x.Laden = "Laden", x))(gt || {}), wt = /* @__PURE__ */ ((x) => (x.Cp = "CP", x.Perf = "Basis", x.Instruct = "Other", x))(wt || {});
706
+ const Mt = new mt("", !0);
707
+ var gt = /* @__PURE__ */ ((E) => (E.common = "common", E.container = "container", E.tugs = "tugs", E))(gt || {}), bt = /* @__PURE__ */ ((E) => (E.Ballast = "Ballast", E.Laden = "Laden", E))(bt || {}), vt = /* @__PURE__ */ ((E) => (E.Cp = "CP", E.Perf = "Basis", E.Instruct = "Other", E))(vt || {});
613
708
  class O {
614
709
  /**
615
710
  * @see https://baike.baidu.com/item/%E6%96%B9%E5%BD%A2%E7%B3%BB%E6%95%B0/4965568?fr=aladdin
@@ -623,10 +718,10 @@ class O {
623
718
  * @param draught 吃水 m
624
719
  * @return [0.55, 0.85]
625
720
  */
626
- static blockCoefficient(t, e, a, i) {
627
- let o = Math.round(t / (e * a * i) * 100) / 100;
721
+ static blockCoefficient(e, t, a, i) {
722
+ let o = Math.round(e / (t * a * i) * 100) / 100;
628
723
  o = o < 0.55 ? 0.55 : o > 0.85 ? 0.85 : o;
629
- const n = [0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85], s = n.map((d) => Math.abs(d - o));
724
+ const n = [0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85], s = n.map((r) => Math.abs(r - o));
630
725
  return n[s.indexOf(Math.min(...s))];
631
726
  }
632
727
  /**
@@ -640,8 +735,8 @@ class O {
640
735
  * @param g 重力加速度 9.80 m/s^2
641
736
  * @return [0.05, 0.30]
642
737
  */
643
- static froudeNumber(t, e, a = 9.8) {
644
- let i = Math.round(Math.sqrt(t * t / (a * e)) * 100) / 100;
738
+ static froudeNumber(e, t, a = 9.8) {
739
+ let i = Math.round(Math.sqrt(e * e / (a * t)) * 100) / 100;
645
740
  return i = i < 0.05 ? 0.05 : i > 0.3 ? 0.3 : i, i;
646
741
  }
647
742
  /**
@@ -651,7 +746,7 @@ class O {
651
746
  * @param loadCondition
652
747
  * @private
653
748
  */
654
- static amendFactor(t, e, a) {
749
+ static amendFactor(e, t, a) {
655
750
  const i = {
656
751
  0.55: [1.7, -1.4, -7.4],
657
752
  0.6: [2.2, -2.5, -9.7],
@@ -669,8 +764,8 @@ class O {
669
764
  0.75: [2.6, -12.5, -13.5],
670
765
  0.8: [3, -16.3, -21.6],
671
766
  0.85: [3.4, -20.9, 31.8]
672
- }[t];
673
- return a === "Laden" && (n = i[t]), n[0] + n[1] * e + n[2] * Math.pow(e, 2);
767
+ }[e];
768
+ return a === "Laden" && (n = i[e]), n[0] + n[1] * t + n[2] * Math.pow(t, 2);
674
769
  }
675
770
  /**
676
771
  * 失速方向因子
@@ -683,9 +778,9 @@ class O {
683
778
  * @param bn
684
779
  * @private
685
780
  */
686
- static directionFactor(t, e = 0) {
781
+ static directionFactor(e, t = 0) {
687
782
  let a;
688
- return t > 30 && t <= 60 ? a = (1.7 - 0.03 * Math.pow(e - 4, 2)) / 2 : t > 60 && t <= 150 ? a = (0.9 - 0.06 * Math.pow(e - 6, 2)) / 2 : t > 150 && t <= 180 ? a = (0.4 - 0.03 * Math.pow(e - 8, 2)) / 2 : a = 1, Math.round(a * 1e5) / 1e5;
783
+ return e > 30 && e <= 60 ? a = (1.7 - 0.03 * Math.pow(t - 4, 2)) / 2 : e > 60 && e <= 150 ? a = (0.9 - 0.06 * Math.pow(t - 6, 2)) / 2 : e > 150 && e <= 180 ? a = (0.4 - 0.03 * Math.pow(t - 8, 2)) / 2 : a = 1, Math.round(a * 1e5) / 1e5;
689
784
  }
690
785
  /**
691
786
  * 失速船型因子
@@ -698,20 +793,20 @@ class O {
698
793
  * @param bn
699
794
  * @private
700
795
  */
701
- static vesselTagFactor(t, e, a, i = 0) {
796
+ static vesselTagFactor(e, t, a, i = 0) {
702
797
  i = i > 6 ? i - 0.9 * (i - 6) : i;
703
798
  let o;
704
- return a === "container" ? o = 0.7 * i + Math.pow(i, 6.5) / (22 * Math.pow(t, 2 / 3)) : e === "Ballast" ? o = 0.7 * i + Math.pow(i, 6.5) / (2.7 * Math.pow(t, 2 / 3)) : o = 0.5 * i + Math.pow(i, 6.5) / (2.7 * Math.pow(t, 2 / 3)), o;
799
+ return a === "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;
705
800
  }
706
801
  /**
707
802
  * 浪高影响因子
708
803
  * @param ht 浪高,单位m
709
804
  * @private
710
805
  */
711
- static waveHeightFactor(t, e) {
712
- t = t < 3 ? t * 0.7 : t, t = t < 0 ? 0.2 : t, t = t > 6 ? t - 0.9 * (t - 6) : t, t = t > 9 ? 9 : t;
806
+ static waveHeightFactor(e, t) {
807
+ e = e < 3 ? e * 0.7 : e, e = e < 0 ? 0.2 : e, e = e > 6 ? e - 0.9 * (e - 6) : e, e = e > 9 ? 9 : e;
713
808
  let a;
714
- return e > 30 && e <= 60 ? a = -0.6 : e > 60 && e <= 90 ? a = -0.4 : e > 90 && e <= 120 ? a = t < 3 ? 0.4 : -0.3 : e > 120 && e <= 150 ? a = t < 3 ? 0.6 : -0.5 : e > 150 && e <= 180 ? a = t < 3 ? 0.7 : -0.6 : a = -0.7, Math.round(a * (0.144 * Math.pow(t, 2) + 0.278 * t) * 1e4) / 1e4;
809
+ return t > 30 && t <= 60 ? a = -0.6 : t > 60 && t <= 90 ? a = -0.4 : t > 90 && t <= 120 ? a = e < 3 ? 0.4 : -0.3 : t > 120 && t <= 150 ? a = e < 3 ? 0.6 : -0.5 : t > 150 && t <= 180 ? a = e < 3 ? 0.7 : -0.6 : a = -0.7, Math.round(a * (0.144 * Math.pow(e, 2) + 0.278 * e) * 1e4) / 1e4;
715
810
  }
716
811
  /**
717
812
  * 组装船舶运行参数
@@ -721,18 +816,18 @@ class O {
721
816
  * @param bearing 方位角
722
817
  * @private
723
818
  */
724
- static assembleProperties(t, e, a, i) {
725
- var l;
726
- const o = t.lbp ?? t.length ?? t.lengthOverall ?? 198.9642, n = t.draught ?? 8, s = t.breadthMoulded ?? t.breadth ?? t.breadthExtreme ?? 32.4572, d = t.deadweight ?? 67035.7773, r = ((l = t == null ? void 0 : t.type) == null ? void 0 : l.toLowerCase()) || "common";
819
+ static assembleProperties(e, t, a, i) {
820
+ var f;
821
+ const o = e.lbp ?? e.length ?? e.lengthOverall ?? 198.9642, n = e.draught ?? 8, s = e.breadthMoulded ?? e.breadth ?? e.breadthExtreme ?? 32.4572, r = e.deadweight ?? 67035.7773, c = ((f = e == null ? void 0 : e.type) == null ? void 0 : f.toLowerCase()) || "common";
727
822
  return {
728
- tag: r.indexOf("container") > -1 ? "container" : r.indexOf("tugs") > -1 ? "tugs" : "common",
823
+ tag: c.indexOf("container") > -1 ? "container" : c.indexOf("tugs") > -1 ? "tugs" : "common",
729
824
  lbp: o,
730
- loadCondition: e,
825
+ loadCondition: t,
731
826
  draught: n,
732
827
  breadthMoulded: s,
733
828
  // 排水量(吨)= 载重量(吨)/ 1.025 + 吃水(米)× 船舶型宽(米)× 船舶型长(米)× 0.7
734
829
  // 其中,1.025是指海水的密度,吨是指公吨,吃水是指船舶的最大吃水深度。船舶型宽是指船舶的最大型宽,船舶型长是指船舶的设计型长。上述公式是针对常规船舶适用的,不同类型的船舶可能会有一些差异。
735
- displacement: Math.round((d / 1.025 + n * s * o * 0.7) * 1e4) / 1e4,
830
+ displacement: Math.round((r / 1.025 + n * s * o * 0.7) * 1e4) / 1e4,
736
831
  // 换算为m/s
737
832
  speed: Math.round((a ?? 14.1382) * 1852 / 3600 * 1e4) / 1e4,
738
833
  bearing: i || 90
@@ -749,41 +844,41 @@ class O {
749
844
  * @param useRouteParam true 启用设置速度
750
845
  * @param options
751
846
  */
752
- static async speedLoseAt(t, e, a, i = "", o = 2, n = !0, s = !1, d = {}) {
753
- let r;
754
- if (e.velocity && s && (t.speed = J.roundPrecision(e.velocity * 1852 / 3600, 6)), n) {
755
- let m;
847
+ static async speedLoseAt(e, t, a, i = "", o = 2, n = !0, s = !1, r = {}) {
848
+ let c;
849
+ if (t.velocity && s && (e.speed = _.roundPrecision(t.velocity * 1852 / 3600, 6)), n) {
850
+ let u;
756
851
  try {
757
852
  i = (i == null ? void 0 : i.toUpperCase()) === "CMEMS" ? "ECMWF" : i, i = (i == null ? void 0 : i.toUpperCase()) === "METEO2" ? "best_match" : i;
758
- const { weatherModels: f, marineModels: C } = await it.autoPickMeteoModel(i), S = await Mt.spotForecast(e.lat, e.lng, a.utc().format(), !1, !1, !0, {
759
- ...d,
853
+ const { weatherModels: y, marineModels: F } = await it.autoPickMeteoModel(i), I = await Mt.spotForecast(t.lat, t.lng, a.utc().format(), !1, !1, !0, {
854
+ ...r,
760
855
  pastDays: 1,
761
856
  forecastDays: 1,
762
- weatherModels: f,
763
- marineModels: C
764
- }), [p] = it.pickHourly(S, a);
765
- m = it.toLegacy(p);
766
- } catch (f) {
767
- F.warn("[%s] meteo2 spot(%j) forecast failed: %s", d.requestId, { ...e, eta: a.utc().format(), source: i }, f);
857
+ weatherModels: y,
858
+ marineModels: F
859
+ }), [p] = it.pickHourly(I, a);
860
+ u = it.toLegacy(p);
861
+ } catch (y) {
862
+ C.warn("[%s] meteo2 spot(%j) forecast failed: %s", r.requestId, { ...t, eta: a.utc().format(), source: i }, y);
768
863
  }
769
- const M = O.weatherFactor(t, m), l = O.currentFactor(t.bearing, m == null ? void 0 : m.current, o), b = Math.round((t.speed * 1.943844 + M + l) * 100) / 100;
770
- r = {
771
- meteo: { ...m },
772
- wxFactor: M,
773
- cFactor: l,
774
- speed: e.velocity && s ? e.velocity : b < 0 ? 1 : b,
864
+ const m = O.weatherFactor(e, u), f = O.currentFactor(e.bearing, u == null ? void 0 : u.current, o), b = Math.round((e.speed * 1.943844 + m + f) * 100) / 100;
865
+ c = {
866
+ meteo: { ...u },
867
+ wxFactor: m,
868
+ cFactor: f,
869
+ speed: t.velocity && s ? t.velocity : b < 0 ? 1 : b,
775
870
  eta: a.utc().format(),
776
871
  etd: a.utc().format()
777
872
  };
778
873
  } else
779
- r = {
874
+ c = {
780
875
  wxFactor: 0,
781
876
  cFactor: 0,
782
- speed: e.velocity && s ? e.velocity : Math.round((t.speed * 1.943844 + 0 + 0) * 100) / 100,
877
+ speed: t.velocity && s ? t.velocity : Math.round((e.speed * 1.943844 + 0 + 0) * 100) / 100,
783
878
  eta: a.utc().format(),
784
879
  etd: a.utc().format()
785
880
  };
786
- return delete e.meteo, delete e.wxFactor, delete e.cFactor, delete e.speed, delete e.etd, { ...r, ...e };
881
+ return delete t.meteo, delete t.wxFactor, delete t.cFactor, delete t.speed, delete t.etd, { ...c, ...t };
787
882
  }
788
883
  /**
789
884
  * 基于步长计算失速样本
@@ -799,53 +894,53 @@ class O {
799
894
  * @param options
800
895
  * @private
801
896
  */
802
- static async speedLoseInHoursStep(t, e, a, i, o, n, s = "", d = !0, r = !1, m = {}) {
803
- e.utc();
804
- const M = e.clone().add(14, "days"), l = [], b = [];
805
- let f = 0, C = 0, S, p;
806
- for (let w = 0; w < n.length - 1; w++) {
807
- let c = n[w];
808
- c.distanceFromStart = Math.round((o + C) * 1e3) / 1e3;
809
- const y = n[w + 1];
810
- if (t.bearing = W.calculateBearing(c, y, !y.gcToPrevious), c.bearing = t.bearing, c.suspend && r) {
811
- c.eta = c.eta || e.utc().format(), c.elapsed = c.elapsed ?? 0;
812
- const I = c.suspend - c.elapsed;
813
- if (i - f > I)
814
- i = i - f - I, e.add(I, "hour"), c.elapsed = c.suspend;
897
+ static async speedLoseInHoursStep(e, t, a, i, o, n, s = "", r = !0, c = !1, u = {}) {
898
+ t.utc();
899
+ const m = t.clone().add(14, "days"), f = [], b = [];
900
+ let y = 0, F = 0, I, p;
901
+ for (let v = 0; v < n.length - 1; v++) {
902
+ let d = n[v];
903
+ d.distanceFromStart = Math.round((o + F) * 1e3) / 1e3;
904
+ const g = n[v + 1];
905
+ if (e.bearing = W.calculateBearing(d, g, !g.gcToPrevious), d.bearing = e.bearing, d.suspend && c) {
906
+ d.eta = d.eta || t.utc().format(), d.elapsed = d.elapsed ?? 0;
907
+ const k = d.suspend - d.elapsed;
908
+ if (i - y > k)
909
+ i = i - y - k, t.add(k, "hour"), d.elapsed = d.suspend;
815
910
  else {
816
- const k = i - f;
817
- c.elapsed += k, e.add(k, "hour"), i = 0;
911
+ const S = i - y;
912
+ d.elapsed += S, t.add(S, "hour"), i = 0;
818
913
  }
819
- if (F == null || F.info(`[%s] suspend ${c.elapsed} hours at %j, and remain ${i} hours need to go...`, m.requestId, c), i === 0)
820
- return c.distanceFromPrevious = C, { etd: e, from: p || c, to: c, next: n.filter((k) => k), wps: l, days: b };
914
+ if (C == null || C.info(`[%s] suspend ${d.elapsed} hours at %j, and remain ${i} hours need to go...`, u.requestId, d), i === 0)
915
+ return d.distanceFromPrevious = F, { etd: t, from: p || d, to: d, next: n.filter((S) => S), wps: f, days: b };
821
916
  } else
822
- c.suspend = 0;
823
- d = e.isAfter(M) ? !1 : d, c = await O.speedLoseAt(t, c, e, s, 0, d, r, m), p = p || c, c.important && l.push(c), e.isSameOrAfter(a) && (b.push(c), a.add(24, "hour"));
824
- const h = W.calculateDistance(c, y, !y.gcToPrevious);
825
- let u = Math.round(h / p.speed * 1e5) / 1e5;
826
- if (f + u < i) {
827
- if (f += u, e.add(u, "hour"), delete n[w], F == null || F.debug(
828
- `[%s] go to %j from %j with ${h}nm, and cost ${u} hours`,
829
- m.requestId,
830
- { lat: y.lat, lng: y.lng },
917
+ d.suspend = 0;
918
+ r = t.isAfter(m) ? !1 : r, d = await O.speedLoseAt(e, d, t, s, 0, r, c, u), p = p || d, d.important && f.push(d), t.isSameOrAfter(a) && (b.push(d), a.add(24, "hour"));
919
+ const l = W.calculateDistance(d, g, !g.gcToPrevious);
920
+ let h = Math.round(l / p.speed * 1e5) / 1e5;
921
+ if (y + h < i) {
922
+ if (y += h, t.add(h, "hour"), delete n[v], C == null || C.debug(
923
+ `[%s] go to %j from %j with ${l}nm, and cost ${h} hours`,
924
+ u.requestId,
925
+ { lat: g.lat, lng: g.lng },
831
926
  { lat: p.lat, lng: p.lng, etd: p.etd }
832
- ), C += h, n.filter((I) => I).length <= 1) {
833
- S = y, S.eta = e.utc().format(), S.distanceFromPrevious = h, S.distanceFromStart = Math.round((o + C) * 1e4) / 1e4, l.push(S), delete n[w + 1];
927
+ ), F += l, n.filter((k) => k).length <= 1) {
928
+ I = g, I.eta = t.utc().format(), I.distanceFromPrevious = l, I.distanceFromStart = Math.round((o + F) * 1e4) / 1e4, f.push(I), delete n[v + 1];
834
929
  break;
835
930
  }
836
931
  } else {
837
- u = i - f, e.add(u, "hour");
838
- const I = J.roundPrecision(p.speed * u, 5);
839
- S = W.calculateCoordinate(c, t.bearing, I, "nauticalmiles", !y.gcToPrevious), S.eta = e.utc().format(), n[w] = S, F == null || F.debug(
840
- `[%s] go to %j from %j with ${I}nm, and cost ${u} hours`,
841
- m.requestId,
842
- { lat: S.lat, lng: S.lng },
843
- { lat: c.lat, lng: c.lng, etd: c.etd }
844
- ), C += I, S.distanceFromPrevious = Math.round(C * 1e4) / 1e4, S.distanceFromStart = Math.round((o + C) * 1e4) / 1e4;
932
+ h = i - y, t.add(h, "hour");
933
+ const k = _.roundPrecision(p.speed * h, 5);
934
+ I = W.calculateCoordinate(d, e.bearing, k, "nauticalmiles", !g.gcToPrevious), I.eta = t.utc().format(), n[v] = I, C == null || C.debug(
935
+ `[%s] go to %j from %j with ${k}nm, and cost ${h} hours`,
936
+ u.requestId,
937
+ { lat: I.lat, lng: I.lng },
938
+ { lat: d.lat, lng: d.lng, etd: d.etd }
939
+ ), F += k, I.distanceFromPrevious = Math.round(F * 1e4) / 1e4, I.distanceFromStart = Math.round((o + F) * 1e4) / 1e4;
845
940
  break;
846
941
  }
847
942
  }
848
- return { etd: e, from: p, to: S, next: n.filter((w) => w), wps: l, days: b };
943
+ return { etd: t, from: p, to: I, next: n.filter((v) => v), wps: f, days: b };
849
944
  }
850
945
  /**
851
946
  * 洋流影响因子
@@ -853,11 +948,11 @@ class O {
853
948
  * @param current 洋流要素
854
949
  * @param role 1: 船东, 2: 租家, 0: 未知
855
950
  */
856
- static currentFactor(t, e, a = 0) {
857
- const i = (t - (e == null ? void 0 : e.degree) || 0) / 180 * Math.PI;
951
+ static currentFactor(e, t, a = 0) {
952
+ const i = (e - (t == null ? void 0 : t.degree) || 0) / 180 * Math.PI;
858
953
  if (Math.abs(i) === Math.PI / 2)
859
954
  return 0;
860
- let o = ((e == null ? void 0 : e.kts) || 0) * Math.cos(i);
955
+ let o = ((t == null ? void 0 : t.kts) || 0) * Math.cos(i);
861
956
  return a & 2 ? o = Math.ceil(o * 100) / 100 : a & 1 ? o = Math.floor(o * 100) / 100 : o = Math.round(o * 100) / 100, Math.abs(o) > 5 ? 0 : o;
862
957
  }
863
958
  /**
@@ -865,17 +960,17 @@ class O {
865
960
  * @param props 船舶档案
866
961
  * @param wwc 气象要素
867
962
  */
868
- static weatherFactor(t, e) {
869
- var M, l, b, f, C, S, p;
870
- F == null || F.debug("calculate weather factor via: %j", { ...t, ...e });
871
- const a = O.blockCoefficient(t.displacement, t.lbp, t.breadthMoulded, t.draught), i = O.froudeNumber(t.speed, t.lbp), o = O.amendFactor(a, i, t.loadCondition);
872
- let n = Math.abs(t.bearing % 360 - (((M = e == null ? void 0 : e.wind) == null ? void 0 : M.degree) % 360 || 0));
963
+ static weatherFactor(e, t) {
964
+ var m, f, b, y, F, I, p;
965
+ C == null || C.debug("calculate weather factor via: %j", { ...e, ...t });
966
+ const a = O.blockCoefficient(e.displacement, e.lbp, e.breadthMoulded, e.draught), i = O.froudeNumber(e.speed, e.lbp), o = O.amendFactor(a, i, e.loadCondition);
967
+ let n = Math.abs(e.bearing % 360 - (((m = t == null ? void 0 : t.wind) == null ? void 0 : m.degree) % 360 || 0));
873
968
  n = n > 180 ? 360 - n : n;
874
- const s = O.directionFactor(n, (l = e == null ? void 0 : e.wind) == null ? void 0 : l.scale), d = O.vesselTagFactor(t.displacement, t.loadCondition, t.tag, (b = e == null ? void 0 : e.wind) == null ? void 0 : b.scale);
875
- let r = s * o * d / 100 * t.speed;
876
- r = Math.round(r * 1.943844 * 1e4) / 1e4 * -1, t.tag === "tugs" && Math.abs(r) > 1 && (r = r / (Math.abs(Math.round(r)) + 1)), F == null || F.debug("wind wx factor = %d", r), n = Math.abs(t.bearing % 360 - (((C = (f = e == null ? void 0 : e.wave) == null ? void 0 : f.sig) == null ? void 0 : C.degree) % 360 || 0));
877
- const m = O.waveHeightFactor(((p = (S = e == null ? void 0 : e.wave) == null ? void 0 : S.sig) == null ? void 0 : p.height) ?? 1, n);
878
- return F == null || F.debug("wave wx factor = %d", m), r = Math.abs(r) > Math.abs(m) ? r : r * 0.3 + m * 0.7, F == null || F.debug("weather factor = %d", r), r = Math.abs(r) > 3 ? 3 * (Math.abs(r) / r) + Math.abs(r) / r * (Math.abs(r) - 2) * 0.1 : r, Math.round((r || 0) * 100) / 100;
969
+ const s = O.directionFactor(n, (f = t == null ? void 0 : t.wind) == null ? void 0 : f.scale), r = O.vesselTagFactor(e.displacement, e.loadCondition, e.tag, (b = t == null ? void 0 : t.wind) == null ? void 0 : b.scale);
970
+ let c = s * o * r / 100 * e.speed;
971
+ c = Math.round(c * 1.943844 * 1e4) / 1e4 * -1, e.tag === "tugs" && Math.abs(c) > 1 && (c = c / (Math.abs(Math.round(c)) + 1)), C == null || C.debug("wind wx factor = %d", c), n = Math.abs(e.bearing % 360 - (((F = (y = t == null ? void 0 : t.wave) == null ? void 0 : y.sig) == null ? void 0 : F.degree) % 360 || 0));
972
+ const u = O.waveHeightFactor(((p = (I = t == null ? void 0 : t.wave) == null ? void 0 : I.sig) == null ? void 0 : p.height) ?? 1, n);
973
+ return C == null || C.debug("wave wx factor = %d", u), c = Math.abs(c) > Math.abs(u) ? c : c * 0.3 + u * 0.7, C == null || C.debug("weather factor = %d", c), c = Math.abs(c) > 3 ? 3 * (Math.abs(c) / c) + Math.abs(c) / c * (Math.abs(c) - 2) * 0.1 : c, Math.round((c || 0) * 100) / 100;
879
974
  }
880
975
  /**
881
976
  * 全程失速分析(走完航程)
@@ -890,77 +985,77 @@ class O {
890
985
  * @param useRouteParam
891
986
  * @param options
892
987
  */
893
- static async analyseInstant(t, e, a, i, o, n = "", s = 0, d = !0, r = !1, m = {}) {
894
- var z, G, X, Q, Z, $;
895
- const M = g().valueOf();
896
- t.lng = J.convertToStdLng(t.lng);
897
- const { route: l, waypoints: b } = o.points, f = W.calculateSubRoute(t, l);
898
- if (((z = f[0]) == null ? void 0 : z.length) <= 1)
988
+ static async analyseInstant(e, t, a, i, o, n = "", s = 0, r = !0, c = !1, u = {}) {
989
+ var K, G, X, Q, Z, $;
990
+ const m = w().valueOf();
991
+ e.lng = _.convertToStdLng(e.lng);
992
+ const { route: f, waypoints: b } = o.points, y = W.calculateSubRoute(e, f);
993
+ if (((K = y[0]) == null ? void 0 : K.length) <= 1)
899
994
  return;
900
- const { v0: C, label: S } = t.sog ? {
901
- v0: t.sog,
902
- label: t.label || "Other"
995
+ const { v0: F, label: I } = e.sog ? {
996
+ v0: e.sog,
997
+ label: e.label || "Other"
903
998
  /* Instruct */
904
999
  } : {
905
1000
  v0: i.speed,
906
1001
  label: "CP"
907
1002
  /* Cp */
908
- }, p = O.assembleProperties(a, i.loadCondition, C, 0), w = b.length ? W.calculateSubWaypoints(t, b) : [];
909
- w.forEach((q) => q.important = !0);
910
- const c = {
911
- from: { ...t },
912
- route: f,
913
- waypoints: w,
914
- v0: C,
915
- label: S
916
- }, y = {
1003
+ }, p = O.assembleProperties(a, i.loadCondition, F, 0), v = b.length ? W.calculateSubWaypoints(e, b) : [];
1004
+ v.forEach((Y) => Y.important = !0);
1005
+ const d = {
1006
+ from: { ...e },
1007
+ route: y,
1008
+ waypoints: v,
1009
+ v0: F,
1010
+ label: I
1011
+ }, g = {
917
1012
  hours: [],
918
1013
  days: [],
919
1014
  wps: []
920
1015
  };
921
- s || (W.calculateRouteDistance(f) / i.speed <= 72 ? s = 3 : s = 6);
922
- let h = W.simplifyRouteToCoordinates(f, w, 0), u = 0, I = 0, k = 0, D = 0;
923
- e = g(e).utc();
924
- const Y = e.clone();
925
- for (; h.length > 0; ) {
926
- const q = s - e.hour() % s, V = Math.ceil(e.clone().add(q, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(e, "h", !0) * 1e4) / 1e4, E = await O.speedLoseInHoursStep(
1016
+ s || (W.calculateRouteDistance(y) / i.speed <= 72 ? s = 3 : s = 6);
1017
+ let l = W.simplifyRouteToCoordinates(y, v, 0), h = 0, k = 0, S = 0, D = 0;
1018
+ t = w(t).utc();
1019
+ const P = t.clone();
1020
+ for (; l.length > 0; ) {
1021
+ const Y = s - t.hour() % s, B = Math.ceil(t.clone().add(Y, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4, j = await O.speedLoseInHoursStep(
927
1022
  p,
928
- e,
929
- Y,
930
- V,
931
- u,
1023
+ t,
1024
+ P,
1025
+ B,
932
1026
  h,
1027
+ l,
933
1028
  n,
934
- d,
935
1029
  r,
936
- m
1030
+ c,
1031
+ u
937
1032
  );
938
- (G = E.from) != null && G.speed && (y.hours.push(E.from), y.wps.push(...E.wps), y.days.push(...E.days)), h = E == null ? void 0 : E.next, h.length || y.hours.push(E == null ? void 0 : E.to), u += Math.round((((X = E == null ? void 0 : E.to) == null ? void 0 : X.distanceFromPrevious) ?? 0) * 1e4) / 1e4;
1033
+ (G = j.from) != null && G.speed && (g.hours.push(j.from), g.wps.push(...j.wps), g.days.push(...j.days)), l = j == null ? void 0 : j.next, l.length || g.hours.push(j == null ? void 0 : j.to), h += Math.round((((X = j == null ? void 0 : j.to) == null ? void 0 : X.distanceFromPrevious) ?? 0) * 1e4) / 1e4;
939
1034
  }
940
- const j = y.hours;
941
- for (let q = 0; q < j.length - 1; q++) {
942
- const V = g(j[q + 1].eta).diff(j[q].etd, "hour", !0) || 1;
943
- I += (j[q].wxFactor || 0) * V, k += (j[q].cFactor || 0) * V, D += V;
1035
+ const N = g.hours;
1036
+ for (let Y = 0; Y < N.length - 1; Y++) {
1037
+ const B = w(N[Y + 1].eta).diff(N[Y].etd, "hour", !0) || 1;
1038
+ k += (N[Y].wxFactor || 0) * B, S += (N[Y].cFactor || 0) * B, D += B;
944
1039
  }
945
- (Q = y.wps) == null || Q.forEach((q, V) => {
946
- q.positionTime = g.utc(q.etd || q.eta).unix();
947
- const E = y.wps[V - 1];
948
- if (E) {
949
- const L = q.distanceFromStart - E.distanceFromStart, H = g(q.eta || q.etd).diff(g(E.etd || E.eta), "h", !0);
950
- q.avgSpd = Math.round(L / H * 100) / 100, E.bearing = W.calculateBearing(E, q);
1040
+ (Q = g.wps) == null || Q.forEach((Y, B) => {
1041
+ Y.positionTime = w.utc(Y.etd || Y.eta).unix();
1042
+ const j = g.wps[B - 1];
1043
+ if (j) {
1044
+ const V = Y.distanceFromStart - j.distanceFromStart, H = w(Y.eta || Y.etd).diff(w(j.etd || j.eta), "h", !0);
1045
+ Y.avgSpd = Math.round(V / H * 100) / 100, j.bearing = W.calculateBearing(j, Y);
951
1046
  }
952
- }), y.wps = (Z = y.wps) == null ? void 0 : Z.reduce((q, V) => (q.some((E) => Math.round(E.positionTime / 60) === Math.round(V.positionTime / 60)) || q.push(V), q), []), c.sample = y;
953
- const A = y.hours.at(0), T = y.hours.at(-1);
954
- c.distance = Math.round(T.distanceFromStart * 1e3) / 1e3, c.etd = g(A.eta).utc().format(), c.eta = g(T.eta).utc().format(), c.wxFactor = Math.round(I / D * 1e3) / 1e3, c.cFactor = Math.round(k / D * 1e3) / 1e3, c.avgSpeed = Math.round(T.distanceFromStart / D * 1e3) / 1e3, c.totalHrs = Math.round(D * 1e3) / 1e3;
955
- const { distanceInECA: N, hoursInECA: P, totalDgoConsInECA: R, eca: U } = await this.calculateECA(c, i, m), tt = J.roundPrecision(i.fo / 24 * (D - P), 3), at = J.roundPrecision(i.dgo / 24 * D, 3);
956
- c.extend = {
957
- eca: U,
958
- distanceInECA: N,
959
- hoursInECA: P,
1047
+ }), g.wps = (Z = g.wps) == null ? void 0 : Z.reduce((Y, B) => (Y.some((j) => Math.round(j.positionTime / 60) === Math.round(B.positionTime / 60)) || Y.push(B), Y), []), d.sample = g;
1048
+ const A = g.hours.at(0), x = g.hours.at(-1);
1049
+ d.distance = Math.round(x.distanceFromStart * 1e3) / 1e3, d.etd = w(A.eta).utc().format(), d.eta = w(x.eta).utc().format(), d.wxFactor = Math.round(k / D * 1e3) / 1e3, d.cFactor = Math.round(S / D * 1e3) / 1e3, d.avgSpeed = Math.round(x.distanceFromStart / D * 1e3) / 1e3, d.totalHrs = Math.round(D * 1e3) / 1e3;
1050
+ const { distanceInECA: T, hoursInECA: q, totalDgoConsInECA: R, eca: J } = await this.calculateECA(d, i, u), tt = _.roundPrecision(i.fo / 24 * (D - q), 3), at = _.roundPrecision(i.dgo / 24 * D, 3);
1051
+ d.extend = {
1052
+ eca: J,
1053
+ distanceInECA: T,
1054
+ hoursInECA: q,
960
1055
  totalDgoConsInECA: R
961
- }, c.totalFoCons = tt < 0 ? 0 : tt, c.totalDgoCons = at;
962
- const et = g().valueOf() - M, nt = (($ = y == null ? void 0 : y.hours) == null ? void 0 : $.length) || 1;
963
- return F == null || F.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", m == null ? void 0 : m.requestId, et, nt, Math.round(et / nt * 1e3) / 1e3), c;
1056
+ }, d.totalFoCons = tt < 0 ? 0 : tt, d.totalDgoCons = at;
1057
+ const et = w().valueOf() - m, ot = (($ = g == null ? void 0 : g.hours) == null ? void 0 : $.length) || 1;
1058
+ return C == null || C.info("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", u == null ? void 0 : u.requestId, et, ot, Math.round(et / ot * 1e3) / 1e3), d;
964
1059
  }
965
1060
  /**
966
1061
  * 分段失速分析(最多走hours 小时)
@@ -975,78 +1070,78 @@ class O {
975
1070
  * @param useMeteo true 启用气象分析
976
1071
  * @param useRouteParam
977
1072
  */
978
- static async analyseInstantWithThreshed(t, e, a, i, o, n, s, d = "", r = 3, m = !0, M = !1, l = {}) {
979
- var X, Q, Z, $, q, V;
980
- const b = g().valueOf();
981
- t.lng = J.convertToStdLng(t.lng);
982
- const { v0: f, label: C } = t.sog ? {
983
- v0: t.sog,
984
- label: t.label || "Other"
1073
+ static async analyseInstantWithThreshed(e, t, a, i, o, n, s, r = "", c = 3, u = !0, m = !1, f = {}) {
1074
+ var X, Q, Z, $, Y, B;
1075
+ const b = w().valueOf();
1076
+ e.lng = _.convertToStdLng(e.lng);
1077
+ const { v0: y, label: F } = e.sog ? {
1078
+ v0: e.sog,
1079
+ label: e.label || "Other"
985
1080
  /* Instruct */
986
1081
  } : {
987
1082
  v0: o.speed,
988
1083
  label: "CP"
989
1084
  /* Cp */
990
- }, S = O.assembleProperties(i, o.loadCondition, f, 0), p = W.calculateSubRoute(t, n);
1085
+ }, I = O.assembleProperties(i, o.loadCondition, y, 0), p = W.calculateSubRoute(e, n);
991
1086
  if (((X = p[0]) == null ? void 0 : X.length) <= 1)
992
1087
  return;
993
- const w = s.length ? W.calculateSubWaypoints(t, s) : [];
994
- w.forEach((E) => E.important = !0);
995
- let c = W.simplifyRouteToCoordinates(p, w, 0), y = 0, h = 0, u = 0, I = 0;
996
- const k = {
1088
+ const v = s.length ? W.calculateSubWaypoints(e, s) : [];
1089
+ v.forEach((j) => j.important = !0);
1090
+ let d = W.simplifyRouteToCoordinates(p, v, 0), g = 0, l = 0, h = 0, k = 0;
1091
+ const S = {
997
1092
  hours: [],
998
1093
  wps: [],
999
1094
  days: []
1000
1095
  };
1001
- e = g(e).utc();
1002
- const D = e.clone();
1003
- for (; c.length > 0; ) {
1004
- const E = r - e.hour() % r;
1005
- let L = Math.ceil(e.clone().add(E, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(e, "h", !0) * 1e4) / 1e4;
1006
- L = e.clone().add(L, "h").isSameOrAfter(a) ? a.diff(e, "h", !0) * 1e4 / 1e4 : L;
1007
- const H = await O.speedLoseInHoursStep(S, e, D, L, y, c, d, m, M, l);
1008
- if ((Q = H.from) != null && Q.speed && (k.hours.push(H.from), H != null && H.wps && k.wps.push(...H.wps), k.days.push(...H.days)), c = H == null ? void 0 : H.next, c.length || k.hours.push(H == null ? void 0 : H.to), y += Math.round((((Z = H == null ? void 0 : H.to) == null ? void 0 : Z.distanceFromPrevious) ?? 0) * 1e4) / 1e4, !L)
1096
+ t = w(t).utc();
1097
+ const D = t.clone();
1098
+ for (; d.length > 0; ) {
1099
+ const j = c - t.hour() % c;
1100
+ let V = Math.ceil(t.clone().add(j, "h").set({ minute: 0, second: 0, millisecond: 0 }).diff(t, "h", !0) * 1e4) / 1e4;
1101
+ V = t.clone().add(V, "h").isSameOrAfter(a) ? a.diff(t, "h", !0) * 1e4 / 1e4 : V;
1102
+ const H = await O.speedLoseInHoursStep(I, t, D, V, g, d, r, u, m, f);
1103
+ if ((Q = H.from) != null && Q.speed && (S.hours.push(H.from), H != null && H.wps && S.wps.push(...H.wps), S.days.push(...H.days)), d = H == null ? void 0 : H.next, d.length || S.hours.push(H == null ? void 0 : H.to), g += Math.round((((Z = H == null ? void 0 : H.to) == null ? void 0 : Z.distanceFromPrevious) ?? 0) * 1e4) / 1e4, !V)
1009
1104
  break;
1010
1105
  }
1011
- k.wps = ($ = k.wps) == null ? void 0 : $.reduce((E, L) => (E.some((H) => Math.round(g(H.etd).unix() / 60) === Math.round(g(L.etd).unix() / 60)) || E.push(L), E), []), (q = k.wps) == null || q.forEach((E, L) => {
1012
- const H = k.wps[L - 1];
1106
+ S.wps = ($ = S.wps) == null ? void 0 : $.reduce((j, V) => (j.some((H) => Math.round(w(H.etd).unix() / 60) === Math.round(w(V.etd).unix() / 60)) || j.push(V), j), []), (Y = S.wps) == null || Y.forEach((j, V) => {
1107
+ const H = S.wps[V - 1];
1013
1108
  if (H) {
1014
- const ct = E.distanceFromStart - H.distanceFromStart, dt = g(E.eta || E.etd).diff(g(H.etd || H.eta), "h", !0);
1015
- E.avgSpd = Math.round(ct / dt * 100) / 100;
1016
- const ut = W.calculateBearing(H, E);
1109
+ const rt = j.distanceFromStart - H.distanceFromStart, dt = w(j.eta || j.etd).diff(w(H.etd || H.eta), "h", !0);
1110
+ j.avgSpd = Math.round(rt / dt * 100) / 100;
1111
+ const ut = W.calculateBearing(H, j);
1017
1112
  H.bearing = ut;
1018
1113
  }
1019
1114
  });
1020
- const Y = k.hours;
1021
- for (let E = 0; E < Y.length - 1; E++) {
1022
- const L = g(Y[E + 1].eta).diff(Y[E].etd, "hour", !0);
1023
- h += Y[E].wxFactor * L, u += Y[E].cFactor * L, I += L;
1115
+ const P = S.hours;
1116
+ for (let j = 0; j < P.length - 1; j++) {
1117
+ const V = w(P[j + 1].eta).diff(P[j].etd, "hour", !0);
1118
+ l += P[j].wxFactor * V, h += P[j].cFactor * V, k += V;
1024
1119
  }
1025
- const j = k.hours.at(0), A = k.hours.at(-1), T = await W.calculateRangeRoute(j, A, p), N = await W.calculateRangeWaypoints(j, A, p, w), P = {
1026
- sample: k,
1120
+ const N = S.hours.at(0), A = S.hours.at(-1), x = await W.calculateRangeRoute(N, A, p), T = await W.calculateRangeWaypoints(N, A, p, v), q = {
1121
+ sample: S,
1027
1122
  distance: Math.round(((A == null ? void 0 : A.distanceFromStart) || 0) * 1e4) / 1e4,
1028
1123
  // 注意,可能会在first节点Drift,所有采用eta做为初始出发时间
1029
- etd: g(j.eta).utc().format(),
1030
- eta: g(A == null ? void 0 : A.eta).utc().format(),
1031
- wxFactor: Math.round(h / I * 1e3) / 1e3,
1032
- cFactor: Math.round(u / I * 1e3) / 1e3,
1033
- avgSpeed: Math.round(((A == null ? void 0 : A.distanceFromStart) || 0) / I * 1e3) / 1e3,
1034
- totalHrs: Math.round(I * 1e3) / 1e3,
1035
- from: j,
1124
+ etd: w(N.eta).utc().format(),
1125
+ eta: w(A == null ? void 0 : A.eta).utc().format(),
1126
+ wxFactor: Math.round(l / k * 1e3) / 1e3,
1127
+ cFactor: Math.round(h / k * 1e3) / 1e3,
1128
+ avgSpeed: Math.round(((A == null ? void 0 : A.distanceFromStart) || 0) / k * 1e3) / 1e3,
1129
+ totalHrs: Math.round(k * 1e3) / 1e3,
1130
+ from: N,
1036
1131
  to: A,
1037
- route: T,
1038
- waypoints: N,
1039
- v0: f,
1040
- label: C
1041
- }, { distanceInECA: R, hoursInECA: U, totalDgoConsInECA: tt, eca: at } = await this.calculateECA(P, o, l), ot = J.roundPrecision(o.fo / 24 * (I - U), 3), et = J.roundPrecision(o.dgo / 24 * I, 3);
1042
- P.extend = {
1132
+ route: x,
1133
+ waypoints: T,
1134
+ v0: y,
1135
+ label: F
1136
+ }, { distanceInECA: R, hoursInECA: J, totalDgoConsInECA: tt, eca: at } = await this.calculateECA(q, o, f), nt = _.roundPrecision(o.fo / 24 * (k - J), 3), et = _.roundPrecision(o.dgo / 24 * k, 3);
1137
+ q.extend = {
1043
1138
  eca: at,
1044
1139
  distanceInECA: R,
1045
- hoursInECA: U,
1140
+ hoursInECA: J,
1046
1141
  totalDgoConsInECA: tt
1047
- }, P.totalDgoCons = et, P.totalFoCons = ot < 0 ? 0 : ot;
1048
- const z = g().valueOf() - b, G = ((V = k == null ? void 0 : k.hours) == null ? void 0 : V.length) || 1;
1049
- return F == null || F.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", l == null ? void 0 : l.requestId, z, G, Math.round(z / G * 1e3) / 1e3), P;
1142
+ }, q.totalDgoCons = et, q.totalFoCons = nt < 0 ? 0 : nt;
1143
+ const K = w().valueOf() - b, G = ((B = S == null ? void 0 : S.hours) == null ? void 0 : B.length) || 1;
1144
+ return C == null || C.debug("[%s] each hour-sample speed analyse cost: (%d / %d = %d) ms", f == null ? void 0 : f.requestId, K, G, Math.round(K / G * 1e3) / 1e3), q;
1050
1145
  }
1051
1146
  /**
1052
1147
  * 在指定航线条件下,基于多CP,动态计算最优成本(租金+油费)方案
@@ -1063,59 +1158,59 @@ class O {
1063
1158
  * @param lane 基础航线(重要转向点)
1064
1159
  * @param options
1065
1160
  */
1066
- static async analyseCost(t, e, a, i, o = {}) {
1067
- var p, w;
1068
- const n = g().valueOf(), s = [];
1069
- t.speedStep = t.speedStep || 3, t.alterStep = t.alterStep ?? 1;
1070
- const d = W.calculateRouteDistance(i.route);
1071
- let r = 0;
1072
- a.forEach((c) => {
1073
- const y = Math.ceil(d / c.speed / 24);
1074
- r = r < y ? y : r;
1075
- }), r = r * 1.3;
1076
- const m = g.utc(t.etd).add(r ?? 14, "day");
1077
- let M = 1;
1078
- for (const c of a) {
1079
- const y = JSON.parse(JSON.stringify(i.route)), h = JSON.parse(JSON.stringify(i.waypoints)), u = await O.analyseInstantWithThreshed(
1080
- { lat: t.lat, lng: t.lng },
1081
- t.etd,
1082
- m,
1083
- e,
1084
- c,
1085
- y,
1086
- h,
1087
- t.meteoVendor,
1088
- t.speedStep,
1089
- t.useMeteo,
1090
- t.useRouteParam,
1161
+ static async analyseCost(e, t, a, i, o = {}) {
1162
+ var p, v;
1163
+ const n = w().valueOf(), s = [];
1164
+ e.speedStep = e.speedStep || 3, e.alterStep = e.alterStep ?? 1;
1165
+ const r = W.calculateRouteDistance(i.route);
1166
+ let c = 0;
1167
+ a.forEach((d) => {
1168
+ const g = Math.ceil(r / d.speed / 24);
1169
+ c = c < g ? g : c;
1170
+ }), c = c * 1.3;
1171
+ const u = w.utc(e.etd).add(c ?? 14, "day");
1172
+ let m = 1;
1173
+ for (const d of a) {
1174
+ const g = JSON.parse(JSON.stringify(i.route)), l = JSON.parse(JSON.stringify(i.waypoints)), h = await O.analyseInstantWithThreshed(
1175
+ { lat: e.lat, lng: e.lng },
1176
+ e.etd,
1177
+ u,
1178
+ t,
1179
+ d,
1180
+ g,
1181
+ l,
1182
+ e.meteoVendor,
1183
+ e.speedStep,
1184
+ e.useMeteo,
1185
+ e.useRouteParam,
1091
1186
  o
1092
1187
  );
1093
- u && (await O.calculateCost(u, c, t, o), s.push(u), F == null || F.info("[%s][L%d-%d] analyse from %s to %s cost: %j", o.requestId, 1, M, t.etd, m.format(), {
1094
- cost: u.cost.total,
1095
- hire: u.cost.hire,
1096
- bunker: u.cost.bunker,
1097
- distance: u.distance,
1098
- hours: u.totalHrs,
1099
- cp: `${c.speed}/${c.fo}/${c.dgo}`
1100
- })), M++;
1188
+ h && (await O.calculateCost(h, d, e, o), s.push(h), C == null || C.info("[%s][L%d-%d] analyse from %s to %s cost: %j", o.requestId, 1, m, e.etd, u.format(), {
1189
+ cost: h.cost.total,
1190
+ hire: h.cost.hire,
1191
+ bunker: h.cost.bunker,
1192
+ distance: h.distance,
1193
+ hours: h.totalHrs,
1194
+ cp: `${d.speed}/${d.fo}/${d.dgo}`
1195
+ })), m++;
1101
1196
  }
1102
- s.sort((c, y) => c.cost.total - y.cost.total);
1103
- const l = s.at(0), b = s.at(1), f = [];
1104
- if (f.push({ combined: !1, speeds: [l], cost: (p = l.cost) == null ? void 0 : p.total }), b) {
1105
- const c = l.cost.cp, y = b.cost.cp, h = g(l.eta), u = g(l.etd), I = h.diff(u, "days", !0);
1106
- let k = Math.ceil(I / 2);
1107
- k = k > 7 ? 7 : k < t.alterStep ? t.alterStep : k;
1108
- let D = 2, Y = { combined: !1, speeds: [b], cost: (w = b.cost) == null ? void 0 : w.total }, j;
1109
- for (; k >= t.alterStep; ) {
1110
- const A = await O.combinedAnalyse(t, e, m, [c, y], i, k, { ...o, level: D });
1111
- if (Y.cost > A.cost ? j ? (j == null ? void 0 : j.cost) > A.cost && (j = A) : (j = Y, Y = A) : (!j || (j == null ? void 0 : j.cost) > A.cost) && (j = A), k <= t.alterStep)
1197
+ s.sort((d, g) => d.cost.total - g.cost.total);
1198
+ const f = s.at(0), b = s.at(1), y = [];
1199
+ if (y.push({ combined: !1, speeds: [f], cost: (p = f.cost) == null ? void 0 : p.total }), b) {
1200
+ const d = f.cost.cp, g = b.cost.cp, l = w(f.eta), h = w(f.etd), k = l.diff(h, "days", !0);
1201
+ let S = Math.ceil(k / 2);
1202
+ S = S > 7 ? 7 : S < e.alterStep ? e.alterStep : S;
1203
+ let D = 2, P = { combined: !1, speeds: [b], cost: (v = b.cost) == null ? void 0 : v.total }, N;
1204
+ for (; S >= e.alterStep; ) {
1205
+ const A = await O.combinedAnalyse(e, t, u, [d, g], i, S, { ...o, level: D });
1206
+ if (P.cost > A.cost ? N ? (N == null ? void 0 : N.cost) > A.cost && (N = A) : (N = P, P = A) : (!N || (N == null ? void 0 : N.cost) > A.cost) && (N = A), S <= e.alterStep)
1112
1207
  break;
1113
- k = Math.ceil(k / 2), D += 1;
1208
+ S = Math.ceil(S / 2), D += 1;
1114
1209
  }
1115
- f.push(Y), j && f.push(j);
1210
+ y.push(P), N && y.push(N);
1116
1211
  }
1117
- const S = g().valueOf() - n;
1118
- return F == null || F.info("[%s] analyse elapsed: %d ms", o == null ? void 0 : o.requestId, S), f.sort((c, y) => c.cost - y.cost);
1212
+ const I = w().valueOf() - n;
1213
+ return C == null || C.info("[%s] analyse elapsed: %d ms", o == null ? void 0 : o.requestId, I), y.sort((d, g) => d.cost - g.cost);
1119
1214
  }
1120
1215
  /**
1121
1216
  * 按步长多次减半,分别用7,4,2,1天步长及cpa,cpb交替计算各种组合下的成本
@@ -1127,24 +1222,24 @@ class O {
1127
1222
  * @param step 步长,7,4,2,1
1128
1223
  * @param options
1129
1224
  */
1130
- static async combinedAnalyse(t, e, a, i, o, n, s = {}) {
1131
- s.counter = 1, F == null || F.info("[%s][L%d] analyse with alternate cp in every %d days", s.requestId, s.level, n);
1132
- const d = await O.alternateAnalyse(t, e, a, i, 0, o, n, s), r = d.reduce((y, h) => y + h.cost.total, 0), m = d.reduce((y, h) => y + h.cost.hire, 0), M = d.reduce((y, h) => y + h.cost.bunker, 0), l = d.reduce((y, h) => y + h.distance, 0), b = d.reduce((y, h) => y + h.totalHrs, 0);
1133
- F == null || F.info("[%s][L%d] cost with cpa/cpb turn: %j", s.requestId, s.level, {
1134
- cost: r,
1135
- hire: m,
1136
- bunker: M,
1137
- distance: l,
1225
+ static async combinedAnalyse(e, t, a, i, o, n, s = {}) {
1226
+ s.counter = 1, C == null || C.info("[%s][L%d] analyse with alternate cp in every %d days", s.requestId, s.level, n);
1227
+ const r = await O.alternateAnalyse(e, t, a, i, 0, o, n, s), c = r.reduce((g, l) => g + l.cost.total, 0), u = r.reduce((g, l) => g + l.cost.hire, 0), m = r.reduce((g, l) => g + l.cost.bunker, 0), f = r.reduce((g, l) => g + l.distance, 0), b = r.reduce((g, l) => g + l.totalHrs, 0);
1228
+ C == null || C.info("[%s][L%d] cost with cpa/cpb turn: %j", s.requestId, s.level, {
1229
+ cost: c,
1230
+ hire: u,
1231
+ bunker: m,
1232
+ distance: f,
1138
1233
  hours: b
1139
1234
  });
1140
- const f = await O.alternateAnalyse(t, e, a, i, 1, o, n, s), C = f.reduce((y, h) => y + h.cost.total, 0), S = f.reduce((y, h) => y + h.cost.hire, 0), p = f.reduce((y, h) => y + h.cost.bunker, 0), w = f.reduce((y, h) => y + h.distance, 0), c = f.reduce((y, h) => y + h.totalHrs, 0);
1141
- return F == null || F.info("[%s][L%d] cost with cpb/cpa turn: %j", s.requestId, s.level, {
1142
- cost: C,
1143
- hire: S,
1235
+ const y = await O.alternateAnalyse(e, t, a, i, 1, o, n, s), F = y.reduce((g, l) => g + l.cost.total, 0), I = y.reduce((g, l) => g + l.cost.hire, 0), p = y.reduce((g, l) => g + l.cost.bunker, 0), v = y.reduce((g, l) => g + l.distance, 0), d = y.reduce((g, l) => g + l.totalHrs, 0);
1236
+ return C == null || C.info("[%s][L%d] cost with cpb/cpa turn: %j", s.requestId, s.level, {
1237
+ cost: F,
1238
+ hire: I,
1144
1239
  bunker: p,
1145
- distance: w,
1146
- hours: c
1147
- }), r < C ? { combined: !0, cost: Math.round(r * 1e3) / 1e3, speeds: d, step: n } : { combined: !0, cost: Math.round(C * 1e3) / 1e3, speeds: f, step: n };
1240
+ distance: v,
1241
+ hours: d
1242
+ }), c < F ? { combined: !0, cost: Math.round(c * 1e3) / 1e3, speeds: r, step: n } : { combined: !0, cost: Math.round(F * 1e3) / 1e3, speeds: y, step: n };
1148
1243
  }
1149
1244
  /**
1150
1245
  * 基于cp索引,交替计算指定步长下的成本
@@ -1157,48 +1252,48 @@ class O {
1157
1252
  * @param step 步长,7,4,2,1
1158
1253
  * @param options
1159
1254
  */
1160
- static async alternateAnalyse(t, e, a, i, o, n, s, d = {}) {
1161
- var l, b;
1162
- let r = g.utc(t.etd);
1163
- const m = { lat: t.lat, lng: t.lng }, M = [];
1164
- for (; r.isBefore(a); ) {
1165
- const f = r.clone().utc().add(s, "day"), C = JSON.parse(JSON.stringify(n.route)), S = JSON.parse(JSON.stringify(n.waypoints)), p = i[o], w = await O.analyseInstantWithThreshed(
1166
- m,
1167
- r.utc().format(),
1168
- f,
1169
- e,
1255
+ static async alternateAnalyse(e, t, a, i, o, n, s, r = {}) {
1256
+ var f, b;
1257
+ let c = w.utc(e.etd);
1258
+ const u = { lat: e.lat, lng: e.lng }, m = [];
1259
+ for (; c.isBefore(a); ) {
1260
+ const y = c.clone().utc().add(s, "day"), F = JSON.parse(JSON.stringify(n.route)), I = JSON.parse(JSON.stringify(n.waypoints)), p = i[o], v = await O.analyseInstantWithThreshed(
1261
+ u,
1262
+ c.utc().format(),
1263
+ y,
1264
+ t,
1170
1265
  p,
1171
- C,
1172
- S,
1173
- t.meteoVendor,
1174
- t.speedStep,
1175
- t.useMeteo,
1176
- t.useRouteParam,
1177
- d
1266
+ F,
1267
+ I,
1268
+ e.meteoVendor,
1269
+ e.speedStep,
1270
+ e.useMeteo,
1271
+ e.useRouteParam,
1272
+ r
1178
1273
  );
1179
- w && (await O.calculateCost(w, p, t, d), F == null || F.info(
1274
+ v && (await O.calculateCost(v, p, e, r), C == null || C.info(
1180
1275
  "[%s][L%d-%d] analyse from %s to %s cost: %j",
1181
- d.requestId,
1182
- d.level,
1183
- d.counter,
1184
- r.utc().format(),
1185
- f.utc().format(),
1276
+ r.requestId,
1277
+ r.level,
1278
+ r.counter,
1279
+ c.utc().format(),
1280
+ y.utc().format(),
1186
1281
  {
1187
- cost: w.cost.total,
1188
- hire: w.cost.hire,
1189
- bunker: w.cost.bunker,
1190
- distance: w.distance,
1191
- hours: w.totalHrs,
1282
+ cost: v.cost.total,
1283
+ hire: v.cost.hire,
1284
+ bunker: v.cost.bunker,
1285
+ distance: v.distance,
1286
+ hours: v.totalHrs,
1192
1287
  cp: `${p.speed}/${p.fo}/${p.dgo}`
1193
1288
  }
1194
- )), d.counter = d.counter + 1;
1195
- const c = (b = (l = w == null ? void 0 : w.sample) == null ? void 0 : l.hours) == null ? void 0 : b.at(-1);
1196
- if (c)
1197
- m.lat = c.lat, m.lng = c.lng, r = g(c.eta), M.push(w), o = o ? 0 : 1;
1289
+ )), r.counter = r.counter + 1;
1290
+ const d = (b = (f = v == null ? void 0 : v.sample) == null ? void 0 : f.hours) == null ? void 0 : b.at(-1);
1291
+ if (d)
1292
+ u.lat = d.lat, u.lng = d.lng, c = w(d.eta), m.push(v), o = o ? 0 : 1;
1198
1293
  else
1199
1294
  break;
1200
1295
  }
1201
- return M;
1296
+ return m;
1202
1297
  }
1203
1298
  /**
1204
1299
  * 计算Speed的cost
@@ -1207,36 +1302,36 @@ class O {
1207
1302
  * @param props
1208
1303
  * @param options
1209
1304
  */
1210
- static async calculateCost(t, e, a, i = {}) {
1305
+ static async calculateCost(e, t, a, i = {}) {
1211
1306
  var o;
1212
- if (t) {
1213
- const n = (a.addComm || 0) >= 1 ? (a.addComm || 0) / 100 : a.addComm || 0, s = Math.round(t.totalHrs / 24 * (a.dailyHire || 0) * (1 - n) * 1e3) / 1e3, d = Math.round(t.totalFoCons * (a.priceFO || 0) * 1e3) / 1e3, r = Math.round((t.totalDgoCons + (((o = t.extend) == null ? void 0 : o.totalDgoConsInECA) || 0)) * (a.priceDGO || 0) * 1e3) / 1e3;
1214
- t.cost = {
1215
- total: Math.round((s + d + r) * 1e3) / 1e3,
1307
+ if (e) {
1308
+ const n = (a.addComm || 0) >= 1 ? (a.addComm || 0) / 100 : a.addComm || 0, s = Math.round(e.totalHrs / 24 * (a.dailyHire || 0) * (1 - n) * 1e3) / 1e3, r = Math.round(e.totalFoCons * (a.priceFO || 0) * 1e3) / 1e3, c = Math.round((e.totalDgoCons + (((o = e.extend) == null ? void 0 : o.totalDgoConsInECA) || 0)) * (a.priceDGO || 0) * 1e3) / 1e3;
1309
+ e.cost = {
1310
+ total: Math.round((s + r + c) * 1e3) / 1e3,
1216
1311
  hire: s,
1217
- bunker: Math.round((d + r) * 1e3) / 1e3,
1218
- cp: e
1312
+ bunker: Math.round((r + c) * 1e3) / 1e3,
1313
+ cp: t
1219
1314
  };
1220
1315
  }
1221
- return t;
1316
+ return e;
1222
1317
  }
1223
1318
  /**
1224
1319
  * 计算单cp模式下的ECA属性
1225
1320
  *
1226
1321
  */
1227
- static async calculateECA(t, e, a = {}) {
1228
- var d, r, m, M;
1229
- const i = await W.intersectInECA((t == null ? void 0 : t.route) || []);
1322
+ static async calculateECA(e, t, a = {}) {
1323
+ var r, c, u, m;
1324
+ const i = await W.intersectInECA((e == null ? void 0 : e.route) || []);
1230
1325
  let o = 0, n = 0, s = 0;
1231
- (r = (d = t == null ? void 0 : t.sample) == null ? void 0 : d.wps) == null || r.forEach((l) => {
1232
- l.positionTime = g.utc(l.etd || l.eta).unix();
1326
+ (c = (r = e == null ? void 0 : e.sample) == null ? void 0 : r.wps) == null || c.forEach((f) => {
1327
+ f.positionTime = w.utc(f.etd || f.eta).unix();
1233
1328
  });
1234
- for (const l of i) {
1235
- o += l.distance;
1236
- const b = await W.deadReckoningTime((m = l.waypoints) == null ? void 0 : m.at(0), t.sample.wps), f = await W.deadReckoningTime((M = l.waypoints) == null ? void 0 : M.at(-1), t.sample.wps);
1237
- l.in = b, l.out = f, l.totalHrs = J.roundPrecision((f.positionTime - b.positionTime) / 3600, 3), l.totalDgoCons = J.roundPrecision(e.fo / 24 * l.totalHrs, 3), n += l.totalHrs, s += l.totalDgoCons;
1329
+ for (const f of i) {
1330
+ o += f.distance;
1331
+ const b = await W.deadReckoningTime((u = f.waypoints) == null ? void 0 : u.at(0), e.sample.wps), y = await W.deadReckoningTime((m = f.waypoints) == null ? void 0 : m.at(-1), e.sample.wps);
1332
+ f.in = b, f.out = y, f.totalHrs = _.roundPrecision((y.positionTime - b.positionTime) / 3600, 3), f.totalDgoCons = _.roundPrecision(t.fo / 24 * f.totalHrs, 3), n += f.totalHrs, s += f.totalDgoCons;
1238
1333
  }
1239
- return o = J.roundPrecision(o, 3), n = J.roundPrecision(n, 3), s = J.roundPrecision(s, 3), {
1334
+ return o = _.roundPrecision(o, 3), n = _.roundPrecision(n, 3), s = _.roundPrecision(s, 3), {
1240
1335
  distanceInECA: o,
1241
1336
  hoursInECA: n,
1242
1337
  totalDgoConsInECA: s,
@@ -1248,84 +1343,84 @@ class O {
1248
1343
  * @param speeds
1249
1344
  * @param options
1250
1345
  */
1251
- static async mergeSpeeds(t, e = {}) {
1252
- var c, y;
1346
+ static async mergeSpeeds(e, t = {}) {
1347
+ var d, g;
1253
1348
  const a = {
1254
1349
  hours: [],
1255
1350
  wps: [],
1256
1351
  days: []
1257
- }, i = t.reduce((h, u) => h + u.distance, 0), o = t.reduce((h, u) => {
1258
- var I;
1259
- return h + (((I = u.extend) == null ? void 0 : I.distanceInECA) || 0);
1260
- }, 0), n = t.reduce((h, u) => h + u.totalHrs, 0), s = t.reduce((h, u) => {
1261
- var I;
1262
- return h + (((I = u.extend) == null ? void 0 : I.hoursInECA) || 0);
1263
- }, 0), d = t.reduce((h, u) => {
1264
- var I;
1265
- return h + (((I = u.extend) == null ? void 0 : I.totalDgoConsInECA) || 0);
1266
- }, 0), r = t.reduce((h, u) => h + u.wxFactor * u.totalHrs / n, 0), m = t.reduce((h, u) => h + u.cFactor * u.totalHrs / n, 0), M = t.reduce((h, u) => h + u.totalFoCons, 0), l = t.reduce((h, u) => h + u.totalDgoCons, 0), b = t.reduce((h, u) => h + u.cost.total, 0), f = t.reduce((h, u) => h + u.cost.hire, 0), C = t.reduce((h, u) => h + u.cost.bunker, 0), S = [], p = [];
1267
- let w;
1268
- for (const h of t) {
1269
- p.push(...((c = h.extend) == null ? void 0 : c.eca) || []);
1270
- const u = h.sample.hours, I = h.sample.wps, k = h.sample.days, D = u.at(0);
1271
- w && (D.distanceFromPrevious = w.distanceFromPrevious, D.distanceFromStart = w.distanceFromStart, u.forEach((T, N) => {
1272
- N && (T.distanceFromStart = T.distanceFromStart + w.distanceFromStart);
1273
- }), I.at(0).distanceFromPrevious = w.distanceFromPrevious, I.at(0).distanceFromStart = w.distanceFromStart, I.forEach((T, N) => {
1274
- N && (T.distanceFromStart = T.distanceFromStart + w.distanceFromStart);
1275
- }), k.at(0).distanceFromPrevious = w.distanceFromPrevious, k.at(0).distanceFromStart = w.distanceFromStart, k.forEach((T, N) => {
1276
- N && (T.distanceFromStart = T.distanceFromStart + w.distanceFromStart);
1277
- })), D.cp = h.cost.cp;
1278
- const Y = [h.etd, h.eta], j = S.findIndex((T) => T.id === D.cp.id);
1279
- j === -1 ? (D.cp.segment = [Y], S.push(D.cp)) : S[j].segment.push(Y), u.forEach((T) => {
1280
- var P;
1281
- ((P = a.hours) == null ? void 0 : P.findIndex((R) => R.eta === T.eta)) === -1 && a.hours.push(T);
1282
- }), I.forEach((T) => {
1283
- var P;
1284
- ((P = a.wps) == null ? void 0 : P.findIndex((R) => R.eta === T.eta)) === -1 && a.wps.push(T);
1285
- }), k.forEach((T) => {
1286
- var P;
1287
- ((P = a == null ? void 0 : a.days) == null ? void 0 : P.findIndex((R) => R.eta === T.eta)) === -1 && a.days.push(T);
1352
+ }, i = e.reduce((l, h) => l + h.distance, 0), o = e.reduce((l, h) => {
1353
+ var k;
1354
+ return l + (((k = h.extend) == null ? void 0 : k.distanceInECA) || 0);
1355
+ }, 0), n = e.reduce((l, h) => l + h.totalHrs, 0), s = e.reduce((l, h) => {
1356
+ var k;
1357
+ return l + (((k = h.extend) == null ? void 0 : k.hoursInECA) || 0);
1358
+ }, 0), r = e.reduce((l, h) => {
1359
+ var k;
1360
+ return l + (((k = h.extend) == null ? void 0 : k.totalDgoConsInECA) || 0);
1361
+ }, 0), c = e.reduce((l, h) => l + h.wxFactor * h.totalHrs / n, 0), u = e.reduce((l, h) => l + h.cFactor * h.totalHrs / n, 0), m = e.reduce((l, h) => l + h.totalFoCons, 0), f = e.reduce((l, h) => l + h.totalDgoCons, 0), b = e.reduce((l, h) => l + h.cost.total, 0), y = e.reduce((l, h) => l + h.cost.hire, 0), F = e.reduce((l, h) => l + h.cost.bunker, 0), I = [], p = [];
1362
+ let v;
1363
+ for (const l of e) {
1364
+ p.push(...((d = l.extend) == null ? void 0 : d.eca) || []);
1365
+ const h = l.sample.hours, k = l.sample.wps, S = l.sample.days, D = h.at(0);
1366
+ v && (D.distanceFromPrevious = v.distanceFromPrevious, D.distanceFromStart = v.distanceFromStart, h.forEach((x, T) => {
1367
+ T && (x.distanceFromStart = x.distanceFromStart + v.distanceFromStart);
1368
+ }), k.at(0).distanceFromPrevious = v.distanceFromPrevious, k.at(0).distanceFromStart = v.distanceFromStart, k.forEach((x, T) => {
1369
+ T && (x.distanceFromStart = x.distanceFromStart + v.distanceFromStart);
1370
+ }), S.at(0).distanceFromPrevious = v.distanceFromPrevious, S.at(0).distanceFromStart = v.distanceFromStart, S.forEach((x, T) => {
1371
+ T && (x.distanceFromStart = x.distanceFromStart + v.distanceFromStart);
1372
+ })), D.cp = l.cost.cp;
1373
+ const P = [l.etd, l.eta], N = I.findIndex((x) => x.id === D.cp.id);
1374
+ N === -1 ? (D.cp.segment = [P], I.push(D.cp)) : I[N].segment.push(P), h.forEach((x) => {
1375
+ var q;
1376
+ ((q = a.hours) == null ? void 0 : q.findIndex((R) => R.eta === x.eta)) === -1 && a.hours.push(x);
1377
+ }), k.forEach((x) => {
1378
+ var q;
1379
+ ((q = a.wps) == null ? void 0 : q.findIndex((R) => R.eta === x.eta)) === -1 && a.wps.push(x);
1380
+ }), S.forEach((x) => {
1381
+ var q;
1382
+ ((q = a == null ? void 0 : a.days) == null ? void 0 : q.findIndex((R) => R.eta === x.eta)) === -1 && a.days.push(x);
1288
1383
  });
1289
- const A = (y = a.wps) == null ? void 0 : y.findIndex((T) => T.eta === D.eta);
1290
- A === -1 ? a.wps.push(D) : a.wps[A] = D, w = u.at(-1);
1384
+ const A = (g = a.wps) == null ? void 0 : g.findIndex((x) => x.eta === D.eta);
1385
+ A === -1 ? a.wps.push(D) : a.wps[A] = D, v = h.at(-1);
1291
1386
  }
1292
- return a.wps.sort((h, u) => {
1293
- g(h.etd).unix() - g(u.etd).unix();
1294
- }), a.wps.forEach((h, u) => {
1295
- const I = a.wps[u - 1];
1296
- if (I) {
1297
- const k = h.distanceFromStart - (I.distanceFromStart || 0), D = g(h.eta || h.etd).diff(g(I.etd || I.eta), "hour", !0), Y = Math.round(k / D * 100) / 100;
1298
- h.avgSpd = Y;
1299
- const j = W.calculateBearing(I, h);
1300
- I.bearing = j;
1387
+ return a.wps.sort((l, h) => {
1388
+ w(l.etd).unix() - w(h.etd).unix();
1389
+ }), a.wps.forEach((l, h) => {
1390
+ const k = a.wps[h - 1];
1391
+ if (k) {
1392
+ const S = l.distanceFromStart - (k.distanceFromStart || 0), D = w(l.eta || l.etd).diff(w(k.etd || k.eta), "hour", !0), P = Math.round(S / D * 100) / 100;
1393
+ l.avgSpd = P;
1394
+ const N = W.calculateBearing(k, l);
1395
+ k.bearing = N;
1301
1396
  }
1302
1397
  }), {
1303
1398
  sample: a,
1304
- etd: t.at(0).etd,
1305
- eta: t.at(-1).eta,
1306
- from: t.at(0).from,
1307
- to: t.at(-1).to,
1308
- v0: t.at(0).v0,
1399
+ etd: e.at(0).etd,
1400
+ eta: e.at(-1).eta,
1401
+ from: e.at(0).from,
1402
+ to: e.at(-1).to,
1403
+ v0: e.at(0).v0,
1309
1404
  label: "Combined",
1310
1405
  distance: Math.round(i * 1e3) / 1e3,
1311
1406
  totalHrs: Math.round(n * 1e3) / 1e3,
1312
1407
  avgSpeed: Math.round(i / n * 1e3) / 1e3,
1313
- wxFactor: Math.round(r * 1e3) / 1e3,
1314
- cFactor: Math.round(m * 1e3) / 1e3,
1315
- totalFoCons: Math.round(M * 1e3) / 1e3,
1316
- totalDgoCons: Math.round(l * 1e3) / 1e3,
1408
+ wxFactor: Math.round(c * 1e3) / 1e3,
1409
+ cFactor: Math.round(u * 1e3) / 1e3,
1410
+ totalFoCons: Math.round(m * 1e3) / 1e3,
1411
+ totalDgoCons: Math.round(f * 1e3) / 1e3,
1317
1412
  cost: {
1318
1413
  total: Math.round(b * 1e3) / 1e3,
1319
- hire: Math.round(f * 1e3) / 1e3,
1320
- bunker: Math.round(C * 1e3) / 1e3
1414
+ hire: Math.round(y * 1e3) / 1e3,
1415
+ bunker: Math.round(F * 1e3) / 1e3
1321
1416
  },
1322
1417
  extend: {
1323
- cps: S,
1418
+ cps: I,
1324
1419
  eca: p,
1325
1420
  distanceInECA: Math.round(o * 1e3) / 1e3,
1326
1421
  hoursInECA: Math.round(s * 1e3) / 1e3,
1327
- totalDgoConsInECA: Math.round(d * 1e3) / 1e3,
1328
- speeds: t
1422
+ totalDgoConsInECA: Math.round(r * 1e3) / 1e3,
1423
+ speeds: e
1329
1424
  }
1330
1425
  };
1331
1426
  }
@@ -1333,14 +1428,14 @@ class O {
1333
1428
  export {
1334
1429
  st as AISImpl,
1335
1430
  yt as AlertHelper,
1336
- mt as AlertLevel,
1337
- xt as HifleetImpl,
1338
- gt as LoadCondition,
1339
- Nt as MyShipImpl,
1340
- Et as MyVesselImpl,
1341
- jt as ShipxyImpl,
1431
+ ft as AlertLevel,
1432
+ Et as HifleetImpl,
1433
+ bt as LoadCondition,
1434
+ Tt as MyShipImpl,
1435
+ jt as MyVesselImpl,
1436
+ Nt as ShipxyImpl,
1342
1437
  O as SpeedHelper,
1343
- wt as SpeedLabel,
1344
- bt as VesselTag,
1345
- Tt as alertHelper
1438
+ vt as SpeedLabel,
1439
+ gt as VesselTag,
1440
+ xt as alertHelper
1346
1441
  };