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>
99 lines
2.9 KiB
Go
99 lines
2.9 KiB
Go
package weather
|
|
|
|
import (
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("TAF Parser", func() {
|
|
Describe("parseTaf", func() {
|
|
It("should parse a simple TAF", func() {
|
|
raw := "TAF KJFK 251200Z 2512/2612 35012KT 10SM FEW020="
|
|
taf, err := parseTaf(raw)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(taf).ToNot(BeNil())
|
|
Expect(taf.StationID).To(Equal("KJFK"))
|
|
Expect(len(taf.Periods)).To(BeNumerically(">", 0))
|
|
})
|
|
|
|
It("should parse TAF with FM period", func() {
|
|
raw := "TAF KJFK 251200Z 2512/2612 35012KT 10SM FEW020 FM251800 36015KT 10SM SCT030="
|
|
taf, err := parseTaf(raw)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(len(taf.Periods)).To(BeNumerically(">=", 2))
|
|
Expect(taf.Periods[1].Type).To(Equal("FM"))
|
|
})
|
|
|
|
It("should parse TAF with TEMPO period", func() {
|
|
raw := "TAF KJFK 251200Z 2512/2612 35012KT 10SM FEW020 TEMPO2512/2515 27015G25KT 5SM -RA="
|
|
taf, err := parseTaf(raw)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(len(taf.Periods)).To(BeNumerically(">=", 1))
|
|
// Find TEMPO period
|
|
found := false
|
|
for _, period := range taf.Periods {
|
|
if period.Type == "TEMPO" {
|
|
found = true
|
|
Expect(period.Wind).ToNot(BeNil())
|
|
Expect(len(period.Phenomena)).To(BeNumerically(">", 0))
|
|
break
|
|
}
|
|
}
|
|
Expect(found).To(BeTrue())
|
|
})
|
|
|
|
It("should parse TAF with BECMG period", func() {
|
|
raw := "TAF KJFK 251200Z 2512/2612 35012KT 10SM FEW020 BECMG2512/2515 36015KT="
|
|
taf, err := parseTaf(raw)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
// Find BECMG period
|
|
found := false
|
|
for _, period := range taf.Periods {
|
|
if period.Type == "BECMG" {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
Expect(found).To(BeTrue())
|
|
})
|
|
|
|
It("should parse TAF with PROB", func() {
|
|
raw := "TAF KJFK 251200Z 2512/2612 35012KT 10SM FEW020 PROB30 TEMPO2512/2515 27015G25KT 5SM -RA="
|
|
taf, err := parseTaf(raw)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
// Find period with probability
|
|
found := false
|
|
for _, period := range taf.Periods {
|
|
if period.Probability > 0 {
|
|
found = true
|
|
Expect(period.Probability).To(Equal(30))
|
|
break
|
|
}
|
|
}
|
|
Expect(found).To(BeTrue())
|
|
})
|
|
|
|
It("should parse TAF with multiple periods", func() {
|
|
raw := "TAF KJFK 251200Z 2512/2612 35012KT 10SM FEW020 FM251800 36015KT 10SM SCT030 TEMPO2520/2602 27015G25KT 5SM -RA="
|
|
taf, err := parseTaf(raw)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(len(taf.Periods)).To(BeNumerically(">=", 2))
|
|
})
|
|
|
|
It("should parse TAF with remarks", func() {
|
|
raw := "TAF KJFK 251200Z 2512/2612 35012KT 10SM FEW020 RMK TEST REMARKS="
|
|
taf, err := parseTaf(raw)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(taf.Remarks).To(ContainSubstring("RMK"))
|
|
})
|
|
|
|
It("should handle unrecognized tokens as warnings", func() {
|
|
raw := "TAF KJFK 251200Z 2512/2612 35012KT 10SM FEW020 UNKNOWN TOKEN="
|
|
taf, err := parseTaf(raw)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(len(taf.Warnings)).To(BeNumerically(">", 0))
|
|
})
|
|
})
|
|
})
|
|
|