<commit_before>module Spree
  module Marketing
    class LeastZoneWiseOrdersList < List

      # Constants
      TIME_FRAME = 1.month
      LEAST_ZONE_WISE_ORDER_COUNT = 5

      attr_accessor :state_id

      def user_ids
        # FIXME: what if state id is not available, only country id is available. Should we use only zones.
        # If yes then how?
        # Also leaving cases for guest users
        Spree::Order.joins(ship_address: :state)
                    .of_registered_users
                    .where("spree_states.id = ?", @state_id)
                    .where("spree_orders.completed_at >= :time_frame", time_frame: computed_time)
                    .group(:user_id)
                    .order("COUNT(spree_orders.id)")
                    .pluck("spree_orders.user_id")
      end

      def self.generator
        lists = []
        data.each do |state_id|
          list = find_by(name: name_text(state_id))
          if list
            list.update_list
          else
            list = new(state_id: state_id).generate(name_text(state_id))
          end
          lists << list
        end
        ListCleanupJob.perform_later lists.map(&:uid)
      end

      def self.state_name state_id
        Spree::State.find_by(id: state_id).name.downcase.gsub(" ", "_")
      end

      def self.name_text state_id
        humanized_name + "_" + state_name(state_id)
      end

      def self.data
        Spree::Order.joins(ship_address: :state)
          .group("spree_states.id")
          .order("COUNT(spree_orders.id)")
          .limit(MOST_ZONE_WISE_ORDER_COUNT)
          .pluck(:state_id)
      end
    end
  end
end<commit_msg>change least_zone_count constant from most_zone_count<commit_after>module Spree
  module Marketing
    class LeastZoneWiseOrdersList < List

      # Constants
      TIME_FRAME = 1.month
      LEAST_ZONE_WISE_ORDER_COUNT = 5

      attr_accessor :state_id

      def user_ids
        # FIXME: what if state id is not available, only country id is available. Should we use only zones.
        # If yes then how?
        # Also leaving cases for guest users
        Spree::Order.joins(ship_address: :state)
                    .of_registered_users
                    .where("spree_states.id = ?", @state_id)
                    .where("spree_orders.completed_at >= :time_frame", time_frame: computed_time)
                    .group(:user_id)
                    .order("COUNT(spree_orders.id)")
                    .pluck("spree_orders.user_id")
      end

      def self.generator
        lists = []
        data.each do |state_id|
          list = find_by(name: name_text(state_id))
          if list
            list.update_list
          else
            list = new(state_id: state_id).generate(name_text(state_id))
          end
          lists << list
        end
        ListCleanupJob.perform_later lists.map(&:uid)
      end

      def self.state_name state_id
        Spree::State.find_by(id: state_id).name.downcase.gsub(" ", "_")
      end

      def self.name_text state_id
        humanized_name + "_" + state_name(state_id)
      end

      def self.data
        Spree::Order.joins(ship_address: :state)
          .group("spree_states.id")
          .order("COUNT(spree_orders.id)")
          .limit(LEAST_ZONE_WISE_ORDER_COUNT)
          .pluck(:state_id)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08822652757078987, 'fraction_numerical': 0.0011922503725782414, 'mean_word_length': 1.870829769033362, 'pattern_counts': {'":': 0, '<': 9, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4247657', 'n_tokens_mistral': 1047, 'n_tokens_neox': 1012, 'n_words': 211}