Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@types/leaflet": "^1.9.21",
"comlink": "^4.4.2",
"geolib": "^3.3.4",
"gtfs-sqljs": "github:sysdevrun/gtfs-sqljs#7912bef",
"gtfs-sqljs": "github:sysdevrun/gtfs-sqljs#005bf84",
"leaflet": "^1.9.4",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
29 changes: 28 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ function App() {
const [loadingProgress, setLoadingProgress] = useState<ProgressInfo | null>(null)
const [error, setError] = useState<string | null>(null)
const [realtimeLastUpdated, setRealtimeLastUpdated] = useState<number>(0)
const [lastRtFetchTimestamp, setLastRtFetchTimestamp] = useState<number | null>(null)
const [secondsSinceLastUpdate, setSecondsSinceLastUpdate] = useState<number | null>(null)

// Web Worker reference
const workerRef = useRef<Remote<GtfsWorkerAPI> | null>(null)
Expand Down Expand Up @@ -341,6 +343,10 @@ function App() {
setVehicles(sortedVehicles)
setTripUpdates(tripUpdatesData)

// Get and store the last realtime fetch timestamp from the library
const rtTimestamp = await workerRef.current.getLastRealtimeFetchTimestamp()
setLastRtFetchTimestamp(rtTimestamp)

// Update timestamp to trigger stop times refresh
setRealtimeLastUpdated(Date.now())
} catch (err) {
Expand Down Expand Up @@ -370,6 +376,25 @@ function App() {
return () => clearInterval(interval)
}, [gtfsLoaded, config.updateInterval, updateRealtimeData])

// Update seconds since last realtime update every second
useEffect(() => {
if (lastRtFetchTimestamp === null) {
setSecondsSinceLastUpdate(null)
return
}

const updateSeconds = () => {
const now = Date.now()
const seconds = Math.floor((now - lastRtFetchTimestamp) / 1000)
setSecondsSinceLastUpdate(seconds)
}

updateSeconds()
const interval = setInterval(updateSeconds, 1000)

return () => clearInterval(interval)
}, [lastRtFetchTimestamp])

// Load trips for selected route (Browse Data tab)
useEffect(() => {
if (!workerRef.current || !gtfsLoaded || !selectedRoute || !gtfsApiRef.current) return
Expand Down Expand Up @@ -454,7 +479,9 @@ function App() {
{agencies.length > 0 && `${agencies.map(a => a.agency_name).join(', ')} - `}GTFS Real-Time Explorer
</Typography>
<Typography variant="caption" sx={{ opacity: 0.9 }}>
Explore transit data with gtfs-sqljs
{secondsSinceLastUpdate !== null
? `GTFS-RT: last update ${secondsSinceLastUpdate} seconds ago`
: 'Explore transit data with gtfs-sqljs'}
</Typography>
</Box>
</Toolbar>
Expand Down
8 changes: 8 additions & 0 deletions src/gtfs.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface GtfsWorkerAPI {
// Realtime methods
fetchRealtimeData: () => Promise<void>
getActiveServiceIds: (date: string) => string[]
getLastRealtimeFetchTimestamp: () => number | null

// Database methods
getDatabase: () => Uint8Array | null
Expand Down Expand Up @@ -223,6 +224,13 @@ class GtfsWorker implements GtfsWorkerAPI {
await this.gtfs.fetchRealtimeData()
}

getLastRealtimeFetchTimestamp(): number | null {
if (!this.gtfs) {
return null
}
return this.gtfs.getLastRealtimeFetchTimestamp()
}

getDatabase(): Uint8Array | null {
if (!this.gtfs) {
return null
Expand Down