This commit is contained in:
Christian 2019-04-06 01:21:18 +02:00
commit 409d7a202a
7 changed files with 60 additions and 2 deletions

View file

@ -1,4 +1,5 @@
```bash
cd server/
source activate.sh
run
```

View file

@ -15,5 +15,5 @@ if (( $FIRST_RUN )); then
fi
function run() {
python -m
}
python -m nightr
}

View file

@ -0,0 +1,4 @@
if __name__ == "__main__":
from .app import main
main()

43
server/nightr/app.py Normal file
View file

@ -0,0 +1,43 @@
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()

View file

@ -0,0 +1,6 @@
def probability(phone_data) -> float:
"""
The data from DMI.
"""
return 0.63

View file

@ -0,0 +1,3 @@
def lol(phone_data) -> float:
return 0.21

View file

@ -1 +1,2 @@
Flask==1.0.2
requests==2.21.0