<commit_before>class StatisticsController < ApplicationController
  protect_from_forgery :except => [:create]
  before_action :check_if_smokedetector, :only => [:create]

  # GET /statistics
  def index
    @smoke_detector = SmokeDetector.find(params[:id])
    @statistics = @smoke_detector.statistics
  end

  # POST /statistics.json
  def create
    @statistic = Statistic.new(statistic_params)
    @statistic.smoke_detector = @smoke_detector

    respond_to do |format|
      if @statistic.save
        format.json { render plain: "OK", status: :created }
      else
        format.json { render json: @statistic.errors, status: :unprocessable_entity }
      end
    end
  end

  private
    # Never trust parameters from the scary internet, only allow the white list through.
    def statistic_params
      params.require(:statistic).permit(:posts_scanned, :api_quota)
    end
end<commit_msg>Reject obviously bad statistic sends<commit_after>class StatisticsController < ApplicationController
  protect_from_forgery :except => [:create]
  before_action :check_if_smokedetector, :only => [:create]

  # GET /statistics
  def index
    @smoke_detector = SmokeDetector.find(params[:id])
    @statistics = @smoke_detector.statistics
  end

  # POST /statistics.json
  def create
    @statistic = Statistic.new(statistic_params)

    if @statistic.posts_scanned == 0 or @statistic.api_quota == -1
      render plain: "OK", status: :created and return
    end

    @statistic.smoke_detector = @smoke_detector

    respond_to do |format|
      if @statistic.save
        format.json { render plain: "OK", status: :created }
      else
        format.json { render json: @statistic.errors, status: :unprocessable_entity }
      end
    end
  end

  private
    # Never trust parameters from the scary internet, only allow the white list through.
    def statistic_params
      params.require(:statistic).permit(:posts_scanned, :api_quota)
    end
end
{'fraction_non_alphanumeric': 0.08890030832476875, 'fraction_numerical': 0.0010277492291880781, 'mean_word_length': 3.5704225352112675, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4319330', 'n_tokens_mistral': 608, 'n_tokens_neox': 591, 'n_words': 153}