app/models/chouette/time_table.rb
# produce a copy of periods without anyone overlapping or including another
produce a copy of periods without anyone overlapping or including another
produce a copy of periods without anyone overlapping or including another
def optimize_overlapping_periods
      periods = self.clone_periods
      optimized = []
      i=0
      while i < periods.length
        p1 = periods[i]
        optimized << p1
        j= i+1
        while j < periods.length
          p2 = periods[j]
          if p1.contains? p2
            periods.delete p2
          elsif p1.overlap? p2
            p1.period_start = [p1.period_start,p2.period_start].min
            p1.period_end = [p1.period_end,p2.period_end].max
            periods.delete p2
          else
            j += 1
          end
        end
        i+= 1
      end
      optimized.sort { |a,b| a.period_start <=> b.period_start}
    end
def optimize_overlapping_periods periods = self . clone_periods optimized = [ ] i = 0 while i < periods . length p1 = periods [ i ] optimized << p1 j = i + 1 while j < periods . length p2 = periods [ j ] if p1 . contains? p2 periods . delete p2 elsif p1 . overlap? p2 p1 . period_start = [ p1 . period_start , p2 . period_start ] . min p1 . period_end = [ p1 . period_end , p2 . period_end ] . max periods . delete p2 else j += 1 end end i += 1 end optimized . sort { | a , b | a . period_start <=> b . period_start } end
produce a copy of periods without anyone overlapping or including another
produce a copy of periods without anyone overlapping or including another