Cleaning
This commit is contained in:
parent
be9d8128d6
commit
eddd0853b5
99
__init__.py
99
__init__.py
|
|
@ -1,7 +1,6 @@
|
|||
from flask import Flask, redirect, render_template, send_from_directory, session
|
||||
from flask import Flask, send_from_directory, session
|
||||
import os
|
||||
from os.path import join
|
||||
from . import db, config, scanner, routes, utils
|
||||
from . import db, config, routes, utils
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
|
@ -46,100 +45,6 @@ def manage_auto_use_last_calibration():
|
|||
app.register_blueprint(routes.blueprint)
|
||||
|
||||
|
||||
@app.route('/scan/<id>')
|
||||
def scan(id: int):
|
||||
conn = db.get()
|
||||
calibration_id = session.get('calibration_id', None)
|
||||
object = db.Object.get_from_id(id, conn)
|
||||
|
||||
if calibration_id is None:
|
||||
raise RuntimeError("Impossible de faire l'acquisition sans étalonnage")
|
||||
|
||||
return render_template('scan.html', object=object, calibrated=True)
|
||||
|
||||
|
||||
@app.route('/scan-acquisition/<id>')
|
||||
def scan_existing(id: int):
|
||||
conn = db.get()
|
||||
calibrated = session.get('calibration_id', None) is not None
|
||||
acquisition = db.Acquisition.get_from_id(id, conn)
|
||||
object = acquisition.object(conn)
|
||||
return render_template('scan.html', object=object, acquisition=acquisition, calibrated=calibrated)
|
||||
|
||||
|
||||
@app.route("/api/scan-for-object/<object_id>")
|
||||
def scan_object(object_id: int):
|
||||
conn = db.get()
|
||||
calibration_id = session.get('calibration_id', None)
|
||||
|
||||
if calibration_id is None:
|
||||
raise RuntimeError("Impossible de faire l'acquisition sans étalonnage")
|
||||
|
||||
object = db.Object.get_from_id(object_id, conn)
|
||||
|
||||
if object is None:
|
||||
raise RuntimeError(f"Aucun objet d'id {object_id}")
|
||||
|
||||
with conn:
|
||||
acquisition = object.add_acquisition(calibration_id, conn)
|
||||
|
||||
def generate():
|
||||
yield str(acquisition.id)
|
||||
length = len(config.LEDS_UUIDS)
|
||||
for index, led_uuid in enumerate(scanner.scan(join(config.OBJECT_DIR, str(object.id), str(acquisition.id)))):
|
||||
yield f"{led_uuid},{(index+1)/length}\n"
|
||||
|
||||
return app.response_class(generate(), mimetype='text/plain')
|
||||
|
||||
|
||||
@app.route("/api/scan-for-acquisition/<acquisition_id>")
|
||||
def scan_acquisition(acquisition_id: int):
|
||||
conn = db.get()
|
||||
calibration_id = session.get('calibration_id', None)
|
||||
|
||||
if calibration_id is None:
|
||||
raise RuntimeError("Impossible de faire l'acquisition sans étalonnage")
|
||||
|
||||
acquisition = db.Acquisition.get_from_id(acquisition_id, conn)
|
||||
|
||||
if acquisition is None:
|
||||
raise RuntimeError(f"Aucun acquisition d'id {acquisition_id}")
|
||||
|
||||
object = acquisition.object(conn)
|
||||
|
||||
def generate():
|
||||
length = len(config.LEDS_UUIDS)
|
||||
for index, led_uuid in enumerate(scanner.scan(join(config.OBJECT_DIR, str(object.id), str(acquisition.id)))):
|
||||
yield f"{led_uuid},{(index+1)/length}\n"
|
||||
|
||||
return app.response_class(generate(), mimetype='text/plain')
|
||||
|
||||
|
||||
@app.route("/validate-acquisition/<acquisition_id>")
|
||||
def validate_acquisition(acquisition_id: int):
|
||||
conn = db.get()
|
||||
acquisition = db.Acquisition.get_from_id(acquisition_id, conn)
|
||||
|
||||
if acquisition is None:
|
||||
raise f"Aucune acquisition d'id {acquisition_id}"
|
||||
|
||||
object = acquisition.object(conn)
|
||||
|
||||
acquisition.validated = True
|
||||
with conn:
|
||||
acquisition.save(conn)
|
||||
|
||||
return redirect(f'/object/{object.id}')
|
||||
|
||||
|
||||
@app.route("/delete-acquisition/<acquisition_id>")
|
||||
def delete_acquisition(acquisition_id: int):
|
||||
conn = db.get()
|
||||
with conn:
|
||||
acqusition = db.Acquisition.delete_from_id(acquisition_id, conn)
|
||||
return redirect('/object/' + str(acqusition.object_id))
|
||||
|
||||
|
||||
@app.route('/static/<path:path>')
|
||||
def send_static(path):
|
||||
return send_from_directory('static', path)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from flask import Blueprint, render_template
|
||||
|
||||
from .. import db
|
||||
from . import object, calibration
|
||||
from . import object, calibration, acquisition
|
||||
|
||||
blueprint = Blueprint('routes', __name__)
|
||||
|
||||
|
|
@ -19,3 +19,4 @@ def index():
|
|||
|
||||
blueprint.register_blueprint(object.blueprint, url_prefix='/object')
|
||||
blueprint.register_blueprint(calibration.blueprint, url_prefix='/calibration')
|
||||
blueprint.register_blueprint(acquisition.blueprint, url_prefix='/acquisition')
|
||||
|
|
|
|||
|
|
@ -0,0 +1,106 @@
|
|||
from flask import Blueprint, Response, render_template, session, redirect
|
||||
from os.path import join
|
||||
|
||||
from .. import db, config, scanner
|
||||
|
||||
blueprint = Blueprint('acquisition', __name__)
|
||||
|
||||
|
||||
@blueprint.route('/scan/<id>')
|
||||
def scan(id: int):
|
||||
"""
|
||||
Route to scan an object
|
||||
"""
|
||||
conn = db.get()
|
||||
calibration_id = session.get('calibration_id', None)
|
||||
object = db.Object.get_from_id(id, conn)
|
||||
|
||||
if calibration_id is None:
|
||||
raise RuntimeError("Impossible de faire l'acquisition sans étalonnage")
|
||||
|
||||
return render_template('scan.html', object=object, calibrated=True)
|
||||
|
||||
|
||||
@blueprint.route('/rescan/<id>')
|
||||
def scan_existing(id: int):
|
||||
conn = db.get()
|
||||
calibrated = session.get('calibration_id', None) is not None
|
||||
acquisition = db.Acquisition.get_from_id(id, conn)
|
||||
object = acquisition.object(conn)
|
||||
return render_template('scan.html', object=object, acquisition=acquisition, calibrated=calibrated)
|
||||
|
||||
|
||||
@blueprint.route('/run/<object_id>')
|
||||
def run(object_id: int):
|
||||
conn = db.get()
|
||||
calibration_id = session.get('calibration_id', None)
|
||||
|
||||
if calibration_id is None:
|
||||
raise RuntimeError("Impossible de faire l'acquisition sans étalonnage")
|
||||
|
||||
object = db.Object.get_from_id(object_id, conn)
|
||||
|
||||
if object is None:
|
||||
raise RuntimeError(f"Aucun objet d'id {object_id}")
|
||||
|
||||
with conn:
|
||||
acquisition = object.add_acquisition(calibration_id, conn)
|
||||
|
||||
def generate():
|
||||
yield str(acquisition.id)
|
||||
length = len(config.LEDS_UUIDS)
|
||||
for index, led_uuid in enumerate(scanner.scan(join(config.OBJECT_DIR, str(object.id), str(acquisition.id)))):
|
||||
yield f"{led_uuid},{(index+1)/length}\n"
|
||||
|
||||
return Response(generate(), mimetype='text/plain')
|
||||
|
||||
|
||||
@blueprint.route('/rerun/<acquisition_id>')
|
||||
def rescan(acquisition_id: int):
|
||||
"""
|
||||
Route to relaunch an acquisition
|
||||
"""
|
||||
conn = db.get()
|
||||
calibration_id = session.get('calibration_id', None)
|
||||
|
||||
if calibration_id is None:
|
||||
raise RuntimeError("Impossible de faire l'acquisition sans étalonnage")
|
||||
|
||||
acquisition = db.Acquisition.get_from_id(acquisition_id, conn)
|
||||
|
||||
if acquisition is None:
|
||||
raise RuntimeError(f"Aucun acquisition d'id {acquisition_id}")
|
||||
|
||||
object = acquisition.object(conn)
|
||||
|
||||
def generate():
|
||||
length = len(config.LEDS_UUIDS)
|
||||
for index, led_uuid in enumerate(scanner.scan(join(config.OBJECT_DIR, str(object.id), str(acquisition.id)))):
|
||||
yield f"{led_uuid},{(index+1)/length}\n"
|
||||
|
||||
return Response(generate(), mimetype='text/plain')
|
||||
|
||||
|
||||
@blueprint.route('/validate/<acquisition_id>')
|
||||
def validate(acquisition_id: int):
|
||||
conn = db.get()
|
||||
acquisition = db.Acquisition.get_from_id(acquisition_id, conn)
|
||||
|
||||
if acquisition is None:
|
||||
raise f"Aucune acquisition d'id {acquisition_id}"
|
||||
|
||||
object = acquisition.object(conn)
|
||||
|
||||
acquisition.validated = True
|
||||
with conn:
|
||||
acquisition.save(conn)
|
||||
|
||||
return redirect(f'/object/{object.id}')
|
||||
|
||||
|
||||
@blueprint.route("/delete/<acquisition_id>")
|
||||
def delete(acquisition_id: int):
|
||||
conn = db.get()
|
||||
with conn:
|
||||
acqusition = db.Acquisition.delete_from_id(acquisition_id, conn)
|
||||
return redirect('/object/' + str(acqusition.object_id))
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
<div class="fixed-grid has-6-cols">
|
||||
<div class="grid">
|
||||
{% for acquisition in object.acquisitions %}
|
||||
<a class="cell" href="/scan-acquisition/{{ acquisition.id }}">
|
||||
<a class="cell" href="/acquisition/rescan/{{ acquisition.id }}">
|
||||
<div class="has-text-centered p-3" style="border-radius: 15px; border-width: 1px; border-color: {% if acquisition.validated %}green{% else %}red{% endif %}; border-style: solid;">
|
||||
<div>
|
||||
<img src="/data/objects/{{ object.id }}/{{ acquisition.id }}/{{ leds[0] }}.jpg">
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
<div class="field is-grouped">
|
||||
{% if calibration.state == CalibrationState.IsValidated %}
|
||||
<div class="control">
|
||||
<a href="/scan/{{ object.id }}" class="button is-link">Faire un scan</a>
|
||||
<a href="/acquisition/scan/{{ object.id }}" class="button is-link">Faire un scan</a>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="control">
|
||||
|
|
|
|||
|
|
@ -32,16 +32,16 @@
|
|||
</div>
|
||||
{% else %}
|
||||
<div class="control">
|
||||
<a href="/validate-acquisition/{{ acquisition.id }}" id="calibrate-button" class="button is-link">Valider l'acquisition</a>
|
||||
<a href="/acquisition/validate/{{ acquisition.id }}" id="calibrate-button" class="button is-link">Valider l'acquisition</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<div class="control">
|
||||
<a id="calibrate-button" class="button is-link">Valider l'acquisition</a>
|
||||
<a id="validate-button" class="button is-link">Valider l'acquisition</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="control">
|
||||
<a id="delete-button" class="button is-danger" {% if acquisition %}href="/delete-acquisition/{{ acquisition.id }}"{% endif %}>Supprimer l'acquisition</a>
|
||||
<a id="delete-button" class="button is-danger" {% if acquisition %}href="/acquisition/delete/{{ acquisition.id }}"{% endif %}>Supprimer l'acquisition</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -60,7 +60,7 @@
|
|||
let errorContainer = document.getElementById('error-container');
|
||||
let errorContent = document.getElementById('error-content');
|
||||
let calibrateDiv = document.getElementById('calibrate');
|
||||
let calibrateButton = document.getElementById('calibrate-button');
|
||||
let validateButton = document.getElementById('validate-button');
|
||||
let deleteButton = document.getElementById('delete-button');
|
||||
|
||||
// If we already have calibration images, we show them right now
|
||||
|
|
@ -88,9 +88,9 @@
|
|||
|
||||
let response;
|
||||
if (acquisitionId === null) {
|
||||
response = await fetch('/api/scan-for-object/{{ object.id }}');
|
||||
response = await fetch('/acquisition/run/{{ object.id }}');
|
||||
} else {
|
||||
response = await fetch('/api/scan-for-acquisition/' + acquisitionId);
|
||||
response = await fetch('/acquisition/rerun/' + acquisitionId);
|
||||
}
|
||||
|
||||
let reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
||||
|
|
@ -107,9 +107,9 @@
|
|||
|
||||
if (acquisitionId === null) {
|
||||
acquisitionId = parseInt(value, 10);
|
||||
calibrateButton.setAttribute('href', '/validate-acquisition/' + acquisitionId);
|
||||
deleteButton.setAttribute('href', '/delete-acquisition/' + acquisitionId);
|
||||
window.history.pushState('', '', '/scan-acquisition/' + acquisitionId);
|
||||
validateButton.setAttribute('href', '/acquisition/validate/' + acquisitionId);
|
||||
deleteButton.setAttribute('href', '/acquisition/delete/' + acquisitionId);
|
||||
window.history.pushState('', '', '/acquisition/rescan/' + acquisitionId);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue