Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Damien Jeandemange <damien.jeandemange@gmail.com>
  • Loading branch information
jeandemanged committed Nov 12, 2024
1 parent 5488efd commit f87f98a
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 20 deletions.
48 changes: 48 additions & 0 deletions yagat/frames/impl/buses_bus_breaker_view_list_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# Copyright (c) 2024, Damien Jeandemange (https://github.com/jeandemanged)
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# SPDX-License-Identifier: MPL-2.0
#
import os
import tkinter as tk

import pandas as pd
import pypowsybl.network as pn

from yagat.app_context import AppContext
from yagat.frames.impl.base_list_view import BaseListView


class BusesBusBreakerViewListView(BaseListView):

def __init__(self, parent, context: AppContext, *args, **kwargs):
BaseListView.__init__(self, parent, context, *args, **kwargs)

@property
def tab_name(self) -> str:
return 'Buses (Bus/Breaker View)'

def get_data_frame(self) -> pd.DataFrame:
return self.context.network_structure.buses_bus_breaker_view

def filter_data_frame(self, df: pd.DataFrame, voltage_levels: list[str]) -> pd.DataFrame:
return df.loc[df['voltage_level_id'].isin(voltage_levels)]


if __name__ == "__main__":

if os.name == 'nt':
# Fixing the blur UI on Windows
from ctypes import windll

windll.shcore.SetProcessDpiAwareness(2)
root = tk.Tk()
ctx = AppContext(root)
bw = BusesBusBreakerViewListView(root, ctx)
bw.pack(fill="both", expand=True)
ctx.network = pn.create_ieee9()
ctx.selection = ('network', '', None)
ctx.selected_tab = bw.tab_name
root.mainloop()
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
from yagat.frames.impl.base_list_view import BaseListView


class BusListView(BaseListView):
class BusesListView(BaseListView):

def __init__(self, parent, context: AppContext, *args, **kwargs):
BaseListView.__init__(self, parent, context, *args, **kwargs)

@property
def tab_name(self) -> str:
return 'Bus list'
return 'Buses (Bus View)'

def get_data_frame(self) -> pd.DataFrame:
return self.context.network_structure.buses
Expand All @@ -40,7 +40,7 @@ def filter_data_frame(self, df: pd.DataFrame, voltage_levels: list[str]) -> pd.D
windll.shcore.SetProcessDpiAwareness(2)
root = tk.Tk()
ctx = AppContext(root)
bw = BusListView(root, ctx)
bw = BusesListView(root, ctx)
bw.pack(fill="both", expand=True)
ctx.network = pn.create_ieee9()
ctx.selection = ('network', '', None)
Expand Down
2 changes: 1 addition & 1 deletion yagat/frames/impl/generator_list_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, parent, context: AppContext, *args, **kwargs):

@property
def tab_name(self) -> str:
return 'Generator list'
return 'Generators'

def get_data_frame(self) -> pd.DataFrame:
return self.context.network_structure.generators
Expand Down
2 changes: 1 addition & 1 deletion yagat/frames/impl/load_list_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, parent, context: AppContext, *args, **kwargs):

@property
def tab_name(self) -> str:
return 'Load list'
return 'Loads'

def get_data_frame(self) -> pd.DataFrame:
return self.context.network_structure.loads
Expand Down
20 changes: 11 additions & 9 deletions yagat/frames/impl/tabs_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

from yagat.app_context import AppContext
from yagat.frames.impl.diagram_view_bus import DiagramViewBus
from yagat.frames.impl.bus_list_view import BusListView
from yagat.frames.impl.buses_bus_view_list_view import BusesListView
from yagat.frames.impl.buses_bus_breaker_view_list_view import BusesBusBreakerViewListView
from yagat.frames.impl.generator_list_view import GeneratorListView
from yagat.frames.impl.load_list_view import LoadListView
from yagat.networkstructure import BusView
Expand All @@ -26,28 +27,29 @@ def __init__(self, parent, context: AppContext, *args, **kwargs):
self.tab_control.bind('<<NotebookTabChanged>>', lambda _: self.on_tab_changed())

# Bus-Breaker view tab
self.tab_bus_breaker = DiagramViewBus(self.tab_control, context, 'Bus-Breaker View', BusView.BUS_BREAKER)
self.tab_bus_breaker = DiagramViewBus(self.tab_control, context, 'Bus/Breaker View', BusView.BUS_BREAKER)
self.tab_control.add(self.tab_bus_breaker, text=self.tab_bus_breaker.tab_name)
self.tab_control.pack(expand=True, fill=tk.BOTH)

# Bus-Branch view tab
self.tab_bus_branch = DiagramViewBus(self.tab_control, context, 'Bus-Branch View', BusView.BUS_BRANCH)
self.tab_bus_branch = DiagramViewBus(self.tab_control, context, 'Bus View', BusView.BUS_BRANCH)
self.tab_control.add(self.tab_bus_branch, text=self.tab_bus_branch.tab_name)
self.tab_control.pack(expand=True, fill=tk.BOTH)

# Bus List view tab
self.tab_bus_list = BusListView(self.tab_control, context)
self.tab_bus_list = BusesListView(self.tab_control, context)
self.tab_control.add(self.tab_bus_list, text=self.tab_bus_list.tab_name)
self.tab_control.pack(expand=True, fill=tk.BOTH)

# Bus List view tab
self.tab_bus_bus_breaker_view_list = BusesBusBreakerViewListView(self.tab_control, context)
self.tab_control.add(self.tab_bus_bus_breaker_view_list, text=self.tab_bus_bus_breaker_view_list.tab_name)

# Generators List view tab
self.tab_gen_list = GeneratorListView(self.tab_control, context)
self.tab_control.add(self.tab_gen_list, text=self.tab_gen_list.tab_name)
self.tab_control.pack(expand=True, fill=tk.BOTH)

# Loads List view tab
self.tab_load_list = LoadListView(self.tab_control, context)
self.tab_control.add(self.tab_load_list, text=self.tab_load_list.tab_name)

self.tab_control.pack(expand=True, fill=tk.BOTH)

def on_tab_changed(self):
Expand All @@ -59,5 +61,5 @@ def on_tab_changed(self):
ctx = AppContext(root)
TabsView(root, ctx).pack(fill="both", expand=True)
ctx.network = pn.create_ieee9()
ctx.selection = 'S1'
ctx.selection = ('substation', 'S1', None)
root.mainloop()
18 changes: 12 additions & 6 deletions yagat/networkstructure/impl/network_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# SPDX-License-Identifier: MPL-2.0
#
import logging
from typing import Dict, List, Optional
from typing import Dict, List, Optional, Tuple

import pandas as pd
import pypowsybl.network as pn
Expand All @@ -19,7 +19,7 @@ def __init__(self, network: pn.Network):
self._network: pn.Network = network
self._substations: Dict[str, ns.Substation] = {}
self._voltage_levels: Dict[str, ns.VoltageLevel] = {}
self._connections: Dict[(str, Optional[int]), ns.Connection] = {}
self._connections: Dict[Tuple[str, Optional[int]], ns.Connection] = {}

self._substations_df: pd.DataFrame = pd.DataFrame()
self._voltage_levels_df: pd.DataFrame = pd.DataFrame()
Expand All @@ -29,6 +29,7 @@ def __init__(self, network: pn.Network):
self._three_windings_transformers_df: pd.DataFrame = pd.DataFrame()
self._tie_lines_df: pd.DataFrame = pd.DataFrame()
self._buses_df: pd.DataFrame = pd.DataFrame()
self._buses_bus_breaker_view_df: pd.DataFrame = pd.DataFrame()
self._switches_df: pd.DataFrame = pd.DataFrame()
self._hvdc_lines_df: pd.DataFrame = pd.DataFrame()

Expand Down Expand Up @@ -105,6 +106,10 @@ def network(self) -> pn.Network:
def buses(self) -> pd.DataFrame:
return self._buses_df

@property
def buses_bus_breaker_view(self) -> pd.DataFrame:
return self._buses_bus_breaker_view_df

@property
def generators(self) -> pd.DataFrame:
return self._injections_df[ns.EquipmentType.GENERATOR]
Expand Down Expand Up @@ -135,6 +140,7 @@ def refresh(self):
self._branches_df[ns.EquipmentType.TWO_WINDINGS_TRANSFORMER] = self._network.get_2_windings_transformers(
all_attributes=True)
self._buses_df = self._network.get_buses(all_attributes=True)
self._buses_bus_breaker_view_df = self._network.get_bus_breaker_view_buses(all_attributes=True)
self._linear_shunt_compensator_sections_df = self._network.get_linear_shunt_compensator_sections(
all_attributes=True)
self._non_linear_shunt_compensator_sections_df = self._network.get_non_linear_shunt_compensator_sections(
Expand Down Expand Up @@ -200,10 +206,10 @@ def get_connection(self, connection_id: str, side: Optional[int]) -> 'Optional[n
return self._connections[(connection_id, side)]
return None

def get_voltage_level_data(self, voltage_level: 'ns.VoltageLevel') -> pd.Series:
def get_voltage_level_data(self, voltage_level: 'ns.VoltageLevel') -> pd.DataFrame:
return self._voltage_levels_df.loc[voltage_level.voltage_level_id]

def get_connection_data(self, connection_id: str, side: Optional[int]) -> pd.Series:
def get_connection_data(self, connection_id: str, side: Optional[int]) -> pd.DataFrame:
connection = self._connections[(connection_id, side)]
if not connection:
return pd.Series()
Expand Down Expand Up @@ -235,12 +241,12 @@ def get_shunt_compensator_type(self, connection: ns.Connection) -> 'ns.ShuntComp
def is_retained(self, connection: ns.Connection) -> bool:
if connection.equipment_type != ns.EquipmentType.SWITCH:
raise RuntimeError('Not a switch')
return self._switches_df.loc[connection.equipment_id]['retained']
return bool(self._switches_df.loc[connection.equipment_id]['retained'])

def is_open(self, connection: ns.Connection) -> bool:
if connection.equipment_type != ns.EquipmentType.SWITCH:
raise RuntimeError('Not a switch')
return self._switches_df.loc[connection.equipment_id]['open']
return bool(self._switches_df.loc[connection.equipment_id]['open'])

def get_other_sides(self, connection: ns.Connection) -> List[ns.Connection]:
if connection.equipment_type in ns.EquipmentType.branch_types() or connection.equipment_type == ns.EquipmentType.SWITCH:
Expand Down

0 comments on commit f87f98a

Please sign in to comment.