<commit_before>class DataAnalysis::AnalysisUsersHavingSameSymptomWorker
  include Sidekiq::Worker

  @@bin_lcm_path = './data-analysis-fimi03'

  def perform(analysis_id)
    @analysis = DataAnalysis::AnalysisUsersHavingSameSymptom.find analysis_id
    input_path = create_input_file @analysis
    output_path = "./data-analysis-fimi03/outputs/#{@analysis.token}.output"
    puts "if system \"#{@@bin_lcm_path}/fim_closed #{input_path} #{@analysis.threshold} #{output_path}"
    if system "#{@@bin_lcm_path}/fim_closed #{input_path} #{@analysis.threshold} #{output_path}"
      @analysis.status = 'done'
    else
      @analysis.status = 'dead'
      puts $?
    end
    delete_input_file input_path
    @analysis.save
  end

  def create_input_file(analysis)
    input_path = "#{@@bin_lcm_path}/inputs/#{analysis.token}.input"
    puts "touch #{input_path}"
    system "touch #{input_path}"

    occurrences = get_occurrences_matching_analysis analysis

    current_user_id = nil
    current_line = ''
    occurrences.each do |occurrence|
      if current_user_id == occurrence.user_id
        current_line = current_line + ' ' unless current_line == ''
        current_line = current_line + occurrence.symptom_id.to_s
      else
        puts "system(\"echo '#{current_line}' >> #{input_path}\") unless #{current_user_id.nil?}"
        system("echo '#{current_line}' >> #{input_path}") unless current_user_id.nil?
        current_user_id = occurrence.user_id
        current_line = occurrence.symptom_id.to_s
      end
    end
    puts "system(\"echo '#{current_line}' >> #{input_path}\")"
    system("echo '#{current_line}' >> #{input_path}")
    input_path
  end

  def get_occurrences_matching_analysis(analysis)
    Occurrence
        .select('DISTINCT user_id, symptom_id')
        .where('date BETWEEN :start_date AND :end_date',
               {start_date: analysis.start_date, end_date: analysis.end_date})
        .order(:user_id)
  end

  def delete_input_file(input_file_path)
    puts "system(rm #{input_file_path})"
    system("rm #{input_file_path}")
  end
end<commit_msg>ref #52 & #53 less verbose version<commit_after>class DataAnalysis::AnalysisUsersHavingSameSymptomWorker
  include Sidekiq::Worker

  @@bin_lcm_path = './data-analysis-fimi03'

  def perform(analysis_id)
    @analysis = DataAnalysis::AnalysisUsersHavingSameSymptom.find analysis_id
    input_path = create_input_file @analysis
    output_path = "./data-analysis-fimi03/outputs/#{@analysis.token}.output"
    if system "#{@@bin_lcm_path}/fim_closed #{input_path} #{@analysis.threshold} #{output_path}"
      @analysis.status = 'done'
    else
      @analysis.status = 'dead'
      puts $?
    end
    delete_input_file input_path
    @analysis.save
  end

  def create_input_file(analysis)
    input_path = "#{@@bin_lcm_path}/inputs/#{analysis.token}.input"
    system "touch #{input_path}"

    occurrences = get_occurrences_matching_analysis analysis

    current_user_id = nil
    current_line = ''
    occurrences.each do |occurrence|
      if current_user_id == occurrence.user_id
        current_line = current_line + ' ' unless current_line == ''
        current_line = current_line + occurrence.symptom_id.to_s
      else
        system("echo '#{current_line}' >> #{input_path}") unless current_user_id.nil?
        current_user_id = occurrence.user_id
        current_line = occurrence.symptom_id.to_s
      end
    end
    system("echo '#{current_line}' >> #{input_path}")
    input_path
  end

  def get_occurrences_matching_analysis(analysis)
    Occurrence
        .select('DISTINCT user_id, symptom_id')
        .where('date BETWEEN :start_date AND :end_date',
               {start_date: analysis.start_date, end_date: analysis.end_date})
        .order(:user_id)
  end

  def delete_input_file(input_file_path)
    system("rm #{input_file_path}")
  end
end
{'fraction_non_alphanumeric': 0.11793675479523069, 'fraction_numerical': 0.003110419906687403, 'mean_word_length': 3.7291666666666665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '3141459', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1235, 'n_words': 225}