<commit_before>require 'carto/tracking/services/pubsub_tracker'

require_dependency 'carto/tracking/formats/internal'
require_dependency 'carto/tracking/services/pubsub'
require_dependency 'carto/tracking/services/segment'
require_dependency 'carto/tracking/services/hubspot'
require_dependency 'carto/tracking/validators/visualization'
require_dependency 'carto/tracking/validators/layer'
require_dependency 'carto/tracking/validators/user'
require_dependency 'carto/tracking/validators/widget'

#  IMPORTANT: Events must be kept in sync with frontend!
#  See `/lib/assets/javascripts/builder/components/metrics/metrics-types.js`

DEFAULT_EVENT_VERSION = 1

module Carto
  module Tracking
    module Events
      class Event
        include ::LoggerHelper

        def initialize(reporter_id, properties)
          properties.merge!({event_version: event_version})

          @format = Carto::Tracking::Formats::Internal.new(properties)
          @reporter = Carto::User.find(reporter_id)
        end

        def name
          self.class.name.demodulize.underscore.humanize.capitalize
        end

        def event_version
          DEFAULT_EVENT_VERSION
        end

        def self.required_properties(*required_properties)
          @required_properties ||= []
          @required_properties += required_properties
        end

        def required_properties
          these_required_properties = self.class.instance_eval { @required_properties || [] }

          these_required_properties + self.class.superclass.required_properties
        end

        def self.optional_properties(*optional_properties)
          @optional_properties ||= []
          @optional_properties += optional_properties<commit_msg>Make it possible to send event w/o current_viewer<commit_after>require 'carto/tracking/services/pubsub_tracker'

require_dependency 'carto/tracking/formats/internal'
require_dependency 'carto/tracking/services/pubsub'
require_dependency 'carto/tracking/services/segment'
require_dependency 'carto/tracking/services/hubspot'
require_dependency 'carto/tracking/validators/visualization'
require_dependency 'carto/tracking/validators/layer'
require_dependency 'carto/tracking/validators/user'
require_dependency 'carto/tracking/validators/widget'

#  IMPORTANT: Events must be kept in sync with frontend!
#  See `/lib/assets/javascripts/builder/components/metrics/metrics-types.js`

DEFAULT_EVENT_VERSION = 1

module Carto
  module Tracking
    module Events
      class Event
        include ::LoggerHelper

        def initialize(reporter_id, properties)
          properties.merge!({event_version: event_version})

          @format = Carto::Tracking::Formats::Internal.new(properties)
          @reporter = Carto::User.find(reporter_id || properties[:user_id])
        end

        def name
          self.class.name.demodulize.underscore.humanize.capitalize
        end

        def event_version
          DEFAULT_EVENT_VERSION
        end

        def self.required_properties(*required_properties)
          @required_properties ||= []
          @required_properties += required_properties
        end

        def required_properties
          these_required_properties = self.class.instance_eval { @required_properties || [] }

          these_required_properties + self.class.superclass.required_properties
        end

        def self.optional_properties(*optional_properties)
          @optional_properties ||= []
          @optional_properties += optional_properties
{'fraction_non_alphanumeric': 0.08180778032036613, 'fraction_numerical': 0.0005720823798627002, 'mean_word_length': 3.559322033898305, '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': '2733909', 'n_tokens_mistral': 975, 'n_tokens_neox': 916, 'n_words': 163}