Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/battery-attributes #87

Merged
merged 33 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
43bb235
Added charge rate and RTE attributes to battery
fletchapin Apr 16, 2024
877a1a7
Added ContentsType for chemical dosing
fletchapin May 6, 2024
103b7b5
Tweak to Speed units
fletchapin May 6, 2024
99bef06
Added hertz to unit processing
fletchapin May 6, 2024
2e92df7
Removed units from capacity, charge, and discharge rate
fletchapin May 6, 2024
d5b4cd4
Implemented FutureWarning for old syntax
fletchapin May 6, 2024
42720bc
Added backwards compatability with getters/setters
fletchapin May 7, 2024
475b899
test_get_capacities completed
fletchapin May 7, 2024
95b9837
Created get_efficiencies function
fletchapin May 7, 2024
dcf5e91
Autoreformatted with black
fletchapin May 7, 2024
6e3267e
Trying to fix getter and setter for backwards compatability
fletchapin May 7, 2024
3feec89
Fixed test_get_efficiencies
fletchapin May 7, 2024
8434b49
Still trying to figure out back compat
fletchapin May 7, 2024
db91390
Forgot to import warnings, duh
fletchapin May 7, 2024
7f84561
Removed flake8 warnings
fletchapin May 7, 2024
9204df7
trying to break circular dependency
fletchapin May 7, 2024
d9b38b9
Typos in energy_capacity
fletchapin May 7, 2024
51d44f4
Trying to avoid infinite recursion
fletchapin May 7, 2024
1a0860b
Finally fixed the getter/setters
fletchapin May 7, 2024
4c44e7a
Fixed backwards compat with charge_rate
fletchapin May 7, 2024
19901f9
Typo in del_charge_rate
fletchapin May 7, 2024
0198f12
Added RTE getter/setter
fletchapin May 7, 2024
d7a0eb1
Forgot getter/setter for leakage
fletchapin May 7, 2024
1c8ccc8
Adding verbose flag
fletchapin May 7, 2024
379d80d
Missed variable assignment in parse_json
fletchapin May 7, 2024
d6f5000
WIP updating flow rate logic
fletchapin May 8, 2024
3e033d0
Reworked flow rate and pressure representation
fletchapin May 8, 2024
e3b4ee8
fixed test_get_capacities
fletchapin May 10, 2024
7e23aa3
Typo in CAPACITY_ATTRS
fletchapin May 13, 2024
da2a980
Fixed to_json bug with capacities
fletchapin May 13, 2024
a6d26a5
Fixed line too long linter error
fletchapin May 13, 2024
21088f5
Extending tests to DeprecationWarnings
fletchapin May 13, 2024
8c492eb
Fixed unused import linter error
fletchapin May 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test_and_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
pip install .[test]
- name: Test with pytest
run: |
pytest --cov-report xml --cov=pype_schema pype_schema/tests/
pytest --cov-report xml --cov=pype_schema pype_schema/tests/ -vv
codecov -t ${{ secrets.CODECOV_TOKEN }}
lint:
runs-on: ubuntu-latest
Expand Down
235 changes: 201 additions & 34 deletions pype_schema/connection.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from abc import ABC
from . import utils
from . import node
Expand Down Expand Up @@ -237,29 +238,29 @@
destination : Node
Endpoint of the connection

min_flow : int
min_flow : pint.Quantity or int
Minimum flow rate through the pipe

max_flow : int
max_flow : pint.Quantity or int
Maximum flow rate through the pipe

avg_flow : int
avg_flow : pint.Quantity or int
Average flow rate through the pipe

diameter : int
Pipe diameter in meters
diameter : pint.Quantity or int
Pipe diameter

friction_coeff : int
Friction coefficient for the pipe

min_pres : int
min_pres : pint.Quantity or int
Minimum pressure inside the pipe

max_pres : int
max_pres : pint.Quantity or int
Maximum pressure inside the pipe

avg_pres : int
Average pressure inside the pipe
design_pres : pint.Quantity or int
Design pressure of the pipe

lower_heating_value : float
Lower heating value of gas in the pipe
Expand Down Expand Up @@ -295,17 +296,29 @@
destination : Node
Endpoint of the connection

flow_rate : tuple
Minimum, maximum, and average flow rate through the pipe
min_flow : pint.Quantity or int
Minimum flow rate through the pipe

max_flow : pint.Quantity or int
Maximum flow rate through the pipe

diameter : int
Pipe diameter in meters
design_flow : pint.Quantity or int
Design flow rate through the pipe

diameter : pint.Quantity or int
Pipe diameter

friction_coeff : int
Friction coefficient for the pipe

pressure : tuple
Minimum, maximum, and average pressure in the pipe
min_pressure : pint.Quantity or int
Minimum pressure inside the pipe

max_pressure : pint.Quantity or int
Maximum pressure inside the pipe

design_pressure : pint.Quantity or int
Design pressure of the pipe

heating_values : tuple
The lower and higher heating values of the gas in the pipe.
Expand Down Expand Up @@ -334,12 +347,12 @@
destination,
min_flow,
max_flow,
avg_flow,
design_flow,
diameter=None,
friction=None,
min_pres=None,
max_pres=None,
avg_pres=None,
design_pres=None,
lower_heating_value=None,
higher_heating_value=None,
tags={},
Expand All @@ -353,8 +366,12 @@
self.destination = destination
self.diameter = diameter
self.friction_coeff = friction
self.set_pressure(min_pres, max_pres, avg_pres)
self.set_flow_rate(min_flow, max_flow, avg_flow)
self.min_pressure = min_pres
self.max_pressure = max_pres
self.design_pressure = design_pres
self.min_flow = min_flow
self.max_flow = max_flow
self.design_flow = design_flow
self.set_heating_values(lower_heating_value, higher_heating_value)
self.tags = tags
self.bidirectional = bidirectional
Expand All @@ -376,7 +393,10 @@
f"<pype_schema.connection.Pipe id:{self.id} "
f"contents:{self.contents} source:{self.source.id} "
f"destination:{self.destination.id} "
f"flow_rate:{self.flow_rate} pressure:{self.pressure} "
f"min_flow:{self.min_flow} max_flow:{self.max_flow} "
f"design_flow:{self.design_flow} min_pressure:{self.min_pressure} "
f"max_pressure:{self.max_pressure} "
f"design_pressure:{self.design_pressure}"
f"heating_values:{self.heating_values} "
f"diameter:{self.diameter} friction_coeff:{self.friction_coeff} "
f"tags:{self.tags} bidirectional:{self.bidirectional} "
Expand All @@ -395,9 +415,13 @@
and self.destination == other.destination
and self.diameter == other.diameter
and self.friction_coeff == other.friction_coeff
and self.pressure == other.pressure
and self.min_pressure == other.min_pressure
and self.max_pressure == other.max_pressure
and self.design_pressure == other.design_pressure
and self.heating_values == other.heating_values
and self.flow_rate == other.flow_rate
and self.min_flow == other.min_flow
and self.max_flow == other.max_flow
and self.design_flow == other.design_flow
and self.tags == other.tags
and self.bidirectional == other.bidirectional
and self.exit_point == other.exit_point
Expand All @@ -411,12 +435,20 @@

if self.diameter != other.diameter:
return self.diameter < other.diameter
elif self.flow_rate != other.flow_rate:
return self.flow_rate < other.flow_rate
elif self.min_flow != other.min_flow:
return self.min_flow < other.min_flow

Check warning on line 439 in pype_schema/connection.py

View check run for this annotation

Codecov / codecov/patch

pype_schema/connection.py#L439

Added line #L439 was not covered by tests
elif self.max_flow != other.max_flow:
return self.max_flow < other.max_flow

Check warning on line 441 in pype_schema/connection.py

View check run for this annotation

Codecov / codecov/patch

pype_schema/connection.py#L441

Added line #L441 was not covered by tests
elif self.design_flow != other.design_flow:
return self.design_flow < other.design_flow

Check warning on line 443 in pype_schema/connection.py

View check run for this annotation

Codecov / codecov/patch

pype_schema/connection.py#L443

Added line #L443 was not covered by tests
elif self.friction_coeff != other.friction_coeff:
return self.friction_coeff < other.friction_coeff
elif self.pressure != other.pressure:
return self.pressure < other.pressure
elif self.min_pressure != other.min_pressure:
return self.min_pressure < other.min_pressure

Check warning on line 447 in pype_schema/connection.py

View check run for this annotation

Codecov / codecov/patch

pype_schema/connection.py#L447

Added line #L447 was not covered by tests
elif self.max_pressure != other.max_pressure:
return self.max_pressure < other.max_pressure

Check warning on line 449 in pype_schema/connection.py

View check run for this annotation

Codecov / codecov/patch

pype_schema/connection.py#L449

Added line #L449 was not covered by tests
elif self.design_pressure != other.design_pressure:
return self.design_pressure < other.design_pressure

Check warning on line 451 in pype_schema/connection.py

View check run for this annotation

Codecov / codecov/patch

pype_schema/connection.py#L451

Added line #L451 was not covered by tests
elif self.heating_values != other.heating_values:
return self.heating_values < other.heating_values
elif self.contents != other.contents:
Expand Down Expand Up @@ -452,7 +484,7 @@
if tag != other_tags[i]:
return tag < other_tags[i]

def set_flow_rate(self, min, max, avg):
def set_flow_rate(self, min, max, design):
"""Set the minimum, maximum, and average flow rate through the connection

Parameters
Expand All @@ -463,12 +495,78 @@
max : int
Maximum flow rate through the connection

avg : int
Average flow rate through the connection
design : int
Design flow rate through the connection
"""
self.flow_rate = (min, max, avg)
warnings.warn(
"Please switch from `flow_rate` tuple to separate "
+ "`min_flow`, `max_flow` and `design_flow` attributes",
DeprecationWarning,
)
self.flow_rate = (min, max, design)
self._min_flow = min
self._max_flow = max
self._design_flow = design

def get_min_flow(self):
try:
return self._min_flow
except AttributeError:
warnings.warn(
"Please switch from `flow_rate` tuple to new `min_flow` attribute",
DeprecationWarning,
)
return self.flow_rate[0]

def set_min_flow(self, min_flow):
self._min_flow = min_flow

def del_min_flow(self):
del self._min_flow
if hasattr(self, "flow_rate"):
self.flow_rate = (None, self.flow_rate[1], self.flow_rate[2])

def get_max_flow(self):
try:
return self._max_flow
except AttributeError:
warnings.warn(
"Please switch from `flow_rate` tuple to new `max_flow` attribute",
DeprecationWarning,
)
return self.flow_rate[1]

def set_max_flow(self, max_flow):
self._max_flow = max_flow

def set_pressure(self, min, max, avg):
def del_max_flow(self):
del self._max_flow
if hasattr(self, "flow_rate"):
self.flow_rate = (self.flow_rate[0], None, self.flow_rate[2])

def get_design_flow(self):
try:
return self._design_flow
except AttributeError:
warnings.warn(
"Please switch from `flow_rate` tuple to new `design_flow` attribute",
DeprecationWarning,
)
return self.flow_rate[2]

def set_design_flow(self, design_flow):
self._design_flow = design_flow

def del_design_flow(self):
del self._design_flow
if hasattr(self, "flow_rate"):
self.flow_rate = (self.flow_rate[0], self.flow_rate[1], None)

min_flow = property(get_min_flow, set_min_flow, del_min_flow)
max_flow = property(get_max_flow, set_max_flow, del_max_flow)
design_flow = property(get_design_flow, set_design_flow, del_design_flow)

def set_pressure(self, min, max, design):
"""Set the minimum, maximum, and average pressure inside the connection

Parameters
Expand All @@ -479,10 +577,79 @@
max : int
Maximum pressure inside the connection

avg : int
Average pressure inside the connection
design : int
Design pressure inside the connection
"""
self.pressure = (min, max, avg)
warnings.warn(

Check warning on line 583 in pype_schema/connection.py

View check run for this annotation

Codecov / codecov/patch

pype_schema/connection.py#L583

Added line #L583 was not covered by tests
"Please switch from `pressure` tuple to separate "
+ "`min_pressure`, `max_pressure` and `design_pressure` attributes",
DeprecationWarning,
)
self.pressure = (min, max, design)
self._min_pressure = min
self._max_pressure = max
self._design_pressure = design

Check warning on line 591 in pype_schema/connection.py

View check run for this annotation

Codecov / codecov/patch

pype_schema/connection.py#L588-L591

Added lines #L588 - L591 were not covered by tests

def get_min_pressure(self):
try:
return self._min_pressure
except AttributeError:
warnings.warn(
"Please switch from `pressure` tuple to new `min_pressure` attribute",
DeprecationWarning,
)
return self.pressure[0]

def set_min_pressure(self, min_pressure):
self._min_pressure = min_pressure

def del_min_pressure(self):
del self._min_pressure
if hasattr(self, "pressure"):
self.pressure = (None, self.pressure[1], self.pressure[2])

Check warning on line 609 in pype_schema/connection.py

View check run for this annotation

Codecov / codecov/patch

pype_schema/connection.py#L607-L609

Added lines #L607 - L609 were not covered by tests

def get_max_pressure(self):
try:
return self._max_pressure
except AttributeError:
warnings.warn(
"Please switch from `pressure` tuple to new `max_pressure` attribute",
DeprecationWarning,
)
return self.pressure[1]

def set_max_pressure(self, max_pressure):
self._max_pressure = max_pressure

def del_max_pressure(self):
del self._max_pressure
if hasattr(self, "pressure"):
self.pressure = (self.pressure[0], None, self.pressure[2])

Check warning on line 627 in pype_schema/connection.py

View check run for this annotation

Codecov / codecov/patch

pype_schema/connection.py#L625-L627

Added lines #L625 - L627 were not covered by tests

def get_design_pressure(self):
try:
return self._design_pressure
except AttributeError:
warnings.warn(
"Please switch from `pressure` tuple to "
+ "new `design_pressure` attribute",
DeprecationWarning,
)
return self.pressure[2]

def set_design_pressure(self, design_pressure):
self._design_pressure = design_pressure

def del_design_pressure(self):
del self._design_pressure
if hasattr(self, "pressure"):
self.pressure = (self.pressure[0], self.pressure[1], None)

Check warning on line 646 in pype_schema/connection.py

View check run for this annotation

Codecov / codecov/patch

pype_schema/connection.py#L644-L646

Added lines #L644 - L646 were not covered by tests

min_pressure = property(get_min_pressure, set_min_pressure, del_min_pressure)
max_pressure = property(get_max_pressure, set_max_pressure, del_max_pressure)
design_pressure = property(
get_design_pressure, set_design_pressure, del_design_pressure
)

def set_heating_values(self, lower, higher):
"""Set the lower and higher heating values for gas in the connection
Expand Down
Loading
Loading