DEV Community

Cover image for Settlr - Splitwise settling for Poker sessions (written in Python)
Joqim
Joqim

Posted on

Settlr - Splitwise settling for Poker sessions (written in Python)

LIVE on Vercel + Heroku

Recently over the past couple of months, a bunch of friends - including my roommates and I get together on Fridays (and maybe also Saturday nights considering we're not sore losers lol) for Poker.

We begin dealing around 10 PM and go all night until 1 AM.
By 1 AM almost all of us are exceptionally exhausted (not to mention losing multiple buy-in's certainly doesn't help).

Then comes the annoying part, besides counting each player's chips value, someone takes turns in uploading the winnings/loses as each activity/transaction in Splitwise.

Transactions in splitwise are mandatory to be accurate to the penny, followed by assignment of players as corresponding debtor and creditors.
Carelessness in this regard is simply begging for arguments between the group members.

An age old way to tackling human error has been the concept of "machines" and more so in this case "an application", which is why I came up with Settlr.

Splitwise API documentation while being slightly obscure does contain sufficient examples to get you started.

Settlr is a python-flask web app backed with a minimalistic user interface built using Material UI, focused on ReactJS.

Image description

Source code - Settlr
Live - Vercel + Heroku

I began working on Settlr on tuesday, coming out hot out of last weekend's game and speedran developing the codebase just in time for the upcoming weekend.

Considering the on and off intricacies of Splitwise API, I managed to present Settlr for user testing by Wednesday evening.

The high level overview is that at the end of each poker game, Settlr requests key information such as the buy-in amount (which corresponds to 1000 units value in chips).

FYI, each player initially sets up with 1 "buy-in" which is, assume for this example, "$5" in real money and thus translates to 1000 units split into denominations of 10*5, 20*5, 50*3, 100*2 and 500*1.

As each player burns through his first buy-in, he requests the house for additional buy-in's thus spending additional $5's.

Besides, the buy-in amount, Settlr also requires the total number of individual players participated in the poker session.

Using the beauty of oauth2, Settlr makes a request to the dedicated poker group on Splitwise using my access token and renders each member of the group as a participant in the front-end.

At the end of the session, the user then specifies the value of chips left with each player in units as well as the number of buy-ins for each player.

Ultimately, a button click for "Splitwise Update" carries user provided data to the python backend and uses a custom distribution logic which then prepares an Expense() object rendering the transactions between each participant, all of which is encompassed as a single activity in Splitwise.

    expense = Expense()
    expense.setCost(total_money_paid)

    users = []
    for member in members:
        user = ExpenseUser()
        user.setId(member['id'])

        if(float (member['money']) > 0):
            user.setPaidShare(member['money'])
            #user.setPaidShare('2.00')
        else:
            money = abs(float (member['money']))
            print("money negative", money, flush=True)
            user.setOwedShare(str(money))

        users.append(user)

    expense.setDescription("Testing")
    expense.setUsers(users)
    expense.setGroupId(44555421)

    sObj.createExpense(expense)
Enter fullscreen mode Exit fullscreen mode

Thus essentially settling.

Life before Settlr:
Image description

User testing Settlr resulted in exponentially faster run-times (as expected) compared to manually updating each activity in Splitwise while also reiterating accuracy.

Life after Settlr:
Image description

I can't wait to test this out in the upcoming weekend.

Besides the plethora of quality of life changes I have in the pipeline for Settlr, I was researching into "playing cards and chip identification using computer vision".

Integrating this concept greatly improves the aspect of "settling" manifold.

Top comments (0)