diff --git a/README.md b/README.md index 35c8c53..8a23ce4 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/lib/designator/selection.ex b/lib/designator/selection.ex index 32f02d7..f2bf159 100644 --- a/lib/designator/selection.ex +++ b/lib/designator/selection.ex @@ -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) @@ -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 diff --git a/test/designator/selection_test.exs b/test/designator/selection_test.exs index 4acfe1d..dd9593a 100644 --- a/test/designator/selection_test.exs +++ b/test/designator/selection_test.exs @@ -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]},