diff --git a/Sources/src/main/kotlin/allin/data/postgres/PostgresBetDataSource.kt b/Sources/src/main/kotlin/allin/data/postgres/PostgresBetDataSource.kt index 58a553a..35c0fd1 100644 --- a/Sources/src/main/kotlin/allin/data/postgres/PostgresBetDataSource.kt +++ b/Sources/src/main/kotlin/allin/data/postgres/PostgresBetDataSource.kt @@ -197,12 +197,27 @@ class PostgresBetDataSource(private val database: Database) : BetDataSource { } ) - if (bet.type == BetType.CUSTOM) { - bet.response.forEach { selected -> + val responses = if (bet.type == BetType.BINARY) { + listOf(YES_VALUE, NO_VALUE) + } else { + bet.response + } + + responses.forEach { response -> + database.betAnswerInfos.add( + BetAnswerInfoEntity { + this.betId = bet.id + this.response = response + this.totalStakes = 0 + this.odds = 1f + } + ) + + if (bet.type == BetType.CUSTOM) { database.responses.add( ResponseEntity { this.betId = bet.id - this.response = selected + this.response = response } ) } diff --git a/Sources/src/main/kotlin/allin/data/postgres/PostgresParticipationDataSource.kt b/Sources/src/main/kotlin/allin/data/postgres/PostgresParticipationDataSource.kt index c6b3b96..6a56aa3 100644 --- a/Sources/src/main/kotlin/allin/data/postgres/PostgresParticipationDataSource.kt +++ b/Sources/src/main/kotlin/allin/data/postgres/PostgresParticipationDataSource.kt @@ -34,8 +34,9 @@ class PostgresParticipationDataSource(private val database: Database) : Particip if (it.response == participation.answer) { it.totalStakes += participation.stake } - val probability = it.totalStakes / betInfo.totalStakes.toFloat() - it.odds = 1 / probability + + val probability = (it.totalStakes / betInfo.totalStakes.toFloat()) + it.odds = if (probability == 0f) 1f else 1 / probability it.flushChanges() } }