|
2 | 2 | import math
|
3 | 3 | import time
|
4 | 4 | import sys
|
| 5 | +from io import TextIOWrapper |
5 | 6 | from pathlib import Path
|
| 7 | +from typing import Any |
6 | 8 |
|
7 | 9 | # noinspection PyPackageRequirements
|
8 | 10 | import numpy as np
|
@@ -324,19 +326,6 @@ def PrintOutputs(self, model: Model):
|
324 | 326 | if model.surfaceplant.enduse_option.value in [EndUseOptions.ELECTRICITY]:
|
325 | 327 | f.write(f' Estimated Jobs Created: {model.economics.jobs_created.value}\n')
|
326 | 328 |
|
327 |
| - if econ.royalty_rate.Provided: |
328 |
| - for royalty_output in [ |
329 |
| - econ.royalty_holder_npv, |
330 |
| - econ.royalty_holder_annual_revenue, |
331 |
| - econ.royalty_holder_total_revenue |
332 |
| - ]: |
333 |
| - label = Outputs._field_label(royalty_output.display_name, 49) |
334 |
| - f.write( |
335 |
| - f' {label}{royalty_output.value:10.2f} {royalty_output.CurrentUnits.value}\n') |
336 |
| - |
337 |
| - |
338 |
| - |
339 |
| - |
340 | 329 | f.write(NL)
|
341 | 330 | f.write(' ***ENGINEERING PARAMETERS***\n')
|
342 | 331 | f.write(NL)
|
@@ -803,9 +792,25 @@ def PrintOutputs(self, model: Model):
|
803 | 792 |
|
804 | 793 | addon_df = pd.DataFrame()
|
805 | 794 | addon_results = []
|
| 795 | + extended_economics_header_printed = False |
806 | 796 | if model.economics.DoAddOnCalculations.value and not is_sam_econ_model:
|
807 | 797 | # SAM econ models incorporate add-on economics into main economics, not as separate extended economics.
|
808 | 798 | addon_df, addon_results = model.addoutputs.PrintOutputs(model)
|
| 799 | + extended_economics_header_printed = True |
| 800 | + |
| 801 | + if econ.royalty_rate.Provided: |
| 802 | + with open(self.output_file, 'a', encoding='UTF-8') as f_: |
| 803 | + if not extended_economics_header_printed: |
| 804 | + self._print_extended_economics_header(f_) |
| 805 | + |
| 806 | + for royalty_output in [ |
| 807 | + econ.royalty_holder_npv, |
| 808 | + econ.royalty_holder_annual_revenue, |
| 809 | + econ.royalty_holder_total_revenue |
| 810 | + ]: |
| 811 | + label = Outputs._field_label(royalty_output.display_name, 49) |
| 812 | + f_.write( |
| 813 | + f' {label}{royalty_output.value:10.2f} {royalty_output.CurrentUnits.value}\n') |
809 | 814 |
|
810 | 815 | sdac_df = pd.DataFrame()
|
811 | 816 | sdac_results = []
|
@@ -909,6 +914,24 @@ def get_sam_cash_flow_profile_output(self, model):
|
909 | 914 |
|
910 | 915 | return ret
|
911 | 916 |
|
| 917 | + def _print_extended_economics_header(self, f_output_file: TextIOWrapper | None = None) -> None: |
| 918 | + """ |
| 919 | + Header may be printed by either OutputsAddOns, or parent class if royalties are calculated and add-ons are not. |
| 920 | + """ |
| 921 | + |
| 922 | + close_f = False |
| 923 | + if f_output_file is None: |
| 924 | + f_output_file = open(self.output_file, 'a', encoding='UTF-8') |
| 925 | + close_f = True |
| 926 | + |
| 927 | + f_output_file.write(NL) |
| 928 | + f_output_file.write(NL) |
| 929 | + f_output_file.write(" ***EXTENDED ECONOMICS***\n") |
| 930 | + f_output_file.write(NL) |
| 931 | + |
| 932 | + if close_f: |
| 933 | + f_output_file.close() |
| 934 | + |
912 | 935 | @staticmethod
|
913 | 936 | def _field_label(field_name: str, print_width_before_value: int) -> str:
|
914 | 937 | return f'{field_name}:{" " * (print_width_before_value - len(field_name) - 1)}'
|
|
0 commit comments