refactor: Update constants and remove unused code in aviation_parser.go and constants.go
This commit is contained in:
@@ -39,17 +39,17 @@ require (
|
|||||||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
||||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||||
github.com/spf13/afero v1.11.0 // indirect
|
github.com/spf13/afero v1.11.0 // indirect
|
||||||
github.com/spf13/cast v1.6.0 // indirect
|
github.com/spf13/cast v1.7.0 // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
github.com/subosito/gotenv v1.6.0 // indirect
|
github.com/subosito/gotenv v1.6.0 // indirect
|
||||||
github.com/vektah/gqlparser/v2 v2.5.16 // indirect
|
github.com/vektah/gqlparser/v2 v2.5.16 // indirect
|
||||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
|
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
|
||||||
go.uber.org/multierr v1.11.0 // indirect
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
golang.org/x/crypto v0.25.0 // indirect
|
golang.org/x/crypto v0.26.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
|
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
|
||||||
golang.org/x/net v0.27.0 // indirect
|
golang.org/x/net v0.27.0 // indirect
|
||||||
golang.org/x/sys v0.23.0 // indirect
|
golang.org/x/sys v0.23.0 // indirect
|
||||||
golang.org/x/text v0.16.0 // indirect
|
golang.org/x/text v0.17.0 // indirect
|
||||||
golang.org/x/tools v0.23.0 // indirect
|
golang.org/x/tools v0.23.0 // indirect
|
||||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
|||||||
@@ -11,25 +11,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
StartIndicatorPrefix = "ZCZC"
|
|
||||||
EndHeaderMarker = "."
|
|
||||||
BeginPartMarker = "BEGIN PART"
|
|
||||||
|
|
||||||
Category = "category"
|
|
||||||
CategoryArrival = "ARR"
|
|
||||||
// FlightNumber = "number"
|
// FlightNumber = "number"
|
||||||
SSR = "ssr"
|
SSR = "ssr"
|
||||||
DepartureCode = "dep"
|
DepartureCode = "dep"
|
||||||
DepartureTime = "dep_time"
|
DepartureTime = "dep_time"
|
||||||
ArrivalCode = "arr"
|
ArrivalCode = "arr"
|
||||||
ArrivalTime = "arr_time"
|
ArrivalTime = "arr_time"
|
||||||
CategoryDeparture = "DEP"
|
// CategoryDeparture = "DEP"
|
||||||
DestinationCode = "dest"
|
DestinationCode = "dest"
|
||||||
OtherInfo = "other"
|
OtherInfo = "other"
|
||||||
CategoryCancellation = "CNL"
|
// CategoryCancellation = "CNL"
|
||||||
CategoryDelay = "DLA"
|
// CategoryDelay = "DLA"
|
||||||
NewDepartureTime = "new_departure_time"
|
// NewDepartureTime = "new_departure_time"
|
||||||
CategoryFlightPlan = "FPL"
|
// CategoryFlightPlan = "FPL"
|
||||||
ReferenceData = "reference_data"
|
ReferenceData = "reference_data"
|
||||||
Aircraft = "aircraft"
|
Aircraft = "aircraft"
|
||||||
CategorySurveillance = "surve"
|
CategorySurveillance = "surve"
|
||||||
|
|||||||
@@ -4,6 +4,17 @@ import "regexp"
|
|||||||
|
|
||||||
// String constants
|
// String constants
|
||||||
const (
|
const (
|
||||||
|
StartIndicatorPrefix = "ZCZC"
|
||||||
|
EndHeaderMarker = "."
|
||||||
|
BeginPartMarker = "BEGIN PART"
|
||||||
|
|
||||||
|
Category = "category"
|
||||||
|
CategoryArrival = "ARR"
|
||||||
|
CategoryDeparture = "DEP"
|
||||||
|
CategoryCancellation = "CNL"
|
||||||
|
CategoryDelay = "DLA"
|
||||||
|
CategoryFlightPlan = "FPL"
|
||||||
|
|
||||||
CANCELLED = "CNL"
|
CANCELLED = "CNL"
|
||||||
AirportCode = "airport"
|
AirportCode = "airport"
|
||||||
Date = "date"
|
Date = "date"
|
||||||
|
|||||||
@@ -97,103 +97,6 @@ func ParseWithDef(line string, parserDef *LineParser) *domain.ScheduleLine {
|
|||||||
return flightSchedule
|
return flightSchedule
|
||||||
}
|
}
|
||||||
|
|
||||||
// func ParseLine(line string) *domain.ScheduleLine {
|
|
||||||
// log := utils.GetSugaredLogger()
|
|
||||||
// cleanLine := strings.TrimSpace(line)
|
|
||||||
// words := strings.Split(cleanLine, " ")
|
|
||||||
// var flightSchedule = &domain.ScheduleLine{
|
|
||||||
// Reference: line,
|
|
||||||
// }
|
|
||||||
// var data map[string]string
|
|
||||||
|
|
||||||
// if indexData := extract(words[0], IndexExpression); indexData != nil {
|
|
||||||
// flightSchedule.Index = indexData[Index]
|
|
||||||
// words = words[1:]
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Define the parsing strategy
|
|
||||||
// parseStrategy := []string{
|
|
||||||
// Task,
|
|
||||||
// Date,
|
|
||||||
// FlightNumber,
|
|
||||||
// Register,
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Track parsed fields to avoid re-parsing
|
|
||||||
// parsed := make(map[string]bool)
|
|
||||||
// var maxParsed int
|
|
||||||
|
|
||||||
// // Parse each word in the line
|
|
||||||
// for i, word := range words {
|
|
||||||
// // Check if all fields have been parsed
|
|
||||||
// for _, name := range parseStrategy {
|
|
||||||
// // Skip if already parsed
|
|
||||||
// if parsed[name] {
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
// // Parse the word
|
|
||||||
// if data = extract(word, parserMap[name]); data != nil {
|
|
||||||
// // Update the flight schedule
|
|
||||||
// switch name {
|
|
||||||
// case Task:
|
|
||||||
// flightSchedule.Task = data[Task]
|
|
||||||
// parsed[Task] = true
|
|
||||||
// maxParsed = i
|
|
||||||
// case Date:
|
|
||||||
// flightSchedule.Date = data[Date]
|
|
||||||
// parsed[Date] = true
|
|
||||||
// maxParsed = i
|
|
||||||
// case FlightNumber:
|
|
||||||
// flightSchedule.FlightNumber = getFlightNumbers(data[FlightNumber])
|
|
||||||
// parsed[FlightNumber] = true
|
|
||||||
// maxParsed = i
|
|
||||||
// case Register:
|
|
||||||
// flightSchedule.AircraftReg = data[Register]
|
|
||||||
// parsed[Register] = true
|
|
||||||
// maxParsed = i
|
|
||||||
// }
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
// if maxParsed+1 < len(words) {
|
|
||||||
// flightSchedule.Waypoints = parseWaypoints(words[maxParsed+1:])
|
|
||||||
// } else {
|
|
||||||
// log.Warn("No waypoints found")
|
|
||||||
// flightSchedule.Comments = "No waypoints found"
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return flightSchedule
|
|
||||||
// }
|
|
||||||
// func ParseLine(line string) *domain.ScheduleLine {
|
|
||||||
// log := utils.GetSugaredLogger()
|
|
||||||
// cleanLine := strings.TrimSpace(line)
|
|
||||||
// words := strings.Split(cleanLine, " ")
|
|
||||||
// flightSchedule := &domain.ScheduleLine{Reference: line}
|
|
||||||
|
|
||||||
// if indexData := extract(words[0], IndexExpression); indexData != nil {
|
|
||||||
// flightSchedule.Index = indexData[Index]
|
|
||||||
// words = words[1:]
|
|
||||||
// }
|
|
||||||
|
|
||||||
// parseStrategy := []string{Task, Date, FlightNumber, Register}
|
|
||||||
// _, maxParsed := parseFields(words, parseStrategy, flightSchedule)
|
|
||||||
|
|
||||||
// if maxParsed+1 < len(words) {
|
|
||||||
// flightSchedule.Waypoints = parseWaypoints(words[maxParsed+1:])
|
|
||||||
// } else {
|
|
||||||
// log.Warn("No waypoints found")
|
|
||||||
// flightSchedule.Comments = "No waypoints found"
|
|
||||||
// }
|
|
||||||
// return flightSchedule
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func parseFields(words []string, parseStrategy []string, flightSchedule *domain.ScheduleLine) (map[string]bool, int) {
|
|
||||||
// parsed := make(map[string]bool)
|
|
||||||
// var maxParsed int
|
|
||||||
|
|
||||||
// for i, word := range words {
|
|
||||||
// for _, name := range parseStrategy {
|
// for _, name := range parseStrategy {
|
||||||
// if parsed[name] {
|
// if parsed[name] {
|
||||||
// continue
|
// continue
|
||||||
@@ -209,27 +112,6 @@ func ParseWithDef(line string, parserDef *LineParser) *domain.ScheduleLine {
|
|||||||
// return parsed, maxParsed
|
// return parsed, maxParsed
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// func updateFlightSchedule(flightSchedule *domain.ScheduleLine, name string, data map[string]string) {
|
|
||||||
// switch name {
|
|
||||||
// case Task:
|
|
||||||
// flightSchedule.Task = data[Task]
|
|
||||||
// case Date:
|
|
||||||
// flightSchedule.Date = data[Date]
|
|
||||||
// case FlightNumber:
|
|
||||||
// flightSchedule.FlightNumber = getFlightNumbers(data[FlightNumber])
|
|
||||||
// case Register:
|
|
||||||
// flightSchedule.AircraftReg = data[Register]
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func parseWaypoints(points []string) []domain.WayPoint {
|
|
||||||
// log := utils.GetSugaredLogger()
|
|
||||||
// if len(points) == 0 {
|
|
||||||
// log.Warn("No waypoints found")
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //find first waypoint
|
|
||||||
// var realWaypoints []string
|
// var realWaypoints []string
|
||||||
// for i, point := range points {
|
// for i, point := range points {
|
||||||
// if extract(point, WaypointExpression) != nil {
|
// if extract(point, WaypointExpression) != nil {
|
||||||
@@ -330,45 +212,38 @@ func updateFlightSchedule(flightSchedule *domain.ScheduleLine, name string, data
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parseWaypoints processes a slice of waypoint strings and returns a slice of WayPoint objects.
|
// parseWaypoints processes a slice of waypoint strings and returns a slice of WayPoint objects.
|
||||||
func parseWaypoints(points []string) ([]domain.WayPoint, error) {
|
func parseWaypoints(target []string) ([]domain.WayPoint, error) {
|
||||||
log := utils.GetSugaredLogger()
|
log := utils.GetSugaredLogger()
|
||||||
|
points := getValidPoints(target)
|
||||||
if len(points) == 0 {
|
if len(points) == 0 {
|
||||||
log.Warn("No waypoints found")
|
log.Warn("No waypoints found")
|
||||||
return nil, errors.New("no waypoints")
|
return nil, errors.New("no waypoints")
|
||||||
}
|
}
|
||||||
|
var waypoints []domain.WayPoint
|
||||||
//find first waypoint
|
|
||||||
var realWaypoints []string
|
|
||||||
for i, point := range points {
|
for i, point := range points {
|
||||||
if extract(point, WaypointExpression) != nil {
|
if digits := extract(point, AllDigitsExpression); i > 0 && digits != nil && len(waypoints) > 0 {
|
||||||
realWaypoints = points[i:]
|
waypoints[len(waypoints)-1].DepartureTime = digits[DepartureTime]
|
||||||
break
|
} else if waypoint := ExtractWaypoint(point); waypoint != nil {
|
||||||
|
waypoints = append(waypoints, *waypoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(realWaypoints) == 0 {
|
if len(waypoints) == 0 {
|
||||||
log.Warn("No waypoints found")
|
log.Warn("No waypoints found")
|
||||||
return nil, errors.New("no waypoints")
|
return nil, errors.New("no waypoints")
|
||||||
}
|
}
|
||||||
var waypoints []domain.WayPoint
|
|
||||||
for i, point := range realWaypoints {
|
|
||||||
// log.Debugf("Parsing waypoint: %s", point)
|
|
||||||
// check the next point for departure time
|
|
||||||
if digits := extract(point, AllDigitsExpression); i > 0 && digits != nil {
|
|
||||||
// if the previous point was a waypoint, update the departure time
|
|
||||||
if l := len(waypoints); l > 0 {
|
|
||||||
waypoints[l-1].DepartureTime = digits[DepartureTime]
|
|
||||||
}
|
|
||||||
} else if waypoint := ExtractWaypoint(point); waypoint != nil {
|
|
||||||
// log.Debugf("Waypoint: %v", waypoint)
|
|
||||||
waypoints = append(waypoints, *waypoint)
|
|
||||||
} else {
|
|
||||||
log.Warnf("Failed to parse waypoint: %s", point)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// log.Debugf("Found %d waypoints", len(waypoints))
|
|
||||||
return waypoints, nil
|
return waypoints, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getValidPoints(data []string) []string {
|
||||||
|
var points []string
|
||||||
|
for i, point := range data {
|
||||||
|
if extract(point, WaypointExpression) != nil {
|
||||||
|
return data[i:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return points
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CZ6794/79
|
* CZ6794/79
|
||||||
* CZ3301/2
|
* CZ3301/2
|
||||||
|
|||||||
Reference in New Issue
Block a user