diff --git a/models/common.go b/models/common.go index e9699a4..0c5e460 100644 --- a/models/common.go +++ b/models/common.go @@ -21,7 +21,12 @@ type Material struct { DestinationActual Station `json:"destination_actual"` DestinationPlanned Station `json:"destination_planned"` Accessible bool `json:"accessible"` - RemainsBehind bool `json:"remains_behind"` + + Closed bool `json:"closed"` + RemainsBehind bool `json:"remains_behind"` + Added bool `json:"added"` + + Modifications []Modification } // StoreItem is for shared fields like ID, timestamp etc. diff --git a/models/modification.go b/models/modification.go index b7bdf66..016fd05 100644 --- a/models/modification.go +++ b/models/modification.go @@ -89,6 +89,15 @@ const ModificationSprinterRunsAsIntercity = 80 // ModificationSprinterRunsAsIntercity when an Sprinter train is running with intercity stock const ModificationIntercityRunsAsSprinter = 81 +// ModificationMaterialClosed when material is closed for passengers +const ModificationMaterialClosed = 82 + +// ModificationMaterialAdded when material is added on a station +const ModificationMaterialAdded = 83 + +// ModificationMaterialLeftBehind when material is left behind on a station +const ModificationMaterialLeftBehind = 84 + // Modification is a change (to the schedule) which is communicated to travellers type Modification struct { ModificationType int `json:"type"` diff --git a/parsers/dvsparser.go b/parsers/dvsparser.go index dcaedac..829eff7 100644 --- a/parsers/dvsparser.go +++ b/parsers/dvsparser.go @@ -167,6 +167,19 @@ func ParseDvsMessage(reader io.Reader) (departure models.Departure, err error) { material.DestinationActual = ParseInfoPlusStation(ParseWhenAttribute(materialInfo, "MaterieelDeelEindBestemming", "InfoStatus", "Actueel")) material.DestinationPlanned = ParseInfoPlusStation(ParseWhenAttribute(materialInfo, "MaterieelDeelEindBestemming", "InfoStatus", "Gepland")) + material.Modifications = ParseInfoPlusModifications(materialInfo) + + // Check for flags that may be set: + for _, modification := range material.Modifications { + switch modification.ModificationType { + case models.ModificationMaterialClosed: + material.Closed = true + case models.ModificationMaterialAdded: + material.Added = true + case models.ModificationMaterialLeftBehind: + material.RemainsBehind = true + } + } trainWing.Material = append(trainWing.Material, material) } diff --git a/parsers/dvsparser_test.go b/parsers/dvsparser_test.go index b393b1d..1dc1ec6 100644 --- a/parsers/dvsparser_test.go +++ b/parsers/dvsparser_test.go @@ -181,3 +181,19 @@ func testParseDeparture(t *testing.T, name string) models.Departure { return departure } + +func TestParseMaterialLeftBehind(t *testing.T) { + departure := testParseDeparture(t, "departure_material-left-behind.xml") + + if departure.TrainWings[0].Material[0].RemainsBehind != true { + t.Errorf("Wrong Material.RemainsBehind: expected '%v', but got '%v'", true, departure.TrainWings[0].Material[0].RemainsBehind) + } +} + +func TestParseMaterialModifications(t *testing.T) { + departure := testParseDeparture(t, "departure_material-added.xml") + + if departure.TrainWings[0].Material[0].Added != true { + t.Errorf("Wrong Material.RemainsBehind: expected '%v', but got '%v'", true, departure.TrainWings[0].Material[0].Added) + } +} diff --git a/parsers/testdata/departure_material-added.xml b/parsers/testdata/departure_material-added.xml new file mode 100644 index 0000000..476d8e4 --- /dev/null +++ b/parsers/testdata/departure_material-added.xml @@ -0,0 +1,402 @@ + + + + + 2197032278644005 + 54 + 2022-07-16T19:59:00.000Z + + + 32278 + 2022-07-16 + + VL + 5 + Venlo + Venlo + Venlo + 8400644 + + + 32278 + Stoptrein + 1 + 0 + RS11 + Arriva + N + N + N + N + N + N + + NM + 5 + Nijmegen + Nijmegen + Nijmegen + 8400470 + + + NM + 5 + Nijmegen + Nijmegen + Nijmegen + 8400470 + + + + Nijmegen + + + 2022-07-16T19:59:00.000Z + 2022-07-16T20:00:25.000Z + PT1M25S + + + +1 min. + + + PT0S + + 1 + b + + + 1 + b + + + + 1b + + + A + 0 + + + BR + 0 + Blerick + Blerick + Blerick + 8400117 + + + VRY + 1 + Venray + Venray + Venray + 8400646 + + + VLB + 0 + Vierlingsb + Vierlingsbeek + Vierlingsbeek + 8400647 + + + BMR + 1 + Boxmeer + Boxmeer + Boxmeer + 8400128 + + + + + BR + 0 + Blerick + Blerick + Blerick + 8400117 + + + VRY + 1 + Venray + Venray + Venray + 8400646 + + + VLB + 0 + Vierlingsb + Vierlingsbeek + Vierlingsbeek + 8400647 + + + BMR + 1 + Boxmeer + Boxmeer + Boxmeer + 8400128 + + + + + Blerick, Venray, Vierlingsbeek, Boxmeer + + + + + 1 + b + + + 1 + b + + + + 1b + + + + NM + 5 + Nijmegen + Nijmegen + Nijmegen + 8400470 + + + NM + 5 + Nijmegen + Nijmegen + Nijmegen + 8400470 + + + + Nijmegen + + + + + BR + 0 + Blerick + Blerick + Blerick + 8400117 + + + VRY + 1 + Venray + Venray + Venray + 8400646 + + + VLB + 0 + Vierlingsb + Vierlingsbeek + Vierlingsbeek + 8400647 + + + BMR + 1 + Boxmeer + Boxmeer + Boxmeer + 8400128 + + + CK + 0 + Cuijk + Cuijk + Cuijk + 8400155 + + + MMLH + 0 + Mook-Molen + Molenhoek + Mook-Molenhoek + 8400446 + + + NMH + 0 + Heyendaal + Nm Heyendaal + Nijmegen Heyendaal + 8400468 + + + NM + 5 + Nijmegen + Nijmegen + Nijmegen + 8400470 + + + + + BR + 0 + Blerick + Blerick + Blerick + 8400117 + + + VRY + 1 + Venray + Venray + Venray + 8400646 + + + VLB + 0 + Vierlingsb + Vierlingsbeek + Vierlingsbeek + 8400647 + + + BMR + 1 + Boxmeer + Boxmeer + Boxmeer + 8400128 + + + CK + 0 + Cuijk + Cuijk + Cuijk + 8400155 + + + MMLH + 0 + Mook-Molen + Molenhoek + Mook-Molenhoek + 8400446 + + + NMH + 0 + Heyendaal + Nm Heyendaal + Nijmegen Heyendaal + 8400468 + + + NM + 5 + Nijmegen + Nijmegen + Nijmegen + 8400470 + + + + GTW-D-ARR + 2/6 + 4100 + 1 + 1 + + NM + 5 + Nijmegen + Nijmegen + Nijmegen + 8400470 + + + NM + 5 + Nijmegen + Nijmegen + Nijmegen + 8400470 + + + + Nijmegen + + + + 83 + + + + GTW-D-ARR + 2/8 + 5600 + 3 + 2 + + NM + 5 + Nijmegen + Nijmegen + Nijmegen + 8400470 + + + NM + 5 + Nijmegen + Nijmegen + Nijmegen + 8400470 + + + + Nijmegen + + + + + + 10 + + + Later vertrek + + + Delayed + + + + + + + Later vertrek + + + + Delayed + + + + + \ No newline at end of file diff --git a/parsers/testdata/departure_material-left-behind.xml b/parsers/testdata/departure_material-left-behind.xml new file mode 100644 index 0000000..21c42cf --- /dev/null +++ b/parsers/testdata/departure_material-left-behind.xml @@ -0,0 +1,342 @@ + + + + + 2197001887282001 + 54 + 2022-07-16T21:03:00.000Z + + + 1887 + 2022-07-16 + + GVC + 6 + Den Haag C + Den Haag C. + Den Haag Centraal + 8400282 + + + 1887 + Intercity + 3 + 0 + NS + N + N + N + N + N + N + + ZL + 5 + Zwolle + Zwolle + Zwolle + 8400747 + + + ZL + 5 + Zwolle + Zwolle + Zwolle + 8400747 + + + + Zwolle + + + 2022-07-16T21:03:00.000Z + 2022-07-16T21:03:00.000Z + PT0S + PT0S + + 10 + + + 10 + + + + 10 + + + B + 0 + + + LEDN + 5 + Leiden C + Leiden C. + Leiden Centraal + 8400390 + + + SHL + 6 + Schiphol + Schiphol Airport + Schiphol Airport + 8400561 + + + ASDZ + 4 + Amsterdm Z + Amsterdam Zuid + Amsterdam Zuid + 8400061 + + + ALM + 5 + Almere C + Almere C. + Almere Centrum + 8400080 + + + + + LEDN + 5 + Leiden C + Leiden C. + Leiden Centraal + 8400390 + + + SHL + 6 + Schiphol + Schiphol Airport + Schiphol Airport + 8400561 + + + ASDZ + 4 + Amsterdm Z + Amsterdam Zuid + Amsterdam Zuid + 8400061 + + + ALM + 5 + Almere C + Almere C. + Almere Centrum + 8400080 + + + + + Leiden C., Schiphol Airport, Amsterdam Zuid, Almere C. + + + + + 10 + + + 10 + + + + 10 + + + + ZL + 5 + Zwolle + Zwolle + Zwolle + 8400747 + + + ZL + 5 + Zwolle + Zwolle + Zwolle + 8400747 + + + + Zwolle + + + + + LEDN + 5 + Leiden C + Leiden C. + Leiden Centraal + 8400390 + + + SHL + 6 + Schiphol + Schiphol Airport + Schiphol Airport + 8400561 + + + ASDZ + 4 + Amsterdm Z + Amsterdam Zuid + Amsterdam Zuid + 8400061 + + + ALM + 5 + Almere C + Almere C. + Almere Centrum + 8400080 + + + LLS + 5 + Lelystad C + Lelystad C. + Lelystad Centrum + 8400394 + + + ZL + 5 + Zwolle + Zwolle + Zwolle + 8400747 + + + + + LEDN + 5 + Leiden C + Leiden C. + Leiden Centraal + 8400390 + + + SHL + 6 + Schiphol + Schiphol Airport + Schiphol Airport + 8400561 + + + ASDZ + 4 + Amsterdm Z + Amsterdam Zuid + Amsterdam Zuid + 8400061 + + + ALM + 5 + Almere C + Almere C. + Almere Centrum + 8400080 + + + LLS + 5 + Lelystad C + Lelystad C. + Lelystad Centrum + 8400394 + + + ZL + 5 + Zwolle + Zwolle + Zwolle + 8400747 + + + + ICM + 3 + 8100 + 1 + 1 + 000000-04067-0 + + GVC + 6 + Den Haag C + Den Haag C. + Den Haag Centraal + 8400282 + + + GVC + 6 + Den Haag C + Den Haag C. + Den Haag Centraal + 8400282 + + + + Den Haag Centraal + + + + 84 + + + + ICM + 4 + 10700 + 3 + 2 + 000000-04208-0 + + ZL + 5 + Zwolle + Zwolle + Zwolle + 8400747 + + + ZL + 5 + Zwolle + Zwolle + Zwolle + 8400747 + + + + Zwolle + + + + + + + + \ No newline at end of file