@azohra/meteo.station 0.3.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) 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 +53 -0
  4. package/dist/client/history.js +114 -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 +61 -0
  9. package/dist/climatology.js +208 -0
  10. package/dist/contract-climatology.d.ts +69 -0
  11. package/dist/contract-climatology.js +50 -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 +20 -12
  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 +16 -3
  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 +22 -3
  48. package/dist/geometry.js +41 -5
  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 +13 -6
  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 +19 -0
  69. package/dist/react/components/RecentSummaries.js +65 -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 +18 -3
  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 +6 -3
  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 +20 -6
  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/wind-history.d.ts +1 -0
  108. package/dist/scene/wind-history.js +4 -3
  109. package/dist/scene/wind-plot.d.ts +1 -0
  110. package/dist/scene/wind-plot.js +30 -3
  111. package/dist/server/adapter.d.ts +2 -1
  112. package/dist/server/adapter.js +2 -1
  113. package/dist/server/adapters/windnerd-climatology.d.ts +33 -0
  114. package/dist/server/adapters/windnerd-climatology.js +81 -0
  115. package/dist/server/adapters/windnerd-live.js +21 -13
  116. package/dist/server/adapters/windnerd.d.ts +31 -4
  117. package/dist/server/adapters/windnerd.js +197 -19
  118. package/dist/server/feed.d.ts +44 -2
  119. package/dist/server/feed.js +63 -2
  120. package/dist/server/handler.d.ts +11 -1
  121. package/dist/server/handler.js +83 -2
  122. package/dist/server/index.d.ts +4 -3
  123. package/dist/server/index.js +4 -3
  124. package/dist/strings.d.ts +12 -0
  125. package/dist/strings.js +12 -0
  126. package/package.json +2 -2
  127. package/schema/example-climatology.json +86 -0
  128. package/schema/example-history.json +38 -0
  129. package/schema/stationclimatology.schema.json +195 -0
  130. package/schema/stationcurrent.schema.json +173 -0
  131. package/schema/stationfeed.schema.json +173 -0
  132. package/schema/stationhistory.schema.json +186 -0
  133. package/schema/stationlive.schema.json +202 -0
  134. package/styles.css +215 -0
@@ -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,53 @@
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
+ /**
10
+ * The archive fetch contract: one requested window in, one
11
+ * parsed document (or null on failure) out. A host that mounts the feed
12
+ * handler uses `stationHistoryFetcher`; one that serves history its own way
13
+ * — an authenticated server function, a proxy — supplies any function of
14
+ * this shape and never touches the handler.
15
+ */
16
+ type StationHistoryFetcher = (query: StationHistoryQuery) => Promise<StationHistory | null>;
17
+ /** The default fetcher, against the mounted handler's /history route. */
18
+ declare function stationHistoryFetcher(base: string, stationId: string, fetchInit?: RequestInit): StationHistoryFetcher;
19
+ type StationHistoryStore = {
20
+ /** The window's document — cache-served when held, deduplicated while in
21
+ * flight. A failed fetch resolves null and is not cached, so the next
22
+ * ask retries. */
23
+ window(query: StationHistoryQuery): Promise<StationHistory | null>;
24
+ /** Windows currently held. */
25
+ size(): number;
26
+ };
27
+ /** A window-keyed LRU over a fetcher, so pan/zoom revisits cost nothing. */
28
+ declare function createStationHistoryStore(fetcher: StationHistoryFetcher, options?: {
29
+ maxWindows?: number;
30
+ }): StationHistoryStore;
31
+ declare const ARCHIVE_DEFAULT_PERIODS_MINUTES: readonly [1, 5, 10, 15, 30, 60, 180, 360];
32
+ declare const ARCHIVE_TARGET_POINTS = 500;
33
+ type ArchiveWindow = {
34
+ fromMs: number;
35
+ toMs: number;
36
+ };
37
+ /** The finest ladder period that keeps the span at or under the point
38
+ * target; a span too wide for every rung takes the coarsest. */
39
+ declare function archivePeriodFor(spanMs: number, periods?: ReadonlyArray<number>, targetPoints?: number): number;
40
+ /** One whole LOCAL day from a YYYY-MM-DD date-input value — the day the
41
+ * person picking it means, not the UTC day; null when the value is not a
42
+ * real date. */
43
+ declare function archiveDayWindow(dateValue: string): ArchiveWindow | null;
44
+ /** The YYYY-MM-DD value naming an instant's local day. */
45
+ declare function archiveDayValue(atMs: number): string;
46
+ /** The day value a number of days away — how a pager steps. Stepping
47
+ * through noon of the target day keeps a DST-shifted midnight from landing
48
+ * the step on the wrong side. Null when the value is not a real date. */
49
+ declare function archiveDayStep(dateValue: string, deltaDays: number): string | null;
50
+ /** The trailing window ending now — a pager's "today". */
51
+ declare function archiveTrailingWindow(nowMs: number, spanMs?: number): ArchiveWindow;
52
+ //#endregion
53
+ 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,114 @@
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 — the day the
75
+ * person picking it means, not the UTC day; null when the value is not a
76
+ * real date. */
77
+ function archiveDayWindow(dateValue) {
78
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(dateValue);
79
+ if (!match) return null;
80
+ const [year, month, day] = [
81
+ Number(match[1]),
82
+ Number(match[2]),
83
+ Number(match[3])
84
+ ];
85
+ const at = new Date(year, month - 1, day);
86
+ if (at.getFullYear() !== year || at.getMonth() !== month - 1 || at.getDate() !== day) return null;
87
+ return {
88
+ fromMs: at.getTime(),
89
+ toMs: at.getTime() + DAY_MS
90
+ };
91
+ }
92
+ /** The YYYY-MM-DD value naming an instant's local day. */
93
+ function archiveDayValue(atMs) {
94
+ const at = new Date(atMs);
95
+ const pad = (value) => String(value).padStart(2, "0");
96
+ return `${at.getFullYear()}-${pad(at.getMonth() + 1)}-${pad(at.getDate())}`;
97
+ }
98
+ /** The day value a number of days away — how a pager steps. Stepping
99
+ * through noon of the target day keeps a DST-shifted midnight from landing
100
+ * the step on the wrong side. Null when the value is not a real date. */
101
+ function archiveDayStep(dateValue, deltaDays) {
102
+ const window = archiveDayWindow(dateValue);
103
+ if (window == null) return null;
104
+ return archiveDayValue(window.fromMs + deltaDays * DAY_MS + DAY_MS / 2);
105
+ }
106
+ /** The trailing window ending now — a pager's "today". */
107
+ function archiveTrailingWindow(nowMs, spanMs = DAY_MS) {
108
+ return {
109
+ fromMs: nowMs - spanMs,
110
+ toMs: nowMs
111
+ };
112
+ }
113
+ //#endregion
114
+ 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,61 @@
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
+ };
31
+ declare function createClimatologyAccumulator(params: ClimatologyFoldParams): ClimatologyAccumulator;
32
+ declare function foldClimatologyPoints(accumulator: ClimatologyAccumulator, points: ReadonlyArray<HistoryPoint>): void;
33
+ /** The accumulated buckets as wire cells: month, then slot, then sector,
34
+ * every empty bucket absent. */
35
+ declare function accumulatedCells(accumulator: ClimatologyAccumulator): ClimatologyCell[];
36
+ type ClimatologyFilters = {
37
+ /** Calendar months to keep, 1–12; absent keeps all. */
38
+ months?: ReadonlyArray<number>;
39
+ /** Slot-of-day indices to keep; absent keeps all. */
40
+ slots?: ReadonlyArray<number>;
41
+ };
42
+ /** The filtered cube as a rose — geometry's WindRoseSummary shape, every
43
+ * sector carrying its bandCounts stack. */
44
+ declare function climatologyRose(document: StationClimatology, filters?: ClimatologyFilters): WindRoseSummary;
45
+ /** The filtered cube as a typical day — geometry's DailyPatternSlot list,
46
+ * vector-averaged per slot, calm records weighing the mean down exactly as
47
+ * the point-level dailyPattern does. */
48
+ declare function climatologyPattern(document: StationClimatology, filters?: Pick<ClimatologyFilters, "months">): DailyPatternSlot[];
49
+ type ClimatologyCoverage = {
50
+ sampleCount: number;
51
+ expectedCount: number;
52
+ ratio: number;
53
+ };
54
+ /** The whole record's honesty figure, summed over the year ledger. */
55
+ declare function climatologyCoverage(document: StationClimatology): ClimatologyCoverage;
56
+ /** The share of the filtered non-calm record blowing from inside the
57
+ * consumer's arcs, judged at each sector's centre bearing; null when
58
+ * nothing non-calm was recorded — absence over a fabricated zero. */
59
+ declare function climatologyFavorableShare(document: StationClimatology, arcs: ReadonlyArray<DirectionArc>, filters?: ClimatologyFilters): number | null;
60
+ //#endregion
61
+ export { ClimatologyAccumulator, ClimatologyCoverage, ClimatologyFilters, ClimatologyFoldParams, accumulatedCells, climatologyCoverage, climatologyFavorableShare, climatologyPattern, climatologyRose, createClimatologyAccumulator, foldClimatologyPoints };
@@ -0,0 +1,208 @@
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
+ };
12
+ }
13
+ function foldClimatologyPoints(accumulator, points) {
14
+ const { sectorCount, slotMinutes, thresholdsMps, utcOffsetMinutes } = accumulator.params;
15
+ const sectorWidth = 360 / sectorCount;
16
+ for (const point of points) {
17
+ const localMs = Date.parse(point.observedAt) + utcOffsetMinutes * 6e4;
18
+ const local = new Date(localMs);
19
+ const month = local.getUTCMonth() + 1;
20
+ const minuteOfDay = local.getUTCHours() * 60 + local.getUTCMinutes();
21
+ const key = `${month}/${Math.floor(minuteOfDay / slotMinutes)}`;
22
+ let cell = accumulator.cells.get(key);
23
+ if (cell == null) {
24
+ cell = {
25
+ sampleCount: 0,
26
+ calmCount: 0,
27
+ sectors: /* @__PURE__ */ new Map()
28
+ };
29
+ accumulator.cells.set(key, cell);
30
+ }
31
+ cell.sampleCount += 1;
32
+ if (isCalm(point.windAvgMps) || point.windDirectionDeg == null) {
33
+ cell.calmCount += 1;
34
+ continue;
35
+ }
36
+ const bearing = normalizeDegrees(point.windDirectionDeg);
37
+ const sectorIndex = Math.round(bearing / sectorWidth) % sectorCount;
38
+ let sector = cell.sectors.get(sectorIndex);
39
+ if (sector == null) {
40
+ sector = {
41
+ count: 0,
42
+ uSum: 0,
43
+ vSum: 0,
44
+ speedSumMps: 0,
45
+ bandCounts: Array.from({ length: thresholdsMps.length + 1 }, () => 0),
46
+ maxGustMps: null
47
+ };
48
+ cell.sectors.set(sectorIndex, sector);
49
+ }
50
+ const components = windToComponents(point.windAvgMps, bearing);
51
+ sector.count += 1;
52
+ sector.uSum += components.uMps;
53
+ sector.vSum += components.vMps;
54
+ sector.speedSumMps += point.windAvgMps;
55
+ sector.bandCounts[speedBand(point.windAvgMps, thresholdsMps)] = (sector.bandCounts[speedBand(point.windAvgMps, thresholdsMps)] ?? 0) + 1;
56
+ if (point.windGustMps != null) sector.maxGustMps = sector.maxGustMps == null ? point.windGustMps : Math.max(sector.maxGustMps, point.windGustMps);
57
+ }
58
+ }
59
+ /** The accumulated buckets as wire cells: month, then slot, then sector,
60
+ * every empty bucket absent. */
61
+ function accumulatedCells(accumulator) {
62
+ const cells = [];
63
+ for (const [key, cell] of accumulator.cells) {
64
+ const [month, slot] = key.split("/").map(Number);
65
+ cells.push({
66
+ month,
67
+ slot,
68
+ sampleCount: cell.sampleCount,
69
+ calmCount: cell.calmCount,
70
+ sectors: [...cell.sectors.entries()].sort(([left], [right]) => left - right).map(([sector, sums]) => ({
71
+ sector,
72
+ count: sums.count,
73
+ uSum: roundSum(sums.uSum),
74
+ vSum: roundSum(sums.vSum),
75
+ speedSumMps: roundSum(sums.speedSumMps),
76
+ bandCounts: sums.bandCounts,
77
+ maxGustMps: sums.maxGustMps
78
+ }))
79
+ });
80
+ }
81
+ return cells.sort((left, right) => left.month - right.month || left.slot - right.slot);
82
+ }
83
+ function roundSum(value) {
84
+ return Math.round(value * 1e6) / 1e6;
85
+ }
86
+ function selectedCells(document, filters) {
87
+ const months = filters?.months == null ? null : new Set(filters.months);
88
+ const slots = filters?.slots == null ? null : new Set(filters.slots);
89
+ return document.cells.filter((cell) => (months == null || months.has(cell.month)) && (slots == null || slots.has(cell.slot)));
90
+ }
91
+ /** The filtered cube as a rose — geometry's WindRoseSummary shape, every
92
+ * sector carrying its bandCounts stack. */
93
+ function climatologyRose(document, filters) {
94
+ const cells = selectedCells(document, filters);
95
+ const sectorWidth = 360 / document.sectorCount;
96
+ const totals = /* @__PURE__ */ new Map();
97
+ let sampleCount = 0;
98
+ let calm = 0;
99
+ for (const cell of cells) {
100
+ sampleCount += cell.sampleCount;
101
+ calm += cell.calmCount;
102
+ for (const sector of cell.sectors) {
103
+ let total = totals.get(sector.sector);
104
+ if (total == null) {
105
+ total = {
106
+ count: 0,
107
+ uSum: 0,
108
+ vSum: 0,
109
+ speedSumMps: 0,
110
+ bandCounts: Array.from({ length: document.thresholdsMps.length + 1 }, () => 0),
111
+ maxGustMps: null
112
+ };
113
+ totals.set(sector.sector, total);
114
+ }
115
+ total.count += sector.count;
116
+ total.uSum += sector.uSum;
117
+ total.vSum += sector.vSum;
118
+ total.speedSumMps += sector.speedSumMps;
119
+ sector.bandCounts.forEach((bandCount, band) => {
120
+ total.bandCounts[band] = (total.bandCounts[band] ?? 0) + bandCount;
121
+ });
122
+ if (sector.maxGustMps != null) total.maxGustMps = total.maxGustMps == null ? sector.maxGustMps : Math.max(total.maxGustMps, sector.maxGustMps);
123
+ }
124
+ }
125
+ const blowing = sampleCount - calm;
126
+ return {
127
+ sectors: Array.from({ length: document.sectorCount }, (_, index) => {
128
+ const total = totals.get(index);
129
+ return {
130
+ bearingDeg: index * sectorWidth,
131
+ count: total?.count ?? 0,
132
+ frequency: blowing === 0 || total == null ? 0 : total.count / blowing,
133
+ meanSpeedMps: total == null || total.count === 0 ? null : total.speedSumMps / total.count,
134
+ maxGustMps: total?.maxGustMps ?? null,
135
+ bandCounts: total?.bandCounts ?? void 0
136
+ };
137
+ }),
138
+ calmFraction: sampleCount === 0 ? 0 : calm / sampleCount,
139
+ sampleCount
140
+ };
141
+ }
142
+ /** The filtered cube as a typical day — geometry's DailyPatternSlot list,
143
+ * vector-averaged per slot, calm records weighing the mean down exactly as
144
+ * the point-level dailyPattern does. */
145
+ function climatologyPattern(document, filters) {
146
+ const cells = selectedCells(document, filters);
147
+ const slotCount = 1440 / document.slotMinutes;
148
+ const slots = Array.from({ length: slotCount }, (_, index) => ({
149
+ startMinuteOfDay: index * document.slotMinutes,
150
+ sampleCount: 0,
151
+ uSum: 0,
152
+ vSum: 0
153
+ }));
154
+ for (const cell of cells) {
155
+ const slot = slots[cell.slot];
156
+ if (slot == null) continue;
157
+ slot.sampleCount += cell.sampleCount;
158
+ for (const sector of cell.sectors) {
159
+ slot.uSum += sector.uSum;
160
+ slot.vSum += sector.vSum;
161
+ }
162
+ }
163
+ return slots.map((slot) => {
164
+ if (slot.sampleCount === 0) return {
165
+ startMinuteOfDay: slot.startMinuteOfDay,
166
+ sampleCount: 0,
167
+ windDirectionDeg: null,
168
+ speedMps: 0
169
+ };
170
+ const mean = componentsToWind(slot.uSum / slot.sampleCount, slot.vSum / slot.sampleCount);
171
+ return {
172
+ startMinuteOfDay: slot.startMinuteOfDay,
173
+ sampleCount: slot.sampleCount,
174
+ windDirectionDeg: mean.speedMps < .5 ? null : mean.directionDeg,
175
+ speedMps: mean.speedMps
176
+ };
177
+ });
178
+ }
179
+ /** The whole record's honesty figure, summed over the year ledger. */
180
+ function climatologyCoverage(document) {
181
+ let sampleCount = 0;
182
+ let expectedCount = 0;
183
+ for (const year of document.years) {
184
+ sampleCount += year.sampleCount;
185
+ expectedCount += year.expectedCount;
186
+ }
187
+ return {
188
+ sampleCount,
189
+ expectedCount,
190
+ ratio: expectedCount === 0 ? 0 : sampleCount / expectedCount
191
+ };
192
+ }
193
+ /** The share of the filtered non-calm record blowing from inside the
194
+ * consumer's arcs, judged at each sector's centre bearing; null when
195
+ * nothing non-calm was recorded — absence over a fabricated zero. */
196
+ function climatologyFavorableShare(document, arcs, filters) {
197
+ if (arcs.length === 0) return null;
198
+ const sectorWidth = 360 / document.sectorCount;
199
+ let blowing = 0;
200
+ let favorable = 0;
201
+ for (const cell of selectedCells(document, filters)) for (const sector of cell.sectors) {
202
+ blowing += sector.count;
203
+ if (inDirectionArcs(sector.sector * sectorWidth, arcs)) favorable += sector.count;
204
+ }
205
+ return blowing === 0 ? null : favorable / blowing;
206
+ }
207
+ //#endregion
208
+ export { accumulatedCells, climatologyCoverage, climatologyFavorableShare, climatologyPattern, climatologyRose, createClimatologyAccumulator, foldClimatologyPoints };
@@ -0,0 +1,69 @@
1
+ import { z } from "zod";
2
+ //#region src/contract-climatology.d.ts
3
+ declare const STATION_CLIMATOLOGY_SCHEMA_VERSION = 1;
4
+ declare const climatologySectorSchema: z.ZodObject<{
5
+ sector: z.ZodNumber;
6
+ count: z.ZodNumber;
7
+ uSum: z.ZodNumber;
8
+ vSum: z.ZodNumber;
9
+ speedSumMps: z.ZodNumber;
10
+ bandCounts: z.ZodArray<z.ZodNumber>;
11
+ maxGustMps: z.ZodNullable<z.ZodNumber>;
12
+ }, z.core.$strip>;
13
+ type ClimatologySector = z.infer<typeof climatologySectorSchema>;
14
+ declare const climatologyCellSchema: z.ZodObject<{
15
+ month: z.ZodNumber;
16
+ slot: z.ZodNumber;
17
+ sampleCount: z.ZodNumber;
18
+ calmCount: z.ZodNumber;
19
+ sectors: z.ZodArray<z.ZodObject<{
20
+ sector: z.ZodNumber;
21
+ count: z.ZodNumber;
22
+ uSum: z.ZodNumber;
23
+ vSum: z.ZodNumber;
24
+ speedSumMps: z.ZodNumber;
25
+ bandCounts: z.ZodArray<z.ZodNumber>;
26
+ maxGustMps: z.ZodNullable<z.ZodNumber>;
27
+ }, z.core.$strip>>;
28
+ }, z.core.$strip>;
29
+ type ClimatologyCell = z.infer<typeof climatologyCellSchema>;
30
+ declare const climatologyYearSchema: z.ZodObject<{
31
+ year: z.ZodNumber;
32
+ sampleCount: z.ZodNumber;
33
+ expectedCount: z.ZodNumber;
34
+ }, z.core.$strip>;
35
+ type ClimatologyYear = z.infer<typeof climatologyYearSchema>;
36
+ declare const stationClimatologySchema: z.ZodObject<{
37
+ schemaVersion: z.ZodLiteral<1>;
38
+ servedAt: z.ZodString;
39
+ stationId: z.ZodString;
40
+ sectorCount: z.ZodNumber;
41
+ slotMinutes: z.ZodNumber;
42
+ thresholdsMps: z.ZodArray<z.ZodNumber>;
43
+ utcOffsetMinutes: z.ZodNumber;
44
+ years: z.ZodArray<z.ZodObject<{
45
+ year: z.ZodNumber;
46
+ sampleCount: z.ZodNumber;
47
+ expectedCount: z.ZodNumber;
48
+ }, z.core.$strip>>;
49
+ cells: z.ZodArray<z.ZodObject<{
50
+ month: z.ZodNumber;
51
+ slot: z.ZodNumber;
52
+ sampleCount: z.ZodNumber;
53
+ calmCount: z.ZodNumber;
54
+ sectors: z.ZodArray<z.ZodObject<{
55
+ sector: z.ZodNumber;
56
+ count: z.ZodNumber;
57
+ uSum: z.ZodNumber;
58
+ vSum: z.ZodNumber;
59
+ speedSumMps: z.ZodNumber;
60
+ bandCounts: z.ZodArray<z.ZodNumber>;
61
+ maxGustMps: z.ZodNullable<z.ZodNumber>;
62
+ }, z.core.$strip>>;
63
+ }, z.core.$strip>>;
64
+ }, z.core.$strip>;
65
+ type StationClimatology = z.infer<typeof stationClimatologySchema>;
66
+ declare function parseStationClimatology(value: unknown): StationClimatology | null;
67
+ declare function parseStationClimatologyJson(text: string): StationClimatology | null;
68
+ //#endregion
69
+ export { ClimatologyCell, ClimatologySector, ClimatologyYear, STATION_CLIMATOLOGY_SCHEMA_VERSION, StationClimatology, climatologyCellSchema, climatologySectorSchema, climatologyYearSchema, parseStationClimatology, parseStationClimatologyJson, stationClimatologySchema };