Nice badge
This commit is contained in:
parent
31610f6100
commit
b1ddbe23ee
47
app.py
47
app.py
|
|
@ -5,7 +5,6 @@ import json
|
||||||
import os
|
import os
|
||||||
from os.path import join
|
from os.path import join
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from typing import Optional
|
|
||||||
import uuid
|
import uuid
|
||||||
from . import db, config, scanner, calibration
|
from . import db, config, scanner, calibration
|
||||||
|
|
||||||
|
|
@ -13,10 +12,10 @@ app = Flask(__name__)
|
||||||
app.config['SECRET_KEY'] = os.urandom(20).hex()
|
app.config['SECRET_KEY'] = os.urandom(20).hex()
|
||||||
|
|
||||||
|
|
||||||
def get_calibration(conn: sqlite3.Connection) -> Optional[db.Calibration]:
|
def get_calibration(conn: sqlite3.Connection) -> db.Calibration:
|
||||||
calibration_id = session.get('calibration_id', None)
|
calibration_id = session.get('calibration_id', None)
|
||||||
if calibration_id is None:
|
if calibration_id is None:
|
||||||
return None
|
return db.Calibration.Dummy
|
||||||
|
|
||||||
return db.Calibration.get_from_id(calibration_id, conn)
|
return db.Calibration.get_from_id(calibration_id, conn)
|
||||||
|
|
||||||
|
|
@ -24,7 +23,7 @@ def get_calibration(conn: sqlite3.Connection) -> Optional[db.Calibration]:
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
def inject_stage_and_region():
|
def inject_stage_and_region():
|
||||||
conn = db.get()
|
conn = db.get()
|
||||||
return dict(calibration=get_calibration(conn))
|
return dict(calibration=get_calibration(conn), CalibrationState=db.CalibrationState)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
|
|
@ -58,11 +57,13 @@ def scan(id: int):
|
||||||
|
|
||||||
@app.route("/calibrate/")
|
@app.route("/calibrate/")
|
||||||
def calibrate():
|
def calibrate():
|
||||||
|
print(session)
|
||||||
conn = db.get()
|
conn = db.get()
|
||||||
with conn:
|
if 'calibration_id' not in session:
|
||||||
calibration = db.Calibration.create(conn)
|
with conn:
|
||||||
session['calibration_id'] = calibration.id
|
calibration = db.Calibration.create(conn)
|
||||||
return render_template('calibrate.html', calibration=calibration)
|
session['calibration_id'] = calibration.id
|
||||||
|
return render_template('calibrate.html', leds=config.LEDS_UUIDS)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/preview/<id>")
|
@app.route("/api/preview/<id>")
|
||||||
|
|
@ -76,14 +77,22 @@ def preview(id: int):
|
||||||
return "Impossible de capturer l'image.", 500
|
return "Impossible de capturer l'image.", 500
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/scan-for-calibration/<id>")
|
@app.route("/api/scan-for-calibration")
|
||||||
def scan_calibration(id: int):
|
def scan_calibration():
|
||||||
conn = db.get()
|
conn = db.get()
|
||||||
calibration = db.Calibration.get_from_id(id, conn)
|
|
||||||
|
if 'calibration_id' not in session:
|
||||||
|
with conn:
|
||||||
|
calibration = db.Calibration.create(conn)
|
||||||
|
calibration_id = str(calibration.id)
|
||||||
|
session['calibration_id'] = calibration.id
|
||||||
|
else:
|
||||||
|
calibration_id = str(session['calibration_id'])
|
||||||
|
calibration = get_calibration(conn)
|
||||||
|
|
||||||
def generate():
|
def generate():
|
||||||
length = len(config.LEDS_UUIDS)
|
length = len(config.LEDS_UUIDS)
|
||||||
for index, led_uuid in enumerate(scanner.scan(join(config.CALIBRATION_DIR, id))):
|
for index, led_uuid in enumerate(scanner.scan(join(config.CALIBRATION_DIR, calibration_id))):
|
||||||
yield f"{led_uuid},{(index+1)/length}\n"
|
yield f"{led_uuid},{(index+1)/length}\n"
|
||||||
|
|
||||||
with conn:
|
with conn:
|
||||||
|
|
@ -110,6 +119,20 @@ def run_calibration(id: int):
|
||||||
return 'ok'
|
return 'ok'
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/validate-calibration')
|
||||||
|
def validate_calibration():
|
||||||
|
conn = db.get()
|
||||||
|
calib = get_calibration(conn)
|
||||||
|
if calib is None:
|
||||||
|
return 'oops', 404
|
||||||
|
|
||||||
|
calib.state = db.CalibrationState.IsValidated
|
||||||
|
with conn:
|
||||||
|
calib.save(conn)
|
||||||
|
|
||||||
|
return redirect('/')
|
||||||
|
|
||||||
|
|
||||||
@app.route("/calibration/<id>")
|
@app.route("/calibration/<id>")
|
||||||
def calibration_page(id: int):
|
def calibration_page(id: int):
|
||||||
conn = db.get()
|
conn = db.get()
|
||||||
|
|
|
||||||
3
db.py
3
db.py
|
|
@ -93,6 +93,9 @@ class Calibration:
|
||||||
return Calibration.from_row(response.fetchone())
|
return Calibration.from_row(response.fetchone())
|
||||||
|
|
||||||
|
|
||||||
|
Calibration.Dummy = Calibration(-1, CalibrationState.Empty)
|
||||||
|
|
||||||
|
|
||||||
class Acquisition:
|
class Acquisition:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def select_args() -> str:
|
def select_args() -> str:
|
||||||
|
|
|
||||||
|
|
@ -22,29 +22,30 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="navbarBasicExample" class="navbar-menu">
|
<div id="navbarBasicExample" class="navbar-menu">
|
||||||
<div class="navbar-end">
|
<div class="navbar-end">
|
||||||
<a class="navbar-item" href="#">
|
<a id="calibration-tag-0" class="calibration-tag navbar-item" href="#" {% if calibration.state != 0 %}style="display: none;"{% endif %}>
|
||||||
{% if calibration is none or calibration.state == 0 %}
|
<span id="calibration-tag-0" class="tags has-addons">
|
||||||
<span class="tags has-addons">
|
<span class="tag is-dark">étalonnage</span>
|
||||||
<span class="tag is-dark">étalonnage</span>
|
<span class="tag is-danger">aucune donnée</span>
|
||||||
<span class="tag is-danger">aucune donnée</span>
|
</span>
|
||||||
</span>
|
|
||||||
{% elif calibration.state == 1 %}
|
|
||||||
<span class="tags has-addons">
|
|
||||||
<span class="tag is-dark">étalonnage</span>
|
|
||||||
<span class="tag is-warning">non calculé</span>
|
|
||||||
</span>
|
|
||||||
{% elif calibration.state == 2 %}
|
|
||||||
<span class="tags has-addons">
|
|
||||||
<span class="tag is-dark">étalonnage</span>
|
|
||||||
<span class="tag is-warning">non validé</span>
|
|
||||||
</span>
|
|
||||||
{% elif calibration.state == 3 %}
|
|
||||||
<a href="/calibration/{{ object.id }}" class="tags has-addons">
|
|
||||||
<span class="tag is-dark">étalonnage</span>
|
|
||||||
<span class="tag is-success">fait</span>
|
|
||||||
</a>
|
|
||||||
{% endif %}
|
|
||||||
</a>
|
</a>
|
||||||
|
<a id="calibration-tag-1" class="calibration-tag navbar-item" href="#" {% if calibration.state != 1 %}style="display: none;"{% endif %}>
|
||||||
|
<span class="tags has-addons" >
|
||||||
|
<span class="tag is-dark">étalonnage</span>
|
||||||
|
<span class="tag is-warning">non calculé</span>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
<a id="calibration-tag-2" class="calibration-tag navbar-item" href="#" {% if calibration.state != 2 %}style="display: none;"{% endif %}>
|
||||||
|
<span class="tags has-addons">
|
||||||
|
<span class="tag is-dark">étalonnage</span>
|
||||||
|
<span class="tag is-warning">non validé</span>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
<span id="calibration-tag-3" class="calibration-tag navbar-item" href="#" {% if calibration.state != 3 %}style="display: none;"{% endif %}>
|
||||||
|
<span, class="tags has-addons">
|
||||||
|
<span class="tag is-dark">étalonnage</span>
|
||||||
|
<span class="tag is-success">validé</span>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@
|
||||||
cell.classList.add('cell');
|
cell.classList.add('cell');
|
||||||
img = document.createElement('img');
|
img = document.createElement('img');
|
||||||
img.classList.add('is-loading');
|
img.classList.add('is-loading');
|
||||||
img.src = '/data/calibration/{{ calibration.id }}/{{ led }}.jpg?v=0';
|
img.src = '/data/calibrations/{{ calibration.id }}/{{ led }}.jpg?v=0';
|
||||||
cell.appendChild(img);
|
cell.appendChild(img);
|
||||||
grid.appendChild(cell);
|
grid.appendChild(cell);
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
@ -98,7 +98,7 @@
|
||||||
progressBar.style.display = "block";
|
progressBar.style.display = "block";
|
||||||
grid.innerHTML = '';
|
grid.innerHTML = '';
|
||||||
|
|
||||||
let response = await fetch('/api/scan-for-calibration/{{ calibration.id }}');
|
let response = await fetch('/api/scan-for-calibration');
|
||||||
let reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
let reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
@ -108,6 +108,11 @@
|
||||||
buttons.forEach(x => x.removeAttribute('disabled'));
|
buttons.forEach(x => x.removeAttribute('disabled'));
|
||||||
scanButton.classList.remove('is-loading');
|
scanButton.classList.remove('is-loading');
|
||||||
calibrateDiv.style.display = "block";
|
calibrateDiv.style.display = "block";
|
||||||
|
|
||||||
|
for (let elt of document.getElementsByClassName('calibration-tag')) {
|
||||||
|
elt.style.display = "none";
|
||||||
|
}
|
||||||
|
document.getElementById('calibration-tag-1').style.display = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,19 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<div class="container">
|
||||||
|
<div class="field is-grouped is-grouped-right">
|
||||||
|
<div class="control">
|
||||||
|
<a href="/calibrate" class="button">Retourner à la page d'acquisition</a>
|
||||||
|
</div>
|
||||||
|
<div class="control">
|
||||||
|
<a href="/validate-calibration" class="button is-link">Valider l'étalonnage</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
||||||
{% block extracss %}
|
{% block extracss %}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
<section class="section">
|
<section class="section">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1 class="title">{{ object.name }}</h1>
|
<h1 class="title">{{ object.name }}</h1>
|
||||||
{% if calibration %}
|
{% if calibration.state == CalibrationState.IsValidated %}
|
||||||
<a href="/scan/{{ object.id }}" class="button is-link">Faire un scan</a>
|
<a href="/scan/{{ object.id }}" class="button is-link">Faire un scan</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<button class="button is-link" id="scan">Faire un scan</button>
|
<button class="button is-link" id="scan">Faire un scan</button>
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
</section>
|
</section>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
||||||
{% block extrajs %}{% if not calibration %}
|
{% block extrajs %}{% if calibration.state < CalibrationState.IsValidated %}
|
||||||
<script>
|
<script>
|
||||||
let modal = document.getElementById('calibration-modal');
|
let modal = document.getElementById('calibration-modal');
|
||||||
document.getElementById('scan').addEventListener('click', () => {
|
document.getElementById('scan').addEventListener('click', () => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue