From 7e09a1e51f5954856011e9997a587fc0ae28f656 Mon Sep 17 00:00:00 2001 From: Kristjan Komlosi Date: Mon, 13 Jul 2020 14:28:09 +0200 Subject: [PATCH] modify index.html into Jinja2 rendering template --- terahz/__init_.py | 29 +++++++++- terahz/templates/index.html | 110 ++++++------------------------------ 2 files changed, 42 insertions(+), 97 deletions(-) diff --git a/terahz/__init_.py b/terahz/__init_.py index 35cdcec..314ebee 100644 --- a/terahz/__init_.py +++ b/terahz/__init_.py @@ -2,9 +2,11 @@ '''Main TeraHz backend program''' # All code in this file is licensed under the ISC license, provided in LICENSE.txt from flask import Flask, jsonify -import .sensors +import .terahz app = Flask(__name__) + + @app.route('/data') def sendData(): '''Responder function for /data route''' @@ -15,6 +17,27 @@ def sendData(): response.headers.add('Access-Control-Allow-Origin', '*') return response + @app.route('/') -def renderTable() - return render_template('index.html') +def renderTable(): + wavelengthDict = { + 'A': '410 nm', + 'B': '435 nm', + 'C': '460 nm', + 'D': '485 nm', + 'E': '510 nm', + 'F': '535 nm', + 'G': '560 nm', + 'H': '585 nm', + 'R': '610 nm', + 'I': '645 nm', + 'S': '680 nm', + 'J': '705 nm', + 'T': '730 nm', + 'U': '760 nm', + 'V': '810 nm', + 'W': '860 nm', + 'K': '900 nm', + 'L': '940 nm'} + data = [s.getData(), l.getData(), u.getABI()] + return render_template('index.html', data = data, wavelengths = wavelengthDict) diff --git a/terahz/templates/index.html b/terahz/templates/index.html index 573d246..88c9581 100644 --- a/terahz/templates/index.html +++ b/terahz/templates/index.html @@ -48,96 +48,18 @@ Irradiance [μW/cm²] - - A - 410 nm - --- - - - B - 435 nm - --- - - - C - 460 nm - --- - - - D - 485 nm - --- - - - E - 510 nm - --- - - - F - 535 nm - --- - - - G - 560 nm - --- - - - H - 585 nm - --- - - - R - 610 nm - --- - - - I - 645 nm - --- - - - S - 680 nm - --- - - - J - 705 nm - --- - - - T - 730 nm - --- - - - U - 760 nm - --- - - - V - 810 nm - --- - - - W - 860 nm - --- - - - K - 900 nm - --- - - - L - 940 nm - --- - + {% for band, irr in data[0] %} + + + {{band}} + + + {{wld[band]}} + + + {{irr}} + + @@ -152,19 +74,19 @@ Illuminance [lx] - --- + {{data[1]}} UVA irradiance [μW/cm²] - --- + {{data[2][0]}} UVB irradiance [μW/cm²] - --- + {{data[2][1]}} UVA/UVB average [μW/cm²] - --- + {{data[2][2]}}