1616from sqlalchemy .ext .asyncio import AsyncSession
1717from sqlalchemy .sql .expression import Select , select , text
1818from sqlalchemy .sql .functions import func
19+ import aiohttp
1920
2021router = APIRouter ()
2122
@@ -55,7 +56,6 @@ class Prediction(BaseModel):
5556 Gauntlet_bot : Optional [float ] = 0
5657 Nex_bot : Optional [float ] = 0
5758
58-
5959@router .get ("/prediction" , tags = ["Prediction" ])
6060async def get_account_prediction_result (name : str , breakdown : Optional [bool ] = False ):
6161 """
@@ -67,33 +67,25 @@ async def get_account_prediction_result(name: str, breakdown: Optional[bool] = F
6767 A dict containing the prediction data for the player
6868 """
6969 name = await functions .to_jagex_name (name )
70- sql : Select = select (dbPrediction )
71- sql = sql .where (dbPrediction .name == name )
72-
73- async with PLAYERDATA_ENGINE .get_session () as session :
74- session : AsyncSession = session
75- async with session .begin ():
76- data = await session .execute (sql )
77-
78- data = sqlalchemy_result (data ).rows2dict ()
79- keys = ["name" , "Prediction" , "id" , "created" ]
80- data = [
81- {k : float (v ) / 100 if k not in keys else v for k , v in d .items ()} for d in data
82- ]
83- if len (data ) == 0 :
84- raise HTTPException (
85- status_code = status .HTTP_404_NOT_FOUND , detail = "Player not found"
86- )
87-
88- data : dict = data [0 ]
89- prediction = data .pop ("Prediction" )
70+ url = "https://api-v2.prd.osrsbotdetector.com/v2/player/prediction"
71+ params = {"name" : name , "breakdown" : str (breakdown )}
72+ async with aiohttp .ClientSession () as session :
73+ async with session .get (url = url , params = params ) as resp :
74+ if resp .status == 404 :
75+ raise HTTPException (
76+ status_code = status .HTTP_404_NOT_FOUND ,
77+ detail = "Player not found" ,
78+ )
79+ predictions :list [dict ] = await resp .json ()
80+ # [{"player_id":1,"player_name":"extreme4all","prediction_label":"real_player","prediction_confidence":0.988,"created":"2025-11-11T00:14:37","predictions_breakdown":{"LMS_bot":0.0,"Doom_bot":0.0,"Magic_bot":0.0,"Hunter_bot":0.0,"Mining_bot":0.0,"Zulrah_bot":0.004,"Barrows_bot":0.0,"Cooking_bot":0.0,"Fishing_bot":0.0,"Real_Player":0.988,"Vorkath_bot":0.0,"Crafting_bot":0.0,"Gauntlet_bot":0.0,"Smithing_bot":0.0,"Fletching_bot":0.0,"Blast_mine_bot":0.0,"Wildy_boss_bot":0.008,"Wintertodt_bot":0.0,"Woodcutting_bot":0.0,"Thieving_vyre_bot":0.0,"Thieving_master_farmer_bot":0.0}}]
81+ prediction = predictions [0 ]
9082 data = {
91- "player_id" : data .pop ("id " ),
92- "player_name" : data .pop ("name " ),
93- "prediction_label" : prediction ,
94- "prediction_confidence" : data .pop ("Predicted_confidence " ),
95- "created" : data .pop ("created" ),
96- "predictions_breakdown" : data
83+ "player_id" : prediction .pop ("player_id " ),
84+ "player_name" : prediction .pop ("player_name " ),
85+ "prediction_label" : prediction . pop ( "prediction_label" ) ,
86+ "prediction_confidence" : prediction .pop ("prediction_confidence " ),
87+ "created" : prediction .pop ("created" ),
88+ "predictions_breakdown" : prediction
9789 if breakdown or prediction != "Stats_Too_Low"
9890 else None ,
9991 }
@@ -105,8 +97,58 @@ async def get_account_prediction_result(name: str, breakdown: Optional[bool] = F
10597 data ["prediction_confidence" ] = None
10698 if not breakdown :
10799 data ["predictions_breakdown" ] = None
108-
109100 return data
101+ # @router.get("/prediction", tags=["Prediction"])
102+ # async def get_account_prediction_result(name: str, breakdown: Optional[bool] = False):
103+ # """
104+ # Parameters:
105+ # name: The name of the player to get the prediction for
106+ # breakdown: If True, always return breakdown, even if the prediction is Stats_Too_Low
107+
108+ # Returns:
109+ # A dict containing the prediction data for the player
110+ # """
111+ # name = await functions.to_jagex_name(name)
112+ # sql: Select = select(dbPrediction)
113+ # sql = sql.where(dbPrediction.name == name)
114+
115+ # async with PLAYERDATA_ENGINE.get_session() as session:
116+ # session: AsyncSession = session
117+ # async with session.begin():
118+ # data = await session.execute(sql)
119+
120+ # data = sqlalchemy_result(data).rows2dict()
121+ # keys = ["name", "Prediction", "id", "created"]
122+ # data = [
123+ # {k: float(v) / 100 if k not in keys else v for k, v in d.items()} for d in data
124+ # ]
125+ # if len(data) == 0:
126+ # raise HTTPException(
127+ # status_code=status.HTTP_404_NOT_FOUND, detail="Player not found"
128+ # )
129+
130+ # data: dict = data[0]
131+ # prediction = data.pop("Prediction")
132+ # data = {
133+ # "player_id": data.pop("id"),
134+ # "player_name": data.pop("name"),
135+ # "prediction_label": prediction,
136+ # "prediction_confidence": data.pop("Predicted_confidence"),
137+ # "created": data.pop("created"),
138+ # "predictions_breakdown": data
139+ # if breakdown or prediction != "Stats_Too_Low"
140+ # else None,
141+ # }
142+
143+ # prediction = data.get("prediction_label")
144+
145+ # if prediction == "Stats_Too_Low":
146+ # # never show confidence if stats to low
147+ # data["prediction_confidence"] = None
148+ # if not breakdown:
149+ # data["predictions_breakdown"] = None
150+
151+ # return data
110152
111153
112154@router .post ("/prediction" , tags = ["Prediction" ])
0 commit comments