Class: BiologicalAssociationsGraph
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- BiologicalAssociationsGraph
- Includes:
- Housekeeping, Shared::AssertedDistributions, Shared::Citations, Shared::Identifiers, Shared::IsData, Shared::Notes, Shared::Tags
- Defined in:
- app/models/biological_associations_graph.rb
Overview
A biological associations graph is a collection of BiologicalAssociations. For example, a citable foodweb.
Constant Summary collapse
- GRAPH_ENTRY_POINTS =
[:asserted_distributions].freeze
Instance Attribute Summary collapse
-
#graph ⇒ Json
A layout for the graph.
-
#name ⇒ String
The name of the graph.
-
#project_id ⇒ Integer
the project ID.
Class Method Summary collapse
- .select_optimized(user_id, project_id, klass) ⇒ Object
-
.used_recently(user_id, project_id, used_on) ⇒ Scope
The max 10 most recently used.
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::Identifiers
#dwc_occurrence_id, #identified?, #next_by_identifier, #previous_by_identifier, #reject_identifiers, #uri, #uuid
Methods included from Shared::Tags
#reject_tags, #tag_with, #tagged?, #tagged_with?
Methods included from Shared::Notes
#concatenated_notes_string, #reject_notes
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
#graph ⇒ Json
Returns a layout for the graph.
15 16 17 18 19 20 21 22 23 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 |
# File 'app/models/biological_associations_graph.rb', line 15 class BiologicalAssociationsGraph < ApplicationRecord include Housekeeping include Shared::Citations include Shared::Notes include Shared::Tags include Shared::Identifiers include Shared::AssertedDistributions include Shared::IsData GRAPH_ENTRY_POINTS = [:asserted_distributions].freeze has_many :biological_associations_biological_associations_graphs, inverse_of: :biological_associations_graph, dependent: :delete_all has_many :biological_associations, through: :biological_associations_biological_associations_graphs accepts_nested_attributes_for :biological_associations_biological_associations_graphs, allow_destroy: true # @return [Scope] # the max 10 most recently used def self.used_recently(user_id, project_id, used_on) t = case used_on when 'AssertedDistribution' AssertedDistribution.arel_table else return BiologicalAssociationsGraph.none end # i is a select manager i = case used_on when 'AssertedDistribution' t.project(t['asserted_distribution_object_id'], t['updated_at']).from(t) .where( t['updated_at'].gt(1.week.ago).and( t['asserted_distribution_object_type'].eq('BiologicalAssociationsGraph') ) ) .where(t['updated_by_id'].eq(user_id)) .where(t['project_id'].eq(project_id)) .order(t['updated_at'].desc) end z = i.as('recent_t') p = BiologicalAssociationsGraph.arel_table case used_on when 'AssertedDistribution' BiologicalAssociationsGraph.joins( Arel::Nodes::InnerJoin.new(z, Arel::Nodes::On.new(z['asserted_distribution_object_id'].eq(p['id']))) ).pluck(:id).uniq end end def self.select_optimized(user_id, project_id, klass) r = used_recently(user_id, project_id, klass) h = { quick: [], pinboard: BiologicalAssociationsGraph.pinned_by(user_id).where(project_id: project_id).to_a, recent: [] } if r.empty? h[:quick] = BiologicalAssociationsGraph.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a else h[:recent] = BiologicalAssociationsGraph.where('"biological_associations_graphs"."id" IN (?)', r.first(10) ).order(updated_at: :desc).to_a h[:quick] = (BiologicalAssociationsGraph.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a + BiologicalAssociationsGraph.where('"biological_associations_graphs"."id" IN (?)', r.first(4) ).order(updated_at: :desc).to_a).uniq end h end end |
#name ⇒ String
Returns the name of the graph.
15 16 17 18 19 20 21 22 23 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 |
# File 'app/models/biological_associations_graph.rb', line 15 class BiologicalAssociationsGraph < ApplicationRecord include Housekeeping include Shared::Citations include Shared::Notes include Shared::Tags include Shared::Identifiers include Shared::AssertedDistributions include Shared::IsData GRAPH_ENTRY_POINTS = [:asserted_distributions].freeze has_many :biological_associations_biological_associations_graphs, inverse_of: :biological_associations_graph, dependent: :delete_all has_many :biological_associations, through: :biological_associations_biological_associations_graphs accepts_nested_attributes_for :biological_associations_biological_associations_graphs, allow_destroy: true # @return [Scope] # the max 10 most recently used def self.used_recently(user_id, project_id, used_on) t = case used_on when 'AssertedDistribution' AssertedDistribution.arel_table else return BiologicalAssociationsGraph.none end # i is a select manager i = case used_on when 'AssertedDistribution' t.project(t['asserted_distribution_object_id'], t['updated_at']).from(t) .where( t['updated_at'].gt(1.week.ago).and( t['asserted_distribution_object_type'].eq('BiologicalAssociationsGraph') ) ) .where(t['updated_by_id'].eq(user_id)) .where(t['project_id'].eq(project_id)) .order(t['updated_at'].desc) end z = i.as('recent_t') p = BiologicalAssociationsGraph.arel_table case used_on when 'AssertedDistribution' BiologicalAssociationsGraph.joins( Arel::Nodes::InnerJoin.new(z, Arel::Nodes::On.new(z['asserted_distribution_object_id'].eq(p['id']))) ).pluck(:id).uniq end end def self.select_optimized(user_id, project_id, klass) r = used_recently(user_id, project_id, klass) h = { quick: [], pinboard: BiologicalAssociationsGraph.pinned_by(user_id).where(project_id: project_id).to_a, recent: [] } if r.empty? h[:quick] = BiologicalAssociationsGraph.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a else h[:recent] = BiologicalAssociationsGraph.where('"biological_associations_graphs"."id" IN (?)', r.first(10) ).order(updated_at: :desc).to_a h[:quick] = (BiologicalAssociationsGraph.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a + BiologicalAssociationsGraph.where('"biological_associations_graphs"."id" IN (?)', r.first(4) ).order(updated_at: :desc).to_a).uniq end h end end |
#project_id ⇒ Integer
the project ID
15 16 17 18 19 20 21 22 23 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 |
# File 'app/models/biological_associations_graph.rb', line 15 class BiologicalAssociationsGraph < ApplicationRecord include Housekeeping include Shared::Citations include Shared::Notes include Shared::Tags include Shared::Identifiers include Shared::AssertedDistributions include Shared::IsData GRAPH_ENTRY_POINTS = [:asserted_distributions].freeze has_many :biological_associations_biological_associations_graphs, inverse_of: :biological_associations_graph, dependent: :delete_all has_many :biological_associations, through: :biological_associations_biological_associations_graphs accepts_nested_attributes_for :biological_associations_biological_associations_graphs, allow_destroy: true # @return [Scope] # the max 10 most recently used def self.used_recently(user_id, project_id, used_on) t = case used_on when 'AssertedDistribution' AssertedDistribution.arel_table else return BiologicalAssociationsGraph.none end # i is a select manager i = case used_on when 'AssertedDistribution' t.project(t['asserted_distribution_object_id'], t['updated_at']).from(t) .where( t['updated_at'].gt(1.week.ago).and( t['asserted_distribution_object_type'].eq('BiologicalAssociationsGraph') ) ) .where(t['updated_by_id'].eq(user_id)) .where(t['project_id'].eq(project_id)) .order(t['updated_at'].desc) end z = i.as('recent_t') p = BiologicalAssociationsGraph.arel_table case used_on when 'AssertedDistribution' BiologicalAssociationsGraph.joins( Arel::Nodes::InnerJoin.new(z, Arel::Nodes::On.new(z['asserted_distribution_object_id'].eq(p['id']))) ).pluck(:id).uniq end end def self.select_optimized(user_id, project_id, klass) r = used_recently(user_id, project_id, klass) h = { quick: [], pinboard: BiologicalAssociationsGraph.pinned_by(user_id).where(project_id: project_id).to_a, recent: [] } if r.empty? h[:quick] = BiologicalAssociationsGraph.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a else h[:recent] = BiologicalAssociationsGraph.where('"biological_associations_graphs"."id" IN (?)', r.first(10) ).order(updated_at: :desc).to_a h[:quick] = (BiologicalAssociationsGraph.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a + BiologicalAssociationsGraph.where('"biological_associations_graphs"."id" IN (?)', r.first(4) ).order(updated_at: :desc).to_a).uniq end h end end |
Class Method Details
.select_optimized(user_id, project_id, klass) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/models/biological_associations_graph.rb', line 66 def self.select_optimized(user_id, project_id, klass) r = used_recently(user_id, project_id, klass) h = { quick: [], pinboard: BiologicalAssociationsGraph.pinned_by(user_id).where(project_id: project_id).to_a, recent: [] } if r.empty? h[:quick] = BiologicalAssociationsGraph.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a else h[:recent] = BiologicalAssociationsGraph.where('"biological_associations_graphs"."id" IN (?)', r.first(10) ).order(updated_at: :desc).to_a h[:quick] = (BiologicalAssociationsGraph.pinned_by(user_id).pinboard_inserted.where(project_id: project_id).to_a + BiologicalAssociationsGraph.where('"biological_associations_graphs"."id" IN (?)', r.first(4) ).order(updated_at: :desc).to_a).uniq end h end |
.used_recently(user_id, project_id, used_on) ⇒ Scope
Returns the max 10 most recently used.
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 |
# File 'app/models/biological_associations_graph.rb', line 33 def self.used_recently(user_id, project_id, used_on) t = case used_on when 'AssertedDistribution' AssertedDistribution.arel_table else return BiologicalAssociationsGraph.none end # i is a select manager i = case used_on when 'AssertedDistribution' t.project(t['asserted_distribution_object_id'], t['updated_at']).from(t) .where( t['updated_at'].gt(1.week.ago).and( t['asserted_distribution_object_type'].eq('BiologicalAssociationsGraph') ) ) .where(t['updated_by_id'].eq(user_id)) .where(t['project_id'].eq(project_id)) .order(t['updated_at'].desc) end z = i.as('recent_t') p = BiologicalAssociationsGraph.arel_table case used_on when 'AssertedDistribution' BiologicalAssociationsGraph.joins( Arel::Nodes::InnerJoin.new(z, Arel::Nodes::On.new(z['asserted_distribution_object_id'].eq(p['id']))) ).pluck(:id).uniq end end |