Display 'live' status in overview

main
Jasper Bok 2024-04-16 18:36:47 +02:00
parent 5007ccb287
commit ca83496e8a
3 changed files with 36 additions and 2 deletions

12
bus.go
View File

@ -21,6 +21,18 @@ type Departure struct {
RouteShortName string RouteShortName string
} }
func (d Departure) HasRealtimeDepartureTime() bool {
return !d.RealtimeDepartureTime.IsZero()
}
func (d Departure) IsDelayed() bool {
if !d.HasRealtimeDepartureTime() {
return false
}
return d.RealtimeDepartureTime.After(d.DepartureTime)
}
type ResponseDeparture struct { type ResponseDeparture struct {
TripID int `json:"trip_id"` TripID int `json:"trip_id"`
RealtimeTripId string `json:"realtime_trip_id"` RealtimeTripId string `json:"realtime_trip_id"`

View File

@ -30,7 +30,11 @@
<tr> <tr>
<td>{{ $val.RouteShortName }}</td> <td>{{ $val.RouteShortName }}</td>
<td>{{ $val.StopHeadsign }}</td> <td>{{ $val.StopHeadsign }}</td>
{{ if $val.HasRealtimeDepartureTime }}
<td><time class="{{ if $val.IsDelayed }}delayed{{ else }}on-time{{ end }}">{{ formatTime $val.RealtimeDepartureTime }}</time></td>
{{ else }}
<td><time>{{ formatTime $val.DepartureTime }}</time></td> <td><time>{{ formatTime $val.DepartureTime }}</time></td>
{{ end }}
</tr> </tr>
{{ end }} {{ end }}
{{ end }} {{ end }}
@ -40,4 +44,4 @@
{{ end }} {{ end }}
</main> </main>
</body> </body>
</html> </html>

View File

@ -43,4 +43,22 @@ td:first-child {
td:last-child { td:last-child {
padding-right: 0; padding-right: 0;
} }
time {
background: black;
color: white;
display: inline-block;
font-size: .8rem;
padding: .2em .2em .1em;
}
.on-time {
background: green;
color: white;
}
.delayed {
background: red;
color: white;
}