Skip to content

Commit 1797031

Browse files
committed
docs(stations): document measurement retrieval
1 parent 12304ba commit 1797031

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

docs/stations.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,53 @@ Each `Weather` represents one entry in the `weather` array. It accepts the
169169
available METAR precipitation, descriptor, intensity, proximity, obscuration,
170170
and other codes. At least one value must be provided, and codes are kept as
171171
strings so additional values accepted by OpenWeather are not restricted.
172+
173+
## Retrieve Measurements
174+
175+
Use `measurements()` to retrieve measurements aggregated by minute, hour, or
176+
day for a station and time range.
177+
178+
```php
179+
use ProgrammatorDev\OpenWeatherMap\Enum\AggregationInterval;
180+
181+
$measurements = $api->stations()->measurements(
182+
stationId: $station->id(),
183+
interval: AggregationInterval::HOUR,
184+
startAt: new DateTimeImmutable('2 days ago'),
185+
endAt: new DateTimeImmutable('now'),
186+
limit: 100,
187+
);
188+
```
189+
190+
> **Processing delay:** Submitted measurements are aggregated asynchronously
191+
> and may take more than 24 hours to appear. OpenWeather does not document an
192+
> availability timeframe.
193+
194+
The method returns an array of `MeasurementAggregate` entities and returns an
195+
empty array when no aggregates are available for the requested interval. Each
196+
entity identifies its aggregation interval, bucket time, and station.
197+
198+
```php
199+
foreach ($measurements as $measurement) {
200+
echo $measurement->interval()?->value;
201+
echo $measurement->dateTime()?->format(DATE_ATOM);
202+
echo $measurement->stationId();
203+
204+
echo $measurement->temperature()?->average(); // 20.5
205+
echo $measurement->temperature()?->averageWithUnit(); // 20.5 °C
206+
echo $measurement->humidity()?->averageWithUnit(); // 64 %
207+
echo $measurement->wind()?->speedWithUnit(); // 3.08 m/s
208+
echo $measurement->pressure()?->averageWithUnit(); // 1013 hPa
209+
echo $measurement->precipitation()?->rainWithUnit(); // 0.6 mm
210+
}
211+
```
212+
213+
Temperature and pressure aggregates expose `minimum()`, `maximum()`,
214+
`average()`, and `weight()`. Humidity exposes `average()` and `weight()`. Wind
215+
exposes `direction()` and `speed()`, while precipitation exposes `rain()` and
216+
`snow()`. Measurement properties and nested structures are nullable because
217+
OpenWeather may omit data that was unavailable for an aggregation bucket.
218+
219+
The endpoint returns aggregates rather than the original submitted
220+
measurements. Submitted visibility, cloud layers, METAR weather descriptions,
221+
and other raw fields are not included in the documented aggregate response.

0 commit comments

Comments
 (0)