Fix parsing errors where 'CIF_speed' is not defined

This commit is contained in:
Fred Boniface
2023-07-21 09:36:23 +01:00
parent 9526f7da9d
commit 849f23b507
4 changed files with 14 additions and 5 deletions

View File

@@ -41,6 +41,7 @@ func formatData(dataInput *upstreamApi.Schedule) database.Service {
service := database.Service{
TransactionType: dataInput.TransactionType,
StpIndicator: dataInput.CIFSTPIndicator,
Vstp: true,
Operator: dataInput.ScheduleSegment[0].ATOCCode,
TrainUid: dataInput.CIFTrainUID,
Headcode: dataInput.ScheduleSegment[0].SignallingID,
@@ -56,7 +57,11 @@ func formatData(dataInput *upstreamApi.Schedule) database.Service {
// Uses the map provided in 'helpers' to translate incorrect CIF speeds to their correct equivalent
func parseSpeed(CIFSpeed string) int32 {
log.Msg.Debug("CIFSpeed Input: " + CIFSpeed)
log.Msg.Debug("CIFSpeed Input: '" + CIFSpeed + "'")
if CIFSpeed == "" {
log.Msg.Debug("Speed data not provided")
return int32(0)
}
actualSpeed, exists := helpers.SpeedMap[CIFSpeed]
if !exists {
actualSpeed = CIFSpeed
@@ -65,7 +70,7 @@ func parseSpeed(CIFSpeed string) int32 {
speed, err := strconv.ParseInt(actualSpeed, 10, 32)
if err != nil {
log.Msg.Warn("Unable to parse speed: " + CIFSpeed + ", returning nil")
log.Msg.Warn("Unable to parse speed: " + CIFSpeed + ", returning 0")
return int32(0)
}
return int32(speed)

View File

@@ -19,9 +19,9 @@ func Subscribe() {
for {
msg := <-sub.C
if msg.Err != nil {
log.Msg.Error("STOMP Message Error: " + msg.Err.Error())
log.Msg.Error("\nSTOMP Message Error: " + msg.Err.Error())
} else {
log.Msg.Debug("STOMP Message Received")
log.Msg.Debug("\nSTOMP Message Received")
saveToFile(string(msg.Body), "msgBody")
handle(msg)
}