2023-06-19 14:20:17 +00:00
|
|
|
import json
|
|
|
|
|
|
|
|
from db import database
|
|
|
|
|
|
|
|
|
2024-06-20 10:34:03 +00:00
|
|
|
class BlackJackStats:
|
|
|
|
def __init__(self, user_id, is_won, bet, payout, hand_player, hand_dealer):
|
|
|
|
self.user_id = user_id
|
|
|
|
self.is_won = is_won
|
|
|
|
self.bet = bet
|
|
|
|
self.payout = payout
|
|
|
|
self.hand_player = json.dumps(hand_player)
|
|
|
|
self.hand_dealer = json.dumps(hand_dealer)
|
|
|
|
|
|
|
|
def push(self):
|
|
|
|
query = """
|
|
|
|
INSERT INTO blackjack (user_id, is_won, bet, payout, hand_player, hand_dealer)
|
|
|
|
VALUES (%s, %s, %s, %s, %s, %s)
|
|
|
|
"""
|
|
|
|
|
2024-07-17 11:47:26 +00:00
|
|
|
values = (
|
|
|
|
self.user_id,
|
|
|
|
self.is_won,
|
|
|
|
self.bet,
|
|
|
|
self.payout,
|
|
|
|
self.hand_player,
|
|
|
|
self.hand_dealer,
|
|
|
|
)
|
2024-06-20 10:34:03 +00:00
|
|
|
|
|
|
|
database.execute_query(query, values)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_user_stats(user_id):
|
|
|
|
query = """
|
|
|
|
SELECT
|
|
|
|
COUNT(*) AS amount_of_games,
|
|
|
|
SUM(bet) AS total_bet,
|
|
|
|
SUM(payout) AS total_payout,
|
|
|
|
SUM(CASE WHEN is_won = 1 THEN 1 ELSE 0 END) AS winning,
|
|
|
|
SUM(CASE WHEN is_won = 0 THEN 1 ELSE 0 END) AS losing
|
|
|
|
FROM blackjack
|
|
|
|
WHERE user_id = %s;
|
|
|
|
"""
|
2024-07-17 11:47:26 +00:00
|
|
|
(
|
|
|
|
amount_of_games,
|
|
|
|
total_bet,
|
|
|
|
total_payout,
|
|
|
|
winning_amount,
|
|
|
|
losing_amount,
|
|
|
|
) = database.select_query(query, (user_id,))[0]
|
2024-06-20 10:34:03 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
"amount_of_games": amount_of_games,
|
|
|
|
"total_bet": total_bet,
|
|
|
|
"total_payout": total_payout,
|
|
|
|
"winning_amount": winning_amount,
|
2024-07-17 11:47:26 +00:00
|
|
|
"losing_amount": losing_amount,
|
2024-06-20 10:34:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_total_rows_count():
|
|
|
|
query = """
|
|
|
|
SELECT SUM(TABLE_ROWS)
|
|
|
|
FROM INFORMATION_SCHEMA.TABLES
|
|
|
|
"""
|
|
|
|
|
|
|
|
return database.select_query_one(query)
|
|
|
|
|
|
|
|
|
2023-06-19 14:20:17 +00:00
|
|
|
class SlotsStats:
|
2024-01-02 15:35:55 +00:00
|
|
|
"""
|
|
|
|
Handles statistics for the /slots command
|
|
|
|
"""
|
2024-03-29 17:17:51 +00:00
|
|
|
|
2023-06-19 14:20:17 +00:00
|
|
|
def __init__(self, user_id, is_won, bet, payout, spin_type, icons):
|
|
|
|
self.user_id = user_id
|
|
|
|
self.is_won = is_won
|
|
|
|
self.bet = bet
|
|
|
|
self.payout = payout
|
|
|
|
self.spin_type = spin_type
|
|
|
|
self.icons = json.dumps(icons)
|
|
|
|
|
2023-06-19 18:18:23 +00:00
|
|
|
def push(self):
|
2024-01-02 15:35:55 +00:00
|
|
|
"""
|
2024-02-28 13:01:20 +00:00
|
|
|
Insert the services from any given slots game into the database
|
2024-01-02 15:35:55 +00:00
|
|
|
"""
|
2023-06-19 14:20:17 +00:00
|
|
|
query = """
|
2024-03-14 20:30:58 +00:00
|
|
|
INSERT INTO slots (user_id, is_won, bet, payout, spin_type, icons)
|
2023-10-23 12:49:46 +00:00
|
|
|
VALUES (%s, %s, %s, %s, %s, %s)
|
2023-06-19 14:20:17 +00:00
|
|
|
"""
|
|
|
|
|
2024-07-17 11:47:26 +00:00
|
|
|
values = (
|
|
|
|
self.user_id,
|
|
|
|
self.is_won,
|
|
|
|
self.bet,
|
|
|
|
self.payout,
|
|
|
|
self.spin_type,
|
|
|
|
self.icons,
|
|
|
|
)
|
2023-06-19 14:20:17 +00:00
|
|
|
|
|
|
|
database.execute_query(query, values)
|
2023-07-14 11:32:05 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_user_stats(user_id):
|
2024-01-02 15:35:55 +00:00
|
|
|
"""
|
|
|
|
Retrieve the Slots stats for a given user from the database.
|
|
|
|
"""
|
2023-07-14 11:32:05 +00:00
|
|
|
query = """
|
|
|
|
SELECT
|
|
|
|
COUNT(*) AS amount_of_games,
|
|
|
|
SUM(bet) AS total_bet,
|
|
|
|
SUM(payout) AS total_payout,
|
|
|
|
SUM(CASE WHEN spin_type = 'pair' AND is_won = 1 THEN 1 ELSE 0 END) AS games_won_pair,
|
|
|
|
SUM(CASE WHEN spin_type = 'three_of_a_kind' AND is_won = 1 THEN 1 ELSE 0 END) AS games_won_three_of_a_kind,
|
|
|
|
SUM(CASE WHEN spin_type = 'three_diamonds' AND is_won = 1 THEN 1 ELSE 0 END) AS games_won_three_diamonds,
|
|
|
|
SUM(CASE WHEN spin_type = 'jackpot' AND is_won = 1 THEN 1 ELSE 0 END) AS games_won_jackpot
|
2024-03-14 20:30:58 +00:00
|
|
|
FROM slots
|
2023-10-23 12:49:46 +00:00
|
|
|
WHERE user_id = %s
|
2023-07-14 11:32:05 +00:00
|
|
|
"""
|
|
|
|
|
2024-07-17 11:47:26 +00:00
|
|
|
(
|
|
|
|
amount_of_games,
|
|
|
|
total_bet,
|
|
|
|
total_payout,
|
|
|
|
games_won_pair,
|
|
|
|
games_won_three_of_a_kind,
|
|
|
|
games_won_three_diamonds,
|
|
|
|
games_won_jackpot,
|
|
|
|
) = database.select_query(query, (user_id,))[0]
|
2023-07-14 11:32:05 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
"amount_of_games": amount_of_games,
|
|
|
|
"total_bet": total_bet,
|
|
|
|
"total_payout": total_payout,
|
|
|
|
"games_won_pair": games_won_pair,
|
|
|
|
"games_won_three_of_a_kind": games_won_three_of_a_kind,
|
|
|
|
"games_won_three_diamonds": games_won_three_diamonds,
|
2024-07-17 11:47:26 +00:00
|
|
|
"games_won_jackpot": games_won_jackpot,
|
2023-07-14 11:32:05 +00:00
|
|
|
}
|