Skip to content

Commit

Permalink
Merge branch 'master' into nlws-concurrent-limiter-rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
nlwstein authored Jan 16, 2024
2 parents 8f79e1a + 4651cac commit d9ccff0
Show file tree
Hide file tree
Showing 38 changed files with 942 additions and 109 deletions.
46 changes: 12 additions & 34 deletions .github/workflows/asana.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,17 @@
name: Asana integration for Github PRs
name: Asana integration for GitHub PRs
on:
workflow_dispatch:
pull_request:
types: [closed, edited, opened, reopened]
types: [review_requested, closed, opened, reopened]

jobs:
move-to-merged-asana-ticket-job:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Github-Asana action from Insurify
uses: insurify/[email protected]
with:
asana-pat: ${{ secrets.ASANA_PERSONAL_ACCESS_TOKEN }}
trigger-phrase: "\\*\\*Asana Ticket:\\*\\*"
targets: '[{"project": "TRC - Sprint", "section": "Merged / Not Deployed"}]'
move-to-in-review-asana-ticket-job:
runs-on: ubuntu-latest
if: github.event.pull_request.merged != true
steps:
- name: Github-Asana action from Insurify
uses: insurify/[email protected]
with:
asana-pat: ${{ secrets.ASANA_PERSONAL_ACCESS_TOKEN }}
trigger-phrase: "\\*\\*Asana Ticket:\\*\\*"
targets: '[{"project": "TRC - Sprint", "section": "In Review"}]'
create-asana-attachment-job:
runs-on: ubuntu-latest
name: Create pull request attachments on Asana tasks
if: github.repository_owner == 'mbta'
steps:
- name: Create pull request attachments
uses: Asana/create-app-attachment-github-action@latest
id: postAttachment
with:
asana-secret: ${{ secrets.ASANA_GITHUB_INTEGRATION_SECRET }}
- name: Log output status
run: echo "Status is ${{ steps.postAttachment.outputs.status }}"
call-workflow:
uses: mbta/workflows/.github/workflows/asana.yml@main
with:
development-section: "In Development"
review-section: "Pending Review"
merged-section: "Merged / Not Deployed"
attach-pr: true
secrets:
asana-token: ${{ secrets.ASANA_PERSONAL_ACCESS_TOKEN }}
github-secret: ${{ secrets.ASANA_GITHUB_INTEGRATION_SECRET }}
106 changes: 95 additions & 11 deletions apps/api_web/lib/api_web/controllers/prediction_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule ApiWeb.PredictionController do
alias ApiWeb.LegacyStops
alias State.Prediction

@filters ~w(stop route trip latitude longitude radius direction_id stop_sequence route_type route_pattern)s
@filters ~w(stop route trip latitude longitude radius direction_id stop_sequence route_type route_pattern revenue)s
@pagination_opts ~w(offset limit order_by)a
@includes ~w(schedule stop route trip vehicle alerts)

Expand Down Expand Up @@ -61,6 +61,7 @@ defmodule ApiWeb.PredictionController do
filter_param(:stop_id, includes_children: true)
filter_param(:id, name: :route)
filter_param(:id, name: :trip)
filter_param(:revenue, desc: "Filter predictions by revenue status.")

parameter("filter[route_pattern]", :query, :string, """
Filter by `/included/{index}/relationships/route_pattern/data/id` of a trip. Multiple `route_pattern_id` #{comma_separated_list()}.
Expand All @@ -84,13 +85,17 @@ defmodule ApiWeb.PredictionController do
route_ids = Params.split_on_comma(filtered_params, "route")
route_pattern_ids = Params.split_on_comma(filtered_params, "route_pattern")
route_types = Params.route_types(filtered_params)
revenue = filtered_params |> Map.get("revenue") |> Params.revenue()

direction_id_matcher =
filtered_params
|> Params.direction_id()
|> direction_id_matcher()

matchers = stop_sequence_matchers(filtered_params, direction_id_matcher)
matchers =
filtered_params
|> build_stop_sequence_matchers(direction_id_matcher)
|> add_revenue_matchers(revenue)

case filtered_params do
%{"route_type" => _} = p when map_size(p) == 1 ->
Expand Down Expand Up @@ -217,7 +222,7 @@ defmodule ApiWeb.PredictionController do
%{direction_id: direction_id}
end

defp stop_sequence_matchers(params, direction_id_matcher) do
defp build_stop_sequence_matchers(params, direction_id_matcher) do
case Params.split_on_comma(params, "stop_sequence") do
[_ | _] = strs ->
for str <- strs,
Expand All @@ -230,6 +235,15 @@ defmodule ApiWeb.PredictionController do
end
end

defp add_revenue_matchers(matchers, :error),
do: add_revenue_matchers(matchers, {:ok, :REVENUE})

defp add_revenue_matchers(matchers, {:ok, revenue_matchers}) do
for revenue_matcher <- List.wrap(revenue_matchers), matcher <- matchers do
Map.put(matcher, :revenue, revenue_matcher)
end
end

def swagger_definitions do
import PhoenixSwagger.JsonApi, except: [page: 1]

Expand All @@ -240,29 +254,86 @@ defmodule ApiWeb.PredictionController do

attributes do
arrival_time(
[:string, :null],
:string,
"""
When the vehicle is now predicted to arrive. `null` if the first stop \
(`*/relationships/stop/data/id`) on the trip (`*/relationships/trip/data/id`). See \
[GTFS `Realtime` `FeedMessage` `FeedEntity` `TripUpdate` `StopTimeUpdate` `arrival`](https://github.com/google/transit/blob/master/gtfs-realtime/spec/en/reference.md#message-stoptimeupdate).
Format is ISO8601.
""",
example: "2017-08-14T15:38:58-04:00"
example: "2017-08-14T15:38:58-04:00",
"x-nullable": true
)

departure_time(
[:string, :null],
:string,
"""
When the vehicle is now predicted to depart. `null` if the last stop \
(`*/relationships/stop/data/id`) on the trip (`*/relationships/trip/data/id`). See \
[GTFS `Realtime` `FeedMessage` `FeedEntity` `TripUpdate` `StopTimeUpdate` `departure`](https://github.com/google/transit/blob/master/gtfs-realtime/spec/en/reference.md#message-stoptimeupdate).
Format is ISO8601.
""",
example: "2017-08-14T15:38:58-04:00"
example: "2017-08-14T15:38:58-04:00",
"x-nullable": true
)

arrival_uncertainty(
[:integer, :null],
"""
Uncertainty value for the arrival time prediction.
Bus and Commuter Rail
See [entities tripUpdate stop_time_updates arrival uncertainty](https://swiftly-inc.stoplight.io/docs/realtime-standalone/613d1d7f1eae3-gtfs-rt-trip-updates)
| Value | Description |
|------------------|-------------|
| < 300 or omitted | Valid real-time prediction |
| 300 | Real-time prediction not available. This code is primarily used when a vehicle has not yet been assigned to the trip, (i.e. because the block has not started yet). It is a schedule-based prediction, but Swiftly adjusts the schedule-based prediction time using observed historical travel times to make predictions more accurate than the schedule |
| 301 | Valid real-time prediction, though the bus appears to be stalled or significantly delayed and predictions are not as accurate |
| > 301 | Likely invalid prediction, recommend not showing anything (and not showing scheduled time), very rare situation |
Subway/Light Rail
See [GTFS `Realtime` `FeedMessage` `FeedEntity` `TripUpdate` `StopTimeUpdate` `arrival`](https://github.com/google/transit/blob/master/gtfs-realtime/spec/en/reference.md#message-stoptimeupdate).
| Value | Description |
|--------|-------------|
| 60 | A trip that has already started |
| 120 | A terminal/reverse trip departure for a trip that has NOT started and a train is awaiting departure at the origin |
| 360 | A terminal/reverse trip for a trip that has NOT started and a train is completing a previous trip |
""",
example: 60
)

departure_uncertainty(
[:integer, :null],
"""
Uncertainty value for the departure time prediction.
Bus and Commuter Rail
See [entities tripUpdate stop_time_updates departure uncertainty](https://swiftly-inc.stoplight.io/docs/realtime-standalone/613d1d7f1eae3-gtfs-rt-trip-updates)
| Value | Description |
|------------------|-------------|
| < 300 or omitted | Valid real-time prediction |
| 300 | Real-time prediction not available. This code is primarily used when a vehicle has not yet been assigned to the trip, (i.e. because the block has not started yet). It is a schedule-based prediction, but Swiftly adjusts the schedule-based prediction time using observed historical travel times to make predictions more accurate than the schedule |
| 301 | Valid real-time prediction, though the bus appears to be stalled or significantly delayed and predictions are not as accurate |
| > 301 | Likely invalid prediction, recommend not showing anything (and not showing scheduled time), very rare situation |
Subway/Light Rail
See [GTFS `Realtime` `FeedMessage` `FeedEntity` `TripUpdate` `StopTimeUpdate` `departure`](https://github.com/google/transit/blob/master/gtfs-realtime/spec/en/reference.md#message-stoptimeupdate).
| Value | Description |
|-------|-------------|
| 60 | A trip that has already started |
| 120 | A terminal/reverse trip departure for a trip that has NOT started and a train is awaiting departure at the origin |
| 360 | A terminal/reverse trip for a trip that has NOT started and a train is completing a previous trip |
""",
example: 60
)

schedule_relationship(
[:string, :null],
:string,
"""
How the predicted stop relates to the `Model.Schedule.t` stops.
Expand All @@ -278,22 +349,35 @@ defmodule ApiWeb.PredictionController do
See [GTFS Realtime `FeedMesage` `FeedEntity` `TripUpdate` `TripDescriptor` `ScheduleRelationship`](https://github.com/google/transit/blob/master/gtfs-realtime/spec/en/reference.md#enum-schedulerelationship-1)
See [GTFS Realtime `FeedMesage` `FeedEntity` `TripUpdate` `StopTimeUpdate` `ScheduleRelationship`](https://github.com/google/transit/blob/master/gtfs-realtime/spec/en/reference.md#enum-schedulerelationship)
""",
example: "UNSCHEDULED"
example: "UNSCHEDULED",
"x-nullable": true
)

stop_sequence(
[:integer, :null],
:integer,
"""
The sequence the stop (`*/relationships/stop/data/id`) is arrived at during the trip \
(`*/relationships/trip/data/id`). The stop sequence is monotonically increasing along the \
trip, but the `stop_sequence` along the trip are not necessarily consecutive.
See [GTFS Realtime `FeedMesage` `FeedEntity` `TripUpdate` `StopTimeUpdate` `stop_sequence`](https://github.com/google/transit/blob/master/gtfs-realtime/spec/en/reference.md#message-stoptimeupdate).
""",
example: 19
example: 19,
"x-nullable": true
)

status(:string, "Status of the schedule", example: "Approaching")

revenue_status(
:string,
"""
| Value | Description |
|-----------------|-------------|
| `"REVENUE"` | Indicates that the associated trip is accepting passengers. |
| `"NON_REVENUE"` | Indicates that the associated trip is not accepting passengers. |
""",
example: "REVENUE"
)
end

direction_id_attribute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ defmodule ApiWeb.RoutePatternController do
)

time_desc(
[:string, :null],
:string,
"""
User-facing description of when the route pattern operate. Not all route patterns will include a time description
""",
Expand Down
42 changes: 25 additions & 17 deletions apps/api_web/lib/api_web/controllers/stop_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -270,35 +270,39 @@ defmodule ApiWeb.StopController do
)

description(
[:string, :null],
:string,
"""
Description of the stop. See [GTFS `stops.txt` `stop_desc`](https://github.com/google/transit/blob/master/gtfs/spec/en/reference.md#stopstxt).
""",
example: "Alewife - Red Line"
example: "Alewife - Red Line",
"x-nullable": true
)

address(
[:string, :null],
:string,
"""
A street address for the station. See [MBTA extensions to GTFS](https://docs.google.com/document/d/1RoQQj3_-7FkUlzFP4RcK1GzqyHp4An2lTFtcmW0wrqw/view).
""",
example: "Alewife Brook Parkway and Cambridge Park Drive, Cambridge, MA 02140"
example: "Alewife Brook Parkway and Cambridge Park Drive, Cambridge, MA 02140",
"x-nullable": true
)

platform_code(
[:string, :null],
:string,
"""
A short code representing the platform/track (like a number or letter). See [GTFS `stops.txt` `platform_code`](https://developers.google.com/transit/gtfs/reference/gtfs-extensions#stopstxt_1).
""",
example: "5"
example: "5",
"x-nullable": true
)

platform_name(
[:string, :null],
:string,
"""
A textual description of the platform or track. See [MBTA extensions to GTFS](https://docs.google.com/document/d/1RoQQj3_-7FkUlzFP4RcK1GzqyHp4An2lTFtcmW0wrqw/view).
""",
example: "Red Line"
example: "Red Line",
"x-nullable": true
)

latitude(
Expand Down Expand Up @@ -334,7 +338,7 @@ defmodule ApiWeb.StopController do
example: 0
)

location_type(%Schema{type: :integer, enum: [0, 1, 2]}, """
location_type(%Schema{type: :integer, enum: [0, 1, 2, 3]}, """
The type of the stop.
| Value | Type | Description |
Expand All @@ -348,31 +352,35 @@ defmodule ApiWeb.StopController do
""")

municipality(
[:string, :null],
:string,
"The municipality in which the stop is located.",
example: "Cambridge"
example: "Cambridge",
"x-nullable": true
)

on_street(
[:string, :null],
:string,
"The street on which the stop is located.",
example: "Massachusetts Avenue"
example: "Massachusetts Avenue",
"x-nullable": true
)

at_street(
[:string, :null],
:string,
"The cross street at which the stop is located.",
example: "Essex Street"
example: "Essex Street",
"x-nullable": true
)

vehicle_type(
[:integer, :null],
:integer,
"""
The type of transportation used at the stop. `vehicle_type` will be a valid routes.txt `route_type` value:
#{route_type_description()}
""",
example: 3
example: 3,
"x-nullable": true
)
end

Expand Down
Loading

0 comments on commit d9ccff0

Please sign in to comment.