From 84b7d428984687692581d4a9a77d2f907ad72e3c Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sun, 7 Apr 2024 21:28:48 +0100 Subject: [PATCH] Begin parsing of JsonSchedule --- cif/convert.go | 27 +++++++++++++++++++++++++++ cif/convert_test.go | 24 ++++++++++-------------- go.mod | 2 +- go.sum | 2 ++ 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/cif/convert.go b/cif/convert.go index 5097ddc..020cbfa 100644 --- a/cif/convert.go +++ b/cif/convert.go @@ -49,7 +49,34 @@ func parseSpeed(CIFSpeed *string) int32 { return int32(speed) } +// Not tested func parseStops(input *[]upstreamApi.CifScheduleLocation) []database.Stop { output := make([]database.Stop, 0, len(*input)) + + for _, item := range *input { + stop := database.Stop{ + PublicDeparture: item.PublicDeparture, + PublicArrival: item.PublicArrival, + WttDeparture: item.Departure, + WttArrival: item.Arrival, + Pass: item.Pass, + Platform: item.Platform, + ArrLine: item.Path, + DepLine: item.Line, + Tiploc: item.TiplocCode, + IsPublic: isPublic(&item), + } + + output = append(output, stop) + } + return output } + +// Not tested +func isPublic(input *upstreamApi.CifScheduleLocation) bool { + if input.PublicArrival == "" && input.PublicDeparture == "" { + return false + } + return true +} diff --git a/cif/convert_test.go b/cif/convert_test.go index 8233ebc..3a167b8 100644 --- a/cif/convert_test.go +++ b/cif/convert_test.go @@ -4,28 +4,24 @@ import "testing" func TestParseSpeed(t *testing.T) { testCases := []struct { - input *string + input string expected int32 }{ - {strPtr("075"), 75}, - {strPtr("125"), 125}, - {strPtr("40"), 40}, - {strPtr("040"), 40}, - {strPtr("134"), 60}, - {strPtr("179"), 80}, - {strPtr("186"), 186}, - {strPtr("417"), 186}, + {"075", 75}, + {"125", 125}, + {"40", 40}, + {"040", 40}, + {"134", 60}, + {"179", 80}, + {"186", 186}, + {"417", 186}, } for _, tc := range testCases { - result := parseSpeed(tc.input) + result := parseSpeed(&tc.input) if result != tc.expected { t.Errorf("For speed: %s, expected: %d, but got: %d", tc.input, tc.expected, result) } } } - -func strPtr(s string) *string { - return &s -} diff --git a/go.mod b/go.mod index b2b48d8..c2709a0 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.fjla.uk/owlboard/timetable-mgr go 1.21 require ( - git.fjla.uk/owlboard/go-types v0.0.0-20240405194933-7dafca950460 + git.fjla.uk/owlboard/go-types v0.0.0-20240407202712-e58d7d1d9aa9 github.com/go-stomp/stomp/v3 v3.0.5 go.mongodb.org/mongo-driver v1.12.0 go.uber.org/zap v1.24.0 diff --git a/go.sum b/go.sum index 691ed95..92b47a3 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ git.fjla.uk/owlboard/go-types v0.0.0-20240403200521-41796e25b6c3 h1:veGmL8GeWsgG git.fjla.uk/owlboard/go-types v0.0.0-20240403200521-41796e25b6c3/go.mod h1:kG+BX9UF+yJaAVnln/QSKlTdrtKRRReezMeSk1ZLMzY= git.fjla.uk/owlboard/go-types v0.0.0-20240405194933-7dafca950460 h1:39vcejk0MzZIL2WdriKSfcDoCc/0NWzZMncHqw5ctbY= git.fjla.uk/owlboard/go-types v0.0.0-20240405194933-7dafca950460/go.mod h1:kG+BX9UF+yJaAVnln/QSKlTdrtKRRReezMeSk1ZLMzY= +git.fjla.uk/owlboard/go-types v0.0.0-20240407202712-e58d7d1d9aa9 h1:aNxMYEsbBkFx9b9J8zR1m08KL3JG9b0rPHszryKm5uk= +git.fjla.uk/owlboard/go-types v0.0.0-20240407202712-e58d7d1d9aa9/go.mod h1:kG+BX9UF+yJaAVnln/QSKlTdrtKRRReezMeSk1ZLMzY= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=