Skip to content

Commit

Permalink
more refactoring on code smell
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfeismann committed Jul 24, 2024
1 parent af3eb81 commit 727f53b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -868,18 +868,36 @@ protected trait ParticipantAgentFundamentals[
)(baseStateData.outputConfig)
)

val updatedBaseStateData = result.foldLeft(baseStateData) {
(stateData, res) =>
stateData.copy(
resultValueStore = ValueStore.updateValueStore(
stateData.resultValueStore,
currentTick,
res,
)
createUpdatedBaseStateData(baseStateData, result, currentTick)
}

/** Updates the given `baseStateData` using a sequence of `result` values and
* the current tick.
*
* @param baseStateData
* The initial ParticipantModelBaseStateData object to be updated.
* @param result
* A list of result values used to update the resultValueStore.
* @param currentTick
* The current tick
* @return
* A new ParticipantModelBaseStateData object with the updated
* resultValueStore.
*/
protected def createUpdatedBaseStateData(
baseStateData: ParticipantModelBaseStateData[PD, CD, MS, M],
result: List[PD],
currentTick: Long,
): ParticipantModelBaseStateData[PD, CD, MS, M] = {
result.foldLeft(baseStateData) { (stateData, res) =>
stateData.copy(
resultValueStore = ValueStore.updateValueStore(
stateData.resultValueStore,
currentTick,
res,
)
)
}

updatedBaseStateData
}

/** Calculate the power output of the participant without needing any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,7 @@ trait StorageAgentFundamentals
)
}

val updatedBaseStateData = result.foldLeft(baseStateData) {
(stateData, res) =>
stateData.copy(
resultValueStore = ValueStore.updateValueStore(
stateData.resultValueStore,
currentTick,
res,
)
)
}

updatedBaseStateData
createUpdatedBaseStateData(baseStateData, result, currentTick)
}

/** Handle an active power change by flex control.
Expand Down

0 comments on commit 727f53b

Please sign in to comment.