48 lines
990 B
Python
48 lines
990 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():
|
|
try:
|
|
prob = strategy(phone_data)
|
|
except Exception as e:
|
|
print(f"Strategy {name} failed: {e}")
|
|
continue
|
|
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()
|