<commit_before>module RotaGeneration
  class Allocator
    def mutate_slots!(slots, solution_clauses)
      solution_clauses.each do |clause|
        shift_id, date_of_month, month, year, firm_uid = split_clause(clause)
        date = Date.new(year.to_i, month.to_i, date_of_month.to_i)
        matching_slot = slots.detect { |s| s.date == date && s.shift_id == shift_id.to_i }
        matching_slot.organisation_uid = firm_uid if matching_slot
      end

      slots
    end

    private

    def split_clause(clause)
      clause.match(/allocated\(([^,]*),[^,]*,(\d+),(\d+),(\d+),\"([^,]*)\"\)/).captures
    end
  end
end
<commit_msg>Ensure that we don't assign organisation_uids to a RotaSlot more than once<commit_after>module RotaGeneration
  class Allocator
    def mutate_slots!(slots, solution_clauses)
      solution_clauses.each do |clause|
        shift_id, date_of_month, month, year, firm_uid = split_clause(clause)
        date = Date.new(year.to_i, month.to_i, date_of_month.to_i)
        matching_slot = slots.detect { |s| s.date == date && s.shift_id == shift_id.to_i && s.organisation_uid == nil }
        matching_slot.organisation_uid = firm_uid if matching_slot
      end

      slots
    end

    private

    def split_clause(clause)
      clause.match(/allocated\(([^,]*),[^,]*,(\d+),(\d+),(\d+),\"([^,]*)\"\)/).captures
    end
  end
end

{'fraction_non_alphanumeric': 0.1436950146627566, 'fraction_numerical': 0.0, 'mean_word_length': 3.2, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5694576', 'n_tokens_mistral': 503, 'n_tokens_neox': 492, 'n_words': 95}