<commit_before>module Qernel::RecursiveFactor::PrimaryDemand


  # Calculates the primary energy demand. It recursively iterates through all the child links.
  #
  # primary_demand: demand * SUM(links)[ link_share * 1/(1-share_of_loss) * primary_demand_link]
  #
  # It uses primary_energy_demand? to determine if primary or not.
  #
  def primary_demand
    fetch_and_rescue(:primary_demand) do
      primary_demand_share = recursive_factor(:primary_demand_factor)
      (self.demand || 0.0) * (primary_demand_share)
    end
  end

  def primary_demand_of(*carriers)
    carriers.flatten.map do |c|
      key = c.respond_to?(:key) ? c.key : c
      primary_demand_of_carrier(key)
    end.compact.sum
  end

  # Primary demand of multiple carriers.

  # Public: Calculates how much energy must be generated earlier in the graph -
  # matching the given +carriers+ keys - in order to fulfil demand of this
  # converter.
  #
  # You may supply one or more carrier keys. If you want to determine the
  # primary demand of multiple, related carriers, you MUST always call this
  # method once with all of the carrier keys, rather than calling it once PER
  # carrier and them summing the result. This is because multiple separate calls
  # may traverse the same edges, causing energy to be counted many times.
  #
  # A good example of this is with gas, where you may specifiy:
  #
  #   primary_demand_of_carriers(:network_gas, :natural_gas)
  #
  # If you were to do this:
  #
  #   SUM(
  #     primary_demand_of_carriers(:network_gas),
  #     primary_demand_of_carriers(:natural_gas))
  #
  # ... the natural gas which SUPPLIES the network gas converters would be
  # counted twice.
  #
  # Returns a numeric.
  def primary_demand_of_carriers(*carriers)
     if demand && ! demand.zero?<commit_msg>Remove unnecessary comment<commit_after>module Qernel::RecursiveFactor::PrimaryDemand


  # Calculates the primary energy demand. It recursively iterates through all the child links.
  #
  # primary_demand: demand * SUM(links)[ link_share * 1/(1-share_of_loss) * primary_demand_link]
  #
  # It uses primary_energy_demand? to determine if primary or not.
  #
  def primary_demand
    fetch_and_rescue(:primary_demand) do
      primary_demand_share = recursive_factor(:primary_demand_factor)
      (self.demand || 0.0) * (primary_demand_share)
    end
  end

  def primary_demand_of(*carriers)
    carriers.flatten.map do |c|
      key = c.respond_to?(:key) ? c.key : c
      primary_demand_of_carrier(key)
    end.compact.sum
  end

  # Public: Calculates how much energy must be generated earlier in the graph -
  # matching the given +carriers+ keys - in order to fulfil demand of this
  # converter.
  #
  # You may supply one or more carrier keys. If you want to determine the
  # primary demand of multiple, related carriers, you MUST always call this
  # method once with all of the carrier keys, rather than calling it once PER
  # carrier and them summing the result. This is because multiple separate calls
  # may traverse the same edges, causing energy to be counted many times.
  #
  # A good example of this is with gas, where you may specifiy:
  #
  #   primary_demand_of_carriers(:network_gas, :natural_gas)
  #
  # If you were to do this:
  #
  #   SUM(
  #     primary_demand_of_carriers(:network_gas),
  #     primary_demand_of_carriers(:natural_gas))
  #
  # ... the natural gas which SUPPLIES the network gas converters would be
  # counted twice.
  #
  # Returns a numeric.
  def primary_demand_of_carriers(*carriers)
     if demand && ! demand.zero?
{'fraction_non_alphanumeric': 0.07448893867264071, 'fraction_numerical': 0.0022402688322598714, 'mean_word_length': 3.5736235595390524, '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': '1211549', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1069, 'n_words': 376}