add arr parser
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
package parser
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
FlopRegex = `(?m)^\((?P<flop>\w{3})-.*`
|
||||||
|
DestinationRegex = `(?P<dest>[A-Z]+)(?P<time>\d{0,4})?`
|
||||||
|
DOFRegex = `(?P<dof>\w+)/(?P<time>\d{6})`
|
||||||
|
TypeArrival = "ARR"
|
||||||
|
)
|
||||||
|
|
||||||
|
func parseArr(telegram *Telegram, data string) {
|
||||||
|
values := getFlopValues(data)
|
||||||
|
l := len(values)
|
||||||
|
if l < 4 {
|
||||||
|
telegram.ParseErrors = append(telegram.ParseErrors, errors.New("arrival data less than 4 "))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
telegram.FlightNumber, telegram.RegisterNumber = parseFlight(values[1])
|
||||||
|
telegram.Departure = values[2]
|
||||||
|
telegram.Destination, telegram.DestinationTime = getAirportAndTime(values[3])
|
||||||
|
if l == 5 {
|
||||||
|
parseDof(telegram, values[4])
|
||||||
|
}
|
||||||
|
telegram.Parsed = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseDof(telegram *Telegram, text string) {
|
||||||
|
if dof := getFields(DOFRegex, text); dof["dof"] == "DOF" {
|
||||||
|
telegram.DateOfFlight, _ = time.Parse("060102", dof["time"])
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package parser
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestArr(t *testing.T) {
|
||||||
|
ast := assert.New(t)
|
||||||
|
s := `ZCZC TMQ2526 141605
|
||||||
|
FF ZBTJZPZX
|
||||||
|
141604 ZBACZQZX
|
||||||
|
(ARR-JAE7433/A0132-RKSI-ZBTJ1604-DOF/120820)
|
||||||
|
NNNN`
|
||||||
|
tele, err := Parse(s)
|
||||||
|
ast.Nil(err, "Should be no error")
|
||||||
|
ast.Equal(tele.Complete, true, "Should be complete telegram")
|
||||||
|
ast.Equal(4, len(tele.Fields), "get 4 lines")
|
||||||
|
ast.Equal("ZCZC TMQ2526 141605", tele.Fields[0])
|
||||||
|
ast.Equal(2526, tele.Sequence, "TMQ must be 2526")
|
||||||
|
ast.Equal(false, tele.Type == "PLN", "Not a plan")
|
||||||
|
ast.Equal("ARR", tele.Type, "Flop type is ARR")
|
||||||
|
ast.Equal("JAE7433", tele.FlightNumber, "flight number is JAE7433")
|
||||||
|
ast.Equal("A0132", tele.RegisterNumber, "register number is A0132")
|
||||||
|
ast.Equal("RKSI", tele.Departure, "departure airport is RKSI")
|
||||||
|
ast.Equal("ZBTJ", tele.Destination, "destination airport is ZBTJ")
|
||||||
|
ast.Equal(16, tele.DestinationTime.Hour())
|
||||||
|
ast.Equal(4, tele.DestinationTime.Minute())
|
||||||
|
ast.Equal(2012, tele.DateOfFlight.Year())
|
||||||
|
ast.Equal(8, int(tele.DateOfFlight.Month()))
|
||||||
|
ast.Equal(20, tele.DateOfFlight.Day())
|
||||||
|
|
||||||
|
s = `ZCZC TMQ2526 141605
|
||||||
|
FF ZBTJZPZX
|
||||||
|
141604 ZBACZQZX
|
||||||
|
(ARR-JAE7433/A0132-RKSI)
|
||||||
|
NNNN`
|
||||||
|
tele, err = Parse(s)
|
||||||
|
ast.Equal(1, len(tele.ParseErrors))
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user