<commit_before>class RecordsController < ApplicationController
  def index
    @service = Service.find_by(slug: params[:service_slug])
    v_num = params[:version][1..-1]
    @version = @service.versions.find_by(number: v_num)
    if @service.activated && @version.active
      @records = RecordQueryService.new(@version, default_params.merge(params)).fetch_records
      render json: @records.to_json(json_options), status: 200
    else
      render json: "This service has been deactivated. Check the service's documentation for details."
    end
  end

  protected

  def default_params
    {limit: 50, offset: 0, sortby: :insertion_id, order: :asc}.with_indifferent_access
  end

  def default_options
    @options = {except: "_id"}
  end

  def json_options<commit_msg>records controller returns DataFormatter object<commit_after>class RecordsController < ApplicationController
  def index
    @service = Service.find_by(slug: params[:service_slug])
    v_num = params[:version][1..-1]
    @version = @service.versions.find_by(number: v_num)
    if @service.activated && @version.active
      @records = RecordQueryService.new(@service, default_params.merge(params)).fetch_records
      @formatter = DataFormatter.new(start: params[:start], data: @records.to_json(json_options))
      render json: @formatter.to_json(except: ["created_at","updated_at","id"]), status: 200
    else
      render json: "This service has been deactivated. Check the service's documentation for details."
    end
  end

  protected

  def default_params
    {limit: 50, offset: 0, sortby: :insertion_id, order: :asc}.with_indifferent_access
  end

  def default_options
    @options = {except: "_id"}
  end

  def json_options
{'fraction_non_alphanumeric': 0.10760233918128655, 'fraction_numerical': 0.00935672514619883, 'mean_word_length': 4.313664596273292, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1441078', 'n_tokens_mistral': 525, 'n_tokens_neox': 500, 'n_words': 129}