Better handling of payloads

This commit is contained in:
2024-10-20 16:26:50 +11:00
parent 05c9b1f713
commit fe25895b38
+23 -13
View File
@@ -56,23 +56,33 @@ def on_message(client, userdata, msg):
process_snapshot(msg.payload)
def process_latest_snapshot():
# Placeholder for processing the latest snapshot (if available)
print("Attempting to process the latest snapshot...")
# Assuming we have a way to get the latest snapshot payload
# For now, this is just a debug statement
# Simulate fetching the latest snapshot payload (replace with actual logic if available)
latest_snapshot_payload = os.getenv('LATEST_SNAPSHOT_PAYLOAD', None)
if latest_snapshot_payload:
process_snapshot(latest_snapshot_payload.encode('utf-8'))
else:
print("No latest snapshot available to process.")
def process_snapshot(payload):
print("Processing snapshot...")
image_data = base64.b64decode(payload)
nparr = np.frombuffer(image_data, np.uint8)
image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
if not payload:
print("Empty payload received, skipping processing.")
return
if image is not None:
rating = calculate_dayglo_rating(image)
print("Dayglo Rating calculated:", rating)
publish_rating(rating)
else:
print("Invalid image received")
print("Processing snapshot...")
try:
image_data = base64.b64decode(payload)
nparr = np.frombuffer(image_data, np.uint8)
image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
if image is not None:
rating = calculate_dayglo_rating(image)
print("Dayglo Rating calculated:", rating)
publish_rating(rating)
else:
print("Invalid image received")
except Exception as e:
print(f"Error processing snapshot: {e}")
def calculate_dayglo_rating(image):
print("Calculating dayglo rating...")