Skip to content

Commit

Permalink
Merge branch 'master' of github.com:w3champions/mmr-service
Browse files Browse the repository at this point in the history
  • Loading branch information
sickboyyy committed Feb 10, 2021
2 parents 5c2f0ba + 04c7299 commit f9a6b85
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 272 deletions.
10 changes: 10 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ubuntu:20.04

WORKDIR /w3champions-mmr-service

COPY . .

RUN pip install pipenv
RUN pipenv install

CMD pipenv run python main.py
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pytest = "*"

[packages]
glicko2 = "*"
Expand Down
181 changes: 0 additions & 181 deletions Pipfile.lock

This file was deleted.

6 changes: 3 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ pool:
steps:
- script: |
python3 -m pip install --upgrade pip setuptools wheel
python3 -m pip install pipenv pytest
python3 -m pipenv install --system
python3 -m pytest
python3 -m pip install pipenv
python3 -m pipenv install --dev
python3 -m pipenv run pytest
displayName: 'Run fastapi tests'

- task: PublishTestResults@2
Expand Down
5 changes: 4 additions & 1 deletion common/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# TODO: Not sure what this is, could use a more descriptive name.
# Constant to go from Mu/Standard deviation representation of Logistic distr.
# to Mu/Scale representation.
# https://en.wikipedia.org/wiki/Logistic_distribution
C_SD = 0.551328895

# TODO: Should be hardcoded to the same value as in the python mmr service
BETA = 215
20 changes: 18 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
import numpy as np
import uvicorn
from fastapi import FastAPI

from mmr.update_mmr import UpdateMmrRequestBody, update_after_game, UpdateMmrResponseBody
from mmr.bayesian_rating_w3c import UpdateMmrRequestBody, update_after_game, UpdateMmrResponseBody
from teambalance.balance import BalanceTeamResponseBody, BalanceTeamRequestBody, Balance

app = FastAPI()

balance = Balance()

@app.post("/mmr/update")
async def update_mmr(body: UpdateMmrRequestBody) -> UpdateMmrResponseBody:
for i, rd in enumerate(body.rds_list):
if rd < 80:
body.rds_list[i] *= 80/60.25

for i, rating in enumerate(body.ratings_list):
if rating < 0:
body.ratings_list[i] = 0

return update_after_game(body.ratings_list, body.rds_list, body.winning_team, body.number_of_teams)


@app.post("/team/balance")
async def update_mmr(body: BalanceTeamRequestBody) -> BalanceTeamResponseBody:
for i, rd in enumerate(body.rds_list):
if rd < 60.25:
body.rds_list[i] = 60.25
Expand All @@ -16,7 +32,7 @@ async def update_mmr(body: UpdateMmrRequestBody) -> UpdateMmrResponseBody:
if rating < 0:
body.ratings_list[i] = 0

return update_after_game(body.ratings_list, body.rds_list, 1 if body.t1_won else 0)
return balance.find_best_game(np.array(body.ratings_list), np.array(body.rds_list), body.gamemode)


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit f9a6b85

Please sign in to comment.