Various comment updates and small sourcery suggestions

This commit is contained in:
Romain Bazile 2021-12-01 13:33:40 +01:00
parent d4d39c861a
commit 7ef2cd7eab
7 changed files with 13 additions and 13 deletions

View file

@ -11,11 +11,7 @@ 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 smbus2 as smbus
import enum

View file

@ -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}"
@ -92,4 +92,5 @@ class ModuleProcess(multiprocessing.Process):
# This is called if this script is launched directly
if __name__ == "__main__":
# This should be tests of your module
# This should be tests of your module
pass

View file

@ -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

View file

@ -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}"
)
################################################################################

View file

@ -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"

View file

@ -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))

View file

@ -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: