refactor: Update parsing of flight schedule data for improved accuracy and functionality
This commit is contained in:
@@ -9,7 +9,7 @@ require (
|
|||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/nats-io/nats.go v1.36.0
|
github.com/nats-io/nats.go v1.36.0
|
||||||
github.com/onsi/ginkgo/v2 v2.19.1
|
github.com/onsi/ginkgo/v2 v2.19.1
|
||||||
github.com/onsi/gomega v1.34.0
|
github.com/onsi/gomega v1.34.1
|
||||||
github.com/spf13/viper v1.19.0
|
github.com/spf13/viper v1.19.0
|
||||||
go.uber.org/zap v1.27.0
|
go.uber.org/zap v1.27.0
|
||||||
golang.org/x/oauth2 v0.21.0
|
golang.org/x/oauth2 v0.21.0
|
||||||
@@ -17,11 +17,14 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/agnivade/levenshtein v1.1.1 // indirect
|
||||||
|
github.com/alexflint/go-arg v1.4.2 // indirect
|
||||||
|
github.com/alexflint/go-scalar v1.0.0 // indirect
|
||||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||||
github.com/go-logr/logr v1.4.2 // indirect
|
github.com/go-logr/logr v1.4.2 // indirect
|
||||||
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
|
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
|
||||||
github.com/google/go-cmp v0.6.0 // indirect
|
github.com/google/go-cmp v0.6.0 // indirect
|
||||||
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6 // indirect
|
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
|
||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
github.com/klauspost/compress v1.17.9 // indirect
|
github.com/klauspost/compress v1.17.9 // indirect
|
||||||
github.com/lithammer/shortuuid/v3 v3.0.7 // indirect
|
github.com/lithammer/shortuuid/v3 v3.0.7 // indirect
|
||||||
@@ -43,10 +46,13 @@ require (
|
|||||||
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.25.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/mod v0.19.0 // indirect
|
||||||
golang.org/x/net v0.27.0 // indirect
|
golang.org/x/net v0.27.0 // indirect
|
||||||
|
golang.org/x/sync v0.7.0 // indirect
|
||||||
golang.org/x/sys v0.22.0 // indirect
|
golang.org/x/sys v0.22.0 // indirect
|
||||||
golang.org/x/text v0.16.0 // indirect
|
golang.org/x/text v0.16.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.v2 v2.4.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
+4
-24
@@ -2,7 +2,7 @@ package domain
|
|||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
type FlightSchedule struct {
|
type ScheduleLine struct {
|
||||||
Index string `json:"index,omitempty"`
|
Index string `json:"index,omitempty"`
|
||||||
|
|
||||||
// Date of the flight schedule.
|
// Date of the flight schedule.
|
||||||
@@ -15,7 +15,7 @@ type FlightSchedule struct {
|
|||||||
|
|
||||||
// Flight number of the flight schedule. This is a unique identifier for the flight.
|
// Flight number of the flight schedule. This is a unique identifier for the flight.
|
||||||
// Example: "CA1014"
|
// Example: "CA1014"
|
||||||
FlightNumber string `json:"flight_number"`
|
FlightNumber []string `json:"flight_number"`
|
||||||
|
|
||||||
// Aircraft registration number. This is a unique identifier for the aircraft used for the flight.
|
// Aircraft registration number. This is a unique identifier for the aircraft used for the flight.
|
||||||
// Example: "B2458"
|
// Example: "B2458"
|
||||||
@@ -29,26 +29,6 @@ type FlightSchedule struct {
|
|||||||
// Example: "ILS(0)"
|
// Example: "ILS(0)"
|
||||||
ILS string `json:"ils,omitempty"`
|
ILS string `json:"ils,omitempty"`
|
||||||
|
|
||||||
// // ICAO code for the departure airport.
|
|
||||||
// // Example: "ZBTJ"
|
|
||||||
// DepartureAirport string `json:"departure_airport"`
|
|
||||||
|
|
||||||
// // Scheduled departure time of the flight. This field may be formatted as HHMM or include date information.
|
|
||||||
// // Example: "1845"
|
|
||||||
// DepartureTime string `json:"departure_time,omitempty"`
|
|
||||||
|
|
||||||
// // Additional schedule information. This field may include special instructions or additional scheduling details.
|
|
||||||
// // Example: "SI:TSN1845"
|
|
||||||
// ScheduleInfo string `json:"schedule_info,omitempty"`
|
|
||||||
|
|
||||||
// // Estimated or scheduled arrival time of the flight. This field may be formatted as HHMM or include date information.
|
|
||||||
// // Example: "2100"
|
|
||||||
// ArrivalTime string `json:"arrival_time,omitempty"`
|
|
||||||
|
|
||||||
// // ICAO code for the arrival airport.
|
|
||||||
// // Example: "ZSPD"
|
|
||||||
// ArrivalAirport string `json:"arrival_airport"`
|
|
||||||
|
|
||||||
Waypoints []WayPoint `json:"waypoints"`
|
Waypoints []WayPoint `json:"waypoints"`
|
||||||
|
|
||||||
// Additional comments or remarks about the flight schedule. This field may include any relevant notes or observations.
|
// Additional comments or remarks about the flight schedule. This field may include any relevant notes or observations.
|
||||||
@@ -65,11 +45,11 @@ type WayPoint struct {
|
|||||||
DepartureTime string
|
DepartureTime string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FlightSchedule) Validate() error {
|
func (f *ScheduleLine) Validate() error {
|
||||||
if f.Date == "" {
|
if f.Date == "" {
|
||||||
return fmt.Errorf("date is required")
|
return fmt.Errorf("date is required")
|
||||||
}
|
}
|
||||||
if f.FlightNumber == "" {
|
if len(f.FlightNumber) == 0 {
|
||||||
return fmt.Errorf("flight number is required")
|
return fmt.Errorf("flight number is required")
|
||||||
}
|
}
|
||||||
if f.AircraftReg == "" {
|
if f.AircraftReg == "" {
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ const (
|
|||||||
AirportCode = "airport"
|
AirportCode = "airport"
|
||||||
Date = "date"
|
Date = "date"
|
||||||
Task = "task"
|
Task = "task"
|
||||||
IndexPattern = `(?P<idx>\(?L?[0-9]+\)?\.?)`
|
IndexPattern = `^(?P<idx>\(?L?[0-9]+\)?\.?)$`
|
||||||
DatePattern = `\s?(?P<date>\d{2}\w{3})`
|
DatePattern = `^(?P<date>\d{2}\w{3})$`
|
||||||
TaskPattern = `\s?(?P<task>[A-Z]\/[A-Z])`
|
TaskPattern = `^(?P<task>[A-Z]\/[A-Z])$`
|
||||||
WaypointPattern = `^(SI:)?(?P<arr_time>\d{4}(\(\d{2}[A-Z]{3}\))?)?\/?(?P<airport>[A-Z]{3})\/?(?P<dep_time>\d{4}(\(\d{2}[A-Z]{3}\))?)?$`
|
WaypointPattern = `^(SI:)?(?P<arr_time>\d{4}(\(\d{2}[A-Z]{3}\))?)?\/?(?P<airport>[A-Z]{3})\/?(?P<dep_time>\d{4}(\(\d{2}[A-Z]{3}\))?)?$`
|
||||||
FlightNumberPattern = `\s?(?P<number>[0-9A-Z][0-9A-Z]\d{3,5})`
|
FlightNumberPattern = `^(?P<number>[0-9A-Z][0-9A-Z]\d{3,5})$`
|
||||||
RegisterPattern = `\s?(?P<reg>B\d{4})`
|
RegisterPattern = `^(?P<reg>B\d{4})$`
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -57,11 +57,11 @@ func ExtractWaypoint(message string) *domain.WayPoint {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseLine(line string) *domain.FlightSchedule {
|
func ParseLine(line string) *domain.ScheduleLine {
|
||||||
log := utils.GetSugaredLogger()
|
log := utils.GetSugaredLogger()
|
||||||
cleanLine := strings.TrimSpace(line)
|
cleanLine := strings.TrimSpace(line)
|
||||||
words := strings.Split(cleanLine, " ")
|
words := strings.Split(cleanLine, " ")
|
||||||
var flightSchedule = &domain.FlightSchedule{
|
var flightSchedule = &domain.ScheduleLine{
|
||||||
Reference: line,
|
Reference: line,
|
||||||
}
|
}
|
||||||
var data map[string]string
|
var data map[string]string
|
||||||
@@ -104,7 +104,8 @@ func ParseLine(line string) *domain.FlightSchedule {
|
|||||||
parsed[Date] = true
|
parsed[Date] = true
|
||||||
maxParsed = i
|
maxParsed = i
|
||||||
case FlightNumber:
|
case FlightNumber:
|
||||||
flightSchedule.FlightNumber = data[FlightNumber]
|
//TODO: Handle multiple flight numbers
|
||||||
|
flightSchedule.FlightNumber = append(flightSchedule.FlightNumber, data[FlightNumber])
|
||||||
parsed[FlightNumber] = true
|
parsed[FlightNumber] = true
|
||||||
maxParsed = i
|
maxParsed = i
|
||||||
case Register:
|
case Register:
|
||||||
|
|||||||
@@ -14,40 +14,31 @@ import (
|
|||||||
// input type for inserting data into table "aviation.telegrams"
|
// input type for inserting data into table "aviation.telegrams"
|
||||||
type Aviation_telegrams_insert_input struct {
|
type Aviation_telegrams_insert_input struct {
|
||||||
Text string `json:"Text"`
|
Text string `json:"Text"`
|
||||||
Body_and_footer string `json:"body_and_footer"`
|
|
||||||
Body_data json.RawMessage `json:"body_data"`
|
Body_data json.RawMessage `json:"body_data"`
|
||||||
Category string `json:"category"`
|
Category string `json:"category"`
|
||||||
Comments string `json:"comments"`
|
|
||||||
Date_time string `json:"date_time"`
|
Date_time string `json:"date_time"`
|
||||||
Dispatched_at time.Time `json:"dispatched_at"`
|
Dispatched_at time.Time `json:"dispatched_at"`
|
||||||
Message_id string `json:"message_id"`
|
Message_id string `json:"message_id"`
|
||||||
Need_dispatch bool `json:"need_dispatch"`
|
Need_dispatch bool `json:"need_dispatch"`
|
||||||
Originator string `json:"originator"`
|
Originator string `json:"originator"`
|
||||||
Originator_date_time string `json:"originator_date_time"`
|
Originator_date_time string `json:"originator_date_time"`
|
||||||
Parsed bool `json:"parsed"`
|
|
||||||
Parsed_at time.Time `json:"parsed_at"`
|
Parsed_at time.Time `json:"parsed_at"`
|
||||||
Primary_address string `json:"primary_address"`
|
Primary_address string `json:"primary_address"`
|
||||||
Priority_indicator string `json:"priority_indicator"`
|
Priority_indicator string `json:"priority_indicator"`
|
||||||
Received_at time.Time `json:"received_at"`
|
Received_at time.Time `json:"received_at"`
|
||||||
Secondary_addresses json.RawMessage `json:"secondary_addresses"`
|
Secondary_addresses string `json:"secondary_addresses"`
|
||||||
Uuid uuid.UUID `json:"uuid"`
|
Uuid uuid.UUID `json:"uuid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetText returns Aviation_telegrams_insert_input.Text, and is useful for accessing the field via an interface.
|
// GetText returns Aviation_telegrams_insert_input.Text, and is useful for accessing the field via an interface.
|
||||||
func (v *Aviation_telegrams_insert_input) GetText() string { return v.Text }
|
func (v *Aviation_telegrams_insert_input) GetText() string { return v.Text }
|
||||||
|
|
||||||
// GetBody_and_footer returns Aviation_telegrams_insert_input.Body_and_footer, and is useful for accessing the field via an interface.
|
|
||||||
func (v *Aviation_telegrams_insert_input) GetBody_and_footer() string { return v.Body_and_footer }
|
|
||||||
|
|
||||||
// GetBody_data returns Aviation_telegrams_insert_input.Body_data, and is useful for accessing the field via an interface.
|
// GetBody_data returns Aviation_telegrams_insert_input.Body_data, and is useful for accessing the field via an interface.
|
||||||
func (v *Aviation_telegrams_insert_input) GetBody_data() json.RawMessage { return v.Body_data }
|
func (v *Aviation_telegrams_insert_input) GetBody_data() json.RawMessage { return v.Body_data }
|
||||||
|
|
||||||
// GetCategory returns Aviation_telegrams_insert_input.Category, and is useful for accessing the field via an interface.
|
// GetCategory returns Aviation_telegrams_insert_input.Category, and is useful for accessing the field via an interface.
|
||||||
func (v *Aviation_telegrams_insert_input) GetCategory() string { return v.Category }
|
func (v *Aviation_telegrams_insert_input) GetCategory() string { return v.Category }
|
||||||
|
|
||||||
// GetComments returns Aviation_telegrams_insert_input.Comments, and is useful for accessing the field via an interface.
|
|
||||||
func (v *Aviation_telegrams_insert_input) GetComments() string { return v.Comments }
|
|
||||||
|
|
||||||
// GetDate_time returns Aviation_telegrams_insert_input.Date_time, and is useful for accessing the field via an interface.
|
// GetDate_time returns Aviation_telegrams_insert_input.Date_time, and is useful for accessing the field via an interface.
|
||||||
func (v *Aviation_telegrams_insert_input) GetDate_time() string { return v.Date_time }
|
func (v *Aviation_telegrams_insert_input) GetDate_time() string { return v.Date_time }
|
||||||
|
|
||||||
@@ -68,9 +59,6 @@ func (v *Aviation_telegrams_insert_input) GetOriginator_date_time() string {
|
|||||||
return v.Originator_date_time
|
return v.Originator_date_time
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetParsed returns Aviation_telegrams_insert_input.Parsed, and is useful for accessing the field via an interface.
|
|
||||||
func (v *Aviation_telegrams_insert_input) GetParsed() bool { return v.Parsed }
|
|
||||||
|
|
||||||
// GetParsed_at returns Aviation_telegrams_insert_input.Parsed_at, and is useful for accessing the field via an interface.
|
// GetParsed_at returns Aviation_telegrams_insert_input.Parsed_at, and is useful for accessing the field via an interface.
|
||||||
func (v *Aviation_telegrams_insert_input) GetParsed_at() time.Time { return v.Parsed_at }
|
func (v *Aviation_telegrams_insert_input) GetParsed_at() time.Time { return v.Parsed_at }
|
||||||
|
|
||||||
@@ -84,7 +72,7 @@ func (v *Aviation_telegrams_insert_input) GetPriority_indicator() string { retur
|
|||||||
func (v *Aviation_telegrams_insert_input) GetReceived_at() time.Time { return v.Received_at }
|
func (v *Aviation_telegrams_insert_input) GetReceived_at() time.Time { return v.Received_at }
|
||||||
|
|
||||||
// GetSecondary_addresses returns Aviation_telegrams_insert_input.Secondary_addresses, and is useful for accessing the field via an interface.
|
// GetSecondary_addresses returns Aviation_telegrams_insert_input.Secondary_addresses, and is useful for accessing the field via an interface.
|
||||||
func (v *Aviation_telegrams_insert_input) GetSecondary_addresses() json.RawMessage {
|
func (v *Aviation_telegrams_insert_input) GetSecondary_addresses() string {
|
||||||
return v.Secondary_addresses
|
return v.Secondary_addresses
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func (hr *HasuraRepository) CreateNew(pm *domain.ParsedMessage) error {
|
|||||||
Message_id: pm.MessageID,
|
Message_id: pm.MessageID,
|
||||||
Priority_indicator: pm.PriorityIndicator,
|
Priority_indicator: pm.PriorityIndicator,
|
||||||
Primary_address: pm.PrimaryAddress,
|
Primary_address: pm.PrimaryAddress,
|
||||||
Secondary_addresses: []byte(secondAddress),
|
Secondary_addresses: string(secondAddress),
|
||||||
Text: pm.Text,
|
Text: pm.Text,
|
||||||
Body_data: bodyString,
|
Body_data: bodyString,
|
||||||
Category: pm.Category,
|
Category: pm.Category,
|
||||||
|
|||||||
+497
-378
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user