-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedule-feed.go
140 lines (125 loc) · 5.89 KB
/
schedule-feed.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package main
// All lines in the schedule record contain one of three types
// JSONTimetableV1 (metadata)
// JSONScheduleV1 (a schedule)
// Tiploc (a location)
type ScheduleFeedRecord struct {
Timetable Timetable `json:"JsonTimetableV1,omitempty"`
JSONScheduleV1 JSONScheduleV1 `json:"JsonScheduleV1,omitempty"`
Tiploc Tiploc `json:"TiplocV1,omitempty"`
}
type Tiploc struct {
TransactionType string `json:"transaction_type"`
TiplocCode string `gorm:"index" json:"tiploc_code"`
Nalco string `json:"nalco"`
Stanox string `json:"stanox"`
CrsCode string `json:"crs_code"`
Description string `json:"description"`
TpsDescription string `json:"tps_description"`
}
type Timetable struct {
Classification string `json:"classification"`
Timestamp int `json:"timestamp"`
Owner string `json:"owner"`
Sender TimetableSender `json:"Sender" gorm:"-:all"`
Metadata TimetableMetadata `json:"Metadata" gorm:"-:all"`
}
type TimetableSender struct {
Organisation string `json:"organisation"`
Application string `json:"application"`
Component string `json:"component"`
}
type TimetableMetadata struct {
Type string `json:"type"`
Sequence int `json:"sequence"`
}
type JSONScheduleV1 struct {
CIFBankHolidayRunning string `json:"CIF_bank_holiday_running"`
CIFStpIndicator string `json:"CIF_stp_indicator"`
CIFTrainUID string `json:"CIF_train_uid"`
ApplicableTimetable string `json:"applicable_timetable"`
AtocCode string `json:"atoc_code"`
NewScheduleSegment struct {
TractionClass string `json:"traction_class"`
UicCode string `json:"uic_code"`
} `json:"new_schedule_segment"`
ScheduleDaysRuns string `json:"schedule_days_runs"`
ScheduleEndDate string `json:"schedule_end_date"`
ScheduleSegment struct {
SignallingID string `json:"signalling_id"`
CIFTrainCategory string `json:"CIF_train_category"`
CIFHeadcode string `json:"CIF_headcode"`
CIFCourseIndicator int `json:"CIF_course_indicator"`
CIFTrainServiceCode string `json:"CIF_train_service_code"`
CIFBusinessSector string `json:"CIF_business_sector"`
CIFPowerType string `json:"CIF_power_type"`
CIFTimingLoad string `json:"CIF_timing_load"`
CIFSpeed string `json:"CIF_speed"`
CIFOperatingCharacteristics string `json:"CIF_operating_characteristics"`
CIFTrainClass string `json:"CIF_train_class"`
CIFSleepers string `json:"CIF_sleepers"`
CIFReservations string `json:"CIF_reservations"`
CIFConnectionIndicator string `json:"CIF_connection_indicator"`
CIFCateringCode string `json:"CIF_catering_code"`
CIFServiceBranding string `json:"CIF_service_branding"`
ScheduleLocation []ScheduleLocation `json:"schedule_location"`
} `json:"schedule_segment"`
ScheduleStartDate string `json:"schedule_start_date"`
TrainStatus string `json:"train_status"`
TransactionType string `json:"transaction_type"`
}
func (s *ScheduleFeedRecord) IsMetadata() bool {
return s.Timetable.Classification != ""
}
func (s *ScheduleFeedRecord) IsSchedule() bool {
return s.JSONScheduleV1.CIFTrainUID != ""
}
func (s *ScheduleFeedRecord) IsTiploc() bool {
return s.Tiploc.TiplocCode != ""
}
func (s *JSONScheduleV1) ToSchedule() (sch Schedule) {
sch.Source = "Feed"
sch.CIFBankHolidayRunning = s.CIFBankHolidayRunning
sch.CIFStpIndicator = s.CIFStpIndicator
sch.CIFTrainUID = s.CIFTrainUID
sch.ApplicableTimetable = s.ApplicableTimetable
sch.AtocCode = s.AtocCode
sch.ScheduleDaysRuns = s.ScheduleDaysRuns
sch.ScheduleEndDate = s.ScheduleEndDate
sch.ScheduleStartDate = s.ScheduleStartDate
sch.TrainStatus = s.TrainStatus
sch.TransactionType = s.TransactionType
// Move the scheduling segment fields into the schedule segment
sch.SignallingID = s.ScheduleSegment.SignallingID
sch.CIFTrainCategory = s.ScheduleSegment.CIFTrainCategory
sch.CIFTrainCategory = s.ScheduleSegment.CIFTrainCategory
sch.CIFHeadcode = s.ScheduleSegment.CIFHeadcode
sch.CIFCourseIndicator = s.ScheduleSegment.CIFCourseIndicator
sch.CIFTrainServiceCode = s.ScheduleSegment.CIFTrainServiceCode
sch.CIFBusinessSector = s.ScheduleSegment.CIFBusinessSector
sch.CIFPowerType = s.ScheduleSegment.CIFPowerType
sch.CIFTimingLoad = s.ScheduleSegment.CIFTimingLoad
sch.CIFSpeed = s.ScheduleSegment.CIFSpeed
sch.CIFOperatingCharacteristics = s.ScheduleSegment.CIFOperatingCharacteristics
sch.CIFTrainClass = s.ScheduleSegment.CIFTrainClass
sch.CIFSleepers = s.ScheduleSegment.CIFSleepers
sch.CIFHeadcode = s.ScheduleSegment.CIFHeadcode
sch.CIFCourseIndicator = s.ScheduleSegment.CIFCourseIndicator
sch.CIFTrainServiceCode = s.ScheduleSegment.CIFTrainServiceCode
sch.CIFBusinessSector = s.ScheduleSegment.CIFBusinessSector
sch.CIFPowerType = s.ScheduleSegment.CIFPowerType
sch.CIFTimingLoad = s.ScheduleSegment.CIFTimingLoad
sch.CIFSpeed = s.ScheduleSegment.CIFSpeed
sch.CIFOperatingCharacteristics = s.ScheduleSegment.CIFOperatingCharacteristics
sch.CIFTrainClass = s.ScheduleSegment.CIFTrainClass
sch.CIFSleepers = s.ScheduleSegment.CIFSleepers
sch.CIFReservations = s.ScheduleSegment.CIFReservations
sch.CIFConnectionIndicator = s.ScheduleSegment.CIFConnectionIndicator
sch.CIFCateringCode = s.ScheduleSegment.CIFCateringCode
sch.CIFServiceBranding = s.ScheduleSegment.CIFServiceBranding
sch.ScheduleLocation = make([]ScheduleLocation, len(s.ScheduleSegment.ScheduleLocation))
copy(sch.ScheduleLocation, s.ScheduleSegment.ScheduleLocation)
sch.TractionClass = s.NewScheduleSegment.TractionClass
sch.UicCode = s.NewScheduleSegment.UicCode
return sch
}