replace inconsistent rider count with destination and heading

This commit is contained in:
steven 2025-05-18 15:15:22 -04:00
parent 4025bc115b
commit d104b16fc2
2 changed files with 7 additions and 9 deletions

2
app.py
View file

@ -20,7 +20,7 @@ def index():
@cache.cached(timeout=5) @cache.cached(timeout=5)
def tarc(): def tarc():
d=httpx.get("https://tarc.rideralerts.com/InfoPoint/rest/Vehicles/GetAllVehiclesForRoutes?routeIDs=0,"+routes).json() d=httpx.get("https://tarc.rideralerts.com/InfoPoint/rest/Vehicles/GetAllVehiclesForRoutes?routeIDs=0,"+routes).json()
return "\n".join(f"{v['Latitude']},{v['Longitude']},{v['RouteId']},{v['Name']},{v['OnBoard']},{v['DirectionLong']},{v['Speed']},{v['LastUpdated'][6:16]}" for v in d) return "\n".join(f"{v['Latitude']},{v['Longitude']},{v['RouteId']},{v['Name']},{v['Heading']},{v['DirectionLong']},{v['Destination']},{v['Speed']},{v['LastUpdated'][6:16]}" for v in d)
@app.route('/<int:stop>') @app.route('/<int:stop>')
@cache.cached(timeout=5) @cache.cached(timeout=5)

View file

@ -9,7 +9,7 @@
<script src="/static/leaflet/leaflet.js"></script> <script src="/static/leaflet/leaflet.js"></script>
<link rel="stylesheet" href="/static/leaflet/leaflet.css"> <link rel="stylesheet" href="/static/leaflet/leaflet.css">
<base target="_blank"> <base target="_blank">
<style>html,body{height:100%;margin:0;}#map{height:100vh;}iframe{border:none;width:400px;}.leaflet-popup-content{min-width:400px}</style> <style>html,body{height:100%;margin:0;}#map{height:100vh;}iframe{border:none;width:444px;}</style>
</head> </head>
<body> <body>
<div id="map"></div> <div id="map"></div>
@ -35,19 +35,17 @@ function updateMap(){
let routes={}; let routes={};
fetch("tarc.csv").then(response=>response.text()).then(csv=>{ fetch("tarc.csv").then(response=>response.text()).then(csv=>{
csv.split("\n").forEach(line=>{ csv.split("\n").forEach(line=>{
let [lat,lng,r,id,p,d,s,t]=line.split(","); let [lat,lng,r,id,h,dir,dest,s,t]=line.split(",");
p=parseInt(p);
t=new Date(t*1000).toLocaleTimeString("en-US",{hour12:false}); t=new Date(t*1000).toLocaleTimeString("en-US",{hour12:false});
if(!busLayers[r]){busLayers[r]=L.layerGroup().addTo(map)} if(!busLayers[r]){busLayers[r]=L.layerGroup().addTo(map)}
if(!busMarkers[id]){busMarkers[id]=L.marker([0,0],{icon:busIcon}).on('click',()=>filterRoutes(r)).addTo(busLayers[r])} if(!busMarkers[id]){busMarkers[id]=L.marker([0,0],{icon:busIcon}).on('click',()=>filterRoutes(r)).addTo(busLayers[r])}
if(!routes[r]){routes[r]=[0,0]} if(!routes[r]){routes[r]=0}
routes[r][0]++; routes[r]++;
routes[r][1]+=p; busMarkers[id].setLatLng([lat,lng]).bindPopup(`<b>Route ${r}</b><br>#${id} <span style="transform:rotate(${h}deg);display:inline-block;">^</span><br>${dir}<br>${dest}<br>${s}mph<br>${t}`)
busMarkers[id].setLatLng([lat,lng]).bindPopup(`<b>Route ${r}</b><br>#${id}<br>${p} riders<br>${d}<br>${s}mph<br>${t}`)
}) })
let overlayLayers={}; let overlayLayers={};
for(let r in routes){ for(let r in routes){
overlayLayers[`${r.padStart(2,0)} | ${String(routes[r][0]).padStart(2,0)} vehicle(s) | ${routes[r][1]} rider(s)`]=busLayers[r] overlayLayers[`${r.padStart(2,0)} | ${String(routes[r]).padStart(2,0)} vehicle(s)`]=busLayers[r]
} }
layerControl.remove(); layerControl.remove();
layerControl=L.control.layers(null,overlayLayers).addTo(map); layerControl=L.control.layers(null,overlayLayers).addTo(map);