<commit_before>class CsvMethods

  def self.fill_csv file_location, submitters, sections, separator
    puts "Generating CSV file"
    puts "Opened file: #{file_location}"
    CSV.open(file_location, "w", {:col_sep => separator}) do |csv|
      #first row has the id's of the users that are authorized to fill a questionnaire.
      submitters_ids = submitters.sort{ |a,b| a.first_name <=> b.first_name }.map(&:id)
      submitters_head_line = submitters.sort{ |a,b| a.first_name <=> b.first_name }.map{ |a| "#{a.full_name} - #{a.email}" }
      csv << ["Section", "Question", "ID"] + submitters_head_line
      Array(sections).each do |section|
        loop_sources = {}
        if section.looping? && !section.loop_item_type.filtering_field_id.present?
          #item_names = section.loop_item_type.loop_item_names
          loop_items = section.loop_item_type.loop_items
          loop_items.each do |item|
            loop_sources[section.loop_item_type.root.loop_source.id.to_s] = item
            CsvMethods.export(csv, section, submitters_ids, loop_sources, item, item.id.to_s)#item.id.to_s => initial looping_identifier
          end
        else
          CsvMethods.export(csv, section, submitters_ids, loop_sources, nil)
        end<commit_msg>Include more info on submitters in CSV as rows<commit_after>class CsvMethods

  def self.fill_csv file_location, submitters, sections, separator
    puts "Generating CSV file"
    puts "Opened file: #{file_location}"
    CSV.open(file_location, "w", {:col_sep => separator}) do |csv|
      #first row has the id's of the users that are authorized to fill a questionnaire.
      sorted_submitters = submitters.sort { |a,b| a.first_name <=> b.first_name }
      submitters_ids = sorted_submitters.map(&:id)
      submitters_head_line = sorted_submitters.map(&:full_name)
      csv << ["Section", "Question", "ID"] + submitters_head_line

      #Add submitters info as rows at the top of the file
      #Skip two rows as those are related to the Question title and uidentifer columns
      csv << ["Region", '', ''] + sorted_submitters.map(&:region)
      csv << ["Country", '', ''] + sorted_submitters.map(&:country)
      csv << ["e-mail", '', ''] + sorted_submitters.map(&:email)

      Array(sections).each do |section|
        loop_sources = {}
        if section.looping? && !section.loop_item_type.filtering_field_id.present?
          #item_names = section.loop_item_type.loop_item_names
          loop_items = section.loop_item_type.loop_items
          loop_items.each do |item|
            loop_sources[section.loop_item_type.root.loop_source.id.to_s] = item
            CsvMethods.export(csv, section, submitters_ids, loop_sources, item, item.id.to_s)#item.id.to_s => initial looping_identifier
          end
        else
          CsvMethods.export(csv, section, submitters_ids, loop_sources, nil)
        end
{'fraction_non_alphanumeric': 0.11478260869565217, 'fraction_numerical': 0.0, 'mean_word_length': 3.3248120300751878, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 10, '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': '2613804', 'n_tokens_mistral': 918, 'n_tokens_neox': 900, 'n_words': 213}