<commit_before>require 'zip'
class DiscussionComment < ActiveRecord::Base
  include FileHelper

  belongs_to :task_comment
  validates :task_comment, presence: true

  def status
    return "not started" if not started and not completed
    return "opened" if started and not completed
    return "complete"
  end

  def attachment_path(_count)
    FileHelper.comment_prompt_path(self.task_comment, ".wav", _count)
  end

  def reply_attachment_path
    FileHelper.comment_reply_prompt_path(self.task_comment, self.id, ".wav")
  end

  def startDiscussion()
    self.time_started = DateTime.now
    self.save!
  end

  def finishDiscussion()
    self.time_completed = DateTime.now
    self.save!
  end

  def dueDate
    created_at + 10.days
  end

  def started
    not time_started.nil?
  end

  def completed
    not time_completed.nil?
  end

  def get_prompt_files
    i_path = FileHelper.student_work_dir(:discussion, self.task_comment.task, false)
    i_path << self.task_comment.id

    files = Array.new

    i = 0
    while true
      break unless File.exists? "#{i_path}_#{i}"
      files.push(File.read("#{i_path}_#{i}"))
    end

    zip_file_path = FileHelper.zip_file_path_for_discussion_prompts

    zip_file = Zip::File.open(zip_file_path, Zip::File::CREATE) do |zip|
      zip.mkdir task.id.to_s
      input_files.each do |in_file|
        zip.add "#{task.id}/#{in_file}", "#{task_dir}#{in_file}"
      end
    end

    return zip_file, zip_file_path

  end

  def add_prompt(file_upload, _count)
    temp = Tempfile.new(['discussion_comment', '.wav'])
    return false unless process_audio(file_upload.tempfile.path, temp.path)
    save
    logger.info("Saving audio prompt to #{attachment_path(_count)}")
    FileUtils.mv temp.path, attachment_path(_count)
  end

  def add_reply(current_user, reply_attachment)
    temp = Tempfile.new(['discussion_comment_reply', '.wav'])
    return false unless process_audio(file_upload.tempfile.path, temp.path)
    save
    logger.info("Saving discussion comment reply to #{reply_attachment_path()}")
    FileUtils.mv temp.path, reply_attachment_path()
  end
end<commit_msg>WIP: Add zip file generation for all prompts<commit_after>require 'zip'
class DiscussionComment < ActiveRecord::Base
  include FileHelper

  belongs_to :task_comment
  validates :task_comment, presence: true

  def status
    return "not started" if not started and not completed
    return "opened" if started and not completed
    return "complete"
  end

  def attachment_path(_count)
    FileHelper.comment_prompt_path(self.task_comment, ".wav", _count)
  end

  def reply_attachment_path
    FileHelper.comment_reply_prompt_path(self.task_comment, self.id, ".wav")
  end

  def startDiscussion()
    self.time_started = DateTime.now
    self.save!
  end

  def finishDiscussion()
    self.time_completed = DateTime.now
    self.save!
  end

  def dueDate
    created_at + 10.days
  end

  def started
    not time_started.nil?
  end

  def completed
    not time_completed.nil?
  end

  def get_prompt_files
    i_path = FileHelper.student_work_dir(:discussion, self.task_comment.task, false)
    i_path = i_path + self.task_comment.id.to_s

    files = Array.new

    i = 0
    flag = true
    while flag
      temp_path = "#{i_path}_#{i}.wav"
      
      if not File.exists? temp_path
        flag = false
        break
      end

      files.push temp_path
      i = i + 1
    end

    zip_file_path = FileHelper.zip_file_path_for_discussion_prompts(self.task_comment.task)

    zip_file = Zip::File.open(zip_file_path, Zip::File::CREATE) do |zip|
      files.each_with_index do |in_file, index|
        zip.add "#{index}.wav", "#{in_file}"
      end
    end

    return zip_file, zip_file_path

  end

  def add_prompt(file_upload, _count)
    temp = Tempfile.new(['discussion_comment', '.wav'])
    return false unless process_audio(file_upload.tempfile.path, temp.path)
    save
    logger.info("Saving audio prompt to #{attachment_path(_count)}")
    FileUtils.mv temp.path, attachment_path(_count)
  end

  def add_reply(current_user, reply_attachment)
    temp = Tempfile.new(['discussion_comment_reply', '.wav'])
    return false unless process_audio(file_upload.tempfile.path, temp.path)
    save
    logger.info("Saving discussion comment reply to #{reply_attachment_path()}")
    FileUtils.mv temp.path, reply_attachment_path()
  end
end
{'fraction_non_alphanumeric': 0.09478241057188426, 'fraction_numerical': 0.001594896331738437, 'mean_word_length': 3.521112255406797, 'pattern_counts': {'":': 0, '<': 7, '<?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': '645990', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1404, 'n_words': 334}