refactor: Update ARR body parsing logic
The code changes in `pattern_test.go` update the ARR body parsing logic. The message body parsing now correctly handles ARR bodies with a different pattern format. This ensures accurate extraction of data based on patterns and improves the overall functionality of the code. group of more than one alternative in fpl
This commit is contained in:
@@ -107,7 +107,7 @@ const (
|
||||
//
|
||||
// The regular expression uses named capture groups for each segment, allowing for easy extraction of specific information from a matched flight plan string.
|
||||
// fplPatternString = `\((?P<category>[A-Z]{3})\-(?P<number>[A-Z]+\d+)\-(?P<indicator>[A-Z]{2})(.*\n)?(.*\n)?\-(?P<aircraft>[A-Z]+\d+\/?[A-Z]?)\s*\-(?P<surve>.*)(.*\n)?\-(?P<departure>[A-Z]{4})(?P<departure_time>\d{4})(.*\n)?\-(?P<speed>[A-Z]+\d+)(?P<level>[A-Z0-9]+)\s(?P<route>.*)(.*\n)?\-(?P<destination>[A-Z]{4})(?P<estt>\d{4})\s(?P<alter>[A-Z]{4})(.*\n)?\-(?P<pbn>PBN\/[A-Z0-9]+)\s(?P<nav>NAV\/\w+)\sREG\/(?P<reg>[A-Z0-9]+)\sEET\/(?P<eet>\w{4}\d{4})\sSEL\/(?P<sel>\w+)\sPER\/(?P<performance>\w)\sRIF\/(?P<rif>\w+\s[A-Z0-9]+\s[A-Z]+)\s*RMK\/(?P<remark>.*)\)$`
|
||||
fplPatternString = `\((?P<category>[A-Z]{3})-(?P<number>[A-Z]+\d+)-(?P<indicator>[A-Z]{2})\n-(?P<aircraft>[A-Z]+\d+\/?[A-Z]?)\n?-(?P<surve>.*)\n?-(?P<departure>[A-Z]{4})(?P<departure_time>\d{4})\n?-(?P<speed>[A-Z]+\d+)(?P<level>[A-Z0-9]+)\s+(?P<route>(.|\n)+)\n-(?P<destination>[A-Z]{4})(?P<estt>\d{4})\s+(?P<alter>[A-Z]{4})\n?-([A-Z]{3}\/(?:[A-Z]{4}\d{4}\s?)+)?(?P<other>(?m)[A-Z]{3}\/(.|\n)*)\)$`
|
||||
fplPatternString = `\((?P<category>[A-Z]{3})-(?P<number>[A-Z]+\d+)-(?P<indicator>[A-Z]{2})\n-(?P<aircraft>[A-Z]+\d+\/?[A-Z]?)\n?-(?P<surve>.*)\n?-(?P<departure>[A-Z]{4})(?P<departure_time>\d{4})\n?-(?P<speed>[A-Z]+\d+)(?P<level>[A-Z0-9]+)\s+(?P<route>(.|\n)+)\n-(?P<destination>[A-Z]{4})(?P<estt>\d{4})\s?(?P<alter>(\s[A-Z]{4})+)\n?-([A-Z]{3}\/(?:[A-Z]{4}\d{4}\s?)+)?(?P<other>(?m)[A-Z]{3}\/(.|\n)*)\)$`
|
||||
)
|
||||
|
||||
// Initialize the bodyPatterns map
|
||||
|
||||
@@ -86,7 +86,7 @@ func extractData(match []string, re *regexp.Regexp) map[string]string {
|
||||
data := make(map[string]string)
|
||||
for i, name := range re.SubexpNames() {
|
||||
if i != 0 && name != "" {
|
||||
data[name] = match[i]
|
||||
data[name] = strings.TrimSpace(match[i])
|
||||
}
|
||||
}
|
||||
return data
|
||||
|
||||
@@ -246,6 +246,66 @@ NNNN
|
||||
Expect(arrmsg.ArrivalTime).To(Equal("1604"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("with this real FPL message", func() {
|
||||
message := `ZCZC TMQ2617 142150
|
||||
|
||||
|
||||
GG ZBTJZPZX
|
||||
|
||||
|
||||
150551 ZBTJUOBK
|
||||
|
||||
|
||||
(FPL-OKA2861-IS
|
||||
|
||||
|
||||
-MA60/M-SHID/C
|
||||
|
||||
|
||||
-ZBTJ0030
|
||||
|
||||
|
||||
-K0420S0450 CG J1 FZ
|
||||
|
||||
|
||||
-ZSYT0100 ZSQD ZYTL
|
||||
|
||||
|
||||
-REG/B3710 SEL/ RMK/TCAS )
|
||||
|
||||
NNNN
|
||||
`
|
||||
It("should parse the whole message correctly", func() {
|
||||
parsedMessage, err := Parse(message)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(parsedMessage).ToNot(BeNil())
|
||||
Expect(parsedMessage.MessageID).To(Equal("TMQ2617"))
|
||||
Expect(parsedMessage.DateTime).To(Equal("142150"))
|
||||
Expect(parsedMessage.PrimaryAddress).To(Equal("ZBTJZPZX"))
|
||||
Expect(parsedMessage.SecondaryAddresses).To(BeNil())
|
||||
Expect(parsedMessage.PriorityIndicator).To(Equal("GG"))
|
||||
Expect(parsedMessage.OriginatorDateTime).To(Equal("150551"))
|
||||
Expect(parsedMessage.Originator).To(Equal("ZBTJUOBK"))
|
||||
|
||||
fplmsg := parsedMessage.BodyData.(*domain.FPL)
|
||||
Expect(fplmsg.Category).To(Equal("FPL"))
|
||||
Expect(fplmsg.FlightNumber).To(Equal("OKA2861"))
|
||||
Expect(fplmsg.FlightRulesAndType).To(Equal("IS"))
|
||||
Expect(fplmsg.AircraftID).To(Equal("MA60/M"))
|
||||
Expect(fplmsg.SSRModeAndCode).To(Equal("SHID/C"))
|
||||
Expect(fplmsg.DepartureAirport).To(Equal("ZBTJ"))
|
||||
Expect(fplmsg.DepartureTime).To(Equal("0030"))
|
||||
Expect(fplmsg.CruisingSpeedAndLevel).To(Equal("K0420S0450"))
|
||||
Expect(fplmsg.Route).To(Equal("CG J1 FZ"))
|
||||
Expect(fplmsg.DestinationAndTotalTime).To(Equal("ZSYT0100"))
|
||||
Expect(fplmsg.AlternateAirport).To(Equal("ZSQD ZYTL"))
|
||||
Expect(fplmsg.OtherInfo).To(Equal("REG/B3710 SEL/ RMK/TCAS"))
|
||||
// Expect(fplmsg.PBN).To(Equal("B3710"))
|
||||
Expect(fplmsg.SELCALCode).To(Equal(""))
|
||||
Expect(fplmsg.Remarks).To(Equal("TCAS"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Describe("Utility Functions", func() {
|
||||
|
||||
Reference in New Issue
Block a user