Adjust actions actions

This commit is contained in:
Fred Boniface 2023-07-21 21:20:44 +01:00
parent d557241107
commit 5cbc6aef9b
2 changed files with 21 additions and 7 deletions

View File

@ -1,6 +1,8 @@
package vstp package vstp
import ( import (
"fmt"
"git.fjla.uk/owlboard/go-types/pkg/database" "git.fjla.uk/owlboard/go-types/pkg/database"
"git.fjla.uk/owlboard/mq-client/log" "git.fjla.uk/owlboard/mq-client/log"
) )
@ -23,4 +25,5 @@ func createEntry(entry database.Service) {
func deleteEntry(entry database.Service) { func deleteEntry(entry database.Service) {
log.Msg.Info("Entry DELETE requested for: " + entry.TrainUid + " - " + entry.Headcode) log.Msg.Info("Entry DELETE requested for: " + entry.TrainUid + " - " + entry.Headcode)
fmt.Printf("%+v\n", entry)
} }

View File

@ -25,10 +25,8 @@ func unmarshalData(jsonData string) database.Service {
if schedule.Data.CIFMsg.ScheduleSegment == nil { if schedule.Data.CIFMsg.ScheduleSegment == nil {
log.Msg.Warn("ScheduleSegment is nil") log.Msg.Warn("ScheduleSegment is nil")
return database.Service{}
} else if len(schedule.Data.CIFMsg.ScheduleSegment) == 0 { } else if len(schedule.Data.CIFMsg.ScheduleSegment) == 0 {
log.Msg.Warn("ScheduleSegment is empty") log.Msg.Warn("ScheduleSegment is empty")
return database.Service{}
} }
saveToFile(schedule, "unmarshalled") // For Debugging Only saveToFile(schedule, "unmarshalled") // For Debugging Only
return formatData(&schedule.Data.CIFMsg) return formatData(&schedule.Data.CIFMsg)
@ -38,19 +36,32 @@ func unmarshalData(jsonData string) database.Service {
func formatData(dataInput *upstreamApi.Schedule) database.Service { func formatData(dataInput *upstreamApi.Schedule) database.Service {
log.Msg.Debug("ScheduleSegment length: " + fmt.Sprint(len(dataInput.ScheduleSegment))) log.Msg.Debug("ScheduleSegment length: " + fmt.Sprint(len(dataInput.ScheduleSegment)))
log.Msg.Debug("Printing dataInput to console:") log.Msg.Debug("Printing dataInput to console:")
var operator, headcode, powerType string
var planSpeed int32
var stops []database.Stop
// Check that the ScheduleSegment contains data, 'Delete' messages have no ScheduleSegment
if len(dataInput.ScheduleSegment) > 0 {
operator = dataInput.ScheduleSegment[0].ATOCCode
headcode = dataInput.ScheduleSegment[0].SignallingID
powerType = dataInput.ScheduleSegment[0].CIFPowerType
planSpeed = parseSpeed(dataInput.ScheduleSegment[0].CIFSpeed)
stops = parseStops(dataInput.ScheduleSegment[0].ScheduleLocation)
}
service := database.Service{ service := database.Service{
TransactionType: dataInput.TransactionType, TransactionType: dataInput.TransactionType,
StpIndicator: dataInput.CIFSTPIndicator, StpIndicator: dataInput.CIFSTPIndicator,
Vstp: true, Vstp: true,
Operator: dataInput.ScheduleSegment[0].ATOCCode, Operator: operator,
TrainUid: dataInput.CIFTrainUID, TrainUid: dataInput.CIFTrainUID,
Headcode: dataInput.ScheduleSegment[0].SignallingID, Headcode: headcode,
PowerType: dataInput.ScheduleSegment[0].CIFPowerType, PowerType: powerType,
PlanSpeed: parseSpeed(dataInput.ScheduleSegment[0].CIFSpeed), PlanSpeed: planSpeed,
ScheduleStartDate: parseDate(dataInput.ScheduleStartDate, false), ScheduleStartDate: parseDate(dataInput.ScheduleStartDate, false),
ScheduleEndDate: parseDate(dataInput.ScheduleEndDate, true), ScheduleEndDate: parseDate(dataInput.ScheduleEndDate, true),
DaysRun: parseDaysRun(dataInput.ScheduleDaysRun), DaysRun: parseDaysRun(dataInput.ScheduleDaysRun),
Stops: parseStops(dataInput.ScheduleSegment[0].ScheduleLocation), Stops: stops,
} }
return service return service
} }