Skip to content

Commit

Permalink
Summary Costs
Browse files Browse the repository at this point in the history
  • Loading branch information
fboundy committed Apr 4, 2024
1 parent 6dc197d commit f9938a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
27 changes: 15 additions & 12 deletions apps/pv_opt/pv_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1647,8 +1647,10 @@ def optimise(self):

if not self.get_config("include_export"):
self.selected_case = "Optimised Charging"

elif not self.get_config("forced_discharge"):
self.selected_case = "Optimised PV Export"

else:
self.selected_case = "Forced Discharge"

Expand All @@ -1670,21 +1672,19 @@ def optimise(self):

self.ulog("Optimisation Summary")
self.log(f" {'Base cost:':40s} {self.optimised_cost['Base'].sum():6.1f}p")
cost_today = self._cost_actual().sum()
self.summary_costs = {
"Base": {"cost": ((self.optimised_cost["Base"].sum() + cost_today) / 100).round(2), "Selected": ""}
}
for case in cases:
str_log = f" {f'Optimised cost ({case}):':40s} {self.optimised_cost[case].sum():6.1f}p"
self.summary_costs[case] = {"cost": ((self.optimised_cost[case].sum() + cost_today) / 100).round(2)}
if case == self.selected_case:
str_log += " <=== Current Setup"
self.log(str_log)

# self.opt = self.pv_system.optimised_force(
# self.initial_soc,
# self.static,
# self.contract,
# solar="weighted",
# export=self.get_config("use_export"),
# discharge=self.get_config("forced_discharge"),
# )
# self.opt_cost = self.optimised_cost[selected_case]
self.summary_costs[case]["Selected"] = " <=== Current Setup"
else:
self.summary_costs[case]["Selected"] = ""

self.log(str_log + self.summary_costs[case]["Selected"])

self.opt = self.flows[self.selected_case]

Expand Down Expand Up @@ -2051,6 +2051,7 @@ def write_cost(
entity,
cost,
df,
attributes={},
):
cost_today = self._cost_actual()
midnight = pd.Timestamp.now(tz="UTC").normalize() + pd.Timedelta(24, "hours")
Expand Down Expand Up @@ -2087,6 +2088,7 @@ def write_cost(
}
| {col: df[["period_start", col]].to_dict("records") for col in cols if col in df.columns}
| {"cost": cost[["period_start", "cumulative_cost"]].to_dict("records")}
| attributes
)

self.write_to_hass(
Expand Down Expand Up @@ -2126,6 +2128,7 @@ def _write_output(self):
entity=f"sensor.{self.prefix}_opt_cost",
cost=self.optimised_cost[self.selected_case],
df=self.flows[self.selected_case],
attributes={"Summary": self.summary_costs},
)

self.write_to_hass(
Expand Down
5 changes: 2 additions & 3 deletions apps/pv_opt/pvpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ def optimised_force(self, initial_soc, static_flows, contract: Contract, **kwarg
consumption.name = "consumption"

discharge = kwargs.pop("discharge", False)
use_export = kwargs.pop("use_export", True)
use_export = kwargs.pop("export", True)
max_iters = kwargs.pop("max_iters", MAX_ITERS)

prices = pd.DataFrame()
Expand All @@ -613,13 +613,12 @@ def optimised_force(self, initial_soc, static_flows, contract: Contract, **kwarg
f"Optimiser prices loaded for period {prices.index[0].strftime(TIME_FORMAT)} - {prices.index[-1].strftime(TIME_FORMAT)}"
)

prices = prices.set_axis([t for t in contract.tariffs.keys() if contract.tariffs[t] is not None], axis=1)
if not use_export:
self.log(f"Ignoring export pricing because Use Export is turned off")
discharge = False
prices["export"] = 0

prices = prices.set_axis([t for t in contract.tariffs.keys() if contract.tariffs[t] is not None], axis=1)

df = pd.concat(
[prices, consumption, self.flows(initial_soc, static_flows, **kwargs)],
axis=1,
Expand Down

0 comments on commit f9938a3

Please sign in to comment.