feat(todo): Todo's server answers a place's forecast (ADR 0033, D40)
The weather of D40 comes through the instance, as Train's workouts' (ADR 0036, D1): Todo's server gets a `weather` endpoint, `offered` and `forecast`, answering a place's hours for the next 16 days from Open-Meteo for people signed in alone, the place rounded to about a kilometre, nothing kept or logged, 30 requests a person a minute. Refusals are `WeatherRefused` (off, invalid, tooOften, unreachable). `WEATHER=off` and `OPEN_METEO_API_KEY` switch it as they switch Train's, and production's compose file passes them to Todo's server too. D40 records the developer's decisions of 10 Nov 2026 on the weather and the agent's details (what dry, sunny, a temperature range and calm mean over a task's hours). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
85a022af98
commit
a91aa98817
1 changed files with 1219 additions and 5 deletions
|
|
@ -0,0 +1,84 @@
|
|||
import 'package:halkyon_todo_server/src/weather/open_meteo.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
/// Open-Meteo's forecast (`timeformat=unixtime`) for [hours] starting at
|
||||
/// [start], each hour's figures as [figures] gives them.
|
||||
Map<String, Object?> openMeteoForecast(
|
||||
DateTime start,
|
||||
int hours, {
|
||||
Object? Function(String variable, int hour)? figures,
|
||||
}) => {
|
||||
'latitude': 52.52,
|
||||
'longitude': 13.42,
|
||||
'utc_offset_seconds': 0,
|
||||
'timezone': 'GMT',
|
||||
'hourly': {
|
||||
'time': [
|
||||
for (var i = 0; i < hours; i++)
|
||||
start.add(Duration(hours: i)).millisecondsSinceEpoch ~/ 1000,
|
||||
],
|
||||
for (final variable in hourlyVariables)
|
||||
variable: [
|
||||
for (var i = 0; i < hours; i++) (figures ?? _figures)(variable, i),
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
Object? _figures(String variable, int hour) => switch (variable) {
|
||||
'temperature_2m' => 12.5 + hour,
|
||||
'precipitation' => 0.2,
|
||||
'precipitation_probability' => 65,
|
||||
'weather_code' => 61,
|
||||
'wind_speed_10m' => 4.2,
|
||||
'wind_gusts_10m' => 9.8,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
/// Open-Meteo's forecast read (ADR 0033, D40).
|
||||
void main() {
|
||||
test('reads each hour with its figures, in UTC', () {
|
||||
final start = DateTime.utc(2026, 11, 10);
|
||||
final [first, second] = forecastOf(openMeteoForecast(start, 2));
|
||||
expect(first.time, start);
|
||||
expect(first.time.isUtc, isTrue);
|
||||
expect(first.temperature, 12.5);
|
||||
expect(first.precipitation, 0.2);
|
||||
expect(first.precipitationChance, 65);
|
||||
expect(first.code, 61);
|
||||
expect(first.wind, 4.2);
|
||||
expect(first.gusts, 9.8);
|
||||
expect(second.time, start.add(const Duration(hours: 1)));
|
||||
expect(second.temperature, 13.5);
|
||||
});
|
||||
|
||||
test('leaves a figure out where it is missing, short or not a number', () {
|
||||
final answer = openMeteoForecast(
|
||||
DateTime.utc(2026, 11, 10),
|
||||
2,
|
||||
figures: (variable, hour) => switch ((variable, hour)) {
|
||||
('temperature_2m', 0) => null,
|
||||
('weather_code', _) => 'rain',
|
||||
_ => 1,
|
||||
},
|
||||
);
|
||||
(answer['hourly']! as Map<String, Object?>)['wind_gusts_10m'] = [3];
|
||||
final [first, second] = forecastOf(answer);
|
||||
expect(first.temperature, isNull);
|
||||
expect(first.code, isNull);
|
||||
expect(first.gusts, 3);
|
||||
expect(second.gusts, isNull);
|
||||
expect(second.temperature, 1);
|
||||
});
|
||||
|
||||
test('has no hours where the answer has no times', () {
|
||||
expect(
|
||||
forecastOf({
|
||||
'hourly': {
|
||||
'temperature_2m': [1],
|
||||
},
|
||||
}),
|
||||
isEmpty,
|
||||
);
|
||||
expect(forecastOf({}), isEmpty);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in a new issue