Files
puvetra/cmd/tracker/main.go
shellixa 96f8cfa55c make it work for my tram board
adds webserer with endpoint /line?number=3

you need to specify a post body text using b64-encoded, semicolon-separated names of the stops

index of stop name corresponds to returned value (led index)
2026-07-03 11:41:25 +02:00

63 lines
1.5 KiB
Go

package main
import (
// "fmt"
"log"
// "maps"
trmaps "shellixa/puvetra/internal/maps"
"shellixa/puvetra/internal/types"
/*"slices"
"strings" */
"time"
)
func main() {
log.Printf("Starting up..\n")
trams := trmaps.GetTrips()
var allTrams []types.MapTrip
for _, t := range trams {
if t.Mode == "TRAM" && t.Trips[0].RouteShortName == "3" {
allTrams = append(allTrams, t)
}
}
var traminfo = make(map[string]types.MapTrip)
now := time.Now()
for _, tr := range allTrams {
// Überschreibe [tripId] nur, wenn (OR)
// - [tripId] == nil
// - departure < now && arrival > [tripId].departure
storedTram := traminfo[tr.Trips[0].TripId]
if tr.Departure.Sub(now).Abs() < storedTram.Departure.Sub(now).Abs() {
// Current is past now, Stored is future now
traminfo[tr.Trips[0].TripId] = tr
}
}
log.Printf("%+v\n", traminfo)
log.Printf("%d", len(traminfo))
/*
activeLights := make(map[int]bool)
for _, tram := range allTrams {
// Calculate current Station name depending on current time
realStation := tram.From
if now.Sub(depTime) > arrTime.Sub(now) {
// log.Printf("> %v, %v\n", now.Sub(tram.Departure), tram.Arrival.Sub(now))
realStation = tram.To
}
// log.Printf("From='%s' To='%s' Real='%s'\n", tram.From.Name, tram.To.Name, realStation.Name)
activeLights[stationLookupTable[strings.ToLower(realStation.Name)]] = true
}
fmt.Println(slices.Collect(maps.Keys(activeLights)))
*/
}