@idm-plugin/vessel 1.5.7 → 1.5.9

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