Skip to content

Commit

Permalink
Create remarks and tips for added/left behind/closed material
Browse files Browse the repository at this point in the history
  • Loading branch information
geertw committed Jul 16, 2022
1 parent 41e63d9 commit 46f6539
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
6 changes: 5 additions & 1 deletion cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ var inspectDepartureCommand = &cobra.Command{

fmt.Print(" Material: ")
for _, material := range wing.Material {
fmt.Printf("%s[%s]>%s ", material.NaterialType, *material.NormalizedNumber(), material.DestinationActual.Code)
unitNumber := "(none)"
if material.Number != "" {
unitNumber = *material.NormalizedNumber()
}
fmt.Printf("%s[%s]>%s ", material.NaterialType, unitNumber, material.DestinationActual.Code)
}

fmt.Print("\n")
Expand Down
55 changes: 51 additions & 4 deletions models/departure.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ func (departure *Departure) GenerateID() {

// RealDepartureTime returns the actual departure time, including delay
func (departure Departure) RealDepartureTime() time.Time {
var delayDuration time.Duration
delayDuration = time.Second * time.Duration(departure.Delay)
delayDuration := time.Second * time.Duration(departure.Delay)
return departure.DepartureTime.Add(delayDuration)
}

Expand Down Expand Up @@ -221,14 +220,62 @@ func (departure Departure) GetRemarksTips(language string) (remarks, tips []stri
tips = append(tips, tip.Translation(language))
}

// Check for closed material:
var closedMaterialUnits = make([]string, 0)
var leftBehindMaterialUnits = make([]string, 0)
var addedMaterialUnits = make([]string, 0)

for _, wing := range departure.TrainWings {
for _, material := range wing.Material {
if material.Number == "" {
continue
}

if material.Closed {
closedMaterialUnits = append(closedMaterialUnits, *material.NormalizedNumber())
}
if material.RemainsBehind {
leftBehindMaterialUnits = append(leftBehindMaterialUnits, *material.NormalizedNumber())
}
if material.Added {
addedMaterialUnits = append(addedMaterialUnits, *material.NormalizedNumber())
}
}
}

if len(closedMaterialUnits) > 0 {
if len(closedMaterialUnits) == 1 {
remarks = append(remarks, fmt.Sprintf(Translate("Treinstel %s: niet instappen", "Coach %s: do not board", language), strings.Join(closedMaterialUnits, ", ")))
} else {
remarks = append(remarks, fmt.Sprintf(Translate("Treinstellen %s: niet instappen", "Coaches %s: do not board", language), strings.Join(closedMaterialUnits, ", ")))
}
}

if len(leftBehindMaterialUnits) > 0 {
if len(leftBehindMaterialUnits) == 1 {
remarks = append(remarks, fmt.Sprintf(Translate("Treinstel %s blijft achter in %s", "Coach %s remains at %s", language), strings.Join(leftBehindMaterialUnits, ", "), departure.Station.NameMedium))
} else {
remarks = append(remarks, fmt.Sprintf(Translate("Treinstellen %s blijven in %s", "Coaches %s remain at %s", language), strings.Join(leftBehindMaterialUnits, ", "), departure.Station.NameMedium))
}
}

if len(addedMaterialUnits) > 0 {
if len(addedMaterialUnits) == 1 {
tips = append(tips, "Hoi")
// tips = append(tips, fmt.Sprintf(Translate("Trein wordt op dit station verlengd. Treinstel %s wordt op dit station bijgeplaatst", "Coach %s is added to the train at this station", language), strings.Join(addedMaterialUnits, ", ")))
} else {
tips = append(tips, fmt.Sprintf(Translate("Trein wordt op dit station verlengd. Treinstellen %s worden op dit station bijgeplaatst", "Coaches %s are added to the train at this station", language), strings.Join(addedMaterialUnits, ", ")))
}
}

// Check for material destinations:
for _, wing := range departure.TrainWings {
differentTerminus := make(map[string][]Material)

for _, material := range wing.Material {
if len(wing.DestinationActual) > 0 && material.DestinationActual.Code != wing.DestinationActual[0].Code {
// Different terminus:
if material.Number != "" {
// Different terminus, and not explained by modifications 82-84:
if material.Number != "" && !material.Closed && !material.RemainsBehind {
terminus := material.DestinationActual.NameLong

differentTerminus[terminus] = append(differentTerminus[terminus], material)
Expand Down
8 changes: 4 additions & 4 deletions models/departure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,20 @@ func TestDepartureRemarks(t *testing.T) {
tips []string
}{
{
[]Modification{Modification{ModificationType: ModificationCancelledDeparture}},
[]Modification{{ModificationType: ModificationCancelledDeparture}},
[]Modification{},
[]string{"Trein rijdt niet"},
[]string{},
},
{
[]Modification{Modification{ModificationType: ModificationDiverted}, Modification{ModificationType: ModificationChangedDeparturePlatform}},
[]Modification{{ModificationType: ModificationDiverted}, {ModificationType: ModificationChangedDeparturePlatform}},
[]Modification{},
[]string{"Rijdt via een andere route", "Gewijzigd vertrekspoor"},
[]string{},
},
{
[]Modification{Modification{ModificationType: ModificationDiverted}, Modification{ModificationType: ModificationChangedDeparturePlatform}},
[]Modification{Modification{ModificationType: ModificationChangedDeparturePlatform}},
[]Modification{{ModificationType: ModificationDiverted}, {ModificationType: ModificationChangedDeparturePlatform}},
[]Modification{{ModificationType: ModificationChangedDeparturePlatform}},
[]string{"Rijdt via een andere route", "Gewijzigd vertrekspoor"},
[]string{},
},
Expand Down

0 comments on commit 46f6539

Please sign in to comment.