<commit_before>module Network
  # Represents a generic technology within the testing ground, which may have a
  # capacity and profile, or a constant load.
  class Technology
    # Public: Creates a new Technology instance, suited to represent the given
    # InstalledTechnology in the network calculation.
    #
    # Returns a Technology.
    def self.from_installed(installed, profile, options = {})
      behaviors[
        installed.behavior.presence || installed.technology.behavior
      ].build(installed, profile, options)
    end

    # Public: A hash containing the permitted behaviors which may be used by
    # technologies in the testing ground.
    def self.behaviors
      @behaviors ||=
        Hash.new { Technology }.tap do |behaviors|
          behaviors['storage']          = Storage
          behaviors['electric_vehicle'] = ElectricVehicle
          behaviors['buffer']           = Buffer
          behaviors['siphon']           = Siphon
        end.freeze
    end

    def self.build(installed, profile, _options)
      new(installed, profile)
    end

    attr_reader :installed, :profile

    def initialize(installed, profile)
      @installed = installed
      @profile   = profile
    end

    def load_at(frame)
      @profile.at(frame)
    end

    # Public: Determines the minimum amount of energy the technology consumes in
    # a given time-step.
    #
    # Mandatory consumption describes the amount of load which must be assigned
    # to the technology, regardless of excesses or deficits in the network.
    #
    # If the mandatory load of all consumers in the network exceeds
    # total production, the deficit will be supplied from the external grid.
    #
    # Returns a numeric.
    def mandatory_consumption_at(frame)
      consumer? ? load_at(frame) : 0.0
    end

    # Public: Determines the extra amount of energy the technology *may* consume
    # in addition to its mandatory load.
    #
    # Conditional load describes extra load which a technology may want if there
    # is an excess of production in the network. A common example might be the
    # remaining capacity in a battery, which should be fulfilled if there is
    # enough excess elsewhere.
    #
    # Returns a numeric.
    def conditional_consumption_at(frame)
      0.0
    end

    # Public: Determines the energy produced by the technology in the given
    # time-step.
    #
    # Returns a numeric.
    def production_at(frame)
      producer? ? load_at(frame).abs : 0.0
    end

    def capacity
      @installed.capacity || @installed.load || 0.0
    end

    def volume
      @installed.storage || Float::INFINITY
    end

    def consumer?
      capacity.present? && capacity > 0 ||
        @installed.demand ||
        # When storage is disabled, it may turn into a normal technology in
        # order to draw load -- but NOT store -- from the network.
        @installed.storage
    end

    def producer?
      not consumer?<commit_msg>Default technology is a consumer<commit_after>module Network
  # Represents a generic technology within the testing ground, which may have a
  # capacity and profile, or a constant load.
  class Technology
    # Public: Creates a new Technology instance, suited to represent the given
    # InstalledTechnology in the network calculation.
    #
    # Returns a Technology.
    def self.from_installed(installed, profile, options = {})
      behaviors[
        installed.behavior.presence || installed.technology.behavior
      ].build(installed, profile, options)
    end

    # Public: A hash containing the permitted behaviors which may be used by
    # technologies in the testing ground.
    def self.behaviors
      @behaviors ||=
        Hash.new { Technology }.tap do |behaviors|
          behaviors['storage']          = Storage
          behaviors['electric_vehicle'] = ElectricVehicle
          behaviors['buffer']           = Buffer
          behaviors['siphon']           = Siphon
        end.freeze
    end

    def self.build(installed, profile, _options)
      new(installed, profile)
    end

    attr_reader :installed, :profile

    def initialize(installed, profile)
      @installed = installed
      @profile   = profile
    end

    def load_at(frame)
      @profile.at(frame)
    end

    # Public: Determines the minimum amount of energy the technology consumes in
    # a given time-step.
    #
    # Mandatory consumption describes the amount of load which must be assigned
    # to the technology, regardless of excesses or deficits in the network.
    #
    # If the mandatory load of all consumers in the network exceeds
    # total production, the deficit will be supplied from the external grid.
    #
    # Returns a numeric.
    def mandatory_consumption_at(frame)
      consumer? ? load_at(frame) : 0.0
    end

    # Public: Determines the extra amount of energy the technology *may* consume
    # in addition to its mandatory load.
    #
    # Conditional load describes extra load which a technology may want if there
    # is an excess of production in the network. A common example might be the
    # remaining capacity in a battery, which should be fulfilled if there is
    # enough excess elsewhere.
    #
    # Returns a numeric.
    def conditional_consumption_at(frame)
      0.0
    end

    # Public: Determines the energy produced by the technology in the given
    # time-step.
    #
    # Returns a numeric.
    def production_at(frame)
      producer? ? load_at(frame).abs : 0.0
    end

    def capacity
      @installed.capacity || @installed.load || 0.0
    end

    def volume
      @installed.storage || Float::INFINITY
    end

    def consumer?
      capacity.present? && capacity >= 0 ||
        @installed.demand ||
        # When storage is disabled, it may turn into a normal technology in
        # order to draw load -- but NOT store -- from the network.
        @installed.storage
    end

    def producer?
      not consumer?
{'fraction_non_alphanumeric': 0.06690140845070422, 'fraction_numerical': 0.0030181086519114686, 'mean_word_length': 2.502642395772167, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3081062', 'n_tokens_mistral': 1597, 'n_tokens_neox': 1524, 'n_words': 619}