Skip to content

Commit

Permalink
lines and 2wt
Browse files Browse the repository at this point in the history
Signed-off-by: Damien Jeandemange <[email protected]>
  • Loading branch information
jeandemanged committed Nov 12, 2024
1 parent f87f98a commit 3182365
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
48 changes: 48 additions & 0 deletions yagat/frames/impl/line_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 LineListView(BaseListView):

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

@property
def tab_name(self) -> str:
return 'Lines'

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

def filter_data_frame(self, df: pd.DataFrame, voltage_levels: list[str]) -> pd.DataFrame:
return df.loc[df['voltage_level1_id'].isin(voltage_levels) | df['voltage_level2_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 = LineListView(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()
9 changes: 9 additions & 0 deletions yagat/frames/impl/tabs_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
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.frames.impl.line_list_view import LineListView
from yagat.frames.impl.two_windings_transformer_list_view import TwoWindingsTransformerListView
from yagat.networkstructure import BusView


Expand Down Expand Up @@ -50,6 +52,13 @@ def __init__(self, parent, context: AppContext, *args, **kwargs):
self.tab_load_list = LoadListView(self.tab_control, context)
self.tab_control.add(self.tab_load_list, text=self.tab_load_list.tab_name)

# Lines List view tab
self.tab_lines_list = LineListView(self.tab_control, context)
self.tab_control.add(self.tab_lines_list, text=self.tab_lines_list.tab_name)

self.tab_t2wt_list = TwoWindingsTransformerListView(self.tab_control, context)
self.tab_control.add(self.tab_t2wt_list, text=self.tab_t2wt_list.tab_name)

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

def on_tab_changed(self):
Expand Down
48 changes: 48 additions & 0 deletions yagat/frames/impl/two_windings_transformer_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 TwoWindingsTransformerListView(BaseListView):

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

@property
def tab_name(self) -> str:
return '2W Transformers'

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

def filter_data_frame(self, df: pd.DataFrame, voltage_levels: list[str]) -> pd.DataFrame:
return df.loc[df['voltage_level1_id'].isin(voltage_levels) | df['voltage_level2_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 = TwoWindingsTransformerListView(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()
8 changes: 8 additions & 0 deletions yagat/networkstructure/impl/network_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ def generators(self) -> pd.DataFrame:
def loads(self) -> pd.DataFrame:
return self._injections_df[ns.EquipmentType.LOAD]

@property
def lines(self) -> pd.DataFrame:
return self._branches_df[ns.EquipmentType.LINE]

@property
def two_windings_transformers(self) -> pd.DataFrame:
return self._branches_df[ns.EquipmentType.TWO_WINDINGS_TRANSFORMER]

def refresh(self):
logging.info('refresh start')
self._substations_df = self._network.get_substations(all_attributes=True)
Expand Down

0 comments on commit 3182365

Please sign in to comment.