Skip to content

Commit

Permalink
Merge pull request #552 from LACMTA/dev
Browse files Browse the repository at this point in the history
Update documentation and config
  • Loading branch information
matikin9 authored Oct 3, 2024
2 parents a450518 + 53314f4 commit 0333204
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 22 deletions.
12 changes: 7 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
},
{
Expand All @@ -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"
},
]
Expand Down
7 changes: 5 additions & 2 deletions readme.md → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
```
```

### Error connection to server at "localhost"

3 changes: 3 additions & 0 deletions documentation/docs/docs.md
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 0 additions & 10 deletions documentation/docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:** [email protected]
- **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!
60 changes: 60 additions & 0 deletions documentation/docs/websockets.md
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 10 additions & 0 deletions documentation/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
4 changes: 4 additions & 0 deletions documentation/src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,8 @@
.patch>.menu__link::before {
content: "patch";
background-color: var(--openapi-code-orange);
}

* {
line-height: 1.5em;
}
8 changes: 6 additions & 2 deletions fastapi/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
9 changes: 6 additions & 3 deletions fastapi/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 0333204

Please sign in to comment.