mirror of
https://github.com/cjdenio/uta-trax-api.git
synced 2026-10-03 16:06:19 +00:00
yeah
This commit is contained in:
1 file changed
+15
-2
+15
-2
@@ -43,6 +43,7 @@ func getStationForVehicle(vehicle *pb.VehiclePosition) *pb.VehicleFeed_Station {
|
|||||||
rows, err := scheduleDb.Query(`SELECT stop_lat, stop_lon, stops.stop_id, stop_name FROM stop_times INNER JOIN stops ON stops.stop_id = stop_times.stop_id WHERE stop_times.trip_id = ? AND stop_times.pickup_type != 1 AND stop_times.drop_off_type != 1;`, vehicle.Trip.TripId)
|
rows, err := scheduleDb.Query(`SELECT stop_lat, stop_lon, stops.stop_id, stop_name FROM stop_times INNER JOIN stops ON stops.stop_id = stop_times.stop_id WHERE stop_times.trip_id = ? AND stop_times.pickup_type != 1 AND stop_times.drop_off_type != 1;`, vehicle.Trip.TripId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
nearestStop := new(pb.VehicleFeed_Station)
|
nearestStop := new(pb.VehicleFeed_Station)
|
||||||
@@ -67,6 +68,11 @@ func getStationForVehicle(vehicle *pb.VehiclePosition) *pb.VehicleFeed_Station {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sometimes trains aren't where they should be, ignore nearest stop if more than 2 miles away
|
||||||
|
if nearestStopDistance > 2 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return nearestStop
|
return nearestStop
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,11 +219,18 @@ func main() {
|
|||||||
http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
|
||||||
vehicles, err := getVehicles()
|
vehicles, err := getVehicles()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
feed := feedifyVehicles(vehicles)
|
feed := feedifyVehicles(vehicles)
|
||||||
b, _ := proto.Marshal(&feed)
|
b, err := proto.Marshal(&feed)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
w.Header().Add("Content-Type", "application/protobuf")
|
w.Header().Add("Content-Type", "application/protobuf")
|
||||||
w.Write(b)
|
w.Write(b)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in new issue
Block a user