Class: Confidence
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Confidence
- Defined in:
- app/models/confidence.rb
Overview
A Confidence is an annotation that links a user-defined confidence level to a data object. It is an assertion as to the quality of that data.
Instance Attribute Summary collapse
-
#confidence_level_id ⇒ Integer
The controlled vocabulary term used in the confidence.
-
#confidence_object_id ⇒ Integer
Rails polymorphic.
-
#confidence_object_type ⇒ String
Rails polymorphic.
-
#position ⇒ Integer
A user definable sort code on the tags on an object, handled by acts_as_list.
-
#project_id ⇒ Integer
the project ID.
Class Method Summary collapse
- .batch_by_filter_scope(filter_query: nil, confidence_level_id: nil, replace_confidence_level_id: nil, mode: :add, async_cutoff: 300, project_id: nil, user_id: nil) ⇒ Object
- .exists?(global_id, confidence_level_id, project_id) ⇒ Boolean
Methods included from Shared::PolymorphicAnnotator
#annotated_object_is_persisted?
Methods included from Shared::IsData
#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar
Methods included from Shared::Citations
#cited?, #mark_citations_for_destruction, #nomenclature_date, #origin_citation_source_id, #reject_citations, #requires_citation?, #sources_by_topic_id
Methods included from Housekeeping
#has_polymorphic_relationship?
Methods inherited from ApplicationRecord
Instance Attribute Details
#confidence_level_id ⇒ Integer
Returns the controlled vocabulary term used in the confidence.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/models/confidence.rb', line 24 class Confidence < ApplicationRecord include Housekeeping include Shared::Citations include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates(:confidence_object) acts_as_list scope: [:confidence_object_id, :confidence_object_type, :project_id] belongs_to :confidence_level, inverse_of: :confidences, validate: true belongs_to :controlled_vocabulary_term, foreign_key: :confidence_level_id, inverse_of: :confidences validates :confidence_level, presence: true validates_uniqueness_of :confidence_level_id, scope: [:confidence_object_id, :confidence_object_type] accepts_nested_attributes_for :confidence_level, allow_destroy: true def self.exists?(global_id, confidence_level_id, project_id) o = GlobalID::Locator.locate(global_id) return false unless o Confidence.where(project_id: project_id, confidence_object: o, confidence_level_id: confidence_level_id).first end def self.batch_by_filter_scope(filter_query: nil, confidence_level_id: nil, replace_confidence_level_id: nil, mode: :add, async_cutoff: 300, project_id: nil, user_id: nil) r = ::BatchResponse.new( preview: false, method: 'Confidence batch_by_filter_scope', ) if filter_query.nil? r.errors['scoping filter not provided'] = 1 return r end b = ::Queries::Query::Filter.instantiated_base_filter(filter_query) q = b.all(true) fq = ::Queries::Query::Filter.base_query_to_h(filter_query) r.klass = b.referenced_klass.name if b.only_project? r.total_attempted = 0 r.errors['can not update records without at least one filter parameter'] = 1 return r else c = q.count async = c > async_cutoff ? true : false r.total_attempted = c r.async = async end case mode.to_sym when :replace # TODO: Return response if replace_confidence_level_id.nil? r.errors['no replacement confidence level provided'] = 1 return r.to_json end if async ConfidenceBatchJob.perform_later( filter_query: fq, confidence_level_id:, replace_confidence_level_id:, mode: :replace, project_id:, user_id:, ) else Confidence .where( confidence_object_id: q.pluck(:id), confidence_object_type: b.referenced_klass.base_class.name, confidence_level_id: replace_confidence_level_id ).find_each do |o| o.update(confidence_level_id:) end end when :remove # Just delete, async or not Confidence .where( confidence_object_id: q.pluck(:id), confidence_object_type: b.referenced_klass.name ).delete_all when :add if async ConfidenceBatchJob.perform_later( filter_query: fq, confidence_level_id:, replace_confidence_level_id:, mode: :add, project_id:, user_id:, ) else q.find_each do |o| Confidence.create(confidence_object: o, confidence_level_id:) end end end return r.to_json end end |
#confidence_object_id ⇒ Integer
Returns Rails polymorphic. The id of of the object being annotated.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/models/confidence.rb', line 24 class Confidence < ApplicationRecord include Housekeeping include Shared::Citations include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates(:confidence_object) acts_as_list scope: [:confidence_object_id, :confidence_object_type, :project_id] belongs_to :confidence_level, inverse_of: :confidences, validate: true belongs_to :controlled_vocabulary_term, foreign_key: :confidence_level_id, inverse_of: :confidences validates :confidence_level, presence: true validates_uniqueness_of :confidence_level_id, scope: [:confidence_object_id, :confidence_object_type] accepts_nested_attributes_for :confidence_level, allow_destroy: true def self.exists?(global_id, confidence_level_id, project_id) o = GlobalID::Locator.locate(global_id) return false unless o Confidence.where(project_id: project_id, confidence_object: o, confidence_level_id: confidence_level_id).first end def self.batch_by_filter_scope(filter_query: nil, confidence_level_id: nil, replace_confidence_level_id: nil, mode: :add, async_cutoff: 300, project_id: nil, user_id: nil) r = ::BatchResponse.new( preview: false, method: 'Confidence batch_by_filter_scope', ) if filter_query.nil? r.errors['scoping filter not provided'] = 1 return r end b = ::Queries::Query::Filter.instantiated_base_filter(filter_query) q = b.all(true) fq = ::Queries::Query::Filter.base_query_to_h(filter_query) r.klass = b.referenced_klass.name if b.only_project? r.total_attempted = 0 r.errors['can not update records without at least one filter parameter'] = 1 return r else c = q.count async = c > async_cutoff ? true : false r.total_attempted = c r.async = async end case mode.to_sym when :replace # TODO: Return response if replace_confidence_level_id.nil? r.errors['no replacement confidence level provided'] = 1 return r.to_json end if async ConfidenceBatchJob.perform_later( filter_query: fq, confidence_level_id:, replace_confidence_level_id:, mode: :replace, project_id:, user_id:, ) else Confidence .where( confidence_object_id: q.pluck(:id), confidence_object_type: b.referenced_klass.base_class.name, confidence_level_id: replace_confidence_level_id ).find_each do |o| o.update(confidence_level_id:) end end when :remove # Just delete, async or not Confidence .where( confidence_object_id: q.pluck(:id), confidence_object_type: b.referenced_klass.name ).delete_all when :add if async ConfidenceBatchJob.perform_later( filter_query: fq, confidence_level_id:, replace_confidence_level_id:, mode: :add, project_id:, user_id:, ) else q.find_each do |o| Confidence.create(confidence_object: o, confidence_level_id:) end end end return r.to_json end end |
#confidence_object_type ⇒ String
Returns Rails polymorphic. The type of the object being annotated.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/models/confidence.rb', line 24 class Confidence < ApplicationRecord include Housekeeping include Shared::Citations include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates(:confidence_object) acts_as_list scope: [:confidence_object_id, :confidence_object_type, :project_id] belongs_to :confidence_level, inverse_of: :confidences, validate: true belongs_to :controlled_vocabulary_term, foreign_key: :confidence_level_id, inverse_of: :confidences validates :confidence_level, presence: true validates_uniqueness_of :confidence_level_id, scope: [:confidence_object_id, :confidence_object_type] accepts_nested_attributes_for :confidence_level, allow_destroy: true def self.exists?(global_id, confidence_level_id, project_id) o = GlobalID::Locator.locate(global_id) return false unless o Confidence.where(project_id: project_id, confidence_object: o, confidence_level_id: confidence_level_id).first end def self.batch_by_filter_scope(filter_query: nil, confidence_level_id: nil, replace_confidence_level_id: nil, mode: :add, async_cutoff: 300, project_id: nil, user_id: nil) r = ::BatchResponse.new( preview: false, method: 'Confidence batch_by_filter_scope', ) if filter_query.nil? r.errors['scoping filter not provided'] = 1 return r end b = ::Queries::Query::Filter.instantiated_base_filter(filter_query) q = b.all(true) fq = ::Queries::Query::Filter.base_query_to_h(filter_query) r.klass = b.referenced_klass.name if b.only_project? r.total_attempted = 0 r.errors['can not update records without at least one filter parameter'] = 1 return r else c = q.count async = c > async_cutoff ? true : false r.total_attempted = c r.async = async end case mode.to_sym when :replace # TODO: Return response if replace_confidence_level_id.nil? r.errors['no replacement confidence level provided'] = 1 return r.to_json end if async ConfidenceBatchJob.perform_later( filter_query: fq, confidence_level_id:, replace_confidence_level_id:, mode: :replace, project_id:, user_id:, ) else Confidence .where( confidence_object_id: q.pluck(:id), confidence_object_type: b.referenced_klass.base_class.name, confidence_level_id: replace_confidence_level_id ).find_each do |o| o.update(confidence_level_id:) end end when :remove # Just delete, async or not Confidence .where( confidence_object_id: q.pluck(:id), confidence_object_type: b.referenced_klass.name ).delete_all when :add if async ConfidenceBatchJob.perform_later( filter_query: fq, confidence_level_id:, replace_confidence_level_id:, mode: :add, project_id:, user_id:, ) else q.find_each do |o| Confidence.create(confidence_object: o, confidence_level_id:) end end end return r.to_json end end |
#position ⇒ Integer
Returns a user definable sort code on the tags on an object, handled by acts_as_list.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/models/confidence.rb', line 24 class Confidence < ApplicationRecord include Housekeeping include Shared::Citations include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates(:confidence_object) acts_as_list scope: [:confidence_object_id, :confidence_object_type, :project_id] belongs_to :confidence_level, inverse_of: :confidences, validate: true belongs_to :controlled_vocabulary_term, foreign_key: :confidence_level_id, inverse_of: :confidences validates :confidence_level, presence: true validates_uniqueness_of :confidence_level_id, scope: [:confidence_object_id, :confidence_object_type] accepts_nested_attributes_for :confidence_level, allow_destroy: true def self.exists?(global_id, confidence_level_id, project_id) o = GlobalID::Locator.locate(global_id) return false unless o Confidence.where(project_id: project_id, confidence_object: o, confidence_level_id: confidence_level_id).first end def self.batch_by_filter_scope(filter_query: nil, confidence_level_id: nil, replace_confidence_level_id: nil, mode: :add, async_cutoff: 300, project_id: nil, user_id: nil) r = ::BatchResponse.new( preview: false, method: 'Confidence batch_by_filter_scope', ) if filter_query.nil? r.errors['scoping filter not provided'] = 1 return r end b = ::Queries::Query::Filter.instantiated_base_filter(filter_query) q = b.all(true) fq = ::Queries::Query::Filter.base_query_to_h(filter_query) r.klass = b.referenced_klass.name if b.only_project? r.total_attempted = 0 r.errors['can not update records without at least one filter parameter'] = 1 return r else c = q.count async = c > async_cutoff ? true : false r.total_attempted = c r.async = async end case mode.to_sym when :replace # TODO: Return response if replace_confidence_level_id.nil? r.errors['no replacement confidence level provided'] = 1 return r.to_json end if async ConfidenceBatchJob.perform_later( filter_query: fq, confidence_level_id:, replace_confidence_level_id:, mode: :replace, project_id:, user_id:, ) else Confidence .where( confidence_object_id: q.pluck(:id), confidence_object_type: b.referenced_klass.base_class.name, confidence_level_id: replace_confidence_level_id ).find_each do |o| o.update(confidence_level_id:) end end when :remove # Just delete, async or not Confidence .where( confidence_object_id: q.pluck(:id), confidence_object_type: b.referenced_klass.name ).delete_all when :add if async ConfidenceBatchJob.perform_later( filter_query: fq, confidence_level_id:, replace_confidence_level_id:, mode: :add, project_id:, user_id:, ) else q.find_each do |o| Confidence.create(confidence_object: o, confidence_level_id:) end end end return r.to_json end end |
#project_id ⇒ Integer
the project ID
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/models/confidence.rb', line 24 class Confidence < ApplicationRecord include Housekeeping include Shared::Citations include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates(:confidence_object) acts_as_list scope: [:confidence_object_id, :confidence_object_type, :project_id] belongs_to :confidence_level, inverse_of: :confidences, validate: true belongs_to :controlled_vocabulary_term, foreign_key: :confidence_level_id, inverse_of: :confidences validates :confidence_level, presence: true validates_uniqueness_of :confidence_level_id, scope: [:confidence_object_id, :confidence_object_type] accepts_nested_attributes_for :confidence_level, allow_destroy: true def self.exists?(global_id, confidence_level_id, project_id) o = GlobalID::Locator.locate(global_id) return false unless o Confidence.where(project_id: project_id, confidence_object: o, confidence_level_id: confidence_level_id).first end def self.batch_by_filter_scope(filter_query: nil, confidence_level_id: nil, replace_confidence_level_id: nil, mode: :add, async_cutoff: 300, project_id: nil, user_id: nil) r = ::BatchResponse.new( preview: false, method: 'Confidence batch_by_filter_scope', ) if filter_query.nil? r.errors['scoping filter not provided'] = 1 return r end b = ::Queries::Query::Filter.instantiated_base_filter(filter_query) q = b.all(true) fq = ::Queries::Query::Filter.base_query_to_h(filter_query) r.klass = b.referenced_klass.name if b.only_project? r.total_attempted = 0 r.errors['can not update records without at least one filter parameter'] = 1 return r else c = q.count async = c > async_cutoff ? true : false r.total_attempted = c r.async = async end case mode.to_sym when :replace # TODO: Return response if replace_confidence_level_id.nil? r.errors['no replacement confidence level provided'] = 1 return r.to_json end if async ConfidenceBatchJob.perform_later( filter_query: fq, confidence_level_id:, replace_confidence_level_id:, mode: :replace, project_id:, user_id:, ) else Confidence .where( confidence_object_id: q.pluck(:id), confidence_object_type: b.referenced_klass.base_class.name, confidence_level_id: replace_confidence_level_id ).find_each do |o| o.update(confidence_level_id:) end end when :remove # Just delete, async or not Confidence .where( confidence_object_id: q.pluck(:id), confidence_object_type: b.referenced_klass.name ).delete_all when :add if async ConfidenceBatchJob.perform_later( filter_query: fq, confidence_level_id:, replace_confidence_level_id:, mode: :add, project_id:, user_id:, ) else q.find_each do |o| Confidence.create(confidence_object: o, confidence_level_id:) end end end return r.to_json end end |
Class Method Details
.batch_by_filter_scope(filter_query: nil, confidence_level_id: nil, replace_confidence_level_id: nil, mode: :add, async_cutoff: 300, project_id: nil, user_id: nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/models/confidence.rb', line 47 def self.batch_by_filter_scope(filter_query: nil, confidence_level_id: nil, replace_confidence_level_id: nil, mode: :add, async_cutoff: 300, project_id: nil, user_id: nil) r = ::BatchResponse.new( preview: false, method: 'Confidence batch_by_filter_scope', ) if filter_query.nil? r.errors['scoping filter not provided'] = 1 return r end b = ::Queries::Query::Filter.instantiated_base_filter(filter_query) q = b.all(true) fq = ::Queries::Query::Filter.base_query_to_h(filter_query) r.klass = b.referenced_klass.name if b.only_project? r.total_attempted = 0 r.errors['can not update records without at least one filter parameter'] = 1 return r else c = q.count async = c > async_cutoff ? true : false r.total_attempted = c r.async = async end case mode.to_sym when :replace # TODO: Return response if replace_confidence_level_id.nil? r.errors['no replacement confidence level provided'] = 1 return r.to_json end if async ConfidenceBatchJob.perform_later( filter_query: fq, confidence_level_id:, replace_confidence_level_id:, mode: :replace, project_id:, user_id:, ) else Confidence .where( confidence_object_id: q.pluck(:id), confidence_object_type: b.referenced_klass.base_class.name, confidence_level_id: replace_confidence_level_id ).find_each do |o| o.update(confidence_level_id:) end end when :remove # Just delete, async or not Confidence .where( confidence_object_id: q.pluck(:id), confidence_object_type: b.referenced_klass.name ).delete_all when :add if async ConfidenceBatchJob.perform_later( filter_query: fq, confidence_level_id:, replace_confidence_level_id:, mode: :add, project_id:, user_id:, ) else q.find_each do |o| Confidence.create(confidence_object: o, confidence_level_id:) end end end return r.to_json end |
.exists?(global_id, confidence_level_id, project_id) ⇒ Boolean
41 42 43 44 45 |
# File 'app/models/confidence.rb', line 41 def self.exists?(global_id, confidence_level_id, project_id) o = GlobalID::Locator.locate(global_id) return false unless o Confidence.where(project_id: project_id, confidence_object: o, confidence_level_id: confidence_level_id).first end |