""" Shared formatting utilities for consistent output across all tools. """ from typing import List, Dict, Any class ResponseFormatter: """Handles consistent formatting of responses with emojis and structure.""" @staticmethod def format_restaurant_response(location: str, distance: float, restaurants: List[Dict]) -> str: """Format restaurant search results.""" output = f"đŸŊī¸ **Top Restaurants in {location.title()}** đŸŊī¸\n" output += f"📍 *Within {distance} miles*\n\n" output += f"đŸŽ¯ Found {len(restaurants)} amazing restaurants! Here are the top picks:\n\n" for i, restaurant in enumerate(restaurants, 1): output += f"**#{i} {restaurant['name']}** ⭐\n" output += f"🍴 **Cuisine:** {restaurant['cuisine_type']}\n" output += f"📍 **Address:** {restaurant['address']}\n" output += f"đŸšļ **Distance:** {restaurant['distance']}\n" if restaurant['rating'] != 'Not rated': output += f"⭐ **Rating:** {restaurant['rating']}\n" if restaurant['price']: output += f"💰 **Price:** {restaurant['price']}\n" output += f"đŸ‘¨â€đŸŗ **Recommended Dishes:**\n" for dish in restaurant['recommended_dishes']: output += f" â€ĸ {dish}\n" if restaurant['description'] != 'No description available': output += f"â„šī¸ **About:** {restaurant['description'][:150]}...\n" output += "\n" + "─" * 50 + "\n\n" output += "🌟 *Enjoy your dining experience!* 🌟" return output @staticmethod def format_place_response(location: str, places: List[Dict]) -> str: """Format place/hotel search results.""" output = f"🏨 **Places to Stay in {location.title()}** 🏨\n\n" output += f"đŸŽ¯ Found {len(places)} amazing places! Here are the top suggestions:\n\n" for i, place in enumerate(places, 1): output += f"**#{i} {place['name']}** ⭐\n" output += f"🏨 **Type:** {place['type']}\n" output += f"📍 **Address:** {place['address']}\n" output += f"đŸšļ **Distance:** {place['distance']}\n" if place['rating'] != 'Not rated': output += f"⭐ **Rating:** {place['rating']}\n" if place['description'] != 'No description available': output += f"â„šī¸ **About:** {place['description'][:150]}...\n" output += "\n" + "─" * 50 + "\n\n" output += "🌟 *Have a wonderful stay!* 🌟" return output @staticmethod def format_hiking_response(location: str, max_distance: int, difficulty: str, hikes: List[Dict], stats: Dict) -> str: """Format hiking trail search results.""" output = f"đŸ”ī¸ **Hiking Trails near {location.title()}** đŸ”ī¸\n" output += f"📍 *Within {max_distance} miles, Difficulty: {difficulty}*\n\n" # Add statistics output += "📊 **Quick Stats:**\n" output += f"â€ĸ đŸĨž **Total Trails Found:** {stats['total_hikes']}\n" output += f"â€ĸ 📏 **Average Distance:** {stats['avg_distance']} miles\n" output += f"â€ĸ â›°ī¸ **Average Elevation Gain:** {stats['avg_elevation']:,} ft\n" output += f"â€ĸ ⭐ **Average Rating:** {stats['avg_rating']}\n\n" # Add difficulty distribution output += "đŸŽ¯ **Difficulty Distribution:**\n" for diff, count in stats['difficulty_distribution'].items(): output += f"â€ĸ {diff}: {count} trails\n" output += "\n" # Add trail details output += "đŸĨž **Top Recommended Trails:**\n\n" for i, hike in enumerate(hikes[:5], 1): # Limit to top 5 output += f"**#{i} {hike['name']}** đŸ”ī¸\n" output += f"đŸŽ¯ **Difficulty:** {hike['difficulty_level']} (Score: {hike['difficulty_score']:.1f}/100)\n" output += f"📏 **Distance:** {hike['distance']} miles\n" output += f"â›°ī¸ **Elevation Gain:** {hike['elevation_gain']:,} ft\n" output += f"⭐ **Rating:** {hike['rating']} ({hike['reviews']} reviews)\n" output += f"🚗 **Distance from you:** {hike['distance_from_user']} miles\n" output += f"🌟 **Features:** {', '.join(hike['features'])}\n" output += f"📊 **Source:** {hike.get('source', 'Database')}\n" output += "\n" + "─" * 50 + "\n\n" output += "🌲 *Happy hiking and stay safe on the trails!* 🌲" return output @staticmethod def format_sentiment_response(text: str, polarity: float = 0.5, subjectivity: float = 0.5, assessment: str = "neutral") -> str: """Format sentiment analysis results.""" output = f"😊 **Sentiment Analysis Result** 😊\n\n" output += f"📝 **Text Analyzed:** {text}\n\n" output += f"📊 **Analysis:**\n" output += f"â€ĸ 🎭 **Polarity:** {polarity} ({'Positive' if polarity > 0.1 else 'Negative' if polarity < -0.1 else 'Neutral'})\n" output += f"â€ĸ 🤔 **Subjectivity:** {subjectivity} ({'Subjective' if subjectivity > 0.5 else 'Objective'})\n" output += f"â€ĸ 📈 **Overall Assessment:** {assessment.title()} sentiment\n\n" if polarity > 0.3: output += f"💡 *This text expresses positive emotions and favorable opinions.*" elif polarity < -0.3: output += f"💡 *This text expresses negative emotions and unfavorable opinions.*" else: output += f"💡 *This text shows a balanced emotional tone with neutral sentiment.*" return output @staticmethod def format_error(error_message: str) -> str: """Format error messages consistently.""" return f"❌ **Error:** {error_message}" @staticmethod def format_no_results(service_type: str, location: str = "") -> str: """Format no results messages.""" emoji_map = { "restaurants": "đŸŊī¸", "places": "🏨", "hotels": "🏨", "trails": "đŸ”ī¸", "hikes": "đŸ”ī¸" } emoji = emoji_map.get(service_type.lower(), "🔍") location_text = f" in {location}" if location else "" return f"{emoji} **No {service_type} found{location_text}.** Try expanding your search radius or using a different location."