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