Implement comprehensive weather parsing capabilities following Clean Architecture principles with composite parser pattern for routing between aviation and weather messages. ## Features Added - Weather report parsing (METAR, SPECI, TAF) - Composite parser pattern for message routing - Lenient parsing with warnings for unrecognized tokens - Support for PROB and RMK sections in TAF - Rich domain modeling with typed weather elements ## Architecture **Domain Layer** (internal/domain/weather/): - WeatherMessage interface with Metar and Taf implementations - Weather elements: Wind, Visibility, Cloud, Temperature, Altimeter, Phenomenon - Domain errors: ErrInvalidFormat, ErrMissingStation, ErrMissingTime **Port Layer** (internal/port/weather_parser.go): - WeatherParser interface with CanParse and Parse methods **Adapter Layer** (internal/adapter/parser/weather/): - WeatherParserImpl with classification and parsing logic - Comprehensive regex patterns for weather elements - METAR/SPECI parser with element extraction - TAF parser with period handling (FM, TEMPO, BECMG, PROB) - Helper functions for time parsing and unit conversions **Composite Parser** (internal/adapter/parser/composite.go): - Routes weather reports to weather parser - Falls back to aviation parser for telegrams - Converts WeatherMessage to ParsedTelegram format ## Integration - Updated ProvideParser to create composite parser with weather parser - Added weather parser to Wire DI configuration - Updated processor_bench_test.go for weather parser integration - Documentation added in docs/weather-parser.md ## Testing - 29 comprehensive tests for weather parsing (all passing) - Tests for classification, METAR, SPECI, TAF, and composite routing - Benchmark compatibility maintained ## Fixes Applied - TAF PROB parsing: Include PROB/RMK in special section detection - Composite test: Updated to use properly formatted AFTN telegram - Linter issues: Switch statement refactor, removed unused patterns - Ineffective break statement fixed in TAF parser ## Coverage ~1,743 lines of new code with: - Complete METAR/SPECI parsing - TAF parsing with period support - Lenient error handling with warnings - Unit conversions and time utilities 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
4.0 KiB
Weather Parser Documentation
Overview
The weather parser module provides parsing capabilities for aviation weather reports including METAR, SPECI, and TAF messages. It is integrated into the system using a composite parser pattern that routes weather reports to the weather parser while maintaining backward compatibility with existing aviation telegram parsing.
Architecture
The weather parser follows Clean Architecture principles:
- Domain Layer (
internal/domain/weather/): Core domain types and interfaces - Port Layer (
internal/port/weather_parser.go): Parser interface definition - Adapter Layer (
internal/adapter/parser/weather/): Parser implementation - Composite Parser (
internal/adapter/parser/composite.go): Routes messages to appropriate parser
Supported Report Types
METAR (Aviation Routine Weather Report)
Standard hourly weather observations from airports.
Example:
METAR KJFK 251200Z 35012KT 10SM FEW020 25/18 Q1013=
SPECI (Aviation Selected Special Weather Report)
Special weather observations issued when conditions change significantly.
Example:
SPECI KORD 251215Z 27015G25KT 5SM -RA BKN030 OVC050 20/18 A2992=
TAF (Terminal Aerodrome Forecast)
Forecast weather conditions for airports, typically valid for 24-30 hours.
Example:
TAF KJFK 251200Z 2512/2612 35012KT 10SM FEW020 FM251800 36015KT 10SM SCT030=
Parsed Elements
Core Elements
- Station: 4-letter ICAO airport code
- Time: Issue/observation time (DDHHmmZ format)
- Wind: Direction, speed, gusts, variable conditions
- Visibility: Distance, unit (meters or statute miles), directional visibility
- Clouds: Type (FEW/SCT/BKN/OVC/VV), altitude, modifiers (CB/TCU)
- Temperature/Dewpoint: Temperature in Celsius
- Altimeter: Pressure setting (QNH in hPa or A in inHg)
- Weather Phenomena: Intensity, descriptors, weather codes
TAF-Specific Elements
- Validity Period: Forecast valid from/to times
- Periods: Main forecast, FM (from), TEMPO (temporary), BECMG (becoming)
- Probability: PROB30, PROB40 for uncertain conditions
Error Handling
The parser uses a lenient approach:
- Unrecognized tokens: Recorded in
warningsarray, parsing continues - Missing required fields: Returns appropriate domain errors
- Invalid format: Returns
ErrInvalidFormat
This ensures that partial parsing is possible even when some elements are not recognized.
Usage
The weather parser is automatically integrated via the composite parser. No special configuration is required.
Message Flow
- Raw message received
- Composite parser checks if message is a weather report
- If weather report: parsed by weather parser
- If not: parsed by aviation parser (existing behavior)
- Parsed result stored in
telegramstable withcategory= "METAR"/"SPECI"/"TAF" - Structured data stored in
body_dataJSONB field
Database Storage
Weather reports are stored in the existing telegrams table:
category: "METAR", "SPECI", or "TAF"body_data: JSONB containing structured weather datacontent: Original raw textmessage_id: Generated as{station}-{issue_time}
Testing
Test files are located in internal/adapter/parser/weather/:
classifier_test.go: Tests report type classificationmetar_parser_test.go: Tests METAR/SPECI parsingtaf_parser_test.go: Tests TAF parsingcomposite_test.go: Tests composite parser routing
Run tests:
go test ./internal/adapter/parser/weather/... -v
Limitations and Future Enhancements
Current implementation covers core METAR/TAF elements. Future enhancements may include:
- Runway Visual Range (RVR) parsing
- More comprehensive weather phenomenon codes
- Enhanced TAF period parsing
- Additional METAR modifiers
- Station metadata integration