@@ -13,10 +13,11 @@ import (
1313)
1414
1515type StopView struct {
16- Station string `header:"Station"`
17- Track string `header:"Track"`
18- TimeToArrival string `header:"Arriving"`
19- DelayReasons string `header:"Reasons for delay"`
16+ Station string `header:"Station"`
17+ Track string `header:"Track"`
18+ TimeToArrival string `header:"Arriving"`
19+ RemainingDistance string `header:"Remaining Distance"`
20+ DelayReasons string `header:"Reasons for delay"`
2021}
2122
2223var stopsCmd = & cobra.Command {
@@ -30,22 +31,42 @@ var stopsCmd = &cobra.Command{
3031 }
3132
3233 stopViews := []StopView {}
33- for _ , stop := range t .Stops {
34+ for idx , stop := range t .Stops {
3435 stopView := StopView {}
3536 stopView .Station = stop .Station .Name
3637 stopView .Track = stop .Track .Actual
3738 stopView .TimeToArrival = func () string {
3839 arrivalTime := unixMillisToTime (stop .TimeTable .ActualArrivalTime )
3940 remainingDuration := time .Until (arrivalTime )
41+ if idx == 0 {
42+ return ""
43+ }
4044 if remainingDuration < 0 {
4145 return "-"
4246 }
43- if remainingDuration < time .Duration (time .Minute * 3 ) {
47+ if stop . Station . Name == t . YourDestination && remainingDuration < time .Duration (time .Minute * 3 ) {
4448 return "GET OUT NOW"
4549 }
4650 return formatTimeDelta (remainingDuration )
4751 }()
52+ stopView .RemainingDistance = func () string {
53+ if idx == 0 {
54+ return ""
55+ }
56+ // Is this actually correct or should ActualPosition be replaced with info from the last stop?
57+ traveledDistance := t .ActualPosition + t .DistanceFromLastStop
58+ remainingMeters := stop .Info .DistanceFromStart - traveledDistance
59+ roundedKilometers := remainingMeters / 1000
60+ if roundedKilometers <= 0 {
61+ return "-"
62+ }
63+
64+ return fmt .Sprintf ("%d km" , roundedKilometers )
65+ }()
4866 stopView .DelayReasons = func () string {
67+ if idx == 0 {
68+ return ""
69+ }
4970 reasons := []string {}
5071 for _ , r := range stop .DelayReasons {
5172 reasons = append (reasons , r .Message )
@@ -83,6 +104,12 @@ var stopsCmd = &cobra.Command{
83104 arrivalDurations = append (arrivalDurations , stopView .Track )
84105 }
85106 fmt .Println (strings .Join (arrivalDurations , "," ))
107+ case "REMAINING DISTANCE" :
108+ distances := []string {}
109+ for _ , stopView := range stopViews {
110+ distances = append (distances , stopView .RemainingDistance )
111+ }
112+ fmt .Println (strings .Join (distances , "," ))
86113 case "REASONS FOR DELAY" :
87114 delayReasons := []string {}
88115 for _ , stopView := range stopViews {
@@ -104,7 +131,7 @@ var stopsCmd = &cobra.Command{
104131 }
105132 if Output == "csv" {
106133 for _ , stopView := range stopViews {
107- fmt .Printf ("%s,%s,%s,%s\n " , stopView .Station , stopView .Track , stopView .TimeToArrival , stopView .DelayReasons )
134+ fmt .Printf ("%s,%s,%s,%s,%s \n " , stopView .Station , stopView .Track , stopView .TimeToArrival , stopView . RemainingDistance , stopView .DelayReasons )
108135 }
109136 return
110137 }
0 commit comments