@azohra/meteo.station 0.1.1

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 (160) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -0
  3. package/dist/air.d.ts +13 -0
  4. package/dist/air.js +76 -0
  5. package/dist/client/index.d.ts +4 -0
  6. package/dist/client/index.js +4 -0
  7. package/dist/client/poll.d.ts +42 -0
  8. package/dist/client/poll.js +121 -0
  9. package/dist/client/stores.d.ts +46 -0
  10. package/dist/client/stores.js +128 -0
  11. package/dist/client/ticker.d.ts +4 -0
  12. package/dist/client/ticker.js +19 -0
  13. package/dist/contract.d.ts +381 -0
  14. package/dist/contract.js +143 -0
  15. package/dist/derive.d.ts +54 -0
  16. package/dist/derive.js +134 -0
  17. package/dist/display.d.ts +28 -0
  18. package/dist/display.js +27 -0
  19. package/dist/elements/elements/AirMatrixElement.d.ts +14 -0
  20. package/dist/elements/elements/AirMatrixElement.js +83 -0
  21. package/dist/elements/elements/CurrentConditionsElement.d.ts +9 -0
  22. package/dist/elements/elements/CurrentConditionsElement.js +52 -0
  23. package/dist/elements/elements/DailyPatternElement.d.ts +15 -0
  24. package/dist/elements/elements/DailyPatternElement.js +200 -0
  25. package/dist/elements/elements/DialElement.d.ts +9 -0
  26. package/dist/elements/elements/DialElement.js +128 -0
  27. package/dist/elements/elements/FreshnessBadgeElement.d.ts +8 -0
  28. package/dist/elements/elements/FreshnessBadgeElement.js +22 -0
  29. package/dist/elements/elements/SparklineElement.d.ts +9 -0
  30. package/dist/elements/elements/SparklineElement.js +74 -0
  31. package/dist/elements/elements/StationCardElement.d.ts +53 -0
  32. package/dist/elements/elements/StationCardElement.js +211 -0
  33. package/dist/elements/elements/StationFeedElement.d.ts +32 -0
  34. package/dist/elements/elements/StationFeedElement.js +215 -0
  35. package/dist/elements/elements/StationStripElement.d.ts +9 -0
  36. package/dist/elements/elements/StationStripElement.js +43 -0
  37. package/dist/elements/elements/StationTableElement.d.ts +18 -0
  38. package/dist/elements/elements/StationTableElement.js +102 -0
  39. package/dist/elements/elements/TrendChartElement.d.ts +10 -0
  40. package/dist/elements/elements/TrendChartElement.js +174 -0
  41. package/dist/elements/elements/WindArrowElement.d.ts +8 -0
  42. package/dist/elements/elements/WindArrowElement.js +14 -0
  43. package/dist/elements/elements/WindHistoryChartElement.d.ts +10 -0
  44. package/dist/elements/elements/WindHistoryChartElement.js +277 -0
  45. package/dist/elements/elements/WindRoseElement.d.ts +17 -0
  46. package/dist/elements/elements/WindRoseElement.js +106 -0
  47. package/dist/elements/elements/atoms.d.ts +48 -0
  48. package/dist/elements/elements/atoms.js +131 -0
  49. package/dist/elements/index.d.ts +48 -0
  50. package/dist/elements/index.js +57 -0
  51. package/dist/elements/lib/ambient.d.ts +15 -0
  52. package/dist/elements/lib/ambient.js +5 -0
  53. package/dist/elements/lib/attributes.js +21 -0
  54. package/dist/elements/lib/base.d.ts +45 -0
  55. package/dist/elements/lib/base.js +152 -0
  56. package/dist/elements/lib/context.js +28 -0
  57. package/dist/elements/lib/fragments.js +45 -0
  58. package/dist/elements/lib/h.js +35 -0
  59. package/dist/elements/register.d.ts +1 -0
  60. package/dist/elements/register.js +5 -0
  61. package/dist/endpoints.d.ts +5 -0
  62. package/dist/endpoints.js +10 -0
  63. package/dist/fixtures.d.ts +23 -0
  64. package/dist/fixtures.js +67 -0
  65. package/dist/format.d.ts +31 -0
  66. package/dist/format.js +82 -0
  67. package/dist/geometry.d.ts +84 -0
  68. package/dist/geometry.js +333 -0
  69. package/dist/index.d.ts +12 -0
  70. package/dist/index.js +12 -0
  71. package/dist/instruments.d.ts +75 -0
  72. package/dist/instruments.js +173 -0
  73. package/dist/merge-current.d.ts +13 -0
  74. package/dist/merge-current.js +54 -0
  75. package/dist/react/components/AirMatrix.d.ts +11 -0
  76. package/dist/react/components/AirMatrix.js +82 -0
  77. package/dist/react/components/CurrentConditions.d.ts +17 -0
  78. package/dist/react/components/CurrentConditions.js +98 -0
  79. package/dist/react/components/DailyPattern.d.ts +19 -0
  80. package/dist/react/components/DailyPattern.js +212 -0
  81. package/dist/react/components/Dial.d.ts +17 -0
  82. package/dist/react/components/Dial.js +133 -0
  83. package/dist/react/components/FreshnessBadge.d.ts +10 -0
  84. package/dist/react/components/FreshnessBadge.js +20 -0
  85. package/dist/react/components/Sparkline.d.ts +17 -0
  86. package/dist/react/components/Sparkline.js +60 -0
  87. package/dist/react/components/StationCard.d.ts +46 -0
  88. package/dist/react/components/StationCard.js +140 -0
  89. package/dist/react/components/StationFeedProvider.d.ts +27 -0
  90. package/dist/react/components/StationFeedProvider.js +40 -0
  91. package/dist/react/components/StationStrip.d.ts +16 -0
  92. package/dist/react/components/StationStrip.js +84 -0
  93. package/dist/react/components/StationTable.d.ts +18 -0
  94. package/dist/react/components/StationTable.js +115 -0
  95. package/dist/react/components/TrendChart.d.ts +14 -0
  96. package/dist/react/components/TrendChart.js +150 -0
  97. package/dist/react/components/WindArrow.d.ts +7 -0
  98. package/dist/react/components/WindArrow.js +21 -0
  99. package/dist/react/components/WindHistoryChart.d.ts +18 -0
  100. package/dist/react/components/WindHistoryChart.js +278 -0
  101. package/dist/react/components/WindRose.d.ts +17 -0
  102. package/dist/react/components/WindRose.js +99 -0
  103. package/dist/react/components/atoms.d.ts +33 -0
  104. package/dist/react/components/atoms.js +136 -0
  105. package/dist/react/hooks/useFreshness.d.ts +6 -0
  106. package/dist/react/hooks/useFreshness.js +21 -0
  107. package/dist/react/hooks/usePolledJson.js +17 -0
  108. package/dist/react/hooks/useStation.d.ts +23 -0
  109. package/dist/react/hooks/useStation.js +42 -0
  110. package/dist/react/hooks/useStationCurrent.d.ts +23 -0
  111. package/dist/react/hooks/useStationCurrent.js +32 -0
  112. package/dist/react/hooks/useStationFeed.d.ts +22 -0
  113. package/dist/react/hooks/useStationFeed.js +28 -0
  114. package/dist/react/index.d.ts +20 -0
  115. package/dist/react/index.js +21 -0
  116. package/dist/react/lib/cells.js +29 -0
  117. package/dist/scene/air-matrix.js +71 -0
  118. package/dist/scene/atoms.js +102 -0
  119. package/dist/scene/card.js +54 -0
  120. package/dist/scene/chart.js +28 -0
  121. package/dist/scene/current.js +66 -0
  122. package/dist/scene/daily-pattern.js +81 -0
  123. package/dist/scene/dial.js +141 -0
  124. package/dist/scene/glyphs.js +24 -0
  125. package/dist/scene/rose.js +120 -0
  126. package/dist/scene/sparkline.js +73 -0
  127. package/dist/scene/strip.js +63 -0
  128. package/dist/scene/table.js +76 -0
  129. package/dist/scene/trend.js +160 -0
  130. package/dist/scene/wind-history.js +148 -0
  131. package/dist/scene/wind-plot.js +214 -0
  132. package/dist/server/adapter.d.ts +28 -0
  133. package/dist/server/adapter.js +32 -0
  134. package/dist/server/adapters/campbell.d.ts +112 -0
  135. package/dist/server/adapters/campbell.js +414 -0
  136. package/dist/server/adapters/tempest.d.ts +27 -0
  137. package/dist/server/adapters/tempest.js +137 -0
  138. package/dist/server/adapters/windnerd.d.ts +39 -0
  139. package/dist/server/adapters/windnerd.js +159 -0
  140. package/dist/server/config.d.ts +135 -0
  141. package/dist/server/config.js +57 -0
  142. package/dist/server/environment.d.ts +48 -0
  143. package/dist/server/environment.js +128 -0
  144. package/dist/server/feed.d.ts +31 -0
  145. package/dist/server/feed.js +216 -0
  146. package/dist/server/handler.d.ts +17 -0
  147. package/dist/server/handler.js +133 -0
  148. package/dist/server/index.d.ts +10 -0
  149. package/dist/server/index.js +10 -0
  150. package/dist/strings.d.ts +118 -0
  151. package/dist/strings.js +237 -0
  152. package/dist/windnerd.d.ts +5 -0
  153. package/dist/windnerd.js +25 -0
  154. package/package.json +97 -0
  155. package/schema/README.md +14 -0
  156. package/schema/example-current.json +48 -0
  157. package/schema/example-feed.json +147 -0
  158. package/schema/stationcurrent.schema.json +641 -0
  159. package/schema/stationfeed.schema.json +656 -0
  160. package/styles.css +1141 -0
@@ -0,0 +1,160 @@
1
+ import { chartFrame, chartScales, trendRuns, trendSeriesPad, trendValueOf, valueScale } from "../geometry.js";
2
+ import { tickAnchor } from "./chart.js";
3
+ //#region src/scene/trend.ts
4
+ const TREND_CLASS = "meteo-trend";
5
+ function trendGate(station, series, words) {
6
+ if (!station.capabilities.history) return { kind: "hidden" };
7
+ const history = station.status === "ok" ? station.history : null;
8
+ if (history == null || history.points.length < 2) return {
9
+ kind: "note",
10
+ className: `${TREND_CLASS} meteo-trend-na`,
11
+ text: words.noHistory
12
+ };
13
+ if (history.points.filter((point) => trendValueOf(point, series) != null).length < 2) return {
14
+ kind: "note",
15
+ className: `${TREND_CLASS} meteo-trend-na`,
16
+ text: words.notMeasured
17
+ };
18
+ return {
19
+ kind: "draw",
20
+ history
21
+ };
22
+ }
23
+ function trendFrame(width) {
24
+ const core = chartFrame(width);
25
+ return {
26
+ ...core,
27
+ vaneRow: core.plotBottom,
28
+ labelRow: core.plotBottom + 22,
29
+ height: core.plotBottom + 30
30
+ };
31
+ }
32
+ function trendScene(input) {
33
+ const { formatTime, history, series, stationName, width, words } = input;
34
+ const points = history.points;
35
+ const frame = trendFrame(width);
36
+ const scales = chartScales(points, frame);
37
+ const scale = valueScale(points.map((point) => trendValueOf(point, series)), frame, { paddingMin: trendSeriesPad(series) });
38
+ const segments = trendRuns(points, series, history.periodMinutes).map((run) => {
39
+ const coords = run.samples.map(([ms, value]) => [scales.xAtMs(ms), scale.yAt(value)]);
40
+ const only = coords[0];
41
+ return coords.length === 1 && only != null ? {
42
+ kind: "dot",
43
+ className: "meteo-trend-dot",
44
+ startedAt: run.startedAt,
45
+ cx: only[0],
46
+ cy: only[1],
47
+ r: 2.5
48
+ } : {
49
+ kind: "polyline",
50
+ className: "meteo-trend-line",
51
+ startedAt: run.startedAt,
52
+ points: coords.map(([x, y]) => `${x.toFixed(1)},${y.toFixed(1)}`).join(" ")
53
+ };
54
+ });
55
+ const seriesLabel = series === "temperature" ? words.trendTemperature : words.trendPressure;
56
+ const unitWord = series === "temperature" ? words.degC : words.air.unitHpa;
57
+ const grid = [
58
+ 0,
59
+ .5,
60
+ 1
61
+ ].map((fraction) => {
62
+ const gridY = frame.plotBottom - fraction * (frame.plotBottom - frame.plotTop);
63
+ return {
64
+ key: fraction,
65
+ line: {
66
+ className: "meteo-grid-line",
67
+ x1: frame.left,
68
+ x2: frame.right,
69
+ y1: gridY,
70
+ y2: gridY
71
+ },
72
+ label: {
73
+ className: "meteo-grid-label",
74
+ anchor: "end",
75
+ x: frame.left - 6,
76
+ y: gridY + 5,
77
+ text: String(Math.round(scale.min + fraction * (scale.max - scale.min)))
78
+ }
79
+ };
80
+ });
81
+ const ticks = [
82
+ 0,
83
+ .25,
84
+ .5,
85
+ .75,
86
+ 1
87
+ ].map((fraction, index) => {
88
+ const timeMs = scales.startMs + fraction * scales.durationMs;
89
+ return {
90
+ key: index,
91
+ className: "meteo-tick",
92
+ anchor: tickAnchor(index, 4),
93
+ x: scales.xAtMs(timeMs),
94
+ y: frame.labelRow,
95
+ text: formatTime(new Date(timeMs))
96
+ };
97
+ });
98
+ return {
99
+ frame,
100
+ scales,
101
+ points,
102
+ readout: {
103
+ ariaLabel: words.aria.readout(stationName),
104
+ className: "meteo-trend-readout"
105
+ },
106
+ svg: {
107
+ ariaLabel: words.aria.trend(stationName, seriesLabel),
108
+ className: "meteo-trend-svg",
109
+ height: frame.height,
110
+ viewBox: `0 0 ${frame.width} ${frame.height}`,
111
+ width: frame.width
112
+ },
113
+ grid,
114
+ segments,
115
+ ticks,
116
+ hit: {
117
+ className: "meteo-hit",
118
+ fill: "transparent",
119
+ height: frame.height,
120
+ width: frame.width,
121
+ x: 0,
122
+ y: 0
123
+ },
124
+ inspect: (activeIndex) => {
125
+ const active = activeIndex == null ? void 0 : points[activeIndex];
126
+ if (active == null) return {
127
+ readout: {
128
+ strong: `${formatTime(new Date(scales.startMs))}–${formatTime(new Date(scales.endMs))}`,
129
+ span: words.inspectHint
130
+ },
131
+ cursor: null
132
+ };
133
+ const activeValue = trendValueOf(active, series);
134
+ const x = scales.xAt(active.observedAt);
135
+ return {
136
+ readout: {
137
+ strong: formatTime(new Date(active.observedAt)),
138
+ span: `${seriesLabel} ${activeValue == null ? "—" : `${activeValue.toFixed(1)} ${unitWord}`}`
139
+ },
140
+ cursor: {
141
+ line: {
142
+ className: "meteo-cursor",
143
+ x1: x,
144
+ x2: x,
145
+ y1: frame.plotTop,
146
+ y2: frame.plotBottom + 4
147
+ },
148
+ dot: activeValue == null ? null : {
149
+ className: "meteo-cursor-dot",
150
+ cx: x,
151
+ cy: scale.yAt(activeValue),
152
+ r: 3
153
+ }
154
+ }
155
+ };
156
+ }
157
+ };
158
+ }
159
+ //#endregion
160
+ export { TREND_CLASS, trendFrame, trendGate, trendScene };
@@ -0,0 +1,148 @@
1
+ import { compassDirection, isCalm, thresholdsToMps } from "../derive.js";
2
+ import { roundSpeed } from "../format.js";
3
+ import { bandPoints, compareTracePoints, compareWindow, historyGaps, isCalmHistory, thinVanes, windowPoints } from "../geometry.js";
4
+ import { calmNoteText, displaySpeedScales, gapHatchPattern, gapHatchRect, gradedMeanTrace, speedGridLines, stretchedChartFrame, vaneCells, vaneGuideLines, vaneTickTexts, windRowLabels, windThresholdGuides, windZoneRects } from "./wind-plot.js";
5
+ //#region src/scene/wind-history.ts
6
+ const WIND_CHART_CLASS = "meteo-wind-chart";
7
+ function windChartGate(station, words) {
8
+ if (!station.capabilities.history) return { kind: "hidden" };
9
+ const history = station.status === "ok" ? station.history : null;
10
+ if (history == null || history.points.length < 2) return {
11
+ kind: "note",
12
+ className: `${WIND_CHART_CLASS} meteo-wind-chart-na`,
13
+ text: words.noHistory
14
+ };
15
+ return {
16
+ kind: "draw",
17
+ history
18
+ };
19
+ }
20
+ function windChartScene(input) {
21
+ const { compareOffsetDays, formatTime, hatchId, history, plotHeight, stationName, thresholds, unit, width, windowHours, words } = input;
22
+ const points = windowPoints(history.points, windowHours);
23
+ const shown = (speedMps) => roundSpeed(speedMps, unit);
24
+ const frame = stretchedChartFrame(width, plotHeight);
25
+ const scales = displaySpeedScales(points, frame, unit);
26
+ const band = bandPoints(points, scales);
27
+ const vanes = thinVanes(points);
28
+ const gaps = historyGaps({
29
+ ...history,
30
+ points
31
+ });
32
+ const comparePoints = compareOffsetDays == null ? null : compareWindow(history.points, compareOffsetDays, windowHours);
33
+ const compareTrace = comparePoints == null || compareOffsetDays == null ? null : compareTracePoints(comparePoints, scales, compareOffsetDays);
34
+ const boundsMps = thresholds == null ? null : thresholdsToMps(thresholds);
35
+ return {
36
+ frame,
37
+ scales,
38
+ points,
39
+ readout: {
40
+ ariaLabel: words.aria.readout(stationName),
41
+ className: "meteo-wind-chart-readout"
42
+ },
43
+ svg: {
44
+ ariaLabel: words.aria.chart(stationName),
45
+ className: "meteo-wind-chart-svg",
46
+ height: frame.height,
47
+ viewBox: `0 0 ${frame.width} ${frame.height}`,
48
+ width: frame.width
49
+ },
50
+ defs: {
51
+ pattern: gapHatchPattern(hatchId),
52
+ clip: {
53
+ id: `${hatchId}-plot`,
54
+ rect: {
55
+ height: frame.plotBottom - frame.plotTop,
56
+ width: frame.right - frame.left,
57
+ x: frame.left,
58
+ y: frame.plotTop
59
+ }
60
+ }
61
+ },
62
+ zones: windZoneRects(boundsMps, frame, scales),
63
+ grid: speedGridLines(frame, scales, shown),
64
+ thresholdGuides: windThresholdGuides(thresholds, boundsMps, unit, frame, scales, shown),
65
+ vaneGuides: vaneGuideLines(vanes, frame, scales),
66
+ gaps: gaps.map(([startMs, endMs]) => gapHatchRect(hatchId, frame, startMs, scales.xAtMs(startMs), scales.xAtMs(endMs) - scales.xAtMs(startMs))),
67
+ band: band == null ? null : {
68
+ className: "meteo-wind-band",
69
+ points: band
70
+ },
71
+ compare: compareTrace == null ? null : {
72
+ className: "meteo-wind-compare",
73
+ clipPath: `url(#${hatchId}-plot)`,
74
+ points: compareTrace
75
+ },
76
+ mean: gradedMeanTrace(points, scales, boundsMps),
77
+ calmNote: isCalmHistory(points) ? calmNoteText(frame, words) : null,
78
+ rowLabels: windRowLabels(frame, words),
79
+ vanes: vaneCells(vanes, frame, scales, (vane) => String(shown(vane.windAvgMps))),
80
+ ticks: vaneTickTexts(vanes, frame, scales, (timeMs) => formatTime(new Date(timeMs))),
81
+ hit: {
82
+ className: "meteo-hit",
83
+ fill: "transparent",
84
+ height: frame.height,
85
+ width: frame.width,
86
+ x: 0,
87
+ y: 0
88
+ },
89
+ inspect: (activeIndex) => {
90
+ const active = activeIndex == null ? void 0 : points[activeIndex];
91
+ if (active == null) return {
92
+ readout: {
93
+ strong: `${formatTime(new Date(scales.startMs))}–${formatTime(new Date(scales.endMs))}`,
94
+ span: [{
95
+ kind: "text",
96
+ text: words.inspectHint
97
+ }]
98
+ },
99
+ cursor: null
100
+ };
101
+ const lead = `${words.avgLabel} ${shown(active.windAvgMps)} · ${words.lullLabel} ${active.windLullMps == null ? "—" : shown(active.windLullMps)} · ${words.gustLabel} ${active.windGustMps == null ? "—" : shown(active.windGustMps)} ${words.speedUnits[unit]} · `;
102
+ const span = isCalm(active.windAvgMps) ? [{
103
+ kind: "text",
104
+ text: `${lead}${words.calm}`
105
+ }] : active.windDirectionDeg == null ? [{
106
+ kind: "text",
107
+ text: `${lead}—`
108
+ }] : [
109
+ {
110
+ kind: "text",
111
+ text: `${lead}${words.fromLabel} `
112
+ },
113
+ {
114
+ kind: "arrow",
115
+ deg: active.windDirectionDeg
116
+ },
117
+ {
118
+ kind: "text",
119
+ text: ` ${compassDirection(active.windDirectionDeg)} ${Math.round(active.windDirectionDeg)}°`
120
+ }
121
+ ];
122
+ const x = scales.xAt(active.observedAt);
123
+ return {
124
+ readout: {
125
+ strong: formatTime(new Date(active.observedAt)),
126
+ span
127
+ },
128
+ cursor: {
129
+ line: {
130
+ className: "meteo-cursor",
131
+ x1: x,
132
+ x2: x,
133
+ y1: frame.plotTop,
134
+ y2: frame.vaneRow + 9
135
+ },
136
+ dot: {
137
+ className: "meteo-cursor-dot",
138
+ cx: x,
139
+ cy: scales.yAt(active.windAvgMps),
140
+ r: 3
141
+ }
142
+ }
143
+ };
144
+ }
145
+ };
146
+ }
147
+ //#endregion
148
+ export { WIND_CHART_CLASS, windChartGate, windChartScene };
@@ -0,0 +1,214 @@
1
+ import { compassDirection, speedToMps } from "../derive.js";
2
+ import { averagePoints, chartFrame, chartScales, speedBand, stretchFrame, vanePath, vaneTicks } from "../geometry.js";
3
+ import { tickAnchor } from "./chart.js";
4
+ //#region src/scene/wind-plot.ts
5
+ function stretchedChartFrame(width, plotHeight) {
6
+ const core = chartFrame(width);
7
+ const corePlotHeight = core.plotBottom - core.plotTop;
8
+ return stretchFrame(core, plotHeight ?? (width < 520 ? corePlotHeight : Math.max(corePlotHeight, 160)));
9
+ }
10
+ function displaySpeedScales(points, frame, unit) {
11
+ return chartScales(points, frame, {
12
+ niceStepMps: speedToMps(5, unit),
13
+ floorMps: speedToMps(10, unit)
14
+ });
15
+ }
16
+ function speedGridLines(frame, scales, shown) {
17
+ return [
18
+ 0,
19
+ .5,
20
+ 1
21
+ ].map((fraction) => {
22
+ const gridY = frame.plotBottom - fraction * (frame.plotBottom - frame.plotTop);
23
+ return {
24
+ key: fraction,
25
+ line: {
26
+ className: "meteo-grid-line",
27
+ x1: frame.left,
28
+ x2: frame.right,
29
+ y1: gridY,
30
+ y2: gridY
31
+ },
32
+ label: {
33
+ className: "meteo-grid-label",
34
+ anchor: "end",
35
+ x: frame.left - 6,
36
+ y: gridY + 5,
37
+ text: String(shown(scales.scaleMax * fraction))
38
+ }
39
+ };
40
+ });
41
+ }
42
+ function windThresholdGuides(thresholds, boundsMps, unit, frame, scales, shown) {
43
+ if (thresholds == null || boundsMps == null) return [];
44
+ return boundsMps.map((boundMps, index) => ({
45
+ boundMps,
46
+ label: unit === thresholds.unit ? String(thresholds.values[index]) : String(shown(boundMps))
47
+ })).filter(({ boundMps }) => boundMps > 0 && boundMps <= scales.scaleMax).map(({ boundMps, label }) => ({
48
+ key: boundMps,
49
+ line: {
50
+ className: `meteo-wind-threshold meteo-band-${speedBand(boundMps, boundsMps)}`,
51
+ x1: frame.left,
52
+ x2: frame.right,
53
+ y1: scales.yAt(boundMps),
54
+ y2: scales.yAt(boundMps)
55
+ },
56
+ label: {
57
+ className: `meteo-wind-threshold-label meteo-band-${speedBand(boundMps, boundsMps)}`,
58
+ anchor: "end",
59
+ x: frame.right - 3,
60
+ y: scales.yAt(boundMps) - 3,
61
+ text: label
62
+ }
63
+ }));
64
+ }
65
+ function windZoneRects(boundsMps, frame, scales) {
66
+ if (boundsMps == null) return [];
67
+ const cuts = [
68
+ 0,
69
+ ...boundsMps.filter((bound) => bound > 0 && bound < scales.scaleMax),
70
+ scales.scaleMax
71
+ ];
72
+ return cuts.slice(0, -1).map((lower, index) => {
73
+ const upper = cuts[index + 1];
74
+ return {
75
+ key: lower,
76
+ className: `meteo-wind-zone meteo-band-${speedBand((lower + upper) / 2, boundsMps)}`,
77
+ height: scales.yAt(lower) - scales.yAt(upper),
78
+ width: frame.right - frame.left,
79
+ x: frame.left,
80
+ y: scales.yAt(upper)
81
+ };
82
+ });
83
+ }
84
+ function vaneGuideLines(vanes, frame, scales) {
85
+ return vanes.map((vane) => ({
86
+ key: vane.midMs,
87
+ className: "meteo-wind-guide",
88
+ x1: scales.xAtMs(vane.midMs),
89
+ x2: scales.xAtMs(vane.midMs),
90
+ y1: frame.plotTop,
91
+ y2: frame.vaneRow - 9
92
+ }));
93
+ }
94
+ function gapHatchPattern(hatchId) {
95
+ return {
96
+ id: hatchId,
97
+ width: "6",
98
+ height: "6",
99
+ transform: "rotate(45)",
100
+ units: "userSpaceOnUse",
101
+ line: {
102
+ className: "meteo-wind-gap-hatch",
103
+ x1: "0",
104
+ x2: "0",
105
+ y1: "0",
106
+ y2: "6"
107
+ }
108
+ };
109
+ }
110
+ function gapHatchRect(hatchId, frame, key, x, width) {
111
+ return {
112
+ key,
113
+ className: "meteo-wind-gap",
114
+ fill: `url(#${hatchId})`,
115
+ height: frame.plotBottom - frame.plotTop,
116
+ width,
117
+ x,
118
+ y: frame.plotTop
119
+ };
120
+ }
121
+ function gradedMeanTrace(points, scales, boundsMps) {
122
+ if (boundsMps == null) return {
123
+ kind: "polyline",
124
+ className: "meteo-wind-mean",
125
+ points: averagePoints(points, scales)
126
+ };
127
+ return {
128
+ kind: "segments",
129
+ segments: points.slice(1).map((point, index) => {
130
+ const previous = points[index];
131
+ return {
132
+ key: point.observedAt,
133
+ className: `meteo-wind-mean-segment meteo-band-${speedBand((previous.windAvgMps + point.windAvgMps) / 2, boundsMps)}`,
134
+ x1: scales.xAt(previous.observedAt),
135
+ x2: scales.xAt(point.observedAt),
136
+ y1: scales.yAt(previous.windAvgMps),
137
+ y2: scales.yAt(point.windAvgMps)
138
+ };
139
+ })
140
+ };
141
+ }
142
+ function calmNoteText(frame, words) {
143
+ return {
144
+ className: "meteo-wind-calm-note",
145
+ anchor: "middle",
146
+ x: (frame.left + frame.right) / 2,
147
+ y: (frame.plotTop + frame.plotBottom) / 2 + 4,
148
+ text: words.calmHistory
149
+ };
150
+ }
151
+ function windRowLabels(frame, words) {
152
+ return {
153
+ to: {
154
+ className: "meteo-wind-row-label",
155
+ anchor: "end",
156
+ x: frame.left - 8,
157
+ y: frame.vaneRow + 4,
158
+ text: words.toLabel
159
+ },
160
+ avg: {
161
+ className: "meteo-wind-row-label",
162
+ anchor: "end",
163
+ x: frame.left - 8,
164
+ y: frame.valueRow + 4,
165
+ text: words.avgLabel
166
+ }
167
+ };
168
+ }
169
+ function vaneCells(vanes, frame, scales, valueText) {
170
+ return vanes.map((vane) => ({
171
+ key: vane.midMs,
172
+ mark: vane.windDirectionDeg == null ? {
173
+ kind: "calm",
174
+ text: {
175
+ className: "meteo-wind-vane-calm",
176
+ anchor: "middle",
177
+ x: scales.xAtMs(vane.midMs),
178
+ y: frame.vaneRow + 4,
179
+ text: "—"
180
+ }
181
+ } : {
182
+ kind: "vane",
183
+ className: "meteo-wind-vane",
184
+ d: vanePath(scales.xAtMs(vane.midMs), frame.vaneRow, vane.windDirectionDeg)
185
+ },
186
+ label: {
187
+ className: "meteo-wind-vane-label",
188
+ anchor: "middle",
189
+ x: scales.xAtMs(vane.midMs),
190
+ y: frame.vaneLabelRow + 4,
191
+ text: vane.windDirectionDeg == null ? "—" : compassDirection(vane.windDirectionDeg)
192
+ },
193
+ value: {
194
+ className: "meteo-wind-vane-value",
195
+ anchor: "middle",
196
+ x: scales.xAtMs(vane.midMs),
197
+ y: frame.valueRow + 4,
198
+ text: valueText(vane)
199
+ }
200
+ }));
201
+ }
202
+ function vaneTickTexts(vanes, frame, scales, labelText) {
203
+ const ticks = vaneTicks(vanes, scales);
204
+ return ticks.map(({ index, timeMs, x }) => ({
205
+ key: index,
206
+ className: "meteo-tick",
207
+ anchor: tickAnchor(index, ticks.length - 1),
208
+ x,
209
+ y: frame.labelRow,
210
+ text: labelText(timeMs)
211
+ }));
212
+ }
213
+ //#endregion
214
+ export { calmNoteText, displaySpeedScales, gapHatchPattern, gapHatchRect, gradedMeanTrace, speedGridLines, stretchedChartFrame, vaneCells, vaneGuideLines, vaneTickTexts, windRowLabels, windThresholdGuides, windZoneRects };
@@ -0,0 +1,28 @@
1
+ import { History, Reading, Station, StationMeta } from "../contract.js";
2
+ import { ResolvedEnvironment, ServerEnvironment } from "./environment.js";
3
+ //#region src/server/adapter.d.ts
4
+ type StationAdapterMode = "full" | "current";
5
+ type StationAdapterOptions = {
6
+ historyHours?: number;
7
+ mode?: StationAdapterMode;
8
+ environment?: ServerEnvironment;
9
+ };
10
+ type StationAdapterContext<O extends StationAdapterOptions = StationAdapterOptions> = {
11
+ readonly environment: ResolvedEnvironment;
12
+ readonly historyHours: number;
13
+ readonly mode: StationAdapterMode;
14
+ readonly options: O;
15
+ };
16
+ type StationAdapterResult = {
17
+ readonly reading: Reading;
18
+ readonly history: History | null;
19
+ readonly meta?: Partial<StationMeta>;
20
+ };
21
+ type StationAdapterDefinition<C, O extends StationAdapterOptions = StationAdapterOptions> = {
22
+ readonly meta: (config: C) => StationMeta;
23
+ readonly load: (config: C, context: StationAdapterContext<O>) => Promise<StationAdapterResult>;
24
+ };
25
+ type StationAdapter<C, O extends StationAdapterOptions = StationAdapterOptions> = (config: C, options?: O) => Promise<Station>;
26
+ declare function defineStationAdapter<C, O extends StationAdapterOptions = StationAdapterOptions>(definition: StationAdapterDefinition<C, O>): StationAdapter<C, O>;
27
+ //#endregion
28
+ export { StationAdapter, StationAdapterContext, StationAdapterDefinition, StationAdapterMode, StationAdapterOptions, StationAdapterResult, defineStationAdapter };
@@ -0,0 +1,32 @@
1
+ import { unavailableStation } from "../contract.js";
2
+ import { logUpstreamFailure, resolveEnvironment, unavailableReasonForError } from "./environment.js";
3
+ import "./feed.js";
4
+ //#region src/server/adapter.ts
5
+ function defineStationAdapter(definition) {
6
+ return async (config, options) => {
7
+ const resolved = options ?? {};
8
+ const environment = resolveEnvironment(resolved.environment);
9
+ const mode = resolved.mode ?? "full";
10
+ const meta = definition.meta(config);
11
+ try {
12
+ const result = await definition.load(config, {
13
+ environment,
14
+ historyHours: resolved.historyHours ?? 6,
15
+ mode,
16
+ options: resolved
17
+ });
18
+ return {
19
+ ...meta,
20
+ ...result.meta,
21
+ status: "ok",
22
+ reading: result.reading,
23
+ history: mode === "current" ? null : result.history
24
+ };
25
+ } catch (error) {
26
+ logUpstreamFailure(environment, `${meta.name} live wind unavailable`, error, { station: meta.id });
27
+ return unavailableStation(meta, unavailableReasonForError(error));
28
+ }
29
+ };
30
+ }
31
+ //#endregion
32
+ export { defineStationAdapter };
@@ -0,0 +1,112 @@
1
+ import { HistoryPoint, Reading, Station } from "../../contract.js";
2
+ import { CampbellStationConfig } from "../config.js";
3
+ import { StationAdapter, StationAdapterOptions } from "../adapter.js";
4
+ //#region src/server/adapters/campbell.d.ts
5
+ type CampbellAdapterOptions = StationAdapterOptions;
6
+ type CampbellField = {
7
+ name: string;
8
+ process: string;
9
+ type: string;
10
+ units: string;
11
+ };
12
+ type CampbellRecord = {
13
+ time: string;
14
+ vals: unknown[];
15
+ };
16
+ type CampbellTable = {
17
+ fields: CampbellField[];
18
+ records: CampbellRecord[];
19
+ };
20
+ type TableRole = "current" | "history";
21
+ declare const CAMPBELL_FIELD_CONTRACTS: {
22
+ readonly current: readonly [{
23
+ readonly name: "Wind_Speed";
24
+ readonly process: "Avg";
25
+ readonly type: "xsd:float";
26
+ readonly units: "kilometers/hour";
27
+ }, {
28
+ readonly name: "Wind_Lull";
29
+ readonly process: "Min";
30
+ readonly type: "xsd:float";
31
+ readonly units: "kilometers/hour";
32
+ }, {
33
+ readonly name: "Wind_Gust";
34
+ readonly process: "Max";
35
+ readonly type: "xsd:float";
36
+ readonly units: "kilometers/hour";
37
+ }, {
38
+ readonly name: "WindDir";
39
+ readonly process: "Smp";
40
+ readonly type: "xsd:float";
41
+ readonly units: "degrees";
42
+ }];
43
+ readonly history: readonly [{
44
+ readonly name: "Temp";
45
+ readonly process: "Smp";
46
+ readonly type: "xsd:float";
47
+ readonly units: "Deg C";
48
+ }, {
49
+ readonly name: "Wind_Chill";
50
+ readonly process: "Smp";
51
+ readonly type: "xsd:float";
52
+ readonly units: "Deg C";
53
+ }, {
54
+ readonly name: "WindDir";
55
+ readonly process: "Smp";
56
+ readonly type: "xsd:float";
57
+ readonly units: "degrees";
58
+ }, {
59
+ readonly name: "WS_kph_Max";
60
+ readonly process: "Max";
61
+ readonly type: "xsd:float";
62
+ readonly units: "kilometers/hour";
63
+ }, {
64
+ readonly name: "WS_kph_Avg";
65
+ readonly process: "Avg";
66
+ readonly type: "xsd:float";
67
+ readonly units: "kilometers/hour";
68
+ }, {
69
+ readonly name: "WS_kph_Min";
70
+ readonly process: "Min";
71
+ readonly type: "xsd:float";
72
+ readonly units: "kilometers/hour";
73
+ }];
74
+ };
75
+ type CampbellTableExpectation = {
76
+ role: TableRole;
77
+ tableName: string;
78
+ stationName: string;
79
+ intervalMs: number;
80
+ subject: string;
81
+ };
82
+ declare const loadCampbellStation: StationAdapter<{
83
+ baseUrl: string;
84
+ source: string;
85
+ timeZone: string;
86
+ currentTable: string;
87
+ historyTable: string;
88
+ currentIntervalSeconds: number;
89
+ historyPeriodMinutes: number;
90
+ currentCacheTtlSeconds: number;
91
+ id: string;
92
+ name: string;
93
+ vendor: "campbell";
94
+ pageUrl?: string | null | undefined;
95
+ elevationM?: number | null | undefined;
96
+ latitude?: number | null | undefined;
97
+ longitude?: number | null | undefined;
98
+ }, StationAdapterOptions>;
99
+ declare function loadCampbellCurrent(config: CampbellStationConfig, options?: CampbellAdapterOptions): Promise<Station>;
100
+ declare function parseCampbellCurrent(value: string, config: CampbellStationConfig, nowMs?: number): Reading;
101
+ declare function parseCampbellHistory(value: string, config: CampbellStationConfig): {
102
+ points: HistoryPoint[];
103
+ latestTemperatureC: number;
104
+ latestWindChillC: number;
105
+ };
106
+ declare function parseCampbellTable(value: string, expectation: CampbellTableExpectation): CampbellTable;
107
+ declare function naiveLocalToIso(naive: string, timeZone: string, context?: {
108
+ afterMs?: number | null;
109
+ nearMs?: number;
110
+ }): string;
111
+ //#endregion
112
+ export { CAMPBELL_FIELD_CONTRACTS, CampbellAdapterOptions, CampbellTable, CampbellTableExpectation, loadCampbellCurrent, loadCampbellStation, naiveLocalToIso, parseCampbellCurrent, parseCampbellHistory, parseCampbellTable };