2021-01-04 18:07:48 +08:00
|
|
|
|
package parser
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"errors"
|
2021-01-05 18:04:17 +08:00
|
|
|
|
"fmt"
|
2021-01-04 18:07:48 +08:00
|
|
|
|
"regexp"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
2021-01-05 13:14:15 +08:00
|
|
|
|
FlopRegex = `(?m)\((?P<type>[A-Z]{3}).*(.|\n|\r)*\)`
|
2021-01-05 12:43:04 +08:00
|
|
|
|
DestinationRegex = `(?P<dest>[A-Z]+)(?P<time>\d{0,4})`
|
|
|
|
|
|
DofValueRex = `(?m)DOF\/(?P<time>\d{6})`
|
2021-01-04 18:07:48 +08:00
|
|
|
|
TypeArrival = "ARR"
|
|
|
|
|
|
TypeDeparture = "DEP"
|
|
|
|
|
|
TypeFlightPlan = "FPL"
|
|
|
|
|
|
TypeDelay = "DLA"
|
2021-01-05 12:43:04 +08:00
|
|
|
|
|
2021-01-05 18:04:17 +08:00
|
|
|
|
DepRegex = `(?P<dep>[A-Z]+\d{0,4})`
|
|
|
|
|
|
ArrRegex = `(?P<arr>[A-Z]+\d{0,4})`
|
|
|
|
|
|
PlaneRegex = `(?P<plane>\w+\d+\/?\w\d+)`
|
|
|
|
|
|
AircraftRegex = `-?(?P<aircraft>[\w\/]+)`
|
|
|
|
|
|
DofRegex = `-?(?P<dof>DOF\/\d{6})?`
|
|
|
|
|
|
OtherRegex = `-?(?P<NAME>[A-Z0-9\/ \n\r]+)`
|
|
|
|
|
|
|
2021-01-05 13:14:15 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* example:
|
|
|
|
|
|
* (ARR-CSN3126/A5040-ZSPD-ZBTJ1601)
|
|
|
|
|
|
* (DEP-CSN3125/A4553-ZGHA0554-ZBTJ-DOF/120820)
|
|
|
|
|
|
*/
|
2021-01-05 18:04:17 +08:00
|
|
|
|
CompositeDepArr = `(?m)\([A-Z]{3}-` + PlaneRegex + "-" + DepRegex + "-" + ArrRegex + DofRegex + `\)`
|
2021-01-05 13:14:15 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* sample:
|
|
|
|
|
|
* (DLA‐ABC123‐NZAA0145‐VTBS‐DOF/091120)
|
|
|
|
|
|
*/
|
2021-01-05 18:04:17 +08:00
|
|
|
|
CompositeDelay = `(?m)\(DLA-` + PlaneRegex + "-" + DepRegex + "-" + ArrRegex + DofRegex + `\)`
|
2021-01-05 12:43:04 +08:00
|
|
|
|
|
|
|
|
|
|
KeyDeparture = "dep"
|
|
|
|
|
|
KeyArrival = "arr"
|
|
|
|
|
|
KeyDof = "dof"
|
2021-01-05 18:04:17 +08:00
|
|
|
|
KeyPlane = "plane"
|
|
|
|
|
|
KeyAircraft = "aircraft"
|
|
|
|
|
|
KeyTime = "time"
|
2021-01-04 18:07:48 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var flopRegex = regexp.MustCompile(FlopRegex)
|
|
|
|
|
|
|
2021-01-05 18:04:17 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* example:
|
|
|
|
|
|
* (FPL-AAR997-IS
|
|
|
|
|
|
* -B763/H-SDHIPRWZ/S
|
|
|
|
|
|
* -RKSI0120
|
|
|
|
|
|
* -N0473F320 NOPIK1B NOPIK G597 GONAV/N0473F320 G597 AGAVO/K0876S0980
|
|
|
|
|
|
* G597 DONVO A326 ANRAT ANRAT2A
|
|
|
|
|
|
* -ZBTJ0126 ZBAA
|
|
|
|
|
|
* -EET/ZSHA0025 ZYSH0039 ZBPE0059 REG/HL7507 SEL/KRHJ OPR/AAR
|
|
|
|
|
|
* DOF/090516 RMK/TCAS II EQUIPPED NAV/RNAV1 RNAV5 STS/CARGO)
|
|
|
|
|
|
* NNNN
|
|
|
|
|
|
*/
|
|
|
|
|
|
var CompositeFlightPlan = `(?m)\(FPL-` + PlaneRegex + `-IS( |\n)+` +
|
|
|
|
|
|
AircraftRegex + getOtherRegexWithName("p1") + "-" +
|
|
|
|
|
|
DepRegex + `[ \n]+-` +
|
|
|
|
|
|
getOtherRegexWithName("p2") + "-" +
|
|
|
|
|
|
ArrRegex + ` \w+[ \n]+-` +
|
|
|
|
|
|
getOtherRegexWithName("p3") + `\)`
|
|
|
|
|
|
|
2021-01-04 18:07:48 +08:00
|
|
|
|
func parseArrOrDep(telegram *Telegram, data string) {
|
2021-01-05 18:04:17 +08:00
|
|
|
|
fmt.Println(CompositeDepArr)
|
2021-01-05 12:43:04 +08:00
|
|
|
|
fields := getFields(CompositeDepArr, data)
|
|
|
|
|
|
if len(fields) < 1 {
|
2021-01-05 12:45:24 +08:00
|
|
|
|
telegram.ParseErrors = append(telegram.ParseErrors, errors.New("data less than 4 "))
|
2021-01-05 12:45:09 +08:00
|
|
|
|
telegram.Parsed = false
|
|
|
|
|
|
return
|
2021-01-04 18:07:48 +08:00
|
|
|
|
}
|
2021-01-05 12:45:09 +08:00
|
|
|
|
|
2021-01-05 12:43:04 +08:00
|
|
|
|
telegram.FlightNumber, telegram.RegisterNumber = parseFlight(fields[KeyPlane])
|
|
|
|
|
|
telegram.Departure, telegram.DepartureTime = parseAirportAndTime(fields[KeyDeparture])
|
|
|
|
|
|
telegram.Destination, telegram.DestinationTime = parseAirportAndTime(fields[KeyArrival])
|
|
|
|
|
|
dofValue := fields[KeyDof]
|
|
|
|
|
|
if len(dofValue) > 0 {
|
|
|
|
|
|
telegram.DateOfFlight = parseDof(dofValue)
|
2021-01-04 18:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
telegram.Parsed = true
|
2021-01-05 12:45:09 +08:00
|
|
|
|
|
2021-01-04 18:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func parseFlightPlan(telegram *Telegram, data string) {
|
2021-01-05 18:04:17 +08:00
|
|
|
|
fmt.Println(CompositeFlightPlan)
|
|
|
|
|
|
fields := getFields(CompositeFlightPlan, data)
|
|
|
|
|
|
telegram.FlightNumber, _ = parseFlight(fields[KeyPlane])
|
|
|
|
|
|
telegram.Aircraft = fields[KeyAircraft]
|
|
|
|
|
|
telegram.Departure, telegram.DepartureTime = parseAirportAndTime(fields[KeyDeparture])
|
|
|
|
|
|
telegram.Destination, telegram.DestinationTime = parseAirportAndTime(fields[KeyArrival])
|
|
|
|
|
|
telegram.DateOfFlight = parseDof(fields["p3"])
|
2021-01-04 18:07:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func parseDelay(telegram *Telegram, data string) {
|
2021-01-05 13:14:15 +08:00
|
|
|
|
fields := getFields(CompositeDelay, data)
|
|
|
|
|
|
if len(fields) < 1 {
|
|
|
|
|
|
telegram.ParseErrors = append(telegram.ParseErrors, errors.New("data less than 4 "))
|
|
|
|
|
|
telegram.Parsed = false
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
telegram.FlightNumber, telegram.RegisterNumber = parseFlight(fields[KeyPlane])
|
|
|
|
|
|
telegram.Departure, telegram.DepartureTime = parseAirportAndTime(fields[KeyDeparture])
|
|
|
|
|
|
telegram.Destination, telegram.DestinationTime = parseAirportAndTime(fields[KeyArrival])
|
|
|
|
|
|
dofValue := fields[KeyDof]
|
|
|
|
|
|
if len(dofValue) > 0 {
|
|
|
|
|
|
telegram.DateOfFlight = parseDof(dofValue)
|
|
|
|
|
|
}
|
|
|
|
|
|
telegram.Parsed = true
|
2021-01-04 18:07:48 +08:00
|
|
|
|
}
|