Spaces:
Sleeping
Sleeping
| def get_latest_user_message(messages): | |
| """ | |
| Returns the latest user message. | |
| """ | |
| for message in reversed(messages): | |
| if message.role == "user": | |
| return message.content | |
| return "" | |
| def get_conversation_text(messages): | |
| """ | |
| Converts the conversation into plain text. | |
| """ | |
| conversation = [] | |
| for message in messages: | |
| conversation.append( | |
| f"{message.role}: {message.content}" | |
| ) | |
| return "\n".join(conversation) | |
| KEY_TO_CODE = { | |
| "Ability & Aptitude": "A", | |
| "Personality & Behavior": "P", | |
| "Biodata & Situational Judgment": "B", | |
| "Knowledge & Skills": "K", | |
| "Simulations": "S", | |
| "Competencies": "C", | |
| "Development & 360": "D", | |
| "Assessment Exercises": "E" | |
| } | |
| def get_test_type(item): | |
| name = item.get("name", "").lower() | |
| keys = item.get("keys") or [] | |
| # SVAR exception | |
| if "svar" in name: | |
| return "K" | |
| # Development & 360 exception | |
| if "Development & 360" in keys: | |
| return "D" | |
| key_set = set(keys) | |
| if len(key_set) == 1: | |
| single_key = list(key_set)[0] | |
| return KEY_TO_CODE.get(single_key, "K") | |
| # Combinations: | |
| if { "Competencies", "Knowledge & Skills" }.issubset(key_set): | |
| return "C, K" | |
| if { "Personality & Behavior", "Competencies" }.issubset(key_set): | |
| return "P,C" | |
| if { "Biodata & Situational Judgment", "Simulations" }.issubset(key_set): | |
| return "B,S" | |
| if { "Ability & Aptitude", "Simulations" }.issubset(key_set): | |
| return "A,S" | |
| if { "Knowledge & Skills", "Simulations" }.issubset(key_set): | |
| return "K,S" | |
| # Fallback | |
| mapped_codes = [KEY_TO_CODE.get(k) for k in keys if k in KEY_TO_CODE] | |
| if mapped_codes: | |
| return ",".join(mapped_codes) | |
| return "K" | |
| import re | |
| def clean_catalog_name(name: str) -> str: | |
| n = name.lower() | |
| while True: | |
| next_n = re.sub(r'\s*\([^)]*\)\s*$', '', n) | |
| if next_n == n: | |
| break | |
| n = next_n | |
| n = re.sub(r'\s+new\s*$', '', n) | |
| return n.strip() |