<commit_before>Contract.all(:include => :traffics).each do |c|
  unless c.traffics.empty?
    init = c.traffics.first.from_date
    final = c.traffics.last.to_date
    while init <= final
      last = init.end_of_month
      traffics = []
      c.traffics.each do |t|
        traffics << t if t.from_date >= init and t.to_date <= last
      end
      traffics.shift
      traffics.collect(&:delete)
      init = init + 1.month
    end
  end
end<commit_msg>optimization delete traffic duplicate<commit_after>Contract.all.each do |c|
  unless c.traffics.empty?
    init = c.traffics.first.from_date
    final = c.traffics.last.to_date
    while init <= final
      traffic = Traffic.first(:conditions => ["from_date = '#{init.strftime('%Y-%m-%d')}' and contract_id = #{c.id}"])
      unless traffic.nil?
        Traffic.delete_all(["to_date = '#{traffic.to_date.strftime('%Y-%m-%d')}' and from_date = '#{traffic.from_date.strftime('%Y-%m-%d')}' and contract_id = #{c.id} and id != #{traffic.id}"])
      end
      init = (init + 1.month).beginning_of_month
    end
  end
end
{'fraction_non_alphanumeric': 0.15298507462686567, 'fraction_numerical': 0.0018656716417910447, 'mean_word_length': 2.959409594095941, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '975317', 'n_tokens_mistral': 389, 'n_tokens_neox': 390, 'n_words': 77}