Spaces:
Sleeping
Sleeping
Durand D'souza
commited on
Enhance schema documentation and improve property definitions in SolarPVAssumptions model; add source code button in UI
Browse files
schema.py
CHANGED
|
@@ -3,7 +3,9 @@ from pydantic import BaseModel, Field, computed_field, field_validator, model_va
|
|
| 3 |
|
| 4 |
|
| 5 |
class SolarPVAssumptions(BaseModel):
|
| 6 |
-
capacity_mw: Annotated[
|
|
|
|
|
|
|
| 7 |
capacity_factor: Annotated[
|
| 8 |
float,
|
| 9 |
Field(
|
|
@@ -93,43 +95,75 @@ class SolarPVAssumptions(BaseModel):
|
|
| 93 |
Field(
|
| 94 |
title="Target DSCR?",
|
| 95 |
description="Whether to target the DSCR or the debt percentage. If True, the DCSR will be used to calculate the debt percentage.",
|
| 96 |
-
)
|
| 97 |
] = True
|
| 98 |
|
| 99 |
@model_validator(mode="after")
|
| 100 |
def check_sum_of_parts(self):
|
| 101 |
if not self.targetting_dcsr:
|
| 102 |
-
assert
|
|
|
|
|
|
|
| 103 |
if self.debt_pct_of_capital_cost + self.equity_pct_of_capital_cost != 1:
|
| 104 |
raise ValueError("Debt and equity percentages must sum to 1")
|
| 105 |
return self
|
| 106 |
|
| 107 |
@computed_field
|
| 108 |
@property
|
| 109 |
-
def capital_cost(
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
| 111 |
return self.capacity_mw * self.capital_expenditure_per_kw * 1000
|
| 112 |
|
| 113 |
@computed_field
|
| 114 |
@property
|
| 115 |
-
def tax_adjusted_WACC(
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
@computed_field
|
| 123 |
@property
|
| 124 |
-
def wacc(
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
@computed_field
|
| 129 |
@property
|
| 130 |
-
def equity_pct_of_capital_cost(
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
if self.debt_pct_of_capital_cost is not None:
|
| 134 |
return 1 - self.debt_pct_of_capital_cost
|
| 135 |
|
|
@@ -137,6 +171,7 @@ class SolarPVAssumptions(BaseModel):
|
|
| 137 |
@classmethod
|
| 138 |
def empty_str_to_none(cls, values):
|
| 139 |
if isinstance(values, dict):
|
| 140 |
-
return {
|
|
|
|
|
|
|
| 141 |
return values
|
| 142 |
-
|
|
|
|
| 3 |
|
| 4 |
|
| 5 |
class SolarPVAssumptions(BaseModel):
|
| 6 |
+
capacity_mw: Annotated[
|
| 7 |
+
float, Field(ge=1, le=1000, title="Capacity (MW)", description="Capacity in MW")
|
| 8 |
+
] = 30
|
| 9 |
capacity_factor: Annotated[
|
| 10 |
float,
|
| 11 |
Field(
|
|
|
|
| 95 |
Field(
|
| 96 |
title="Target DSCR?",
|
| 97 |
description="Whether to target the DSCR or the debt percentage. If True, the DCSR will be used to calculate the debt percentage.",
|
| 98 |
+
),
|
| 99 |
] = True
|
| 100 |
|
| 101 |
@model_validator(mode="after")
|
| 102 |
def check_sum_of_parts(self):
|
| 103 |
if not self.targetting_dcsr:
|
| 104 |
+
assert (
|
| 105 |
+
self.debt_pct_of_capital_cost is not None
|
| 106 |
+
), "Debt percentage must be provided"
|
| 107 |
if self.debt_pct_of_capital_cost + self.equity_pct_of_capital_cost != 1:
|
| 108 |
raise ValueError("Debt and equity percentages must sum to 1")
|
| 109 |
return self
|
| 110 |
|
| 111 |
@computed_field
|
| 112 |
@property
|
| 113 |
+
def capital_cost(
|
| 114 |
+
self,
|
| 115 |
+
) -> Annotated[
|
| 116 |
+
float, Field(title="Capital Cost ($)", description="Total capital cost")
|
| 117 |
+
]:
|
| 118 |
return self.capacity_mw * self.capital_expenditure_per_kw * 1000
|
| 119 |
|
| 120 |
@computed_field
|
| 121 |
@property
|
| 122 |
+
def tax_adjusted_WACC(
|
| 123 |
+
self,
|
| 124 |
+
) -> Annotated[
|
| 125 |
+
Optional[float],
|
| 126 |
+
Field(
|
| 127 |
+
title="Tax Adjusted WACC (%)",
|
| 128 |
+
description="Tax adjusted weighted average cost of capital",
|
| 129 |
+
),
|
| 130 |
+
]:
|
| 131 |
+
if (self.debt_pct_of_capital_cost is not None) and (
|
| 132 |
+
self.equity_pct_of_capital_cost is not None
|
| 133 |
+
):
|
| 134 |
+
return (
|
| 135 |
+
self.debt_pct_of_capital_cost * self.cost_of_debt * (1 - self.tax_rate)
|
| 136 |
+
+ self.equity_pct_of_capital_cost * self.cost_of_equity
|
| 137 |
+
)
|
| 138 |
|
| 139 |
@computed_field
|
| 140 |
@property
|
| 141 |
+
def wacc(
|
| 142 |
+
self,
|
| 143 |
+
) -> Annotated[
|
| 144 |
+
Optional[float],
|
| 145 |
+
Field(title="WACC (%)", description="Weighted average cost of capital"),
|
| 146 |
+
]:
|
| 147 |
+
if (
|
| 148 |
+
self.debt_pct_of_capital_cost is not None
|
| 149 |
+
and self.equity_pct_of_capital_cost is not None
|
| 150 |
+
):
|
| 151 |
+
return (
|
| 152 |
+
self.debt_pct_of_capital_cost * self.cost_of_debt
|
| 153 |
+
+ self.equity_pct_of_capital_cost * self.cost_of_equity
|
| 154 |
+
)
|
| 155 |
|
| 156 |
@computed_field
|
| 157 |
@property
|
| 158 |
+
def equity_pct_of_capital_cost(
|
| 159 |
+
self,
|
| 160 |
+
) -> Annotated[
|
| 161 |
+
Optional[float],
|
| 162 |
+
Field(
|
| 163 |
+
title="Equity Percentage (%)",
|
| 164 |
+
description="Equity as a percentage of capital expenditure",
|
| 165 |
+
),
|
| 166 |
+
]:
|
| 167 |
if self.debt_pct_of_capital_cost is not None:
|
| 168 |
return 1 - self.debt_pct_of_capital_cost
|
| 169 |
|
|
|
|
| 171 |
@classmethod
|
| 172 |
def empty_str_to_none(cls, values):
|
| 173 |
if isinstance(values, dict):
|
| 174 |
+
return {
|
| 175 |
+
k: (None if v == "" or v == "None" else v) for k, v in values.items()
|
| 176 |
+
}
|
| 177 |
return values
|
|
|
ui.py
CHANGED
|
@@ -396,6 +396,9 @@ with gr.Blocks(theme="citrus", title="Renewable LCOE API") as interface:
|
|
| 396 |
cashflow_bar_chart = gr.Plot()
|
| 397 |
with gr.Row():
|
| 398 |
model_output = gr.Matrix(headers=None, max_height=800)
|
|
|
|
|
|
|
|
|
|
| 399 |
|
| 400 |
# Set up event handlers for all inputs
|
| 401 |
input_components = [
|
|
|
|
| 396 |
cashflow_bar_chart = gr.Plot()
|
| 397 |
with gr.Row():
|
| 398 |
model_output = gr.Matrix(headers=None, max_height=800)
|
| 399 |
+
with gr.Row():
|
| 400 |
+
with gr.Column(scale=1):
|
| 401 |
+
gr.Button(link="https://github.com/dldx/renewables-lcoe-api", value="Source Code", variant="secondary", size="sm")
|
| 402 |
|
| 403 |
# Set up event handlers for all inputs
|
| 404 |
input_components = [
|