From b3b33032131b8f603cd37a76e13beac80176b2b6 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Sat, 6 Apr 2019 01:16:02 +0200 Subject: [PATCH] Yeah boi. --- server/README.md | 1 + server/activate.sh | 4 +-- server/nightr/__main__.py | 4 +++ server/nightr/app.py | 43 +++++++++++++++++++++++++++++++ server/nightr/strategies/dmi.py | 6 +++++ server/nightr/strategies/steam.py | 3 +++ server/requirements.txt | 1 + 7 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 server/nightr/__main__.py create mode 100644 server/nightr/app.py create mode 100644 server/nightr/strategies/dmi.py create mode 100644 server/nightr/strategies/steam.py diff --git a/server/README.md b/server/README.md index 63bb37a..f931c46 100644 --- a/server/README.md +++ b/server/README.md @@ -1,4 +1,5 @@ ```bash cd server/ source activate.sh +run ``` diff --git a/server/activate.sh b/server/activate.sh index 7db2ab7..d9583b3 100755 --- a/server/activate.sh +++ b/server/activate.sh @@ -15,5 +15,5 @@ if (( $FIRST_RUN )); then fi function run() { - python -m -} \ No newline at end of file + python -m nightr +} diff --git a/server/nightr/__main__.py b/server/nightr/__main__.py new file mode 100644 index 0000000..fb17b7a --- /dev/null +++ b/server/nightr/__main__.py @@ -0,0 +1,4 @@ + +if __name__ == "__main__": + from .app import main + main() diff --git a/server/nightr/app.py b/server/nightr/app.py new file mode 100644 index 0000000..5ca1031 --- /dev/null +++ b/server/nightr/app.py @@ -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() diff --git a/server/nightr/strategies/dmi.py b/server/nightr/strategies/dmi.py new file mode 100644 index 0000000..3c601a4 --- /dev/null +++ b/server/nightr/strategies/dmi.py @@ -0,0 +1,6 @@ + +def probability(phone_data) -> float: + """ + The data from DMI. + """ + return 0.63 diff --git a/server/nightr/strategies/steam.py b/server/nightr/strategies/steam.py new file mode 100644 index 0000000..194cca8 --- /dev/null +++ b/server/nightr/strategies/steam.py @@ -0,0 +1,3 @@ + +def lol(phone_data) -> float: + return 0.21 diff --git a/server/requirements.txt b/server/requirements.txt index f2e1e50..0e2276f 100644 --- a/server/requirements.txt +++ b/server/requirements.txt @@ -1 +1,2 @@ Flask==1.0.2 +requests==2.21.0