From 9c98e5bc50971e91def3b4490deff727c72caa23 Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Mon, 25 Mar 2019 15:49:18 +0000 Subject: Start work on annotation view --- app/main/datasets.py | 19 +++ app/main/routes.py | 25 ++- app/static/annotate.css | 40 +++++ app/templates/annotate/index.html | 337 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 417 insertions(+), 4 deletions(-) create mode 100644 app/main/datasets.py create mode 100644 app/static/annotate.css create mode 100644 app/templates/annotate/index.html (limited to 'app') diff --git a/app/main/datasets.py b/app/main/datasets.py new file mode 100644 index 0000000..c06b4bf --- /dev/null +++ b/app/main/datasets.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +import os +import json + +from flask import current_app + + +def load_data_for_chart(name): + dataset_dir = os.path.join( + current_app.instance_path, current_app.config["DATASET_DIR"] + ) + target_filename = os.path.join(dataset_dir, name + ".json") + with open(target_filename, 'rb') as fid: + data = json.load(fid) + chart_data = [{"value": x} for x in data['series']['V1']['raw']] + return {"chart_data": chart_data} + + diff --git a/app/main/routes.py b/app/main/routes.py index 662e14a..a1d1a63 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- -from flask import render_template -from flask_login import current_user +from flask import render_template, flash, url_for, redirect +from flask_login import current_user, login_required from app.main import bp from app.models import Task +from app.main.datasets import load_data_for_chart @bp.route("/") @@ -15,6 +16,22 @@ def index(): tasks = Task.query.filter_by(annotator_id=user_id).all() tasks_done = [t for t in tasks if t.done] tasks_todo = [t for t in tasks if not t.done] - return render_template("index.html", title="Home", - tasks_done=tasks_done, tasks_todo=tasks_todo) + return render_template( + "index.html", + title="Home", + tasks_done=tasks_done, + tasks_todo=tasks_todo, + ) return render_template("index.html", title="Home") + + +@bp.route("/annotate/", methods=("GET", "POST")) +@login_required +def task(task_id): + task = Task.query.filter_by(id=task_id).first() + if task is None: + flash("No task with id %r has been assigned to you." % task_id) + return redirect(url_for("main.index")) + data = load_data_for_chart(task.dataset.name) + return render_template("annotate/index.html", title="Annotate %s" % + task.dataset.name, task=task, data=data) diff --git a/app/static/annotate.css b/app/static/annotate.css new file mode 100644 index 0000000..d6e30fc --- /dev/null +++ b/app/static/annotate.css @@ -0,0 +1,40 @@ +#graph { + margin: 0 auto; + text-align: center; +} + +/* +path { + stroke-width: 2; + fill: none; +} + +.axis path, .axis line { + fill: none; + stroke: grey; + stroke-width: 1; + shape-rendering: crispEdges; +} + +#changepoint-table { + margin: 0 auto; +} + +*/ + +.line { + fill: none; + stroke: blue; + clip-path: url(#clip); +} + +circle { + clip-path: url(#clip); + fill: blue; +} + +.zoom { + cursor: move; + fill: none; + pointer-events: fill; +} diff --git a/app/templates/annotate/index.html b/app/templates/annotate/index.html new file mode 100644 index 0000000..b605dc3 --- /dev/null +++ b/app/templates/annotate/index.html @@ -0,0 +1,337 @@ +{% extends "base.html" %} + +{% block styles %} +{{super()}} + +{% endblock %} + +{% block app_content %} +

{{ task.dataset.name }}

+
+ +
+
+ +
+
+ + +

Selected Changepoints

+
+ +
+
+ + +{# Based on: https://github.com/benalexkeen/d3-flask-blog-post/blob/master/templates/index.html #} + + +{% endblock %} -- cgit v1.2.3