Implement flexible charging strategies for subset of charging parks #558
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #330
Type of change
Please delete options that are not relevant.
Summary
This PR allows charging strategies to be applied to a subset of charging parks instead of always to all integrated charging parks. This makes it possible to combine different charging strategies within the same EDisGo instance (e.g. some charging parks using
residual, others usingdumb).Changes
EDisGo.apply_charging_strategyto accept an optional argumentcharging_park_ids: Iterable[int] | None.charging_park_idsisNone(default), behaviour is unchanged: the strategy is applied to all integrated charging parks.flex_opt.charging_strategies.charging_strategyto:charging_park_idsargument.target_park_idsas the intersection of the provided IDs with the indices ofintegrated_charging_parks_df.charging_parksandcharging_processes_dftotarget_park_ids."dumb","reduced"and"residual"working as before, but applied to the filtered subset whencharging_park_idsis set, preserving backward compatibility when it is not provided.Implementation details
EDisGo.apply_charging_strategyremains a thin wrapper aroundcharging_strategy, now forwarding the optionalcharging_park_idsargument.charging_strategy:integrated_parksis derived fromedisgo_obj.electromobility.integrated_charging_parks_df.target_park_idsis computed fromcharging_park_ids(or all integrated parks ifNone).edisgo_ids_to_updateis taken fromintegrated_parks.loc[target_park_ids, "edisgo_id"]."residual"strategy,charging_processes_dfis restricted totarget_park_idsinstead of all integrated charging parks.edisgo_ids_to_update, so multiple calls with different subsets do not overwrite each other’s results.Checklist:
pre-commithooks(existing test suite still passes; no new tests added)