-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c22c40
commit 7148b97
Showing
6 changed files
with
79 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/cds/core/src/main/kotlin/org/icpclive/cds/adapters/CommentaryAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.icpclive.cds.adapters | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.transform | ||
import org.icpclive.cds.CommentaryMessagesUpdate | ||
import org.icpclive.cds.api.CommentaryMessage | ||
import org.icpclive.cds.api.ContestState | ||
import org.icpclive.cds.scoreboard.ContestStateWithScoreboard | ||
|
||
|
||
public fun Flow<ContestStateWithScoreboard>.generateCommentary( | ||
generator: (ContestStateWithScoreboard) -> List<CommentaryMessage> | ||
) : Flow<ContestStateWithScoreboard> { | ||
var contestState: ContestState? = null | ||
return transform { | ||
contestState = contestState.applyEvent(it.state.lastEvent) | ||
emit( | ||
ContestStateWithScoreboard( | ||
state = contestState!!, | ||
scoreboardRowsAfter = it.scoreboardRowsAfter, | ||
scoreboardRowsBefore = it.scoreboardRowsBefore, | ||
scoreboardRowsChanged = it.scoreboardRowsChanged, | ||
rankingBefore = it.rankingAfter, | ||
rankingAfter = it.rankingBefore, | ||
lastSubmissionTime = it.lastSubmissionTime | ||
) | ||
) | ||
for (message in generator(it)) { | ||
val event = CommentaryMessagesUpdate(message) | ||
contestState = contestState.applyEvent(event) | ||
emit( | ||
ContestStateWithScoreboard( | ||
state = contestState!!, | ||
scoreboardRowsAfter = it.scoreboardRowsAfter, | ||
scoreboardRowsBefore = it.scoreboardRowsAfter, | ||
scoreboardRowsChanged = emptyList(), | ||
rankingBefore = it.rankingAfter, | ||
rankingAfter = it.rankingAfter, | ||
lastSubmissionTime = it.lastSubmissionTime | ||
) | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters