@@ -62,6 +62,13 @@ def self.next_departures(stops, now)
6262 . sort_by { |stop | stop [ :departure ] }
6363 end
6464
65+ # The next train that ends at a station. It has no departure, so #next_departures never sees
66+ # it, and no destination either, because the station it is standing in is the destination.
67+ def self . next_arrival ( stops , now )
68+ stops . select { |stop | stop [ :departure ] . nil? && stop [ :arrival ] && stop [ :arrival ] >= now }
69+ . min_by { |stop | stop [ :arrival ] }
70+ end
71+
6572 # How many minutes late a stop is. The live time and the planned one have to be the same event:
6673 # comparing an arrival against a planned departure would report the stop time as being early.
6774 def self . delay ( stop )
@@ -101,17 +108,21 @@ def self.delay_colors(minutes)
101108 # route_setup left in label-title:
102109 #
103110 # 12:20 (12:18) → Gräfenberg (+2)
104- # 12:35 → Nürnberg Nordost
111+ # 12:35
105112 #
106113 # Planned departure, planned arrival in brackets where the train does not start here, terminus,
107- # and how late it currently is.
114+ # and how late it currently is. A train that ends here has no departure and no destination but
115+ # this station, whose name is above the board already, so its line is the planned arrival alone.
108116 def self . board_label ( stops , now )
109- next_departures ( stops , now ) . map { |stop |
110- minutes = ( ( stop [ :departure ] - stop [ :planned ] ) / 60 ) . round
117+ lines = next_departures ( stops , now ) . map { |stop |
111118 arrival = stop [ :planned_arrival ]
112- "#{ hhmm ( stop [ :planned ] ) } #{ " (#{ hhmm ( arrival ) } )" if arrival } " \
113- "→ #{ stop [ :destination ] } #{ " (+#{ minutes } )" unless minutes . zero? } "
114- } . join ( "\n " )
119+ [ stop [ :planned ] , "#{ hhmm ( stop [ :planned ] ) } #{ " (#{ hhmm ( arrival ) } )" if arrival } → #{ stop [ :destination ] } " ,
120+ ( ( stop [ :departure ] - stop [ :planned ] ) / 60 ) . round ]
121+ }
122+ ends_here = next_arrival ( stops , now )
123+ lines << [ ends_here [ :planned ] , hhmm ( ends_here [ :planned ] ) , delay ( ends_here ) ] if ends_here
124+ lines . sort_by ( &:first ) . map { |_time , text , minutes | "#{ text } #{ " (+#{ minutes } )" unless minutes . zero? } " }
125+ . join ( "\n " )
115126 end
116127
117128 # Every time here comes from the DB API and belongs to a German platform display, so it is shown
0 commit comments