From 54ad48a5ba3bf8bf53683eac4bd9b48360e686df Mon Sep 17 00:00:00 2001 From: lucas Date: Mon, 22 Apr 2024 16:57:21 -0700 Subject: [PATCH] Remove NaN from dict --- python/status_server/server.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/python/status_server/server.py b/python/status_server/server.py index 71fbfbe0..82d08c83 100644 --- a/python/status_server/server.py +++ b/python/status_server/server.py @@ -43,12 +43,20 @@ def stopped(self): latest_pose_message = {} +def replace_nan_in_dict(d): + for k, v in d.items(): + if isinstance(v, dict): + replace_nan_in_dict(v) + elif isinstance(v, str) and v == "NaN": + d[k] = "0.0" + @app.route('/', methods=['GET', 'POST']) def index(): global latest_pose_message mutex.acquire() latest_json_data = latest_pose_message mutex.release() + replace_nan_in_dict(latest_json_data) return jsonify(latest_json_data), 200 def start_fe_server(options):