Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix loadmanagement for sub counter #1163

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions packages/control/algorithm/additional_current.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from control.loadmanagement import LimitingValue, Loadmanagement
from control.counter import Counter
from control.chargepoint.chargepoint import Chargepoint
from control.algorithm.filter_chargepoints import (get_chargepoints_by_mode, get_chargepoints_by_mode_and_counter,
from control.algorithm.filter_chargepoints import (get_chargepoints_by_mode_and_counter,
get_preferenced_chargepoint_charging)
from modules.common.utils.component_parser import get_component_name_by_id

Expand All @@ -17,7 +17,7 @@ def __init__(self) -> None:
pass

def set_additional_current(self, mode_range: List[int]) -> None:
self._reset_current()
common.reset_current_by_chargemode(common.CHARGEMODES[0:8])
for mode_tuple, counter in common.mode_and_counter_generator(mode_range):
preferenced_chargepoints, preferenced_cps_without_set_current = get_preferenced_chargepoint_charging(
get_chargepoints_by_mode_and_counter(mode_tuple, f"counter{counter.num}"))
Expand Down Expand Up @@ -48,14 +48,9 @@ def _set_loadmangement_message(self,
chargepoint: Chargepoint,
counter: Counter) -> None:
# Strom muss an diesem Zähler geändert werden
if (current != max(chargepoint.data.set.target_current, chargepoint.data.set.current) and
if (current != max(chargepoint.data.set.target_current, chargepoint.data.set.current or 0) and
# Strom erreicht nicht die vorgegebene Stromstärke
current != max(
chargepoint.data.set.charging_ev_data.data.control_parameter.required_currents)):
chargepoint.set_state_and_log(f"Es kann nicht mit der vorgegebenen Stromstärke geladen werden"
f"{limit.value.format(get_component_name_by_id(counter.num))}")

def _reset_current(self) -> None:
for mode in common.CHARGEMODES[0:8]:
for cp in get_chargepoints_by_mode(mode):
cp.data.set.current = 0
2 changes: 1 addition & 1 deletion packages/control/algorithm/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def calc_current(self) -> None:
self._check_auto_phase_switch_delay()
self.surplus_controlled.check_submode_pv_charging()
common.reset_current()
common.reset_current_to_target_current()
log.info("**Mindestrom setzen**")
self.min_current.set_min_current()
log.info("**Sollstrom setzen**")
Expand All @@ -43,6 +42,7 @@ def calc_current(self) -> None:
else:
log.info("**Keine Leistung für PV-geführtes Laden übrig.**")
self.no_current.set_no_current()
self.no_current.set_none_current()
except Exception:
log.exception("Fehler im Algorithmus-Modul")

Expand Down
24 changes: 16 additions & 8 deletions packages/control/algorithm/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Iterable, List, Optional, Tuple

from control import data
from control.algorithm.filter_chargepoints import get_chargepoints_by_mode
from control.chargemode import Chargemode
from control.chargepoint.chargepoint import Chargepoint
from control.counter import Counter
Expand Down Expand Up @@ -34,11 +35,18 @@
def reset_current():
for cp in data.data.cp_data.values():
try:
cp.data.set.current = 0
cp.data.set.current = None
cp.data.set.target_current = 0
except Exception:
log.exception(f"Fehler im Algorithmus-Modul für Ladepunkt{cp.num}")


def reset_current_by_chargemode(mode_tuple: Tuple[Optional[str], str, bool]) -> None:
for mode in mode_tuple:
for cp in get_chargepoints_by_mode(mode):
cp.data.set.current = None


def mode_range_list_factory() -> List[int]:
return [0, -1]

Expand Down Expand Up @@ -94,12 +102,12 @@ def get_current_to_set(set_current: float, diff: float, prev_current: float) ->
Zähler nicht zu untergraben. Der Vergleich muss positiv sein, wenn zum ersten Mal auf dieser Stufe ein Strom gesetzt
wird."""
new_current = prev_current + diff
if new_current > set_current and set_current != 0:
log.debug("Neuer Sollstrom darf nicht höher als bisher gesetzter sein: "
f"bisher {set_current}A, neuer {new_current}")
return set_current
else:
return new_current
if set_current is not None:
if new_current > set_current:
log.debug("Neuer Sollstrom darf nicht höher als bisher gesetzter sein: "
f"bisher {set_current}A, neuer {new_current}")
return set_current
return new_current

# tested

Expand Down Expand Up @@ -130,7 +138,7 @@ def update_raw_data(preferenced_chargepoints: List[Chargepoint],
continue
charging_ev_data = chargepoint.data.set.charging_ev_data
required_currents = charging_ev_data.data.control_parameter.required_currents
max_target_set_current = max(chargepoint.data.set.target_current, chargepoint.data.set.current)
max_target_set_current = max(chargepoint.data.set.target_current, chargepoint.data.set.current or 0)

if diff_to_zero is False:
if charging_ev_data.ev_template.data.min_current < max_target_set_current:
Expand Down
6 changes: 3 additions & 3 deletions packages/control/algorithm/common_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def cp() -> None:


@pytest.mark.parametrize("set_current, expected_current",
[pytest.param(6, 0),
pytest.param(0, 0)])
[pytest.param(6, None),
pytest.param(0, None)])
def test_reset_current(set_current: int, expected_current: int):
# setup
data.data.cp_data["cp0"].data.set.current = set_current
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_get_min_current(required_currents: List[float], expected_mins_counts: T
@pytest.mark.parametrize(
"set_current, diff, expected_current",
[
pytest.param(0, 2, 8, id="min current is set, no current has been set on this iteration"),
pytest.param(None, 2, 8, id="min current is set, no current has been set on this iteration"),
pytest.param(6, 2, 6, id="min current is set, current has been set on this iteration"),
pytest.param(7, 2, 7, id="new current is higher, current has been set on this iteration"),
pytest.param(9, 2, 8, id="new current is lower, current has been set on this iteration"),
Expand Down
11 changes: 7 additions & 4 deletions packages/control/algorithm/min_current.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ def set_min_current(self) -> None:
available_currents, limit = Loadmanagement().get_available_currents(missing_currents, counter)
available_for_cp = common.available_current_for_cp(
cp, counts, available_currents, missing_currents)
current = common.get_current_to_set(
cp.data.set.current, available_for_cp, cp.data.set.target_current)
if common.consider_not_charging_chargepoint_in_loadmanagement(cp):
cp.data.set.current = cp.data.set.charging_ev_data.ev_template.data.min_current
log.debug(
f"LP{cp.num}: Stromstärke {cp.data.set.charging_ev_data.ev_template.data.min_current}"
"A. Zuteilung ohne Berücksichtigung im Lastmanagement, da kein Ladestart zu erwarten "
"ist und Reserve für nicht-ladende inaktiv.")
else:
if available_for_cp < cp.data.set.charging_ev_data.ev_template.data.min_current:
common.set_current_counterdiff(-cp.data.set.current, 0, cp)
cp.set_state_and_log(
f"Ladung kann nicht gestartet werden{limit.value.format(counter.num)}")
if current < cp.data.set.charging_ev_data.ev_template.data.min_current:
common.set_current_counterdiff(-(cp.data.set.current or 0), 0, cp)
if limit:
cp.set_state_and_log(
f"Ladung kann nicht gestartet werden{limit.value.format(counter.num)}")
else:
common.set_current_counterdiff(
(cp.data.set.charging_ev_data.ev_template.data.min_current
Expand Down
6 changes: 6 additions & 0 deletions packages/control/algorithm/no_current.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from typing import List
from control import data

from control.algorithm.common import CHARGEMODES
from control.chargepoint.chargepoint import Chargepoint
Expand All @@ -18,3 +19,8 @@ def set_no_current(self) -> None:
chargepoints.extend(get_chargepoints_by_mode(mode))
for cp in chargepoints:
cp.data.set.current = 0

def set_none_current(self) -> None:
for cp in data.data.cp_data.values():
if cp.data.set.current is None:
cp.data.set.current = 0
9 changes: 2 additions & 7 deletions packages/control/algorithm/surplus_controlled.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from control.loadmanagement import LimitingValue, Loadmanagement
from control.counter import Counter
from control.chargepoint.chargepoint import Chargepoint
from control.algorithm.filter_chargepoints import (get_chargepoints_by_mode, get_chargepoints_by_mode_and_counter,
from control.algorithm.filter_chargepoints import (get_chargepoints_by_mode_and_counter,
get_preferenced_chargepoint_charging, get_chargepoints_pv_charging,
get_chargepoints_surplus_controlled)
from control.chargepoint.chargepoint_state import ChargepointState, CHARGING_STATES
Expand All @@ -20,7 +20,7 @@ def __init__(self) -> None:
pass

def set_surplus_current(self, mode_range) -> None:
self._reset_current()
common.reset_current_by_chargemode(common.CHARGEMODES[6:12])
for mode_tuple, counter in common.mode_and_counter_generator(mode_range):
preferenced_chargepoints, preferenced_cps_without_set_current = get_preferenced_chargepoint_charging(
get_chargepoints_by_mode_and_counter(mode_tuple, f"counter{counter.num}"))
Expand Down Expand Up @@ -58,11 +58,6 @@ def _set(self,
surplus=True)
chargepoints.pop(0)

def _reset_current(self) -> None:
for mode in common.CHARGEMODES[6:12]:
for cp in get_chargepoints_by_mode(mode):
cp.data.set.current = 0

def _set_loadmangement_message(self,
current: float,
limit: LimitingValue,
Expand Down