Various comment updates and small sourcery suggestions
This commit is contained in:
parent
d4d39c861a
commit
7ef2cd7eab
|
@ -11,10 +11,6 @@ from loguru import logger
|
|||
import subprocess # nosec
|
||||
|
||||
# Library to send command over I2C for the light module on the fan
|
||||
try:
|
||||
import smbus2 as smbus
|
||||
except ModuleNotFoundError: # We need this to install the library on machine that do not have the module yet
|
||||
subprocess.run("pip3 install smbus2".split()) # nosec
|
||||
import smbus2 as smbus
|
||||
|
||||
import enum
|
||||
|
|
|
@ -52,7 +52,7 @@ class ModuleProcess(multiprocessing.Process):
|
|||
action = last_message["action"]
|
||||
if action == "on":
|
||||
# Treat the received messages here
|
||||
|
||||
pass
|
||||
elif action != "":
|
||||
logger.warning(
|
||||
f"We did not understand the received request {action} - {last_message}"
|
||||
|
@ -93,3 +93,4 @@ class ModuleProcess(multiprocessing.Process):
|
|||
# This is called if this script is launched directly
|
||||
if __name__ == "__main__":
|
||||
# This should be tests of your module
|
||||
pass
|
|
@ -86,7 +86,7 @@ class MQTT_Client:
|
|||
@logger.catch
|
||||
def connect(self):
|
||||
logger.info(f"trying to connect to {self.server}:{self.port}")
|
||||
# TODO add try: except ConnectionRefusedError: block here
|
||||
# TODO #104 add try: except ConnectionRefusedError: block here
|
||||
# This is a symptom that Mosquitto may have failed to start
|
||||
self.client.connect(self.server, self.port, 60)
|
||||
self.client.on_connect = self.on_connect
|
||||
|
|
|
@ -274,7 +274,7 @@ class SegmenterProcess(multiprocessing.Process):
|
|||
h_stddev = np.std(h_channel, where=mask)
|
||||
s_stddev = np.std(s_channel, where=mask)
|
||||
v_stddev = np.std(v_channel, where=mask)
|
||||
# TODO Add skewness and kurtosis calculation (with scipy) here
|
||||
# TODO #103 Add skewness and kurtosis calculation (with scipy) here
|
||||
# using https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.skew.html#scipy.stats.skew
|
||||
# and https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.kurtosis.html#scipy.stats.kurtosis
|
||||
# h_quartiles = np.quantile(h_channel, quartiles)
|
||||
|
@ -789,7 +789,7 @@ class SegmenterProcess(multiprocessing.Process):
|
|||
else:
|
||||
self.segmenter_client.client.publish(
|
||||
"status/segmenter",
|
||||
f'{{"status":"An exception was raised during the segmentation: {e}."}}',
|
||||
f'{{"status":"An exception was raised during the segmentation: {exception}."}}',
|
||||
)
|
||||
# Reset process_id
|
||||
self.__process_id = ""
|
||||
|
@ -856,6 +856,7 @@ class SegmenterProcess(multiprocessing.Process):
|
|||
self.__ecotaxa_path,
|
||||
# filename includes project name, timestamp and sample id
|
||||
f"ecotaxa_{project}_{date}_{sample}.zip",
|
||||
# TODO #102 sanitize the filename to remove potential problems with spaces and special characters
|
||||
)
|
||||
|
||||
self.__working_path = path
|
||||
|
@ -978,7 +979,7 @@ class SegmenterProcess(multiprocessing.Process):
|
|||
|
||||
elif last_message["action"] != "":
|
||||
logger.warning(
|
||||
f"We did not understand the received request {action} - {last_message}"
|
||||
f"We did not understand the received request {last_message}"
|
||||
)
|
||||
|
||||
################################################################################
|
||||
|
|
|
@ -205,7 +205,7 @@ def ecotaxa_export(archive_filepath, metadata, image_base_path, keep_files=False
|
|||
logger.error("No objects metadata recorded, cannot continue the export")
|
||||
return 0
|
||||
|
||||
# fix crappy old camera resolution that was not exported as string
|
||||
# sometimes the camera resolution is not exported as string
|
||||
if type(metadata["acq_camera_resolution"]) != str:
|
||||
metadata[
|
||||
"acq_camera_resolution"
|
||||
|
@ -216,7 +216,7 @@ def ecotaxa_export(archive_filepath, metadata, image_base_path, keep_files=False
|
|||
tsv_line = {}
|
||||
tsv_line.update(metadata)
|
||||
tsv_line.update(("object_" + k, v) for k, v in roi["metadata"].items())
|
||||
tsv_line.update({"object_id": roi["name"]})
|
||||
tsv_line["object_id"] = roi["name"]
|
||||
|
||||
filename = roi["name"] + ".jpg"
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ class StreamingHandler(http.server.BaseHTTPRequestHandler):
|
|||
)
|
||||
break
|
||||
frame = file.getvalue()
|
||||
# TODO #101 insert try block here to catch ConnectionResetError: [Errno 104] Connection reset by peer
|
||||
self.wfile.write(b"--FRAME\r\n")
|
||||
self.send_header("Content-Type", "image/jpeg")
|
||||
self.send_header("Content-Length", len(frame))
|
||||
|
|
|
@ -185,6 +185,7 @@ class StepperProcess(multiprocessing.Process):
|
|||
if os.path.exists("/home/pi/PlanktoScope/hardware.json"):
|
||||
# load hardware.json
|
||||
with open("/home/pi/PlanktoScope/hardware.json", "r") as config_file:
|
||||
# TODO #100 insert guard for config_file empty
|
||||
configuration = json.load(config_file)
|
||||
logger.debug(f"Hardware configuration loaded is {configuration}")
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue