___  ___    _ _    _  _ _____   _____
 / __|/ _ \  | | |  | || |_ _\ \ / / __|
| (_ | (_) | |_  _| | __ || | \ V /| _|
 \___|\___/    |_|  |_||_|___| \_/ |___|

 --- A GOPHER-LIKE INTERFACE FOR HIVE BLOCKCHAIN ---

[Python] Code to calculate your total earned DEC per day

BY: @cs50x | CREATED: Nov. 9, 2021, 8:57 p.m. | VOTES: 9 | PAYOUT: $2.95 | [ VOTE ]

I wrote a Python code to calculate the total number of DEC won per day, the number of games won, and the average number of DEC won per game.

Code

import sys
from datetime import datetime
from pprint import pprint
import requests

username = sys.argv[-1]
url = "https://api2.splinterlands.com/players/balance_history"
params = f"?token_type=DEC&offset=0&limit=1000&username={username}"
rows = requests.get(url + params).json()
d = []

for row in rows:
    if row["type"] == "dec_reward":
        dt = datetime.fromisoformat(row["created_date"].split('T')[0])
        date_key = int(f"{dt.year}{str(dt.month).zfill(2)}{str(dt.day).zfill(2)}")
        r = [r for r in d if r["date"] == date_key]
        if r:
            r[0]["total"] = round(float(row["amount"]) + r[0]["total"], 3)
            r[0]["wins"] += 1
            r[0]["average"] = round(r[0]["total"] / r[0]["wins"], 3)
        else:
            d.append({
                "date": date_key,
                "total": round(float(row["amount"]), 3),
                "wins": 1
            })
pprint(d)

Result

[IMAGE: https://i.gyazo.com/38c6244b132312d9efd9a1214fc76262.png]

TAGS: [ #Splinterlands ] [ #splintertalk ] [ #splinterlands ] [ #python ]

Replies

NO REPLIES FOUND.

[ BACK TO TRENDING ] [ BACK TO MENU ]
CMD>