Skip to content

Commit

Permalink
add a threshold of 5 before aggregated children in tree/graph view #2120
Browse files Browse the repository at this point in the history
  • Loading branch information
stuzart committed Jan 24, 2025
1 parent 7cc2cea commit 6262ecc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/seek/isa_graph_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def initialize(object, type, children)
end

class IsaGraphGenerator
MIN_AGGREGATED_CHILDREN = 5
def initialize(object)
@object = object
end
Expand Down Expand Up @@ -126,11 +127,15 @@ def traverse(method, object, max_depth = nil, depth = 0)
associations(object)[:aggregated_children].each do |type, method|
associations = resolve_association(object, method)
next unless associations.any?
agg = Seek::ObjectAggregation.new(object, type, associations)
agg_node = Seek::IsaGraphNode.new(agg)
agg_node.can_view = true
nodes << agg_node
edges << [object, agg]
if associations.count > MIN_AGGREGATED_CHILDREN
agg = Seek::ObjectAggregation.new(object, type, associations)
agg_node = Seek::IsaGraphNode.new(agg)
agg_node.can_view = true
nodes << agg_node
edges << [object, agg]
else
children |= associations
end
end
end

Expand Down
33 changes: 33 additions & 0 deletions test/unit/isa_graph_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,37 @@ class IsaGraphGeneratorTest < ActiveSupport::TestCase
assert_empty inv_pub_edges

end

test 'aggregated_children' do
assert_equal 5, Seek::IsaGraphGenerator::MIN_AGGREGATED_CHILDREN
person = FactoryBot.create(:person)
samples = FactoryBot.create_list(:sample, 6, contributor: person)
obs_unit = FactoryBot.create(:observation_unit, contributor: person, samples: samples)
assert_equal 6, obs_unit.samples.count

generator = Seek::IsaGraphGenerator.new(obs_unit)
result = generator.generate(parent_depth: nil)

assert_equal 3, result[:edges].count
assert_equal 1, result[:edges].select { |edge| edge[1].is_a?(Seek::ObjectAggregation) }.count
assert_equal 0, result[:edges].select { |edge| edge[1].is_a?(Sample) }.count
assert_equal 4, result[:nodes].count
assert_equal 1, result[:nodes].select { |node| node.object.is_a?(Seek::ObjectAggregation) }.count
assert_equal 0, result[:nodes].select { |node| node.object.is_a?(Sample) }.count

#below threshold
samples = FactoryBot.create_list(:sample, 5, contributor: person)
obs_unit = FactoryBot.create(:observation_unit, contributor: person, samples: samples)
assert_equal 5, obs_unit.samples.count

generator = Seek::IsaGraphGenerator.new(obs_unit)
result = generator.generate(parent_depth: nil)

assert_equal 7, result[:edges].count
assert_equal 0, result[:edges].select { |edge| edge[1].is_a?(Seek::ObjectAggregation) }.count
assert_equal 5, result[:edges].select { |edge| edge[1].is_a?(Sample) }.count
assert_equal 8, result[:nodes].count
assert_equal 0, result[:nodes].select { |node| node.object.is_a?(Seek::ObjectAggregation) }.count
assert_equal 5, result[:nodes].select { |node| node.object.is_a?(Sample) }.count
end
end

0 comments on commit 6262ecc

Please sign in to comment.