@azohra/meteo.station 0.3.1 → 0.5.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 (138) hide show
  1. package/dist/client/climatology.d.ts +27 -0
  2. package/dist/client/climatology.js +83 -0
  3. package/dist/client/history.d.ts +47 -0
  4. package/dist/client/history.js +112 -0
  5. package/dist/client/index.d.ts +3 -1
  6. package/dist/client/index.js +3 -1
  7. package/dist/client/live.js +15 -0
  8. package/dist/climatology.d.ts +66 -0
  9. package/dist/climatology.js +230 -0
  10. package/dist/contract-climatology.d.ts +73 -0
  11. package/dist/contract-climatology.js +52 -0
  12. package/dist/contract.d.ts +234 -1
  13. package/dist/contract.js +52 -4
  14. package/dist/derive.d.ts +23 -1
  15. package/dist/derive.js +43 -4
  16. package/dist/display.d.ts +4 -0
  17. package/dist/display.js +2 -1
  18. package/dist/elements/elements/AirExtremesElement.d.ts +8 -0
  19. package/dist/elements/elements/AirExtremesElement.js +33 -0
  20. package/dist/elements/elements/ClimatologyDailyPatternElement.d.ts +15 -0
  21. package/dist/elements/elements/ClimatologyDailyPatternElement.js +84 -0
  22. package/dist/elements/elements/ClimatologyRoseElement.d.ts +14 -0
  23. package/dist/elements/elements/ClimatologyRoseElement.js +51 -0
  24. package/dist/elements/elements/CompassFanElement.d.ts +14 -0
  25. package/dist/elements/elements/CompassFanElement.js +92 -0
  26. package/dist/elements/elements/DailyPatternElement.d.ts +1 -0
  27. package/dist/elements/elements/DailyPatternElement.js +24 -16
  28. package/dist/elements/elements/DialElement.js +14 -3
  29. package/dist/elements/elements/FavorableShareElement.d.ts +14 -0
  30. package/dist/elements/elements/FavorableShareElement.js +47 -0
  31. package/dist/elements/elements/RecentSummariesElement.d.ts +14 -0
  32. package/dist/elements/elements/RecentSummariesElement.js +54 -0
  33. package/dist/elements/elements/StationFeedElement.d.ts +3 -0
  34. package/dist/elements/elements/StationFeedElement.js +13 -2
  35. package/dist/elements/elements/WindHistoryChartElement.js +20 -7
  36. package/dist/elements/elements/WindRoseElement.d.ts +1 -3
  37. package/dist/elements/elements/WindRoseElement.js +60 -62
  38. package/dist/elements/elements/atoms.js +3 -3
  39. package/dist/elements/index.d.ts +13 -1
  40. package/dist/elements/index.js +15 -3
  41. package/dist/elements/lib/ambient.d.ts +2 -0
  42. package/dist/elements/lib/attributes.js +24 -1
  43. package/dist/elements/lib/base.d.ts +3 -0
  44. package/dist/elements/lib/base.js +14 -2
  45. package/dist/endpoints.d.ts +7 -1
  46. package/dist/endpoints.js +13 -1
  47. package/dist/geometry.d.ts +23 -4
  48. package/dist/geometry.js +44 -13
  49. package/dist/index.d.ts +8 -6
  50. package/dist/index.js +8 -6
  51. package/dist/instruments.d.ts +7 -5
  52. package/dist/instruments.js +20 -7
  53. package/dist/merge-current.js +2 -1
  54. package/dist/react/components/AirExtremes.d.ts +16 -0
  55. package/dist/react/components/AirExtremes.js +38 -0
  56. package/dist/react/components/ClimatologyDailyPattern.d.ts +20 -0
  57. package/dist/react/components/ClimatologyDailyPattern.js +59 -0
  58. package/dist/react/components/ClimatologyRose.d.ts +18 -0
  59. package/dist/react/components/ClimatologyRose.js +45 -0
  60. package/dist/react/components/CompassFan.d.ts +17 -0
  61. package/dist/react/components/CompassFan.js +93 -0
  62. package/dist/react/components/DailyPattern.d.ts +4 -1
  63. package/dist/react/components/DailyPattern.js +15 -8
  64. package/dist/react/components/Dial.d.ts +3 -1
  65. package/dist/react/components/Dial.js +13 -2
  66. package/dist/react/components/FavorableShare.d.ts +14 -0
  67. package/dist/react/components/FavorableShare.js +43 -0
  68. package/dist/react/components/RecentSummaries.d.ts +18 -0
  69. package/dist/react/components/RecentSummaries.js +64 -0
  70. package/dist/react/components/StationFeedProvider.d.ts +4 -1
  71. package/dist/react/components/StationFeedProvider.js +5 -3
  72. package/dist/react/components/WindHistoryChart.d.ts +6 -1
  73. package/dist/react/components/WindHistoryChart.js +20 -5
  74. package/dist/react/components/WindRose.d.ts +4 -2
  75. package/dist/react/components/WindRose.js +80 -71
  76. package/dist/react/components/WindSampleStrip.d.ts +3 -1
  77. package/dist/react/components/WindSampleStrip.js +8 -5
  78. package/dist/react/components/atoms.d.ts +4 -1
  79. package/dist/react/components/atoms.js +6 -3
  80. package/dist/react/hooks/useStationClimatology.d.ts +18 -0
  81. package/dist/react/hooks/useStationClimatology.js +25 -0
  82. package/dist/react/index.d.ts +10 -3
  83. package/dist/react/index.js +9 -2
  84. package/dist/scene/air-extremes.d.ts +2 -0
  85. package/dist/scene/air-extremes.js +42 -0
  86. package/dist/scene/atoms.d.ts +2 -1
  87. package/dist/scene/atoms.js +6 -4
  88. package/dist/scene/climatology-pattern.d.ts +6 -0
  89. package/dist/scene/climatology-pattern.js +35 -0
  90. package/dist/scene/climatology-rose.d.ts +5 -0
  91. package/dist/scene/climatology-rose.js +49 -0
  92. package/dist/scene/compass-fan.d.ts +3 -0
  93. package/dist/scene/compass-fan.js +115 -0
  94. package/dist/scene/daily-pattern.d.ts +1 -0
  95. package/dist/scene/daily-pattern.js +21 -7
  96. package/dist/scene/dial.d.ts +1 -0
  97. package/dist/scene/dial.js +16 -3
  98. package/dist/scene/favorable-share.d.ts +3 -0
  99. package/dist/scene/favorable-share.js +41 -0
  100. package/dist/scene/index.d.ts +9 -3
  101. package/dist/scene/recent-summaries.d.ts +4 -0
  102. package/dist/scene/recent-summaries.js +75 -0
  103. package/dist/scene/rose.d.ts +2 -1
  104. package/dist/scene/rose.js +18 -3
  105. package/dist/scene/sample-strip.d.ts +1 -0
  106. package/dist/scene/sample-strip.js +1 -1
  107. package/dist/scene/trend.js +2 -7
  108. package/dist/scene/wind-history.d.ts +1 -0
  109. package/dist/scene/wind-history.js +4 -3
  110. package/dist/scene/wind-plot.d.ts +1 -0
  111. package/dist/scene/wind-plot.js +44 -9
  112. package/dist/server/adapter.d.ts +2 -1
  113. package/dist/server/adapter.js +2 -1
  114. package/dist/server/adapters/windnerd-climatology.d.ts +30 -0
  115. package/dist/server/adapters/windnerd-climatology.js +82 -0
  116. package/dist/server/adapters/windnerd-live.d.ts +5 -8
  117. package/dist/server/adapters/windnerd-live.js +26 -21
  118. package/dist/server/adapters/windnerd.d.ts +31 -4
  119. package/dist/server/adapters/windnerd.js +196 -19
  120. package/dist/server/environment.d.ts +4 -10
  121. package/dist/server/environment.js +4 -10
  122. package/dist/server/feed.d.ts +44 -2
  123. package/dist/server/feed.js +63 -2
  124. package/dist/server/handler.d.ts +11 -1
  125. package/dist/server/handler.js +83 -2
  126. package/dist/server/index.d.ts +4 -3
  127. package/dist/server/index.js +4 -3
  128. package/dist/strings.d.ts +13 -1
  129. package/dist/strings.js +13 -1
  130. package/package.json +2 -2
  131. package/schema/example-climatology.json +86 -0
  132. package/schema/example-history.json +38 -0
  133. package/schema/stationclimatology.schema.json +221 -0
  134. package/schema/stationcurrent.schema.json +173 -0
  135. package/schema/stationfeed.schema.json +173 -0
  136. package/schema/stationhistory.schema.json +186 -0
  137. package/schema/stationlive.schema.json +202 -0
  138. package/styles.css +232 -19
@@ -0,0 +1,27 @@
1
+ import { PollError } from "./poll.js";
2
+ import { StationClimatology } from "../contract-climatology.js";
3
+ //#region src/client/climatology.d.ts
4
+ type StationClimatologySnapshot = {
5
+ document: StationClimatology | null;
6
+ receivedAtMs: number | null;
7
+ loading: boolean;
8
+ error: PollError | null;
9
+ };
10
+ type StationClimatologyStore = {
11
+ getSnapshot(): StationClimatologySnapshot;
12
+ subscribe(listener: () => void): () => void;
13
+ /** Fetches once; further calls while a document is held are no-ops. */
14
+ load(): Promise<void>;
15
+ /** Forces a refetch — e.g. after the served document's cache lifetime. */
16
+ refresh(): Promise<void>;
17
+ };
18
+ /**
19
+ * Fetch-once store for the climatology document: near-immutable history
20
+ * needs no poller. Every filter interaction re-aggregates the held cube
21
+ * client-side; only load()/refresh() touch the network.
22
+ */
23
+ declare function createStationClimatologyStore(url: string, options?: {
24
+ fetchInit?: RequestInit;
25
+ }): StationClimatologyStore;
26
+ //#endregion
27
+ export { StationClimatologySnapshot, StationClimatologyStore, createStationClimatologyStore };
@@ -0,0 +1,83 @@
1
+ import { parseStationClimatologyJson } from "../contract-climatology.js";
2
+ //#region src/client/climatology.ts
3
+ const REQUEST_TIMEOUT_MS = 15e3;
4
+ /**
5
+ * Fetch-once store for the climatology document: near-immutable history
6
+ * needs no poller. Every filter interaction re-aggregates the held cube
7
+ * client-side; only load()/refresh() touch the network.
8
+ */
9
+ function createStationClimatologyStore(url, options = {}) {
10
+ let snapshot = {
11
+ document: null,
12
+ receivedAtMs: null,
13
+ loading: false,
14
+ error: null
15
+ };
16
+ const listeners = /* @__PURE__ */ new Set();
17
+ const setSnapshot = (next) => {
18
+ snapshot = next;
19
+ for (const listener of [...listeners]) listener();
20
+ };
21
+ let inFlight = null;
22
+ const fetchDocument = async () => {
23
+ setSnapshot({
24
+ ...snapshot,
25
+ loading: true
26
+ });
27
+ try {
28
+ const response = await fetch(url, {
29
+ ...options.fetchInit,
30
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
31
+ });
32
+ if (!response.ok) {
33
+ setSnapshot({
34
+ ...snapshot,
35
+ loading: false,
36
+ error: {
37
+ kind: "network",
38
+ status: response.status
39
+ }
40
+ });
41
+ return;
42
+ }
43
+ const document = parseStationClimatologyJson(await response.text());
44
+ if (document == null) {
45
+ setSnapshot({
46
+ ...snapshot,
47
+ loading: false,
48
+ error: { kind: "contract" }
49
+ });
50
+ return;
51
+ }
52
+ setSnapshot({
53
+ document,
54
+ receivedAtMs: Date.now(),
55
+ loading: false,
56
+ error: null
57
+ });
58
+ } catch {
59
+ setSnapshot({
60
+ ...snapshot,
61
+ loading: false,
62
+ error: { kind: "network" }
63
+ });
64
+ } finally {
65
+ inFlight = null;
66
+ }
67
+ };
68
+ const refresh = () => {
69
+ inFlight ??= fetchDocument();
70
+ return inFlight;
71
+ };
72
+ return {
73
+ getSnapshot: () => snapshot,
74
+ subscribe: (listener) => {
75
+ listeners.add(listener);
76
+ return () => listeners.delete(listener);
77
+ },
78
+ load: () => snapshot.document != null ? Promise.resolve() : refresh(),
79
+ refresh
80
+ };
81
+ }
82
+ //#endregion
83
+ export { createStationClimatologyStore };
@@ -0,0 +1,47 @@
1
+ import { StationHistory } from "../contract.js";
2
+ //#region src/client/history.d.ts
3
+ declare const HISTORY_STORE_DEFAULT_MAX_WINDOWS = 32;
4
+ type StationHistoryQuery = {
5
+ fromMs: number;
6
+ toMs: number;
7
+ periodMinutes: number;
8
+ };
9
+ /** One requested window in, one parsed document (or null on failure) out.
10
+ * A host that mounts the feed handler uses `stationHistoryFetcher`; a host
11
+ * serving history its own way supplies any function of this shape. */
12
+ type StationHistoryFetcher = (query: StationHistoryQuery) => Promise<StationHistory | null>;
13
+ /** The default fetcher, against the mounted handler's /history route. */
14
+ declare function stationHistoryFetcher(base: string, stationId: string, fetchInit?: RequestInit): StationHistoryFetcher;
15
+ type StationHistoryStore = {
16
+ /** The window's document — cache-served when held, deduplicated while in
17
+ * flight. A failed fetch resolves null and is not cached, so the next
18
+ * ask retries. */
19
+ window(query: StationHistoryQuery): Promise<StationHistory | null>;
20
+ /** Windows currently held. */
21
+ size(): number;
22
+ };
23
+ /** A window-keyed LRU over a fetcher, so pan/zoom revisits cost nothing. */
24
+ declare function createStationHistoryStore(fetcher: StationHistoryFetcher, options?: {
25
+ maxWindows?: number;
26
+ }): StationHistoryStore;
27
+ declare const ARCHIVE_DEFAULT_PERIODS_MINUTES: readonly [1, 5, 10, 15, 30, 60, 180, 360];
28
+ declare const ARCHIVE_TARGET_POINTS = 500;
29
+ type ArchiveWindow = {
30
+ fromMs: number;
31
+ toMs: number;
32
+ };
33
+ /** The finest ladder period that keeps the span at or under the point
34
+ * target; a span too wide for every rung takes the coarsest. */
35
+ declare function archivePeriodFor(spanMs: number, periods?: ReadonlyArray<number>, targetPoints?: number): number;
36
+ /** One whole LOCAL day from a YYYY-MM-DD date-input value (not the UTC
37
+ * day); null when the value is not a real date. */
38
+ declare function archiveDayWindow(dateValue: string): ArchiveWindow | null;
39
+ /** The YYYY-MM-DD value naming an instant's local day. */
40
+ declare function archiveDayValue(atMs: number): string;
41
+ /** The day value deltaDays away. Steps through noon so a DST-shifted
42
+ * midnight cannot skip a day; null for an invalid value. */
43
+ declare function archiveDayStep(dateValue: string, deltaDays: number): string | null;
44
+ /** The trailing 24 h ending at nowMs. */
45
+ declare function archiveTrailingWindow(nowMs: number, spanMs?: number): ArchiveWindow;
46
+ //#endregion
47
+ export { ARCHIVE_DEFAULT_PERIODS_MINUTES, ARCHIVE_TARGET_POINTS, ArchiveWindow, HISTORY_STORE_DEFAULT_MAX_WINDOWS, StationHistoryFetcher, StationHistoryQuery, StationHistoryStore, archiveDayStep, archiveDayValue, archiveDayWindow, archivePeriodFor, archiveTrailingWindow, createStationHistoryStore, stationHistoryFetcher };
@@ -0,0 +1,112 @@
1
+ import { parseStationHistoryJson } from "../contract.js";
2
+ import { historyEndpoint } from "../endpoints.js";
3
+ //#region src/client/history.ts
4
+ const REQUEST_TIMEOUT_MS = 15e3;
5
+ const HISTORY_STORE_DEFAULT_MAX_WINDOWS = 32;
6
+ /** The default fetcher, against the mounted handler's /history route. */
7
+ function stationHistoryFetcher(base, stationId, fetchInit) {
8
+ return async (query) => {
9
+ try {
10
+ const response = await fetch(historyEndpoint(base, stationId, query), {
11
+ ...fetchInit,
12
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
13
+ });
14
+ if (!response.ok) return null;
15
+ return parseStationHistoryJson(await response.text());
16
+ } catch {
17
+ return null;
18
+ }
19
+ };
20
+ }
21
+ /** A window-keyed LRU over a fetcher, so pan/zoom revisits cost nothing. */
22
+ function createStationHistoryStore(fetcher, options = {}) {
23
+ const maxWindows = options.maxWindows ?? 32;
24
+ const held = /* @__PURE__ */ new Map();
25
+ const inFlight = /* @__PURE__ */ new Map();
26
+ const keyOf = (query) => `${query.fromMs}/${query.toMs}/${query.periodMinutes}`;
27
+ return {
28
+ window: (query) => {
29
+ const key = keyOf(query);
30
+ const cached = held.get(key);
31
+ if (cached != null) {
32
+ held.delete(key);
33
+ held.set(key, cached);
34
+ return Promise.resolve(cached);
35
+ }
36
+ const pending = inFlight.get(key);
37
+ if (pending != null) return pending;
38
+ const request = fetcher(query).then((document) => {
39
+ if (document != null) {
40
+ held.set(key, document);
41
+ while (held.size > maxWindows) {
42
+ const oldest = held.keys().next().value;
43
+ if (oldest == null) break;
44
+ held.delete(oldest);
45
+ }
46
+ }
47
+ return document;
48
+ }).finally(() => inFlight.delete(key));
49
+ inFlight.set(key, request);
50
+ return request;
51
+ },
52
+ size: () => held.size
53
+ };
54
+ }
55
+ const ARCHIVE_DEFAULT_PERIODS_MINUTES = [
56
+ 1,
57
+ 5,
58
+ 10,
59
+ 15,
60
+ 30,
61
+ 60,
62
+ 180,
63
+ 360
64
+ ];
65
+ const ARCHIVE_TARGET_POINTS = 500;
66
+ const DAY_MS = 864e5;
67
+ /** The finest ladder period that keeps the span at or under the point
68
+ * target; a span too wide for every rung takes the coarsest. */
69
+ function archivePeriodFor(spanMs, periods = ARCHIVE_DEFAULT_PERIODS_MINUTES, targetPoints = 500) {
70
+ const ascending = [...periods].sort((left, right) => left - right);
71
+ for (const period of ascending) if (spanMs / (period * 6e4) <= targetPoints) return period;
72
+ return ascending[ascending.length - 1];
73
+ }
74
+ /** One whole LOCAL day from a YYYY-MM-DD date-input value (not the UTC
75
+ * day); null when the value is not a real date. */
76
+ function archiveDayWindow(dateValue) {
77
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(dateValue);
78
+ if (!match) return null;
79
+ const [year, month, day] = [
80
+ Number(match[1]),
81
+ Number(match[2]),
82
+ Number(match[3])
83
+ ];
84
+ const at = new Date(year, month - 1, day);
85
+ if (at.getFullYear() !== year || at.getMonth() !== month - 1 || at.getDate() !== day) return null;
86
+ return {
87
+ fromMs: at.getTime(),
88
+ toMs: at.getTime() + DAY_MS
89
+ };
90
+ }
91
+ /** The YYYY-MM-DD value naming an instant's local day. */
92
+ function archiveDayValue(atMs) {
93
+ const at = new Date(atMs);
94
+ const pad = (value) => String(value).padStart(2, "0");
95
+ return `${at.getFullYear()}-${pad(at.getMonth() + 1)}-${pad(at.getDate())}`;
96
+ }
97
+ /** The day value deltaDays away. Steps through noon so a DST-shifted
98
+ * midnight cannot skip a day; null for an invalid value. */
99
+ function archiveDayStep(dateValue, deltaDays) {
100
+ const window = archiveDayWindow(dateValue);
101
+ if (window == null) return null;
102
+ return archiveDayValue(window.fromMs + deltaDays * DAY_MS + DAY_MS / 2);
103
+ }
104
+ /** The trailing 24 h ending at nowMs. */
105
+ function archiveTrailingWindow(nowMs, spanMs = DAY_MS) {
106
+ return {
107
+ fromMs: nowMs - spanMs,
108
+ toMs: nowMs
109
+ };
110
+ }
111
+ //#endregion
112
+ export { ARCHIVE_DEFAULT_PERIODS_MINUTES, ARCHIVE_TARGET_POINTS, HISTORY_STORE_DEFAULT_MAX_WINDOWS, archiveDayStep, archiveDayValue, archiveDayWindow, archivePeriodFor, archiveTrailingWindow, createStationHistoryStore, stationHistoryFetcher };
@@ -1,5 +1,7 @@
1
1
  import { FRESHNESS_REEVALUATE_MS, JsonPoller, JsonPollerOptions, ParseOutcome, PollError, PollSeed, PollSnapshot, REQUEST_TIMEOUT_MS, createJsonPoller } from "./poll.js";
2
2
  import { StationSnapshot, StationStore, createStationCurrentStore, createStationFeedStore, createStationStore, parseCurrentText, parseFeedText } from "./stores.js";
3
3
  import { LIVE_BACKOFF_MAX_MS, LIVE_BACKOFF_MIN_MS, LIVE_IDLE_RECONNECT_MS, LiveStatus, StationLiveSnapshot, StationLiveStore, createStationLiveStore, liveSnapshotToCurrent } from "./live.js";
4
+ import { StationClimatologySnapshot, StationClimatologyStore, createStationClimatologyStore } from "./climatology.js";
5
+ import { ARCHIVE_DEFAULT_PERIODS_MINUTES, ARCHIVE_TARGET_POINTS, ArchiveWindow, HISTORY_STORE_DEFAULT_MAX_WINDOWS, StationHistoryFetcher, StationHistoryQuery, StationHistoryStore, archiveDayStep, archiveDayValue, archiveDayWindow, archivePeriodFor, archiveTrailingWindow, createStationHistoryStore, stationHistoryFetcher } from "./history.js";
4
6
  import { subscribeTicker } from "./ticker.js";
5
- export { FRESHNESS_REEVALUATE_MS, type JsonPoller, type JsonPollerOptions, LIVE_BACKOFF_MAX_MS, LIVE_BACKOFF_MIN_MS, LIVE_IDLE_RECONNECT_MS, type LiveStatus, type ParseOutcome, type PollError, type PollSeed, type PollSnapshot, REQUEST_TIMEOUT_MS, type StationLiveSnapshot, type StationLiveStore, type StationSnapshot, type StationStore, createJsonPoller, createStationCurrentStore, createStationFeedStore, createStationLiveStore, createStationStore, liveSnapshotToCurrent, parseCurrentText, parseFeedText, subscribeTicker };
7
+ export { ARCHIVE_DEFAULT_PERIODS_MINUTES, ARCHIVE_TARGET_POINTS, type ArchiveWindow, FRESHNESS_REEVALUATE_MS, HISTORY_STORE_DEFAULT_MAX_WINDOWS, type JsonPoller, type JsonPollerOptions, LIVE_BACKOFF_MAX_MS, LIVE_BACKOFF_MIN_MS, LIVE_IDLE_RECONNECT_MS, type LiveStatus, type ParseOutcome, type PollError, type PollSeed, type PollSnapshot, REQUEST_TIMEOUT_MS, type StationClimatologySnapshot, type StationClimatologyStore, type StationHistoryFetcher, type StationHistoryQuery, type StationHistoryStore, type StationLiveSnapshot, type StationLiveStore, type StationSnapshot, type StationStore, archiveDayStep, archiveDayValue, archiveDayWindow, archivePeriodFor, archiveTrailingWindow, createJsonPoller, createStationClimatologyStore, createStationCurrentStore, createStationFeedStore, createStationHistoryStore, createStationLiveStore, createStationStore, liveSnapshotToCurrent, parseCurrentText, parseFeedText, stationHistoryFetcher, subscribeTicker };
@@ -1,5 +1,7 @@
1
1
  import { FRESHNESS_REEVALUATE_MS, REQUEST_TIMEOUT_MS, createJsonPoller } from "./poll.js";
2
2
  import { LIVE_BACKOFF_MAX_MS, LIVE_BACKOFF_MIN_MS, LIVE_IDLE_RECONNECT_MS, createStationLiveStore, liveSnapshotToCurrent } from "./live.js";
3
3
  import { createStationCurrentStore, createStationFeedStore, createStationStore, parseCurrentText, parseFeedText } from "./stores.js";
4
+ import { createStationClimatologyStore } from "./climatology.js";
5
+ import { ARCHIVE_DEFAULT_PERIODS_MINUTES, ARCHIVE_TARGET_POINTS, HISTORY_STORE_DEFAULT_MAX_WINDOWS, archiveDayStep, archiveDayValue, archiveDayWindow, archivePeriodFor, archiveTrailingWindow, createStationHistoryStore, stationHistoryFetcher } from "./history.js";
4
6
  import { subscribeTicker } from "./ticker.js";
5
- export { FRESHNESS_REEVALUATE_MS, LIVE_BACKOFF_MAX_MS, LIVE_BACKOFF_MIN_MS, LIVE_IDLE_RECONNECT_MS, REQUEST_TIMEOUT_MS, createJsonPoller, createStationCurrentStore, createStationFeedStore, createStationLiveStore, createStationStore, liveSnapshotToCurrent, parseCurrentText, parseFeedText, subscribeTicker };
7
+ export { ARCHIVE_DEFAULT_PERIODS_MINUTES, ARCHIVE_TARGET_POINTS, FRESHNESS_REEVALUATE_MS, HISTORY_STORE_DEFAULT_MAX_WINDOWS, LIVE_BACKOFF_MAX_MS, LIVE_BACKOFF_MIN_MS, LIVE_IDLE_RECONNECT_MS, REQUEST_TIMEOUT_MS, archiveDayStep, archiveDayValue, archiveDayWindow, archivePeriodFor, archiveTrailingWindow, createJsonPoller, createStationClimatologyStore, createStationCurrentStore, createStationFeedStore, createStationHistoryStore, createStationLiveStore, createStationStore, liveSnapshotToCurrent, parseCurrentText, parseFeedText, stationHistoryFetcher, subscribeTicker };
@@ -72,6 +72,21 @@ function createStationLiveStore(base, stationId, options = {}) {
72
72
  });
73
73
  return;
74
74
  }
75
+ case "summaries": {
76
+ const station = snapshot.station;
77
+ setSnapshot({
78
+ ...snapshot,
79
+ status: "open",
80
+ station: station?.status === "ok" ? {
81
+ ...station,
82
+ recentSummaries: frame.summaries
83
+ } : station,
84
+ servedAt: frame.servedAt,
85
+ receivedAtMs: Date.now(),
86
+ error: null
87
+ });
88
+ return;
89
+ }
75
90
  case "ping": return;
76
91
  case "unavailable":
77
92
  setSnapshot({
@@ -0,0 +1,66 @@
1
+ import { HistoryPoint } from "./contract.js";
2
+ import { ClimatologyCell, StationClimatology } from "./contract-climatology.js";
3
+ import { DailyPatternSlot, WindRoseSummary } from "./geometry.js";
4
+ import { DirectionArc } from "@azohra/meteo.core";
5
+ //#region src/climatology.d.ts
6
+ type ClimatologyFoldParams = {
7
+ sectorCount: number;
8
+ slotMinutes: number;
9
+ /** The consumer's band bounds in m/s, ascending — a judgment parameter
10
+ * with no default; it shapes every bandCounts list. */
11
+ thresholdsMps: ReadonlyArray<number>;
12
+ utcOffsetMinutes: number;
13
+ };
14
+ type MutableSector = {
15
+ count: number;
16
+ uSum: number;
17
+ vSum: number;
18
+ speedSumMps: number;
19
+ bandCounts: number[];
20
+ maxGustMps: number | null;
21
+ };
22
+ type MutableCell = {
23
+ sampleCount: number;
24
+ calmCount: number;
25
+ sectors: Map<number, MutableSector>;
26
+ };
27
+ type ClimatologyAccumulator = {
28
+ readonly params: ClimatologyFoldParams;
29
+ readonly cells: Map<string, MutableCell>;
30
+ /** Distinct (month, day, slot) buckets holding a record, per year. */
31
+ readonly coveredSlots: Map<number, Set<string>>;
32
+ };
33
+ declare function createClimatologyAccumulator(params: ClimatologyFoldParams): ClimatologyAccumulator;
34
+ declare function foldClimatologyPoints(accumulator: ClimatologyAccumulator, points: ReadonlyArray<HistoryPoint>): void;
35
+ /** The accumulated buckets as wire cells: month, then slot, then sector,
36
+ * every empty bucket absent. */
37
+ declare function accumulatedCells(accumulator: ClimatologyAccumulator): ClimatologyCell[];
38
+ type ClimatologyFilters = {
39
+ /** Calendar months to keep, 1–12; absent keeps all. */
40
+ months?: ReadonlyArray<number>;
41
+ /** Slot-of-day indices to keep; absent keeps all. */
42
+ slots?: ReadonlyArray<number>;
43
+ };
44
+ /** The filtered cube as a rose — geometry's WindRoseSummary shape, every
45
+ * sector carrying its bandCounts stack. */
46
+ declare function climatologyRose(document: StationClimatology, filters?: ClimatologyFilters): WindRoseSummary;
47
+ /** The filtered cube as a typical day — geometry's DailyPatternSlot list,
48
+ * vector-averaged per slot, calm records weighing the mean down exactly as
49
+ * the point-level dailyPattern does. */
50
+ declare function climatologyPattern(document: StationClimatology, filters?: Pick<ClimatologyFilters, "months">): DailyPatternSlot[];
51
+ type ClimatologyCoverage = {
52
+ sampleCount: number;
53
+ expectedCount: number;
54
+ ratio: number | null;
55
+ };
56
+ /** Per-year covered-slot counts, for producers writing the ledger. */
57
+ declare function coveredSlotCountByYear(accumulator: ClimatologyAccumulator): Map<number, number>;
58
+ /** Summed over the ledger. The ratio comes only from the slot pair and is
59
+ * null when any year lacks it — no percent beats a wrong-unit percent. */
60
+ declare function climatologyCoverage(document: StationClimatology): ClimatologyCoverage;
61
+ /** The share of the filtered non-calm record blowing from inside the
62
+ * consumer's arcs, judged at each sector's centre bearing; null when
63
+ * nothing non-calm was recorded — absence over a fabricated zero. */
64
+ declare function climatologyFavorableShare(document: StationClimatology, arcs: ReadonlyArray<DirectionArc>, filters?: ClimatologyFilters): number | null;
65
+ //#endregion
66
+ export { ClimatologyAccumulator, ClimatologyCoverage, ClimatologyFilters, ClimatologyFoldParams, accumulatedCells, climatologyCoverage, climatologyFavorableShare, climatologyPattern, climatologyRose, coveredSlotCountByYear, createClimatologyAccumulator, foldClimatologyPoints };
@@ -0,0 +1,230 @@
1
+ import { isCalm, normalizeDegrees } from "./derive.js";
2
+ import { speedBand } from "./geometry.js";
3
+ import { componentsToWind, inDirectionArcs, windToComponents } from "@azohra/meteo.core";
4
+ //#region src/climatology.ts
5
+ function createClimatologyAccumulator(params) {
6
+ if (params.slotMinutes <= 0 || 1440 % params.slotMinutes !== 0) throw new Error(`climatology: slotMinutes must evenly divide 1440, got ${params.slotMinutes}`);
7
+ if (params.sectorCount < 4) throw new Error(`climatology: sectorCount must be at least 4, got ${params.sectorCount}`);
8
+ return {
9
+ params,
10
+ cells: /* @__PURE__ */ new Map(),
11
+ coveredSlots: /* @__PURE__ */ new Map()
12
+ };
13
+ }
14
+ function foldClimatologyPoints(accumulator, points) {
15
+ const { sectorCount, slotMinutes, thresholdsMps, utcOffsetMinutes } = accumulator.params;
16
+ const sectorWidth = 360 / sectorCount;
17
+ for (const point of points) {
18
+ const localMs = Date.parse(point.observedAt) + utcOffsetMinutes * 6e4;
19
+ const local = new Date(localMs);
20
+ const month = local.getUTCMonth() + 1;
21
+ const minuteOfDay = local.getUTCHours() * 60 + local.getUTCMinutes();
22
+ const slot = Math.floor(minuteOfDay / slotMinutes);
23
+ const year = local.getUTCFullYear();
24
+ let covered = accumulator.coveredSlots.get(year);
25
+ if (covered == null) {
26
+ covered = /* @__PURE__ */ new Set();
27
+ accumulator.coveredSlots.set(year, covered);
28
+ }
29
+ covered.add(`${month}/${local.getUTCDate()}/${slot}`);
30
+ const key = `${month}/${slot}`;
31
+ let cell = accumulator.cells.get(key);
32
+ if (cell == null) {
33
+ cell = {
34
+ sampleCount: 0,
35
+ calmCount: 0,
36
+ sectors: /* @__PURE__ */ new Map()
37
+ };
38
+ accumulator.cells.set(key, cell);
39
+ }
40
+ cell.sampleCount += 1;
41
+ if (isCalm(point.windAvgMps) || point.windDirectionDeg == null) {
42
+ cell.calmCount += 1;
43
+ continue;
44
+ }
45
+ const bearing = normalizeDegrees(point.windDirectionDeg);
46
+ const sectorIndex = Math.round(bearing / sectorWidth) % sectorCount;
47
+ let sector = cell.sectors.get(sectorIndex);
48
+ if (sector == null) {
49
+ sector = {
50
+ count: 0,
51
+ uSum: 0,
52
+ vSum: 0,
53
+ speedSumMps: 0,
54
+ bandCounts: Array.from({ length: thresholdsMps.length + 1 }, () => 0),
55
+ maxGustMps: null
56
+ };
57
+ cell.sectors.set(sectorIndex, sector);
58
+ }
59
+ const components = windToComponents(point.windAvgMps, bearing);
60
+ sector.count += 1;
61
+ sector.uSum += components.uMps;
62
+ sector.vSum += components.vMps;
63
+ sector.speedSumMps += point.windAvgMps;
64
+ sector.bandCounts[speedBand(point.windAvgMps, thresholdsMps)] = (sector.bandCounts[speedBand(point.windAvgMps, thresholdsMps)] ?? 0) + 1;
65
+ if (point.windGustMps != null) sector.maxGustMps = sector.maxGustMps == null ? point.windGustMps : Math.max(sector.maxGustMps, point.windGustMps);
66
+ }
67
+ }
68
+ /** The accumulated buckets as wire cells: month, then slot, then sector,
69
+ * every empty bucket absent. */
70
+ function accumulatedCells(accumulator) {
71
+ const cells = [];
72
+ for (const [key, cell] of accumulator.cells) {
73
+ const [month, slot] = key.split("/").map(Number);
74
+ cells.push({
75
+ month,
76
+ slot,
77
+ sampleCount: cell.sampleCount,
78
+ calmCount: cell.calmCount,
79
+ sectors: [...cell.sectors.entries()].sort(([left], [right]) => left - right).map(([sector, sums]) => ({
80
+ sector,
81
+ count: sums.count,
82
+ uSum: roundSum(sums.uSum),
83
+ vSum: roundSum(sums.vSum),
84
+ speedSumMps: roundSum(sums.speedSumMps),
85
+ bandCounts: sums.bandCounts,
86
+ maxGustMps: sums.maxGustMps
87
+ }))
88
+ });
89
+ }
90
+ return cells.sort((left, right) => left.month - right.month || left.slot - right.slot);
91
+ }
92
+ function roundSum(value) {
93
+ return Math.round(value * 1e6) / 1e6;
94
+ }
95
+ function selectedCells(document, filters) {
96
+ const months = filters?.months == null ? null : new Set(filters.months);
97
+ const slots = filters?.slots == null ? null : new Set(filters.slots);
98
+ return document.cells.filter((cell) => (months == null || months.has(cell.month)) && (slots == null || slots.has(cell.slot)));
99
+ }
100
+ /** The filtered cube as a rose — geometry's WindRoseSummary shape, every
101
+ * sector carrying its bandCounts stack. */
102
+ function climatologyRose(document, filters) {
103
+ const cells = selectedCells(document, filters);
104
+ const sectorWidth = 360 / document.sectorCount;
105
+ const totals = /* @__PURE__ */ new Map();
106
+ let sampleCount = 0;
107
+ let calm = 0;
108
+ for (const cell of cells) {
109
+ sampleCount += cell.sampleCount;
110
+ calm += cell.calmCount;
111
+ for (const sector of cell.sectors) {
112
+ let total = totals.get(sector.sector);
113
+ if (total == null) {
114
+ total = {
115
+ count: 0,
116
+ uSum: 0,
117
+ vSum: 0,
118
+ speedSumMps: 0,
119
+ bandCounts: Array.from({ length: document.thresholdsMps.length + 1 }, () => 0),
120
+ maxGustMps: null
121
+ };
122
+ totals.set(sector.sector, total);
123
+ }
124
+ total.count += sector.count;
125
+ total.uSum += sector.uSum;
126
+ total.vSum += sector.vSum;
127
+ total.speedSumMps += sector.speedSumMps;
128
+ sector.bandCounts.forEach((bandCount, band) => {
129
+ total.bandCounts[band] = (total.bandCounts[band] ?? 0) + bandCount;
130
+ });
131
+ if (sector.maxGustMps != null) total.maxGustMps = total.maxGustMps == null ? sector.maxGustMps : Math.max(total.maxGustMps, sector.maxGustMps);
132
+ }
133
+ }
134
+ const blowing = sampleCount - calm;
135
+ return {
136
+ sectors: Array.from({ length: document.sectorCount }, (_, index) => {
137
+ const total = totals.get(index);
138
+ return {
139
+ bearingDeg: index * sectorWidth,
140
+ count: total?.count ?? 0,
141
+ frequency: blowing === 0 || total == null ? 0 : total.count / blowing,
142
+ meanSpeedMps: total == null || total.count === 0 ? null : total.speedSumMps / total.count,
143
+ maxGustMps: total?.maxGustMps ?? null,
144
+ bandCounts: total?.bandCounts ?? void 0
145
+ };
146
+ }),
147
+ calmFraction: sampleCount === 0 ? 0 : calm / sampleCount,
148
+ sampleCount
149
+ };
150
+ }
151
+ /** The filtered cube as a typical day — geometry's DailyPatternSlot list,
152
+ * vector-averaged per slot, calm records weighing the mean down exactly as
153
+ * the point-level dailyPattern does. */
154
+ function climatologyPattern(document, filters) {
155
+ const cells = selectedCells(document, filters);
156
+ const slotCount = 1440 / document.slotMinutes;
157
+ const slots = Array.from({ length: slotCount }, (_, index) => ({
158
+ startMinuteOfDay: index * document.slotMinutes,
159
+ sampleCount: 0,
160
+ uSum: 0,
161
+ vSum: 0
162
+ }));
163
+ for (const cell of cells) {
164
+ const slot = slots[cell.slot];
165
+ if (slot == null) continue;
166
+ slot.sampleCount += cell.sampleCount;
167
+ for (const sector of cell.sectors) {
168
+ slot.uSum += sector.uSum;
169
+ slot.vSum += sector.vSum;
170
+ }
171
+ }
172
+ return slots.map((slot) => {
173
+ if (slot.sampleCount === 0) return {
174
+ startMinuteOfDay: slot.startMinuteOfDay,
175
+ sampleCount: 0,
176
+ windDirectionDeg: null,
177
+ speedMps: 0
178
+ };
179
+ const mean = componentsToWind(slot.uSum / slot.sampleCount, slot.vSum / slot.sampleCount);
180
+ return {
181
+ startMinuteOfDay: slot.startMinuteOfDay,
182
+ sampleCount: slot.sampleCount,
183
+ windDirectionDeg: mean.speedMps < .5 ? null : mean.directionDeg,
184
+ speedMps: mean.speedMps
185
+ };
186
+ });
187
+ }
188
+ /** Per-year covered-slot counts, for producers writing the ledger. */
189
+ function coveredSlotCountByYear(accumulator) {
190
+ return new Map([...accumulator.coveredSlots.entries()].map(([year, slots]) => [year, slots.size]));
191
+ }
192
+ /** Summed over the ledger. The ratio comes only from the slot pair and is
193
+ * null when any year lacks it — no percent beats a wrong-unit percent. */
194
+ function climatologyCoverage(document) {
195
+ let sampleCount = 0;
196
+ let expectedCount = 0;
197
+ let coveredSlots = 0;
198
+ let expectedSlots = 0;
199
+ let slotsKnown = true;
200
+ for (const year of document.years) {
201
+ sampleCount += year.sampleCount;
202
+ expectedCount += year.expectedCount;
203
+ if (year.coveredSlotCount == null || year.expectedSlotCount == null) slotsKnown = false;
204
+ else {
205
+ coveredSlots += year.coveredSlotCount;
206
+ expectedSlots += year.expectedSlotCount;
207
+ }
208
+ }
209
+ return {
210
+ sampleCount,
211
+ expectedCount,
212
+ ratio: slotsKnown && expectedSlots > 0 ? coveredSlots / expectedSlots : null
213
+ };
214
+ }
215
+ /** The share of the filtered non-calm record blowing from inside the
216
+ * consumer's arcs, judged at each sector's centre bearing; null when
217
+ * nothing non-calm was recorded — absence over a fabricated zero. */
218
+ function climatologyFavorableShare(document, arcs, filters) {
219
+ if (arcs.length === 0) return null;
220
+ const sectorWidth = 360 / document.sectorCount;
221
+ let blowing = 0;
222
+ let favorable = 0;
223
+ for (const cell of selectedCells(document, filters)) for (const sector of cell.sectors) {
224
+ blowing += sector.count;
225
+ if (inDirectionArcs(sector.sector * sectorWidth, arcs)) favorable += sector.count;
226
+ }
227
+ return blowing === 0 ? null : favorable / blowing;
228
+ }
229
+ //#endregion
230
+ export { accumulatedCells, climatologyCoverage, climatologyFavorableShare, climatologyPattern, climatologyRose, coveredSlotCountByYear, createClimatologyAccumulator, foldClimatologyPoints };