MarketSync / modules /profile_utils.py
hyeonjoo's picture
Initial project commit with LFS
9b1e3db
# modules/profile_utils.py
from typing import Dict, Any
import config
logger = config.get_logger(__name__)
def get_chat_profile_dict(store_profile_dict: Dict[str, Any]) -> Dict[str, Any]:
"""
FastAPI (server.py)์—์„œ ๋ฐ›์€ 'store_profile' ๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ,
visualization.py์™€ orchestrator.py์—์„œ ๊ณตํ†ต์œผ๋กœ ์‚ฌ์šฉํ• 
'์ฑ„ํŒ…์šฉ ํ”„๋กœํ•„ ๋”•์…”๋„ˆ๋ฆฌ' (์‚ฌ์žฅ๋‹˜์ด ์š”์ฒญํ•˜์‹  ํ•ญ๋ชฉ)๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
์ด ํ•จ์ˆ˜๊ฐ€ '์ฑ„ํŒ…์šฉ ํ”„๋กœํ•„'์˜ ๋‹จ์ผ ์ •์˜(Source of Truth) ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค.
"""
try:
# 1. ๊ธฐ๋ณธ ์ •๋ณด
chat_profile_data = {
"๊ฐ€๋งน์ ๋ช…": store_profile_dict.get('๊ฐ€๋งน์ ๋ช…', 'N/A'),
"๊ฐ€๋งน์ ID": store_profile_dict.get('๊ฐ€๋งน์ ID', 'N/A'),
"์ƒ๊ถŒ": store_profile_dict.get('์ƒ๊ถŒ', 'N/A'),
"์—…์ข…": store_profile_dict.get('์—…์ข…', 'N/A'),
"์ฃผ์†Œ": store_profile_dict.get('๊ฐ€๋งน์ ์ฃผ์†Œ', 'N/A'),
"์šด์˜ ๊ธฐ๊ฐ„ ์ˆ˜์ค€": store_profile_dict.get('์šด์˜๊ฐœ์›”์ˆ˜_์ˆ˜์ค€', 'N/A'),
"๋งค์ถœ ์ˆ˜์ค€": store_profile_dict.get('๋งค์ถœ๊ตฌ๊ฐ„_์ˆ˜์ค€', 'N/A'),
"๋งค์ถœ ๊ฑด์ˆ˜ ์ˆ˜์ค€": store_profile_dict.get('์›”๋งค์ถœ๊ฑด์ˆ˜_์ˆ˜์ค€', 'N/A'),
"๋ฐฉ๋ฌธ ๊ณ ๊ฐ์ˆ˜ ์ˆ˜์ค€": store_profile_dict.get('์›”์œ ๋‹ˆํฌ๊ณ ๊ฐ์ˆ˜_์ˆ˜์ค€', 'N/A'),
"๊ฐ๋‹จ๊ฐ€ ์ˆ˜์ค€": store_profile_dict.get('์›”๊ฐ๋‹จ๊ฐ€_์ˆ˜์ค€', 'N/A'),
"์‹ ๊ทœ/์žฌ๋ฐฉ๋ฌธ์œจ": f"์‹ ๊ทœ {(store_profile_dict.get('์‹ ๊ทœ๊ณ ๊ฐ๋น„์œจ') or 0):.1f}% / ์žฌ๋ฐฉ๋ฌธ {(store_profile_dict.get('์žฌ์ด์šฉ๊ณ ๊ฐ๋น„์œจ') or 0):.1f}%",
"๋™์ผ ์ƒ๊ถŒ ๋Œ€๋น„ ๋งค์ถœ ์ˆœ์œ„": f"์ƒ์œ„ {(store_profile_dict.get('๋™์ผ์ƒ๊ถŒ๋‚ด๋งค์ถœ์ˆœ์œ„๋น„์œจ') or 0):.1f}%",
"๋™์ผ ์—…์ข… ๋Œ€๋น„ ๋งค์ถœ ์ˆœ์œ„": f"์ƒ์œ„ {(store_profile_dict.get('๋™์ผ์—…์ข…๋‚ด๋งค์ถœ์ˆœ์œ„๋น„์œจ') or 0):.1f}%"
}
# 2. '์ž๋™์ถ”์ถœํŠน์ง•' ์ถ”๊ฐ€
chat_profile_data["์ž๋™์ถ”์ถœํŠน์ง•"] = store_profile_dict.get('์ž๋™์ถ”์ถœํŠน์ง•', {})
return chat_profile_data
except Exception as e:
logger.critical(f"--- [Profile Utils CRITICAL] ์ฑ„ํŒ… ํ”„๋กœํ•„ ๋”•์…”๋„ˆ๋ฆฌ ์ƒ์„ฑ ์‹คํŒจ: {e} ---", exc_info=True)
return {
"์—…์ข…": store_profile_dict.get('์—…์ข…', '์•Œ ์ˆ˜ ์—†์Œ'),
"์ž๋™์ถ”์ถœํŠน์ง•": store_profile_dict.get('์ž๋™์ถ”์ถœํŠน์ง•', {}),
"์ฃผ์†Œ": store_profile_dict.get('๊ฐ€๋งน์ ์ฃผ์†Œ', '์•Œ ์ˆ˜ ์—†์Œ'),
"error": "ํ”„๋กœํ•„ ์š”์•ฝ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ"
}