<commit_before>class GenerateJob < ActiveJob::Base
  include ActiveJob::Status

  queue_as MarkusConfigurator.markus_job_generate_queue_name

  def self.on_complete_js(status)
    path = Rails.application.routes.url_helpers.download_generate_assignment_exam_template_path(assignment_id: status[:id],
                                                                                                id: status[:exam_id])
    "function(){window.location='#{path}?file_name=#{status[:file_name]}'}"
  end

  def self.show_status(status)
    I18n.t('poll_job.generate_job', progress: status[:progress],
           total: status[:total],
           exam_name: status[:exam_name])
  end

  before_enqueue do |job|
    status.update(job_class: self.class)
    status.update(exam_name: job.arguments[0].name)
  end

  def perform(exam_template, num_copies, start)
    m_logger = MarkusLogger.instance
    begin
      progress.total = num_copies
      template_path = File.join(
        exam_template.base_path,
        exam_template.filename
      )
      template_pdf = CombinePDF.load template_path
      generated_pdf = CombinePDF.new
      (start..start + num_copies - 1).each do |exam_num|
        m_logger.log("Now generating: #{exam_num}")
        pdf = Prawn::Document::new(margin: 20) do
          exam_template.num_pages.times do |page_num|
            qrcode_content = "#{exam_template.name}-#{exam_num}-#{page_num + 1}"
            qrcode = RQRCode::QRCode.new qrcode_content, level: :h, size: 4
            alignment = page_num % 2 == 0 ? :right : :left
            text = "#{exam_template.name} #{exam_num}-#{page_num + 1}"
            if alignment == :right
              text_width = width_of(text)
              draw_text(text, :at => [400 - text_width, 690])
            else
              draw_text(text, :at => [175, 690])
            end
            render_qr_code(qrcode, align: alignment, dot: 3.2, stroke: false)
            start_new_page
          end
        end
        combine_pdf_qr = CombinePDF.parse(pdf.render)
        template_pdf.pages.zip(combine_pdf_qr.pages) do |template_page, qr_page|
          generated_pdf << (qr_page << template_page)
        end
        progress.increment
      end

      generated_pdf.save File.join(
        exam_template.base_path,
        "#{exam_template.name}-#{start}-#{start + num_copies - 1}.pdf"
      )
     end
     m_logger.log('Generate pdf copies process done')
    rescue => e
      Rails.logger.error e.message
      raise e
    end
  end<commit_msg>made the QR code dots in three edges bigger<commit_after>class GenerateJob < ActiveJob::Base
  include ActiveJob::Status

  queue_as MarkusConfigurator.markus_job_generate_queue_name

  def self.on_complete_js(status)
    path = Rails.application.routes.url_helpers.download_generate_assignment_exam_template_path(assignment_id: status[:id],
                                                                                                id: status[:exam_id])
    "function(){window.location='#{path}?file_name=#{status[:file_name]}'}"
  end

  def self.show_status(status)
    I18n.t('poll_job.generate_job', progress: status[:progress],
           total: status[:total],
           exam_name: status[:exam_name])
  end

  before_enqueue do |job|
    status.update(job_class: self.class)
    status.update(exam_name: job.arguments[0].name)
  end

  def perform(exam_template, num_copies, start)
    m_logger = MarkusLogger.instance
    begin
      progress.total = num_copies
      template_path = File.join(
        exam_template.base_path,
        exam_template.filename
      )
      template_pdf = CombinePDF.load template_path
      generated_pdf = CombinePDF.new
      (start..start + num_copies - 1).each do |exam_num|
        m_logger.log("Now generating: #{exam_num}")
        pdf = Prawn::Document::new(margin: 20) do
          exam_template.num_pages.times do |page_num|
            qrcode_content = "#{exam_template.name}-#{exam_num}-#{page_num + 1}"
            qrcode = RQRCode::QRCode.new qrcode_content, level: :l, size: 2
            alignment = page_num % 2 == 0 ? :right : :left
            text = "#{exam_template.name} #{exam_num}-#{page_num + 1}"
            if alignment == :right
              text_width = width_of(text)
              draw_text(text, :at => [400 - text_width, 690])
            else
              draw_text(text, :at => [175, 690])
            end
            render_qr_code(qrcode, align: alignment, dot: 4.0, stroke: false)
            start_new_page
          end
        end
        combine_pdf_qr = CombinePDF.parse(pdf.render)
        template_pdf.pages.zip(combine_pdf_qr.pages) do |template_page, qr_page|
          generated_pdf << (qr_page << template_page)
        end
        progress.increment
      end

      generated_pdf.save File.join(
        exam_template.base_path,
        "#{exam_template.name}-#{start}-#{start + num_copies - 1}.pdf"
      )
     end
     m_logger.log('Generate pdf copies process done')
    rescue => e
      Rails.logger.error e.message
      raise e
    end
  end
{'fraction_non_alphanumeric': 0.10729783037475345, 'fraction_numerical': 0.010256410256410256, 'mean_word_length': 2.333990795529257, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3185204', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1578, 'n_words': 297}