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)
This commit is contained in:
2026-07-03 11:41:25 +02:00
parent 3b84fad254
commit 96f8cfa55c
5 changed files with 194 additions and 29 deletions

View File

@@ -1,37 +1,62 @@
package main
import (
// "fmt"
"log"
"shellixa/puvetra/internal/maps"
// "maps"
trmaps "shellixa/puvetra/internal/maps"
"shellixa/puvetra/internal/types"
/*"slices"
"strings" */
"time"
)
func main() {
log.Printf("Starting up..\n")
trips := maps.GetTrips()
trams := trmaps.GetTrips()
var allTrams []types.MapTrip
for _, t := range trips {
if t.Mode == "TRAM" {
for _, t := range trams {
if t.Mode == "TRAM" && t.Trips[0].RouteShortName == "3" {
allTrams = append(allTrams, t)
}
}
var traminfo []map[string]string
var traminfo = make(map[string]types.MapTrip)
now := time.Now()
for _, tr := range allTrams {
data := map[string]string{}
data["line"] = tr.Trips[0].RouteShortName
data["currentStation"] = tr.From.Name
data["nextStation"] = tr.To.Name
data["departure"] = tr.Departure
data["arrival"] = tr.Arrival
traminfo = append(traminfo, data)
// Ü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)))
*/
}