<commit_before>require 'whales_cli/feature'

module Whales
  class FeatureCollection

    def initialize(features_attributes)
      @features_attributes = JSON.parse(features_attributes)
    end

    def features
      @features ||= @features_attributes.map do |feature_attributes|
        Whales::Feature.new(feature_attributes)
      end
    end

    def dominant_language
      @dominant_language ||= if rails? || sinatra? || middleman?
                               language_features.select { |feature| feature["name"] == "Ruby" }[0]
                             else
                               max_ratio_language
                             end
    end

    def language_features
      @language_features ||= features.select { |feature| feature.categories.include? "Language" }
    end

    def to_json
      features.map(&:to_json)
    end

    private

    def max_ratio_language
      @max_ratio_language ||= language_features.max_by { |feature| feature.dig("meta", "ratio").to_f }
    end

    def rails?
      frameworks.map { |f| f["name"] }.include? "rails"
    end

    def middleman?<commit_msg>Adds django & python support<commit_after>require 'whales_cli/feature'

module Whales
  class FeatureCollection

    def initialize(features_attributes)
      @features_attributes = JSON.parse(features_attributes)
    end

    def features
      @features ||= @features_attributes.map do |feature_attributes|
        Whales::Feature.new(feature_attributes)
      end
    end

    def dominant_language
      @dominant_language ||= if rails? || sinatra? || middleman?
                               language_features.select { |feature| feature["name"] == "Ruby" }[0]
                             elsif django?
                               language_features.select { |feature| feature["name"] == "Python" }[0]
                             else
                               max_ratio_language
                             end
    end

    def language_features
      @language_features ||= features.select { |feature| feature.categories.include? "Language" }
    end

    def to_json
      features.map(&:to_json)
    end

    private

    def max_ratio_language
      @max_ratio_language ||= language_features.max_by { |feature| feature.dig("meta", "ratio").to_f }
    end

    def django?
      frameworks.map { |f| f["name"] }.include? "django"
    end

    def rails?
      frameworks.map { |f| f["name"] }.include? "rails"
    end

    def middleman?
{'fraction_non_alphanumeric': 0.09672197490894374, 'fraction_numerical': 0.0012140833670578712, 'mean_word_length': 2.1172761664564943, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6327719', 'n_tokens_mistral': 698, 'n_tokens_neox': 667, 'n_words': 151}