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
6 changes: 3 additions & 3 deletions biosteam/_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -4401,7 +4401,7 @@ def _to_network(self):

def results(self, with_units=True):
"""
Return a DataFrame of key results from simulation.
Return key simulation results as a DataFrame, or a Series without units.
"""
keys = []; addkey = keys.append
vals = []; addval = vals.append
Expand Down Expand Up @@ -4467,13 +4467,13 @@ def results(self, with_units=True):
addval(heat_utility.flow)
addkey((ID, 'Cost'))
addval(heat_utility.cost)
for name, flow in self.get_inlet_utility_flows().items():
for name, flow in self.get_inlet_cost_flows().items():
ID = name + ' (inlet)'
addkey((ID, 'Flow'))
addval(flow)
addkey((ID, 'Cost'))
addval(flow * stream_prices[name])
for name, flow in self.get_outlet_utility_flows().items():
for name, flow in self.get_outlet_revenue_flows().items():
ID = name + ' (outlet)'
addkey((ID, 'Flow'))
addval(flow)
Expand Down
22 changes: 22 additions & 0 deletions tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ def test_unit_result_tables(system):
columns = ['Units', 'H1', 'Units', 'M1']
assert [i for df in results for i in df] == columns

@pytest.mark.parametrize('with_stream_fees', [False, True])
def test_system_results_without_units(system, monkeypatch, with_stream_fees):
if with_stream_fees:
monkeypatch.setitem(bst.stream_prices, 'Mock feed fee', 0.01)
monkeypatch.setitem(bst.stream_prices, 'Mock product credit', 0.02)
mixer = system.flowsheet.unit.M1
heater = system.flowsheet.unit.H1
mixer.define_fee('Mock feed fee', mixer.ins[0])
heater.define_credit('Mock product credit', heater.outs[0])
system.simulate()
expected = system.results()[system.ID]
results = system.results(with_units=False)
assert results.index.equals(expected.index)
assert results.name == system.ID
assert_allclose(results.values, expected.values)
if with_stream_fees:
flow = mixer.ins[0].F_mass
assert results['Mock feed fee (inlet)', 'Flow'] == flow
assert results['Mock feed fee (inlet)', 'Cost'] == flow * 0.01
assert results['Mock product credit (outlet)', 'Flow'] == flow
assert results['Mock product credit (outlet)', 'Cost'] == -flow * 0.02

def test_cost_table(tea):
df = bst.report.cost_table(tea)
columns = ['Unit operation',
Expand Down
Loading