<commit_before># a single server node where an agent is installed
class System < ActiveRecord::Base
  belongs_to :system_group

  has_many :concrete_package_versions
  has_many :package_versions, -> { distinct }, through: :concrete_package_versions
  has_many :packages, -> { distinct }, through: :package_versions

  has_many :tasks, -> { distinct }, through: :concrete_package_versions

  validates_presence_of :urn

  filterrific(
    default_filter_params: { sorted_by: 'registered_at_desc' },
    available_filters: [
      :sorted_by,
      :sys_search_query,
      :with_system_group_id
    ]
  )

    def self.get_maybe_create(system)
        if exists?(:urn => system["urn"])
            system_obj = where(urn: system["urn"])[0]
        else
            system_obj = new
            apply_system_properties( system_obj, system )
            system_obj.system_group = SystemGroup.first
            system_obj.last_seen = DateTime.now
            system_obj.save()
        end
        return system_obj
    end


  # Scope definitions. We implement all Filterrific filters through ActiveRecord
  # scopes. In this example we omit the implementation of the scopes for brevity.
  # Please see 'Scope patterns' for scope implementation details.
  scope :sys_search_query, lambda { |query|
    return nil  if query.blank?
    # condition query, parse into individual keywords
    terms = query.downcase.split(/\s+/)
    # replace "*" with "%" for wildcard searches,
    # append '%', remove duplicate '%'s
    terms = terms.map { |e|
      (e.gsub('*', '%') + '%').gsub(/%+/, '%')<commit_msg>extracted method from API to Model/System<commit_after># a single server node where an agent is installed
class System < ActiveRecord::Base
  belongs_to :system_group

  has_many :concrete_package_versions
  has_many :package_versions, -> { distinct }, through: :concrete_package_versions
  has_many :packages, -> { distinct }, through: :package_versions

  has_many :tasks, -> { distinct }, through: :concrete_package_versions

  validates_presence_of :urn

  filterrific(
    default_filter_params: { sorted_by: 'registered_at_desc' },
    available_filters: [
      :sorted_by,
      :sys_search_query,
      :with_system_group_id
    ]
  )

    # used in api
    def self.get_maybe_create(system)
        if exists?(:urn => system["urn"])
            system_obj = where(urn: system["urn"])[0]
        else
            system_obj = new
            apply_system_properties( system_obj, system )
            system_obj.system_group = SystemGroup.first
            system_obj.last_seen = DateTime.now
            system_obj.save()
        end
        return system_obj
    end


  # Scope definitions. We implement all Filterrific filters through ActiveRecord
  # scopes. In this example we omit the implementation of the scopes for brevity.
  # Please see 'Scope patterns' for scope implementation details.
  scope :sys_search_query, lambda { |query|
    return nil  if query.blank?
    # condition query, parse into individual keywords
    terms = query.downcase.split(/\s+/)
    # replace "*" with "%" for wildcard searches,
    # append '%', remove duplicate '%'s
    terms = terms.map { |e|
      (e.gsub('*', '%') + '%').gsub(/%+/, '%')
{'fraction_non_alphanumeric': 0.102532427424336, 'fraction_numerical': 0.0006176652254478073, 'mean_word_length': 3.0844892812105926, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '3057433', 'n_tokens_mistral': 955, 'n_tokens_neox': 934, 'n_words': 258}