mirror of
https://github.com/cjdenio/uta-trax-api.git
synced 2026-12-01 00:26:25 +00:00
Compare commits
2
Commits
30466acca5
...
65a66e552c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
65a66e552c | ||
|
|
dd8f215888 |
No files matched your search
+21
-5
@@ -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
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ module github.com/cjdenio/uta-trax-api
|
|||||||
go 1.24.2
|
go 1.24.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/jmoiron/sqlx v1.4.0 // indirect
|
github.com/jmoiron/sqlx v1.4.0
|
||||||
github.com/mattn/go-sqlite3 v1.14.28 // indirect
|
github.com/mattn/go-sqlite3 v1.14.28
|
||||||
google.golang.org/protobuf v1.36.6 // indirect
|
google.golang.org/protobuf v1.36.6
|
||||||
)
|
)
|
||||||
@@ -1,10 +1,17 @@
|
|||||||
|
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||||
|
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
|
||||||
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
||||||
|
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||||
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
|
github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
|
||||||
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
|
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
|
||||||
|
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||||
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||||
github.com/mattn/go-sqlite3 v1.14.28 h1:ThEiQrnbtumT+QMknw63Befp/ce/nUPgBPMlRFEum7A=
|
github.com/mattn/go-sqlite3 v1.14.28 h1:ThEiQrnbtumT+QMknw63Befp/ce/nUPgBPMlRFEum7A=
|
||||||
github.com/mattn/go-sqlite3 v1.14.28/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
github.com/mattn/go-sqlite3 v1.14.28/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
|
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
|
||||||
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
||||||
Reference in new issue
Block a user