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

Constant Summary

Constants inherited from ControlledVocabularyTerm

ControlledVocabularyTerm::ALTERNATE_VALUES_FOR

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

find_for_autocomplete, #uri_relation_is_a_skos_relation

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from ActiverecordUtilities

#trim_attributes

Class Method Details

+ (Object) select_optimized(user_id, project_id, klass)



34
35
36
37
38
39
40
41
42
# File 'app/models/confidence_level.rb', line 34

def self.select_optimized(user_id, project_id, klass)
  h = {
    recent: ConfidenceLevel.where(project_id: project_id).used_on_klass(klass).used_recently.distinct.limit(10).to_a,
    pinboard:  ConfidenceLevel.pinned_by(user_id).where(project_id: project_id).to_a
  }

  h[:quick] = (ConfidenceLevel.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a + h[:recent][0..3]).uniq
  h
end

+ (Scope) used_recently

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

def self.used_recently
  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 ))
    .order(c['created_at'])
   
  # z is a table alias 
  z = i.as('recent_c')

  ConfidenceLevel.joins(
    Arel::Nodes::InnerJoin.new(z, Arel::Nodes::On.new(z['confidence_level_id'].eq(t['id'])))
  ).distinct.limit(10)
end

Instance Method Details

- (Object) confidenced_object_class_names



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

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

- (Object) confidenced_objects



26
27
28
# File 'app/models/confidence_level.rb', line 26

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