class StatisticsController < ApplicationController
  include StatisticsHelper

  before_action :authorize!, only: [:show, :graphs, :user_activity, :user_activity_history, :rfc_activity,
                                    :rfc_activity_history]

  def policy_class
    StatisticsPolicy
  end

  def show
    respond_to do |format|
      format.html
      format.json { render(json: statistics_data) }
    end
  end

  def graphs
  end

  def user_activity
    respond_to do |format|
      format.json { render(json: user_activity_live_data) }
    end
  end

  def user_activity_history
  end

  def rfc_activity
    respond_to do |format|
      format.json { render(json: rfc_activity_data) }
    end
  end

  def rfc_activity_history
    respond_to do |format|
      format.html { render 'rfc_activity_history' }
      format.json do
        interval = params[:interval].to_s.nil? ? 'year' : params[:interval]
        from = DateTime.strptime(params[:from], '%Y-%m-%d') rescue DateTime.new(0)
        to = DateTime.strptime(params[:to], '%Y-%m-%d') rescue DateTime.now
        render(json: ranged_rfc_data(interval, from, to))
      end
    end
  end

  def authorize!
    authorize self
  end
  private :authorize!

end

class StatisticsController < ApplicationController
  include StatisticsHelper

  before_action :authorize!, only: [:show, :graphs, :user_activity, :user_activity_history, :rfc_activity,
                                    :rfc_activity_history]

  def policy_class
    StatisticsPolicy
  end

  def show
    respond_to do |format|
      format.html
      format.json { render(json: statistics_data) }
    end
  end

  def graphs
  end

  def user_activity
    respond_to do |format|
      format.json { render(json: user_activity_live_data) }
    end
  end

  def user_activity_history
  end

  def rfc_activity
    respond_to do |format|
      format.json { render(json: rfc_activity_data) }
    end
  end

  def rfc_activity_history
    respond_to do |format|
      format.html { render 'rfc_activity_history' }
      format.json do
        interval = params[:interval].to_s.empty? ? 'year' : params[:interval]
        from = DateTime.strptime(params[:from], '%Y-%m-%d') rescue DateTime.new(0)
        to = DateTime.strptime(params[:to], '%Y-%m-%d') rescue DateTime.now
        render(json: ranged_rfc_data(interval, from, to))
      end
    end
  end

  def authorize!
    authorize self
  end
  private :authorize!

end

Fix empty parameter causing db exception
Fix empty parameter causing db exception
