cantabile_edge, cantabile_modbus, cantabile_eebus 0.1.1789: full source
This commit is contained in:
1 parent
94f46db8f8
commit
b24675fe9c
25 files changed
+766
-40
No files matched your search
@@ -946,6 +946,8 @@ class Model:
|
||||
"lo_c": lo_c, "hi_c": hi_c, "heater": heater, "pmax": pmax, "cops": cops, "switched": switched,
|
||||
"eff": sup.curve["full"] if heater == "boiler" else None, "e_leg": e_leg, "window": window,
|
||||
"qmax": sup.qmax if sup else None,
|
||||
# a boiler-heated tank's fuel (gas or heating oil: the plan's series, plan_series)
|
||||
"fuel": sup.carrier if heater == "boiler" and sup else None,
|
||||
"src": "electric" if heater in ("element", "heat_pump") else heater})
|
||||
|
||||
def cover(self, d, room_ids):
|
||||
@@ -1307,6 +1309,10 @@ def plan(s: dict, time_limit: float = 30.0) -> dict:
|
||||
notes += m.notes
|
||||
if notes:
|
||||
out["notes"] = notes
|
||||
# the site's energy per carrier and use, per step for 24 h (the console's plan chart; methods A2.17)
|
||||
series = plan_series(s, m, x, outlook)
|
||||
if series:
|
||||
out["series"] = series
|
||||
steps_eur = step_costs(s, m, x)
|
||||
if steps_eur is not None:
|
||||
out["steps_eur"] = steps_eur # per step and carrier: with and without the plan (costs.py)
|
||||
@@ -1619,6 +1625,70 @@ def flexibility(m, x) -> dict:
|
||||
return out
|
||||
|
||||
|
||||
|
||||
def plan_series(s, m, x, outlook) -> dict:
|
||||
"""The plan's energy picture per step for the next 24 h (FLEX_STEPS; W,
|
||||
the mean power in the step: docs/methods.md A2.17), for the console's
|
||||
plan chart: electricity's sources (import_w, pv_w: the forecast, the
|
||||
battery's discharge) and uses (load_w: the house's own forecast,
|
||||
heating_w / cooling_w: electric heat and cooling, ev_w, dhw_element_w:
|
||||
a tank's electric heater, the battery's charge, export_w), and the other
|
||||
carriers' inputs: gas_w and oil_w (a boiler's fuel, Hi), heat_w (heat
|
||||
bought from a district or the building), dhw_w (hot water's heat drawn,
|
||||
where forecast); per hot-water tank its planned temperature
|
||||
("tank_c:<id>", °C). Only what the site has (a key absent: not in the plan,
|
||||
never 0 for it); the heat outlook (A2.16) adds its fixed heat as drawn."""
|
||||
n = min(m.T, FLEX_STEPS)
|
||||
out: dict[str, list] = {}
|
||||
|
||||
def add(key, t, w):
|
||||
out.setdefault(key, [0.0] * n)[t] += w
|
||||
|
||||
for t in range(n):
|
||||
add("import_w", t, x(m.gin[t]) + sum((x(v) for v in m.buy[t]), 0.0))
|
||||
add("export_w", t, x(m.gout[t]) + sum((x(v) for v in m.sell[t]), 0.0))
|
||||
add("load_w", t, max(0.0, float(s["load_w"][t])))
|
||||
if any(float(v) > 0 for v in s["pv_w"][:n]):
|
||||
out["pv_w"] = [max(0.0, float(v)) for v in s["pv_w"][:n]]
|
||||
temps = {}
|
||||
for did, (kind, v) in m.devices.items():
|
||||
if not v:
|
||||
continue
|
||||
if kind == "battery":
|
||||
for t in range(min(n, len(v["ch"]))):
|
||||
add("battery_charge_w", t, _x(x, v["ch"][t]))
|
||||
add("battery_discharge_w", t, _x(x, v["dis"][t]))
|
||||
continue
|
||||
if kind == "ev":
|
||||
for t in range(min(n, len(v["power"]))):
|
||||
add("ev_w", t, _x(x, v["power"][t]))
|
||||
continue
|
||||
if kind not in ("heating", "cooling", "dhw_tank"):
|
||||
continue
|
||||
el = "dhw_element_w" if kind == "dhw_tank" else kind + "_w"
|
||||
fuel = (v.get("fuel") or "gas") + "_w"
|
||||
for col, key in (("power", el), ("gas", fuel), ("district", "heat_w")):
|
||||
xs = v.get(col) or []
|
||||
if not any(c is not None and hasattr(c, "index") for c in xs[:n]):
|
||||
continue
|
||||
for t in range(min(n, len(xs))):
|
||||
add(key, t, _x(x, xs[t]))
|
||||
if kind == "dhw_tank":
|
||||
# its planned mean temperature at each step's end (°C, not W: "tank_c:<id>")
|
||||
temps["tank_c:" + did] = [round(tank_temp(v, t, x), 1) for t in range(min(n, len(v["e"])))]
|
||||
for t in range(min(n, len(v.get("draw") or []))):
|
||||
d = v["draw"][t]
|
||||
add("dhw_w", t, float(d) if isinstance(d, (int, float)) else _x(x, d))
|
||||
if outlook:
|
||||
key = {"gas": "gas_w", "oil": "oil_w", "heat": "heat_w"}.get(outlook.get("carrier"))
|
||||
for kind, ln in (outlook.get("lines") or {}).items():
|
||||
for t in range(min(n, len(ln["input_w"]))):
|
||||
if key:
|
||||
add(key, t, float(ln["input_w"][t]))
|
||||
if kind == "dhw":
|
||||
add("dhw_w", t, float(ln["heat_w"][t]))
|
||||
return {**{k: [round(w) for w in v] for k, v in out.items()}, **temps}
|
||||
|
||||
def _x(x, v) -> float:
|
||||
"""A step's value: a variable's, or 0 where there is none (an EV's steps after departure)."""
|
||||
return x(v) if v is not None and hasattr(v, "index") else 0.0
|
||||
|
||||
Reference in new issue
Block a user