-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75d582a
commit d85e1cf
Showing
13 changed files
with
637 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"[python]": { | ||
"editor.defaultFormatter": "ms-python.black-formatter" | ||
}, | ||
"python.formatting.provider": "none" | ||
} | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "charliermarsh.ruff" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from fastapi import APIRouter, Query | ||
from src.app.repositories.highscore import HighscoreLatest | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/highscore/latest") | ||
async def get_highscore_latest( | ||
player_id: int, | ||
many: bool = False, | ||
limit: int = Query(default=10, ge=0, le=10_000), | ||
): | ||
repo = HighscoreLatest() | ||
if many: | ||
data = await repo.get_many(start=player_id, limit=limit) | ||
else: | ||
data = await repo.get(id=player_id) | ||
return data | ||
|
||
|
||
# @router.get("/highscore") | ||
# async def get_highscore( | ||
# player_id: str = None, | ||
# greater_than: bool = None, | ||
# limit: int = Query(default=1_000, ge=0, le=10_000), | ||
# ): | ||
# return {} | ||
|
||
|
||
# @router.get("/highscore/xp") | ||
# async def get_highscore_xp( | ||
# player_id: str = None, | ||
# greater_than: bool = None, | ||
# limit: int = Query(default=1_000, ge=0, le=10_000), | ||
# ): | ||
# return {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
class AbstractAPI(ABC): | ||
@abstractmethod | ||
def get(self, id): | ||
raise NotImplementedError | ||
|
||
@abstractmethod | ||
def get_many(self, start, limit): | ||
raise NotImplementedError | ||
|
||
@abstractmethod | ||
def update(self, id, data): | ||
raise NotImplementedError | ||
|
||
@abstractmethod | ||
def delete(self, id): | ||
raise NotImplementedError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from src.core.database.models.highscore import ( | ||
# playerHiscoreData, | ||
PlayerHiscoreDataLatest, | ||
# PlayerHiscoreDataXPChange, | ||
) | ||
from src.core.database.database import SessionFactory | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
from sqlalchemy import select | ||
from sqlalchemy.ext.asyncio import AsyncResult, AsyncSession | ||
from sqlalchemy.sql.expression import Select | ||
from fastapi.encoders import jsonable_encoder | ||
from src.app.repositories.abstract_repo import AbstractAPI | ||
|
||
|
||
class HighscoreLatest(AbstractAPI): | ||
def __init__(self) -> None: | ||
super().__init__() | ||
self.table = PlayerHiscoreDataLatest | ||
|
||
async def _simple_execute(self, sql) -> dict: | ||
async with SessionFactory() as session: | ||
session: AsyncSession | ||
|
||
result: AsyncResult = await session.execute(sql) | ||
result = result.scalars().all() | ||
return jsonable_encoder(result) | ||
|
||
async def get(self, id: int): | ||
sql: Select = select(self.table) | ||
sql = sql.where(self.table.Player_id == id) | ||
return await self._simple_execute(sql) | ||
|
||
async def get_many(self, start: int, limit: int = 5000): | ||
sql: Select = select(self.table) | ||
sql = sql.where(self.table.Player_id > start) | ||
sql = sql.limit(limit) | ||
return await self._simple_execute(sql) |
68 changes: 34 additions & 34 deletions
68
src/app/models/player.py → src/app/repositories/player.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
from src.core.database.models.player import Player as dbPlayer | ||
from src.core.database.database import SessionFactory | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
from sqlalchemy import delete, insert, select, update | ||
from sqlalchemy.ext.asyncio import AsyncResult, AsyncSession | ||
from sqlalchemy.sql.expression import Delete, Insert, Select, Update, and_ | ||
from fastapi.encoders import jsonable_encoder | ||
|
||
|
||
class Player: | ||
def __init__(self) -> None: | ||
pass | ||
|
||
async def get_player( | ||
self, player_id: int, player_name: str, greater_than: bool, limit: int = 1_000 | ||
): | ||
table = dbPlayer | ||
sql_select: Select = select(table) | ||
sql_select = sql_select.limit(limit) | ||
|
||
if player_name: | ||
sql_select = sql_select.where(dbPlayer.name >= player_name) | ||
|
||
if greater_than: | ||
sql_select = sql_select.where(dbPlayer.id >= player_id) | ||
elif player_id: | ||
sql_select = sql_select.where(dbPlayer.id == player_id) | ||
|
||
async with SessionFactory() as session: | ||
session: AsyncSession | ||
|
||
result: AsyncResult = await session.execute(sql_select) | ||
result = result.scalars().all() | ||
return jsonable_encoder(result) | ||
from src.core.database.models.player import Player as dbPlayer | ||
from src.core.database.database import SessionFactory | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
from sqlalchemy import delete, insert, select, update | ||
from sqlalchemy.ext.asyncio import AsyncResult, AsyncSession | ||
from sqlalchemy.sql.expression import Delete, Insert, Select, Update, and_ | ||
from fastapi.encoders import jsonable_encoder | ||
|
||
|
||
class Player: | ||
def __init__(self) -> None: | ||
pass | ||
|
||
async def get_player( | ||
self, player_id: int, player_name: str, greater_than: bool, limit: int = 1_000 | ||
): | ||
table = dbPlayer | ||
sql_select: Select = select(table) | ||
sql_select = sql_select.limit(limit) | ||
|
||
if player_name: | ||
sql_select = sql_select.where(dbPlayer.name >= player_name) | ||
|
||
if greater_than: | ||
sql_select = sql_select.where(dbPlayer.id >= player_id) | ||
elif player_id: | ||
sql_select = sql_select.where(dbPlayer.id == player_id) | ||
|
||
async with SessionFactory() as session: | ||
session: AsyncSession | ||
|
||
result: AsyncResult = await session.execute(sql_select) | ||
result = result.scalars().all() | ||
return jsonable_encoder(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
from pydantic import BaseModel, ConfigDict | ||
from datetime import datetime, date | ||
from typing import Optional | ||
|
||
class PlayerHiscoreData(BaseModel): | ||
model_config = ConfigDict(from_attributes=True) | ||
|
||
id: Optional[int] = None | ||
timestamp: datetime = datetime.utcnow() | ||
ts_date: Optional[date] = None | ||
Player_id: int | ||
total: int | ||
attack: int | ||
defence: int | ||
strength: int | ||
hitpoints: int | ||
ranged: int | ||
prayer: int | ||
magic: int | ||
cooking: int | ||
woodcutting: int | ||
fletching: int | ||
fishing: int | ||
firemaking: int | ||
crafting: int | ||
smithing: int | ||
mining: int | ||
herblore: int | ||
agility: int | ||
thieving: int | ||
slayer: int | ||
farming: int | ||
runecraft: int | ||
hunter: int | ||
construction: int | ||
league: int | ||
bounty_hunter_hunter: int | ||
bounty_hunter_rogue: int | ||
cs_all: int | ||
cs_beginner: int | ||
cs_easy: int | ||
cs_medium: int | ||
cs_hard: int | ||
cs_elite: int | ||
cs_master: int | ||
lms_rank: int | ||
soul_wars_zeal: int | ||
abyssal_sire: int | ||
alchemical_hydra: int | ||
barrows_chests: int | ||
bryophyta: int | ||
callisto: int | ||
cerberus: int | ||
chambers_of_xeric: int | ||
chambers_of_xeric_challenge_mode: int | ||
chaos_elemental: int | ||
chaos_fanatic: int | ||
commander_zilyana: int | ||
corporeal_beast: int | ||
crazy_archaeologist: int | ||
dagannoth_prime: int | ||
dagannoth_rex: int | ||
dagannoth_supreme: int | ||
deranged_archaeologist: int | ||
general_graardor: int | ||
giant_mole: int | ||
grotesque_guardians: int | ||
hespori: int | ||
kalphite_queen: int | ||
king_black_dragon: int | ||
kraken: int | ||
kreearra: int | ||
kril_tsutsaroth: int | ||
mimic: int | ||
nightmare: int | ||
nex: int = 0 | ||
phosanis_nightmare: int | ||
obor: int | ||
phantom_muspah: int = 0 | ||
sarachnis: int | ||
scorpia: int | ||
skotizo: int | ||
tempoross: int = 0 | ||
the_gauntlet: int | ||
the_corrupted_gauntlet: int | ||
theatre_of_blood: int | ||
theatre_of_blood_hard: int = 0 | ||
thermonuclear_smoke_devil: int | ||
tombs_of_amascut: int = 0 | ||
tombs_of_amascut_expert: int = 0 | ||
tzkal_zuk: int | ||
tztok_jad: int | ||
venenatis: int | ||
vetion: int | ||
vorkath: int | ||
wintertodt: int | ||
zalcano: int | ||
zulrah: int | ||
rifts_closed: int = 0 | ||
artio: int = 0 | ||
calvarion: int = 0 | ||
duke_sucellus: int = 0 | ||
spindel: int = 0 | ||
the_leviathan: int = 0 | ||
the_whisperer: int = 0 | ||
vardorvis: int = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import logging | ||
# needed for log formatting |
Oops, something went wrong.