Yeah boi.

This commit is contained in:
Casper 2019-04-06 01:16:02 +02:00
parent 24ea332aff
commit b3b3303213
No known key found for this signature in database
GPG Key ID: 289CA03790535054
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