Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: require
stop_sequence
for StopTimeUpdates
Previously we merged StopTimeUpdates using a "key" of trip ID + stop ID + stop sequence. Since stop ID and sequence are both optional (only one needs to be present), this created the potential for duplicates: two updates that referred to the same stop would not be merged if one of them used a sequence and the other used a stop ID. Given: 1. it's not universally possible to merge StopTimeUpdates without a stop sequence (it's required if a trip contains a loop) 2. merging updates correctly using "maybe stop ID or sequence or both" would require significant changes to the merging system 3. grouping and the `RemoveUnneededTimes` filter assume the presence of stop sequences 4. all our current input feeds either include stop sequences already or are planned to ...we can simplify things by explicitly requiring a stop sequence, and only merging based on trip ID + stop sequence.
- Loading branch information
1 parent
93306aa
commit ac72186
Showing
5 changed files
with
54 additions
and
22 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
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,19 @@ | ||
defmodule Concentrate.Filter.NullStopSequence do | ||
@moduledoc """ | ||
Filters out StopTimeUpdates with a null `stop_sequence`, since they would not have been merged | ||
correctly (and wouldn't work with downstream modules that assume a stop sequence is present). | ||
""" | ||
@behaviour Concentrate.Filter | ||
alias Concentrate.StopTimeUpdate | ||
require Logger | ||
|
||
@impl Concentrate.Filter | ||
def filter(%StopTimeUpdate{} = stu) do | ||
case StopTimeUpdate.stop_sequence(stu) do | ||
nil -> :skip | ||
_ -> {:cont, stu} | ||
end | ||
end | ||
|
||
def filter(other), do: {:cont, other} | ||
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,22 @@ | ||
defmodule Concentrate.Filter.NullStopSequenceTest do | ||
@moduledoc false | ||
use ExUnit.Case, async: true | ||
import Concentrate.Filter.NullStopSequence | ||
alias Concentrate.StopTimeUpdate | ||
|
||
describe "filter/1" do | ||
test "skips a stop time update with a null stop_sequence" do | ||
stu = StopTimeUpdate.new(stop_sequence: nil) | ||
assert :skip = filter(stu) | ||
end | ||
|
||
test "passes through a stop time update with a stop_sequence" do | ||
stu = StopTimeUpdate.new(stop_sequence: 1) | ||
assert {:cont, ^stu} = filter(stu) | ||
end | ||
|
||
test "passes through other values" do | ||
assert {:cont, :value} = filter(:value) | ||
end | ||
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