@idm-plugin/meteo2 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  var T = Object.defineProperty;
2
- var F = (_, e, s) => e in _ ? T(_, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : _[e] = s;
3
- var y = (_, e, s) => (F(_, typeof e != "symbol" ? e + "" : e, s), s);
2
+ var F = (d, e, s) => e in d ? T(d, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : d[e] = s;
3
+ var y = (d, e, s) => (F(d, typeof e != "symbol" ? e + "" : e, s), s);
4
4
  import D from "@log4js-node/log4js-api";
5
- import f from "moment";
5
+ import l from "moment";
6
6
  import I from "got";
7
7
  import { fetchWeatherApi as O } from "openmeteo";
8
8
  let u;
@@ -11,7 +11,7 @@ try {
11
11
  } catch {
12
12
  } finally {
13
13
  }
14
- var U = /* @__PURE__ */ ((_) => (_.Arome = "arome", _.IconEU = "iconEu", _.GFS = "gfs", _.GFSWave = "gfsWave", _.NamConus = "namConus", _.NamHawaii = "namHawaii", _.NamAlaska = "namAlaska", _.Geos5 = "geos5", _))(U || {});
14
+ var U = /* @__PURE__ */ ((d) => (d.Arome = "arome", d.IconEU = "iconEu", d.GFS = "gfs", d.GFSWave = "gfsWave", d.NamConus = "namConus", d.NamHawaii = "namHawaii", d.NamAlaska = "namAlaska", d.Geos5 = "geos5", d))(U || {});
15
15
  class W {
16
16
  /**
17
17
  * 点查海洋气象要素(全量)
@@ -22,9 +22,9 @@ class W {
22
22
  * @param source
23
23
  * @param options
24
24
  */
25
- static async queryPointMeteo(e, s, t, o = !1, a = "", l = {}) {
25
+ static async queryPointMeteo(e, s, t, o = !1, a = "", f = {}) {
26
26
  typeof t == "number" && (t = t < 1e12 ? t * 1e3 : t);
27
- const c = f(t), r = {
27
+ const c = l(t), r = {
28
28
  searchParams: {
29
29
  lng: e,
30
30
  lat: s,
@@ -33,15 +33,15 @@ class W {
33
33
  source: a == null ? void 0 : a.toLowerCase()
34
34
  },
35
35
  timeout: 3e4
36
- }, h = f(), n = h.valueOf();
37
- c.isBefore(h.subtract(1, "month")) && (u == null || u.warn("[%s] get history meteo on %s: %j", l.requestId, c.format(), r));
38
- const w = "https://aod4idm.idmwx.com/api/ocean/point", i = await I.get(w, r).json(), d = f().valueOf();
39
- if (u == null || u.info("[%s] get meteo(cost: %d ms) from %s with options: %j", l.requestId, d - n, w, r), (i == null ? void 0 : i.code) === 0)
36
+ }, h = l(), n = h.valueOf();
37
+ c.isBefore(h.subtract(1, "month")) && (u == null || u.warn("[%s] get history meteo on %s: %j", f.requestId, c.format(), r));
38
+ const w = "https://aod4idm.idmwx.com/api/ocean/point", i = await I.get(w, r).json(), _ = l().valueOf();
39
+ if (u == null || u.info("[%s] get meteo(cost: %d ms) from %s with options: %j", f.requestId, _ - n, w, r), (i == null ? void 0 : i.code) === 0)
40
40
  return {
41
41
  ...i.data,
42
42
  source: a
43
43
  };
44
- u == null || u.warn("[%s] get meteo failed: %j", l.requestId, i);
44
+ u == null || u.warn("[%s] get meteo failed: %j", f.requestId, i);
45
45
  }
46
46
  /**
47
47
  * 点查海洋气象要素(指定要素组合)
@@ -57,9 +57,9 @@ class W {
57
57
  * @param source
58
58
  * @param options
59
59
  */
60
- static async queryPointFactor(e, s, t, o = "wind,wave,current,watertemp,visibility", a = "", l = {}) {
60
+ static async queryPointFactor(e, s, t, o = "wind,wave,current,watertemp,visibility", a = "", f = {}) {
61
61
  typeof t == "number" && (t = t < 1e12 ? t * 1e3 : t);
62
- const c = f(t), r = {
62
+ const c = l(t), r = {
63
63
  searchParams: {
64
64
  lng: e,
65
65
  lat: s,
@@ -68,24 +68,24 @@ class W {
68
68
  source: a == null ? void 0 : a.toLowerCase()
69
69
  },
70
70
  timeout: 3e4
71
- }, h = f(), n = h.valueOf();
72
- c.isBefore(h.subtract(1, "month")) && (u == null || u.warn("[%s] get history factors on %s: %j", l.requestId, c.format(), r));
73
- const w = "https://aod4idm.idmwx.com/api/ocean/factor", i = await I.get(w, r).json(), d = f().valueOf();
74
- if (u == null || u.info("[%s] get factors(cost: %d ms) from %s with options: %j", l.requestId, d - n, w, r), (i == null ? void 0 : i.code) === 0)
71
+ }, h = l(), n = h.valueOf();
72
+ c.isBefore(h.subtract(1, "month")) && (u == null || u.warn("[%s] get history factors on %s: %j", f.requestId, c.format(), r));
73
+ const w = "https://aod4idm.idmwx.com/api/ocean/factor", i = await I.get(w, r).json(), _ = l().valueOf();
74
+ if (u == null || u.info("[%s] get factors(cost: %d ms) from %s with options: %j", f.requestId, _ - n, w, r), (i == null ? void 0 : i.code) === 0)
75
75
  return {
76
76
  ...i.data,
77
77
  source: a
78
78
  };
79
- u == null || u.warn("[%s] get factors failed: %j", l.requestId, i);
79
+ u == null || u.warn("[%s] get factors failed: %j", f.requestId, i);
80
80
  }
81
81
  /**
82
82
  * @see https://api.windy.com/point-forecast/docs
83
83
  * @param key
84
84
  */
85
85
  static async queryWindyPointForecast(e, s, t, o = {}) {
86
- const a = "https://api.windy.com/api/point-forecast/v2", l = [];
86
+ const a = "https://api.windy.com/api/point-forecast/v2", f = [];
87
87
  try {
88
- let c = f().valueOf();
88
+ let c = l().valueOf();
89
89
  const r = await I.post(a, {
90
90
  headers: {
91
91
  "Content-Type": "application/json"
@@ -115,7 +115,7 @@ class W {
115
115
  levels: ["surface"]
116
116
  }
117
117
  }).json();
118
- let h = f().valueOf();
118
+ let h = l().valueOf();
119
119
  u == null || u.info("[%s] get gfs-factors(cost: %d ms) from %s", o.requestId, h - c, a), c = h;
120
120
  const n = await I.post(a, {
121
121
  headers: {
@@ -130,11 +130,11 @@ class W {
130
130
  levels: ["surface"]
131
131
  }
132
132
  }).json();
133
- h = f().valueOf(), u == null || u.info("[%s] get gfs-wave-factors(cost: %d ms) from %s", o.requestId, h - c, a);
133
+ h = l().valueOf(), u == null || u.info("[%s] get gfs-wave-factors(cost: %d ms) from %s", o.requestId, h - c, a);
134
134
  for (let i = 0; i < r.ts.length; i++) {
135
- const d = this.populateUVFactor(r["wind_u-surface"][i], r["wind_v-surface"][i], !1, o);
136
- d.scale = this.calculateBeaufortWindForceScale(d.speed), l.push({
137
- utc: f(r.ts[i]).utc().format(),
135
+ const _ = this.populateUVFactor(r["wind_u-surface"][i], r["wind_v-surface"][i], !1, o);
136
+ _.scale = this.calculateBeaufortWindForceScale(_.speed), f.push({
137
+ utc: l(r.ts[i]).utc().format(),
138
138
  temp: r["temp-surface"][i] ? Math.round((r["temp-surface"][i] - 273.15) * 100) / 100 : void 0,
139
139
  dp_temp: r["dewpoint-surface"][i] ? Math.round((r["dewpoint-surface"][i] - 273.15) * 100) / 100 : void 0,
140
140
  precip: {
@@ -142,7 +142,7 @@ class W {
142
142
  inter3hSnow: r["past3hsnowprecip-surface"][i] ? Math.round(r["past3hsnowprecip-surface"][i] * 1e3 * 1e3) / 1e3 : 0,
143
143
  inter3hConv: r["past3hconvprecip-surface"][i] ? Math.round(r["past3hconvprecip-surface"][i] * 1e3 * 1e3) / 1e3 : 0
144
144
  },
145
- wind: d,
145
+ wind: _,
146
146
  gusts: {
147
147
  speed: Math.round((r["gust-surface"][i] || 0) * 100) / 100,
148
148
  kts: this.convertMs2Kts(r["gust-surface"][i])
@@ -157,25 +157,25 @@ class W {
157
157
  }
158
158
  const w = [];
159
159
  for (let i = 0; i < n.ts.length; i++) {
160
- const d = this.calculateDouglasScale(n["waves_height-surface"][i], n["waves_direction-surface"][i], n["waves_period-surface"][i]), R = this.calculateDouglasScale(n["wwaves_height-surface"][i], n["wwaves_direction-surface"][i], n["wwaves_period-surface"][i]), p = this.calculateDouglasScale(n["swell1_height-surface"][i], n["swell1_direction-surface"][i], n["swell1_period-surface"][i]), E = this.calculateDouglasScale(n["swell2_height-surface"][i], n["swell2_direction-surface"][i], n["swell2_period-surface"][i]);
160
+ const _ = this.calculateDouglasScale(n["waves_height-surface"][i], n["waves_direction-surface"][i], n["waves_period-surface"][i]), R = this.calculateDouglasScale(n["wwaves_height-surface"][i], n["wwaves_direction-surface"][i], n["wwaves_period-surface"][i]), p = this.calculateDouglasScale(n["swell1_height-surface"][i], n["swell1_direction-surface"][i], n["swell1_period-surface"][i]), E = this.calculateDouglasScale(n["swell2_height-surface"][i], n["swell2_direction-surface"][i], n["swell2_period-surface"][i]);
161
161
  w.push({
162
- utc: f(n.ts[i]).utc().format(),
162
+ utc: l(n.ts[i]).utc().format(),
163
163
  wave: {
164
- sig: d,
164
+ sig: _,
165
165
  wd: R,
166
166
  swell: p,
167
167
  swell2: E
168
168
  }
169
169
  });
170
170
  }
171
- for (const i of l) {
172
- const d = w.find((R) => R.utc === i.utc);
173
- i.wave = d == null ? void 0 : d.wave;
171
+ for (const i of f) {
172
+ const _ = w.find((R) => R.utc === i.utc);
173
+ i.wave = _ == null ? void 0 : _.wave;
174
174
  }
175
175
  } catch (c) {
176
176
  u.warn("[%s] get-gfs-factor failed: %s", o.requestId, c);
177
177
  }
178
- return l;
178
+ return f;
179
179
  }
180
180
  /**
181
181
  * 填充UV向量
@@ -185,11 +185,11 @@ class W {
185
185
  * @param options
186
186
  */
187
187
  static populateUVFactor(e, s, t = !1, o = {}) {
188
- const a = Math.round(Math.sqrt(Math.pow(e, 2) + Math.pow(s, 2)) * 1e4) / 1e4, { degree: l, direction: c } = this.calculateUVDirection(e, s, t, o), r = this.convertMs2Kts(a);
188
+ const a = Math.round(Math.sqrt(Math.pow(e, 2) + Math.pow(s, 2)) * 1e4) / 1e4, { degree: f, direction: c } = this.calculateUVDirection(e, s, t, o), r = this.convertMs2Kts(a);
189
189
  return {
190
190
  speed: a,
191
191
  kts: r,
192
- degree: l,
192
+ degree: f,
193
193
  direction: c,
194
194
  eastward: Math.round(e * 1e4) / 1e4,
195
195
  northward: Math.round(s * 1e4) / 1e4
@@ -208,11 +208,11 @@ class W {
208
208
  static calculateUVDirection(e, s, t = !1, o = {}) {
209
209
  let a = Math.atan2(e, s) + Math.PI;
210
210
  t && (a = Math.atan2(e, s));
211
- const l = this.convert2Direction(a);
211
+ const f = this.convert2Direction(a);
212
212
  return a = Math.round(a / (2 * Math.PI) * 360 * 1e4) / 1e4, {
213
213
  angle: a,
214
214
  degree: a,
215
- direction: l
215
+ direction: f
216
216
  };
217
217
  }
218
218
  /**
@@ -288,8 +288,8 @@ class k {
288
288
  });
289
289
  y(this, "MARINE_VARIABLES", {
290
290
  DAILY: "wave_height_max,wave_direction_dominant,wave_period_max,wind_wave_height_max,wind_wave_direction_dominant,wind_wave_period_max,wind_wave_peak_period_max,swell_wave_height_max,swell_wave_direction_dominant,swell_wave_period_max,swell_wave_peak_period_max",
291
- HOURLY: "wave_height,wave_direction,wave_period,wind_wave_height,wind_wave_direction,wind_wave_period,wind_wave_peak_period,swell_wave_height,swell_wave_direction,swell_wave_period,swell_wave_peak_period,ocean_current_velocity,ocean_current_direction",
292
- CURRENT: "wave_height,wave_direction,wave_period,wind_wave_height,wind_wave_direction,wind_wave_period,wind_wave_peak_period,swell_wave_height,swell_wave_direction,swell_wave_period,swell_wave_peak_period,ocean_current_velocity,ocean_current_direction"
291
+ HOURLY: "wave_height,wave_direction,wave_period,wind_wave_height,wind_wave_direction,wind_wave_period,wind_wave_peak_period,swell_wave_height,swell_wave_direction,swell_wave_period,swell_wave_peak_period,ocean_current_velocity,ocean_current_direction,sea_level_height_msl,sea_surface_temperature",
292
+ CURRENT: "wave_height,wave_direction,wave_period,wind_wave_height,wind_wave_direction,wind_wave_period,wind_wave_peak_period,swell_wave_height,swell_wave_direction,swell_wave_period,swell_wave_peak_period,ocean_current_velocity,ocean_current_direction,sea_level_height_msl,sea_surface_temperature"
293
293
  });
294
294
  this.apikey = e || "smE3JnDLHy3TizVv", this.debug = s;
295
295
  }
@@ -297,59 +297,59 @@ class k {
297
297
  return Array.from({ length: (s - e) / t }, (o, a) => e + a * t);
298
298
  }
299
299
  async weatherForecast(e, s = {}) {
300
- const t = f(), o = await O(e.url, e);
300
+ const t = l(), o = await O(e.url, e);
301
301
  delete e.apikey;
302
- const a = f();
302
+ const a = l();
303
303
  return this.debug && S.info("[%s] fetch weather api (%s) cost: %d ms", s.requestId, e.url, a.diff(t, "ms")), this.parseWeatherData(o, e, s);
304
304
  }
305
305
  async marineForecast(e, s = {}) {
306
- const t = f(), o = await O(e.url, e);
306
+ const t = l(), o = await O(e.url, e);
307
307
  delete e.apikey;
308
- const a = f();
308
+ const a = l();
309
309
  return this.debug && S.info("[%s] fetch marine api (%s) cost: %d ms", s.requestId, e.url, a.diff(t, "ms")), this.parseWeatherData(o, e, s);
310
310
  }
311
311
  async parseWeatherData(e, s, t = {}) {
312
- var l, c, r, h, n, w;
312
+ var f, c, r, h, n, w;
313
313
  const o = [], a = Math.pow(10, t.precision || 6);
314
314
  for (const i of e) {
315
- const d = i.utcOffsetSeconds(), R = i.current(), p = i.hourly(), E = i.daily(), A = {};
315
+ const _ = i.utcOffsetSeconds(), R = i.current(), p = i.hourly(), E = i.daily(), A = {};
316
316
  if (R) {
317
- const N = f();
317
+ const N = l();
318
318
  A.current = {
319
- time: f.unix(Number(R.time()) + d).utc().format()
319
+ time: l.unix(Number(R.time()) + _).utc().format()
320
320
  };
321
321
  for (let m = 0; m < R.variablesLength(); m++) {
322
322
  const v = R.variables(m).value();
323
323
  A.current[s.current[m]] = Number.isNaN(v) ? v : Math.round(v * a) / a;
324
324
  }
325
- const M = f();
325
+ const M = l();
326
326
  this.debug && S.info("[%s] fetch current variables cost: %d ms", t.requestId, M.diff(N, "ms"));
327
327
  }
328
328
  if (p) {
329
- const N = f(), M = f.unix(Number(p.time()) + d);
329
+ const N = l(), M = l.unix(Number(p.time()) + _);
330
330
  A.hourly = {
331
331
  date: M.utc().format(),
332
- time: this.range(Number(p.time()), Number(p.timeEnd()), p.interval()).map((v) => f.unix(v + d).diff(M, "h"))
332
+ time: this.range(Number(p.time()), Number(p.timeEnd()), p.interval()).map((v) => l.unix(v + _).diff(M, "h"))
333
333
  };
334
334
  for (let v = 0; v < p.variablesLength(); v++) {
335
- const L = (r = (c = (l = p.variables(v).valuesArray()) == null ? void 0 : l.toString()) == null ? void 0 : c.split(",")) == null ? void 0 : r.map((b) => Number.isNaN(b) ? b : Math.round(Number(b) * a) / a);
335
+ const L = (r = (c = (f = p.variables(v).valuesArray()) == null ? void 0 : f.toString()) == null ? void 0 : c.split(",")) == null ? void 0 : r.map((b) => Number.isNaN(b) ? b : Math.round(Number(b) * a) / a);
336
336
  A.hourly[s.hourly[v]] = L;
337
337
  }
338
- const m = f();
338
+ const m = l();
339
339
  this.debug && S.info("[%s] fetch hourly variables cost: %d ms", t.requestId, m.diff(N, "ms"));
340
340
  }
341
341
  if (E) {
342
- const N = f();
342
+ const N = l();
343
343
  A.daily = {
344
344
  time: this.range(Number(E.time()), Number(E.timeEnd()), E.interval()).map(
345
- (m) => f.unix(m + d).utc().format()
345
+ (m) => l.unix(m + _).utc().format()
346
346
  )
347
347
  };
348
348
  for (let m = 0; m < E.variablesLength(); m++) {
349
349
  const v = (w = (n = (h = E.variables(m).valuesArray()) == null ? void 0 : h.toString()) == null ? void 0 : n.split(",")) == null ? void 0 : w.map((L) => Number.isNaN(L) ? L : Math.round(Number(L) * a) / a);
350
350
  A.daily[s.daily[m]] = v;
351
351
  }
352
- const M = f();
352
+ const M = l();
353
353
  this.debug && S.info("[%s] fetch daily variables cost: %d ms", t.requestId, M.diff(N, "ms"));
354
354
  }
355
355
  o.push(A);
@@ -365,15 +365,15 @@ class k {
365
365
  */
366
366
  prepare(e, s, t, o = {}) {
367
367
  e ? (t.start_date = e.utc().set({ minute: 0, second: 0, millisecond: 0 }).format("YYYY-MM-DD"), t.end_date = e.clone().add(o.forecastDays ?? 1, "d").utc().format("YYYY-MM-DD")) : t.forecast_days = o.forecastDays;
368
- const a = f().subtract(1, "d");
368
+ const a = l().subtract(1, "d");
369
369
  return s ? (t.url = o.selfHosted ? this.SELF_MARINE_FORECAST_URL : this.MARINE_FORECAST_URL, e != null && e.isBefore(a) && (t.url = this.MARINE_FORECAST_URL)) : (t.url = o.selfHosted ? this.SELF_FORECAST_URL : this.FORECAST_URL, e != null && e.isBefore(a) && (t.url = this.HISTORY_FORECAST_URL)), t;
370
370
  }
371
- async spotForecast(e, s, t, o = !0, a = !0, l = !1, c = {
371
+ async spotForecast(e, s, t, o = !0, a = !0, f = !1, c = {
372
372
  forecastDays: 1,
373
373
  precision: 6,
374
374
  selfHosted: !0
375
375
  }) {
376
- var i, d, R, p, E, A, N, M;
376
+ var i, _, R, p, E, A, N, M;
377
377
  const r = {
378
378
  apikey: this.apikey,
379
379
  latitude: e,
@@ -383,7 +383,7 @@ class k {
383
383
  models: ((i = c.weatherModels) == null ? void 0 : i.split(",")) || ["best_match"],
384
384
  timezone: "auto"
385
385
  };
386
- a && (r.daily = o ? ((d = this.WEATHER_VARIABLES.SIMPLE.DAILY) == null ? void 0 : d.split(",")) || [] : ((R = this.WEATHER_VARIABLES.NORMAL.DAILY) == null ? void 0 : R.split(",")) || []), t || (c.forecastDays = c.forecastDays || 1, r.current = o ? ((p = this.WEATHER_VARIABLES.SIMPLE.CURRENT) == null ? void 0 : p.split(",")) || [] : ((E = this.WEATHER_VARIABLES.NORMAL.CURRENT) == null ? void 0 : E.split(",")) || []), l && (r.hourly = o ? ((A = this.WEATHER_VARIABLES.SIMPLE.HOURLY) == null ? void 0 : A.split(",")) || [] : ((N = this.WEATHER_VARIABLES.NORMAL.HOURLY) == null ? void 0 : N.split(",")) || []), this.prepare(t, !1, r, c);
386
+ a && (r.daily = o ? ((_ = this.WEATHER_VARIABLES.SIMPLE.DAILY) == null ? void 0 : _.split(",")) || [] : ((R = this.WEATHER_VARIABLES.NORMAL.DAILY) == null ? void 0 : R.split(",")) || []), t || (c.forecastDays = c.forecastDays || 1, r.current = o ? ((p = this.WEATHER_VARIABLES.SIMPLE.CURRENT) == null ? void 0 : p.split(",")) || [] : ((E = this.WEATHER_VARIABLES.NORMAL.CURRENT) == null ? void 0 : E.split(",")) || []), f && (r.hourly = o ? ((A = this.WEATHER_VARIABLES.SIMPLE.HOURLY) == null ? void 0 : A.split(",")) || [] : ((N = this.WEATHER_VARIABLES.NORMAL.HOURLY) == null ? void 0 : N.split(",")) || []), this.prepare(t, !1, r, c);
387
387
  const h = await this.weatherForecast(r, c), n = {
388
388
  apikey: this.apikey,
389
389
  latitude: e,
@@ -393,7 +393,7 @@ class k {
393
393
  wind_speed_unit: "kn",
394
394
  models: ((M = c.marineModels) == null ? void 0 : M.split(",")) || ["best_match"]
395
395
  };
396
- a && (n.daily = this.MARINE_VARIABLES.DAILY.split(",")), t || (c.forecastDays = c.forecastDays || 1, n.current = this.MARINE_VARIABLES.CURRENT.split(",")), l && (n.hourly = this.MARINE_VARIABLES.HOURLY.split(",")), this.prepare(t, !0, n, c);
396
+ a && (n.daily = this.MARINE_VARIABLES.DAILY.split(",")), t || (c.forecastDays = c.forecastDays || 1, n.current = this.MARINE_VARIABLES.CURRENT.split(",")), f && (n.hourly = this.MARINE_VARIABLES.HOURLY.split(",")), this.prepare(t, !0, n, c);
397
397
  const w = await this.marineForecast(n, c);
398
398
  return { weather: h, marine: w };
399
399
  }
@@ -1 +1 @@
1
- (function(_,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("@log4js-node/log4js-api"),require("moment"),require("got"),require("openmeteo")):typeof define=="function"&&define.amd?define(["exports","@log4js-node/log4js-api","moment","got","openmeteo"],w):(_=typeof globalThis<"u"?globalThis:_||self,w(_["idm-plugin-rabbitmq"]={},_["@log4js-node/log4js-api"],_.moment,_.got,_.openmeteo))})(this,function(_,w,o,O,D){"use strict";var H=Object.defineProperty;var g=(_,w,o)=>w in _?H(_,w,{enumerable:!0,configurable:!0,writable:!0,value:o}):_[w]=o;var S=(_,w,o)=>(g(_,typeof w!="symbol"?w+"":w,o),o);let f;try{f=w.getLogger("meteo")}catch{}finally{}var F=(p=>(p.Arome="arome",p.IconEU="iconEu",p.GFS="gfs",p.GFSWave="gfsWave",p.NamConus="namConus",p.NamHawaii="namHawaii",p.NamAlaska="namAlaska",p.Geos5="geos5",p))(F||{});class U{static async queryPointMeteo(e,s,t,c=!1,a="",d={}){typeof t=="number"&&(t=t<1e12?t*1e3:t);const n=o(t),r={searchParams:{lng:e,lat:s,ts:n.valueOf(),params:c?"watertemp":void 0,source:a==null?void 0:a.toLowerCase()},timeout:3e4},h=o(),u=h.valueOf();n.isBefore(h.subtract(1,"month"))&&(f==null||f.warn("[%s] get history meteo on %s: %j",d.requestId,n.format(),r));const v="https://aod4idm.idmwx.com/api/ocean/point",i=await O.get(v,r).json(),l=o().valueOf();if(f==null||f.info("[%s] get meteo(cost: %d ms) from %s with options: %j",d.requestId,l-u,v,r),(i==null?void 0:i.code)===0)return{...i.data,source:a};f==null||f.warn("[%s] get meteo failed: %j",d.requestId,i)}static async queryPointFactor(e,s,t,c="wind,wave,current,watertemp,visibility",a="",d={}){typeof t=="number"&&(t=t<1e12?t*1e3:t);const n=o(t),r={searchParams:{lng:e,lat:s,ts:n.valueOf(),params:c,source:a==null?void 0:a.toLowerCase()},timeout:3e4},h=o(),u=h.valueOf();n.isBefore(h.subtract(1,"month"))&&(f==null||f.warn("[%s] get history factors on %s: %j",d.requestId,n.format(),r));const v="https://aod4idm.idmwx.com/api/ocean/factor",i=await O.get(v,r).json(),l=o().valueOf();if(f==null||f.info("[%s] get factors(cost: %d ms) from %s with options: %j",d.requestId,l-u,v,r),(i==null?void 0:i.code)===0)return{...i.data,source:a};f==null||f.warn("[%s] get factors failed: %j",d.requestId,i)}static async queryWindyPointForecast(e,s,t,c={}){const a="https://api.windy.com/api/point-forecast/v2",d=[];try{let n=o().valueOf();const r=await O.post(a,{headers:{"Content-Type":"application/json"},json:{lat:e,lon:s,key:t,model:"gfs",parameters:["temp","dewpoint","precip","convPrecip","snowPrecip","wind","windGust","cape","ptype","lclouds","mclouds","hclouds","rh","gh","pressure"],levels:["surface"]}}).json();let h=o().valueOf();f==null||f.info("[%s] get gfs-factors(cost: %d ms) from %s",c.requestId,h-n,a),n=h;const u=await O.post(a,{headers:{"Content-Type":"application/json"},json:{lat:e,lon:s,key:t,model:"gfsWave",parameters:["waves","windWaves","swell1","swell2"],levels:["surface"]}}).json();h=o().valueOf(),f==null||f.info("[%s] get gfs-wave-factors(cost: %d ms) from %s",c.requestId,h-n,a);for(let i=0;i<r.ts.length;i++){const l=this.populateUVFactor(r["wind_u-surface"][i],r["wind_v-surface"][i],!1,c);l.scale=this.calculateBeaufortWindForceScale(l.speed),d.push({utc:o(r.ts[i]).utc().format(),temp:r["temp-surface"][i]?Math.round((r["temp-surface"][i]-273.15)*100)/100:void 0,dp_temp:r["dewpoint-surface"][i]?Math.round((r["dewpoint-surface"][i]-273.15)*100)/100:void 0,precip:{inter3h:r["past3hprecip-surface"][i]?Math.round(r["past3hprecip-surface"][i]*1e3*1e3)/1e3:0,inter3hSnow:r["past3hsnowprecip-surface"][i]?Math.round(r["past3hsnowprecip-surface"][i]*1e3*1e3)/1e3:0,inter3hConv:r["past3hconvprecip-surface"][i]?Math.round(r["past3hconvprecip-surface"][i]*1e3*1e3)/1e3:0},wind:l,gusts:{speed:Math.round((r["gust-surface"][i]||0)*100)/100,kts:this.convertMs2Kts(r["gust-surface"][i])},lclouds:r["lclouds-surface"][i]?Math.round(r["lclouds-surface"][i]*100)/100:0,mclouds:r["mclouds-surface"][i]?Math.round(r["mclouds-surface"][i]*100)/100:0,hclouds:r["hclouds-surface"][i]?Math.round(r["hclouds-surface"][i]*100)/100:0,rh:r["rh-surface"][i]?Math.round(r["rh-surface"][i]*100)/100:0,gh:r["gh-surface"][i]?Math.round(r["gh-surface"][i]*100)/100:0,pressure:Math.round(r["pressure-surface"][i]/100*100)/100})}const v=[];for(let i=0;i<u.ts.length;i++){const l=this.calculateDouglasScale(u["waves_height-surface"][i],u["waves_direction-surface"][i],u["waves_period-surface"][i]),A=this.calculateDouglasScale(u["wwaves_height-surface"][i],u["wwaves_direction-surface"][i],u["wwaves_period-surface"][i]),R=this.calculateDouglasScale(u["swell1_height-surface"][i],u["swell1_direction-surface"][i],u["swell1_period-surface"][i]),y=this.calculateDouglasScale(u["swell2_height-surface"][i],u["swell2_direction-surface"][i],u["swell2_period-surface"][i]);v.push({utc:o(u.ts[i]).utc().format(),wave:{sig:l,wd:A,swell:R,swell2:y}})}for(const i of d){const l=v.find(A=>A.utc===i.utc);i.wave=l==null?void 0:l.wave}}catch(n){f.warn("[%s] get-gfs-factor failed: %s",c.requestId,n)}return d}static populateUVFactor(e,s,t=!1,c={}){const a=Math.round(Math.sqrt(Math.pow(e,2)+Math.pow(s,2))*1e4)/1e4,{degree:d,direction:n}=this.calculateUVDirection(e,s,t,c),r=this.convertMs2Kts(a);return{speed:a,kts:r,degree:d,direction:n,eastward:Math.round(e*1e4)/1e4,northward:Math.round(s*1e4)/1e4}}static convertMs2Kts(e){return isNaN(e)?0:Math.round(e*3600/1852*1e3)/1e3}static calculateUVDirection(e,s,t=!1,c={}){let a=Math.atan2(e,s)+Math.PI;t&&(a=Math.atan2(e,s));const d=this.convert2Direction(a);return a=Math.round(a/(2*Math.PI)*360*1e4)/1e4,{angle:a,degree:a,direction:d}}static convert2Direction(e){let s="N/A";if(!isNaN(e)){e<0&&(e+=2*Math.PI);const t=Math.PI/16;e<t?s="N":e>=t&&e<3*t?s="NNE":e>=3*t&&e<5*t?s="NE":e>=5*t&&e<7*t?s="ENE":e>=7*t&&e<9*t?s="E":e>=9*t&&e<11*t?s="ESE":e>=11*t&&e<13*t?s="SE":e>=13*t&&e<15*t?s="SSE":e>=15*t&&e<17*t?s="S":e>=17*t&&e<19*t?s="SSW":e>=19*t&&e<21*t?s="SW":e>=21*t&&e<23*t?s="WSW":e>=23*t&&e<25*t?s="W":e>=25*t&&e<27*t?s="WNW":e>=27*t&&e<29*t?s="NW":e>=29*t&&e<31*t?s="NNW":e>=31*t&&e<32*t&&(s="N")}return s}static calculateBeaufortWindForceScale(e){let s=0;return isNaN(e)||(e=Math.round(e*10)/10,e<=.2?s=0:e<=1.5?s=1:e<=3.3?s=2:e<=5.4?s=3:e<=7.9?s=4:e<=10.7?s=5:e<=13.8?s=6:e<=17.1?s=7:e<=20.7?s=8:e<=22.4?s=9:e<=28.4?s=10:e<=32.6?s=11:e>32.6&&(s=12)),s}static calculateDouglasScale(e,s,t){let c="Calm";const a=this.convert2Direction(s/360*2*Math.PI);return isNaN(e)||e<=.1?c="Calm":e<=.5?c="Smooth":e<=1.25?c="Slight":e<=2.5?c="Moderate":e<=4?c="Rough":e<=6?c="VeryRough":e<=9?c="High":e<=14?c="VeryHigh":c="Precipitous",{degree:Math.round(s*100)/100,scale:c,direction:a,height:Math.round(e*1e3)/1e3,period:Math.round(t*100)/100}}}let I;try{I=w.getLogger("open-meteo")}catch{}finally{}class C{constructor(e,s){S(this,"apikey");S(this,"debug");S(this,"FORECAST_URL","https://customer-api.open-meteo.com/v1/forecast");S(this,"SELF_FORECAST_URL","https://meteo2.idmwx.com/v1/forecast");S(this,"HISTORY_FORECAST_URL","https://customer-historical-forecast-api.open-meteo.com/v1/forecast");S(this,"MARINE_FORECAST_URL","https://customer-marine-api.open-meteo.com/v1/marine");S(this,"SELF_MARINE_FORECAST_URL","https://meteo2.idmwx.com/v1/marine");S(this,"WEATHER_VARIABLES",{NORMAL:{DAILY:"weather_code,temperature_2m_max,temperature_2m_min,apparent_temperature_max,apparent_temperature_min,sunrise,sunset,precipitation_sum,precipitation_hours,precipitation_probability_max,wind_speed_10m_max,wind_gusts_10m_max,wind_direction_10m_dominant",HOURLY:"temperature_2m,relative_humidity_2m,dew_point_2m,apparent_temperature,precipitation_probability,precipitation,weather_code,visibility,wind_speed_10m,wind_direction_10m,wind_gusts_10m",CURRENT:"temperature_2m,relative_humidity_2m,apparent_temperature,precipitation,weather_code,wind_speed_10m,wind_direction_10m,wind_gusts_10m"},SIMPLE:{DAILY:"weather_code",HOURLY:"wind_speed_10m,wind_direction_10m,wind_gusts_10m",CURRENT:"wind_speed_10m,wind_direction_10m,wind_gusts_10m"}});S(this,"MARINE_VARIABLES",{DAILY:"wave_height_max,wave_direction_dominant,wave_period_max,wind_wave_height_max,wind_wave_direction_dominant,wind_wave_period_max,wind_wave_peak_period_max,swell_wave_height_max,swell_wave_direction_dominant,swell_wave_period_max,swell_wave_peak_period_max",HOURLY:"wave_height,wave_direction,wave_period,wind_wave_height,wind_wave_direction,wind_wave_period,wind_wave_peak_period,swell_wave_height,swell_wave_direction,swell_wave_period,swell_wave_peak_period,ocean_current_velocity,ocean_current_direction",CURRENT:"wave_height,wave_direction,wave_period,wind_wave_height,wind_wave_direction,wind_wave_period,wind_wave_peak_period,swell_wave_height,swell_wave_direction,swell_wave_period,swell_wave_peak_period,ocean_current_velocity,ocean_current_direction"});this.apikey=e||"smE3JnDLHy3TizVv",this.debug=s}range(e,s,t){return Array.from({length:(s-e)/t},(c,a)=>e+a*t)}async weatherForecast(e,s={}){const t=o(),c=await D.fetchWeatherApi(e.url,e);delete e.apikey;const a=o();return this.debug&&I.info("[%s] fetch weather api (%s) cost: %d ms",s.requestId,e.url,a.diff(t,"ms")),this.parseWeatherData(c,e,s)}async marineForecast(e,s={}){const t=o(),c=await D.fetchWeatherApi(e.url,e);delete e.apikey;const a=o();return this.debug&&I.info("[%s] fetch marine api (%s) cost: %d ms",s.requestId,e.url,a.diff(t,"ms")),this.parseWeatherData(c,e,s)}async parseWeatherData(e,s,t={}){var d,n,r,h,u,v;const c=[],a=Math.pow(10,t.precision||6);for(const i of e){const l=i.utcOffsetSeconds(),A=i.current(),R=i.hourly(),y=i.daily(),M={};if(A){const L=o();M.current={time:o.unix(Number(A.time())+l).utc().format()};for(let m=0;m<A.variablesLength();m++){const E=A.variables(m).value();M.current[s.current[m]]=Number.isNaN(E)?E:Math.round(E*a)/a}const N=o();this.debug&&I.info("[%s] fetch current variables cost: %d ms",t.requestId,N.diff(L,"ms"))}if(R){const L=o(),N=o.unix(Number(R.time())+l);M.hourly={date:N.utc().format(),time:this.range(Number(R.time()),Number(R.timeEnd()),R.interval()).map(E=>o.unix(E+l).diff(N,"h"))};for(let E=0;E<R.variablesLength();E++){const b=(r=(n=(d=R.variables(E).valuesArray())==null?void 0:d.toString())==null?void 0:n.split(","))==null?void 0:r.map(T=>Number.isNaN(T)?T:Math.round(Number(T)*a)/a);M.hourly[s.hourly[E]]=b}const m=o();this.debug&&I.info("[%s] fetch hourly variables cost: %d ms",t.requestId,m.diff(L,"ms"))}if(y){const L=o();M.daily={time:this.range(Number(y.time()),Number(y.timeEnd()),y.interval()).map(m=>o.unix(m+l).utc().format())};for(let m=0;m<y.variablesLength();m++){const E=(v=(u=(h=y.variables(m).valuesArray())==null?void 0:h.toString())==null?void 0:u.split(","))==null?void 0:v.map(b=>Number.isNaN(b)?b:Math.round(Number(b)*a)/a);M.daily[s.daily[m]]=E}const N=o();this.debug&&I.info("[%s] fetch daily variables cost: %d ms",t.requestId,N.diff(L,"ms"))}c.push(M)}return c}prepare(e,s,t,c={}){e?(t.start_date=e.utc().set({minute:0,second:0,millisecond:0}).format("YYYY-MM-DD"),t.end_date=e.clone().add(c.forecastDays??1,"d").utc().format("YYYY-MM-DD")):t.forecast_days=c.forecastDays;const a=o().subtract(1,"d");return s?(t.url=c.selfHosted?this.SELF_MARINE_FORECAST_URL:this.MARINE_FORECAST_URL,e!=null&&e.isBefore(a)&&(t.url=this.MARINE_FORECAST_URL)):(t.url=c.selfHosted?this.SELF_FORECAST_URL:this.FORECAST_URL,e!=null&&e.isBefore(a)&&(t.url=this.HISTORY_FORECAST_URL)),t}async spotForecast(e,s,t,c=!0,a=!0,d=!1,n={forecastDays:1,precision:6,selfHosted:!0}){var i,l,A,R,y,M,L,N;const r={apikey:this.apikey,latitude:e,longitude:s,cell_selection:"sea",wind_speed_unit:"kn",models:((i=n.weatherModels)==null?void 0:i.split(","))||["best_match"],timezone:"auto"};a&&(r.daily=c?((l=this.WEATHER_VARIABLES.SIMPLE.DAILY)==null?void 0:l.split(","))||[]:((A=this.WEATHER_VARIABLES.NORMAL.DAILY)==null?void 0:A.split(","))||[]),t||(n.forecastDays=n.forecastDays||1,r.current=c?((R=this.WEATHER_VARIABLES.SIMPLE.CURRENT)==null?void 0:R.split(","))||[]:((y=this.WEATHER_VARIABLES.NORMAL.CURRENT)==null?void 0:y.split(","))||[]),d&&(r.hourly=c?((M=this.WEATHER_VARIABLES.SIMPLE.HOURLY)==null?void 0:M.split(","))||[]:((L=this.WEATHER_VARIABLES.NORMAL.HOURLY)==null?void 0:L.split(","))||[]),this.prepare(t,!1,r,n);const h=await this.weatherForecast(r,n),u={apikey:this.apikey,latitude:e,longitude:s,cell_selection:"sea",timezone:"auto",wind_speed_unit:"kn",models:((N=n.marineModels)==null?void 0:N.split(","))||["best_match"]};a&&(u.daily=this.MARINE_VARIABLES.DAILY.split(",")),t||(n.forecastDays=n.forecastDays||1,u.current=this.MARINE_VARIABLES.CURRENT.split(",")),d&&(u.hourly=this.MARINE_VARIABLES.HOURLY.split(",")),this.prepare(t,!0,u,n);const v=await this.marineForecast(u,n);return{weather:h,marine:v}}}_.MeteoHelper=U,_.MeteoHelper2=C,_.WindyModel=F,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
1
+ (function(_,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("@log4js-node/log4js-api"),require("moment"),require("got"),require("openmeteo")):typeof define=="function"&&define.amd?define(["exports","@log4js-node/log4js-api","moment","got","openmeteo"],w):(_=typeof globalThis<"u"?globalThis:_||self,w(_["idm-plugin-rabbitmq"]={},_["@log4js-node/log4js-api"],_.moment,_.got,_.openmeteo))})(this,function(_,w,o,O,D){"use strict";var C=Object.defineProperty;var H=(_,w,o)=>w in _?C(_,w,{enumerable:!0,configurable:!0,writable:!0,value:o}):_[w]=o;var S=(_,w,o)=>(H(_,typeof w!="symbol"?w+"":w,o),o);let f;try{f=w.getLogger("meteo")}catch{}finally{}var F=(p=>(p.Arome="arome",p.IconEU="iconEu",p.GFS="gfs",p.GFSWave="gfsWave",p.NamConus="namConus",p.NamHawaii="namHawaii",p.NamAlaska="namAlaska",p.Geos5="geos5",p))(F||{});class U{static async queryPointMeteo(e,s,t,c=!1,a="",l={}){typeof t=="number"&&(t=t<1e12?t*1e3:t);const n=o(t),r={searchParams:{lng:e,lat:s,ts:n.valueOf(),params:c?"watertemp":void 0,source:a==null?void 0:a.toLowerCase()},timeout:3e4},h=o(),u=h.valueOf();n.isBefore(h.subtract(1,"month"))&&(f==null||f.warn("[%s] get history meteo on %s: %j",l.requestId,n.format(),r));const v="https://aod4idm.idmwx.com/api/ocean/point",i=await O.get(v,r).json(),d=o().valueOf();if(f==null||f.info("[%s] get meteo(cost: %d ms) from %s with options: %j",l.requestId,d-u,v,r),(i==null?void 0:i.code)===0)return{...i.data,source:a};f==null||f.warn("[%s] get meteo failed: %j",l.requestId,i)}static async queryPointFactor(e,s,t,c="wind,wave,current,watertemp,visibility",a="",l={}){typeof t=="number"&&(t=t<1e12?t*1e3:t);const n=o(t),r={searchParams:{lng:e,lat:s,ts:n.valueOf(),params:c,source:a==null?void 0:a.toLowerCase()},timeout:3e4},h=o(),u=h.valueOf();n.isBefore(h.subtract(1,"month"))&&(f==null||f.warn("[%s] get history factors on %s: %j",l.requestId,n.format(),r));const v="https://aod4idm.idmwx.com/api/ocean/factor",i=await O.get(v,r).json(),d=o().valueOf();if(f==null||f.info("[%s] get factors(cost: %d ms) from %s with options: %j",l.requestId,d-u,v,r),(i==null?void 0:i.code)===0)return{...i.data,source:a};f==null||f.warn("[%s] get factors failed: %j",l.requestId,i)}static async queryWindyPointForecast(e,s,t,c={}){const a="https://api.windy.com/api/point-forecast/v2",l=[];try{let n=o().valueOf();const r=await O.post(a,{headers:{"Content-Type":"application/json"},json:{lat:e,lon:s,key:t,model:"gfs",parameters:["temp","dewpoint","precip","convPrecip","snowPrecip","wind","windGust","cape","ptype","lclouds","mclouds","hclouds","rh","gh","pressure"],levels:["surface"]}}).json();let h=o().valueOf();f==null||f.info("[%s] get gfs-factors(cost: %d ms) from %s",c.requestId,h-n,a),n=h;const u=await O.post(a,{headers:{"Content-Type":"application/json"},json:{lat:e,lon:s,key:t,model:"gfsWave",parameters:["waves","windWaves","swell1","swell2"],levels:["surface"]}}).json();h=o().valueOf(),f==null||f.info("[%s] get gfs-wave-factors(cost: %d ms) from %s",c.requestId,h-n,a);for(let i=0;i<r.ts.length;i++){const d=this.populateUVFactor(r["wind_u-surface"][i],r["wind_v-surface"][i],!1,c);d.scale=this.calculateBeaufortWindForceScale(d.speed),l.push({utc:o(r.ts[i]).utc().format(),temp:r["temp-surface"][i]?Math.round((r["temp-surface"][i]-273.15)*100)/100:void 0,dp_temp:r["dewpoint-surface"][i]?Math.round((r["dewpoint-surface"][i]-273.15)*100)/100:void 0,precip:{inter3h:r["past3hprecip-surface"][i]?Math.round(r["past3hprecip-surface"][i]*1e3*1e3)/1e3:0,inter3hSnow:r["past3hsnowprecip-surface"][i]?Math.round(r["past3hsnowprecip-surface"][i]*1e3*1e3)/1e3:0,inter3hConv:r["past3hconvprecip-surface"][i]?Math.round(r["past3hconvprecip-surface"][i]*1e3*1e3)/1e3:0},wind:d,gusts:{speed:Math.round((r["gust-surface"][i]||0)*100)/100,kts:this.convertMs2Kts(r["gust-surface"][i])},lclouds:r["lclouds-surface"][i]?Math.round(r["lclouds-surface"][i]*100)/100:0,mclouds:r["mclouds-surface"][i]?Math.round(r["mclouds-surface"][i]*100)/100:0,hclouds:r["hclouds-surface"][i]?Math.round(r["hclouds-surface"][i]*100)/100:0,rh:r["rh-surface"][i]?Math.round(r["rh-surface"][i]*100)/100:0,gh:r["gh-surface"][i]?Math.round(r["gh-surface"][i]*100)/100:0,pressure:Math.round(r["pressure-surface"][i]/100*100)/100})}const v=[];for(let i=0;i<u.ts.length;i++){const d=this.calculateDouglasScale(u["waves_height-surface"][i],u["waves_direction-surface"][i],u["waves_period-surface"][i]),A=this.calculateDouglasScale(u["wwaves_height-surface"][i],u["wwaves_direction-surface"][i],u["wwaves_period-surface"][i]),R=this.calculateDouglasScale(u["swell1_height-surface"][i],u["swell1_direction-surface"][i],u["swell1_period-surface"][i]),y=this.calculateDouglasScale(u["swell2_height-surface"][i],u["swell2_direction-surface"][i],u["swell2_period-surface"][i]);v.push({utc:o(u.ts[i]).utc().format(),wave:{sig:d,wd:A,swell:R,swell2:y}})}for(const i of l){const d=v.find(A=>A.utc===i.utc);i.wave=d==null?void 0:d.wave}}catch(n){f.warn("[%s] get-gfs-factor failed: %s",c.requestId,n)}return l}static populateUVFactor(e,s,t=!1,c={}){const a=Math.round(Math.sqrt(Math.pow(e,2)+Math.pow(s,2))*1e4)/1e4,{degree:l,direction:n}=this.calculateUVDirection(e,s,t,c),r=this.convertMs2Kts(a);return{speed:a,kts:r,degree:l,direction:n,eastward:Math.round(e*1e4)/1e4,northward:Math.round(s*1e4)/1e4}}static convertMs2Kts(e){return isNaN(e)?0:Math.round(e*3600/1852*1e3)/1e3}static calculateUVDirection(e,s,t=!1,c={}){let a=Math.atan2(e,s)+Math.PI;t&&(a=Math.atan2(e,s));const l=this.convert2Direction(a);return a=Math.round(a/(2*Math.PI)*360*1e4)/1e4,{angle:a,degree:a,direction:l}}static convert2Direction(e){let s="N/A";if(!isNaN(e)){e<0&&(e+=2*Math.PI);const t=Math.PI/16;e<t?s="N":e>=t&&e<3*t?s="NNE":e>=3*t&&e<5*t?s="NE":e>=5*t&&e<7*t?s="ENE":e>=7*t&&e<9*t?s="E":e>=9*t&&e<11*t?s="ESE":e>=11*t&&e<13*t?s="SE":e>=13*t&&e<15*t?s="SSE":e>=15*t&&e<17*t?s="S":e>=17*t&&e<19*t?s="SSW":e>=19*t&&e<21*t?s="SW":e>=21*t&&e<23*t?s="WSW":e>=23*t&&e<25*t?s="W":e>=25*t&&e<27*t?s="WNW":e>=27*t&&e<29*t?s="NW":e>=29*t&&e<31*t?s="NNW":e>=31*t&&e<32*t&&(s="N")}return s}static calculateBeaufortWindForceScale(e){let s=0;return isNaN(e)||(e=Math.round(e*10)/10,e<=.2?s=0:e<=1.5?s=1:e<=3.3?s=2:e<=5.4?s=3:e<=7.9?s=4:e<=10.7?s=5:e<=13.8?s=6:e<=17.1?s=7:e<=20.7?s=8:e<=22.4?s=9:e<=28.4?s=10:e<=32.6?s=11:e>32.6&&(s=12)),s}static calculateDouglasScale(e,s,t){let c="Calm";const a=this.convert2Direction(s/360*2*Math.PI);return isNaN(e)||e<=.1?c="Calm":e<=.5?c="Smooth":e<=1.25?c="Slight":e<=2.5?c="Moderate":e<=4?c="Rough":e<=6?c="VeryRough":e<=9?c="High":e<=14?c="VeryHigh":c="Precipitous",{degree:Math.round(s*100)/100,scale:c,direction:a,height:Math.round(e*1e3)/1e3,period:Math.round(t*100)/100}}}let I;try{I=w.getLogger("open-meteo")}catch{}finally{}class g{constructor(e,s){S(this,"apikey");S(this,"debug");S(this,"FORECAST_URL","https://customer-api.open-meteo.com/v1/forecast");S(this,"SELF_FORECAST_URL","https://meteo2.idmwx.com/v1/forecast");S(this,"HISTORY_FORECAST_URL","https://customer-historical-forecast-api.open-meteo.com/v1/forecast");S(this,"MARINE_FORECAST_URL","https://customer-marine-api.open-meteo.com/v1/marine");S(this,"SELF_MARINE_FORECAST_URL","https://meteo2.idmwx.com/v1/marine");S(this,"WEATHER_VARIABLES",{NORMAL:{DAILY:"weather_code,temperature_2m_max,temperature_2m_min,apparent_temperature_max,apparent_temperature_min,sunrise,sunset,precipitation_sum,precipitation_hours,precipitation_probability_max,wind_speed_10m_max,wind_gusts_10m_max,wind_direction_10m_dominant",HOURLY:"temperature_2m,relative_humidity_2m,dew_point_2m,apparent_temperature,precipitation_probability,precipitation,weather_code,visibility,wind_speed_10m,wind_direction_10m,wind_gusts_10m",CURRENT:"temperature_2m,relative_humidity_2m,apparent_temperature,precipitation,weather_code,wind_speed_10m,wind_direction_10m,wind_gusts_10m"},SIMPLE:{DAILY:"weather_code",HOURLY:"wind_speed_10m,wind_direction_10m,wind_gusts_10m",CURRENT:"wind_speed_10m,wind_direction_10m,wind_gusts_10m"}});S(this,"MARINE_VARIABLES",{DAILY:"wave_height_max,wave_direction_dominant,wave_period_max,wind_wave_height_max,wind_wave_direction_dominant,wind_wave_period_max,wind_wave_peak_period_max,swell_wave_height_max,swell_wave_direction_dominant,swell_wave_period_max,swell_wave_peak_period_max",HOURLY:"wave_height,wave_direction,wave_period,wind_wave_height,wind_wave_direction,wind_wave_period,wind_wave_peak_period,swell_wave_height,swell_wave_direction,swell_wave_period,swell_wave_peak_period,ocean_current_velocity,ocean_current_direction,sea_level_height_msl,sea_surface_temperature",CURRENT:"wave_height,wave_direction,wave_period,wind_wave_height,wind_wave_direction,wind_wave_period,wind_wave_peak_period,swell_wave_height,swell_wave_direction,swell_wave_period,swell_wave_peak_period,ocean_current_velocity,ocean_current_direction,sea_level_height_msl,sea_surface_temperature"});this.apikey=e||"smE3JnDLHy3TizVv",this.debug=s}range(e,s,t){return Array.from({length:(s-e)/t},(c,a)=>e+a*t)}async weatherForecast(e,s={}){const t=o(),c=await D.fetchWeatherApi(e.url,e);delete e.apikey;const a=o();return this.debug&&I.info("[%s] fetch weather api (%s) cost: %d ms",s.requestId,e.url,a.diff(t,"ms")),this.parseWeatherData(c,e,s)}async marineForecast(e,s={}){const t=o(),c=await D.fetchWeatherApi(e.url,e);delete e.apikey;const a=o();return this.debug&&I.info("[%s] fetch marine api (%s) cost: %d ms",s.requestId,e.url,a.diff(t,"ms")),this.parseWeatherData(c,e,s)}async parseWeatherData(e,s,t={}){var l,n,r,h,u,v;const c=[],a=Math.pow(10,t.precision||6);for(const i of e){const d=i.utcOffsetSeconds(),A=i.current(),R=i.hourly(),y=i.daily(),M={};if(A){const L=o();M.current={time:o.unix(Number(A.time())+d).utc().format()};for(let m=0;m<A.variablesLength();m++){const E=A.variables(m).value();M.current[s.current[m]]=Number.isNaN(E)?E:Math.round(E*a)/a}const N=o();this.debug&&I.info("[%s] fetch current variables cost: %d ms",t.requestId,N.diff(L,"ms"))}if(R){const L=o(),N=o.unix(Number(R.time())+d);M.hourly={date:N.utc().format(),time:this.range(Number(R.time()),Number(R.timeEnd()),R.interval()).map(E=>o.unix(E+d).diff(N,"h"))};for(let E=0;E<R.variablesLength();E++){const b=(r=(n=(l=R.variables(E).valuesArray())==null?void 0:l.toString())==null?void 0:n.split(","))==null?void 0:r.map(T=>Number.isNaN(T)?T:Math.round(Number(T)*a)/a);M.hourly[s.hourly[E]]=b}const m=o();this.debug&&I.info("[%s] fetch hourly variables cost: %d ms",t.requestId,m.diff(L,"ms"))}if(y){const L=o();M.daily={time:this.range(Number(y.time()),Number(y.timeEnd()),y.interval()).map(m=>o.unix(m+d).utc().format())};for(let m=0;m<y.variablesLength();m++){const E=(v=(u=(h=y.variables(m).valuesArray())==null?void 0:h.toString())==null?void 0:u.split(","))==null?void 0:v.map(b=>Number.isNaN(b)?b:Math.round(Number(b)*a)/a);M.daily[s.daily[m]]=E}const N=o();this.debug&&I.info("[%s] fetch daily variables cost: %d ms",t.requestId,N.diff(L,"ms"))}c.push(M)}return c}prepare(e,s,t,c={}){e?(t.start_date=e.utc().set({minute:0,second:0,millisecond:0}).format("YYYY-MM-DD"),t.end_date=e.clone().add(c.forecastDays??1,"d").utc().format("YYYY-MM-DD")):t.forecast_days=c.forecastDays;const a=o().subtract(1,"d");return s?(t.url=c.selfHosted?this.SELF_MARINE_FORECAST_URL:this.MARINE_FORECAST_URL,e!=null&&e.isBefore(a)&&(t.url=this.MARINE_FORECAST_URL)):(t.url=c.selfHosted?this.SELF_FORECAST_URL:this.FORECAST_URL,e!=null&&e.isBefore(a)&&(t.url=this.HISTORY_FORECAST_URL)),t}async spotForecast(e,s,t,c=!0,a=!0,l=!1,n={forecastDays:1,precision:6,selfHosted:!0}){var i,d,A,R,y,M,L,N;const r={apikey:this.apikey,latitude:e,longitude:s,cell_selection:"sea",wind_speed_unit:"kn",models:((i=n.weatherModels)==null?void 0:i.split(","))||["best_match"],timezone:"auto"};a&&(r.daily=c?((d=this.WEATHER_VARIABLES.SIMPLE.DAILY)==null?void 0:d.split(","))||[]:((A=this.WEATHER_VARIABLES.NORMAL.DAILY)==null?void 0:A.split(","))||[]),t||(n.forecastDays=n.forecastDays||1,r.current=c?((R=this.WEATHER_VARIABLES.SIMPLE.CURRENT)==null?void 0:R.split(","))||[]:((y=this.WEATHER_VARIABLES.NORMAL.CURRENT)==null?void 0:y.split(","))||[]),l&&(r.hourly=c?((M=this.WEATHER_VARIABLES.SIMPLE.HOURLY)==null?void 0:M.split(","))||[]:((L=this.WEATHER_VARIABLES.NORMAL.HOURLY)==null?void 0:L.split(","))||[]),this.prepare(t,!1,r,n);const h=await this.weatherForecast(r,n),u={apikey:this.apikey,latitude:e,longitude:s,cell_selection:"sea",timezone:"auto",wind_speed_unit:"kn",models:((N=n.marineModels)==null?void 0:N.split(","))||["best_match"]};a&&(u.daily=this.MARINE_VARIABLES.DAILY.split(",")),t||(n.forecastDays=n.forecastDays||1,u.current=this.MARINE_VARIABLES.CURRENT.split(",")),l&&(u.hourly=this.MARINE_VARIABLES.HOURLY.split(",")),this.prepare(t,!0,u,n);const v=await this.marineForecast(u,n);return{weather:h,marine:v}}}_.MeteoHelper=U,_.MeteoHelper2=g,_.WindyModel=F,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idm-plugin/meteo2",
3
3
  "private": false,
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "description": "idm plugin for meteo2(open meteo)",
6
6
  "type": "module",
7
7
  "keywords": [