From bba8c0719c966f19b9f4be27b5a79b1391a28aa6 Mon Sep 17 00:00:00 2001 From: Clemens Klug Date: Mon, 30 Apr 2018 14:33:01 +0200 Subject: [PATCH] * update dockerfile --- Dockerfile | 8 +++---- analysis/util/download.py | 3 ++- docker-compose.yml | 10 ++++---- requirements.txt | 4 ++-- selector/temp_config.py | 5 ++++ selector/templates/games.html | 18 +-------------- selector/templates/results.html | 22 ++++++++++++++++++ selector/webserver.py | 41 ++++++++++++++++++++++++++------- 8 files changed, 73 insertions(+), 38 deletions(-) create mode 100644 selector/templates/results.html diff --git a/Dockerfile b/Dockerfile index 2de600e..94f8894 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,9 +2,7 @@ FROM alpine:edge ADD ["requirements.txt", "/"] RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories && \ - sed -i 's/numpy/#numpy/' requirements.txt && \ - sed -i 's/scipy/#scipy/' requirements.txt && \ - apk add --update libpng libpng-dev freetype freetype-dev g++ python3 py3-numpy python3-dev py-numpy-dev py3-scipy&& \ - pip3 install -r requirements.txt && \ - apk del libpng-dev freetype-dev g++ python3-dev py-numpy-dev && \ + apk add --update --no-cache libpng libpng-dev freetype freetype-dev g++ python3 python3-dev libstdc++ openblas-dev && \ + pip3 --no-cache-dir install -r requirements.txt && \ + apk del libpng-dev freetype-dev g++ python3-dev openblas-dev && \ rm requirements.txt \ No newline at end of file diff --git a/analysis/util/download.py b/analysis/util/download.py index 8ee6d89..a70a81d 100644 --- a/analysis/util/download.py +++ b/analysis/util/download.py @@ -69,7 +69,8 @@ def get_json(source, url): data = source.get(url).json() except Exception as e: - print("exception", e, e.args) # TODO: logging + print("exception", e, e.args) + logger.exception(e) data = None cache[url] = data return data diff --git a/docker-compose.yml b/docker-compose.yml index dc00dbe..fe8efe9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,10 @@ -version: "3" +version: "2.2" services: app: - image: docker.clkl.de/ma/celery:0.1 - build: . + image: docker.clkl.de/ma/celery:0.3.3 + build: ./selector + cpu_count: 4 volumes: - ./:/app working_dir: /app/selector @@ -20,8 +21,7 @@ services: - "traefik.url.frontend.rule=Host:select.ma.potato.kinf.wiai.uni-bamberg.de" celery: - image: docker.clkl.de/ma/celery:0.1 - build: . + image: docker.clkl.de/ma/celery:0.3.3 environment: - PYTHONPATH=/app volumes: diff --git a/requirements.txt b/requirements.txt index 8b4ddee..fc7f208 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ requests==2.18.4 -numpy==1.13.1 +numpy==1.14.2 matplotlib==2.1.0 #osmnx==0.6 networkx==2.0 #pydot==1.2.3 -scipy==1.0.0 +scipy==1.0.1 #ipython==6.2.1 flask==0.12.2 diff --git a/selector/temp_config.py b/selector/temp_config.py index 318da1f..7875531 100644 --- a/selector/temp_config.py +++ b/selector/temp_config.py @@ -126,3 +126,8 @@ CONFIGS = { # TODO "KML": KML, "ActivityMapper": ACTIVITY, } + +URLS = { + "KML": "/", + "ActivityMapper": "#", +} \ No newline at end of file diff --git a/selector/templates/games.html b/selector/templates/games.html index 5f7d91a..1dc2418 100644 --- a/selector/templates/games.html +++ b/selector/templates/games.html @@ -21,21 +21,5 @@ - -
- -
- +show analysis progress/results {% endblock %} \ No newline at end of file diff --git a/selector/templates/results.html b/selector/templates/results.html new file mode 100644 index 0000000..3129a94 --- /dev/null +++ b/selector/templates/results.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} +{% block body %} + +create new analysis + +
+ +
+ +{% endblock %} \ No newline at end of file diff --git a/selector/webserver.py b/selector/webserver.py index d7efdb1..ba77179 100644 --- a/selector/webserver.py +++ b/selector/webserver.py @@ -10,9 +10,10 @@ from clients.webclients import Client, CLIENTS from flask import Flask, render_template, request, redirect, session from tasks import tasks -from selector.temp_config import CONFIGS +from selector.temp_config import CONFIGS, URLS BIOGAMES_HOST = "http://biogames.potato.kinf.wiai.uni-bamberg.de" +#BIOGAMES_HOST = "http://www.biodiv2go.de" RESULT_HOST = "http://results.ma.potato.kinf.wiai.uni-bamberg.de/" app = Flask(__name__) @@ -29,7 +30,7 @@ def index(): def login(): game = request.form["game"] if not game in CLIENTS: - return redirect("/") + return redirect("/?invalid_game") client = CLIENTS[game](host=BIOGAMES_HOST, username=request.form['username'], password=request.form['password']) if client.login(): session['logged_in'] = True @@ -39,12 +40,12 @@ def login(): session['game'] = game session['host'] = BIOGAMES_HOST clients[session['uid']] = client - return redirect("/games") - return redirect("/") + return redirect("/results") + return redirect("/?fail") -@app.route("/games") -def games(): +@app.route("/results") +def results(): if not ('logged_in' in session and session['logged_in']): return redirect("/") if session['logged_in'] and not session['uid'] in clients: @@ -54,7 +55,21 @@ def games(): job_status = json.loads(status) else: job_status = {} - return render_template("games.html", logs=clients[session['uid']].list(), configs=CONFIGS, jobs=job_status) + #for job in job_status: + # results = [] + # for path in job_status[job]['results']: + # results.append(path.replace(tasks.DATA_PATH, RESULT_HOST)) + # print(results) #TODO??? + return render_template("results.html", jobs=job_status) + + +@app.route("/games") +def games(): + if not ('logged_in' in session and session['logged_in']): + return redirect("/") + if session['logged_in'] and not session['uid'] in clients: + clients[session['uid']] = CLIENTS[session['game']](host=session['host'], **session['cookies']) + return render_template("games.html", logs=clients[session['uid']].list(), configs=CONFIGS) @app.route("/start", methods=['POST']) @@ -77,7 +92,7 @@ def start(): } tasks.status_update(session['username'], request.form['name'], status) tasks.analyze.delay(**params) - return redirect("/games") + return redirect("/results") @app.route("/status") @@ -94,6 +109,16 @@ def get_url(path: str): return path.replace(tasks.DATA_PATH, "") +@app.template_filter('get_prefix') +def get_prefix(job): + print(job) + try: + return RESULT_HOST + URLS[job['config']] + except: + return RESULT_HOST + "#" + + + if __name__ == '__main__': app.config.update({"SECRET_KEY": "59765798-2784-11e8-8d05-db4d6f6606c9"}) app.run(host="0.0.0.0", debug=True)