<commit_before>class RunsController < ApplicationController
  def create
    splits = params[:file]
    run = Run.create(nick: new_nick, user: nil)
    File.open(Rails.root.join('private', 'runs', run.nick), 'wb') do |file|
      file.write(splits.read)
    end
    render text: run.nick
  end
  def show
    @run_record = Run.find_by nick: params[:nick]
    @run_record.hits += 1
    @run_record.save
    splits = File.read Rails.root.join "private", "runs", @run_record.nick
    wsplit_data           =           WsplitParser.new.parse splits
    timesplittracker_data = TimesplittrackerParser.new.parse splits
    splitterz_data        =        SplitterzParser.new.parse splits
    if wsplit_data.present?
      @run = wsplit_data
      render :wsplit
    elsif timesplittracker_data.present?
      @run = timesplittracker_data
      render :timesplittracker
    elsif splitterz_data.present?
      @run = splitterz_data
      render :splitterz
    else
      if @run_record.hits > 1
        # If the run has already been viewed (and thus successfully parsed in
        # the past), we don't want to delete it
        render "runs/cant_parse"
      else
        # If not, we do
        @run_record.destroy
        redirect_to cant_parse_path
      end
    end
  end
  def download
    run = Run.find_by nick: params[:nick]
    file = Rails.root.join "private", "runs", run.nick
    send_file file, type: "application/text"
  end

  def new_nick
    nick = SecureRandom.urlsafe_base64(4)
    while Run.find_by(nick: nick).present?
      nick = SecureRandom.urlsafe_base64(4)
    end
    nick
  end
end<commit_msg>Changed permalink nicks to 4 characters, from 5<commit_after>class RunsController < ApplicationController
  def create
    splits = params[:file]
    run = Run.create(nick: new_nick, user: nil)
    File.open(Rails.root.join('private', 'runs', run.nick), 'wb') do |file|
      file.write(splits.read)
    end
    render text: run.nick
  end
  def show
    @run_record = Run.find_by nick: params[:nick]
    @run_record.hits += 1
    @run_record.save
    splits = File.read Rails.root.join "private", "runs", @run_record.nick
    wsplit_data           =           WsplitParser.new.parse splits
    timesplittracker_data = TimesplittrackerParser.new.parse splits
    splitterz_data        =        SplitterzParser.new.parse splits
    if wsplit_data.present?
      @run = wsplit_data
      render :wsplit
    elsif timesplittracker_data.present?
      @run = timesplittracker_data
      render :timesplittracker
    elsif splitterz_data.present?
      @run = splitterz_data
      render :splitterz
    else
      if @run_record.hits > 1
        # If the run has already been viewed (and thus successfully parsed in
        # the past), we don't want to delete it
        render "runs/cant_parse"
      else
        # If not, we do
        @run_record.destroy
        redirect_to cant_parse_path
      end
    end
  end
  def download
    run = Run.find_by nick: params[:nick]
    file = Rails.root.join "private", "runs", run.nick
    send_file file, type: "application/text"
  end

  def new_nick
    nick = SecureRandom.urlsafe_base64(3)
    while Run.find_by(nick: nick).present?
      nick = SecureRandom.urlsafe_base64(3)
    end
    nick
  end
end
{'fraction_non_alphanumeric': 0.0860906862745098, 'fraction_numerical': 0.0055147058823529415, 'mean_word_length': 2.6117256637168142, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1060435', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1065, 'n_words': 270}