-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🧠 Implement "uncertainty adapter" within Concentrate #346
Changes from 6 commits
afeb8f5
282e28e
0d56d09
6fab52d
c27deeb
081b6fb
64339d8
75e5c67
0a57eb1
5f789ea
151d844
85e238b
e175528
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: this looks like it always sets the |
||
end) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: since |
||
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 |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: can you add a test than an |
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: typo, should be
Concentrate.GroupFilter.UncertaintyValue