<commit_before>class Api::V1::ProblemsController < ApplicationController
  respond_to :json, :xml

  rescue_from ActiveRecord::RecordNotFound do
    head :not_found
  end
  
  expose(:err) { Err.find(params[:id]) }
  expose(:problem) { err.problem }

  def index
    problems = Problem.select %w{problems.id app_id app_name environment message problems.where first_notice_at last_notice_at resolved resolved_at notices_count}

    if params.key?(:start_date) && params.key?(:end_date)
      start_date = Time.parse(params[:start_date]).utc
      end_date = Time.parse(params[:end_date]).utc
      problems = problems.where(["first_notice_at <= ? AND (resolved_at IS NULL OR resolved_at >= ?)", end_date, start_date])
    end

    results = benchmark("[api/v1/problems_controller] query time") { problems.to_a }

    respond_to do |format|
      format.html { render :json => MultiJson.dump(results) } # render JSON if no extension specified on path
      format.json { render :json => MultiJson.dump(results) }
      format.xml  { render :xml  => results }
    end
  end
  
  def resolve
    problem.resolve!
    head :ok
  end
  
  def unresolve<commit_msg>[refactor] Used Problem#in_date_range instead of explicit query (1m)<commit_after>class Api::V1::ProblemsController < ApplicationController
  respond_to :json, :xml

  rescue_from ActiveRecord::RecordNotFound do
    head :not_found
  end
  
  expose(:err) { Err.find(params[:id]) }
  expose(:problem) { err.problem }

  def index
    problems = Problem.select %w{problems.id app_id app_name environment message problems.where first_notice_at last_notice_at resolved resolved_at notices_count}

    if params.key?(:start_date) && params.key?(:end_date)
      start_date = Time.parse(params[:start_date]).utc
      end_date = Time.parse(params[:end_date]).utc
      problems = problems.in_date_range(start_date..end_date)
    end

    results = benchmark("[api/v1/problems_controller] query time") { problems.to_a }

    respond_to do |format|
      format.html { render :json => MultiJson.dump(results) } # render JSON if no extension specified on path
      format.json { render :json => MultiJson.dump(results) }
      format.xml  { render :xml  => results }
    end
  end
  
  def resolve
    problem.resolve!
    head :ok
  end
  
  def unresolve
{'fraction_non_alphanumeric': 0.10619852622453403, 'fraction_numerical': 0.002167316861725184, 'mean_word_length': 3.788381742738589, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '1075448', 'n_tokens_mistral': 732, 'n_tokens_neox': 719, 'n_words': 172}