<commit_before>module ThinkFeelDoDashboard
  module Concerns
    # adds validations to and associations to group class
    module Group
      extend ActiveSupport::Concern

      # This is perfect for including functionality
      # provided by 3rd party gems, etc.
      included do
        has_many :profile_questions,
                 class_name: "SocialNetworking::ProfileQuestion"
        belongs_to :moderator,
                   class_name: "User",
                   foreign_key: :moderator_id

        before_validation :create_moderator,
                          if: proc { |g| g.arm && g.arm.social? }

        validates :moderator_id,
                  presence: true,
                  if: proc { |g| g.arm && g.arm.social? }
      end

      def moderating_participant
        if active_memberships.count > 0
          active_participants.find_by_is_admin(true)
        end
      end

      # methods added to Class itself...
      module ClassMethods
      end

      private

      def create_moderator
        unless moderating_participant
          begin
            create_moderating_participant
          rescue ActiveRecord::RecordInvalid => e
            errors.add(:base, "There were errors: #{e}")
          end
        end
      end

      def create_moderating_participant
        days = ENV["MODERATOR_LIFESPAN"] || 36_525
        ActiveRecord::Base.transaction do
          participant = create_participant(SecureRandom.hex(8))
          create_profile(participant.id)
          memberships.build(
            participant_id: participant.id,
            start_date: Date.today,
            end_date: Date.today.advance(days: days)
          )
        end
      end

      def create_participant(study_id)
        password = <PASSWORD>(32) + <PASSWORD>
        ::Participant.create!(
          contact_preference: "email",
          display_name: Rails.application
                             .config
                             .moderating_participant_display_name,
          email: <EMAIL>",
          is_admin: true,
          password: password,
          password_confirmation: password,
          study_id: study_id
        )
      end

      def create_profile(participant_id)
        ::SocialNetworking::Profile.create!(
          participant_id: participant_id,
          icon_name: "admin",
          active: true
        )<commit_msg>Change base 16 to base 64<commit_after>module ThinkFeelDoDashboard
  module Concerns
    # adds validations to and associations to group class
    module Group
      extend ActiveSupport::Concern

      # This is perfect for including functionality
      # provided by 3rd party gems, etc.
      included do
        has_many :profile_questions,
                 class_name: "SocialNetworking::ProfileQuestion"
        belongs_to :moderator,
                   class_name: "User",
                   foreign_key: :moderator_id

        before_validation :create_moderator,
                          if: proc { |g| g.arm && g.arm.social? }

        validates :moderator_id,
                  presence: true,
                  if: proc { |g| g.arm && g.arm.social? }
      end

      def moderating_participant
        if active_memberships.count > 0
          active_participants.find_by_is_admin(true)
        end
      end

      # methods added to Class itself...
      module ClassMethods
      end

      private

      def create_moderator
        unless moderating_participant
          begin
            create_moderating_participant
          rescue ActiveRecord::RecordInvalid => e
            errors.add(:base, "There were errors: #{e}")
          end
        end
      end

      def create_moderating_participant
        days = ENV["MODERATOR_LIFESPAN"] || 36_525
        ActiveRecord::Base.transaction do
          participant = create_participant(SecureRandom.hex(8))
          create_profile(participant.id)
          memberships.build(
            participant_id: participant.id,
            start_date: Date.today,
            end_date: Date.today.advance(days: days)
          )
        end
      end

      def create_participant(study_id)
        password = SecureRandom.base64(16)
        ::Participant.create!(
          contact_preference: "email",
          display_name: Rails.application
                             .config
                             .moderating_participant_display_name,
          email: <EMAIL>",
          is_admin: true,
          password: password,
          password_confirmation: password,
          study_id: study_id
        )
      end

      def create_profile(participant_id)
        ::SocialNetworking::Profile.create!(
          participant_id: participant_id,
          icon_name: "admin",
          active: true
        )
{'fraction_non_alphanumeric': 0.06851618327028162, 'fraction_numerical': 0.00546448087431694, 'mean_word_length': 1.7620429483459084, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3828728', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1247, 'n_words': 290}