<commit_before>%w{ models controllers helpers }.each do |dir|
  path = File.join(File.dirname(__FILE__), 'app', dir)
  $LOAD_PATH << path
  ActiveSupport::Dependencies.load_paths << path
  ActiveSupport::Dependencies.load_once_paths.delete(path)
end

module Heatmap

  def heatmap(histogram={})
    html = %{<div class="heatmap">}
    histogram.keys.sort{|a,b| histogram[a] <=> histogram[b]}.reverse.each do |k|
      next if histogram[k] < 1
      _heat = element_heat(histogram, histogram[k])
      _size = element_size(histogram, k)
      _max = histogram_max(histogram)
      html << %{
        <div class="heatmap_element" style="color: ##{_heat}#{_heat}#{_heat}; font-size: #{_size}px; height: #{_max}px;">#{k}</div>
      }
    end
    html << %{<br style="clear: both;" /></div>}
  end

  def histogram_max(histogram)
    histogram.map{|k,v| histogram[k]}.max * 2
  end

  def element_size(histogram, key)
    (((histogram[key] / histogram.map{|k,v| histogram[k]}.sum.to_f) * 100) + 5).to_i
  end
  
  def element_heat(histogram, _size)
    sprintf("%02x" % (255 - (_size * 25)))
  end

end<commit_msg>Tweaked color of elements in heat map.<commit_after>%w{ models controllers helpers }.each do |dir|
  path = File.join(File.dirname(__FILE__), 'app', dir)
  $LOAD_PATH << path
  ActiveSupport::Dependencies.load_paths << path
  ActiveSupport::Dependencies.load_once_paths.delete(path)
end

module Heatmap

  def heatmap(histogram={})
    html = %{<div class="heatmap">}
    histogram.keys.sort{|a,b| histogram[a] <=> histogram[b]}.reverse.each do |k|
      next if histogram[k] < 1
      _heat = element_heat(histogram, histogram[k])
      _size = element_size(histogram, k)
      _max = histogram_max(histogram)
      html << %{
        <div class="heatmap_element" style="color: ##{_heat}#{_heat}#{_heat}; font-size: #{_size}px; height: #{_max}px;">#{k}</div>
      }
    end
    html << %{<br style="clear: both;" /></div>}
  end

  def histogram_max(histogram)
    histogram.map{|k,v| histogram[k]}.max * 2
  end

  def element_size(histogram, key)
    (((histogram[key] / histogram.map{|k,v| histogram[k]}.sum.to_f) * 100) + 5).to_i
  end
  
  def element_heat(histogram, _size)
    sprintf("%02x" % (255 - (_size * 10)))
  end

end
{'fraction_non_alphanumeric': 0.1714922048997773, 'fraction_numerical': 0.011581291759465479, 'mean_word_length': 3.882608695652174, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 15, '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': '5850212', 'n_tokens_mistral': 881, 'n_tokens_neox': 806, 'n_words': 167}