init;add: elo algorithm
This commit is contained in:
commit
4a3da9a536
|
@ -0,0 +1,6 @@
|
|||
# env dir
|
||||
pyelo/
|
||||
|
||||
# config file
|
||||
setup.cfg
|
||||
.vscode/
|
|
@ -0,0 +1,3 @@
|
|||
# ELOStar
|
||||
|
||||
使用`ELO`算法实现明星好感度的比较,原型来自于`Mark Zuckerberg`的[`FaceMash`](https://en.wikipedia.org/wiki/History_of_Facebook#FaceMash)。
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- encoding: utf-8 -*-
|
||||
'''
|
||||
@File : app.py
|
||||
@Author: liuyihui
|
||||
@Email : liuyihui02@gmail.com
|
||||
'''
|
||||
|
||||
# here put the import lib
|
||||
from flask import Flask, request, render_template
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/', methods=["GET"])
|
||||
def root():
|
||||
return "Hello World!"
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='0.0.0.0', port=4002)
|
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- encoding: utf-8 -*-
|
||||
'''
|
||||
@File : elo.py
|
||||
@Author : liuyihui
|
||||
@Email : liuyihui02@gmail.com
|
||||
'''
|
||||
|
||||
# here put the import lib
|
||||
import math
|
||||
from typing_extensions import Self
|
||||
|
||||
class Person(object):
|
||||
'''personal information
|
||||
|
||||
Attributes
|
||||
----------
|
||||
rate : elo rate
|
||||
name : name
|
||||
sex : male or female
|
||||
link : baike link
|
||||
|
||||
Methods
|
||||
-------
|
||||
compute_K : compute the constant K
|
||||
'''
|
||||
def __init__(self, name: str, rate: float = 1400, *, sex: str = None, link: str = None) -> None:
|
||||
self.name = name
|
||||
self.rate = rate
|
||||
self.link = link
|
||||
|
||||
if sex and sex not in ['male', 'female']:
|
||||
raise ValueError("Sex must be male or female")
|
||||
self.sex = sex
|
||||
|
||||
def compute_wre(self, B: Self) -> float:
|
||||
'''compute win rate expectation (wre for short)
|
||||
|
||||
Parameters
|
||||
----------
|
||||
B : another person
|
||||
|
||||
Returns
|
||||
-------
|
||||
wre : win rate expectation
|
||||
'''
|
||||
wre = 1 / (1 + math.pow(10, (B.rate-self.rate)/400))
|
||||
return wre
|
||||
|
||||
def compute_K(self) -> float:
|
||||
if self.rate > 2400:
|
||||
return 12
|
||||
elif self.rate > 2000:
|
||||
return 24
|
||||
else:
|
||||
return 36
|
||||
|
||||
def set_result(self, wre: float, res: float) -> None:
|
||||
'''set result of this game
|
||||
|
||||
Parameters
|
||||
----------
|
||||
wre : win rate expectation
|
||||
res : the result, 0 for lose, 1 for win and 0.5 for draw
|
||||
'''
|
||||
K = self.compute_K()
|
||||
self.rate += K * (res - wre)
|
|
@ -0,0 +1 @@
|
|||
flask
|
Reference in New Issue