Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/models/qernel/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class Graph
Plugins::SimpleMeritOrder,
Plugins::Molecules,
Plugins::Causality,
Plugins::MaxDemandRecursive,
Plugins::ResettableSlots
].freeze

Expand Down
1 change: 0 additions & 1 deletion app/models/qernel/method_meta_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def calculation_methods
:weighted_carrier_cost_per_mj => {},
:weighted_carrier_co2_per_mj => {},
:sustainability_share => {},
:final_demand => {},
:primary_demand => {},
:primary_demand_of_fossil => {},
:primary_demand_of_sustainable => {}
Expand Down
1 change: 0 additions & 1 deletion app/models/qernel/node_api/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class Base

include RecursiveFactor::Base
include RecursiveFactor::WeightedCarrier
include RecursiveFactor::MaxDemand

# attributes updated by #initialize
attr_reader :node, :dataset_group, :dataset_key
Expand Down
2 changes: 0 additions & 2 deletions app/models/qernel/node_api/energy_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class EnergyApi < Base
include RecursiveFactor::PrimaryDemand
include RecursiveFactor::BioDemand
include RecursiveFactor::BioEmissions
include RecursiveFactor::DependentSupply
include RecursiveFactor::FinalDemand
include RecursiveFactor::PrimaryCo2
include RecursiveFactor::Sustainable

Expand Down
6 changes: 0 additions & 6 deletions app/models/qernel/node_api/fallback_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ def respond_to_missing?(name, include_private = false)
name.start_with?('cost_') ||
name.start_with?('primary_demand') ||
name.start_with?('demand_of_') ||
name.start_with?('dependent_supply') ||
name.start_with?('final_demand') ||
super
end

Expand All @@ -83,10 +81,6 @@ def method_missing(method_id, *arguments)
node.send(method_id, *arguments)
elsif /^demand_of_(\w*)$/.match?(method_id_s)
node.send(method_id, *arguments)
elsif /^dependent_supply(\w*)$/.match?(method_id_s)
node.send(method_id, *arguments)
elsif /^final_demand(\w*)$/.match?(method_id_s)
node.send(method_id, *arguments)
else
Rails.logger.info("NodeApi#method_missing: #{method_id}")
super(method_id)
Expand Down
23 changes: 0 additions & 23 deletions app/models/qernel/plugins/max_demand_recursive.rb

This file was deleted.

14 changes: 0 additions & 14 deletions app/models/qernel/recursive_factor/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,6 @@ def right_dead_end?
@right_dead_end
end

# Public: Determines if the node has any parents into which we should
# recurse when performing calculations. A domestic dead end includes when the
# node inputs are all abroad.
#
# Returns true or false.
def domestic_dead_end?
unless defined?(@domestic_dead_end)
@domestic_dead_end = right_dead_end? ||
input_edges.all? { |edge| edge.rgt_node.abroad? }
end

@domestic_dead_end
end

# Public: A combination of loss, treat-as-loss, and output efficiency compensation factors.
#
# Adjusts recursively calculated values for:
Expand Down
94 changes: 0 additions & 94 deletions app/models/qernel/recursive_factor/dependent_supply.rb

This file was deleted.

40 changes: 0 additions & 40 deletions app/models/qernel/recursive_factor/final_demand.rb

This file was deleted.

33 changes: 0 additions & 33 deletions app/models/qernel/recursive_factor/max_demand.rb

This file was deleted.

6 changes: 3 additions & 3 deletions app/models/qernel/recursive_factor/primary_co2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def free_co2_factor
def co2_per_mj_of_carrier_factor(edge, carrier_key)
return 0.0 if query.free_co2_factor == 1.0

return nil unless domestic_dead_end? || primary_energy_demand?
return nil unless right_dead_end? || primary_energy_demand?

edge ||= output_edges.first

Expand Down Expand Up @@ -116,9 +116,9 @@ def co2_per_mj_factor(edge, co2_free: free_co2_factor)
# In rare cases, we want to exclude a node from being included in the primary demand calculation
# while opting in to the CO2 calculation. This is done by omitting the node from the PD group
# and instead adding it to the "include_primary_co2" group.
force_co2 = domestic_dead_end? && @node.groups.include?(:force_primary_co2)
force_co2 = right_dead_end? && @node.groups.include?(:force_primary_co2)

return nil unless domestic_dead_end? || primary_energy_demand? || force_co2
return nil unless right_dead_end? || primary_energy_demand? || force_co2

edge ||= output_edges.first

Expand Down
2 changes: 1 addition & 1 deletion app/models/qernel/recursive_factor/primary_demand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def primary_demand_with(factor_method, node_share_method = nil)
end

def primary_demand_factor(_edge)
factor_for_primary_demand if primary_energy_demand? || domestic_dead_end?
factor_for_primary_demand if primary_energy_demand? || right_dead_end?
end

def primary_demand_including_abroad_factor(_edge)
Expand Down
2 changes: 1 addition & 1 deletion app/models/qernel/recursive_factor/sustainable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def sustainability_share
end

def sustainability_share_factor(edge)
return nil unless domestic_dead_end? || primary_energy_demand?
return nil unless right_dead_end? || primary_energy_demand?

# Called sustainability_share directly on a domestic or primary node.
return query.dataset_get(:sustainability_share) unless edge
Expand Down
6 changes: 3 additions & 3 deletions app/models/qernel/recursive_factor/weighted_carrier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def weighted_carrier_cost_per_mj_factor(edge)

# Carriers with no or zero intrinsic costs are not counted in this calculation.

edge.carrier.cost_per_mj if edge.carrier.cost_per_mj || domestic_dead_end?
edge.carrier.cost_per_mj if edge.carrier.cost_per_mj || right_dead_end?

# Else: continue traversing right.
end
Expand All @@ -31,7 +31,7 @@ def weighted_carrier_co2_per_mj_factor(edge)

# Carriers with no or zero intrinsic CO2 are not counted in this calculation.

if edge.carrier.co2_conversion_per_mj || domestic_dead_end?
if edge.carrier.co2_conversion_per_mj || right_dead_end?
edge.carrier.co2_conversion_per_mj
end

Expand All @@ -51,7 +51,7 @@ def weighted_carrier_potential_co2_per_mj_factor(edge)
# Carriers with no or zero intrinsic biogenic CO2 capture potential are not
# counted in this calculation.

if edge.carrier.potential_co2_conversion_per_mj || domestic_dead_end?
if edge.carrier.potential_co2_conversion_per_mj || right_dead_end?
edge.carrier.potential_co2_conversion_per_mj
end

Expand Down
18 changes: 5 additions & 13 deletions app/serializers/application_demands_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Presents the primary and final demands of application_group nodes
# Presents the primary demands of application_group nodes
# as a CSV file.
class ApplicationDemandsSerializer
attr_reader :final_carriers, :primary_carriers
attr_reader :primary_carriers

# Creates a new application demands serializer.
#
Expand All @@ -22,8 +22,7 @@ def as_csv(*)
CSV.generate do |csv|
csv << [
'key', 'primary_co2_emission',
*primary_carriers.map { |c| "primary_demand_of_#{c} (MJ)" },
*final_carriers.map { |c| "final_demand_of_#{c} (MJ)" }
*primary_carriers.map { |c| "primary_demand_of_#{c} (MJ)" }
]

@graph.group_nodes(:application_group).each do |node|
Expand All @@ -40,29 +39,22 @@ def node_row(node)
[
node.key,
node.query.primary_co2_emission,
*primary_carriers.map { |ca| node.query.primary_demand_of(ca) },
*final_carriers.map { |ca| node.query.final_demand_of(ca) }
*primary_carriers.map { |ca| node.query.primary_demand_of(ca) }
]
end

# Internal: Determines those carriers which may have a non-zero primary
# or final demand, so as not to waste time calculating values which will
# demand, so as not to waste time calculating values which will
# always be zero.
def populate_carriers!
primary_carriers = Set.new
final_carriers = Set.new

@graph.nodes.each do |conv|
if conv.query.right_dead_end? || conv.primary_energy_demand?
primary_carriers.merge(conv.outputs.map { |c| c.carrier.key })
end

if conv.final_demand_group?
final_carriers.merge(conv.outputs.map { |c| c.carrier.key })
end
end

@primary_carriers = primary_carriers.to_a.sort
@final_carriers = final_carriers.to_a.sort
end
end
Loading