timetable-extension #1

Open
fred.boniface wants to merge 163 commits from timetable-extension into main
3 changed files with 45 additions and 0 deletions
Showing only changes of commit 2c34c529e1 - Show all commits

3
.gitignore vendored
View File

@ -13,6 +13,9 @@ message-logs
main main
timetable-mgr timetable-mgr
# Debug data
cif_debug_data
# Test binary, built with `go test -c` # Test binary, built with `go test -c`
*.test *.test

View File

@ -1,9 +1,13 @@
package cif package cif
import ( import (
"encoding/json"
"errors" "errors"
"os"
"time" "time"
"git.fjla.uk/owlboard/go-types/pkg/upstreamApi"
"git.fjla.uk/owlboard/timetable-mgr/helpers"
"git.fjla.uk/owlboard/timetable-mgr/log" "git.fjla.uk/owlboard/timetable-mgr/log"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -103,3 +107,31 @@ func parseDaysRun(daysBinary *string) []string {
} }
return result return result
} }
func debugWriteFile(header *upstreamApi.JsonTimetableV1, schedule *[]upstreamApi.JsonScheduleV1) {
if helpers.Runtime == "debug" {
log.Msg.Debug("Writing CIF Header and Schedule elements to file")
filepath := "./cif_debug_data/"
filename := time.Now().In(londonTimezone).Format("2006-01-02_15:04:05_CIF")
data, err := json.MarshalIndent(map[string]interface{}{
"header": header,
"schedule": schedule,
}, "", " ")
if err != nil {
log.Msg.Error("Error marshalling data", zap.Error(err))
return
}
err = os.MkdirAll(filepath, 0777)
if err != nil {
log.Msg.Error("Error creating directory", zap.Error(err))
return
}
writeErr := os.WriteFile(filepath+filename, data, 0777)
if writeErr != nil {
log.Msg.Error("Error writing debug file to disk", zap.Error(writeErr))
}
}
}

View File

@ -35,6 +35,11 @@ func runCifFullDownload(cfg *helpers.Configuration) error {
// Drop timetable collection // Drop timetable collection
dbAccess.DropCollection(dbAccess.TimetableCollection) // I should edit this to prevent removal of VSTP entries in the database. dbAccess.DropCollection(dbAccess.TimetableCollection) // I should edit this to prevent removal of VSTP entries in the database.
// If debug mode is on, call debugWriteFile
if helpers.Runtime == "debug" {
debugWriteFile(&parsed.header, &parsed.sched)
}
// Process CIF file // Process CIF file
err = processParsedCif(parsed) err = processParsedCif(parsed)
if err != nil { if err != nil {
@ -71,6 +76,11 @@ func runCifUpdateDownload(cfg *helpers.Configuration, metadata *dbAccess.CifMeta
return err return err
} }
// If debug mode is on, call debugWriteFile
if helpers.Runtime == "debug" {
debugWriteFile(&parsed.header, &parsed.sched)
}
// Check CIF Sequence // Check CIF Sequence
// Skip if LastSequence is >= to this sequence // Skip if LastSequence is >= to this sequence
if metadata.LastSequence >= parsed.header.Metadata.Sequence { if metadata.LastSequence >= parsed.header.Metadata.Sequence {