44 lines
871 B
Python
44 lines
871 B
Python
|
import inspect
|
||
|
import statistics
|
||
|
|
||
|
from flask import Flask, jsonify
|
||
|
|
||
|
from server.nightr.strategies import dmi, steam
|
||
|
|
||
|
app = Flask(__name__)
|
||
|
|
||
|
|
||
|
strategies = {
|
||
|
# name: (weight, probability function)
|
||
|
"dmi": (1.0, dmi.probability),
|
||
|
"steam": (0.5, steam.lol),
|
||
|
}
|
||
|
|
||
|
|
||
|
@app.route("/", methods=["GET", "POST"])
|
||
|
def probabilities():
|
||
|
phone_data = None # TODO
|
||
|
|
||
|
probs = []
|
||
|
for name, (weight, strategy) in strategies.items():
|
||
|
prob = strategy(phone_data)
|
||
|
probs.append({
|
||
|
"name": name,
|
||
|
"doc": inspect.getdoc(strategy),
|
||
|
"prob": prob * weight,
|
||
|
})
|
||
|
|
||
|
return jsonify({
|
||
|
"strategies": probs,
|
||
|
"mean": statistics.mean(p["prob"] for p in probs),
|
||
|
"median": statistics.median(p["prob"] for p in probs),
|
||
|
})
|
||
|
|
||
|
|
||
|
def main():
|
||
|
app.run(host='0.0.0.0')
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
main()
|