From ca67fb398e9dc35920de2ebfa8364df953f4746e Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Mon, 22 Jan 2024 08:40:59 -0500 Subject: [PATCH 1/4] add test for the ratings format that confirms int values not floats... --- .../v1/export/ratings/_rre_query.json.jbuilder | 7 ++++--- .../api/v1/export/ratings_controller_test.rb | 15 +++++++++++++-- test/fixtures/teams.yml | 2 +- test/fixtures/tries.yml | 1 + 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/views/api/v1/export/ratings/_rre_query.json.jbuilder b/app/views/api/v1/export/ratings/_rre_query.json.jbuilder index c302f8bf0..36d564ae3 100644 --- a/app/views/api/v1/export/ratings/_rre_query.json.jbuilder +++ b/app/views/api/v1/export/ratings/_rre_query.json.jbuilder @@ -7,12 +7,13 @@ end grouped_ratings = {} query.ratings.fully_rated.each do |r| + int_rating = r.rating.to_i # rre and rankquest both are int based # rubocop:disable Style/IfUnlessModifier - unless grouped_ratings.key?(r.rating) - grouped_ratings[r.rating] = [] + unless grouped_ratings.key?(int_rating) + grouped_ratings[int_rating] = [] end # rubocop:enable Style/IfUnlessModifier - grouped_ratings[r.rating] << r.doc_id + grouped_ratings[int_rating] << r.doc_id end json.relevant_documents do diff --git a/test/controllers/api/v1/export/ratings_controller_test.rb b/test/controllers/api/v1/export/ratings_controller_test.rb index eba688017..c7186b52f 100644 --- a/test/controllers/api/v1/export/ratings_controller_test.rb +++ b/test/controllers/api/v1/export/ratings_controller_test.rb @@ -35,7 +35,7 @@ class RatingsControllerTest < ActionController::TestCase end describe 'Exporting a case in RRE json format' do - let(:the_case) { cases(:one) } + let(:the_case) { cases(:queries_case) } test 'returns case info' do get :show, params: { case_id: the_case.id, file_format: 'rre' } @@ -49,13 +49,24 @@ class RatingsControllerTest < ActionController::TestCase assert_response :ok body = response.parsed_body + + puts response.body assert_equal body['id_field'], 'id' assert_equal body['index'], the_case.tries.latest.index_name_from_search_url assert_equal body['queries'].size, the_case.queries.size assert_equal body['queries'][0]['placeholders']['$query'], the_case.queries[0].query_text assert_equal body['queries'][2]['placeholders']['$query'], the_case.queries[2].query_text - assert_nil body['queries'][2]['relevant_documents'] + assert_not_nil body['queries'][2]['relevant_documents'] + puts body['queries'][2]['relevant_documents'] + + expected_relevant_docs = { + "1": ["docb"], + "3": ["doca"] + } + + + assert_equal expected_relevant_docs, body['queries'][2]['relevant_documents'].deep_symbolize_keys end end diff --git a/test/fixtures/teams.yml b/test/fixtures/teams.yml index d7ab355f2..4e6ccc31a 100644 --- a/test/fixtures/teams.yml +++ b/test/fixtures/teams.yml @@ -21,7 +21,7 @@ valid: name: valid team owner: :doug - cases: shared_through_owned_team + cases: shared_through_owned_team, queries_case members: doug shared: diff --git a/test/fixtures/tries.yml b/test/fixtures/tries.yml index c1bdb7c73..2fff5db98 100644 --- a/test/fixtures/tries.yml +++ b/test/fixtures/tries.yml @@ -206,4 +206,5 @@ for_case_queries_case: case: :queries_case query_params: 'q=#$query##' try_number: 1 + field_spec: id:id title:title search_endpoint: :for_case_queries_case From b6823e8e62d298226220dd5390c8056230684dc9 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Mon, 22 Jan 2024 09:43:19 -0500 Subject: [PATCH 2/4] change the output format to be what RRE does and RankQuest expects. --- .../v1/export/ratings/_rre_query.json.jbuilder | 16 ++-------------- .../api/v1/export/ratings_controller_test.rb | 15 ++++++++------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/app/views/api/v1/export/ratings/_rre_query.json.jbuilder b/app/views/api/v1/export/ratings/_rre_query.json.jbuilder index 36d564ae3..a6fed9787 100644 --- a/app/views/api/v1/export/ratings/_rre_query.json.jbuilder +++ b/app/views/api/v1/export/ratings/_rre_query.json.jbuilder @@ -4,20 +4,8 @@ json.placeholders do json.set!('$query', query.query_text) end -grouped_ratings = {} - -query.ratings.fully_rated.each do |r| - int_rating = r.rating.to_i # rre and rankquest both are int based - # rubocop:disable Style/IfUnlessModifier - unless grouped_ratings.key?(int_rating) - grouped_ratings[int_rating] = [] - end - # rubocop:enable Style/IfUnlessModifier - grouped_ratings[int_rating] << r.doc_id -end - json.relevant_documents do - grouped_ratings.sort.to_h.each do |key, value| - json.set!(key, value) + query.ratings.fully_rated.each do |r| + json.set!(r.doc_id, { gain: r.rating.to_i } ) end end diff --git a/test/controllers/api/v1/export/ratings_controller_test.rb b/test/controllers/api/v1/export/ratings_controller_test.rb index c7186b52f..6f325c949 100644 --- a/test/controllers/api/v1/export/ratings_controller_test.rb +++ b/test/controllers/api/v1/export/ratings_controller_test.rb @@ -49,8 +49,6 @@ class RatingsControllerTest < ActionController::TestCase assert_response :ok body = response.parsed_body - - puts response.body assert_equal body['id_field'], 'id' assert_equal body['index'], the_case.tries.latest.index_name_from_search_url @@ -58,14 +56,17 @@ class RatingsControllerTest < ActionController::TestCase assert_equal body['queries'][0]['placeholders']['$query'], the_case.queries[0].query_text assert_equal body['queries'][2]['placeholders']['$query'], the_case.queries[2].query_text assert_not_nil body['queries'][2]['relevant_documents'] - puts body['queries'][2]['relevant_documents'] + # somewhat verbose RRE format for describing ratings. expected_relevant_docs = { - "1": ["docb"], - "3": ["doca"] + docb: { + gain: 1, + }, + doca: { + gain: 3, + }, } - - + assert_equal expected_relevant_docs, body['queries'][2]['relevant_documents'].deep_symbolize_keys end end From b15c908ea360bb32b77e17542cbca75652772117 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Mon, 22 Jan 2024 09:50:32 -0500 Subject: [PATCH 3/4] lint --- test/controllers/api/v1/export/ratings_controller_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/controllers/api/v1/export/ratings_controller_test.rb b/test/controllers/api/v1/export/ratings_controller_test.rb index 6f325c949..2eacbbe83 100644 --- a/test/controllers/api/v1/export/ratings_controller_test.rb +++ b/test/controllers/api/v1/export/ratings_controller_test.rb @@ -56,7 +56,7 @@ class RatingsControllerTest < ActionController::TestCase assert_equal body['queries'][0]['placeholders']['$query'], the_case.queries[0].query_text assert_equal body['queries'][2]['placeholders']['$query'], the_case.queries[2].query_text assert_not_nil body['queries'][2]['relevant_documents'] - + # somewhat verbose RRE format for describing ratings. expected_relevant_docs = { docb: { From e2c90f75f9e3bb7edfcea825a057f650f2f78773 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Mon, 22 Jan 2024 09:50:37 -0500 Subject: [PATCH 4/4] messaging --- app/assets/javascripts/components/export_case/_modal.html | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/components/export_case/_modal.html b/app/assets/javascripts/components/export_case/_modal.html index cd21e263e..7ad89f79c 100644 --- a/app/assets/javascripts/components/export_case/_modal.html +++ b/app/assets/javascripts/components/export_case/_modal.html @@ -82,10 +82,9 @@