From db0335988963092bcb73e43a439f23df7d196420 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Mon, 22 Jan 2024 10:45:10 -0500 Subject: [PATCH] Remove threshold flag for queries (#927) --- .../controllers/promptThreshold.js | 24 ------- .../javascripts/controllers/searchResults.js | 4 -- .../javascripts/controllers/takeThreshold.js | 27 -------- app/assets/javascripts/services/queriesSvc.js | 26 ------- app/assets/templates/views/searchResults.html | 16 ----- .../templates/views/thresholdModal.html | 15 ----- .../api/v1/queries/thresholds_controller.rb | 24 ------- app/lib/analytics/google_analytics/events.rb | 18 ----- app/lib/analytics/tracker/query.rb | 4 -- app/models/query.rb | 2 - .../api/v1/export/cases/_query.json.jbuilder | 2 - app/views/api/v1/queries/_query.json.jbuilder | 2 - .../queries/thresholds/update.json.jbuilder | 4 -- app/views/books/edit.html.erb | 6 +- config/routes.rb | 1 - ...134401_drop_threshold_enbl_from_queries.rb | 8 +++ db/schema.rb | 4 +- .../angular/services/queriesSvc_spec.js | 43 ------------ .../api/v1/import/cases_controller_test.rb | 38 +++++------ .../v1/queries/thresholds_controller_test.rb | 67 ------------------- test/fixtures/queries.yml | 2 - test/models/query_test.rb | 2 - 22 files changed, 27 insertions(+), 312 deletions(-) delete mode 100644 app/assets/javascripts/controllers/promptThreshold.js delete mode 100644 app/assets/javascripts/controllers/takeThreshold.js delete mode 100644 app/assets/templates/views/thresholdModal.html delete mode 100644 app/controllers/api/v1/queries/thresholds_controller.rb delete mode 100644 app/views/api/v1/queries/thresholds/update.json.jbuilder create mode 100644 db/migrate/20240121134401_drop_threshold_enbl_from_queries.rb delete mode 100644 test/controllers/api/v1/queries/thresholds_controller_test.rb diff --git a/app/assets/javascripts/controllers/promptThreshold.js b/app/assets/javascripts/controllers/promptThreshold.js deleted file mode 100644 index dba411369..000000000 --- a/app/assets/javascripts/controllers/promptThreshold.js +++ /dev/null @@ -1,24 +0,0 @@ -'use strict'; - -angular.module('QuepidApp') - .controller('PromptThresholdCtrl', [ - '$scope', '$uibModalInstance', - 'query', - function($scope, $uibModalInstance, query) { - - $scope.Params = {}; - $scope.setThreshold = function() { }; - - $scope.Params.threshold = query.threshold; - $scope.Params.thresholdEnabled = query.thresholdEnabled; - - $scope.ok = function() { - query.setThreshold($scope.Params.thresholdEnabled, $scope.Params.threshold); - $uibModalInstance.close(); - }; - - $scope.close = function() { - $uibModalInstance.dismiss('cancel'); - }; - } - ]); diff --git a/app/assets/javascripts/controllers/searchResults.js b/app/assets/javascripts/controllers/searchResults.js index 9c37e4f8b..e29ce1bfc 100644 --- a/app/assets/javascripts/controllers/searchResults.js +++ b/app/assets/javascripts/controllers/searchResults.js @@ -30,10 +30,6 @@ angular.module('QuepidApp') } }); - $scope.overThreshold = function() { - return $scope.query.lastScore && $scope.query.thresholdEnabled && - ($scope.query.lastScore < $scope.query.threshold); - }; $scope.displayed = new DisplayConfig(); diff --git a/app/assets/javascripts/controllers/takeThreshold.js b/app/assets/javascripts/controllers/takeThreshold.js deleted file mode 100644 index 2d55443a4..000000000 --- a/app/assets/javascripts/controllers/takeThreshold.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -angular.module('QuepidApp') - .controller('TakeThresholdCtrl', [ - '$scope', '$uibModal', '$log', - function ($scope, $uibModal, $log) { - $scope.snapshot = {}; - $scope.snapshot.prompt = function() { - - var modalInstance = $uibModal.open({ - templateUrl: 'views/thresholdModal.html', - controller: 'PromptThresholdCtrl', - resolve: { - query: function() { - return $scope.query; - } - } - }); - - modalInstance.result.then(function() { - // take the snapshot over all the active queries - $log.debug('Creating snapshot: '); - }); - - }; - } - ]); diff --git a/app/assets/javascripts/services/queriesSvc.js b/app/assets/javascripts/services/queriesSvc.js index f3acf9ea5..439c4f2c7 100644 --- a/app/assets/javascripts/services/queriesSvc.js +++ b/app/assets/javascripts/services/queriesSvc.js @@ -232,9 +232,6 @@ angular.module('QuepidApp') self.modified = queryWithRatings.updated_at; - // Threshold properties - self.threshold = queryWithRatings.threshold; - self.thresholdEnabled = queryWithRatings.threshold_enabled; // Error self.errorText = ''; @@ -631,29 +628,6 @@ angular.module('QuepidApp') }); }; - this.setThreshold = function(enabled, threshold) { - var that = this; - var url = 'api/cases/' + caseNo + '/queries/' + that.queryId + '/threshold'; - var thresholdJson = { - query: { - threshold: threshold, - threshold_enbl: enabled - } - }; - - return $http.put(url, thresholdJson) - .then(function() { - that.threshold = threshold; - that.thresholdEnabled = enabled; - }, function(response) { - $log.debug('Failed to set threshold: ', response); - return response; - }).catch(function(response) { - $log.debug('Failed to set threshold'); - return response; - }); - }; - this.reset = function() { this.errorText = ''; resultsReturned = false; diff --git a/app/assets/templates/views/searchResults.html b/app/assets/templates/views/searchResults.html index 339f11046..a22b9e66c 100644 --- a/app/assets/templates/views/searchResults.html +++ b/app/assets/templates/views/searchResults.html @@ -35,27 +35,13 @@

- - - - {{query.threshold}} - - - - - - - - - -
Score All @@ -90,8 +76,6 @@

-
diff --git a/app/assets/templates/views/thresholdModal.html b/app/assets/templates/views/thresholdModal.html deleted file mode 100644 index 43d662942..000000000 --- a/app/assets/templates/views/thresholdModal.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - diff --git a/app/controllers/api/v1/queries/thresholds_controller.rb b/app/controllers/api/v1/queries/thresholds_controller.rb deleted file mode 100644 index 72901b939..000000000 --- a/app/controllers/api/v1/queries/thresholds_controller.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -module Api - module V1 - module Queries - class ThresholdsController < Api::V1::Queries::ApplicationController - def update - if @query.update query_params - Analytics::Tracker.track_query_threshold_updated_event current_user, @query - respond_with @query - else - render json: @query.errors, status: :bad_request - end - end - - private - - def query_params - params.require(:query).permit(:threshold, :threshold_enbl) - end - end - end - end -end diff --git a/app/lib/analytics/google_analytics/events.rb b/app/lib/analytics/google_analytics/events.rb index 397a51e4d..2c28e4835 100644 --- a/app/lib/analytics/google_analytics/events.rb +++ b/app/lib/analytics/google_analytics/events.rb @@ -558,24 +558,6 @@ def user_bulk_deleted_ratings _user, query create_event data end - # - # Creates an event when a user updates query threshold. - # - # @param user, User - # @param query, Query - # - def user_updated_query_threshold _user, query - data = { - category: 'Queries', - action: 'Updated Query Threshold', - label: query.query_text, - value: nil, - bounce: false, - } - - create_event data - end - # # Creates an event when a user updates query scorer. # diff --git a/app/lib/analytics/tracker/query.rb b/app/lib/analytics/tracker/query.rb index a45131749..a15d383fa 100644 --- a/app/lib/analytics/tracker/query.rb +++ b/app/lib/analytics/tracker/query.rb @@ -15,10 +15,6 @@ def track_query_moved_event user, query, acase Analytics::GoogleAnalytics.user_moved_query user, query, acase end - def track_query_threshold_updated_event user, query - Analytics::GoogleAnalytics.user_updated_query_threshold user, query - end - def track_query_notes_updated_event user, query Analytics::GoogleAnalytics.user_updated_query_notes user, query end diff --git a/app/models/query.rb b/app/models/query.rb index e230a861a..ec30faec3 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -11,8 +11,6 @@ # notes :text(65535) # options :text(65535) # query_text :string(500) -# threshold :float(24) -# threshold_enbl :boolean # created_at :datetime not null # updated_at :datetime not null # case_id :integer diff --git a/app/views/api/v1/export/cases/_query.json.jbuilder b/app/views/api/v1/export/cases/_query.json.jbuilder index a120b12e9..26d09aebe 100644 --- a/app/views/api/v1/export/cases/_query.json.jbuilder +++ b/app/views/api/v1/export/cases/_query.json.jbuilder @@ -3,8 +3,6 @@ json.arranged_at query.arranged_at json.arranged_next query.arranged_next json.query_text query.query_text -json.threshold query.threshold -json.threshold_enbl query.threshold_enbl json.options query.options json.notes query.notes json.information_need query.information_need diff --git a/app/views/api/v1/queries/_query.json.jbuilder b/app/views/api/v1/queries/_query.json.jbuilder index cf9fbf6c4..bdbfc8ca4 100644 --- a/app/views/api/v1/queries/_query.json.jbuilder +++ b/app/views/api/v1/queries/_query.json.jbuilder @@ -4,8 +4,6 @@ json.arranged_at query.arranged_at json.arranged_next query.arranged_next json.query_id query.id json.query_text query.query_text -json.threshold query.threshold -json.threshold_enabled query.threshold_enbl json.options query.options json.notes query.notes json.information_need query.information_need diff --git a/app/views/api/v1/queries/thresholds/update.json.jbuilder b/app/views/api/v1/queries/thresholds/update.json.jbuilder deleted file mode 100644 index a2291a4f2..000000000 --- a/app/views/api/v1/queries/thresholds/update.json.jbuilder +++ /dev/null @@ -1,4 +0,0 @@ -# frozen_string_literal: true - -json.threshold_enabled @query.threshold_enbl || false -json.threshold @query.threshold diff --git a/app/views/books/edit.html.erb b/app/views/books/edit.html.erb index 1b0f3f326..137eb9dc6 100644 --- a/app/views/books/edit.html.erb +++ b/app/views/books/edit.html.erb @@ -98,15 +98,15 @@

<% end %> -

Delete Query Doc Pairs Below a Threshold

+

Delete Query Doc Pairs Below a Rank

- Did you populate your book too deeply? Discover you'll never finish rating them? Here you can delete query doc pairs below a certain position (rank). + Did you populate your book too deeply? Discover you'll never finish rating them? Here you can delete query doc pairs below a certain rank (position).

<%= form_for(@book, url: delete_query_doc_pairs_below_position_book_path(@book), method: :delete, data: { confirm: "Are you sure?" }) do |form| %>
<%= form.label :position, class: 'form-label' %> - <%= select_tag "position", options_for_select(@book.query_doc_pairs.distinct.pluck(:position).sort), required: true, prompt: "Please select threshold to delete below", class: 'form-control' %> + <%= select_tag "position", options_for_select(@book.query_doc_pairs.distinct.pluck(:position).sort), required: true, prompt: "Please select rank to delete below", class: 'form-control' %>

diff --git a/config/routes.rb b/config/routes.rb index f2765829c..3fa102e79 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -147,7 +147,6 @@ resource :notes, only: [ :show, :update ] resource :options, only: [ :show, :update ] resource :position, only: [ :update ] - resource :threshold, only: [ :update ] resource :ratings, only: [ :update, :destroy ] # not actually a singular resource, doc_id in json payload end diff --git a/db/migrate/20240121134401_drop_threshold_enbl_from_queries.rb b/db/migrate/20240121134401_drop_threshold_enbl_from_queries.rb new file mode 100644 index 000000000..c23059e90 --- /dev/null +++ b/db/migrate/20240121134401_drop_threshold_enbl_from_queries.rb @@ -0,0 +1,8 @@ +class DropThresholdEnblFromQueries < ActiveRecord::Migration[7.1] + # thresholds was a feature that was added in the early years of Quepid + # but has never taken off. Removing to simplify code base. + def change + remove_column :queries, :threshold_enbl + remove_column :queries, :threshold + end +end diff --git a/db/schema.rb b/db/schema.rb index dbf61ae2c..81743ad93 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_01_19_123605) do +ActiveRecord::Schema[7.1].define(version: 2024_01_21_134401) 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 @@ -156,8 +156,6 @@ t.bigint "arranged_at" t.string "query_text", limit: 500 t.text "notes" - t.float "threshold" - t.boolean "threshold_enbl" t.integer "case_id" t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false diff --git a/spec/javascripts/angular/services/queriesSvc_spec.js b/spec/javascripts/angular/services/queriesSvc_spec.js index 87b363528..2ba31b0a0 100644 --- a/spec/javascripts/angular/services/queriesSvc_spec.js +++ b/spec/javascripts/angular/services/queriesSvc_spec.js @@ -830,49 +830,6 @@ describe('Service: queriesSvc', function () { expect(bestDocs[1].id).toEqual('doc1'); }); - /** Threshold Testing **/ - describe('- Threshold Tests: ', function() { - var mockThresholdResponse = { - queryId: 1, - threshold: 20, - threshold_enabled: true - }; - var testQuery; - - beforeEach(function() { - setupQuerySvc(); - testQuery = queriesSvc.queries['0']; - }); - - it('Setting threshold on backend', function() { - $httpBackend.expectPUT('api/cases/2/queries/' + testQuery.queryId + '/threshold') - .respond(200, mockThresholdResponse); - var testNewThreshold = 20; - - testQuery.setThreshold(true, testNewThreshold) - .then(function() { - expect(testQuery.thresholdEnabled).toEqual(true); - expect(testQuery.threshold).toEqual(testNewThreshold); - }); - - $httpBackend.flush(); - }); - - it('Disabling threshold on backend', function() { - mockThresholdResponse.threshold_enabled = false; - - $httpBackend.expectPUT('api/cases/2/queries/' + testQuery.queryId + '/threshold') - .respond(200, mockThresholdResponse); - - testQuery.setThreshold(false) - .then(function() { - expect(testQuery.thresholdEnabled).toEqual(false); - }); - - $httpBackend.flush(); - }); - }); - describe('- Max Score Tests: ', function() { var explain1 = {'match':true,'value':1.0,'description':'weight(text:foo)'}; var explain2 = {'match':true,'value':2.0,'description':'weight(text:foo)'}; diff --git a/test/controllers/api/v1/import/cases_controller_test.rb b/test/controllers/api/v1/import/cases_controller_test.rb index 56b350121..9413cdeaa 100644 --- a/test/controllers/api/v1/import/cases_controller_test.rb +++ b/test/controllers/api/v1/import/cases_controller_test.rb @@ -24,26 +24,22 @@ class CasesControllerTest < ActionController::TestCase try: acase.tries.last.as_json, queries: [ { - arranged_at: 1, - arranged_next: nil, - query_text: 'First Query', - threshold: nil, - threshold_enabled: nil, - options: nil, - notes: nil, - information_need: 'I am the first query', - ratings: [], + arranged_at: 1, + arranged_next: nil, + query_text: 'First Query', + options: nil, + notes: nil, + information_need: 'I am the first query', + ratings: [], }, { - arranged_at: 2, - arranged_next: nil, - query_text: 'Second Query', - threshold: nil, - threshold_enabled: nil, - options: nil, - notes: nil, - information_need: 'I am the second query', - ratings: [ + arranged_at: 2, + arranged_next: nil, + query_text: 'Second Query', + options: nil, + notes: nil, + information_need: 'I am the second query', + ratings: [ { doc_id: 'docb', rating: 1.0, @@ -108,7 +104,7 @@ class CasesControllerTest < ActionController::TestCase kase.owner = user end - test 'creates a new book' do + test 'creates a new case' do data = { case_name: 'test case', owner_email: user.email, @@ -126,8 +122,6 @@ class CasesControllerTest < ActionController::TestCase arranged_at: 1, arranged_next: nil, query_text: 'First Query', - threshold: nil, - threshold_enbl: nil, options: nil, notes: nil, information_need: 'I am the first query', @@ -137,8 +131,6 @@ class CasesControllerTest < ActionController::TestCase arranged_at: 2, arranged_next: nil, query_text: 'Second Query', - threshold: nil, - threshold_enbl: nil, options: nil, notes: nil, information_need: 'I am the second query', diff --git a/test/controllers/api/v1/queries/thresholds_controller_test.rb b/test/controllers/api/v1/queries/thresholds_controller_test.rb deleted file mode 100644 index 03aad7ac3..000000000 --- a/test/controllers/api/v1/queries/thresholds_controller_test.rb +++ /dev/null @@ -1,67 +0,0 @@ -# frozen_string_literal: true - -require 'test_helper' - -module Api - module V1 - module Queries - class ThresholdsControllerTest < ActionController::TestCase - let(:user) { users(:random) } - let(:acase) { cases(:queries_case) } - let(:query) { queries(:first_query) } - - before do - @controller = Api::V1::Queries::ThresholdsController.new - - login_user user - end - - describe 'Updates query threshold' do - test 'sets the query threshold attribute' do - put :update, params: { case_id: acase.id, query_id: query.id, query: { threshold: 1 } } - - assert_response :ok - - data = response.parsed_body - - query.reload - assert_equal query.threshold, 1 - - assert_equal data['threshold'], 1 - assert_equal data['threshold_enabled'], false - end - - test 'sets the query threshold enabled flag' do - query.threshold = 1 - query.save - - put :update, params: { case_id: acase.id, query_id: query.id, query: { threshold_enbl: true } } - - assert_response :ok - - data = response.parsed_body - - query.reload - assert_equal query.threshold, 1 - assert_equal query.threshold_enbl, true - - assert_equal data['threshold'], 1 - assert_equal data['threshold_enabled'], true - end - - describe 'analytics' do - test 'posts event' do - expects_any_ga_event_call - - perform_enqueued_jobs do - put :update, params: { case_id: acase.id, query_id: query.id, query: { threshold: 1 } } - - assert_response :ok - end - end - end - end - end - end - end -end diff --git a/test/fixtures/queries.yml b/test/fixtures/queries.yml index 2d6dc56dc..744053e76 100644 --- a/test/fixtures/queries.yml +++ b/test/fixtures/queries.yml @@ -9,8 +9,6 @@ # notes :text(65535) # options :text(65535) # query_text :string(500) -# threshold :float(24) -# threshold_enbl :boolean # created_at :datetime not null # updated_at :datetime not null # case_id :integer diff --git a/test/models/query_test.rb b/test/models/query_test.rb index 9ec7c53e5..ccb6d0189 100644 --- a/test/models/query_test.rb +++ b/test/models/query_test.rb @@ -11,8 +11,6 @@ # notes :text(65535) # options :text(65535) # query_text :string(500) -# threshold :float(24) -# threshold_enbl :boolean # created_at :datetime not null # updated_at :datetime not null # case_id :integer