lib/fertile_forest/modules/reconstructers.rb
#
# Normalize ff_depth fields in ordered grove.
#
# @param  grove_id [Integer|nil] Grove ID to find.
# @return [Boolean] true: Success.
# @return [Boolean] false: Failure.
#
Normalize ff_depth fields in ordered grove.
Normalize ff_depth fields in ordered grove .
def normalize_depth(grove_id = nil)
            transaction do
              return false if has_grove? && grove_id.blank?
              feature_key = 'ff_is_fault'
              columns = [
                "@compare_depth + 1 < (@compare_depth := ff_depth) AS #{feature_key}",
              ]
              ffqq = arel_table[@_ff_queue]
              ffdd = arel_table[@_ff_depth]
              aim_query = ff_required_columns_scope(columns)
                  .ff_usual_order_scope()
                  .ff_usual_conditions_scope(grove_id)
                  .having(feature_key)
                  .limit(1000)
              ff_raw_query("SET @compare_depth = #{ROOT_DEPTH}")
              depth_offset_values = []
              aim_query.all.each do |node|
                prev_node = ff_get_previous_node(node)
                next if prev_node.blank?
                offset = node.ff_depth - prev_node.ff_depth - 1;
                top_queue = prev_node.ff_queue
                top_depth = prev_node.ff_depth
                top_grove = prev_node.ff_grove if has_grove?
                new_node = prev_node.clone
                depth_offets = [];
                (1 .. offset).each do |o|
                  new_node.ff_depth = top_depth + o
                  depth_offets << ff_get_boundary_queue(new_node)
                end
                grove_condition = has_grove? ? "#{@_ff_grove} = #{top_grove} AND" : '';
                depth_offets.each do |boundary_queue|
                  boundary_condition = boundary_queue.blank? \
                      ? ''
                      : "AND ff_queue < #{boundary_queue}"
                  depth_offset_values << "(CASE WHEN #{grove_condition} #{top_queue} < ff_queue #{boundary_condition} THEN 1 ELSE 0 END)"
                end
              end
              return false if depth_offset_values.blank?
              update_query = ff_usual_conditions_scope(grove_id)
              update_rows = update_query.update_all(
                  "#{@_ff_depth} = #{@_ff_depth} - " + depth_offset_values.join('-')
              )
              0 < update_rows.to_i
            end
          end
def normalize_depth ( grove_id = nil ) transaction do return false if has_grove? && grove_id . blank? feature_key = 'ff_is_fault' columns = [ "@compare_depth + 1 < (@compare_depth := ff_depth) AS #{feature_key}" , ] ffqq = arel_table [ @_ff_queue ] ffdd = arel_table [ @_ff_depth ] aim_query = ff_required_columns_scope ( columns ) . ff_usual_order_scope ( ) . ff_usual_conditions_scope ( grove_id ) . having ( feature_key ) . limit ( 1000 ) ff_raw_query ( "SET @compare_depth = #{ROOT_DEPTH}" ) depth_offset_values = [ ] aim_query . all . each do | node | prev_node = ff_get_previous_node ( node ) next if prev_node . blank? offset = node . ff_depth - prev_node . ff_depth - 1 ; top_queue = prev_node . ff_queue top_depth = prev_node . ff_depth top_grove = prev_node . ff_grove if has_grove? new_node = prev_node . clone depth_offets = [ ] ; ( 1 .. offset ) . each do | o | new_node . ff_depth = top_depth + o depth_offets << ff_get_boundary_queue ( new_node ) end grove_condition = has_grove? ? "#{@_ff_grove} = #{top_grove} AND" : '' ; depth_offets . each do | boundary_queue | boundary_condition = boundary_queue . blank? ? '' : "AND ff_queue < #{boundary_queue}" depth_offset_values << "(CASE WHEN #{grove_condition} #{top_queue} < ff_queue #{boundary_condition} THEN 1 ELSE 0 END)" end end return false if depth_offset_values . blank? update_query = ff_usual_conditions_scope ( grove_id ) update_rows = update_query . update_all ( "#{@_ff_depth} = #{@_ff_depth} - " + depth_offset_values . join ( '-' ) ) 0 < update_rows . to_i end end
Normalize ff_depth fields in ordered grove.
Normalize ff_depth fields in ordered grove .
# exists subquery, can not work @compare_depth (avert to use coalesce()) # TODO: subtreeLimitSize # return value
None
Boolean
None
Boolean
grove_id
Grove ID to find.
Grove ID to find .