Class: ConfidenceLevel

Inherits:
ControlledVocabularyTerm show all
Defined in:
app/models/confidence_level.rb

Overview

A user-defined level of data quality vi Confidences.

Constant Summary

Constants inherited from ControlledVocabularyTerm

ControlledVocabularyTerm::ALTERNATE_VALUES_FOR

Constants included from SoftValidation

SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS

Instance Attribute Summary

Attributes inherited from ControlledVocabularyTerm

#definition, #name, #project_id, #type, #uri, #uri_relation

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ControlledVocabularyTerm

#uri_relation_is_a_skos_relation

Methods included from SoftValidation

#clear_soft_validations, #fix_soft_validations, #soft_fixed?, #soft_valid?, #soft_validate, #soft_validated?, #soft_validations

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::AlternateValues

#all_values_for, #alternate_valued?

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods inherited from ApplicationRecord

transaction_with_retry

Class Method Details

.select_optimized(user_id, project_id, klass) ⇒ Object

Parameters:

  • klass (like CollectionObject)

    required



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/confidence_level.rb', line 37

def self.select_optimized(user_id, project_id, klass)
  r = used_recently(user_id, project_id, klass)
  h = {
      quick: [],
      pinboard: ConfidenceLevel.pinned_by(user_id).where(project_id: project_id).to_a,
      recent: []
  }

  if r.empty?
    h[:quick] = ConfidenceLevel.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a
  else
    h[:recent] = ConfidenceLevel.where('"controlled_vocabulary_terms"."id" IN (?)', r.first(10) ).order(:name).to_a
    h[:quick] = (ConfidenceLevel.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a +
        ConfidenceLevel.where('"controlled_vocabulary_terms"."id" IN (?)', r.first(4) ).order(:name).to_a).uniq
  end

  h
end

.used_recently(user_id, project_id, klass) ⇒ Scope

Returns the max 10 most recently used confidence levels

Returns:

  • (Scope)

    the max 10 most recently used confidence levels



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/confidence_level.rb', line 9

def self.used_recently(user_id, project_id, klass)
  t = ConfidenceLevel.arel_table 
  c = Confidence.arel_table

  # i is a select manager
  i = c.project(c['confidence_level_id'], c['created_at']).from(c)
    .where(c['created_at'].gt( 1.weeks.ago ))
    .where(c['created_by_id'].eq(user_id))
    .where(c['project_id'].eq(project_id))
    .order(c['created_at'].desc)
   
  # z is a table alias 
  z = i.as('recent_c')

  ConfidenceLevel.used_on_klass(klass).joins(
    Arel::Nodes::InnerJoin.new(z, Arel::Nodes::On.new(z['confidence_level_id'].eq(t['id'])))
  ).pluck(:id).uniq
end

Instance Method Details

#confidenced_object_class_namesObject



32
33
34
# File 'app/models/confidence_level.rb', line 32

def confidenced_object_class_names
  Confidence.where(confidence_level: self).pluck(:confidence_object_type)
end

#confidenced_objectsObject



28
29
30
# File 'app/models/confidence_level.rb', line 28

def confidenced_objects
  confidences.collect{|c| c.confidence_object}
end