<commit_before>class Compete::WaveAssignmentsController < ApplicationController
  include CsvOutputter
  include WaveBestTimeEagerLoader
  layout "competition_management"
  before_action :authenticate_user!
  before_action :load_competition
  before_action :set_parent_breadcrumbs

  respond_to :html

  # GET /competitions/1/waves
  def show
    authorize @competition, :show?
    add_breadcrumb "Current Waves"
    @competitors = eager_load_competitors_relations(@competition.competitors)

    respond_to do |format|
      format.csv do
        exporter = Exporters::WaveExporter.new(@competitors)
        headers = exporter.headers
        data = exporter.rows
        output_csv(headers, data, "#{@competition.slug}-waves-draft-#{Date.today}.csv")
      end
      format.html {} # normal
    end
  end

  # PUT /competitions/1/waves
  def update
    authorize @competition, :modify_result_data?

    parser = Importers::Parsers::Wave.new(params[:file])
    updater = Importers::WaveUpdater.new(@competition, current_user)

    if updater.process(parser)
      flash[:notice] = "#{updater.num_rows_processed} Waves Configured"
    else
      flash[:alert] = "Error processing file #{updater.errors}"
    end

    redirect_to competition_waves_path(@competition)
  end

  private

  def load_competition
    @competition = Competition.find(params[:competition_id])
  end

  def set_parent_breadcrumbs
    add_breadcrumb @competition.to_s, competition_path(@competition)
  end
end<commit_msg>improve wave import redirect<commit_after>class Compete::WaveAssignmentsController < ApplicationController
  include CsvOutputter
  include WaveBestTimeEagerLoader
  layout "competition_management"
  before_action :authenticate_user!
  before_action :load_competition
  before_action :set_parent_breadcrumbs

  respond_to :html

  # GET /competitions/1/waves
  def show
    authorize @competition, :show?
    add_breadcrumb "Current Waves"
    @competitors = eager_load_competitors_relations(@competition.competitors)

    respond_to do |format|
      format.csv do
        exporter = Exporters::WaveExporter.new(@competitors)
        headers = exporter.headers
        data = exporter.rows
        output_csv(headers, data, "#{@competition.slug}-waves-draft-#{Date.today}.csv")
      end
      format.html {} # normal
    end
  end

  # PUT /competitions/1/waves
  def update
    authorize @competition, :modify_result_data?

    parser = Importers::Parsers::Wave.new(params[:file])
    updater = Importers::WaveUpdater.new(@competition, current_user)

    if updater.process(parser)
      flash[:notice] = "#{updater.num_rows_processed} Waves Configured"
      redirect_to competition_waves_path(@competition)
    else
      flash[:alert] = "Error processing file #{updater.errors}"
      redirect_back(fallback_location: competition_waves_path(@competition))
    end
  end

  private

  def load_competition
    @competition = Competition.find(params[:competition_id])
  end

  def set_parent_breadcrumbs
    add_breadcrumb @competition.to_s, competition_path(@competition)
  end
end
{'fraction_non_alphanumeric': 0.0883403702500812, 'fraction_numerical': 0.0012991230919129587, 'mean_word_length': 4.176470588235294, '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': '7585488', 'n_tokens_mistral': 974, 'n_tokens_neox': 949, 'n_words': 182}