~jae/dn0magik-mc

4f15caa7a63215c16f7bd6908c8c5518cc2dac8b — Jae Lo Presti (DN0) 1 year, 8 months ago 7f37069
StatsAPI: add util + fill API on some stats (number of users registered
all/24h)
2 files changed, 26 insertions(+), 1 deletions(-)

M src/api/statusapi.py
M src/utils/dbutils.py
M src/api/statusapi.py => src/api/statusapi.py +10 -1
@@ 1,5 1,7 @@
from flask import Blueprint, jsonify

from utils.dbutils import get_users_registered_last_day, get_all_users_count

status_api = Blueprint("status_api", __name__)

# KEPT FOR NICE DISPLAY ON LEGACY LAUNCHERS


@@ 22,6 24,13 @@ def status_api_check():
@status_api.route("/orders/statistics")
def status_order_stats():
    # TODO: pull data from DB to feed this endpoint
    sample_res = {"total": "1", "last24h": "1", "saleVelocityPerSecon": "0"}
    last_day_users = get_users_registered_last_day()
    all_users = get_all_users_count()

    sample_res = {
        "total": all_users,
        "last24h": last_day_users,
        "saleVelocityPerSecon": 0,
    }

    return jsonify(sample_res)

M src/utils/dbutils.py => src/utils/dbutils.py +16 -0
@@ 1,3 1,5 @@
from datetime import datetime, timedelta

from utils.db import get_object, Users




@@ 5,3 7,17 @@ def get_uuid_from_username(username: str):
    user = get_object(Users, username=username)

    return user.uuid if user else None


def get_users_registered_last_day():
    day_ago = datetime.now() - timedelta(days=1)

    number_last_day = Users.select().where(Users.registered_on > day_ago).count()

    return number_last_day


def get_all_users_count():
    number_all_users = Users.select().count()

    return number_all_users