From 3f63549cc2da2886d3a4d188a7399a4ffd239dcf Mon Sep 17 00:00:00 2001 From: David Fisher Date: Thu, 28 Mar 2024 10:12:20 -0400 Subject: [PATCH 1/5] Compute p@10 using 0 == irrel, 1+ == rel, so that P@10 is in the expected range [0..1] --- db/scorers/p@10.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/db/scorers/p@10.js b/db/scorers/p@10.js index e8a37cbc4..1bb645bfc 100644 --- a/db/scorers/p@10.js +++ b/db/scorers/p@10.js @@ -1,4 +1,11 @@ -var k = 10 // @Rank -var score = avgRating(k); - +const k = 10; // @Rank +// k may be > length list, so count up the total number of documents processed. +let count = 0, total = 0; +eachDoc(function(doc, i) { + if (hasDocRating(i) && (docRating(i)) > 0) { // map 0 -> irrel, 1+ ->rel + count = count i+1 + } + total = total + 1 +}, k); +const score = rank / total : 0.0; setScore(score); From 55e368f9c770e97ec661e4d27bebe5ff27f160b2 Mon Sep 17 00:00:00 2001 From: David Fisher Date: Thu, 28 Mar 2024 10:16:04 -0400 Subject: [PATCH 2/5] Compute count, not rank divided by total. --- db/scorers/p@10.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/scorers/p@10.js b/db/scorers/p@10.js index 1bb645bfc..7b92b7fc2 100644 --- a/db/scorers/p@10.js +++ b/db/scorers/p@10.js @@ -7,5 +7,5 @@ eachDoc(function(doc, i) { } total = total + 1 }, k); -const score = rank / total : 0.0; +const score = count / total : 0.0; setScore(score); From 3df1a9c22698e5f63cb49cc7f44b83b169534c44 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Wed, 26 Jun 2024 14:29:30 -0400 Subject: [PATCH 3/5] Trigger a migration for existing Quepid users to get the new P@10 javascript code --- db/migrate/20240626181338_reindex_p_at10_code.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 db/migrate/20240626181338_reindex_p_at10_code.rb diff --git a/db/migrate/20240626181338_reindex_p_at10_code.rb b/db/migrate/20240626181338_reindex_p_at10_code.rb new file mode 100644 index 000000000..b7bf0bba9 --- /dev/null +++ b/db/migrate/20240626181338_reindex_p_at10_code.rb @@ -0,0 +1,12 @@ +class ReindexPAt10Code < ActiveRecord::Migration[7.1] + # force existing P@10 scorers to reload using the latest scorer information. + def change + scorers_to_update = ['P@10'] + scorers_to_update.each do |scorer_name| + scorer = Scorer.where(name: scorer_name, communal: true).first + name = scorer.name + scorer.code = File.readlines("./db/scorers/#{name.downcase}.js",'\n').join('\n') + scorer.save! + end + end +end From 0800e1f00c7a307a6ba8475172c0c05b3ae00808 Mon Sep 17 00:00:00 2001 From: David Fisher Date: Wed, 26 Jun 2024 15:08:32 -0400 Subject: [PATCH 4/5] Do that math in a mathy way --- db/scorers/p@10.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/scorers/p@10.js b/db/scorers/p@10.js index 7b92b7fc2..539529f2c 100644 --- a/db/scorers/p@10.js +++ b/db/scorers/p@10.js @@ -3,9 +3,9 @@ const k = 10; // @Rank let count = 0, total = 0; eachDoc(function(doc, i) { if (hasDocRating(i) && (docRating(i)) > 0) { // map 0 -> irrel, 1+ ->rel - count = count i+1 + count = count + 1 } - total = total + 1 + total = total + 1.0 }, k); -const score = count / total : 0.0; +const score = total ? count / total : 0.0; setScore(score); From 9e48483dbd3b6eaf5ceae70ca2f4d0920d0c97cf Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Wed, 26 Jun 2024 15:12:31 -0400 Subject: [PATCH 5/5] lint! --- db/schema.rb | 2 +- db/scorers/p@10.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 0a19e24b7..116dc63f7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_06_26_173902) do +ActiveRecord::Schema[7.1].define(version: 2024_06_26_181338) do create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_bin", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false diff --git a/db/scorers/p@10.js b/db/scorers/p@10.js index 539529f2c..f094fbdb8 100644 --- a/db/scorers/p@10.js +++ b/db/scorers/p@10.js @@ -3,9 +3,9 @@ const k = 10; // @Rank let count = 0, total = 0; eachDoc(function(doc, i) { if (hasDocRating(i) && (docRating(i)) > 0) { // map 0 -> irrel, 1+ ->rel - count = count + 1 + count = count + 1; } - total = total + 1.0 + total = total + 1.0; }, k); const score = total ? count / total : 0.0; setScore(score);