Skip to content

Commit

Permalink
Skip recent seen filtering for priority workflows (#135)
Browse files Browse the repository at this point in the history
* skip recently seen filtering for priority workflows

allow priority workflow to always show the most recently seen do not skip past

* add wip test setup notes
  • Loading branch information
camallen authored Feb 25, 2022
1 parent 986401c commit 8cf1dd8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Using Docker:
# run the tests
mix test
iex -S mix test --trace
# run WIP tests (add the @tag :wip to the test(s) in question)
mix test --only wip
# debug wip tests using pry (require IEx IEx.pry)
Expand Down
8 changes: 6 additions & 2 deletions lib/designator/selection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule Designator.Selection do
|> Designator.StreamTools.interleave
|> deduplicate
|> reject_recently_retired(workflow)
|> reject_recently_selected(user)
|> reject_recently_selected(user, workflow.prioritized)
|> reject_seen_subjects(seen_subject_ids)
|> Enum.take(amount)
end)
Expand Down Expand Up @@ -123,7 +123,11 @@ defmodule Designator.Selection do
Stream.reject(stream, fn id -> MapSet.member?(subject_ids, id) end)
end

defp reject_recently_selected(stream, user) do
defp reject_recently_selected(stream, user, true) do
stream
end

defp reject_recently_selected(stream, user, _) do
Stream.reject(stream, fn x -> MapSet.member?(user.recently_selected_ids, x) end)
end

Expand Down
20 changes: 15 additions & 5 deletions test/designator/selection_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,29 @@ defmodule Designator.SelectionTest do
assert Selection.select(338, 1, [subject_set_id: 1, limit: 2]) == [2,1]
end

test "does not select recently handed out subject ids" do
test "does not select recently selected subject ids" do
Designator.Random.seed({123, 123534, 345345})
Designator.WorkflowCache.set(338, %{configuration: %{"gold_standard_sets" => [681, 1706]},
subject_set_ids: [681, 1706, 1682, 1681]})
Designator.WorkflowCache.set(338, %{configuration: %{}, subject_set_ids: [681, 1706, 1682, 1681]})
SubjectSetCache.set({338, 681}, %SubjectSetCache{workflow_id: 338, subject_set_id: 681, subject_ids: Arrays.new([1])})
SubjectSetCache.set({338, 1706}, %SubjectSetCache{workflow_id: 338, subject_set_id: 1706, subject_ids: Arrays.new([2])})
SubjectSetCache.set({338, 1682}, %SubjectSetCache{workflow_id: 338, subject_set_id: 1682, subject_ids: Arrays.new([3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3])})
SubjectSetCache.set({338, 1681}, %SubjectSetCache{workflow_id: 338, subject_set_id: 1681, subject_ids: Arrays.new([4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4])})
SubjectSetCache.set({338, 1682}, %SubjectSetCache{workflow_id: 338, subject_set_id: 1682, subject_ids: Arrays.new([3])})
SubjectSetCache.set({338, 1681}, %SubjectSetCache{workflow_id: 338, subject_set_id: 1681, subject_ids: Arrays.new([4])})
Designator.UserCache.set({338, 1}, %{seen_ids: MapSet.new, recently_selected_ids: MapSet.new([1,2,3,4]), configuration: %{}})

_run_selection_to_setup_cache = Selection.select(338, 1, [limit: 4])
assert Selection.select(338, 1, [limit: 4]) == []
end

test "does select recently selected subject ids for prioritized workflows" do
Designator.Random.seed({123, 123534, 345345})
Designator.WorkflowCache.set(338, %{configuration: %{}, prioritized: true, subject_set_ids: [681]})
SubjectSetCache.set({338, 681}, %SubjectSetCache{workflow_id: 338, subject_set_id: 681, subject_ids: Arrays.new([4,3,2,1])})
Designator.UserCache.set({338, 1}, %{seen_ids: MapSet.new, recently_selected_ids: MapSet.new([1,2,3,4]), configuration: %{}})

_run_selection_to_setup_cache = Selection.select(338, 1, [limit: 4])
assert Selection.select(338, 1, [limit: 4]) == [4,3,2,1]
end

test "does not select recently retired subject ids" do
Designator.Random.seed({123, 123534, 345345})
Designator.WorkflowCache.set(338, %{configuration: %{"gold_standard_sets" => [681, 1706]},
Expand Down

0 comments on commit 8cf1dd8

Please sign in to comment.