-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move uncertainty calculation to group filter
- Loading branch information
Showing
9 changed files
with
152 additions
and
80 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
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,29 @@ | ||
defmodule Concentrate.GroupFilter.UncertaintyValue do | ||
@moduledoc """ | ||
Populates uncertainty in TripDescriptor based on the update_type value | ||
""" | ||
@behaviour Concentrate.GroupFilter | ||
alias Concentrate.{StopTimeUpdate, TripDescriptor} | ||
|
||
@impl Concentrate.GroupFilter | ||
def filter({%TripDescriptor{update_type: update_type} = td, vps, stus}) do | ||
stus = set_uncertainty(update_type, stus) | ||
|
||
{td, vps, stus} | ||
end | ||
|
||
def filter(other), do: other | ||
|
||
defp set_uncertainty(nil, stus), do: stus | ||
|
||
defp set_uncertainty(update_type, stus) do | ||
Enum.map(stus, fn stu -> | ||
StopTimeUpdate.update_uncertainty(stu, calculate_uncertainty(update_type)) | ||
end) | ||
end | ||
|
||
defp calculate_uncertainty("mid_trip"), do: 60 | ||
defp calculate_uncertainty("at_terminal"), do: 120 | ||
defp calculate_uncertainty("reverse_trip"), do: 360 | ||
defp calculate_uncertainty(_), do: nil | ||
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
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,73 @@ | ||
defmodule Concentrate.GroupFilter.UncertaintyValueTest do | ||
@moduledoc false | ||
use ExUnit.Case, async: true | ||
import Concentrate.GroupFilter.UncertaintyValue | ||
alias Concentrate.StopTimeUpdate | ||
alias Concentrate.TripDescriptor | ||
|
||
describe "filter/1" do | ||
test "populates uncertainty in TripDescriptor based on update_type value of mid_trip" do | ||
td = TripDescriptor.new(update_type: "mid_trip") | ||
|
||
stus = [ | ||
StopTimeUpdate.new(uncertainty: nil), | ||
StopTimeUpdate.new(uncertainty: nil), | ||
StopTimeUpdate.new(uncertainty: nil) | ||
] | ||
|
||
{^td, [], processed_stus} = filter({td, [], stus}) | ||
|
||
assert Enum.all?(processed_stus, fn procced_stu -> | ||
StopTimeUpdate.uncertainty(procced_stu) == 60 | ||
end) | ||
end | ||
|
||
test "populates uncertainty in TripDescriptor based on update_type value of at_terminal" do | ||
td = TripDescriptor.new(update_type: "at_terminal") | ||
|
||
stus = [ | ||
StopTimeUpdate.new(uncertainty: nil), | ||
StopTimeUpdate.new(uncertainty: nil), | ||
StopTimeUpdate.new(uncertainty: nil) | ||
] | ||
|
||
{^td, [], processed_stus} = filter({td, [], stus}) | ||
|
||
assert Enum.all?(processed_stus, fn procced_stu -> | ||
StopTimeUpdate.uncertainty(procced_stu) == 120 | ||
end) | ||
end | ||
|
||
test "populates uncertainty in TripDescriptor based on update_type value of reverse_trip" do | ||
td = TripDescriptor.new(update_type: "reverse_trip") | ||
|
||
stus = [ | ||
StopTimeUpdate.new(uncertainty: nil), | ||
StopTimeUpdate.new(uncertainty: nil), | ||
StopTimeUpdate.new(uncertainty: nil) | ||
] | ||
|
||
{^td, [], processed_stus} = filter({td, [], stus}) | ||
|
||
assert Enum.all?(processed_stus, fn procced_stu -> | ||
StopTimeUpdate.uncertainty(procced_stu) == 360 | ||
end) | ||
end | ||
|
||
test "populates uncertainty in TripDescriptor based on update_type value of other" do | ||
td = TripDescriptor.new(update_type: nil) | ||
|
||
stus = [ | ||
StopTimeUpdate.new(uncertainty: nil), | ||
StopTimeUpdate.new(uncertainty: nil), | ||
StopTimeUpdate.new(uncertainty: nil) | ||
] | ||
|
||
{^td, [], processed_stus} = filter({td, [], stus}) | ||
|
||
assert Enum.all?(processed_stus, fn procced_stu -> | ||
StopTimeUpdate.uncertainty(procced_stu) == nil | ||
end) | ||
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