nightr/server/nightr/app.py

44 lines
871 B
Python
Raw Normal View History

2019-04-05 23:16:02 +00:00
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()