Fix BetAnswerInfos
continuous-integration/drone/push Build is passing Details

pull/17/head^2
avalin 11 months ago
parent 90b099183c
commit fb87d8e7f9

@ -197,12 +197,27 @@ class PostgresBetDataSource(private val database: Database) : BetDataSource {
} }
) )
if (bet.type == BetType.CUSTOM) { val responses = if (bet.type == BetType.BINARY) {
bet.response.forEach { selected -> 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( database.responses.add(
ResponseEntity { ResponseEntity {
this.betId = bet.id this.betId = bet.id
this.response = selected this.response = response
} }
) )
} }

@ -34,8 +34,9 @@ class PostgresParticipationDataSource(private val database: Database) : Particip
if (it.response == participation.answer) { if (it.response == participation.answer) {
it.totalStakes += participation.stake 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() it.flushChanges()
} }
} }

Loading…
Cancel
Save