From 47fbea83b17b39b95764eb31cc51b928e791f2e6 Mon Sep 17 00:00:00 2001 From: Nina Kin Date: Wed, 2 Oct 2024 18:18:38 -0700 Subject: [PATCH 1/7] update documentation quick start tutoriaal --- documentation/docs/intro.md | 10 ---------- 1 file changed, 10 deletions(-) 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 From d1ee67ad2fe6229ab49365714577d8f0d5445e01 Mon Sep 17 00:00:00 2001 From: Nina Kin Date: Wed, 2 Oct 2024 18:25:54 -0700 Subject: [PATCH 2/7] increase line height --- documentation/src/css/custom.css | 4 ++++ 1 file changed, 4 insertions(+) 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 From a7db465b5cd6c01cd50d77c32c76a333ab0b7962 Mon Sep 17 00:00:00 2001 From: Nina Kin Date: Wed, 2 Oct 2024 18:46:53 -0700 Subject: [PATCH 3/7] new tutorial page on documentation website --- documentation/docs/docs.md | 3 +++ documentation/sidebars.js | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 documentation/docs/docs.md 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/sidebars.js b/documentation/sidebars.js index 7e6445d..786be18 100644 --- a/documentation/sidebars.js +++ b/documentation/sidebars.js @@ -20,6 +20,11 @@ const sidebars = { id: 'intro', // document ID label: 'Getting started', // sidebar label }, + { + type: 'doc', + id: 'docs', + label: 'Documentation Site' + } ], openApiSidebar: [ { From 91e598055a80cc72eb4971ca4dd2fe5679803a5d Mon Sep 17 00:00:00 2001 From: Nina Kin Date: Wed, 2 Oct 2024 20:02:58 -0700 Subject: [PATCH 4/7] fix some setup for running the application and debugging --- fastapi/app/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastapi/app/config.py b/fastapi/app/config.py index 3145aa5..a7bd6f1 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( From d5e9be9828dcca3ecc13916f24d1ee5a744c59d5 Mon Sep 17 00:00:00 2001 From: Nina Kin Date: Wed, 2 Oct 2024 20:03:56 -0700 Subject: [PATCH 5/7] fixes for setting up --- .vscode/launch.json | 12 +++++++----- readme.md => README.md | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) rename readme.md => README.md (97%) 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..2c7a6e5 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. From c80feb3a7352ebf348899b36640e10cc7b09305a Mon Sep 17 00:00:00 2001 From: Nina Kin Date: Wed, 2 Oct 2024 20:15:56 -0700 Subject: [PATCH 6/7] change config to not access local db --- README.md | 5 ++++- fastapi/app/config.py | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2c7a6e5..595e38c 100644 --- a/README.md +++ b/README.md @@ -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/fastapi/app/config.py b/fastapi/app/config.py index a7bd6f1..fa4cfd1 100644 --- a/fastapi/app/config.py +++ b/fastapi/app/config.py @@ -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 From 37cb10c59ad026d7bcf1d7a5ac3a9e6744c6aea5 Mon Sep 17 00:00:00 2001 From: Nina Kin Date: Wed, 2 Oct 2024 20:43:06 -0700 Subject: [PATCH 7/7] add websocket documentation details --- documentation/docs/websockets.md | 60 ++++++++++++++++++++++++++++++++ documentation/sidebars.js | 5 +++ fastapi/app/main.py | 9 +++-- 3 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 documentation/docs/websockets.md 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 786be18..3a8b315 100644 --- a/documentation/sidebars.js +++ b/documentation/sidebars.js @@ -24,6 +24,11 @@ const sidebars = { type: 'doc', id: 'docs', label: 'Documentation Site' + }, + { + type: 'doc', + id: 'websockets', + label: 'WebSockets' } ], openApiSidebar: [ 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: