You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note the "..." part, as we have limited space, strings are cut to fit 255 characters.
We have some code in another project using dictdiffer, which we can use for all two existing structures (sensors_to_show, flex_context) and of course later also flex_model:
from dictdiffer import diff
def pretty_diff(result) -> list[str]:
string = []
for change_type, key, value in result:
if isinstance(key, list):
_key = key[0]
for k in key[1:]:
_key += f"[{k}]" if isinstance(k, int) else f".{k}"
key = _key
if change_type == "change":
string.append(f"change {key}: {value[0]} -> {value[1]}")
elif change_type == "add":
for v in value:
key += f"[{v[0]}]" if isinstance(v[0], int) else f".{v[0]}"
string.append(f"add {key}: {v[1]}")
elif change_type == "remove":
for v in value:
if key:
key += f"[{v[0]}]" if isinstance(v[0], int) else f".{v[0]}"
string.append(f"remove {key}: {v[1]}")
else:
string.append(f"remove {v[0]}: {v[1]}")
else:
string.append(f"{change_type} {key}: {value}")
return string
def enumerated_dict_diff(d1: dict, d2: dict) -> str:
result = diff(d1, d2)
string = ""
for index, item in enumerate(pretty_diff(result), start=1):
string += f"{index}. {item}\n"
return string
This hopefully will look informative, at least if there are not too many changes at once.
The text was updated successfully, but these errors were encountered:
Flix6x
changed the title
Better representation of hanges in JSON structures in audit logs
Better representation of changes in JSON structures in audit logs
Feb 10, 2025
Right now, the string representation of changes can become pretty long (showing both whole before and after dicts), for example.
Note the "..." part, as we have limited space, strings are cut to fit 255 characters.
We have some code in another project using dictdiffer, which we can use for all two existing structures (sensors_to_show, flex_context) and of course later also flex_model:
This hopefully will look informative, at least if there are not too many changes at once.
The text was updated successfully, but these errors were encountered: