Skip to content

Commit

Permalink
docs: add docstrings to undocumented functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgenengelsen committed May 24, 2023
1 parent 50e2d66 commit 064adfa
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ecalc/libraries/libecalc/common/libecalc/input/file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,9 @@ def convert_dataframe_to_timeseries_resource(resource_df: pd.DataFrame) -> Resou
# have nan. This method would include that row. Although it is unlikely.
# Drop rows if all values are na (sometimes lines with ,,, are exported from Excel).

resource_df.dropna(axis=0, how="all", inplace=True)
resource_df = resource_df.dropna(axis=0, how="all")
# Drop columns if all values are na
resource_df.dropna(axis=1, how="all", inplace=True)
resource_df = resource_df.dropna(axis=1, how="all")

return _dataframe_to_resource(resource_df)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@


class NodeType:
"""Supported Node types in FDE diagram"""

GENERATOR = "generator"
INSTALLATION = "installation"
CABLE = "cable"
Expand All @@ -26,24 +28,42 @@ class NodeType:


class FlowType:
"""Supported flow types in FDE diagram"""

FUEL = "fuel-flow"
EMISSION = "emission-flow"
ELECTRICITY = "electricity-flow"


def to_camel_case(string: str) -> str:
"""Convert string from snake_case to camelCase
Args:
string: String in snake_case format
Returns:
String in camelCase format
"""
string_split = string.split("_")
return string_split[0] + "".join(word.capitalize() for word in string_split[1:])


class FlowDiagramBaseModel(BaseModel):
"""Pydantic basemodel for FDE pydantic models
Needed for specifying datetime format in json dumps
"""

class Config:
json_encoders = {
datetime: lambda v: v.strftime("%Y-%m-%dT%H:%M:%SZ"),
}


class FlowDiagram(FlowDiagramBaseModel):
"""Pydantic class for flowdiagram of eCalc model"""

id: str
title: str
nodes: List[Node]
Expand All @@ -58,6 +78,8 @@ class Config:


class Flow(FlowDiagramBaseModel):
"""Pydantic class for connection between nodes in FDE diagram"""

id: str
label: str
type: str
Expand All @@ -78,6 +100,8 @@ class Config:


class Node(FlowDiagramBaseModel):
"""Component in flowdiagram model, ex. a turbine or compressor"""

id: str
title: Optional[str] = None
type: Optional[str] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@


class OutputFormat(enum.Enum):
"""Supported output file formats from eCalc"""

CSV = "csv"
JSON = "json"

def __str__(self):
"""Dump enum to string"""
return self.value


Expand All @@ -22,6 +25,20 @@ def dataframe_to_csv(
float_formatter: Optional[Union[Callable, str]] = "%20.5f",
date_format: Optional[str] = None,
) -> str:
"""Dump pandas dataframe to csv file
Wraps pandas to_csv functionality, for more options see pandas docs
Args:
df: Dataframe to dump
separator: value separator in out, defaults to ',' for csv
show_index: if true, will include index in dump
float_formatter:
date_format:
Returns:
"""
return df.to_csv(
float_format=float_formatter,
index=show_index,
Expand All @@ -33,6 +50,17 @@ def dataframe_to_csv(


def to_json(result: Union[ComponentResult, EcalcModelResult], simple_output: bool, date_format_option: int) -> str:
"""Dump result classes to json file
Args:
result: eCalc result data class
simple_output: If true, will provide a simplified output format
date_format_option:
Returns:
String dump of json output
"""
date_format = DateTimeFormats.get_format(date_format_option)
return (
result.simple_result().json(
Expand All @@ -55,6 +83,19 @@ def get_result_output(
simple_output: bool,
date_format_option: int,
) -> str:
"""Result output controller
Output eCalc results in desired format and
Args:
results:
output_format:
simple_output: If true, will provide a simplified output format. Only supported for json format
date_format_option:
Returns:
"""
if output_format == OutputFormat.JSON:
return to_json(results, simple_output=simple_output, date_format_option=date_format_option)
elif output_format == OutputFormat.CSV:
Expand Down Expand Up @@ -85,6 +126,18 @@ def get_component_output(
simple_output: bool,
date_format_option: int,
) -> str:
"""Get eCalc output for a single component by name
Args:
results: Complete from eCalc model
component_name: Name of component to output results from
output_format: Format of output file, CSV and JSON is currently supported
simple_output: If true, will provide a simplified output format. Only supported for json format
date_format_option:
Returns:
"""
components = [component for component in results.components if component.name == component_name]

if len(components) == 0:
Expand Down
4 changes: 4 additions & 0 deletions src/ecalc/libraries/neqsim/neqsim_ecalc_wrapper/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
class NeqsimError(Exception):
"""Placeholder for custom NeqSim Error handling"""

pass


class NeqsimPhaseError(NeqsimError):
"""Placeholder for custom NeqSim Error handling"""

pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@


def create_classpath(jars):
"""Create path to NeqSim .jar file"""
resources_dir = path.dirname(__file__) + "/lib"
return colon.join([path.join(resources_dir, jar) for jar in jars])


def start_server():
"""Start JVM for NeqSim Wrapper"""
global gateway
jars = ["NeqSim.jar"]
classpath = create_classpath(jars)
Expand Down

0 comments on commit 064adfa

Please sign in to comment.