@azohra/meteo.station 0.4.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +1 -1
  2. package/dist/client/climatology.js +1 -1
  3. package/dist/client/history.d.ts +8 -14
  4. package/dist/client/history.js +8 -18
  5. package/dist/client/live.d.ts +2 -1
  6. package/dist/client/live.js +7 -4
  7. package/dist/client/stores.js +10 -2
  8. package/dist/climatology.d.ts +9 -4
  9. package/dist/climatology.js +28 -6
  10. package/dist/contract-climatology.d.ts +4 -0
  11. package/dist/contract-climatology.js +3 -1
  12. package/dist/contract.d.ts +7 -7
  13. package/dist/derive.js +5 -4
  14. package/dist/elements/elements/DailyPatternElement.js +4 -4
  15. package/dist/elements/elements/TrendChartElement.js +12 -31
  16. package/dist/elements/elements/WindHistoryChartElement.js +16 -35
  17. package/dist/elements/elements/atoms.d.ts +1 -1
  18. package/dist/elements/lib/pinned-cursor.js +48 -0
  19. package/dist/fixtures.d.ts +6 -2
  20. package/dist/fixtures.js +30 -2
  21. package/dist/format.js +7 -3
  22. package/dist/geometry.d.ts +2 -2
  23. package/dist/geometry.js +24 -17
  24. package/dist/index.d.ts +2 -2
  25. package/dist/index.js +2 -2
  26. package/dist/react/components/DailyPattern.js +2 -2
  27. package/dist/react/components/Dial.d.ts +1 -2
  28. package/dist/react/components/RecentSummaries.d.ts +1 -2
  29. package/dist/react/components/RecentSummaries.js +1 -2
  30. package/dist/react/components/TrendChart.js +8 -26
  31. package/dist/react/components/WindHistoryChart.js +12 -31
  32. package/dist/react/components/WindSampleStrip.js +11 -29
  33. package/dist/react/hooks/useStation.js +28 -50
  34. package/dist/react/hooks/useStationFeed.d.ts +0 -1
  35. package/dist/react/index.js +2 -2
  36. package/dist/react/lib/use-pinned-cursor.js +32 -0
  37. package/dist/samples.js +7 -43
  38. package/dist/scene/climatology-pattern.js +1 -1
  39. package/dist/scene/climatology-rose.js +1 -1
  40. package/dist/scene/daily-pattern.js +3 -3
  41. package/dist/scene/recent-summaries.js +1 -4
  42. package/dist/scene/trend.js +2 -7
  43. package/dist/scene/wind-plot.js +14 -6
  44. package/dist/server/adapters/windnerd-climatology.d.ts +5 -8
  45. package/dist/server/adapters/windnerd-climatology.js +11 -10
  46. package/dist/server/adapters/windnerd-live.d.ts +5 -8
  47. package/dist/server/adapters/windnerd-live.js +5 -8
  48. package/dist/server/adapters/windnerd.d.ts +2 -3
  49. package/dist/server/adapters/windnerd.js +4 -15
  50. package/dist/server/environment.d.ts +4 -10
  51. package/dist/server/environment.js +4 -10
  52. package/dist/server/index.d.ts +2 -2
  53. package/dist/server/index.js +2 -2
  54. package/dist/strings.d.ts +1 -1
  55. package/dist/strings.js +1 -1
  56. package/dist/windnerd.d.ts +3 -1
  57. package/dist/windnerd.js +11 -1
  58. package/package.json +3 -3
  59. package/schema/README.md +2 -2
  60. package/schema/stationclimatology.schema.json +26 -0
  61. package/styles.css +19 -21
@@ -1,11 +1,12 @@
1
1
  "use client";
2
2
  import { resolveDisplay } from "../../display.js";
3
- import { activeChartIndex, chartIndexAtClient, readoutAriaLive, togglePinnedAt } from "../../scene/chart.js";
3
+ import { readoutAriaLive } from "../../scene/chart.js";
4
4
  import { WIND_CHART_CLASS, windChartGate, windChartScene } from "../../scene/wind-history.js";
5
5
  import { requireResolved, resolveStation, useStationFeedContext } from "./StationFeedProvider.js";
6
+ import { usePinnedCursor } from "../lib/use-pinned-cursor.js";
6
7
  import { Readout } from "./Readout.js";
7
8
  import { useMeasuredChartWidth } from "../hooks/useMeasuredChartWidth.js";
8
- import { useId, useRef, useState } from "react";
9
+ import { useId, useRef } from "react";
9
10
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
11
  //#region src/react/components/WindHistoryChart.tsx
11
12
  function WindHistoryChart({ station: stationProp, stationId, thresholds: thresholdsProp, favorableDirections: favorableDirectionsProp, unit: unitProp, plotHeight, windowHours, compareOffsetDays, nightShading = false, strings: stringsProp, formatTime: formatTimeProp }) {
@@ -50,14 +51,11 @@ function WindHistoryChart({ station: stationProp, stationId, thresholds: thresho
50
51
  });
51
52
  }
52
53
  function MeasuredChart({ compareOffsetDays, favorableDirections, formatTime, history, night, plotHeight, stationName, thresholds, unit, width, windowHours, words }) {
53
- const hatchId = `meteo-hatch-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
54
- const [pinnedAt, setPinnedAt] = useState(null);
55
- const [previewIndex, setPreviewIndex] = useState(null);
56
54
  const scene = windChartScene({
57
55
  compareOffsetDays,
58
56
  favorableDirections,
59
57
  formatTime,
60
- hatchId,
58
+ hatchId: `meteo-hatch-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`,
61
59
  history,
62
60
  night,
63
61
  plotHeight,
@@ -68,28 +66,11 @@ function MeasuredChart({ compareOffsetDays, favorableDirections, formatTime, his
68
66
  windowHours,
69
67
  words
70
68
  });
71
- const { readout, cursor } = scene.inspect(activeChartIndex(scene.points, pinnedAt, previewIndex));
72
- const indexAtPoint = (clientX, hit) => {
73
- const svg = hit.ownerSVGElement;
74
- if (!svg) return null;
75
- const bounds = svg.getBoundingClientRect();
76
- return chartIndexAtClient(scene.points, scene.frame, scene.scales, clientX, bounds);
77
- };
78
- const handlePointerMove = (event) => {
79
- if (event.pointerType === "touch") return;
80
- setPreviewIndex(indexAtPoint(event.clientX, event.currentTarget));
81
- };
82
- const handleClick = (event) => {
83
- const index = indexAtPoint(event.clientX, event.currentTarget);
84
- if (index == null) return;
85
- const observedAt = scene.points[index]?.observedAt;
86
- if (observedAt == null) return;
87
- setPinnedAt((current) => togglePinnedAt(current, observedAt));
88
- setPreviewIndex(null);
89
- };
69
+ const pinned = usePinnedCursor(scene);
70
+ const { readout, cursor } = scene.inspect(pinned.activeIndex);
90
71
  return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Readout, {
91
72
  ariaLabel: scene.readout.ariaLabel,
92
- ariaLive: readoutAriaLive(previewIndex),
73
+ ariaLive: readoutAriaLive(pinned.previewIndex),
93
74
  className: scene.readout.className,
94
75
  parts: readout.span,
95
76
  strong: readout.strong
@@ -221,7 +202,7 @@ function MeasuredChart({ compareOffsetDays, favorableDirections, formatTime, his
221
202
  className: vane.mark.className,
222
203
  d: vane.mark.d
223
204
  }, vane.key)),
224
- scene.vanes.map((vane) => /* @__PURE__ */ jsx("text", {
205
+ scene.vanes.map((vane) => vane.label && /* @__PURE__ */ jsx("text", {
225
206
  className: vane.label.className,
226
207
  textAnchor: vane.label.anchor,
227
208
  x: vane.label.x,
@@ -235,7 +216,7 @@ function MeasuredChart({ compareOffsetDays, favorableDirections, formatTime, his
235
216
  y: scene.rowLabels.avg.y,
236
217
  children: scene.rowLabels.avg.text
237
218
  }),
238
- scene.vanes.map((vane) => /* @__PURE__ */ jsx("text", {
219
+ scene.vanes.map((vane) => vane.value && /* @__PURE__ */ jsx("text", {
239
220
  className: vane.value.className,
240
221
  textAnchor: vane.value.anchor,
241
222
  x: vane.value.x,
@@ -265,9 +246,9 @@ function MeasuredChart({ compareOffsetDays, favorableDirections, formatTime, his
265
246
  className: scene.hit.className,
266
247
  fill: scene.hit.fill,
267
248
  height: scene.hit.height,
268
- onClick: handleClick,
269
- onPointerLeave: () => setPreviewIndex(null),
270
- onPointerMove: handlePointerMove,
249
+ onClick: pinned.handleClick,
250
+ onPointerLeave: pinned.handlePointerLeave,
251
+ onPointerMove: pinned.handlePointerMove,
271
252
  width: scene.hit.width,
272
253
  x: scene.hit.x,
273
254
  y: scene.hit.y
@@ -1,11 +1,12 @@
1
1
  "use client";
2
2
  import { resolveDisplay } from "../../display.js";
3
- import { activeChartIndex, chartIndexAtClient, readoutAriaLive, togglePinnedAt } from "../../scene/chart.js";
3
+ import { readoutAriaLive } from "../../scene/chart.js";
4
4
  import { SAMPLE_STRIP_CLASS, sampleStripGate, sampleStripScene } from "../../scene/sample-strip.js";
5
5
  import { useStationFeedContext } from "./StationFeedProvider.js";
6
+ import { usePinnedCursor } from "../lib/use-pinned-cursor.js";
6
7
  import { Readout } from "./Readout.js";
7
8
  import { useMeasuredChartWidth } from "../hooks/useMeasuredChartWidth.js";
8
- import { useRef, useState } from "react";
9
+ import { useRef } from "react";
9
10
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
11
  //#region src/react/components/WindSampleStrip.tsx
11
12
  function WindSampleStrip({ samples, stationName, unit: unitProp, favorableDirections: favorableDirectionsProp, plotHeight, strings: stringsProp, formatTime: formatTimeProp }) {
@@ -39,8 +40,6 @@ function WindSampleStrip({ samples, stationName, unit: unitProp, favorableDirect
39
40
  });
40
41
  }
41
42
  function MeasuredStrip({ favorableDirections, formatTime, plotHeight, samples, stationName, unit, width, words }) {
42
- const [pinnedAt, setPinnedAt] = useState(null);
43
- const [previewIndex, setPreviewIndex] = useState(null);
44
43
  const scene = sampleStripScene({
45
44
  favorableDirections,
46
45
  formatTime,
@@ -51,28 +50,11 @@ function MeasuredStrip({ favorableDirections, formatTime, plotHeight, samples, s
51
50
  width,
52
51
  words
53
52
  });
54
- const { readout, cursor } = scene.inspect(activeChartIndex(scene.points, pinnedAt, previewIndex));
55
- const indexAtPoint = (clientX, hit) => {
56
- const svg = hit.ownerSVGElement;
57
- if (!svg) return null;
58
- const bounds = svg.getBoundingClientRect();
59
- return chartIndexAtClient(scene.points, scene.frame, scene.scales, clientX, bounds);
60
- };
61
- const handlePointerMove = (event) => {
62
- if (event.pointerType === "touch") return;
63
- setPreviewIndex(indexAtPoint(event.clientX, event.currentTarget));
64
- };
65
- const handleClick = (event) => {
66
- const index = indexAtPoint(event.clientX, event.currentTarget);
67
- if (index == null) return;
68
- const observedAt = scene.points[index]?.observedAt;
69
- if (observedAt == null) return;
70
- setPinnedAt((current) => togglePinnedAt(current, observedAt));
71
- setPreviewIndex(null);
72
- };
53
+ const pinned = usePinnedCursor(scene);
54
+ const { readout, cursor } = scene.inspect(pinned.activeIndex);
73
55
  return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Readout, {
74
56
  ariaLabel: scene.readout.ariaLabel,
75
- ariaLive: readoutAriaLive(previewIndex),
57
+ ariaLive: readoutAriaLive(pinned.previewIndex),
76
58
  className: scene.readout.className,
77
59
  parts: readout.span,
78
60
  strong: readout.strong
@@ -137,7 +119,7 @@ function MeasuredStrip({ favorableDirections, formatTime, plotHeight, samples, s
137
119
  className: vane.mark.className,
138
120
  d: vane.mark.d
139
121
  }, vane.key)),
140
- scene.vanes.map((vane) => /* @__PURE__ */ jsx("text", {
122
+ scene.vanes.map((vane) => vane.label && /* @__PURE__ */ jsx("text", {
141
123
  className: vane.label.className,
142
124
  textAnchor: vane.label.anchor,
143
125
  x: vane.label.x,
@@ -151,7 +133,7 @@ function MeasuredStrip({ favorableDirections, formatTime, plotHeight, samples, s
151
133
  y: scene.rowLabels.avg.y,
152
134
  children: scene.rowLabels.avg.text
153
135
  }),
154
- scene.vanes.map((vane) => /* @__PURE__ */ jsx("text", {
136
+ scene.vanes.map((vane) => vane.value && /* @__PURE__ */ jsx("text", {
155
137
  className: vane.value.className,
156
138
  textAnchor: vane.value.anchor,
157
139
  x: vane.value.x,
@@ -181,9 +163,9 @@ function MeasuredStrip({ favorableDirections, formatTime, plotHeight, samples, s
181
163
  className: scene.hit.className,
182
164
  fill: scene.hit.fill,
183
165
  height: scene.hit.height,
184
- onClick: handleClick,
185
- onPointerLeave: () => setPreviewIndex(null),
186
- onPointerMove: handlePointerMove,
166
+ onClick: pinned.handleClick,
167
+ onPointerLeave: pinned.handlePointerLeave,
168
+ onPointerMove: pinned.handlePointerMove,
187
169
  width: scene.hit.width,
188
170
  x: scene.hit.x,
189
171
  y: scene.hit.y
@@ -1,61 +1,39 @@
1
1
  "use client";
2
- import { foldCurrent } from "../../merge-current.js";
3
- import { liveSnapshotToCurrent } from "../../client/live.js";
4
- import { useStationCurrent } from "./useStationCurrent.js";
5
- import { useStationFeed } from "./useStationFeed.js";
6
- import { useStationLive } from "./useStationLive.js";
7
- import { useCallback, useMemo } from "react";
2
+ import { createStationStore } from "../../client/stores.js";
3
+ import { useEffect, useMemo, useRef, useSyncExternalStore } from "react";
8
4
  //#region src/react/hooks/useStation.ts
9
5
  function useStation(url, stationId, options = {}) {
10
6
  const { pollSeconds, currentPollSeconds, enabled = true, fetchInit, initialData } = options;
11
7
  const live = options.live === true;
12
- const feedResult = useStationFeed(url, {
8
+ const fetchInitRef = useRef(fetchInit);
9
+ fetchInitRef.current = fetchInit;
10
+ const initialRef = useRef(initialData);
11
+ const mountUrlRef = useRef(url);
12
+ const store = useMemo(() => createStationStore(url, stationId, {
13
13
  ...pollSeconds != null ? { pollSeconds } : {},
14
- enabled,
15
- ...fetchInit != null ? { fetchInit } : {},
16
- ...initialData != null ? { initialData } : {}
17
- });
18
- const currentResult = useStationCurrent(url, stationId, {
19
- ...currentPollSeconds != null ? { pollSeconds: currentPollSeconds } : {},
20
- enabled: enabled && !live,
21
- ...fetchInit != null ? { fetchInit } : {}
22
- });
23
- const liveResult = useStationLive(url, stationId, {
24
- enabled: enabled && live,
25
- ...fetchInit != null ? { fetchInit } : {}
26
- });
27
- const liveCurrent = useMemo(() => live ? liveSnapshotToCurrent({
28
- station: liveResult.station,
29
- servedAt: liveResult.servedAt,
30
- samples: liveResult.samples
31
- }) : null, [
32
- live,
33
- liveResult.station,
34
- liveResult.servedAt,
35
- liveResult.samples
14
+ ...currentPollSeconds != null ? { currentPollSeconds } : {},
15
+ fetchInit: () => fetchInitRef.current,
16
+ ...url === mountUrlRef.current && initialRef.current != null ? { initialData: initialRef.current } : {},
17
+ live
18
+ }), [
19
+ url,
20
+ stationId,
21
+ pollSeconds,
22
+ currentPollSeconds,
23
+ live
36
24
  ]);
37
- const current = live ? liveCurrent : currentResult.current;
38
- const currentReceivedAtMs = live ? liveCurrent == null ? null : liveResult.receivedAtMs : currentResult.receivedAtMs;
39
- const currentError = live ? liveResult.error : currentResult.error;
40
- const merged = useMemo(() => foldCurrent(feedResult.feed, feedResult.receivedAtMs, current, currentReceivedAtMs), [
41
- feedResult.feed,
42
- feedResult.receivedAtMs,
43
- current,
44
- currentReceivedAtMs
45
- ]);
46
- const station = merged.feed?.stations.find((entry) => entry.id === stationId) ?? null;
47
- const feedRefresh = feedResult.refresh;
48
- const currentRefresh = currentResult.refresh;
49
- const refresh = useCallback(() => {
50
- feedRefresh();
51
- currentRefresh();
52
- }, [feedRefresh, currentRefresh]);
25
+ useEffect(() => {
26
+ if (!enabled) return;
27
+ store.start();
28
+ return () => store.stop();
29
+ }, [store, enabled]);
30
+ const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
53
31
  return {
54
- feed: merged.feed,
55
- station,
56
- receivedAtMs: merged.receivedAtMs,
57
- error: feedResult.error ?? currentError,
58
- refresh
32
+ feed: snapshot.feed,
33
+ station: snapshot.station,
34
+ receivedAtMs: snapshot.receivedAtMs,
35
+ error: snapshot.error,
36
+ refresh: () => store.refresh()
59
37
  };
60
38
  }
61
39
  //#endregion
@@ -9,7 +9,6 @@ declare function useStationFeed(url: string, options?: {
9
9
  fetchInit?: RequestInit;
10
10
  initialData?: {
11
11
  feed: StationFeed;
12
- servedAt?: string;
13
12
  receivedAtMs: number;
14
13
  };
15
14
  }): {
@@ -24,9 +24,9 @@ import { useMeasuredChartWidth } from "./hooks/useMeasuredChartWidth.js";
24
24
  import { WindHistoryChart } from "./components/WindHistoryChart.js";
25
25
  import { WindSampleStrip } from "./components/WindSampleStrip.js";
26
26
  import { StationCard, StationCardChart, StationCardHeader, StationCardInstrument, StationCardSummary } from "./components/StationCard.js";
27
+ import { useStation } from "./hooks/useStation.js";
28
+ import { useStationClimatology } from "./hooks/useStationClimatology.js";
27
29
  import { useStationCurrent } from "./hooks/useStationCurrent.js";
28
30
  import { useStationFeed } from "./hooks/useStationFeed.js";
29
31
  import { useStationLive } from "./hooks/useStationLive.js";
30
- import { useStation } from "./hooks/useStation.js";
31
- import { useStationClimatology } from "./hooks/useStationClimatology.js";
32
32
  export { AirExtremes, AirMatrix, BandChip, ClimatologyDailyPattern, ClimatologyRose, CompassFan, CurrentConditions, DailyPattern, Dial, Direction, FavorableShare, FreshnessBadge, Gust, Lull, Pressure, Readout, RecentSummaries, Sparkline, Speed, StationCard, StationCardChart, StationCardHeader, StationCardInstrument, StationCardSummary, StationFeedProvider, StationStrip, StationTable, Temperature, TrendChart, UpdatedAt, WindArrow, WindHistoryChart, WindRose, WindSampleStrip, useFreshness, useMeasuredChartWidth, useStation, useStationClimatology, useStationCurrent, useStationFeed, useStationFeedContext, useStationLive };
@@ -0,0 +1,32 @@
1
+ "use client";
2
+ import { activeChartIndex, chartIndexAtClient, togglePinnedAt } from "../../scene/chart.js";
3
+ import { useState } from "react";
4
+ //#region src/react/lib/use-pinned-cursor.ts
5
+ function usePinnedCursor(scene) {
6
+ const [pinnedAt, setPinnedAt] = useState(null);
7
+ const [previewIndex, setPreviewIndex] = useState(null);
8
+ const indexAtPoint = (clientX, hit) => {
9
+ const svg = hit.ownerSVGElement;
10
+ if (!svg) return null;
11
+ return chartIndexAtClient(scene.points, scene.frame, scene.scales, clientX, svg.getBoundingClientRect());
12
+ };
13
+ return {
14
+ activeIndex: activeChartIndex(scene.points, pinnedAt, previewIndex),
15
+ previewIndex,
16
+ handleClick: (event) => {
17
+ const index = indexAtPoint(event.clientX, event.currentTarget);
18
+ if (index == null) return;
19
+ const observedAt = scene.points[index]?.observedAt;
20
+ if (observedAt == null) return;
21
+ setPinnedAt((current) => togglePinnedAt(current, observedAt));
22
+ setPreviewIndex(null);
23
+ },
24
+ handlePointerLeave: () => setPreviewIndex(null),
25
+ handlePointerMove: (event) => {
26
+ if (event.pointerType === "touch") return;
27
+ setPreviewIndex(indexAtPoint(event.clientX, event.currentTarget));
28
+ }
29
+ };
30
+ }
31
+ //#endregion
32
+ export { usePinnedCursor };
package/dist/samples.js CHANGED
@@ -1,10 +1,8 @@
1
- import { KMH_PER_MPS, isCalm } from "./derive.js";
2
- import { HISTORY_GAP_TOLERANCE_FACTOR } from "./geometry.js";
3
- import { meanDirectionDeg } from "@azohra/meteo.core";
1
+ import { HISTORY_GAP_TOLERANCE_FACTOR, chartScalesOf, meanDirectionDegOf, thinVanesOf, tracePointsOf } from "./geometry.js";
4
2
  //#region src/samples.ts
3
+ const speedOf = (sample) => sample.windMps;
4
+ const directionOf = (sample) => sample.windDirectionDeg;
5
5
  const SAMPLE_GAP_TOLERANCE_FACTOR = HISTORY_GAP_TOLERANCE_FACTOR;
6
- const DEFAULT_NICE_STEP_MPS = 5 / KMH_PER_MPS;
7
- const DEFAULT_FLOOR_MPS = 10 / KMH_PER_MPS;
8
6
  function sampleRuns(samples, toleranceFactor = SAMPLE_GAP_TOLERANCE_FACTOR) {
9
7
  const limitMs = samples.intervalSeconds * 1e3 * toleranceFactor;
10
8
  const runs = [];
@@ -19,50 +17,16 @@ function sampleRuns(samples, toleranceFactor = SAMPLE_GAP_TOLERANCE_FACTOR) {
19
17
  return runs;
20
18
  }
21
19
  function sampleScales(samples, frame, options = {}) {
22
- const niceStepMps = options.niceStepMps ?? DEFAULT_NICE_STEP_MPS;
23
- const floorMps = options.floorMps ?? DEFAULT_FLOOR_MPS;
24
- const points = samples.points;
25
- const first = points[0];
26
- const startMs = first ? Date.parse(first.observedAt) : 0;
27
- const last = points[points.length - 1];
28
- const endMs = last ? Date.parse(last.observedAt) : startMs;
29
- const durationMs = Math.max(1, endMs - startMs);
30
- const top = points.reduce((max, sample) => Math.max(max, sample.windMps), 0);
31
- const scaleMax = Math.max(floorMps, Math.ceil(top / niceStepMps) * niceStepMps);
32
- const xAtMs = (ms) => frame.left + (ms - startMs) / durationMs * (frame.right - frame.left);
33
- return {
34
- startMs,
35
- endMs,
36
- durationMs,
37
- scaleMax,
38
- xAtMs,
39
- xAt: (observedAt) => xAtMs(Date.parse(observedAt)),
40
- yAt: (speedMps) => frame.plotBottom - speedMps / scaleMax * (frame.plotBottom - frame.plotTop)
41
- };
20
+ return chartScalesOf(samples.points, frame, speedOf, options);
42
21
  }
43
22
  function samplePoints(run, scales) {
44
- return run.map((sample) => `${scales.xAt(sample.observedAt).toFixed(1)},${scales.yAt(sample.windMps).toFixed(1)}`).join(" ");
23
+ return tracePointsOf(run, scales, speedOf);
45
24
  }
46
25
  function sampleMeanDirectionDeg(samples) {
47
- return meanDirectionDeg(samples.filter((sample) => !isCalm(sample.windMps) && sample.windDirectionDeg != null).map((sample) => sample.windDirectionDeg));
26
+ return meanDirectionDegOf(samples, speedOf, directionOf);
48
27
  }
49
28
  function thinSampleVanes(samples, target = 13) {
50
- if (samples.length === 0) return [];
51
- const step = Math.max(1, Math.round(samples.length / target));
52
- return Array.from({ length: Math.ceil(samples.length / step) }, (_, index) => {
53
- const startIndex = index * step;
54
- const endIndex = startIndex + step;
55
- const window = samples.slice(startIndex, endIndex);
56
- const first = Date.parse(window[0].observedAt);
57
- const last = Date.parse(window[window.length - 1].observedAt);
58
- return {
59
- windAvgMps: window.reduce((sum, sample) => sum + sample.windMps, 0) / window.length,
60
- windDirectionDeg: sampleMeanDirectionDeg(window),
61
- endIndex,
62
- midMs: first + (last - first) / 2,
63
- startIndex
64
- };
65
- });
29
+ return thinVanesOf(samples, speedOf, directionOf, target);
66
30
  }
67
31
  function samplesSummary(samples) {
68
32
  const points = samples.points;
@@ -27,7 +27,7 @@ function climatologyPatternScene(input) {
27
27
  slots,
28
28
  coverage: {
29
29
  totalSamples,
30
- expectedSamples: coverage != null && coverage.expectedCount > 0 ? coverage.expectedCount : null
30
+ percent: coverage != null && coverage.ratio != null ? Math.round(coverage.ratio * 100) : null
31
31
  }
32
32
  });
33
33
  }
@@ -37,7 +37,7 @@ function climatologyRoseScene(input) {
37
37
  captions.push({
38
38
  key: "samples",
39
39
  className: "meteo-climatology-caption",
40
- text: coverage != null && coverage.expectedCount > 0 ? words.dailyPatternCoverage(summary.sampleCount, coverage.expectedCount) : words.dailyPatternSamples(summary.sampleCount)
40
+ text: coverage != null && coverage.ratio != null ? words.dailyPatternCoverage(summary.sampleCount, Math.round(coverage.ratio * 100)) : words.dailyPatternSamples(summary.sampleCount)
41
41
  });
42
42
  return {
43
43
  className: CLIMATOLOGY_ROSE_CLASS,
@@ -47,7 +47,7 @@ function dailyPatternScene(input) {
47
47
  slots,
48
48
  coverage: {
49
49
  totalSamples,
50
- expectedSamples
50
+ percent: expectedSamples != null && expectedSamples > 0 ? Math.round(totalSamples / expectedSamples * 100) : null
51
51
  }
52
52
  });
53
53
  }
@@ -57,7 +57,7 @@ function dailyPatternSlotsScene(input) {
57
57
  const { coverage, hatchId, plotHeight, slotMinutes, slots, stationName, thresholds, unit, width, words } = input;
58
58
  const shown = (speedMps) => roundSpeed(speedMps, unit);
59
59
  const synthetic = slots.map((slot) => slotPoint(slot, slotMinutes));
60
- const { totalSamples, expectedSamples } = coverage;
60
+ const { totalSamples, percent } = coverage;
61
61
  const frame = stretchedChartFrame(width, plotHeight);
62
62
  const scales = displaySpeedScales(synthetic, frame, unit);
63
63
  const vanes = thinVanes(synthetic);
@@ -69,7 +69,7 @@ function dailyPatternSlotsScene(input) {
69
69
  scales,
70
70
  caption: {
71
71
  className: "meteo-daily-pattern-caption",
72
- text: expectedSamples != null ? words.dailyPatternCoverage(totalSamples, expectedSamples) : words.dailyPatternSamples(totalSamples)
72
+ text: percent != null ? words.dailyPatternCoverage(totalSamples, percent) : words.dailyPatternSamples(totalSamples)
73
73
  },
74
74
  svg: {
75
75
  ariaLabel: stationName ? words.aria.dailyPattern(stationName) : words.aria.dailyPatternGeneric,
@@ -1,4 +1,3 @@
1
- import { vectorMeanWind } from "../geometry.js";
2
1
  import { optionalSpeed, roundSpeed } from "../format.js";
3
2
  import { inDirectionArcs } from "@azohra/meteo.core";
4
3
  //#region src/scene/recent-summaries.ts
@@ -29,7 +28,6 @@ function recentSummariesScene(input) {
29
28
  const avgMps = points.length === 0 ? null : points.reduce((sum, point) => sum + point.windAvgMps, 0) / points.length;
30
29
  const gusts = points.map((point) => point.windGustMps).filter((gust) => gust != null);
31
30
  const lulls = points.map((point) => point.windLullMps).filter((lull) => lull != null);
32
- const mean = vectorMeanWind(points);
33
31
  return {
34
32
  key: block.windowMinutes,
35
33
  className: "meteo-recent-summary",
@@ -65,8 +63,7 @@ function recentSummariesScene(input) {
65
63
  className: `meteo-recent-summary-ghost${verdict}`,
66
64
  deg: point.windDirectionDeg
67
65
  }];
68
- }),
69
- meanDirectionDeg: mean.windDirectionDeg
66
+ })
70
67
  };
71
68
  })
72
69
  };
@@ -77,13 +77,8 @@ function trendScene(input) {
77
77
  }
78
78
  };
79
79
  });
80
- const ticks = [
81
- 0,
82
- .25,
83
- .5,
84
- .75,
85
- 1
86
- ].map((fraction, index) => {
80
+ const tickCount = Math.max(2, Math.min(5, Math.floor((frame.right - frame.left) / 76)));
81
+ const ticks = Array.from({ length: tickCount }, (_, at) => at / (tickCount - 1)).map((fraction, index) => {
87
82
  const timeMs = scales.startMs + fraction * scales.durationMs;
88
83
  return {
89
84
  key: index,
@@ -191,9 +191,17 @@ function nightRects(points, frame, scales, night) {
191
191
  }
192
192
  return rects;
193
193
  }
194
+ const COMPASS_LABEL_PX = 30;
195
+ const VALUE_LABEL_PX = 24;
196
+ const TIME_LABEL_PX = 76;
194
197
  function vaneCells(vanes, frame, scales, valueText, favorableDirections) {
195
198
  const verdict = (directionDeg) => favorableDirections == null || favorableDirections.length === 0 ? "" : inDirectionArcs(directionDeg, favorableDirections) ? " meteo-wind-vane-favorable" : " meteo-wind-vane-unfavorable";
196
- return vanes.map((vane) => ({
199
+ const pitch = vanes.length === 0 ? Infinity : (frame.right - frame.left) / vanes.length;
200
+ const step = (needPx) => Math.max(1, Math.ceil(needPx / pitch));
201
+ const labelStep = step(COMPASS_LABEL_PX);
202
+ const valueStep = step(VALUE_LABEL_PX);
203
+ const speaks = (index, every) => (vanes.length - 1 - index) % every === 0;
204
+ return vanes.map((vane, index) => ({
197
205
  key: vane.midMs,
198
206
  mark: vane.windDirectionDeg == null ? {
199
207
  kind: "calm",
@@ -209,24 +217,24 @@ function vaneCells(vanes, frame, scales, valueText, favorableDirections) {
209
217
  className: `meteo-wind-vane${verdict(vane.windDirectionDeg)}`,
210
218
  d: vanePath(scales.xAtMs(vane.midMs), frame.vaneRow, vane.windDirectionDeg)
211
219
  },
212
- label: {
220
+ label: speaks(index, labelStep) ? {
213
221
  className: "meteo-wind-vane-label",
214
222
  anchor: "middle",
215
223
  x: scales.xAtMs(vane.midMs),
216
224
  y: frame.vaneLabelRow + 4,
217
225
  text: vane.windDirectionDeg == null ? "—" : compassDirection(vane.windDirectionDeg)
218
- },
219
- value: {
226
+ } : null,
227
+ value: speaks(index, valueStep) ? {
220
228
  className: "meteo-wind-vane-value",
221
229
  anchor: "middle",
222
230
  x: scales.xAtMs(vane.midMs),
223
231
  y: frame.valueRow + 4,
224
232
  text: valueText(vane)
225
- }
233
+ } : null
226
234
  }));
227
235
  }
228
236
  function vaneTickTexts(vanes, frame, scales, labelText) {
229
- const ticks = vaneTicks(vanes, scales);
237
+ const ticks = vaneTicks(vanes, scales, Math.floor((frame.right - frame.left) / TIME_LABEL_PX));
230
238
  return ticks.map(({ index, timeMs, x }) => ({
231
239
  key: index,
232
240
  className: "meteo-tick",
@@ -20,14 +20,11 @@ type WindnerdClimatologyOptions = {
20
20
  recordsUrl?: string;
21
21
  liveUrl?: string;
22
22
  };
23
- /**
24
- * Builds the station's climatology cube from the vendor's yearly archive:
25
- * one records request per calendar year (closed years cached ~30 days, the
26
- * running year 6 hours), folded into (month, slot, sector) sums bucketed in
27
- * the station's STANDARD time. Any year the upstream refuses fails the
28
- * whole document — a silently missing year would read as an outage, and
29
- * plausible-but-wrong is the named failure mode.
30
- */
23
+ /** Builds the climatology cube from the vendor's yearly archive: one
24
+ * records request per calendar year (closed years cached ~30 days, the
25
+ * running year 6 hours), folded into (month, slot, sector) sums in the
26
+ * station's STANDARD time. Any refused year fails the whole document —
27
+ * a silently missing year would read as an outage. */
31
28
  declare function loadWindnerdClimatology(config: WindnerdStationConfig, options: WindnerdClimatologyOptions): Promise<StationClimatology>;
32
29
  //#endregion
33
30
  export { CLIMATOLOGY_DEFAULT_SECTOR_COUNT, CLIMATOLOGY_DEFAULT_YEARS, CLIMATOLOGY_RECORD_PERIOD_MINUTES, WindnerdClimatologyOptions, loadWindnerdClimatology };
@@ -1,6 +1,6 @@
1
1
  import { thresholdsToMps } from "../../derive.js";
2
2
  import "../../contract-climatology.js";
3
- import { accumulatedCells, createClimatologyAccumulator, foldClimatologyPoints } from "../../climatology.js";
3
+ import { accumulatedCells, coveredSlotCountByYear, createClimatologyAccumulator, foldClimatologyPoints } from "../../climatology.js";
4
4
  import { fetchUpstreamText, logUpstreamFailure, resolveEnvironment } from "../environment.js";
5
5
  import { loadWindnerdLocation, parseWindnerdRecords, windnerdHistoryPoints } from "./windnerd.js";
6
6
  //#region src/server/adapters/windnerd-climatology.ts
@@ -9,14 +9,11 @@ const CLIMATOLOGY_DEFAULT_YEARS = 8;
9
9
  const CLIMATOLOGY_DEFAULT_SECTOR_COUNT = 16;
10
10
  const CLOSED_YEAR_CACHE_TTL_SECONDS = 2592e3;
11
11
  const CURRENT_YEAR_CACHE_TTL_SECONDS = 21600;
12
- /**
13
- * Builds the station's climatology cube from the vendor's yearly archive:
14
- * one records request per calendar year (closed years cached ~30 days, the
15
- * running year 6 hours), folded into (month, slot, sector) sums bucketed in
16
- * the station's STANDARD time. Any year the upstream refuses fails the
17
- * whole document — a silently missing year would read as an outage, and
18
- * plausible-but-wrong is the named failure mode.
19
- */
12
+ /** Builds the climatology cube from the vendor's yearly archive: one
13
+ * records request per calendar year (closed years cached ~30 days, the
14
+ * running year 6 hours), folded into (month, slot, sector) sums in the
15
+ * station's STANDARD time. Any refused year fails the whole document —
16
+ * a silently missing year would read as an outage. */
20
17
  async function loadWindnerdClimatology(config, options) {
21
18
  const environment = resolveEnvironment(options.environment);
22
19
  const yearsBack = options.years ?? 8;
@@ -53,9 +50,13 @@ async function loadWindnerdClimatology(config, options) {
53
50
  years.push({
54
51
  year,
55
52
  sampleCount: points.length,
56
- expectedCount: Math.floor((to - from) / (180 * 6e4))
53
+ expectedCount: Math.floor((to - from) / (180 * 6e4)),
54
+ coveredSlotCount: 0,
55
+ expectedSlotCount: Math.floor((to - from) / (slotMinutes * 6e4))
57
56
  });
58
57
  }
58
+ const coveredByYear = coveredSlotCountByYear(accumulator);
59
+ for (const ledger of years) ledger.coveredSlotCount = coveredByYear.get(ledger.year) ?? 0;
59
60
  while (years.length > 1 && years[0]?.sampleCount === 0) years.shift();
60
61
  return {
61
62
  schemaVersion: 1,
@@ -8,14 +8,11 @@ type WindnerdLiveOptions = {
8
8
  liveUrl?: string;
9
9
  idleTimeoutMs?: number;
10
10
  };
11
- /**
12
- * Opens the station's live stream and returns our frames: one init, then
13
- * samples/reading/ping as the upstream serves them. The connect phase —
14
- * headers plus the upstream init frame — rejects on failure; once resolved,
15
- * failures degrade to a terminal unavailable frame instead of throwing.
16
- * One call is one upstream connection: reconnect and fan-out belong to the
17
- * caller, and a reconnect's fresh init frame is the resume story.
18
- */
11
+ /** Opens the station's live stream: one init frame, then
12
+ * samples/reading/ping as served. The connect phase (headers plus the
13
+ * upstream init frame) rejects on failure; after that, failures degrade
14
+ * to a terminal unavailable frame. One call is one upstream connection;
15
+ * reconnect and fan-out belong to the caller. */
19
16
  declare function openWindnerdLive(config: WindnerdStationConfig, options?: WindnerdLiveOptions): Promise<ReadableStream<StationLiveFrame>>;
20
17
  //#endregion
21
18
  export { WindnerdLiveOptions, openWindnerdLive };
@@ -4,14 +4,11 @@ import { UpstreamError, fetchUpstreamStream, logUpstreamFailure, resolveEnvironm
4
4
  import { WINDNERD_LIVE_INIT_TIMEOUT_MS, parseWindnerdLiveDigest, parseWindnerdLiveInit, parseWindnerdLiveSampleRecords, parseWindnerdRecentSummaries, windnerdEnrichedMeta, windnerdLiveReading, windnerdLiveSamples, windnerdLiveStreamUrl, windnerdStationMeta } from "./windnerd.js";
5
5
  //#region src/server/adapters/windnerd-live.ts
6
6
  const LIVE_IDLE_TIMEOUT_MS = 75e3;
7
- /**
8
- * Opens the station's live stream and returns our frames: one init, then
9
- * samples/reading/ping as the upstream serves them. The connect phase —
10
- * headers plus the upstream init frame — rejects on failure; once resolved,
11
- * failures degrade to a terminal unavailable frame instead of throwing.
12
- * One call is one upstream connection: reconnect and fan-out belong to the
13
- * caller, and a reconnect's fresh init frame is the resume story.
14
- */
7
+ /** Opens the station's live stream: one init frame, then
8
+ * samples/reading/ping as served. The connect phase (headers plus the
9
+ * upstream init frame) rejects on failure; after that, failures degrade
10
+ * to a terminal unavailable frame. One call is one upstream connection;
11
+ * reconnect and fan-out belong to the caller. */
15
12
  async function openWindnerdLive(config, options = {}) {
16
13
  const environment = resolveEnvironment(options.environment);
17
14
  const subject = `WindNerd location ${config.locationId} live stream`;