Skip to content

Commit

Permalink
change if statement to match case
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrypotts committed Aug 14, 2024
1 parent 8f9d4e1 commit fe64318
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions src/infrasys/value_curves.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,40 +87,40 @@ def to_input_output(self) -> InputOutputCurve:
InputOutputCurve
InputOutputCurve using either QuadraticFunctionData or PiecewiseStepData.
"""
if isinstance(self.function_data, LinearFunctionData):
p = self.function_data.proportional_term
m = self.function_data.constant_term
match self.function_data:
case LinearFunctionData():
p = self.function_data.proportional_term
m = self.function_data.constant_term

c = self.initial_input
if c is None:
msg = "Cannot convert `IncrementalCurve` with undefined `initial_input`"
raise ISOperationNotAllowed(msg)
c = self.initial_input
if c is None:
msg = "Cannot convert `IncrementalCurve` with undefined `initial_input`"
raise ISOperationNotAllowed(msg)

if p == 0:
return InputOutputCurve(
function_data=LinearFunctionData(proportional_term=m, constant_term=c)
)
else:
return InputOutputCurve(
function_data=QuadraticFunctionData(
quadratic_term=p / 2, proportional_term=m, constant_term=c
),
input_at_zero=self.input_at_zero,
)
case PiecewiseStepData():
c = self.initial_input
if c is None:
msg = "Cannot convert `IncrementalCurve` with undefined `initial_input`"
raise ISOperationNotAllowed(msg)

points = running_sum(self.function_data)

if p == 0:
return InputOutputCurve(
function_data=LinearFunctionData(proportional_term=m, constant_term=c)
)
else:
return InputOutputCurve(
function_data=QuadraticFunctionData(
quadratic_term=p / 2, proportional_term=m, constant_term=c
),
function_data=PiecewiseLinearData(points=[(p.x, p.y + c) for p in points]),
input_at_zero=self.input_at_zero,
)

elif isinstance(self.function_data, PiecewiseStepData):
c = self.initial_input
if c is None:
msg = "Cannot convert `IncrementalCurve` with undefined `initial_input`"
raise ISOperationNotAllowed(msg)

points = running_sum(self.function_data)

return InputOutputCurve(
function_data=PiecewiseLinearData(points=[(p.x, p.y + c) for p in points]),
input_at_zero=self.input_at_zero,
)


class AverageRateCurve(ValueCurve):
"""Average rate curve relating production quality to average cost rate.
Expand Down

0 comments on commit fe64318

Please sign in to comment.