Skip to content

Commit

Permalink
Improved get_injection_devices_grouped_by_group_type by checking all …
Browse files Browse the repository at this point in the history
…the None chances
  • Loading branch information
SanPen committed Sep 23, 2024
1 parent cc3290a commit 7968abe
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 49 deletions.
53 changes: 28 additions & 25 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/GridCal/Gui/Main/SubClasses/Results/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import GridCal.Gui.gui_functions as gf
from GridCal.Gui.messages import error_msg, warning_msg
from GridCal.Gui.Main.SubClasses.simulations import SimulationsMain
from GridCal.Session.results_model import ResultsModel
from GridCal.Gui.results_model import ResultsModel
from GridCal.Gui.general_dialogues import fill_tree_from_logs
import GridCalEngine.Utils.Filtering as flt
from GridCalEngine.basic_structures import Logger
Expand Down
2 changes: 1 addition & 1 deletion src/GridCal/Gui/SigmaAnalysis/sigma_analysis_dialogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from PySide6 import QtWidgets

from GridCal.Gui.SigmaAnalysis.gui import Ui_MainWindow
from GridCal.Session.results_model import ResultsModel
from GridCal.Gui.results_model import ResultsModel
from GridCalEngine.enumerations import ResultTypes
from GridCalEngine.Simulations.SigmaAnalysis.sigma_analysis_driver import SigmaAnalysisResults

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/GridCal/Session/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
from GridCalEngine.enumerations import ResultTypes, SimulationTypes
from GridCalEngine.Simulations.types import DRIVER_OBJECTS, RESULTS_OBJECTS
from GridCalEngine.basic_structures import Logger
from GridCal.Session.results_model import ResultsModel
from GridCal.Gui.results_model import ResultsModel


class GcThread(QThread):
Expand Down
10 changes: 10 additions & 0 deletions src/GridCalEngine/Devices/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4305,6 +4305,16 @@ def get_injection_devices(self) -> List[INJECTION_DEVICE_TYPES]:
elms += lst
return elms

def injection_items(self) -> Generator[INJECTION_DEVICE_TYPES, None, None]:
"""
Get a list of all devices that can inject or subtract power from a node
:return: List of EditableDevice
"""
for lst in self.get_injection_devices_lists():
for elm in lst:
yield elm


# ------------------------------------------------------------------------------------------------------------------
# Load-like devices
# ------------------------------------------------------------------------------------------------------------------
Expand Down
77 changes: 56 additions & 21 deletions src/GridCalEngine/Devices/multi_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1395,41 +1395,76 @@ def get_injection_devices_grouped_by_group_type(

devices_by_type = dict()

for lst in self.get_injection_devices_lists():
for elm in self.injection_items():

for elm in lst:

if group_type == DeviceType.AreaDevice:
if group_type == DeviceType.AreaDevice:
if elm.bus.area is not None:
matches = elm.bus.area == group_device
else:
matches = False

elif group_type == DeviceType.ZoneDevice:
elif group_type == DeviceType.ZoneDevice:
if elm.bus.zone is not None:
matches = elm.bus.zone == group_device
else:
matches = False

elif group_type == DeviceType.SubstationDevice:
elif group_type == DeviceType.SubstationDevice:
if elm.bus.substation is not None:
matches = elm.bus.substation == group_device
else:
matches = False

elif group_type == DeviceType.CountryDevice:
matches = ((elm.bus.country == group_device) or
(elm.bus.substation.country == group_device))

elif group_type == DeviceType.CommunityDevice:
matches = (elm.bus.substation.community == group_device)
elif group_type == DeviceType.CountryDevice:
if elm.bus.substation is not None:
matches = elm.bus.substation.country == group_device

elif group_type == DeviceType.RegionDevice:
matches = elm.bus.substation.region == group_device
if elm.bus.country is not None:
if elm.bus.substation.country != elm.bus.country:
print(f"Bus <{elm.bus.name}> country is different from its substation country :/")
else:
if elm.bus.country is not None:
matches = elm.bus.country == group_device
else:
matches = False

elif group_type == DeviceType.MunicipalityDevice:
matches = elm.bus.substation.municipality == group_device
elif group_type == DeviceType.CommunityDevice:
if elm.bus.substation is not None:
if elm.bus.substation.community is not None:
matches = elm.bus.substation.community == group_device
else:
matches = False
else:
matches = False

elif group_type == DeviceType.RegionDevice:
if elm.bus.substation is not None:
if elm.bus.substation.region is not None:
matches = elm.bus.substation.region == group_device
else:
matches = False
else:
matches = False

if matches:
lst = devices_by_type.get(elm.device_type, None)
if lst is None:
devices_by_type[elm.device_type] = [elm]
elif group_type == DeviceType.MunicipalityDevice:
if elm.bus.substation is not None:
if elm.bus.substation.municipality is not None:
matches = elm.bus.substation.municipality == group_device
else:
devices_by_type[elm.device_type].append(elm)
matches = False
else:
matches = False

else:
matches = False

# if we found a match ...
if matches:
lst = devices_by_type.get(elm.device_type, None)
if lst is None:
devices_by_type[elm.device_type] = [elm]
else:
devices_by_type[elm.device_type].append(elm)

result.append(devices_by_type)

Expand Down

0 comments on commit 7968abe

Please sign in to comment.