Skip to content

Commit

Permalink
Parse material modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
geertw committed Jul 16, 2022
1 parent acb42d0 commit 41e63d9
Show file tree
Hide file tree
Showing 6 changed files with 788 additions and 1 deletion.
7 changes: 6 additions & 1 deletion models/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions models/modification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
13 changes: 13 additions & 0 deletions parsers/dvsparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
16 changes: 16 additions & 0 deletions parsers/dvsparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Loading

0 comments on commit 41e63d9

Please sign in to comment.