@azohra/meteo.station 0.1.2 → 0.1.3
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.
- package/dist/geometry.d.ts +4 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/samples.d.ts +20 -0
- package/dist/samples.js +88 -0
- package/package.json +1 -1
package/dist/geometry.d.ts
CHANGED
|
@@ -47,6 +47,9 @@ type ChartTick = {
|
|
|
47
47
|
x: number;
|
|
48
48
|
};
|
|
49
49
|
declare function vaneTicks(vanes: ReadonlyArray<Vane>, scales: ChartScales): ChartTick[];
|
|
50
|
+
declare function nearestIndex(points: ReadonlyArray<{
|
|
51
|
+
observedAt: string;
|
|
52
|
+
}>, chartX: number, frame: ChartFrame, scales: ChartScales): number | null;
|
|
50
53
|
declare function speedBand(speedMps: number, thresholdsMps: ReadonlyArray<number>): number;
|
|
51
54
|
type RoseSector = {
|
|
52
55
|
bearingDeg: number;
|
|
@@ -81,4 +84,4 @@ declare function windowPoints(points: ReadonlyArray<HistoryPoint>, hours?: numbe
|
|
|
81
84
|
declare function compareWindow(points: ReadonlyArray<HistoryPoint>, offsetDays: number, windowHours?: number): HistoryPoint[] | null;
|
|
82
85
|
declare function compareTracePoints(comparePoints: ReadonlyArray<HistoryPoint>, scales: ChartScales, offsetDays: number): string;
|
|
83
86
|
//#endregion
|
|
84
|
-
export { ChartFrame, ChartScaleOptions, ChartScales, ChartTick, DAILY_PATTERN_DEFAULT_SLOT_MINUTES, DailyPatternSlot, METEOROLOGICAL_SEASON_MONTHS, RoseSector, TrendSeries, Vane, WindRoseSummary, averagePoints, bandPoints, chartFrame, chartScales, compareTracePoints, compareWindow, dailyPattern, filterByMonth, filterByTimeOfDay, historyGaps, speedBand, thinVanes, vanePath, vaneTicks, windRose, windowPoints };
|
|
87
|
+
export { ChartFrame, ChartScaleOptions, ChartScales, ChartTick, DAILY_PATTERN_DEFAULT_SLOT_MINUTES, DailyPatternSlot, METEOROLOGICAL_SEASON_MONTHS, RoseSector, TrendSeries, Vane, WindRoseSummary, averagePoints, bandPoints, chartFrame, chartScales, compareTracePoints, compareWindow, dailyPattern, filterByMonth, filterByTimeOfDay, historyGaps, nearestIndex, speedBand, thinVanes, vanePath, vaneTicks, windRose, windowPoints };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,9 +4,10 @@ import { FormatTime, StationStringOverrides, StationStrings, defaultFormatTime,
|
|
|
4
4
|
import { DirectionCellData, SummaryEntry, directionCell, optionalSpeed, roundSpeed, summaryEntries, temperatureText, temperatureValue, updatedAtText } from "./format.js";
|
|
5
5
|
import { DisplayDefaults, DisplayProps, ResolvedDisplay, requireResolved, resolveDisplay, resolveStation } from "./display.js";
|
|
6
6
|
import { currentEndpoint, feedEndpoint, liveEndpoint } 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";
|
|
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, nearestIndex, speedBand, thinVanes, vanePath, vaneTicks, windRose, windowPoints } from "./geometry.js";
|
|
8
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
9
|
import { MergeResult, foldCurrent, mergeCurrent } from "./merge-current.js";
|
|
10
|
+
import { SAMPLE_GAP_TOLERANCE_FACTOR, SamplesSummary, sampleMeanDirectionDeg, samplePoints, sampleRuns, sampleScales, samplesSummary, thinSampleVanes } from "./samples.js";
|
|
10
11
|
import { AirRow, airRows, airSummary, lastStrikeWords } from "./air.js";
|
|
11
12
|
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, type LiveSample, type LiveSamples, 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 StationLiveFrame, type StationMeta, type StationStringOverrides, type StationStrings, type StationTelemetry, 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, liveEndpoint, liveSampleSchema, liveSamplesSchema, localeFormatTime, mergeCurrent, mergeStringOverrides, normalizeDegrees, normalizeWindnerdStationKey, optionalSpeed, parseStationCurrent, parseStationCurrentJson, parseStationFeed, parseStationFeedJson, parseStationLiveFrame, parseStationLiveFrameJson, periodSummary, pressureTendency, readingSchema, requireResolved, resolveDisplay, resolveStation, resolveStrings, rosePetalPath, rosePolar, roseRingArcPath, roundSpeed, seaLevelPressureHpa, sparklineScale, speedBand, speedFromMps, speedToMps, speedUnitLabel, stationCurrentSchema, stationFeedSchema, stationFreshnessThresholds, stationLiveFrameSchema, stationMetaSchema, stationSchema, summaryEntries, telemetrySchema, temperatureText, temperatureValue, thinVanes, thresholdsToMps, unavailableStation, updatedAtText, vanePath, vaneTicks, windRose, windnerdStationUrl, windowPoints };
|
|
13
|
+
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, type LiveSample, type LiveSamples, 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, SAMPLE_GAP_TOLERANCE_FACTOR, SPARKLINE_EDGE_INSET, SPARKLINE_MAX_PADDING, STATION_SCHEMA_VERSION, type SamplesSummary, type SpeedThresholds, type SpeedUnit, type Station, type StationCapabilities, type StationCurrent, type StationFeed, type StationLiveFrame, type StationMeta, type StationStringOverrides, type StationStrings, type StationTelemetry, 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, liveEndpoint, liveSampleSchema, liveSamplesSchema, localeFormatTime, mergeCurrent, mergeStringOverrides, nearestIndex, normalizeDegrees, normalizeWindnerdStationKey, optionalSpeed, parseStationCurrent, parseStationCurrentJson, parseStationFeed, parseStationFeedJson, parseStationLiveFrame, parseStationLiveFrameJson, periodSummary, pressureTendency, readingSchema, requireResolved, resolveDisplay, resolveStation, resolveStrings, rosePetalPath, rosePolar, roseRingArcPath, roundSpeed, sampleMeanDirectionDeg, samplePoints, sampleRuns, sampleScales, samplesSummary, seaLevelPressureHpa, sparklineScale, speedBand, speedFromMps, speedToMps, speedUnitLabel, stationCurrentSchema, stationFeedSchema, stationFreshnessThresholds, stationLiveFrameSchema, stationMetaSchema, stationSchema, summaryEntries, telemetrySchema, temperatureText, temperatureValue, thinSampleVanes, thinVanes, thresholdsToMps, unavailableStation, updatedAtText, vanePath, vaneTicks, windRose, windnerdStationUrl, windowPoints };
|
package/dist/index.js
CHANGED
|
@@ -4,9 +4,10 @@ import { defaultFormatTime, defaultStrings, localeFormatTime, mergeStringOverrid
|
|
|
4
4
|
import { requireResolved, resolveDisplay, resolveStation } from "./display.js";
|
|
5
5
|
import { currentEndpoint, feedEndpoint, liveEndpoint } from "./endpoints.js";
|
|
6
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";
|
|
7
|
+
import { DAILY_PATTERN_DEFAULT_SLOT_MINUTES, METEOROLOGICAL_SEASON_MONTHS, averagePoints, bandPoints, chartFrame, chartScales, compareTracePoints, compareWindow, dailyPattern, filterByMonth, filterByTimeOfDay, historyGaps, nearestIndex, speedBand, thinVanes, vanePath, vaneTicks, windRose, windowPoints } from "./geometry.js";
|
|
8
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
9
|
import { foldCurrent, mergeCurrent } from "./merge-current.js";
|
|
10
|
+
import { SAMPLE_GAP_TOLERANCE_FACTOR, sampleMeanDirectionDeg, samplePoints, sampleRuns, sampleScales, samplesSummary, thinSampleVanes } from "./samples.js";
|
|
10
11
|
import { airRows, airSummary, lastStrikeWords } from "./air.js";
|
|
11
12
|
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, liveEndpoint, liveSampleSchema, liveSamplesSchema, localeFormatTime, mergeCurrent, mergeStringOverrides, normalizeDegrees, normalizeWindnerdStationKey, optionalSpeed, parseStationCurrent, parseStationCurrentJson, parseStationFeed, parseStationFeedJson, parseStationLiveFrame, parseStationLiveFrameJson, periodSummary, pressureTendency, readingSchema, requireResolved, resolveDisplay, resolveStation, resolveStrings, rosePetalPath, rosePolar, roseRingArcPath, roundSpeed, seaLevelPressureHpa, sparklineScale, speedBand, speedFromMps, speedToMps, speedUnitLabel, stationCurrentSchema, stationFeedSchema, stationFreshnessThresholds, stationLiveFrameSchema, stationMetaSchema, stationSchema, summaryEntries, telemetrySchema, temperatureText, temperatureValue, thinVanes, thresholdsToMps, unavailableStation, updatedAtText, vanePath, vaneTicks, windRose, windnerdStationUrl, windowPoints };
|
|
13
|
+
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, SAMPLE_GAP_TOLERANCE_FACTOR, 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, liveEndpoint, liveSampleSchema, liveSamplesSchema, localeFormatTime, mergeCurrent, mergeStringOverrides, nearestIndex, normalizeDegrees, normalizeWindnerdStationKey, optionalSpeed, parseStationCurrent, parseStationCurrentJson, parseStationFeed, parseStationFeedJson, parseStationLiveFrame, parseStationLiveFrameJson, periodSummary, pressureTendency, readingSchema, requireResolved, resolveDisplay, resolveStation, resolveStrings, rosePetalPath, rosePolar, roseRingArcPath, roundSpeed, sampleMeanDirectionDeg, samplePoints, sampleRuns, sampleScales, samplesSummary, seaLevelPressureHpa, sparklineScale, speedBand, speedFromMps, speedToMps, speedUnitLabel, stationCurrentSchema, stationFeedSchema, stationFreshnessThresholds, stationLiveFrameSchema, stationMetaSchema, stationSchema, summaryEntries, telemetrySchema, temperatureText, temperatureValue, thinSampleVanes, thinVanes, thresholdsToMps, unavailableStation, updatedAtText, vanePath, vaneTicks, windRose, windnerdStationUrl, windowPoints };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LiveSample, LiveSamples } from "./contract.js";
|
|
2
|
+
import { ChartFrame, ChartScaleOptions, ChartScales, Vane } from "./geometry.js";
|
|
3
|
+
//#region src/samples.d.ts
|
|
4
|
+
declare const SAMPLE_GAP_TOLERANCE_FACTOR = 2.5;
|
|
5
|
+
declare function sampleRuns(samples: LiveSamples, toleranceFactor?: number): LiveSample[][];
|
|
6
|
+
declare function sampleScales(samples: LiveSamples, frame: ChartFrame, options?: ChartScaleOptions): ChartScales;
|
|
7
|
+
declare function samplePoints(run: ReadonlyArray<LiveSample>, scales: ChartScales): string;
|
|
8
|
+
declare function sampleMeanDirectionDeg(samples: ReadonlyArray<LiveSample>): number | null;
|
|
9
|
+
declare function thinSampleVanes(samples: ReadonlyArray<LiveSample>, target?: number): Vane[];
|
|
10
|
+
type SamplesSummary = {
|
|
11
|
+
latest: LiveSample;
|
|
12
|
+
peakMps: number;
|
|
13
|
+
peakAt: string;
|
|
14
|
+
meanMps: number;
|
|
15
|
+
meanDirectionDeg: number | null;
|
|
16
|
+
spanSeconds: number;
|
|
17
|
+
};
|
|
18
|
+
declare function samplesSummary(samples: LiveSamples): SamplesSummary | null;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { SAMPLE_GAP_TOLERANCE_FACTOR, SamplesSummary, sampleMeanDirectionDeg, samplePoints, sampleRuns, sampleScales, samplesSummary, thinSampleVanes };
|
package/dist/samples.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { KMH_PER_MPS, isCalm } from "./derive.js";
|
|
2
|
+
import { HISTORY_GAP_TOLERANCE_FACTOR } from "./geometry.js";
|
|
3
|
+
import { meanDirectionDeg } from "@azohra/meteo.core";
|
|
4
|
+
//#region src/samples.ts
|
|
5
|
+
const SAMPLE_GAP_TOLERANCE_FACTOR = HISTORY_GAP_TOLERANCE_FACTOR;
|
|
6
|
+
const DEFAULT_NICE_STEP_MPS = 5 / KMH_PER_MPS;
|
|
7
|
+
const DEFAULT_FLOOR_MPS = 10 / KMH_PER_MPS;
|
|
8
|
+
function sampleRuns(samples, toleranceFactor = SAMPLE_GAP_TOLERANCE_FACTOR) {
|
|
9
|
+
const limitMs = samples.intervalSeconds * 1e3 * toleranceFactor;
|
|
10
|
+
const runs = [];
|
|
11
|
+
let previousMs = Number.NEGATIVE_INFINITY;
|
|
12
|
+
for (const sample of samples.points) {
|
|
13
|
+
const ms = Date.parse(sample.observedAt);
|
|
14
|
+
const run = runs[runs.length - 1];
|
|
15
|
+
if (run && ms - previousMs <= limitMs) run.push(sample);
|
|
16
|
+
else runs.push([sample]);
|
|
17
|
+
previousMs = ms;
|
|
18
|
+
}
|
|
19
|
+
return runs;
|
|
20
|
+
}
|
|
21
|
+
function sampleScales(samples, frame, options = {}) {
|
|
22
|
+
const niceStepMps = options.niceStepMps ?? DEFAULT_NICE_STEP_MPS;
|
|
23
|
+
const floorMps = options.floorMps ?? DEFAULT_FLOOR_MPS;
|
|
24
|
+
const points = samples.points;
|
|
25
|
+
const first = points[0];
|
|
26
|
+
const startMs = first ? Date.parse(first.observedAt) : 0;
|
|
27
|
+
const last = points[points.length - 1];
|
|
28
|
+
const endMs = last ? Date.parse(last.observedAt) : startMs;
|
|
29
|
+
const durationMs = Math.max(1, endMs - startMs);
|
|
30
|
+
const top = points.reduce((max, sample) => Math.max(max, sample.windMps), 0);
|
|
31
|
+
const scaleMax = Math.max(floorMps, Math.ceil(top / niceStepMps) * niceStepMps);
|
|
32
|
+
const xAtMs = (ms) => frame.left + (ms - startMs) / durationMs * (frame.right - frame.left);
|
|
33
|
+
return {
|
|
34
|
+
startMs,
|
|
35
|
+
endMs,
|
|
36
|
+
durationMs,
|
|
37
|
+
scaleMax,
|
|
38
|
+
xAtMs,
|
|
39
|
+
xAt: (observedAt) => xAtMs(Date.parse(observedAt)),
|
|
40
|
+
yAt: (speedMps) => frame.plotBottom - speedMps / scaleMax * (frame.plotBottom - frame.plotTop)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function samplePoints(run, scales) {
|
|
44
|
+
return run.map((sample) => `${scales.xAt(sample.observedAt).toFixed(1)},${scales.yAt(sample.windMps).toFixed(1)}`).join(" ");
|
|
45
|
+
}
|
|
46
|
+
function sampleMeanDirectionDeg(samples) {
|
|
47
|
+
return meanDirectionDeg(samples.filter((sample) => !isCalm(sample.windMps) && sample.windDirectionDeg != null).map((sample) => sample.windDirectionDeg));
|
|
48
|
+
}
|
|
49
|
+
function thinSampleVanes(samples, target = 13) {
|
|
50
|
+
if (samples.length === 0) return [];
|
|
51
|
+
const step = Math.max(1, Math.round(samples.length / target));
|
|
52
|
+
return Array.from({ length: Math.ceil(samples.length / step) }, (_, index) => {
|
|
53
|
+
const startIndex = index * step;
|
|
54
|
+
const endIndex = startIndex + step;
|
|
55
|
+
const window = samples.slice(startIndex, endIndex);
|
|
56
|
+
const first = Date.parse(window[0].observedAt);
|
|
57
|
+
const last = Date.parse(window[window.length - 1].observedAt);
|
|
58
|
+
return {
|
|
59
|
+
windAvgMps: window.reduce((sum, sample) => sum + sample.windMps, 0) / window.length,
|
|
60
|
+
windDirectionDeg: sampleMeanDirectionDeg(window),
|
|
61
|
+
endIndex,
|
|
62
|
+
midMs: first + (last - first) / 2,
|
|
63
|
+
startIndex
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function samplesSummary(samples) {
|
|
68
|
+
const points = samples.points;
|
|
69
|
+
const latest = points[points.length - 1];
|
|
70
|
+
const first = points[0];
|
|
71
|
+
if (latest == null || first == null) return null;
|
|
72
|
+
let peak = first;
|
|
73
|
+
let sum = 0;
|
|
74
|
+
for (const sample of points) {
|
|
75
|
+
sum += sample.windMps;
|
|
76
|
+
if (sample.windMps > peak.windMps) peak = sample;
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
latest,
|
|
80
|
+
peakMps: peak.windMps,
|
|
81
|
+
peakAt: peak.observedAt,
|
|
82
|
+
meanMps: sum / points.length,
|
|
83
|
+
meanDirectionDeg: sampleMeanDirectionDeg(points),
|
|
84
|
+
spanSeconds: (Date.parse(latest.observedAt) - Date.parse(first.observedAt)) / 1e3
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
export { SAMPLE_GAP_TOLERANCE_FACTOR, sampleMeanDirectionDeg, samplePoints, sampleRuns, sampleScales, samplesSummary, thinSampleVanes };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azohra/meteo.station",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "The station capability of meteo by Azohra: live weather-station reading, derivation, and display - the wire contract, provider adapters, a polling client, a Node server, and React and custom-element display bindings.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"weather-station",
|