Begin parsing of JsonSchedule

This commit is contained in:
Fred Boniface 2024-04-07 21:28:48 +01:00
parent 4a7bcd7f80
commit 84b7d42898
4 changed files with 40 additions and 15 deletions

View File

@ -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
}

View File

@ -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
}

2
go.mod
View File

@ -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

2
go.sum
View File

@ -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=