-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from mbta/jz-glides-report-collapse-by-trip-id
feat: Add a second table to extraneous/missed predictions report that analyzes by `{stop_id, trip_id}`
- Loading branch information
Showing
24 changed files
with
1,673 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Elixir CI | ||
name: CI | ||
|
||
on: [push, pull_request] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Report Elixir Coverage | ||
|
||
on: | ||
workflow_run: | ||
workflows: | ||
- CI | ||
types: | ||
- completed | ||
|
||
permissions: | ||
actions: read | ||
contents: read | ||
pull-requests: write | ||
|
||
jobs: | ||
report-coverage: | ||
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- run: mkdir -p ${{ runner.temp }}/cover | ||
- run: echo Fetching artifacts for ${{ github.event.workflow_run.id }}, event name ${{ github.event_name }}, triggered by ${{ github.event.workflow_run.event }} | ||
- name: Download artifact | ||
uses: actions/[email protected] | ||
with: | ||
script: | | ||
var artifacts = await github.actions.listWorkflowRunArtifacts({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
run_id: ${{github.event.workflow_run.id }}, | ||
}); | ||
var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | ||
return artifact.name == "elixir-lcov" | ||
})[0]; | ||
var download = await github.actions.downloadArtifact({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
artifact_id: matchArtifact.id, | ||
archive_format: 'zip', | ||
}); | ||
var fs = require('fs'); | ||
fs.writeFileSync('${{ runner.temp }}/cover/elixir-lcov.zip', Buffer.from(download.data)); | ||
- working-directory: ${{ runner.temp }}/cover | ||
run: | | ||
unzip elixir-lcov.zip | ||
echo "PR_SHA=$(cat PR_SHA)" >> $GITHUB_ENV | ||
echo "PR_NUMBER=$(cat PR_NUMBER)" >> $GITHUB_ENV | ||
- uses: actions/checkout@v2 # UNTRUSTED CODE - do not run scripts from it | ||
with: | ||
ref: ${{ env.PR_SHA }} | ||
- name: Upload coverage artifact and post comment | ||
uses: mbta/github-actions-report-lcov@v1 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
coverage-files: ${{ runner.temp }}/cover/lcov*.info | ||
artifact-name: elixir-code-coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Config | ||
|
||
import_config "#{config_env()}.exs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Config | ||
|
||
config :elixir, :time_zone_database, Tz.TimeZoneDatabase | ||
|
||
config :transit_data, :data_lake_api, TransitData.MockDataLake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
defmodule TransitData.DataLake do | ||
@moduledoc """ | ||
Functions to work with our mbta-gtfs-s3* data lake buckets. | ||
""" | ||
|
||
############# | ||
# Callbacks # | ||
############# | ||
|
||
@doc """ | ||
Returns a stream of keys of objects in the given bucket that match the given prefix. | ||
""" | ||
@callback stream_object_keys(bucket :: String.t(), prefix :: String.t()) :: | ||
Enumerable.t(String.t()) | ||
|
||
@doc """ | ||
Returns a stream of the contents of a data lake JSON file. | ||
Returns a tuple containing: | ||
- a stream of maps, parsed from the JSON's `entity` field | ||
- the timestamp, parsed from the JSON's `header` field | ||
- the basename of the object's key | ||
""" | ||
@callback stream_json(bucket :: String.t(), key :: String.t()) :: | ||
{data :: Enumerable.t(map()), timestamp :: integer, basename :: String.t()} | ||
|
||
################################# | ||
# Dispatching to implementation # | ||
################################# | ||
|
||
# The module adopting this behaviour that we use for the current environment. | ||
@callback_module Application.compile_env(:transit_data, :data_lake_api, TransitData.S3DataLake) | ||
|
||
defdelegate stream_object_keys(bucket, prefix), to: @callback_module | ||
defdelegate stream_json(bucket, key), to: @callback_module | ||
end | ||
|
||
defmodule TransitData.S3DataLake do | ||
@moduledoc false | ||
|
||
@behaviour TransitData.DataLake | ||
|
||
@impl true | ||
def stream_json(bucket, key) do | ||
stream = | ||
ExAws.S3.download_file(bucket, key, :memory) | ||
|> ExAws.stream!() | ||
|> StreamGzip.gunzip() | ||
|> Jaxon.Stream.from_enumerable() | ||
|
||
timestamp = | ||
stream | ||
|> Jaxon.Stream.query([:root, "header", "timestamp"]) | ||
|> Enum.at(0) | ||
|
||
objects = Jaxon.Stream.query(stream, [:root, "entity", :all]) | ||
|
||
{objects, timestamp, Path.basename(key)} | ||
end | ||
|
||
@impl true | ||
def stream_object_keys(bucket, prefix) do | ||
ExAws.S3.list_objects(bucket, prefix: prefix) | ||
|> ExAws.stream!() | ||
|> Stream.map(& &1.key) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
defmodule TransitData.GlidesReport.Departure do | ||
@moduledoc """ | ||
Data structure representing a single departure from a stop | ||
(either predicted or actual) | ||
""" | ||
|
||
alias TransitData.GlidesReport.Spec.Common | ||
alias TransitData.GlidesReport.Util | ||
|
||
@type t :: %__MODULE__{ | ||
trip: Common.trip_id(), | ||
stop: Common.stop_id(), | ||
timestamp: Common.timestamp(), | ||
# Hour part of the timestamp (in Eastern TZ) | ||
hour: 0..23, | ||
# Minute part of the timestamp | ||
minute: 0..59 | ||
} | ||
|
||
@type minute :: 0..59 | ||
|
||
@enforce_keys [:trip, :stop, :timestamp, :hour, :minute] | ||
defstruct @enforce_keys | ||
|
||
@spec new(Common.trip_id(), Common.stop_id(), Common.timestamp()) :: t() | ||
def new(trip, stop, timestamp) do | ||
hour = Util.unix_timestamp_to_local_hour(timestamp) | ||
minute = Util.unix_timestamp_to_local_minute(timestamp) | ||
%__MODULE__{trip: trip, stop: stop, timestamp: timestamp, hour: hour, minute: minute} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.