Skip to main content
Glama
stationMapper.ts1.88 kB
import { ensureDataLoaded, getStopsData } from './stationService.js'; import { Stop } from '../types/index.js'; export class StationMapper { private stopsMap = new Map<string, Stop>(); private loaded = false; constructor() {} private async loadStops() { if (this.loaded) return; try { // Use lazy-loaded GTFS data from stationService // This avoids duplicate GTFS loading and reduces memory usage await ensureDataLoaded(); const stopsData = getStopsData(); // Convert to Stop objects and populate map for (const stopData of stopsData) { const stop: Stop = { stop_id: stopData.stop_id, stop_name: stopData.stop_name, stop_lat: parseFloat(stopData.stop_lat), stop_lon: parseFloat(stopData.stop_lon), location_type: stopData.location_type, parent_station: stopData.parent_station }; this.stopsMap.set(stop.stop_id, stop); } this.loaded = true; } catch (error) { console.warn('⚠️ Could not load station mappings:', error); } } async getStationName(stopId: string): Promise<string> { await this.loadStops(); const stop = this.stopsMap.get(stopId); return stop ? stop.stop_name : stopId; } getDirection(stopId: string): string { if (stopId.endsWith('N')) return 'Northbound'; if (stopId.endsWith('S')) return 'Southbound'; return 'Unknown'; } getDirectionFromTripId(tripId: string): string { const match = tripId.match(/_([NS])\.\./); if (match) { return match[1] === 'N' ? 'Northbound' : 'Southbound'; } return 'Unknown'; } async formatStopInfo(stopId: string): Promise<string> { const stationName = await this.getStationName(stopId); const direction = this.getDirection(stopId); return `${stationName} (${direction})`; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sasabasara/where_is_my_train_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server