Skip to content

Commit e5bbe59

Browse files
committed
Refactoring code
1 parent ef3662c commit e5bbe59

File tree

6 files changed

+75
-19
lines changed

6 files changed

+75
-19
lines changed

requirements.txt

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
numpy==1.22
2-
pandas==1.4.3
3-
pytest~=6.2.3
4-
setuptools~=56.0.0
5-
6-
colorama~=0.4.4
1+
attrs==22.2.0
2+
colorama==0.4.6
3+
comtypes==1.1.14
4+
exceptiongroup==1.1.0
5+
iniconfig==2.0.0
6+
numpy==1.24.2
7+
packaging==23.0
8+
pandas==1.5.3
9+
pluggy==1.0.0
10+
pytest==7.2.1
11+
python-dateutil==2.8.2
12+
pytz==2022.7.1
13+
six==1.16.0
14+
tomli==2.0.1

src/py_dss_interface/models/ActiveClass/ActiveClass.py

+23-3
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,63 @@
1313

1414
@dataclass
1515
class ActiveClass(ActiveClassS, ActiveClassI, ActiveClassV):
16-
"""This interface implements the ActiveClass (IActiveClass) interface of OpenDSS by declaring 3 procedures for
17-
accessing the different properties included in this interface: ActiveClassS, ActiveClassI, ActiveClassV. Ih the
18-
original paper Davis cited that are 4 procedures, but only 3 were described."""
16+
"""This class implements the ActiveClass interface of OpenDSS.
17+
18+
The ActiveClass interface provides methods for accessing properties of DSS classes.
19+
This class defines the methods for accessing the different properties included in this interface:
20+
ActiveClassS, ActiveClassI, ActiveClassV.
21+
22+
Args:
23+
obj_dss: The COM object that provides access to the OpenDSS engine.
24+
"""
1925

2026
def __init__(self, obj_dss):
2127
super().__init__(obj_dss)
2228

2329
def first(self) -> int:
30+
"""Sets first element in the active class to be the active DSS object.
31+
If object is a CktElement, ActiveCktElement also points to this element.
32+
Returns 0 if none."""
2433
return ActiveClassI._first(self)
2534

2635
def next(self) -> int:
36+
"""Sets next element in the active class to be the active DSS object.
37+
If object is a CktElement, ActiveCktElement also points to this element.
38+
Returns 0 if none."""
2739
return ActiveClassI._next(self)
2840

2941
@property
3042
def num_elements(self) -> int:
43+
"""Gets the number of elements in this class. Same as Count Property."""
3144
return ActiveClassI._num_elements(self)
3245

3346
@property
3447
def count(self) -> int:
48+
"""Gets the number of elements in this class. Same as NumElements Property."""
3549
return ActiveClassI._count(self)
3650

3751
@property
3852
def name(self) -> str:
53+
"""Gets the name of the active Element of the Active class."""
3954
return ActiveClassS._name(self)
4055

4156
@name.setter
4257
def name(self, argument: str):
58+
"""Sets the name of the active Element of the Active class."""
4359
ActiveClassS._name_write(self, argument)
4460

4561
@property
4662
def class_name(self) -> str:
63+
"""Gets the name of the active Element's class."""
4764
return ActiveClassS._class_name(self)
4865

4966
@property
5067
def parent_class_name(self) -> str:
68+
"""Gets the name of the Parent Element of the Active class."""
5169
return ActiveClassS._parent_class_name(self)
5270

5371
@property
5472
def names(self) -> List[str]:
73+
"""Gets a list of all element names in the active Class."""
5574
return ActiveClassV._names(self)
75+

src/py_dss_interface/models/ActiveClass/ActiveClassI.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,31 @@ class ActiveClassI(Base):
2020

2121
def _count(self) -> int:
2222
"""Gets the number of elements in this class. Same as NumElements Property."""
23-
return self.dss_obj.ActiveClassI(3, 0)
23+
try:
24+
return self.dss_obj.ActiveClassI(3, 0)
25+
except Exception as e:
26+
raise Exception(f"Error in _count: {e}")
2427

2528
def _first(self) -> int:
2629
"""Sets first element in the active class to be the active DSS object. If object is a CktElement,
2730
ActiveCktElement also points to this element. Returns 0 if none."""
28-
return self.dss_obj.ActiveClassI(0, 0)
31+
try:
32+
return self.dss_obj.ActiveClassI(0, 0)
33+
except Exception as e:
34+
raise Exception(f"Error in _first: {e}")
2935

3036
def _next(self) -> int:
3137
"""Sets next element in the active class to be the active DSS object.
3238
If object is a CktElement, ActiveCktElement also points to this element. Returns 0 if none."""
33-
return self.dss_obj.ActiveClassI(1, 0)
39+
try:
40+
return self.dss_obj.ActiveClassI(1, 0)
41+
except Exception as e:
42+
raise Exception(f"Error in _next: {e}")
3443

3544
def _num_elements(self) -> int:
3645
"""Gets the number of elements in this class. Same as Count Property."""
37-
return self.dss_obj.ActiveClassI(2, 0)
46+
try:
47+
return self.dss_obj.ActiveClassI(2, 0)
48+
except Exception as e:
49+
raise Exception(f"Error in _num_elements: {e}")
50+

src/py_dss_interface/models/ActiveClass/ActiveClassS.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,28 @@ class ActiveClassS(Base):
2222

2323
def _class_name(self) -> str:
2424
"""Sets the name of the active Element of the Active class."""
25-
return (self.dss_obj.ActiveClassS(2, 0)).decode('ascii')
25+
try:
26+
return (self.dss_obj.ActiveClassS(2, 0)).decode('ascii')
27+
except Exception as e:
28+
raise Exception(f"Error in _class_name: {e}")
2629

2730
def _name(self) -> str:
2831
"""Gets the name of the active Element of the Active class."""
29-
return (self.dss_obj.ActiveClassS(0, 0)).decode('ascii')
32+
try:
33+
return (self.dss_obj.ActiveClassS(0, 0)).decode('ascii')
34+
except Exception as e:
35+
raise Exception(f"Error in _name: {e}")
3036

3137
def _name_write(self, argument) -> str:
3238
"""Sets the name of the active Element of the Active class. """
33-
return (self.dss_obj.ActiveClassS(1, argument.encode('ascii'))).decode('ascii')
39+
try:
40+
return (self.dss_obj.ActiveClassS(1, argument.encode('ascii'))).decode('ascii')
41+
except Exception as e:
42+
raise Exception(f"Error in _name_write: {e}")
3443

3544
def _parent_class_name(self) -> str:
3645
"""Gets the name of the Parent Element of the Active class."""
37-
return (self.dss_obj.ActiveClassS(3, 0)).decode('ascii')
46+
try:
47+
return (self.dss_obj.ActiveClassS(3, 0)).decode('ascii')
48+
except Exception as e:
49+
raise Exception(f"Error in _parent_class_name: {e}")

src/py_dss_interface/models/ActiveClass/ActiveClassV.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ class ActiveClassV(Base):
2525
def _names(self) -> List[str]:
2626
"""Gets a variant array of strings consisting of all element names in the active Class."""
2727
# return Bridge.var_array_function(self.dss_obj.ActiveClassV, 0, None, '')
28-
return Bridge.variant_pointer_read(self.dss_obj.ActiveClassV, 0)
28+
try:
29+
return Bridge.variant_pointer_read(self.dss_obj.ActiveClassV, 0)
30+
except Exception as e:
31+
raise Exception(f"Error while retrieving element names: {e}")

tests/py_dss_interface/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
@pytest.fixture(scope='function')
1919
def solve_snap_13bus():
20-
dss = py_dss_interface.DSS("C:\OpenDSS_rep\Version8\Source")
20+
dss = py_dss_interface.DSS(r"C:\OpenDSS")
2121

2222
dss.text("set DefaultBaseFrequency=60")
2323
dss13_path = os.path.join(pathlib.Path(script_path), "cases", "13Bus", "IEEE13Nodeckt.dss")

0 commit comments

Comments
 (0)