diff --git a/.github/workflows/development-workflow.yml b/.github/workflows/development-workflow.yml deleted file mode 100644 index 92a1b5b..0000000 --- a/.github/workflows/development-workflow.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Development workflow -on: - push: - branches: [ develop ] - -jobs: - setup: - runs-on: self-hosted - steps: - - uses: actions/checkout@v2 - - name: Set Up ENV - run: | - echo "${{ secrets.API_TOKEN }}" >> ./api/.env - echo "${{ secrets.API_ENDPOINT }}" >> ./api/.env - echo "${{ secrets.SECRET_TOKEN}}" >> ./api/.env - - build-image: - needs: setup - runs-on: self-hosted - steps: - - name: Build the Docker image - run: docker build . --file Dockerfile -t bot-detector/bd-ml:latest --build-arg api_port=6532 --build-arg root_path=/ml --target production - - - name: Tag Image - run: docker tag bot-detector/bd-ml:latest hub.osrsbotdetector.com/bot-detector/bd-ml:latest - - - name: Login to Docker Registry - run: echo "${{ secrets.DOCKER_REGISTRY_PASSWORD }}" | docker login https://hub.osrsbotdetector.com -u "${{ secrets.DOCKER_REGISTRY_USERNAME }}" --password-stdin - - - name: Push Image to Registry - run: docker push hub.osrsbotdetector.com/bot-detector/bd-ml:latest - - deploy: - needs: build-image - runs-on: self-hosted - steps: - - name: Apply Possible Deployment Changes - run: kubectl apply -f deployment/ - - - name: Restart Deployment for Possible Container Changes - run: kubectl rollout restart deploy bd-ml \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index f2679e9..154b205 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,6 @@ { - "python.formatting.provider": "black", - "python.terminal.activateEnvironment": true -} \ No newline at end of file + "[python]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "charliermarsh.ruff" + } + } \ No newline at end of file diff --git a/api/cogs/predict.py b/api/cogs/predict.py index 24a84f2..5dc5f56 100644 --- a/api/cogs/predict.py +++ b/api/cogs/predict.py @@ -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. @@ -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") @@ -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"] @@ -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] @@ -107,4 +108,4 @@ def predict( # convert output to dict output = output.to_dict(orient="records") - return output \ No newline at end of file + return output diff --git a/api/cogs/requests.py b/api/cogs/requests.py index 972971c..45322fe 100644 --- a/api/cogs/requests.py +++ b/api/cogs/requests.py @@ -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 @@ -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 = [] @@ -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