From b2e0d5da9ae11dd769e3c46d08be3c957bca6ec8 Mon Sep 17 00:00:00 2001 From: iantei Date: Tue, 24 Sep 2024 21:03:23 -0700 Subject: [PATCH 1/2] Add other to the list of mode/purpose_replace_values if not present in the label-options. --- viz_scripts/scaffolding.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/viz_scripts/scaffolding.py b/viz_scripts/scaffolding.py index 880c8190..f1cf68b5 100644 --- a/viz_scripts/scaffolding.py +++ b/viz_scripts/scaffolding.py @@ -296,6 +296,11 @@ async def mapping_color_labels(dynamic_labels = {}, unique_keys = []): purpose_values = [mode["value"] for mode in labels["PURPOSE"]] if "PURPOSE" in labels else [] replaced_values = [mode["value"] for mode in labels["REPLACED_MODE"]] if "REPLACED_MODE" in labels else [] + # Append 'other' to the list if not present + for values in [mode_values, purpose_values, replaced_values]: + if "other" not in values: + values.append("other") + # Mapping between mode values and base_mode OR baseMode (backwards compatibility) value_to_basemode = {mode["value"]: mode.get("base_mode", mode.get("baseMode", "UNKNOWN")) for mode in labels["MODE"]} # Assign colors to mode, replaced, purpose, and sensed values From 696fe870357fe9189bce16a8309a635d64d25a55 Mon Sep 17 00:00:00 2001 From: iantei Date: Thu, 26 Sep 2024 11:21:24 -0700 Subject: [PATCH 2/2] Add other: Other to the values_to_translations_* dictionary if other key is unavailable --- viz_scripts/scaffolding.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/viz_scripts/scaffolding.py b/viz_scripts/scaffolding.py index f1cf68b5..2a0ee70a 100644 --- a/viz_scripts/scaffolding.py +++ b/viz_scripts/scaffolding.py @@ -337,6 +337,10 @@ async def translate_values_to_labels(dynamic_labels, language="en"): # Mapping between values and translations for display on plots (for Replaced mode) values_to_translations_replaced = mapping_labels(labels, "REPLACED_MODE") + # Add "other": "Other" to the values_to_translations_* dictionary if "other" key is unavailable + for dict_update in [values_to_translations_mode, values_to_translations_purpose, values_to_translations_replaced]: + dict_update.setdefault("other", "Other") + return values_to_translations_mode, values_to_translations_purpose, values_to_translations_replaced # Function: Maps survey answers to colors.