Better progress bar
This commit is contained in:
parent
9eb3c6af0b
commit
bfe4a07be8
|
|
@ -48,9 +48,8 @@ def run(object_id: int):
|
|||
|
||||
def generate():
|
||||
yield str(acquisition.id)
|
||||
length = len(config.LEDS_UUIDS) + 2 # with all_on and all_off
|
||||
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"
|
||||
for value in scanner.scan(join(config.OBJECT_DIR, str(object.id), str(acquisition.id))):
|
||||
yield value
|
||||
|
||||
return Response(generate(), mimetype='text/plain')
|
||||
|
||||
|
|
@ -74,9 +73,8 @@ def rescan(acquisition_id: int):
|
|||
object = acquisition.object(conn)
|
||||
|
||||
def generate():
|
||||
length = len(config.LEDS_UUIDS) + 2 # with all_on and all_off
|
||||
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"
|
||||
for value in scanner.scan(join(config.OBJECT_DIR, str(object.id), str(acquisition.id))):
|
||||
yield value
|
||||
|
||||
return Response(generate(), mimetype='text/plain')
|
||||
|
||||
|
|
|
|||
|
|
@ -56,9 +56,8 @@ def scan():
|
|||
calibration = utils.get_calibration(conn)
|
||||
|
||||
def generate():
|
||||
length = len(config.LEDS_UUIDS)
|
||||
for index, led_uuid in enumerate(scanner.scan(join(config.CALIBRATION_DIR, calibration_id), False)):
|
||||
yield f"{led_uuid},{(index+1)/length}\n"
|
||||
for value in scanner.scan(join(config.CALIBRATION_DIR, calibration_id), False):
|
||||
yield value
|
||||
|
||||
with conn:
|
||||
calibration.state = db.CalibrationState.HasData
|
||||
|
|
|
|||
14
scanner.py
14
scanner.py
|
|
@ -35,6 +35,8 @@ def scan(output_dir: str, on_and_off: bool = True):
|
|||
os.makedirs(output_dir, exist_ok=True)
|
||||
|
||||
file_paths = []
|
||||
length = len(config.LEDS_UUIDS) + (2 if on_and_off else 0)
|
||||
|
||||
with camera.get() as cam:
|
||||
with leds.get() as gpio_leds:
|
||||
for count, led in enumerate(gpio_leds.leds):
|
||||
|
|
@ -46,15 +48,23 @@ def scan(output_dir: str, on_and_off: bool = True):
|
|||
|
||||
print(f'Turn off {led}')
|
||||
|
||||
ratio = (count + 1) / (2 * length)
|
||||
yield f'{{ "status": "captured", "id": "{led}", "ratio": {ratio:.3} }}\n'
|
||||
|
||||
# capture with all leds ON OFF
|
||||
if on_and_off:
|
||||
gpio_leds.on()
|
||||
file_paths.append(('all_on', delay_capture(cam)))
|
||||
ratio = (length - 1) / (2 * length)
|
||||
yield f'{{ "status": "captured", "id": "all_on", "ratio": {ratio:.3} }}\n'
|
||||
|
||||
gpio_leds.off()
|
||||
file_paths.append(('all_off', delay_capture(cam)))
|
||||
ratio = 0.5
|
||||
yield f'{{ "status": "captured", "id": "all_off", "ratio": {ratio:.3} }}\n'
|
||||
|
||||
with camera.get() as cam:
|
||||
for target, source in file_paths:
|
||||
for count, (target, source) in enumerate(file_paths):
|
||||
delay_save(cam, source, join(output_dir, target))
|
||||
yield target
|
||||
ratio = 0.5 + (count + 1) / (2 * length)
|
||||
yield f'{{ "status": "ready", "id": "{target}", "ratio": {ratio:.3} }}\n'
|
||||
|
|
|
|||
|
|
@ -86,15 +86,20 @@
|
|||
break;
|
||||
}
|
||||
|
||||
let [ uuid, ratio ] = value.trim().split(',');
|
||||
console.log(value);
|
||||
let { status, id, ratio } = JSON.parse(value);
|
||||
console.log(status, id, ratio);
|
||||
progress = Math.ceil(1000 * parseFloat(ratio));
|
||||
let cell = document.createElement('div');
|
||||
cell.classList.add('cell');
|
||||
let img = document.createElement('img');
|
||||
img.classList.add('is-loading');
|
||||
img.src = '/data/calibrations/{{ calibration.id }}/' + uuid + '.jpg?v=' + scanIndex;
|
||||
cell.appendChild(img);
|
||||
grid.appendChild(cell);
|
||||
|
||||
if (status === "ready") {
|
||||
let cell = document.createElement('div');
|
||||
cell.classList.add('cell');
|
||||
let img = document.createElement('img');
|
||||
img.classList.add('is-loading');
|
||||
img.src = '/data/calibrations/{{ calibration.id }}/' + id + '.jpg?v=' + scanIndex;
|
||||
cell.appendChild(img);
|
||||
grid.appendChild(cell);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -156,15 +156,18 @@
|
|||
continue;
|
||||
}
|
||||
|
||||
let [ uuid, ratio ] = value.trim().split(',');
|
||||
let { status, id, ratio } = JSON.parse(value);
|
||||
progress = Math.ceil(1000 * parseFloat(ratio));
|
||||
let cell = document.createElement('div');
|
||||
cell.classList.add('cell');
|
||||
let img = document.createElement('img');
|
||||
img.classList.add('is-loading');
|
||||
img.src = '/data/objects/{{ object.id }}/' + acquisitionId + '/' + uuid + '.jpg?v=' + scanIndex;
|
||||
cell.appendChild(img);
|
||||
grid.appendChild(cell);
|
||||
|
||||
if (status === "ready") {
|
||||
let cell = document.createElement('div');
|
||||
cell.classList.add('cell');
|
||||
let img = document.createElement('img');
|
||||
img.classList.add('is-loading');
|
||||
img.src = '/data/objects/{{ object.id }}/' + acquisitionId + '/' + id + '.jpg?v=' + scanIndex;
|
||||
cell.appendChild(img);
|
||||
grid.appendChild(cell);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue