<commit_before>class StatsController < ApplicationController
  def index
    @rpms = FedoraRpm.order('commits desc').limit(10)
    @gems = RubyGem.order('downloads desc').limit(10)
  end

  def gemfile_tool
    if params[:gemfile]
      @gemfile = params[:gemfile]
      unless @gemfile.is_a?(String)
        @gemfile = @gemfile.read
      end

      @gemfile.gsub!(/\r*/, '')

      is_lock = !@gemfile.scan(/\nGEM\n/).empty?
      is_lock = !@gemfile.scan(/\nPLATFORMS\n/).empty?    unless is_lock
      is_lock = !@gemfile.scan(/\nDEPENDENCIES\n/).empty? unless is_lock

      lines = @gemfile.split "\n"

      dependencies = []
      @result = []

      # FIXME very hacky way to do this,
      # most likely we can leverage the bundler api instead
      if !is_lock
        lines.each { |line|
	  if line =~ /^gem\s+'([^']*)'$/
	    # gem name only
            dependencies << {:name => $1, :version => nil}

	  elsif line =~ /^gem\s+'([^']*)',\s*'([^']*)'.*$/
	    # gem with possible version
            name = $1
            version = nil
	    begin
	      version = Versionomy.parse($2.split.last)
	    rescue Versionomy::Errors::ParseError
	    end
            dependencies << {:name => name, :version => version}

          #else # ignore
	  end
	}
      else
        lines.each { |line|
	  if line =~ /^\s*([^\s]*)\s*\(([^\)]*)\)$/
	    # gem name / version
	    name, version = $1, $2
	    begin
	      version = Versionomy.parse(version.split.last)
	    rescue Versionomy::Errors::ParseError
	    end
	    dependencies << {:name => name, :version => version}
          end
	}
      end

      dependencies.each { |dep|
	unless @result.find { |res| res[:name] == dep[:name] }
          dep_fully_satisfied = true
          rpm = FedoraRpm.find_by_name("rubygem-" + dep[:name])
          if !rpm
            dep_fully_satisfied = false
            @result << {:name => dep[:name], :success => false, :message => "#{dep[:name]} not found in Fedora"}

	  elsif !dep[:version].nil?
	    rpm.rpm_versions.each { |rv|
              if Versionomy.parse(rv.rpm_version) < dep[:version]
	        dep_fully_satisfied = false
                @result << {:name => dep[:name], :success => false, :message => "#{dep[:name]} (#{dep[:version]}) is too old in #{rv.fedora_version} (which has #{rv.rpm_version})"}

	      else # TODO comment: (?)
                @result << {:name => dep[:name], :success => true, :message => "#{dep[:name]} (#{dep[:version]}) is sufficient in #{rv.fedora_version}!"}
              end
	    }
	  end

          if dep_fully_satisfied
            @result << {:name => dep[:name], :success => true, :message => "#{dep[:name]} is in Fedora!"}
          end
        end
      }
    end
  end
end
<commit_msg>whitespace fixes<commit_after>class StatsController < ApplicationController
  def index
    @rpms = FedoraRpm.order('commits desc').limit(10)
    @gems = RubyGem.order('downloads desc').limit(10)
  end

  def gemfile_tool
    if params[:gemfile]
      @gemfile = params[:gemfile]
      unless @gemfile.is_a?(String)
        @gemfile = @gemfile.read
      end

      @gemfile.gsub!(/\r*/, '')

      is_lock = !@gemfile.scan(/\nGEM\n/).empty?
      is_lock = !@gemfile.scan(/\nPLATFORMS\n/).empty?    unless is_lock
      is_lock = !@gemfile.scan(/\nDEPENDENCIES\n/).empty? unless is_lock

      lines = @gemfile.split "\n"

      dependencies = []
      @result = []

      # FIXME very hacky way to do this,
      # most likely we can leverage the bundler api instead
      if !is_lock
        lines.each { |line|
          if line =~ /^gem\s+'([^']*)'$/
            # gem name only
           dependencies << {:name => $1, :version => nil}

          elsif line =~ /^gem\s+'([^']*)',\s*'([^']*)'.*$/
            # gem with possible version
            name = $1
            version = nil
            begin
              version = Versionomy.parse($2.split.last)
            rescue Versionomy::Errors::ParseError
            end
            dependencies << {:name => name, :version => version}

            #else # ignore
          end
        }
      else
        lines.each { |line|
          if line =~ /^\s*([^\s]*)\s*\(([^\)]*)\)$/
            # gem name / version
            name, version = $1, $2
            begin
              version = Versionomy.parse(version.split.last)
            rescue Versionomy::Errors::ParseError
            end
            dependencies << {:name => name, :version => version}
          end
        }
      end

      dependencies.each { |dep|
        unless @result.find { |res| res[:name] == dep[:name] }
          dep_fully_satisfied = true
          rpm = FedoraRpm.find_by_name("rubygem-" + dep[:name])
          if !rpm
            dep_fully_satisfied = false
            @result << {:name => dep[:name], :success => false, :message => "#{dep[:name]} not found in Fedora"}

          elsif !dep[:version].nil?
            rpm.rpm_versions.each { |rv|
              if Versionomy.parse(rv.rpm_version) < dep[:version]
                dep_fully_satisfied = false
                @result << {:name => dep[:name], :success => false, :message => "#{dep[:name]} (#{dep[:version]}) is too old in #{rv.fedora_version} (which has #{rv.rpm_version})"}

              else # TODO comment: (?)
                @result << {:name => dep[:name], :success => true, :message => "#{dep[:name]} (#{dep[:version]}) is sufficient in #{rv.fedora_version}!"}
             end
            }
          end

          if dep_fully_satisfied
            @result << {:name => dep[:name], :success => true, :message => "#{dep[:name]} is in Fedora!"}
          end
        end
      }
    end
  end
end

{'fraction_non_alphanumeric': 0.16315696336931518, 'fraction_numerical': 0.0031852769421341354, 'mean_word_length': 2.0, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 39, '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': '4607347', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1747, 'n_words': 415}