diff --git a/.vscode/launch.json b/.vscode/launch.json index a95fb3e..84c2e59 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,8 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + + { "name": "Python: Remote Attach", "type": "python", @@ -19,12 +21,12 @@ }, { - "name": "Python: Module", - "type": "python", + "name": "Launch FastAPI", + "type": "debugpy", "request": "launch", "module": "uvicorn", "args": ["app.main:app", "--reload"], - "cwd": "${workspaceFolder}\\fastapi", + "cwd": "${workspaceFolder}/fastapi", "justMyCode": true }, { @@ -35,10 +37,10 @@ "console": "integratedTerminal" }, { - "name": "Python: UNVICORN", + "name": "Python: UVICORN", "type": "python", "request": "launch", - "program": "${workspaceFolder}/uvicorn app.main:app --reload", + "program": "${workspaceFolder}/fastapi uvicorn app.main:app --reload", "console": "integratedTerminal" }, ] diff --git a/readme.md b/README.md similarity index 97% rename from readme.md rename to README.md index acf3a1d..595e38c 100644 --- a/readme.md +++ b/README.md @@ -88,7 +88,7 @@ sudo apt install python3 python3-pip ### Set Environment Variables -Get the `secrets.py` files with the necessary credentials and add them to the `\fastapi\app\` and `\data-loading-service\app\` folders. +Get the `app_secrets.py` files with the necessary credentials and add them to the `\fastapi\app\` and `\data-loading-service\app\` folders. Make sure they are targeted by the `.gitignore` and grayed out, indicating that they will not be tracked or committed to the repository. @@ -231,4 +231,7 @@ docker build . -t metro-api-v2:metro-api-v2 . # runs metro-api-v2 image docker run --rm -it -p 80:80/tcp metro-api-v2:metro-api-v2 -``` \ No newline at end of file +``` + +### Error connection to server at "localhost" + diff --git a/documentation/docs/docs.md b/documentation/docs/docs.md new file mode 100644 index 0000000..7ac60f0 --- /dev/null +++ b/documentation/docs/docs.md @@ -0,0 +1,3 @@ +# Documentation Site + +Changes to the documentation site, when merged into the `dev` or `main` branches will automatically be copied to the `gh-pages` branch through GitHub Actions. \ No newline at end of file diff --git a/documentation/docs/intro.md b/documentation/docs/intro.md index 165c19e..9f642f3 100644 --- a/documentation/docs/intro.md +++ b/documentation/docs/intro.md @@ -75,13 +75,3 @@ To receive real-time updates about vehicles and trips, connect to our WebSocket - **Issue: The schedule seems outdated.** Solution: Ensure you're accessing the real-time data endpoints for the most current information. - **Issue: Can't find my route.** Solution: Double-check the route code or use the `/{agency_id}/routes` endpoint to search for all available routes. - -## Support and Contact Information - -For further assistance or to provide feedback, please contact our customer support team: - -- **Email:** support@lametro.com -- **Phone:** 1-800-LA-METRO -- **Live Chat:** Available on our web application during business hours. - -We're here to help make your Los Angeles Metro experience as smooth and enjoyable as possible. Start exploring today and take the hassle out of public transit! \ No newline at end of file diff --git a/documentation/docs/websockets.md b/documentation/docs/websockets.md new file mode 100644 index 0000000..6010901 --- /dev/null +++ b/documentation/docs/websockets.md @@ -0,0 +1,60 @@ +# Websockets + +The API has one WebSocket endpoint used to provide a stream of realtime data. The URL is in this format: + +``` +wss://api.metro.net/ws/{agency_id}/{endpoint}/{route_codes (optional)} +``` + +## Parameters + +__agency_id (str)__ + +The agencyID is found in the GTFS-schedule `agency.txt` files. + +Values: +- `LACMTA` (Metro Bus) +- `LACMTA_Rail` (Metro Rail) + +__endpoint (str)__ + +The type of GTFS-realtime data to send. + +Values: +- `vehicle_positions` +- `trip_updates` + +__route_codes (str, optional)__ + +A comma-separated list of route codes to filter updates. If not provided, updates for all routes are sent. + +Route codes are the definitive labels for each of the lines, minus HASTUS version numbers and separated from their "sister" lines. + +## Response + +The WebSocket endpoint sends updates every 3 seconds. + +### Success + +The WebSocket endpoint sends updates in the following format: + +{ + "id": "vehicle_id", + "vehicle": { + "trip": { + "route_id": "route_code", + ... + }, + ... + }, + "route_code": "route_code", + ... +} + +Each message from the WebSocket contains data for a single vehicle. + +### Error + +If an error occurs while processing updates, the WebSocket endpoint sends an error message in the following format: + +"Error: error_message" \ No newline at end of file diff --git a/documentation/sidebars.js b/documentation/sidebars.js index 7e6445d..3a8b315 100644 --- a/documentation/sidebars.js +++ b/documentation/sidebars.js @@ -20,6 +20,16 @@ const sidebars = { id: 'intro', // document ID label: 'Getting started', // sidebar label }, + { + type: 'doc', + id: 'docs', + label: 'Documentation Site' + }, + { + type: 'doc', + id: 'websockets', + label: 'WebSockets' + } ], openApiSidebar: [ { diff --git a/documentation/src/css/custom.css b/documentation/src/css/custom.css index 9aab2ad..f76ad19 100644 --- a/documentation/src/css/custom.css +++ b/documentation/src/css/custom.css @@ -74,4 +74,8 @@ .patch>.menu__link::before { content: "patch"; background-color: var(--openapi-code-orange); +} + +* { + line-height: 1.5em; } \ No newline at end of file diff --git a/fastapi/app/config.py b/fastapi/app/config.py index 3145aa5..fa4cfd1 100644 --- a/fastapi/app/config.py +++ b/fastapi/app/config.py @@ -49,7 +49,7 @@ def get_pgbouncer_uri(original_uri): # Replace the hostname and port with the ones for PgBouncer pgbouncer_host = 'localhost' # PgBouncer is running on the same machine - pgbouncer_port = 6432 # Default PgBouncer port + pgbouncer_port = '6432' # Default PgBouncer port # Construct the new URI pgbouncer_uri = urlunparse( @@ -63,8 +63,12 @@ class Config: REDIS_URL = os.environ.get('REDIS_URL', 'redis://redis:6379') TARGET_DB_SCHEMA = 'metro_api' # TARGET_DB_SCHEMA = os.environ.get('TARGET_DB_SCHEMA') + + API_DB_URI = os.environ.get('API_DB_URI') + + # get_pgbouncer_uri seems to be for locally hosted postgres DB only? + # API_DB_URI = get_pgbouncer_uri(os.environ.get('API_DB_URI')) - API_DB_URI = get_pgbouncer_uri(os.environ.get('API_DB_URI')) SECRET_KEY = os.environ.get('HASH_KEY') ALGORITHM = os.environ.get('HASHING_ALGORITHM') ACCESS_TOKEN_EXPIRE_MINUTES = 30 diff --git a/fastapi/app/main.py b/fastapi/app/main.py index 6f26dd7..a8a8a27 100644 --- a/fastapi/app/main.py +++ b/fastapi/app/main.py @@ -536,9 +536,12 @@ async def dummy_websocket_endpoint(agency_id: str, endpoint: str, route_codes: O This endpoint is used for documentation purposes only. It mirrors the WebSocket endpoint that accepts connections and sends real-time updates about vehicles and trips. Args: - agency_id (str): The ID of the agency. - endpoint (str): The type of updates to send. Can be "vehicle_positions" or "trip_updates". - route_codes (str, optional): A comma-separated list of route codes to filter updates. If not provided, updates for all routes are sent. + + agency_id (str): The ID of the agency. + + endpoint (str): The type of updates to send. Can be "vehicle_positions" or "trip_updates". + + route_codes (str, optional): A comma-separated list of route codes to filter updates. If not provided, updates for all routes are sent. The WebSocket endpoint sends updates in the following format: