@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,333 @@
1
+ import { KMH_PER_MPS, isCalm, normalizeDegrees, radians } from "./derive.js";
2
+ import { componentsToWind, meanDirectionDeg, windToComponents } from "@azohra/meteo.core";
3
+ //#region src/geometry.ts
4
+ const CHART_AXIS_GUTTER = 46;
5
+ function chartFrame(width) {
6
+ const plotHeight = width < 520 ? 76 : 116;
7
+ const plotTop = 10;
8
+ const plotBottom = plotTop + plotHeight;
9
+ return {
10
+ height: plotBottom + 64,
11
+ labelRow: plotBottom + 58,
12
+ left: CHART_AXIS_GUTTER,
13
+ plotBottom,
14
+ plotTop,
15
+ right: Math.max(86, width - 6),
16
+ vaneLabelRow: plotBottom + 12,
17
+ vaneRow: plotBottom + 26,
18
+ valueRow: plotBottom + 40,
19
+ width
20
+ };
21
+ }
22
+ const DEFAULT_NICE_STEP_MPS = 5 / KMH_PER_MPS;
23
+ const DEFAULT_FLOOR_MPS = 10 / KMH_PER_MPS;
24
+ function chartScales(points, frame, options = {}) {
25
+ const niceStepMps = options.niceStepMps ?? DEFAULT_NICE_STEP_MPS;
26
+ const floorMps = options.floorMps ?? DEFAULT_FLOOR_MPS;
27
+ const first = points[0];
28
+ const startMs = first ? Date.parse(first.observedAt) : 0;
29
+ const last = points[points.length - 1];
30
+ const endMs = last ? Date.parse(last.observedAt) : startMs;
31
+ const durationMs = Math.max(1, endMs - startMs);
32
+ const top = points.reduce((max, point) => Math.max(max, point.windGustMps ?? point.windAvgMps), 0);
33
+ const scaleMax = Math.max(floorMps, Math.ceil(top / niceStepMps) * niceStepMps);
34
+ const xAtMs = (ms) => frame.left + (ms - startMs) / durationMs * (frame.right - frame.left);
35
+ return {
36
+ startMs,
37
+ endMs,
38
+ durationMs,
39
+ scaleMax,
40
+ xAtMs,
41
+ xAt: (observedAt) => xAtMs(Date.parse(observedAt)),
42
+ yAt: (speedMps) => frame.plotBottom - speedMps / scaleMax * (frame.plotBottom - frame.plotTop)
43
+ };
44
+ }
45
+ function valueScale(values, frame, options) {
46
+ let low = Infinity;
47
+ let high = -Infinity;
48
+ for (const value of values) {
49
+ if (value == null) continue;
50
+ if (value < low) low = value;
51
+ if (value > high) high = value;
52
+ }
53
+ if (low > high) {
54
+ low = 0;
55
+ high = 0;
56
+ }
57
+ const min = low - options.paddingMin;
58
+ const max = high + options.paddingMin;
59
+ return {
60
+ min,
61
+ max,
62
+ yAt: (value) => frame.plotBottom - (value - min) / (max - min) * (frame.plotBottom - frame.plotTop)
63
+ };
64
+ }
65
+ const coordinate = (x, y) => `${x.toFixed(1)},${y.toFixed(1)}`;
66
+ function bandPoints(points, scales) {
67
+ if (points.length === 0) return null;
68
+ if (points.some((point) => point.windGustMps == null || point.windLullMps == null)) return null;
69
+ const gust = points.map((point) => coordinate(scales.xAt(point.observedAt), scales.yAt(point.windGustMps)));
70
+ const lull = [...points].reverse().map((point) => coordinate(scales.xAt(point.observedAt), scales.yAt(point.windLullMps)));
71
+ return [...gust, ...lull].join(" ");
72
+ }
73
+ function averagePoints(points, scales) {
74
+ return points.map((point) => coordinate(scales.xAt(point.observedAt), scales.yAt(point.windAvgMps))).join(" ");
75
+ }
76
+ function meanDirectionDeg$1(points) {
77
+ return meanDirectionDeg(points.filter((point) => !isCalm(point.windAvgMps) && point.windDirectionDeg != null).map((point) => point.windDirectionDeg));
78
+ }
79
+ function vectorMeanWind(points) {
80
+ if (points.length === 0) return {
81
+ windDirectionDeg: null,
82
+ speedMps: 0
83
+ };
84
+ let u = 0;
85
+ let v = 0;
86
+ for (const point of points) {
87
+ if (point.windDirectionDeg == null) continue;
88
+ const components = windToComponents(point.windAvgMps, point.windDirectionDeg);
89
+ u += components.uMps;
90
+ v += components.vMps;
91
+ }
92
+ const mean = componentsToWind(u / points.length, v / points.length);
93
+ return {
94
+ windDirectionDeg: mean.speedMps < .5 ? null : mean.directionDeg,
95
+ speedMps: mean.speedMps
96
+ };
97
+ }
98
+ function thinVanes(points, target = 13) {
99
+ if (points.length === 0) return [];
100
+ const step = Math.max(1, Math.round(points.length / target));
101
+ return Array.from({ length: Math.ceil(points.length / step) }, (_, index) => {
102
+ const startIndex = index * step;
103
+ const endIndex = startIndex + step;
104
+ const window = points.slice(startIndex, endIndex);
105
+ const first = Date.parse(window[0].observedAt);
106
+ const last = Date.parse(window[window.length - 1].observedAt);
107
+ return {
108
+ windAvgMps: window.reduce((sum, point) => sum + point.windAvgMps, 0) / window.length,
109
+ windDirectionDeg: meanDirectionDeg$1(window),
110
+ endIndex,
111
+ midMs: first + (last - first) / 2,
112
+ startIndex
113
+ };
114
+ });
115
+ }
116
+ function vanePath(cx, cy, fromBearingDeg, { reach = 7, spread = 3.2 } = {}) {
117
+ const angle = radians(fromBearingDeg + 180);
118
+ const sin = Math.sin(angle);
119
+ const cos = Math.cos(angle);
120
+ const tip = [cx + sin * reach, cy - cos * reach];
121
+ const tail = [cx - sin * reach, cy + cos * reach];
122
+ const left = [tip[0] - sin * spread + cos * spread, tip[1] + cos * spread + sin * spread];
123
+ const right = [tip[0] - sin * spread - cos * spread, tip[1] + cos * spread - sin * spread];
124
+ const at = ([px, py]) => `${px.toFixed(1)} ${py.toFixed(1)}`;
125
+ return `M ${at(tail)} L ${at(tip)} M ${at(left)} L ${at(tip)} L ${at(right)}`;
126
+ }
127
+ function vaneTicks(vanes, scales) {
128
+ if (vanes.length === 0) return [];
129
+ return [
130
+ 0,
131
+ .25,
132
+ .5,
133
+ .75,
134
+ 1
135
+ ].map((fraction, index) => {
136
+ const vane = vanes[Math.round(fraction * (vanes.length - 1))];
137
+ return {
138
+ index,
139
+ timeMs: vane.midMs,
140
+ x: scales.xAtMs(vane.midMs)
141
+ };
142
+ });
143
+ }
144
+ function nearestIndex(points, chartX, frame, scales) {
145
+ if (points.length === 0) return null;
146
+ const ms = scales.startMs + (chartX - frame.left) / (frame.right - frame.left) * scales.durationMs;
147
+ return points.reduce((nearest, point, index) => Math.abs(Date.parse(point.observedAt) - ms) < Math.abs(Date.parse(points[nearest].observedAt) - ms) ? index : nearest, 0);
148
+ }
149
+ function isCalmHistory(points) {
150
+ return points.every((point) => isCalm(point.windGustMps ?? point.windAvgMps));
151
+ }
152
+ function speedBand(speedMps, thresholdsMps) {
153
+ let band = 0;
154
+ for (const bound of thresholdsMps) {
155
+ if (speedMps < bound) return band;
156
+ band += 1;
157
+ }
158
+ return band;
159
+ }
160
+ function windRose(points, sectorCount = 16) {
161
+ const sectorWidth = 360 / sectorCount;
162
+ const sectors = Array.from({ length: sectorCount }, (_, index) => ({
163
+ bearingDeg: index * sectorWidth,
164
+ speeds: [],
165
+ gusts: []
166
+ }));
167
+ let calm = 0;
168
+ let counted = 0;
169
+ for (const point of points) {
170
+ counted += 1;
171
+ if (isCalm(point.windAvgMps) || point.windDirectionDeg == null) {
172
+ calm += 1;
173
+ continue;
174
+ }
175
+ const sector = sectors[Math.round(normalizeDegrees(point.windDirectionDeg) / sectorWidth) % sectorCount];
176
+ sector.speeds.push(point.windAvgMps);
177
+ if (point.windGustMps != null) sector.gusts.push(point.windGustMps);
178
+ }
179
+ const blowing = counted - calm;
180
+ return {
181
+ sampleCount: counted,
182
+ calmFraction: counted === 0 ? 0 : calm / counted,
183
+ sectors: sectors.map((sector) => ({
184
+ bearingDeg: sector.bearingDeg,
185
+ count: sector.speeds.length,
186
+ frequency: blowing === 0 ? 0 : sector.speeds.length / blowing,
187
+ meanSpeedMps: sector.speeds.length === 0 ? null : sector.speeds.reduce((sum, speed) => sum + speed, 0) / sector.speeds.length,
188
+ maxGustMps: sector.gusts.length === 0 ? null : Math.max(...sector.gusts)
189
+ }))
190
+ };
191
+ }
192
+ const DAILY_PATTERN_DEFAULT_SLOT_MINUTES = 180;
193
+ function dailyPattern(points, options = {}) {
194
+ const slotMinutes = options.slotMinutes ?? 180;
195
+ if (slotMinutes <= 0 || 1440 % slotMinutes !== 0) throw new Error(`dailyPattern: slotMinutes must evenly divide 1440, got ${slotMinutes}`);
196
+ const utcOffsetMinutes = options.utcOffsetMinutes ?? 0;
197
+ const slotCount = 1440 / slotMinutes;
198
+ const buckets = Array.from({ length: slotCount }, () => []);
199
+ for (const point of points) {
200
+ const minuteOfDay = floorMod(Math.floor(Date.parse(point.observedAt) / 6e4) + utcOffsetMinutes, 1440);
201
+ buckets[Math.floor(minuteOfDay / slotMinutes)].push(point);
202
+ }
203
+ return buckets.map((bucket, index) => ({
204
+ startMinuteOfDay: index * slotMinutes,
205
+ sampleCount: bucket.length,
206
+ ...vectorMeanWind(bucket)
207
+ }));
208
+ }
209
+ function floorMod(value, modulus) {
210
+ return (value % modulus + modulus) % modulus;
211
+ }
212
+ const METEOROLOGICAL_SEASON_MONTHS = {
213
+ winter: [
214
+ 12,
215
+ 1,
216
+ 2
217
+ ],
218
+ spring: [
219
+ 3,
220
+ 4,
221
+ 5
222
+ ],
223
+ summer: [
224
+ 6,
225
+ 7,
226
+ 8
227
+ ],
228
+ fall: [
229
+ 9,
230
+ 10,
231
+ 11
232
+ ]
233
+ };
234
+ function filterByMonth(points, months, utcOffsetMinutes = 0) {
235
+ const wanted = new Set(months);
236
+ return points.filter((point) => wanted.has(localMonth(point.observedAt, utcOffsetMinutes)));
237
+ }
238
+ function localMonth(observedAt, utcOffsetMinutes) {
239
+ return new Date(Date.parse(observedAt) + utcOffsetMinutes * 6e4).getUTCMonth() + 1;
240
+ }
241
+ function filterByTimeOfDay(points, fromMinute, toMinute, utcOffsetMinutes = 0) {
242
+ const wraps = fromMinute > toMinute;
243
+ return points.filter((point) => {
244
+ const minute = floorMod(Math.floor(Date.parse(point.observedAt) / 6e4) + utcOffsetMinutes, 1440);
245
+ return wraps ? minute >= fromMinute || minute < toMinute : minute >= fromMinute && minute < toMinute;
246
+ });
247
+ }
248
+ const HISTORY_GAP_TOLERANCE_FACTOR = 2.5;
249
+ function historyGaps(history, toleranceFactor = HISTORY_GAP_TOLERANCE_FACTOR) {
250
+ const gaps = [];
251
+ const limit = history.periodMinutes * 6e4 * toleranceFactor;
252
+ for (let index = 1; index < history.points.length; index += 1) {
253
+ const previous = Date.parse(history.points[index - 1].observedAt);
254
+ const current = Date.parse(history.points[index].observedAt);
255
+ if (current - previous > limit) gaps.push([previous, current]);
256
+ }
257
+ return gaps;
258
+ }
259
+ function stretchFrame(frame, plotHeight) {
260
+ const delta = plotHeight - (frame.plotBottom - frame.plotTop);
261
+ if (delta === 0) return frame;
262
+ return {
263
+ ...frame,
264
+ height: frame.height + delta,
265
+ labelRow: frame.labelRow + delta,
266
+ plotBottom: frame.plotBottom + delta,
267
+ vaneLabelRow: frame.vaneLabelRow + delta,
268
+ vaneRow: frame.vaneRow + delta,
269
+ valueRow: frame.valueRow + delta
270
+ };
271
+ }
272
+ function trendValueOf(point, series) {
273
+ return series === "temperature" ? point.temperatureC : point.seaLevelPressureHpa ?? null;
274
+ }
275
+ function trendSeriesPad(series) {
276
+ return series === "temperature" ? 1 : 2;
277
+ }
278
+ function trendRuns(points, series, periodMinutes) {
279
+ const gapLimitMs = periodMinutes * 6e4 * HISTORY_GAP_TOLERANCE_FACTOR;
280
+ const runs = [];
281
+ let run = null;
282
+ let previousMs = Number.NEGATIVE_INFINITY;
283
+ for (const point of points) {
284
+ const value = trendValueOf(point, series);
285
+ const ms = Date.parse(point.observedAt);
286
+ if ((value == null || ms - previousMs > gapLimitMs) && run != null) {
287
+ runs.push(run);
288
+ run = null;
289
+ }
290
+ if (value != null) {
291
+ run ??= {
292
+ startedAt: point.observedAt,
293
+ samples: []
294
+ };
295
+ run.samples.push([ms, value]);
296
+ }
297
+ previousMs = ms;
298
+ }
299
+ if (run != null) runs.push(run);
300
+ return runs;
301
+ }
302
+ const HOUR_MS = 36e5;
303
+ const DAY_MS = 864e5;
304
+ function windowPoints(points, hours) {
305
+ if (hours == null || points.length === 0) return points;
306
+ const cutoffMs = Date.parse(points[points.length - 1].observedAt) - hours * HOUR_MS;
307
+ return points.filter((point) => Date.parse(point.observedAt) >= cutoffMs);
308
+ }
309
+ function compareWindow(points, offsetDays, windowHours) {
310
+ const displayed = windowPoints(points, windowHours);
311
+ if (displayed.length === 0) return null;
312
+ const shiftMs = offsetDays * DAY_MS;
313
+ const startMs = Date.parse(displayed[0].observedAt) - shiftMs;
314
+ const endMs = Date.parse(displayed[displayed.length - 1].observedAt) - shiftMs;
315
+ const window = points.filter((point) => {
316
+ const ms = Date.parse(point.observedAt);
317
+ return ms >= startMs && ms <= endMs;
318
+ });
319
+ if (window.length === 0) return null;
320
+ const firstMs = Date.parse(points[0].observedAt);
321
+ const lastMs = Date.parse(points[points.length - 1].observedAt);
322
+ const tolerance = (points.length > 1 ? (lastMs - firstMs) / (points.length - 1) : 0) * HISTORY_GAP_TOLERANCE_FACTOR;
323
+ const matchedStartMs = Date.parse(window[0].observedAt);
324
+ const matchedEndMs = Date.parse(window[window.length - 1].observedAt);
325
+ if (matchedStartMs - startMs > tolerance || endMs - matchedEndMs > tolerance) return null;
326
+ return window;
327
+ }
328
+ function compareTracePoints(comparePoints, scales, offsetDays) {
329
+ const shiftMs = offsetDays * DAY_MS;
330
+ return comparePoints.map((point) => coordinate(scales.xAtMs(Date.parse(point.observedAt) + shiftMs), scales.yAt(point.windAvgMps))).join(" ");
331
+ }
332
+ //#endregion
333
+ export { DAILY_PATTERN_DEFAULT_SLOT_MINUTES, HISTORY_GAP_TOLERANCE_FACTOR, METEOROLOGICAL_SEASON_MONTHS, averagePoints, bandPoints, chartFrame, chartScales, compareTracePoints, compareWindow, dailyPattern, filterByMonth, filterByTimeOfDay, historyGaps, isCalmHistory, meanDirectionDeg$1 as meanDirectionDeg, nearestIndex, speedBand, stretchFrame, thinVanes, trendRuns, trendSeriesPad, trendValueOf, valueScale, vanePath, vaneTicks, vectorMeanWind, windRose, windowPoints };
@@ -0,0 +1,12 @@
1
+ import { AirConditions, History, HistoryPoint, Reading, STATION_SCHEMA_VERSION, Station, StationCapabilities, StationCurrent, StationFeed, StationMeta, UNAVAILABLE_REASONS, UnavailableReason, airConditionsSchema, capabilitiesSchema, emptyConditions, historyPointSchema, historySchema, parseStationCurrent, parseStationCurrentJson, parseStationFeed, parseStationFeedJson, readingSchema, stationCurrentSchema, stationFeedSchema, stationMetaSchema, stationSchema, unavailableStation } from "./contract.js";
2
+ import { CALM_THRESHOLD_MPS, CompassPoint, FreshnessStatus, FreshnessThresholds, PeriodSummary, PressureTendency, SpeedThresholds, SpeedUnit, compassDirection, freshness, isCalm, normalizeDegrees, periodSummary, pressureTendency, seaLevelPressureHpa, speedFromMps, speedToMps, speedUnitLabel, stationFreshnessThresholds, thresholdsToMps } from "./derive.js";
3
+ import { FormatTime, StationStringOverrides, StationStrings, defaultFormatTime, defaultStrings, localeFormatTime, mergeStringOverrides, resolveStrings } from "./strings.js";
4
+ import { DirectionCellData, SummaryEntry, directionCell, optionalSpeed, roundSpeed, summaryEntries, temperatureText, temperatureValue, updatedAtText } from "./format.js";
5
+ import { DisplayDefaults, DisplayProps, ResolvedDisplay, requireResolved, resolveDisplay, resolveStation } from "./display.js";
6
+ import { currentEndpoint, feedEndpoint } from "./endpoints.js";
7
+ import { ChartFrame, ChartScaleOptions, ChartScales, ChartTick, DAILY_PATTERN_DEFAULT_SLOT_MINUTES, DailyPatternSlot, METEOROLOGICAL_SEASON_MONTHS, RoseSector, Vane, WindRoseSummary, averagePoints, bandPoints, chartFrame, chartScales, compareTracePoints, compareWindow, dailyPattern, filterByMonth, filterByTimeOfDay, historyGaps, speedBand, thinVanes, vanePath, vaneTicks, windRose, windowPoints } from "./geometry.js";
8
+ import { DIAL_CARDINALS, DIAL_CARDINAL_TICK_INNER, DIAL_CENTRE, DIAL_COUNTERWEIGHT_RADIUS, DIAL_COUNTERWEIGHT_REACH, DIAL_HUB_RADIUS, DIAL_LETTER_RADIUS, DIAL_MIN_MAX_MPS, DIAL_RING_RADIUS, DIAL_SIZE, DIAL_TICK_INNER, FavorableDirection, HistoryRun, ROSE_CARDINAL_LETTERS, ROSE_CENTRE, ROSE_FAVORABLE_RING_RADIUS, ROSE_HUB_DOT_RADIUS, ROSE_HUB_RADIUS, ROSE_INTERCARDINAL_BEARINGS, ROSE_LETTER_RADIUS, ROSE_MAX_RADIUS, ROSE_PETAL_FILL, ROSE_SIZE, ROSE_TICK_REACH, SPARKLINE_EDGE_INSET, SPARKLINE_MAX_PADDING, bandStrips, dialNeedlePoints, dialPolar, dialScaleMaxMps, dialSpeedArcPath, historyRuns, rosePetalPath, rosePolar, roseRingArcPath, sparklineScale } from "./instruments.js";
9
+ import { MergeResult, foldCurrent, mergeCurrent } from "./merge-current.js";
10
+ import { AirRow, airRows, airSummary, lastStrikeWords } from "./air.js";
11
+ import { normalizeWindnerdStationKey, windnerdStationUrl } from "./windnerd.js";
12
+ export { type AirConditions, type AirRow, CALM_THRESHOLD_MPS, type ChartFrame, type ChartScaleOptions, type ChartScales, type ChartTick, type CompassPoint, DAILY_PATTERN_DEFAULT_SLOT_MINUTES, DIAL_CARDINALS, DIAL_CARDINAL_TICK_INNER, DIAL_CENTRE, DIAL_COUNTERWEIGHT_RADIUS, DIAL_COUNTERWEIGHT_REACH, DIAL_HUB_RADIUS, DIAL_LETTER_RADIUS, DIAL_MIN_MAX_MPS, DIAL_RING_RADIUS, DIAL_SIZE, DIAL_TICK_INNER, type DailyPatternSlot, type DirectionCellData, type DisplayDefaults, type DisplayProps, type FavorableDirection, type FormatTime, type FreshnessStatus, type FreshnessThresholds, type History, type HistoryPoint, type HistoryRun, METEOROLOGICAL_SEASON_MONTHS, type MergeResult, type PeriodSummary, type PressureTendency, ROSE_CARDINAL_LETTERS, ROSE_CENTRE, ROSE_FAVORABLE_RING_RADIUS, ROSE_HUB_DOT_RADIUS, ROSE_HUB_RADIUS, ROSE_INTERCARDINAL_BEARINGS, ROSE_LETTER_RADIUS, ROSE_MAX_RADIUS, ROSE_PETAL_FILL, ROSE_SIZE, ROSE_TICK_REACH, type Reading, type ResolvedDisplay, type RoseSector, SPARKLINE_EDGE_INSET, SPARKLINE_MAX_PADDING, STATION_SCHEMA_VERSION, type SpeedThresholds, type SpeedUnit, type Station, type StationCapabilities, type StationCurrent, type StationFeed, type StationMeta, type StationStringOverrides, type StationStrings, type SummaryEntry, UNAVAILABLE_REASONS, type UnavailableReason, type Vane, type WindRoseSummary, airConditionsSchema, airRows, airSummary, averagePoints, bandPoints, bandStrips, capabilitiesSchema, chartFrame, chartScales, compareTracePoints, compareWindow, compassDirection, currentEndpoint, dailyPattern, defaultFormatTime, defaultStrings, dialNeedlePoints, dialPolar, dialScaleMaxMps, dialSpeedArcPath, directionCell, emptyConditions, feedEndpoint, filterByMonth, filterByTimeOfDay, foldCurrent, freshness, historyGaps, historyPointSchema, historyRuns, historySchema, isCalm, lastStrikeWords, localeFormatTime, mergeCurrent, mergeStringOverrides, normalizeDegrees, normalizeWindnerdStationKey, optionalSpeed, parseStationCurrent, parseStationCurrentJson, parseStationFeed, parseStationFeedJson, periodSummary, pressureTendency, readingSchema, requireResolved, resolveDisplay, resolveStation, resolveStrings, rosePetalPath, rosePolar, roseRingArcPath, roundSpeed, seaLevelPressureHpa, sparklineScale, speedBand, speedFromMps, speedToMps, speedUnitLabel, stationCurrentSchema, stationFeedSchema, stationFreshnessThresholds, stationMetaSchema, stationSchema, summaryEntries, temperatureText, temperatureValue, thinVanes, thresholdsToMps, unavailableStation, updatedAtText, vanePath, vaneTicks, windRose, windnerdStationUrl, windowPoints };
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ import { STATION_SCHEMA_VERSION, UNAVAILABLE_REASONS, airConditionsSchema, capabilitiesSchema, emptyConditions, historyPointSchema, historySchema, parseStationCurrent, parseStationCurrentJson, parseStationFeed, parseStationFeedJson, readingSchema, stationCurrentSchema, stationFeedSchema, stationMetaSchema, stationSchema, unavailableStation } from "./contract.js";
2
+ import { CALM_THRESHOLD_MPS, compassDirection, freshness, isCalm, normalizeDegrees, periodSummary, pressureTendency, seaLevelPressureHpa, speedFromMps, speedToMps, speedUnitLabel, stationFreshnessThresholds, thresholdsToMps } from "./derive.js";
3
+ import { defaultFormatTime, defaultStrings, localeFormatTime, mergeStringOverrides, resolveStrings } from "./strings.js";
4
+ import { requireResolved, resolveDisplay, resolveStation } from "./display.js";
5
+ import { currentEndpoint, feedEndpoint } from "./endpoints.js";
6
+ import { directionCell, optionalSpeed, roundSpeed, summaryEntries, temperatureText, temperatureValue, updatedAtText } from "./format.js";
7
+ import { DAILY_PATTERN_DEFAULT_SLOT_MINUTES, METEOROLOGICAL_SEASON_MONTHS, averagePoints, bandPoints, chartFrame, chartScales, compareTracePoints, compareWindow, dailyPattern, filterByMonth, filterByTimeOfDay, historyGaps, speedBand, thinVanes, vanePath, vaneTicks, windRose, windowPoints } from "./geometry.js";
8
+ import { DIAL_CARDINALS, DIAL_CARDINAL_TICK_INNER, DIAL_CENTRE, DIAL_COUNTERWEIGHT_RADIUS, DIAL_COUNTERWEIGHT_REACH, DIAL_HUB_RADIUS, DIAL_LETTER_RADIUS, DIAL_MIN_MAX_MPS, DIAL_RING_RADIUS, DIAL_SIZE, DIAL_TICK_INNER, ROSE_CARDINAL_LETTERS, ROSE_CENTRE, ROSE_FAVORABLE_RING_RADIUS, ROSE_HUB_DOT_RADIUS, ROSE_HUB_RADIUS, ROSE_INTERCARDINAL_BEARINGS, ROSE_LETTER_RADIUS, ROSE_MAX_RADIUS, ROSE_PETAL_FILL, ROSE_SIZE, ROSE_TICK_REACH, SPARKLINE_EDGE_INSET, SPARKLINE_MAX_PADDING, bandStrips, dialNeedlePoints, dialPolar, dialScaleMaxMps, dialSpeedArcPath, historyRuns, rosePetalPath, rosePolar, roseRingArcPath, sparklineScale } from "./instruments.js";
9
+ import { foldCurrent, mergeCurrent } from "./merge-current.js";
10
+ import { airRows, airSummary, lastStrikeWords } from "./air.js";
11
+ import { normalizeWindnerdStationKey, windnerdStationUrl } from "./windnerd.js";
12
+ export { CALM_THRESHOLD_MPS, DAILY_PATTERN_DEFAULT_SLOT_MINUTES, DIAL_CARDINALS, DIAL_CARDINAL_TICK_INNER, DIAL_CENTRE, DIAL_COUNTERWEIGHT_RADIUS, DIAL_COUNTERWEIGHT_REACH, DIAL_HUB_RADIUS, DIAL_LETTER_RADIUS, DIAL_MIN_MAX_MPS, DIAL_RING_RADIUS, DIAL_SIZE, DIAL_TICK_INNER, METEOROLOGICAL_SEASON_MONTHS, ROSE_CARDINAL_LETTERS, ROSE_CENTRE, ROSE_FAVORABLE_RING_RADIUS, ROSE_HUB_DOT_RADIUS, ROSE_HUB_RADIUS, ROSE_INTERCARDINAL_BEARINGS, ROSE_LETTER_RADIUS, ROSE_MAX_RADIUS, ROSE_PETAL_FILL, ROSE_SIZE, ROSE_TICK_REACH, SPARKLINE_EDGE_INSET, SPARKLINE_MAX_PADDING, STATION_SCHEMA_VERSION, UNAVAILABLE_REASONS, airConditionsSchema, airRows, airSummary, averagePoints, bandPoints, bandStrips, capabilitiesSchema, chartFrame, chartScales, compareTracePoints, compareWindow, compassDirection, currentEndpoint, dailyPattern, defaultFormatTime, defaultStrings, dialNeedlePoints, dialPolar, dialScaleMaxMps, dialSpeedArcPath, directionCell, emptyConditions, feedEndpoint, filterByMonth, filterByTimeOfDay, foldCurrent, freshness, historyGaps, historyPointSchema, historyRuns, historySchema, isCalm, lastStrikeWords, localeFormatTime, mergeCurrent, mergeStringOverrides, normalizeDegrees, normalizeWindnerdStationKey, optionalSpeed, parseStationCurrent, parseStationCurrentJson, parseStationFeed, parseStationFeedJson, periodSummary, pressureTendency, readingSchema, requireResolved, resolveDisplay, resolveStation, resolveStrings, rosePetalPath, rosePolar, roseRingArcPath, roundSpeed, seaLevelPressureHpa, sparklineScale, speedBand, speedFromMps, speedToMps, speedUnitLabel, stationCurrentSchema, stationFeedSchema, stationFreshnessThresholds, stationMetaSchema, stationSchema, summaryEntries, temperatureText, temperatureValue, thinVanes, thresholdsToMps, unavailableStation, updatedAtText, vanePath, vaneTicks, windRose, windnerdStationUrl, windowPoints };
@@ -0,0 +1,75 @@
1
+ import { HistoryPoint } from "./contract.js";
2
+ import { SpeedUnit } from "./derive.js";
3
+ //#region src/instruments.d.ts
4
+ declare const DIAL_SIZE = 160;
5
+ declare const DIAL_CENTRE: number;
6
+ declare const DIAL_RING_RADIUS = 70;
7
+ declare const DIAL_TICK_INNER = 64;
8
+ declare const DIAL_CARDINAL_TICK_INNER = 58;
9
+ declare const DIAL_LETTER_RADIUS = 46;
10
+ declare const DIAL_HUB_RADIUS = 36;
11
+ declare const DIAL_COUNTERWEIGHT_RADIUS = 4.5;
12
+ declare const DIAL_COUNTERWEIGHT_REACH = 46;
13
+ declare const DIAL_MIN_MAX_MPS: number;
14
+ declare function dialPolar(bearingDeg: number, radius: number): readonly [number, number];
15
+ declare function dialNeedlePoints(fromDeg: number): string;
16
+ declare function dialSpeedArcPath(fraction: number): string;
17
+ declare function dialScaleMaxMps(windAvgMps: number | null, windGustMps: number | null, unit: SpeedUnit): number;
18
+ declare const DIAL_CARDINALS: readonly [{
19
+ readonly bearing: 0;
20
+ readonly letter: "N";
21
+ }, {
22
+ readonly bearing: 90;
23
+ readonly letter: "E";
24
+ }, {
25
+ readonly bearing: 180;
26
+ readonly letter: "S";
27
+ }, {
28
+ readonly bearing: 270;
29
+ readonly letter: "W";
30
+ }];
31
+ declare const ROSE_SIZE = 190;
32
+ declare const ROSE_CENTRE: number;
33
+ declare const ROSE_MAX_RADIUS = 70;
34
+ declare const ROSE_FAVORABLE_RING_RADIUS = 75;
35
+ declare const ROSE_HUB_RADIUS = 16;
36
+ declare const ROSE_HUB_DOT_RADIUS = 3;
37
+ declare const ROSE_LETTER_RADIUS = 82;
38
+ declare const ROSE_TICK_REACH = 4;
39
+ declare const ROSE_PETAL_FILL = 0.82;
40
+ declare function rosePolar(bearingDeg: number, radius: number): readonly [number, number];
41
+ declare function rosePetalPath(bearingDeg: number, radius: number, halfWidthDeg: number): string;
42
+ type FavorableDirection = {
43
+ fromDeg: number;
44
+ toDeg: number;
45
+ };
46
+ declare function roseRingArcPath(sector: FavorableDirection): string;
47
+ declare const ROSE_CARDINAL_LETTERS: readonly [{
48
+ readonly bearing: 0;
49
+ readonly letter: "N";
50
+ }, {
51
+ readonly bearing: 90;
52
+ readonly letter: "E";
53
+ }, {
54
+ readonly bearing: 180;
55
+ readonly letter: "S";
56
+ }, {
57
+ readonly bearing: 270;
58
+ readonly letter: "W";
59
+ }];
60
+ declare const ROSE_INTERCARDINAL_BEARINGS: readonly [45, 135, 225, 315];
61
+ declare const SPARKLINE_EDGE_INSET = 1;
62
+ declare const SPARKLINE_MAX_PADDING = 1.1;
63
+ declare function sparklineScale(points: ReadonlyArray<HistoryPoint>, width: number, height: number): {
64
+ scaleMax: number;
65
+ xAt(ms: number): number;
66
+ yAt(speedMps: number): number;
67
+ };
68
+ type HistoryRun = {
69
+ startedAt: string;
70
+ points: HistoryPoint[];
71
+ };
72
+ declare function historyRuns(points: ReadonlyArray<HistoryPoint>, periodMinutes: number): HistoryRun[];
73
+ declare function bandStrips(runs: ReadonlyArray<HistoryRun>): HistoryRun[];
74
+ //#endregion
75
+ export { DIAL_CARDINALS, DIAL_CARDINAL_TICK_INNER, DIAL_CENTRE, DIAL_COUNTERWEIGHT_RADIUS, DIAL_COUNTERWEIGHT_REACH, DIAL_HUB_RADIUS, DIAL_LETTER_RADIUS, DIAL_MIN_MAX_MPS, DIAL_RING_RADIUS, DIAL_SIZE, DIAL_TICK_INNER, FavorableDirection, HistoryRun, ROSE_CARDINAL_LETTERS, ROSE_CENTRE, ROSE_FAVORABLE_RING_RADIUS, ROSE_HUB_DOT_RADIUS, ROSE_HUB_RADIUS, ROSE_INTERCARDINAL_BEARINGS, ROSE_LETTER_RADIUS, ROSE_MAX_RADIUS, ROSE_PETAL_FILL, ROSE_SIZE, ROSE_TICK_REACH, SPARKLINE_EDGE_INSET, SPARKLINE_MAX_PADDING, bandStrips, dialNeedlePoints, dialPolar, dialScaleMaxMps, dialSpeedArcPath, historyRuns, rosePetalPath, rosePolar, roseRingArcPath, sparklineScale };
@@ -0,0 +1,173 @@
1
+ import { COMPASS_POINTS, KMH_PER_MPS, normalizeDegrees, radians, speedToMps } from "./derive.js";
2
+ import { HISTORY_GAP_TOLERANCE_FACTOR } from "./geometry.js";
3
+ //#region src/instruments.ts
4
+ const DIAL_SIZE = 160;
5
+ const DIAL_CENTRE = 160 / 2;
6
+ const DIAL_RING_RADIUS = 70;
7
+ const DIAL_TICK_INNER = 64;
8
+ const DIAL_CARDINAL_TICK_INNER = 58;
9
+ const DIAL_LETTER_RADIUS = 46;
10
+ const DIAL_HUB_RADIUS = 36;
11
+ const DIAL_NEEDLE_REACH = 60;
12
+ const DIAL_NEEDLE_HALF_WIDTH = 5;
13
+ const DIAL_COUNTERWEIGHT_RADIUS = 4.5;
14
+ const DIAL_COUNTERWEIGHT_REACH = 46;
15
+ const DIAL_MIN_MAX_MPS = 40 / KMH_PER_MPS;
16
+ const roundCoordinate = (value) => Math.round(value * 1e3) / 1e3;
17
+ function dialPolar(bearingDeg, radius) {
18
+ const angle = radians(bearingDeg);
19
+ return [roundCoordinate(80 + Math.sin(angle) * radius), roundCoordinate(80 - Math.cos(angle) * radius)];
20
+ }
21
+ const dialAt = ([x, y]) => `${x.toFixed(1)},${y.toFixed(1)}`;
22
+ function dialNeedlePoints(fromDeg) {
23
+ const flowDeg = fromDeg + 180;
24
+ const tip = dialPolar(flowDeg, DIAL_NEEDLE_REACH);
25
+ const left = dialPolar(flowDeg + 90, DIAL_NEEDLE_HALF_WIDTH);
26
+ const right = dialPolar(flowDeg - 90, DIAL_NEEDLE_HALF_WIDTH);
27
+ return `${dialAt(tip)} ${dialAt(left)} ${dialAt(right)}`;
28
+ }
29
+ function dialSpeedArcPath(fraction) {
30
+ const sweepDeg = Math.min(359.9, Math.max(0, fraction) * 360);
31
+ const start = dialPolar(0, 70);
32
+ const end = dialPolar(sweepDeg, 70);
33
+ return `M ${start[0].toFixed(1)} ${start[1].toFixed(1)} A 70 70 0 ${sweepDeg > 180 ? 1 : 0} 1 ${end[0].toFixed(1)} ${end[1].toFixed(1)}`;
34
+ }
35
+ function dialScaleMaxMps(windAvgMps, windGustMps, unit) {
36
+ const stepMps = speedToMps(10, unit);
37
+ return Math.max(DIAL_MIN_MAX_MPS, Math.ceil(Math.max(windGustMps ?? 0, windAvgMps ?? 0) / stepMps) * stepMps);
38
+ }
39
+ const DIAL_CARDINALS = [
40
+ {
41
+ bearing: 0,
42
+ letter: COMPASS_POINTS[0]
43
+ },
44
+ {
45
+ bearing: 90,
46
+ letter: COMPASS_POINTS[4]
47
+ },
48
+ {
49
+ bearing: 180,
50
+ letter: COMPASS_POINTS[8]
51
+ },
52
+ {
53
+ bearing: 270,
54
+ letter: COMPASS_POINTS[12]
55
+ }
56
+ ];
57
+ const ROSE_SIZE = 190;
58
+ const ROSE_CENTRE = 190 / 2;
59
+ const ROSE_MAX_RADIUS = 70;
60
+ const ROSE_FAVORABLE_RING_RADIUS = 75;
61
+ const ROSE_HUB_RADIUS = 16;
62
+ const ROSE_HUB_DOT_RADIUS = 3;
63
+ const ROSE_LETTER_RADIUS = 82;
64
+ const ROSE_TICK_REACH = 4;
65
+ const ROSE_PETAL_FILL = .82;
66
+ function rosePolar(bearingDeg, radius) {
67
+ const angle = radians(bearingDeg);
68
+ return [roundCoordinate(95 + Math.sin(angle) * radius), roundCoordinate(95 - Math.cos(angle) * radius)];
69
+ }
70
+ const roseAt = ([x, y]) => `${x.toFixed(1)} ${y.toFixed(1)}`;
71
+ function rosePetalPath(bearingDeg, radius, halfWidthDeg) {
72
+ const outerLeft = rosePolar(bearingDeg - halfWidthDeg, radius);
73
+ const outerRight = rosePolar(bearingDeg + halfWidthDeg, radius);
74
+ const innerLeft = rosePolar(bearingDeg - halfWidthDeg, 16);
75
+ const innerRight = rosePolar(bearingDeg + halfWidthDeg, 16);
76
+ return [
77
+ `M ${roseAt(innerLeft)}`,
78
+ `L ${roseAt(outerLeft)}`,
79
+ `A ${radius.toFixed(1)} ${radius.toFixed(1)} 0 0 1 ${roseAt(outerRight)}`,
80
+ `L ${roseAt(innerRight)}`,
81
+ `A 16 16 0 0 0 ${roseAt(innerLeft)}`,
82
+ "Z"
83
+ ].join(" ");
84
+ }
85
+ function roseRingArcPath(sector) {
86
+ const from = normalizeDegrees(sector.fromDeg);
87
+ const span = normalizeDegrees(sector.toDeg - sector.fromDeg);
88
+ const start = rosePolar(from, 75);
89
+ const end = rosePolar(from + span, 75);
90
+ return `M ${roseAt(start)} A 75 75 0 ${span > 180 ? 1 : 0} 1 ${roseAt(end)}`;
91
+ }
92
+ const ROSE_CARDINAL_LETTERS = [
93
+ {
94
+ bearing: 0,
95
+ letter: "N"
96
+ },
97
+ {
98
+ bearing: 90,
99
+ letter: "E"
100
+ },
101
+ {
102
+ bearing: 180,
103
+ letter: "S"
104
+ },
105
+ {
106
+ bearing: 270,
107
+ letter: "W"
108
+ }
109
+ ];
110
+ const ROSE_INTERCARDINAL_BEARINGS = [
111
+ 45,
112
+ 135,
113
+ 225,
114
+ 315
115
+ ];
116
+ const SPARKLINE_EDGE_INSET = 1;
117
+ const SPARKLINE_MAX_PADDING = 1.1;
118
+ function sparklineScale(points, width, height) {
119
+ const first = points[0];
120
+ const last = points[points.length - 1];
121
+ const startMs = first ? Date.parse(first.observedAt) : 0;
122
+ const durationMs = Math.max(1, (last ? Date.parse(last.observedAt) : startMs) - startMs);
123
+ const top = points.reduce((max, point) => Math.max(max, point.windGustMps ?? point.windAvgMps), 0);
124
+ const scaleMax = top > 0 ? top * SPARKLINE_MAX_PADDING : 1;
125
+ return {
126
+ scaleMax,
127
+ xAt: (ms) => 1 + (ms - startMs) / durationMs * (width - 2),
128
+ yAt: (speedMps) => height - 1 - speedMps / scaleMax * (height - 2)
129
+ };
130
+ }
131
+ function historyRuns(points, periodMinutes) {
132
+ const gapLimitMs = periodMinutes * 6e4 * HISTORY_GAP_TOLERANCE_FACTOR;
133
+ const runs = [];
134
+ let run = null;
135
+ let previousMs = Number.NEGATIVE_INFINITY;
136
+ for (const point of points) {
137
+ const ms = Date.parse(point.observedAt);
138
+ if (run != null && ms - previousMs > gapLimitMs) run = null;
139
+ if (run == null) {
140
+ run = {
141
+ startedAt: point.observedAt,
142
+ points: []
143
+ };
144
+ runs.push(run);
145
+ }
146
+ run.points.push(point);
147
+ previousMs = ms;
148
+ }
149
+ return runs;
150
+ }
151
+ function bandStrips(runs) {
152
+ const strips = [];
153
+ for (const segment of runs) {
154
+ let strip = null;
155
+ for (const point of segment.points) {
156
+ if (point.windGustMps == null || point.windLullMps == null) {
157
+ strip = null;
158
+ continue;
159
+ }
160
+ if (strip == null) {
161
+ strip = {
162
+ startedAt: point.observedAt,
163
+ points: []
164
+ };
165
+ strips.push(strip);
166
+ }
167
+ strip.points.push(point);
168
+ }
169
+ }
170
+ return strips;
171
+ }
172
+ //#endregion
173
+ export { DIAL_CARDINALS, DIAL_CARDINAL_TICK_INNER, DIAL_CENTRE, DIAL_COUNTERWEIGHT_RADIUS, DIAL_COUNTERWEIGHT_REACH, DIAL_HUB_RADIUS, DIAL_LETTER_RADIUS, DIAL_MIN_MAX_MPS, DIAL_RING_RADIUS, DIAL_SIZE, DIAL_TICK_INNER, ROSE_CARDINAL_LETTERS, ROSE_CENTRE, ROSE_FAVORABLE_RING_RADIUS, ROSE_HUB_DOT_RADIUS, ROSE_HUB_RADIUS, ROSE_INTERCARDINAL_BEARINGS, ROSE_LETTER_RADIUS, ROSE_MAX_RADIUS, ROSE_PETAL_FILL, ROSE_SIZE, ROSE_TICK_REACH, SPARKLINE_EDGE_INSET, SPARKLINE_MAX_PADDING, bandStrips, dialNeedlePoints, dialPolar, dialScaleMaxMps, dialSpeedArcPath, historyRuns, rosePetalPath, rosePolar, roseRingArcPath, sparklineScale };
@@ -0,0 +1,13 @@
1
+ import { StationCurrent, StationFeed } from "./contract.js";
2
+ //#region src/merge-current.d.ts
3
+ type MergeResult = {
4
+ feed: StationFeed;
5
+ merged: boolean;
6
+ };
7
+ declare function mergeCurrent(feed: StationFeed, current: StationCurrent): MergeResult;
8
+ declare function foldCurrent(feed: StationFeed | null, feedReceivedAtMs: number | null, current: StationCurrent | null, currentReceivedAtMs: number | null): {
9
+ feed: StationFeed | null;
10
+ receivedAtMs: number | null;
11
+ };
12
+ //#endregion
13
+ export { MergeResult, foldCurrent, mergeCurrent };
@@ -0,0 +1,54 @@
1
+ //#region src/merge-current.ts
2
+ function preserveOmitted(incoming, prior) {
3
+ if (prior == null) return incoming;
4
+ return {
5
+ ...incoming,
6
+ temperatureC: incoming.temperatureC ?? prior.temperatureC,
7
+ windChillC: incoming.windChillC ?? prior.windChillC,
8
+ conditions: incoming.conditions ?? prior.conditions
9
+ };
10
+ }
11
+ function mergeCurrent(feed, current) {
12
+ const incoming = current.station;
13
+ if (incoming.status !== "ok") return {
14
+ feed,
15
+ merged: false
16
+ };
17
+ if (!feed.stations.some((station) => station.id === incoming.id)) return {
18
+ feed,
19
+ merged: false
20
+ };
21
+ return {
22
+ feed: {
23
+ ...feed,
24
+ servedAt: current.servedAt,
25
+ stations: feed.stations.map((station) => {
26
+ if (station.id !== incoming.id) return station;
27
+ const prior = station.status === "ok" ? station : null;
28
+ return {
29
+ ...incoming,
30
+ reading: preserveOmitted(incoming.reading, prior?.reading ?? null),
31
+ history: prior?.history ?? null
32
+ };
33
+ })
34
+ },
35
+ merged: true
36
+ };
37
+ }
38
+ function foldCurrent(feed, feedReceivedAtMs, current, currentReceivedAtMs) {
39
+ if (feed == null) return {
40
+ feed: null,
41
+ receivedAtMs: null
42
+ };
43
+ if (current == null) return {
44
+ feed,
45
+ receivedAtMs: feedReceivedAtMs
46
+ };
47
+ const result = mergeCurrent(feed, current);
48
+ return {
49
+ feed: result.feed,
50
+ receivedAtMs: result.merged ? currentReceivedAtMs : feedReceivedAtMs
51
+ };
52
+ }
53
+ //#endregion
54
+ export { foldCurrent, mergeCurrent };