|
1 | 1 | import math |
| 2 | +import os |
2 | 3 | import sys |
3 | 4 | import numpy as np |
4 | 5 | import numpy_financial as npf |
@@ -845,7 +846,7 @@ def __init__(self, model: Model): |
845 | 846 | Min=0.0, |
846 | 847 | Max=1.0, |
847 | 848 | UnitType=Units.PERCENT, |
848 | | - PreferredUnits=PercentUnit.PERCENT, |
| 849 | + PreferredUnits=PercentUnit.TENTH, |
849 | 850 | CurrentUnits=PercentUnit.TENTH, |
850 | 851 | ErrMessage=f'assume default discount rate ({discount_rate_default_val})', |
851 | 852 | ToolTipText="Discount rate used in the Standard Levelized Cost Model" |
@@ -1711,6 +1712,12 @@ def __init__(self, model: Model): |
1711 | 1712 | PreferredUnits=MassUnit.LB, |
1712 | 1713 | CurrentUnits=MassUnit.LB |
1713 | 1714 | ) |
| 1715 | + self.interest_rate = self.OutputParameterDict[self.interest_rate.Name] = OutputParameter( |
| 1716 | + Name='Interest Rate', |
| 1717 | + UnitType=Units.PERCENT, |
| 1718 | + PreferredUnits=PercentUnit.PERCENT, |
| 1719 | + CurrentUnits=PercentUnit.PERCENT |
| 1720 | + ) |
1714 | 1721 | self.TotalRevenue = self.OutputParameterDict[self.TotalRevenue.Name] = OutputParameter( |
1715 | 1722 | Name="Annual Revenue from Project", |
1716 | 1723 | UnitType=Units.CURRENCYFREQUENCY, |
@@ -2147,15 +2154,43 @@ def read_parameters(self, model: Model) -> None: |
2147 | 2154 | if key.startswith("AddOn"): |
2148 | 2155 | self.DoAddOnCalculations.value = True |
2149 | 2156 | break |
| 2157 | + |
2150 | 2158 | for key in model.InputParameters.keys(): |
2151 | 2159 | if key.startswith("S-DAC-GT"): |
2152 | 2160 | self.DoSDACGTCalculations.value = True |
2153 | 2161 | break |
2154 | 2162 |
|
2155 | 2163 | coerce_int_params_to_enum_values(self.ParameterDict) |
| 2164 | + self.sync_interest_rate(model) |
2156 | 2165 |
|
2157 | 2166 | model.logger.info(f'complete {__class__!s}: {sys._getframe().f_code.co_name}') |
2158 | 2167 |
|
| 2168 | + def sync_interest_rate(self, model): |
| 2169 | + def discount_rate_display() -> str: |
| 2170 | + return str(self.discountrate.quantity()).replace(' dimensionless', '') |
| 2171 | + |
| 2172 | + if self.discountrate.Provided ^ self.FixedInternalRate.Provided: |
| 2173 | + if self.discountrate.Provided: |
| 2174 | + self.FixedInternalRate.value = self.discountrate.quantity().to( |
| 2175 | + convertible_unit(self.FixedInternalRate.CurrentUnits)).magnitude |
| 2176 | + model.logger.info(f'Set {self.FixedInternalRate.Name} to {self.FixedInternalRate.quantity()} ' |
| 2177 | + f'because {self.discountrate.Name} was provided ({discount_rate_display()})') |
| 2178 | + else: |
| 2179 | + self.discountrate.value = self.FixedInternalRate.quantity().to( |
| 2180 | + convertible_unit(self.discountrate.CurrentUnits)).magnitude |
| 2181 | + model.logger.info( |
| 2182 | + f'Set {self.discountrate.Name} to {discount_rate_display()} because ' |
| 2183 | + f'{self.FixedInternalRate.Name} was provided ({self.FixedInternalRate.quantity()})') |
| 2184 | + |
| 2185 | + if self.discountrate.Provided and self.FixedInternalRate.Provided \ |
| 2186 | + and self.discountrate.quantity().to(convertible_unit(self.FixedInternalRate.CurrentUnits)).magnitude \ |
| 2187 | + != self.FixedInternalRate.value: |
| 2188 | + model.logger.warning(f'{self.discountrate.Name} and {self.FixedInternalRate.Name} provided with different ' |
| 2189 | + f'values ({discount_rate_display()}; {self.FixedInternalRate.quantity()}). ' |
| 2190 | + f'It is recommended to only provide one of these values.') |
| 2191 | + |
| 2192 | + self.interest_rate.value = self.discountrate.quantity().to(convertible_unit(self.interest_rate.CurrentUnits)).magnitude |
| 2193 | + |
2159 | 2194 | def Calculate(self, model: Model) -> None: |
2160 | 2195 | """ |
2161 | 2196 | The Calculate function is where all the calculations are done. |
|
0 commit comments