<commit_before>class AssignmentModulesController < ApplicationController

  before_filter CASClient::Frameworks::Rails::Filter

  rescue_from ActiveRecord::RecordNotFound do |exception|
    respond_to do |format|
      format.json { render :json => { :success => false }, :status => :not_found }
      format.ext_json { render :json => { :success => false }, :status => :not_found }
    end
  end

  before_filter :find_assignment, :only => [ :index, :new, :create ]

  before_filter :find_assignment_module, :only => [ :show, :update, :edit, :destroy, :move_higher, :move_lower, :edit_params, :update_params ]

  before_filter :require_designer

  
  def index
    respond_to do |format|
      format.html
      format.ext_json { render :json => @assignment.configured_modules(nil).to_ext_json }
    end
  end


  def show
  end

  def new
    @assignment_module = AssignmentModule.new
    @assignment_module.assignment = @assignment
  end

  def create
    @assignment_module = AssignmentModule.new
    @assignment_module.assignment = @assignment
    @assignment_module.module_type = params[:assignment_module][:module_type].to_i
    @assignment_module.tag = params[:assignment_module][:tag]
    @assignment_module.duration = 0
    @assignment_module.number_participants = 1
    case @assignment_module.module_type
      when -1: @assignment_module.name = 'Private Messaging'
      when  0: @assignment_module.name = 'Informational'
      else     @assignment_module.name = @assignment_module.module_def.name
    end
    @assignment_module.save!

    redirect_to :action => :index, :assignment_id => @assignment
  end

  def edit
  end

  def update
    if(!params[:assignment_module]["ends_at(1i)"].blank?)
      ends_at = DateTime.civil(
        params[:assignment_module]["ends_at(1i)"].to_i,
        params[:assignment_module]["ends_at(2i)"].to_i,
        params[:assignment_module]["ends_at(3i)"].to_i,
        params[:assignment_module]["ends_at(4i)"].to_i,
        params[:assignment_module]["ends_at(5i)"].to_i
      )
      cm = (@assignment_module.assignment.configured_modules(nil))[@assignment_module.position - 1]

      if ends_at > cm.starts_at.to_datetime
        params[:assignment_module]["duration"] = (ends_at - cm.starts_at.to_datetime).to_i*24*60*60
      end
      params[:assignment_module].delete("ends_at(1i)")
      params[:assignment_module].delete("ends_at(2i)")
      params[:assignment_module].delete("ends_at(3i)")
      params[:assignment_module].delete("ends_at(4i)")
      params[:assignment_module].delete("ends_at(5i)")
    end
    params[:assignment_module].delete('params')
    @assignment_module.update_attributes(params[:assignment_module])
    @assignment_module.save
    redirect_to :action => 'show', :id => @assignment_module
  end

  def edit_params
  end

  def update_params
    # we want to make sure we only get things that are in the form
    form = @assignment_module.params_form
    doc = LibXML::XML::Document.string form<commit_msg>Do conversion to seconds before conversion to integer<commit_after>class AssignmentModulesController < ApplicationController

  before_filter CASClient::Frameworks::Rails::Filter

  rescue_from ActiveRecord::RecordNotFound do |exception|
    respond_to do |format|
      format.json { render :json => { :success => false }, :status => :not_found }
      format.ext_json { render :json => { :success => false }, :status => :not_found }
    end
  end

  before_filter :find_assignment, :only => [ :index, :new, :create ]

  before_filter :find_assignment_module, :only => [ :show, :update, :edit, :destroy, :move_higher, :move_lower, :edit_params, :update_params ]

  before_filter :require_designer

  
  def index
    respond_to do |format|
      format.html
      format.ext_json { render :json => @assignment.configured_modules(nil).to_ext_json }
    end
  end


  def show
  end

  def new
    @assignment_module = AssignmentModule.new
    @assignment_module.assignment = @assignment
  end

  def create
    @assignment_module = AssignmentModule.new
    @assignment_module.assignment = @assignment
    @assignment_module.module_type = params[:assignment_module][:module_type].to_i
    @assignment_module.tag = params[:assignment_module][:tag]
    @assignment_module.duration = 0
    @assignment_module.number_participants = 1
    case @assignment_module.module_type
      when -1: @assignment_module.name = 'Private Messaging'
      when  0: @assignment_module.name = 'Informational'
      else     @assignment_module.name = @assignment_module.module_def.name
    end
    @assignment_module.save!

    redirect_to :action => :index, :assignment_id => @assignment
  end

  def edit
  end

  def update
    if(!params[:assignment_module]["ends_at(1i)"].blank?)
      ends_at = DateTime.civil(
        params[:assignment_module]["ends_at(1i)"].to_i,
        params[:assignment_module]["ends_at(2i)"].to_i,
        params[:assignment_module]["ends_at(3i)"].to_i,
        params[:assignment_module]["ends_at(4i)"].to_i,
        params[:assignment_module]["ends_at(5i)"].to_i
      )
      cm = (@assignment_module.assignment.configured_modules(nil))[@assignment_module.position - 1]

      if ends_at > cm.starts_at.to_datetime
        params[:assignment_module]["duration"] = ((ends_at - cm.starts_at.to_datetime)*24*60*60).to_i
      end
      params[:assignment_module].delete("ends_at(1i)")
      params[:assignment_module].delete("ends_at(2i)")
      params[:assignment_module].delete("ends_at(3i)")
      params[:assignment_module].delete("ends_at(4i)")
      params[:assignment_module].delete("ends_at(5i)")
    end
    params[:assignment_module].delete('params')
    @assignment_module.update_attributes(params[:assignment_module])
    @assignment_module.save
    redirect_to :action => 'show', :id => @assignment_module
  end

  def edit_params
  end

  def update_params
    # we want to make sure we only get things that are in the form
    form = @assignment_module.params_form
    doc = LibXML::XML::Document.string form
{'fraction_non_alphanumeric': 0.12026578073089701, 'fraction_numerical': 0.007308970099667774, 'mean_word_length': 4.1461538461538465, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '6953072', 'n_tokens_mistral': 1988, 'n_tokens_neox': 1937, 'n_words': 340}