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

clone_from_project, #uri_relation_is_a_skos_relation

Methods included from SoftValidation

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

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

#attribute_updated, #attribute_updater

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:



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

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
27
# File 'app/models/confidence_level.rb', line 9

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

  # i is a select manager
  i = t.project(t['confidence_level_id'], t['updated_at']).from(t)
       .where(t['confidence_object_type'].eq(klass))
       .where(t['updated_at'].gt( 1.months.ago ))
       .where(t['updated_by_id'].eq(user_id))
       .where(t['project_id'].eq(project_id))
       .order(t['updated_at'].desc)

  # z is a table alias
  z = i.as('recent_t')

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

Instance Method Details

#confidenced_object_class_namesObject



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

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

#confidenced_objectsObject



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

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