Skip to content

Commit

Permalink
use private api
Browse files Browse the repository at this point in the history
  • Loading branch information
extreme4all committed Feb 3, 2024
1 parent c543b92 commit 7d16d44
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 87 deletions.
41 changes: 0 additions & 41 deletions .github/workflows/development-workflow.yml

This file was deleted.

8 changes: 5 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"python.formatting.provider": "black",
"python.terminal.activateEnvironment": true
}
"[python]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "charliermarsh.ruff"
}
}
19 changes: 10 additions & 9 deletions api/cogs/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@

logger = logging.getLogger(__name__)


def predict(
hiscores, names, binary_classifier: classifier, multi_classifier: classifier,
hiscores,
names,
binary_classifier: classifier,
multi_classifier: classifier,
) -> List[dict]:
"""
This function takes in a list of hiscores, a list of names, and two classifiers.
Expand Down Expand Up @@ -42,13 +46,12 @@ def predict(
multi_pred = pd.DataFrame(
multi_pred, index=hiscores.index, columns=np.unique(config.LABELS)
)

# remove real players from multi
logger.debug("Removing real players from multi for players")
real_players = binary_pred.query("Real_Player > 0.5").index
mask = ~(multi_pred.index.isin(real_players))
multi_pred = multi_pred[mask]


# remove bots from real players
logger.debug("Removing bots from binary for players")
Expand All @@ -69,12 +72,10 @@ def predict(
how="left",
)


# cleanup predictions
logger.debug("Cleaning up predictions for players")
mask = output["Real_Player"].isna() # all multi class predictions


# cleanup multi suffixes
output.loc[mask, "Unknown_bot"] = output[mask]["Unknown_bot_multi"]
output.loc[mask, "Real_Player"] = output[mask]["Real_Player_multi"]
Expand All @@ -93,11 +94,11 @@ def predict(
# low level player predictions are not accurate
logger.debug("Removing low level players for players")

mask = output['id'].isin(low_level)
mask = output["id"].isin(low_level)
output.loc[mask, "Prediction"] = "Stats_Too_Low"

l = len(output[output["Prediction"] == "Stats_Too_Low"])
logger.debug(f"Len low level players {l}")
len_too_low_players = len(output[output["Prediction"] == "Stats_Too_Low"])
logger.debug(f"Len low level players {len_too_low_players}")

# cut off name
output["name"] = output["name"].astype(str).str[:12]
Expand All @@ -107,4 +108,4 @@ def predict(

# convert output to dict
output = output.to_dict(orient="records")
return output
return output
49 changes: 15 additions & 34 deletions api/cogs/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,14 @@ async def get_labels():
return data


# Define an asynchronous function to get player data for a specific label ID
async def get_player_data(label_id):
# Initialize pagination parameters
page = 1
row_count = 5000
url = f"{config.detector_api}/v1/player/bulk"
async def get_player_data(label_id: int, limit: int = 5000):
url = "http://private-api-svc.bd-prd.svc:5000/v2/player"

params = {
"token": config.token,
"page": page,
"row_count": row_count,
"player_id": 1,
"label_id": label_id,
"greater_than": 1,
"limit": limit,
}

# Initialize a list to store player data
Expand All @@ -89,28 +85,18 @@ async def get_player_data(label_id):
logger.info(f"received: {len(data)}, in total {len(players)}")

# Check if the received data is less than the row count, indicating the end of data
if len(data) < row_count:
if len(data) < limit:
break

# Increment the page parameter for the next request
params["page"] += 1
params["player_id"] = data[-1]["id"]

return players


# Define an asynchronous function to get hiscore data for a specific label ID
async def get_hiscore_data(label_id):
# Initialize pagination parameters
page = 1
row_count = 5000
url = f"{config.detector_api}/v1/hiscore/Latest/bulk"

params = {
"token": config.token,
"page": page,
"row_count": row_count,
"label_id": label_id,
}
async def get_hiscore_data(label_id: int, limit: int = 5000):
url = "http://private-api-svc.bd-prd.svc:5000/v2/highscore/latest" # TODO: fix hardcoded
params = {"player_id": id, "many": 1, "limit": limit}

# Initialize a list to store hiscore data
hiscores = []
Expand All @@ -123,23 +109,18 @@ async def get_hiscore_data(label_id):
logger.info(f"received: {len(data)}, in total {len(hiscores)}")

# Check if the received data is less than the row count, indicating the end of data
if len(data) < row_count:
if len(data) < limit:
break

# Increment the page parameter for the next request
params["page"] += 1
params["player_id"] = data[-1]["id"]

return hiscores


async def get_prediction_data(id:int=0, limit:int=0):
url = f"{config.detector_api}/v1/prediction/data"
url = "http://private-api-svc.bd-prd.svc:5000/v2/highscore/latest" #TODO: fix hardcoded
params = {
"player_id":id,
"many": 1,
"limit": limit
}
async def get_prediction_data(id: int = 0, limit: int = 0):
url = "http://private-api-svc.bd-prd.svc:5000/v2/highscore/latest" # TODO: fix hardcoded
params = {"player_id": id, "many": 1, "limit": limit}

data = await retry_request(url=url, params=params)
return data
Expand Down

0 comments on commit 7d16d44

Please sign in to comment.