from typing import List, Tuple, Dict, Any def process_reasons(reasons: dict) -> List[Tuple[str, str, str]]: """Proprocessing for recommendation reasons data to display in a dataframe. Parameters ---------- reasons : dict Returns ------- List[Tuple[str, str, str]] (attribute type, attribute code, attribute description) """ output = [] for code, desc in (reasons.get("subject_codes", {}) or {}).items(): output.append(["PCS subject", code, desc]) for code, desc in (reasons.get("pop_group_codes", {}) or {}).items(): output.append(["PCS population", code, desc]) for code, desc in (reasons.get("geo_ids", {}) or {}).items(): output.append(["Geography served", code, desc]) return output def parse_pcs_descriptions(taxonomy: List[Dict[str, Any]]) -> str: reasons = [] for term in taxonomy: facet = (term.get("facet") or "").lower() if facet == "subject": reasons.append(f"- For {term.get('description')}") elif facet == "population": reasons.append(f"- Serving {term.get('description')}") return '\n'.join(reasons) def parse_geo_descriptions(geos: List[Dict[str, Any]]) -> str: reasons = [] for geo in geos: reasons.append(f"- Serving {geo['name']}") return '\n'.join(reasons)