Class: GeoTreeModule::TreeStats

Inherits:
Object
  • Object
show all
Defined in:
lib/geotree/geotree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTreeStats

Returns a new instance of TreeStats.



806
807
808
809
810
811
812
813
# File 'lib/geotree/geotree.rb', line 806

def initialize
  @leaf_count = 0
  @interior_count = 0
  @overflow_count = 0
  @leaf_used_sum = 0
  @leaf_depth_sum = 0
  @leaf_depth_max = 0
end

Instance Attribute Details

#interior_countObject

Returns the value of attribute interior_count.



805
806
807
# File 'lib/geotree/geotree.rb', line 805

def interior_count
  @interior_count
end

#leaf_countObject

Returns the value of attribute leaf_count.



805
806
807
# File 'lib/geotree/geotree.rb', line 805

def leaf_count
  @leaf_count
end

#leaf_depth_maxObject

Returns the value of attribute leaf_depth_max.



805
806
807
# File 'lib/geotree/geotree.rb', line 805

def leaf_depth_max
  @leaf_depth_max
end

#overflow_countObject

Returns the value of attribute overflow_count.



805
806
807
# File 'lib/geotree/geotree.rb', line 805

def overflow_count
  @overflow_count
end

Instance Method Details

#process_node(n, overflow, depth) ⇒ Object



815
816
817
818
819
820
821
822
823
824
825
826
827
# File 'lib/geotree/geotree.rb', line 815

def process_node(n, overflow, depth)
  if n.leaf
    @leaf_count += 1
    @leaf_used_sum += n.used
    @leaf_depth_sum += depth
    if overflow
      @overflow_count += 1
    end
    @leaf_depth_max = [@leaf_depth_max,depth].max
  else
    @interior_count += 1
  end
end

#summaryObject



829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
# File 'lib/geotree/geotree.rb', line 829

def summary
  s = {}
  s['leaf_nodes'] = leaf_count
  s['interior_nodes'] = interior_count
  s['overflow_nodes'] = overflow_count
  leaf_usage = 0
  if (leaf_count > 0)
    leaf_usage = (@leaf_used_sum / @leaf_count.to_f) / NODEL_CAPACITY
  end
  s['leaf_usage'] = leaf_usage
  avg_depth = 0
  if @leaf_count > 0
    avg_depth = @leaf_depth_sum / @leaf_count.to_f
  end
  s['leaf_depth (avg)'] = avg_depth
  s['leaf_depth (max)'] = leaf_depth_max
  s
end