Fix U.S. PROB group handling and trim RMK from remark
This commit is contained in:
parent
52fb856f9b
commit
486688e72a
@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
var lex = lexer.MustSimple([]lexer.SimpleRule{
|
var lex = lexer.MustSimple([]lexer.SimpleRule{
|
||||||
{Name: "header", Pattern: `TAF (AMD|COR)? ?`},
|
{Name: "header", Pattern: `TAF (AMD|COR)? ?`},
|
||||||
{Name: "Remark", Pattern: `RMK .*`},
|
{Name: "Remark", Pattern: `RMK[^\n]*`},
|
||||||
{Name: "Number", Pattern: `\d+`},
|
{Name: "Number", Pattern: `\d+`},
|
||||||
{Name: "Modifier", Pattern: `[+-]|VC`},
|
{Name: "Modifier", Pattern: `[+-]|VC`},
|
||||||
{Name: "Prob", Pattern: "PROB"},
|
{Name: "Prob", Pattern: "PROB"},
|
||||||
|
@ -34,8 +34,8 @@ type ValidPair struct {
|
|||||||
|
|
||||||
type Probability struct {
|
type Probability struct {
|
||||||
Pos lexer.Position
|
Pos lexer.Position
|
||||||
Value string `Prob @Number`
|
Value string `Prob @Number`
|
||||||
Time string `(WS @Number)?`
|
Valid ValidPair `(WS @@)?`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WindSpeed struct {
|
type WindSpeed struct {
|
||||||
|
29
taf.go
29
taf.go
@ -322,7 +322,7 @@ func DecodeWithOptions(r io.Reader, opts Options) (*Forecast, error) {
|
|||||||
case item.Probability != nil:
|
case item.Probability != nil:
|
||||||
// If the time is empty, this probability belongs to the
|
// If the time is empty, this probability belongs to the
|
||||||
// next change.
|
// next change.
|
||||||
if item.Probability.Time == "" {
|
if item.Probability.Valid.Start == "" {
|
||||||
prob, err := strconv.Atoi(item.Probability.Value)
|
prob, err := strconv.Atoi(item.Probability.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, participle.Errorf(item.Probability.Pos, "prob: %s", err)
|
return nil, participle.Errorf(item.Probability.Pos, "prob: %s", err)
|
||||||
@ -332,34 +332,11 @@ func DecodeWithOptions(r io.Reader, opts Options) (*Forecast, error) {
|
|||||||
} else {
|
} else {
|
||||||
pr := &Probability{}
|
pr := &Probability{}
|
||||||
|
|
||||||
// The probability time string must have 4 characters,
|
pr.Valid, err = parseValid(&item.Probability.Valid, opts.Month, opts.Year)
|
||||||
// 2 for starting time and 2 for ending time
|
|
||||||
if len(item.Probability.Time) < 4 {
|
|
||||||
return nil, participle.Errorf(item.Probability.Pos, "prob: invalid time %q", item.Probability.Time)
|
|
||||||
}
|
|
||||||
|
|
||||||
startStr := item.Probability.Time[:2]
|
|
||||||
endStr := item.Probability.Time[2:]
|
|
||||||
|
|
||||||
start, err := strconv.Atoi(startStr)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, participle.Errorf(item.Probability.Pos, "prob: %s", err)
|
return nil, participle.Errorf(item.Probability.Pos, "prob: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
end, err := strconv.Atoi(endStr)
|
|
||||||
if err != nil {
|
|
||||||
return nil, participle.Errorf(item.Probability.Pos, "prob: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
t := fc.PublishTime
|
|
||||||
pr.Valid = ValidPair{
|
|
||||||
From: time.Date(t.Year(), t.Month(), t.Day(), start, 0, 0, 0, time.UTC),
|
|
||||||
To: time.Date(t.Year(), t.Month(), t.Day(), end, 0, 0, 0, time.UTC),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the duration by subtracting the from time from the to time
|
|
||||||
pr.Valid.Duration = pr.Valid.To.Sub(pr.Valid.From)
|
|
||||||
|
|
||||||
fc.Probabilities = append(fc.Probabilities, pr)
|
fc.Probabilities = append(fc.Probabilities, pr)
|
||||||
|
|
||||||
// Set out to the probability value so that future mutations
|
// Set out to the probability value so that future mutations
|
||||||
@ -367,7 +344,7 @@ func DecodeWithOptions(r io.Reader, opts Options) (*Forecast, error) {
|
|||||||
out = reflect.ValueOf(pr).Elem()
|
out = reflect.ValueOf(pr).Elem()
|
||||||
}
|
}
|
||||||
case item.Remark != nil:
|
case item.Remark != nil:
|
||||||
fc.Remark = *item.Remark
|
fc.Remark = strings.TrimSpace(strings.TrimPrefix(*item.Remark, "RMK"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user