<commit_before>class Dataservice::BundleContentsMetalController < ActionController::Metal

  def create
    controller_start_time = Time.now
    if bundle_logger = Dataservice::BundleLogger.find(params[:id])
      body = request.body.read
      if bundle_logger.in_progress_bundle
        launch_event = ::Dataservice::LaunchProcessEvent.create(
          :event_type => ::Dataservice::LaunchProcessEvent::TYPES[:bundle_saved],
          :event_details => "Learner session data saved. Activity should now be closed.",
          :bundle_content => bundle_logger.in_progress_bundle
        )
      end

      # make a time object out of X-Queue-Start header if it exists
      upload_time = nil
      x_queue_start = request.headers['X-Queue-Start']
      if x_queue_start
        usecs_since_1970 = x_queue_start.match(/t=(\d+)/)[1].to_i
        upload_time = controller_start_time - Time.at(usecs_since_1970/1000000)
      end
      bundle_logger.end_bundle( { :body => body, :upload_time => upload_time } )
      bundle_content = bundle_logger.bundle_contents.last
      digest = Digest::MD5.hexdigest(body)

      self.status = 201
      self.content_type = 'text/xml'
      self.response_body = ''
      self.headers['Last-Modified'] = bundle_content.created_at.httpdate
      self.headers['Content-Length'] = '0'
      self.headers['Content-MD5'] = digest
    else
      self.status = 404
      self.content_type = 'text/html'
      self.response_body = 'Not Found'
    end
  end

  include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
  add_transaction_tracer :create
end
<commit_msg>include more rails time in bundle upload_time<commit_after>class Dataservice::BundleContentsMetalController < ActionController::Metal

  def create
    if bundle_logger = Dataservice::BundleLogger.find(params[:id])
      body = request.body.read
      if bundle_logger.in_progress_bundle
        launch_event = ::Dataservice::LaunchProcessEvent.create(
          :event_type => ::Dataservice::LaunchProcessEvent::TYPES[:bundle_saved],
          :event_details => "Learner session data saved. Activity should now be closed.",
          :bundle_content => bundle_logger.in_progress_bundle
        )
      end

      # make a time object out of X-Queue-Start header if it exists
      upload_time = nil
      x_queue_start = request.headers['X-Queue-Start']
      if x_queue_start
        usecs_since_1970 = x_queue_start.match(/t=(\d+)/)[1].to_i
        upload_time = Time.now - Time.at(usecs_since_1970/1000000)
      end
      bundle_logger.end_bundle( { :body => body, :upload_time => upload_time } )
      bundle_content = bundle_logger.bundle_contents.last
      digest = Digest::MD5.hexdigest(body)

      self.status = 201
      self.content_type = 'text/xml'
      self.response_body = ''
      self.headers['Last-Modified'] = bundle_content.created_at.httpdate
      self.headers['Content-Length'] = '0'
      self.headers['Content-MD5'] = digest
    else
      self.status = 404
      self.content_type = 'text/html'
      self.response_body = 'Not Found'
    end
  end

  include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
  add_transaction_tracer :create
end

{'fraction_non_alphanumeric': 0.10300563556668754, 'fraction_numerical': 0.015654351909830933, 'mean_word_length': 3.2828418230563003, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4739598', 'n_tokens_mistral': 995, 'n_tokens_neox': 951, 'n_words': 182}