complete data for Roy + support to param

This commit is contained in:
cjdenio committed 2026-11-07 12:19:46 -07:00
1 parent 30466acca5
commit dd8f215888
1 file changed
+21 -5
+21 -5
View File
@@ -355,8 +355,10 @@ type DbDeparture struct {
PassingTrain bool `db:"passing_train"` PassingTrain bool `db:"passing_train"`
} }
// format: "NORTH (passing)", "SOUTH (passing)", "NORTH", "SOUTH"
// "1" is the western track, "2" is the eastern track, "0" is unknown track
var predictionData map[string][4]int = map[string][4]int{ var predictionData map[string][4]int = map[string][4]int{
"21760": {1, 2, 0, 0}, // Roy Station "21760": {1, 2, 1, 1}, // Roy Station
"21757": {0, 0, 1, 1}, // Clearfield Station "21757": {0, 0, 1, 1}, // Clearfield Station
"21772": {1, 2, 0, 0}, // Layton Station "21772": {1, 2, 0, 0}, // Layton Station
"21758": {0, 0, 1, 1}, // Farmington Station "21758": {0, 0, 1, 1}, // Farmington Station
@@ -393,8 +395,8 @@ func predictPlatform(d DbDeparture) int {
return data[idx] return data[idx]
} }
func addToTime(h, m, s, add int) (int, int, int) { func addToTime(h, m, s, secsToAdd int) (int, int, int) {
s += add s += secsToAdd
if s >= 60 { if s >= 60 {
m += s / 60 m += s / 60
s = s % 60 s = s % 60
@@ -439,8 +441,22 @@ func upcomingDeparturesHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
toH, toM, toS := addToTime(from.Hour(), from.Minute(), from.Second(), 60*60) var timeToAdd time.Duration = time.Minute * 60
to := from.Add(time.Hour)
toStr := r.URL.Query().Get("to")
if toStr != "" {
toInt, err := strconv.ParseInt(toStr, 10, 64)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("invalid `to` param, expected UNIX timestamp"))
return
}
timeToAdd = time.Duration(toInt) * time.Second
}
toH, toM, toS := addToTime(from.Hour(), from.Minute(), from.Second(), int(timeToAdd.Seconds()))
to := from.Add(timeToAdd)
// get upcoming departures // get upcoming departures
query, args, err := sqlx.In(`select query, args, err := sqlx.In(`select