Skip to content
This repository has been archived by the owner on Sep 1, 2021. It is now read-only.

Commit

Permalink
Handle unresolved bets, fixes #51
Browse files Browse the repository at this point in the history
Unresolved bets will appear with grey question mark
  • Loading branch information
AndreMiras committed Apr 18, 2018
1 parent 9023aab commit ecaed14
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

- Per account bet history, refs #16
- Handle unresolved bets, refs #51


## [v20180414]
Expand Down
34 changes: 22 additions & 12 deletions src/roll_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,31 @@ def create_item_from_dict(roll_log):
bet_result = roll_log['bet_result']
bet_value_ether = bet_log['bet_value_ether']
roll_under = bet_log['roll_under']
dice_result = bet_result['dice_result']
date_time = bet_log['datetime']
chances_win = roll_under - 1
profit = Etheroll.compute_profit(bet_value_ether, chances_win)
player_won = dice_result < roll_under
profit_loss = profit if player_won else -bet_value_ether
sign = '<' if player_won else '>'
# will keep default value on unresolved bets
dice_result = '?'
player_won = None
sign = '?'
win_color = (0, 1, 0, 1)
loss_color = (1, 0, 0, 1)
text_color = win_color if player_won else loss_color
text = (
'{profit_loss:+.{round_digits}f} ETH'
).format(**{
'profit_loss': profit_loss,
'round_digits': constants.ROUND_DIGITS})
unresolved_color = (0.5, 0.5, 0.5, 1)
text_color = unresolved_color
profit_loss_str = '?'
# resolved bets case
if bet_result is not None:
dice_result = bet_result['dice_result']
player_won = dice_result < roll_under
sign = '<' if player_won else '>'
text_color = win_color if player_won else loss_color
chances_win = roll_under - 1
profit = Etheroll.compute_profit(bet_value_ether, chances_win)
profit_loss = profit if player_won else -bet_value_ether
profit_loss_str = (
'{profit_loss:+.{round_digits}f}'
).format(**{
'profit_loss': profit_loss,
'round_digits': constants.ROUND_DIGITS})
text = ('{0} ETH').format(profit_loss_str)
secondary_text = '{0} {1} {2}'.format(
dice_result, sign, roll_under)
tertiary_text = date_time.strftime("%Y-%m-%d %H:%M:%S")
Expand Down

0 comments on commit ecaed14

Please sign in to comment.