Skip to content

Commit

Permalink
Merge pull request #5162 from Simon-Initiative/integrate-v0.28.11
Browse files Browse the repository at this point in the history
[CHORE] [MER-0000] Integrate v0.28.11
  • Loading branch information
rgachuhi authored Oct 4, 2024
2 parents 0d3ddd8 + 0dc8993 commit 87a8da6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
15 changes: 12 additions & 3 deletions lib/oli/delivery/attempts/scoring.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,16 @@ defmodule Oli.Delivery.Attempts.Scoring do

# The most recent is assumed to be the last item in the list
def calculate_score("most_recent", items) do
most_recent = Enum.reverse(items) |> hd
# Sort the resource_attemmpts by the date_evaluated field, so that
# the most recent evaluated attempt is the first item in the list.
#
# This makes this scoring strategy a little more robust in the face of
# attempts where somehow the most recent attempt does not match
# the natural database order - or somehow the query doesn't return
# in database order.
[most_recent | _] =
Enum.filter(items, &(&1.date_evaluated != nil))
|> Enum.sort_by(& &1.date_evaluated, &(DateTime.compare(&1, &2) != :lt))

%Result{
score: Map.get(most_recent, :score),
Expand Down Expand Up @@ -92,7 +101,7 @@ defmodule Oli.Delivery.Attempts.Scoring do

defp translate_nils(items) do
Enum.map(items, fn p ->
%{
Map.merge(p, %{
score:
if is_nil(p.score) do
0
Expand All @@ -105,7 +114,7 @@ defmodule Oli.Delivery.Attempts.Scoring do
else
p.out_of
end
}
})
end)
end

Expand Down
15 changes: 12 additions & 3 deletions test/oli/delivery/attempts/scoring_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@ defmodule Oli.Delivery.Attempts.ScoringTest do
end

test "most recent" do
items = [%{score: 5, out_of: 10}]
items = [%{score: 5, out_of: 10, date_evaluated: ~U[2021-01-01 00:00:00Z]}]
assert %Result{score: 5, out_of: 10} = Scoring.calculate_score("most_recent", items)

items = [%{score: 5, out_of: 10}, %{score: 1, out_of: 20}]
assert %Result{score: 1, out_of: 20} = Scoring.calculate_score("most_recent", items)
items = [
%{score: 2, out_of: 10, date_evaluated: ~U[2019-01-01 00:00:00Z]},
%{score: 5, out_of: 10, date_evaluated: ~U[2023-01-01 00:00:00Z]},
%{score: 1, out_of: 20, date_evaluated: ~U[2021-01-01 00:00:00Z]},
%{score: 9, out_of: 20, date_evaluated: nil}
]

most_recent_id = Oli.Resources.ScoringStrategy.get_id_by_type("most_recent")
assert %Result{score: 5, out_of: 10} = Scoring.calculate_score(most_recent_id, items)

assert %Result{score: 5, out_of: 10} = Scoring.calculate_score("most_recent", items)
end

test "best" do
Expand Down

0 comments on commit 87a8da6

Please sign in to comment.