<commit_before>class ReposController < ApplicationController
  # ZOMG too much logic here.
  # TODO: Refactor and add tests.
  def show
    @repo = Repo.find_by(name: params[:repo_name])
    @commits = @repo.commits
    @result_type = params[:result_type]

    commits_sha1s = ['Commit SHA1']
    commits_data = {}

    @commits.includes(:benchmark_runs).reverse.each do |commit|
      commit_benchmark_runs = commit.benchmark_runs
      next if commit_benchmark_runs.empty?

      if !@result_types
        @result_types = commit_benchmark_runs.map(&:category)
        @result_types.uniq
      end

      @result_type ||= commit.benchmark_runs.first.category

      commit.benchmark_runs.where(category: @result_type).each do |benchmark_run|
        commits_sha1s << commit.sha1[0..4]

        benchmark_run.result.each do |key, value|
          commits_data[key] ||= [key]
          commits_data[key] << value
        end
      end
    end

    @columns = [commits_sha1s]

    commits_data.each do |_, value|
      @columns << value
    end
  end
end
<commit_msg>Add label for Commit SHA1 in graph.<commit_after>class ReposController < ApplicationController
  # ZOMG too much logic here.
  # TODO: Refactor and add tests.
  def show
    @repo = Repo.find_by(name: params[:repo_name])
    @commits = @repo.commits
    @result_type = params[:result_type]

    commits_sha1s = ['Commit SHA1']
    commits_data = {}

    @commits.includes(:benchmark_runs).reverse.each do |commit|
      commit_benchmark_runs = commit.benchmark_runs
      next if commit_benchmark_runs.empty?

      if !@result_types
        @result_types = commit_benchmark_runs.map(&:category)
        @result_types.uniq
      end

      @result_type ||= commit.benchmark_runs.first.category

      commit.benchmark_runs.where(category: @result_type).each do |benchmark_run|
        commits_sha1s << "Commit: #{commit.sha1[0..4]}"

        benchmark_run.result.each do |key, value|
          commits_data[key] ||= [key]
          commits_data[key] << value
        end
      end
    end

    @columns = [commits_sha1s]

    commits_data.each do |_, value|
      @columns << value
    end
  end
end

{'fraction_non_alphanumeric': 0.10392609699769054, 'fraction_numerical': 0.006928406466512702, 'mean_word_length': 2.888689407540395, 'pattern_counts': {'":': 0, '<': 17, '<?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': '2629590', 'n_tokens_mistral': 737, 'n_tokens_neox': 723, 'n_words': 145}