<commit_before>module SocialFramework
  # Module to construct Schedule Graph
  module ScheduleHelper
    autoload :GraphElements, 'graph_elements'

    # Define a Abstract Class to build slots to schedule
    class ScheduleStrategy
      # Init the slots and users in Array
      # ====== Params:
      # +elements_factory+:: +String+ Represent the factory class name to build
      # +max_duration+:: +ActiveSupport::Duration+ used to define max finish day to build graph
      # Returns Graph's Instance
      def initialize(elements_factory, max_duration)
        @elements_factory = elements_factory.new
        @slots = Array.new
        @max_duration = max_duration
      end

      # Build slots to verify availabilities
      # ====== Params:
      # +users+:: +Array+ users to check disponibility
      # +start_day+:: +Date+ start day to get slots
      # +finish_day+:: +Date+ finish day to get slots
      # +start_hour+:: +Time+ start hour at each day to get slots
      # +finish_hour+:: +Time+ finish hour at each day to get slots
      # +slots_size+:: +Integer+ slots size duration
      # Returns NotImplementedError
      def verify_availabilities(users, start_day, finish_day, start_hour, finish_hour, slots_size)
        raise 'Must implement method in subclass'
      end
    end

    # Represent the schedule on a Graph, with Vertices and Edges
    class ScheduleStrategyDefault < ScheduleStrategy
      # Init the slots and users in Array
      # ====== Params:
      # +elements_factory+:: +String+ Represent the factory class name to build
      # +max_duration+:: +ActiveSupport::Duration+ used to define max finish day to build graph
      # Returns Graph's Instance
      def initialize(elements_factory = ElementsFactoryDefault,
        max_duration = SocialFramework.max_duration_to_schedule_graph)
        super
        @users = Array.new
        @fixed_users = Array.new
      end

      # Build slots to verify availabilities
      # ====== Params:
      # +users+:: +Array+ users to check disponibility
      # +start_day+:: +Date+ start day to get slots
      # +finish_day+:: +Date+ finish day to get slots
      # +start_hour+:: +Time+ start hour at each day to get slots
      # +finish_hour+:: +Time+ finish hour at each day to get slots
      # +slots_size+:: +Integer+ slots size duration
      # Returns The Graph mounted
      def verify_availabilities(users, start_day, finish_day, start_hour = Time.parse("00:00"),
        finish_hour = Time.parse("23:59"), slots_size = SocialFramework.slots_size)

        return unless finish_day_ok? start_day, finish_day

        @slots_size = slots_size
        start_time = start_day.to_datetime + start_hour.seconds_since_midnight.seconds
        finish_time = finish_day.to_datetime + finish_hour.seconds_since_midnight.seconds

        build_users(users)
        build_slots(start_time, finish_time, start_hour, finish_hour)

        unless @fixed_users.empty?
          build_edges(@fixed_users, start_time, finish_time)

          @slots.select! { |slot| slot.edges.count == @fixed_users.count }
        end

        build_edges(@users, start_time, finish_time)

        @slots.sort_by! { |slot| -slot.attributes[:gained_weight] }
      end

      protected

      # Verify if finish day is between start day and max duration
      # ====== Params:
      # +start_day+:: +Date+ start day to get slots
      # +finish_day+:: +Date+ finish day to get slots
      # Returns true is ok or false if no
      def finish_day_ok?(start_day, finish_day)
        finish = start_day + @max_duration
        return finish_day <= finish
      end

      # Build slots whitin a period of time
      # ====== Params:
      # +current_time+:: +Datetime+ start date to build slots
      # +finish_time+:: +Datetime+ finish date to build slots
      # +start_hour+:: +Time+ start hour in days to build slots
      # +finish_hour+:: +Time+ finish hour in days to build slots
      # Returns schedule graph with slots
      def build_slots(current_time, finish_time, start_hour, finish_hour)
        while current_time < finish_time
          slots_quantity = get_slots_quantity(start_hour, finish_hour)

          (1..slots_quantity).each do
            verterx = @elements_factory.create_vertex(current_time, current_time.class, {gained_weight: 0})<commit_msg>adding duration attribute to slots<commit_after>module SocialFramework
  # Module to construct Schedule Graph
  module ScheduleHelper
    autoload :GraphElements, 'graph_elements'

    # Define a Abstract Class to build slots to schedule
    class ScheduleStrategy
      # Init the slots and users in Array
      # ====== Params:
      # +elements_factory+:: +String+ Represent the factory class name to build
      # +max_duration+:: +ActiveSupport::Duration+ used to define max finish day to build graph
      # Returns Graph's Instance
      def initialize(elements_factory, max_duration)
        @elements_factory = elements_factory.new
        @slots = Array.new
        @max_duration = max_duration
      end

      # Build slots to verify availabilities
      # ====== Params:
      # +users+:: +Array+ users to check disponibility
      # +start_day+:: +Date+ start day to get slots
      # +finish_day+:: +Date+ finish day to get slots
      # +start_hour+:: +Time+ start hour at each day to get slots
      # +finish_hour+:: +Time+ finish hour at each day to get slots
      # +slots_size+:: +Integer+ slots size duration
      # Returns NotImplementedError
      def verify_availabilities(users, start_day, finish_day, start_hour, finish_hour, slots_size)
        raise 'Must implement method in subclass'
      end
    end

    # Represent the schedule on a Graph, with Vertices and Edges
    class ScheduleStrategyDefault < ScheduleStrategy
      # Init the slots and users in Array
      # ====== Params:
      # +elements_factory+:: +String+ Represent the factory class name to build
      # +max_duration+:: +ActiveSupport::Duration+ used to define max finish day to build graph
      # Returns Graph's Instance
      def initialize(elements_factory = ElementsFactoryDefault,
        max_duration = SocialFramework.max_duration_to_schedule_graph)
        super
        @users = Array.new
        @fixed_users = Array.new
      end

      # Build slots to verify availabilities
      # ====== Params:
      # +users+:: +Array+ users to check disponibility
      # +start_day+:: +Date+ start day to get slots
      # +finish_day+:: +Date+ finish day to get slots
      # +start_hour+:: +Time+ start hour at each day to get slots
      # +finish_hour+:: +Time+ finish hour at each day to get slots
      # +slots_size+:: +Integer+ slots size duration
      # Returns The Graph mounted
      def verify_availabilities(users, start_day, finish_day, start_hour = Time.parse("00:00"),
        finish_hour = Time.parse("23:59"), slots_size = SocialFramework.slots_size)

        return unless finish_day_ok? start_day, finish_day

        @slots_size = slots_size
        start_time = start_day.to_datetime + start_hour.seconds_since_midnight.seconds
        finish_time = finish_day.to_datetime + finish_hour.seconds_since_midnight.seconds

        build_users(users)
        build_slots(start_time, finish_time, start_hour, finish_hour)

        unless @fixed_users.empty?
          build_edges(@fixed_users, start_time, finish_time)

          @slots.select! { |slot| slot.edges.count == @fixed_users.count }
        end

        build_edges(@users, start_time, finish_time)

        @slots.sort_by! { |slot| -slot.attributes[:gained_weight] }
      end

      protected

      # Verify if finish day is between start day and max duration
      # ====== Params:
      # +start_day+:: +Date+ start day to get slots
      # +finish_day+:: +Date+ finish day to get slots
      # Returns true is ok or false if no
      def finish_day_ok?(start_day, finish_day)
        finish = start_day + @max_duration
        return finish_day <= finish
      end

      # Build slots whitin a period of time
      # ====== Params:
      # +current_time+:: +Datetime+ start date to build slots
      # +finish_time+:: +Datetime+ finish date to build slots
      # +start_hour+:: +Time+ start hour in days to build slots
      # +finish_hour+:: +Time+ finish hour in days to build slots
      # Returns schedule graph with slots
      def build_slots(current_time, finish_time, start_hour, finish_hour)
        while current_time < finish_time
          slots_quantity = get_slots_quantity(start_hour, finish_hour)

          (1..slots_quantity).each do
            verterx = @elements_factory.create_vertex(current_time, current_time.class,
              {gained_weight: 0, duration: @slots_size})
{'fraction_non_alphanumeric': 0.08768913342503439, 'fraction_numerical': 0.0022925263640531865, 'mean_word_length': 3.0004585052728108, 'pattern_counts': {'":': 0, '<': 9, '<?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': '2394247', 'n_tokens_mistral': 2495, 'n_tokens_neox': 2434, 'n_words': 795}