Skip to content

Commit

Permalink
WIP API and bindings unit testing; cleaning up #204, #162, #163, #184,
Browse files Browse the repository at this point in the history
  • Loading branch information
cbuahin committed Dec 22, 2024
1 parent ef8f5b7 commit 8e3dca2
Show file tree
Hide file tree
Showing 21 changed files with 705 additions and 687 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ with Solver(inp_file="input_file.inp") as swmm_solver:
print(swmm_solver.current_datetime)

swmm_solver.set_value(
object_type=solver.SWMMObjects.RAIN_GAGE.value,
property_type=solver.SWMMRainGageProperties.GAGE_RAINFALL.value,
object_type=solver.SWMMObjects.RAIN_GAGE,
property_type=solver.SWMMRainGageProperties.GAGE_RAINFALL,
index=0,
value=3.6
)
Expand All @@ -122,7 +122,7 @@ swmm_output = Output(output_file='output_file.out')
# Dict[datetime, float]
link_timeseries = swmm_output.get_link_timeseries(
element_index=5,
attribute=output.LinkAttribute.FLOW_RATE.value,
attribute=output.LinkAttribute.FLOW_RATE,
)

```
Expand Down
5 changes: 5 additions & 0 deletions python/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
include LICENSE
include README.md
recursive-include *.py
recursive-include *.txt
recursive-include *.md
recursive-include *.pyi
recursive-include *.inp
recursive-include *.pickle
recursive-include docs *.rst
recursive-include tests *.csv
global-exclude *.pyc
10 changes: 10 additions & 0 deletions python/epaswmm/output/_output.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,16 @@ class Output:
:cvar _num_periods: Number of reporting periods.
:cvar _times: Times of the simulation in the SWMM output file.
"""

def __init__(self, output_file: str) -> None:
"""
Constructor to initialize the SWMM output file instance.
:param output_file: Path to the SWMM output file.
:type output_file: str
"""
...

def __enter__(self): # -> Self@Output:
"""
Method to return the SWMM output file instance.
Expand Down
35 changes: 21 additions & 14 deletions python/epaswmm/solver/_solver.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ This type stub file was generated by cyright.
"""

from enum import Enum
from typing import Any, Callable, List, Tuple
from typing import Any, Callable, List, Tuple, Union

class SWMMObjects(Enum):
"""
Expand Down Expand Up @@ -575,16 +575,17 @@ class Solver:
"""
A class to represent a SWMM solver.
"""
def __init__(self, inp_file: str, rpt_file: str = ..., out_file: str = ...) -> None:

def __init__(self, inp_file: str, rpt_file: str, out_file: str) -> None:
"""
Constructor to initialize the solver.
Constructor to initialize the SWMM solver.
:param inp_file: Input file name
:param rpt_file: Report file name
:param out_file: Output file name
"""
...

def __enter__(self): # -> Self@Solver:
"""
Enter method for context manager.
Expand Down Expand Up @@ -767,29 +768,35 @@ class Solver:
"""
...

def set_value(self, object_type: int, property_type: int, index: int, value: float, sub_index: int = ...) -> Any:
def set_value(self, object_type: SWMMObjects, property_type: Union[SWMMRainGageProperties, SWMMSubcatchmentProperties, SWMMNodeProperties, SWMMLinkProperties, SWMMSystemProperties], index: int, value: double, sub_index: int = ...) -> None:
"""
Set a SWMM system property value.
:param object_type: SWMM object type (e.g., SWMMObjects.NODE.value)
:type object_type: int
:param property_type: System property type (e.g., SWMMSystemProperties.ELEVATION.value)
:type property_type: int
:param object_type: SWMM object type (e.g., SWMMObjects.NODE)
:type object_type: SWMMObjects
:param property_type: SWMM system property type (e.g., SWMMSystemProperties.START_DATE)
:type property_type: Union[SWMMRainGageProperties, SWMMSubcatchmentProperties, SWMMNodeProperties, SWMMLinkProperties, SWMMSystemProperties]
:param index: Object index (e.g., 0)
:type index: int
:param sub_index: Sub-index (e.g., 0) for properties with sub-indexes. For example pollutant index for POLLUTANT properties.
:type sub_index: int
:param value: Property value (e.g., 10.0)
:type value: double
:param sub_index: Sub-index (e.g., 0) for properties with sub-indexes. For example pollutant index for POLLUTANT properties.
:type sub_index: int
"""
...

def get_value(self, object_type: int, property_type: int, index: int, sub_index: int = ...) -> float:
def get_value(self, object_type: SWMMObjects, property_type: Union[SWMMRainGageProperties, SWMMSubcatchmentProperties, SWMMNodeProperties, SWMMLinkProperties, SWMMSystemProperties], index: int, sub_index: int = ...) -> double:
"""
Get a SWMM system property value.
:param property_type: System property type
:type property_type: SWMMSystemProperties
:param object_type: SWMM object type (e.g., SWMMObjects.NODE)
:type object_type: SWMMObjects
:param property_type: SWMM system property type (e.g., SWMMSystemProperties.START_DATE)
:type property_type: Union[SWMMRainGageProperties, SWMMSubcatchmentProperties, SWMMNodeProperties, SWMMLinkProperties, SWMMSystemProperties]
:param index: Object index (e.g., 0)
:type index: int
:param sub_index: Sub-index (e.g., 0) for properties with sub-indexes. For example pollutant index for POLLUTANT properties.
:type sub_index: int
:return: Property value
:rtype: double
"""
Expand Down
57 changes: 44 additions & 13 deletions python/epaswmm/solver/_solver.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# python and cython imports
from enum import Enum
from warnings import warn
from typing import List, Tuple, Union, Optional, Dict, Set, Callable
from typing import List, Tuple, Union, Dict, Set, Callable
from cpython.datetime cimport datetime, timedelta
from libc.stdlib cimport free, malloc
from functools import partialmethod
Expand Down Expand Up @@ -995,34 +995,65 @@ cdef class Solver:

return index

cpdef void set_value(self, int object_type, int property_type, int index, double value, int sub_index = -1):
def set_value(
self,
object_type: SWMMObjects,
property_type: Union[
SWMMRainGageProperties,
SWMMSubcatchmentProperties,
SWMMNodeProperties,
SWMMLinkProperties,
SWMMSystemProperties
],
index: int,
value: double,
sub_index: int = -1
) -> None:
"""
Set a SWMM system property value.

:param object_type: SWMM object type (e.g., SWMMObjects.NODE.value)
:type object_type: int
:param property_type: System property type (e.g., SWMMSystemProperties.ELEVATION.value)
:type property_type: int
:param object_type: SWMM object type (e.g., SWMMObjects.NODE)
:type object_type: SWMMObjects
:param property_type: SWMM system property type (e.g., SWMMSystemProperties.START_DATE)
:type property_type: Union[SWMMRainGageProperties, SWMMSubcatchmentProperties, SWMMNodeProperties, SWMMLinkProperties, SWMMSystemProperties]
:param index: Object index (e.g., 0)
:type index: int
:param sub_index: Sub-index (e.g., 0) for properties with sub-indexes. For example pollutant index for POLLUTANT properties.
:type sub_index: int
:param value: Property value (e.g., 10.0)
:type value: double
:param sub_index: Sub-index (e.g., 0) for properties with sub-indexes. For example pollutant index for POLLUTANT properties.
:type sub_index: int
"""
cdef int error_code = swmm_setValueExpanded(object_type, property_type, index, sub_index, value)
cdef int error_code = swmm_setValueExpanded(<int>object_type.value, <int>property_type.value, index, sub_index, value)
self.__validate_error(error_code)

cpdef double get_value(self, int object_type, int property_type, int index, int sub_index = -1):
def get_value(
self,
object_type: SWMMObjects,
property_type: Union[
SWMMRainGageProperties,
SWMMSubcatchmentProperties,
SWMMNodeProperties,
SWMMLinkProperties,
SWMMSystemProperties
],
index: int,
sub_index: int = -1
) -> double:
"""
Get a SWMM system property value.

:param property_type: System property type
:type property_type: SWMMSystemProperties
:param object_type: SWMM object type (e.g., SWMMObjects.NODE)
:type object_type: SWMMObjects
:param property_type: SWMM system property type (e.g., SWMMSystemProperties.START_DATE)
:type property_type: Union[SWMMRainGageProperties, SWMMSubcatchmentProperties, SWMMNodeProperties, SWMMLinkProperties, SWMMSystemProperties]
:param index: Object index (e.g., 0)
:type index: int
:param sub_index: Sub-index (e.g., 0) for properties with sub-indexes. For example pollutant index for POLLUTANT properties.
:type sub_index: int
:return: Property value
:rtype: double
"""
cdef double value = swmm_getValueExpanded(object_type, property_type, index, sub_index)
cdef double value = swmm_getValueExpanded(<int>object_type.value, <int>property_type.value, index, sub_index)
self.__validate_error(<int>value)

return value
Expand Down
10 changes: 0 additions & 10 deletions python/epaswmm/tests/data/solver/non_existent_input_file.rpt

This file was deleted.

Loading

0 comments on commit 8e3dca2

Please sign in to comment.