38980-vm/app-9w9pd00g5j41/QUICK_REFERENCE.md
2026-03-04 18:25:09 +00:00

231 lines
5.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Analyze-Trip Enhancement - Quick Reference Card
## ๐ŸŽฏ What Changed?
The analyze-trip edge function now calculates **real distances and times** to make **intelligent, data-driven recommendations** with **full transparency**.
---
## ๐Ÿ“ Density Score Formula
```
density_score = (distance_km ร— 5 + time_hours ร— 10) รท place_count
```
### Thresholds
| Score | Level | Recommendation | Confidence |
|-------|-------|----------------|------------|
| 0-19 | ๐ŸŸข Low | โŒ No tour | 0.0-0.48 |
| 20-34 | ๐ŸŸก Moderate | โš ๏ธ Optional | 0.50-0.70 |
| 35-49 | ๐ŸŸ  High | โญ Recommend | 0.70-0.85 |
| 50+ | ๐Ÿ”ด Very High | ๐Ÿ”ฅ Highly Recommend | 0.85-1.0 |
---
## ๐Ÿ” What Gets Calculated?
### For Each Place
- โœ… Distance from previous place (km)
- โœ… Travel time from previous place (minutes)
- โœ… Visit duration (minutes)
### For Each Day
- โœ… Total places
- โœ… Total distance (km)
- โœ… Total travel time (minutes)
- โœ… Total visit time (minutes)
- โœ… Density score
- โœ… Density level
### For Entire Trip
- โœ… Total days
- โœ… Total places
- โœ… Total distance (km)
- โœ… Total time (hours)
- โœ… Average density score
- โœ… Maximum density score
---
## ๐Ÿง  Decision Factors
The AI considers these factors (in order of importance):
1. **Density Score** (PRIMARY) - How packed is the itinerary?
2. **Total Distance** - >100km suggests organized transport
3. **Time Commitment** - >8h/day suggests professional guidance
4. **Group Size** - โ‰ฅ4 travelers benefit from private guide
5. **Place Count** - โ‰ฅ5 places/day requires efficient routing
6. **Activity Type** - Museums, historical sites benefit from guides
---
## ๐Ÿ“Š Response Structure
```json
{
"recommend": true,
"confidence": 0.82,
"recommended_type": "daily_tour",
"daily_tour_slug": "red_tour",
"debug_info": {
"dailyMetrics": [
{
"dayNumber": 1,
"densityScore": 42.8,
"densityLevel": "high",
"totalDistanceKm": 85.0,
"totalTimeMinutes": 518,
"places": [...]
}
],
"overallMetrics": {
"maxDensityScore": 42.8,
"totalDistanceKm": 85.0,
"totalTimeHours": 8.6
},
"decisionFactors": [
{
"factor": "High Density Day",
"value": 42.8,
"impact": "positive",
"reasoning": "..."
}
],
"recommendation_reasoning": "..."
}
}
```
---
## ๐Ÿš€ Quick Examples
### Example 1: High Density โ†’ Recommend Tour
```
5 places, 85km, 8.5 hours
density = (85ร—5 + 8.5ร—10) รท 5 = 102 รท 5 = 20.4
Level: MODERATE โ†’ Optional tour (confidence: 0.52)
```
### Example 2: Very High Density โ†’ Highly Recommend
```
4 places, 90km, 9.25 hours
density = (90ร—5 + 9.25ร—10) รท 4 = 542.5 รท 4 = 135.6
Level: VERY HIGH โ†’ Highly recommend (confidence: 0.94)
```
### Example 3: Low Density โ†’ No Tour
```
3 places, 8km, 3.5 hours
density = (8ร—5 + 3.5ร—10) รท 3 = 75 รท 3 = 25
Level: MODERATE โ†’ Optional (confidence: 0.55)
```
---
## ๐Ÿ”ง Usage
### API Call (No Changes)
```typescript
const response = await supabase.functions.invoke('analyze-trip', {
body: {
destination: 'Cappadocia',
days: [
{
date: '2024-06-15',
places: [
{ name: 'Gรถreme Museum', type: 'museum', lat: 38.6425, lng: 34.8317, duration: '2 hours' },
{ name: 'Uchisar Castle', type: 'historical', lat: 38.6267, lng: 34.8050, duration: '1.5 hours' }
]
}
],
travelers: 2,
interests: ['history', 'nature']
}
});
const { recommend, confidence, debug_info } = response.data;
```
### Access Debug Info
```typescript
// Overall metrics
console.log(debug_info.overallMetrics.maxDensityScore);
console.log(debug_info.overallMetrics.totalDistanceKm);
// Daily breakdown
debug_info.dailyMetrics.forEach(day => {
console.log(`Day ${day.dayNumber}: ${day.densityScore} (${day.densityLevel})`);
});
// Decision factors
debug_info.decisionFactors.forEach(factor => {
console.log(`${factor.factor}: ${factor.value} (${factor.impact})`);
});
```
---
## ๐Ÿ“ Documentation Files
1. **ANALYZE_TRIP_ENHANCEMENT.md** - Complete feature documentation
2. **DENSITY_SCORE_GUIDE.md** - Visual guide with examples
3. **BEFORE_AFTER_COMPARISON.md** - Detailed comparison
4. **ENHANCEMENT_SUMMARY.md** - Implementation summary
5. **test-analyze-trip.js** - Test script
---
## โœ… Key Benefits
### Accuracy
- Real distance calculations (Haversine formula)
- Actual time estimates (travel + visit)
- Data-driven confidence scores
### Transparency
- See exactly why recommendation was made
- Understand which days are complex
- Know what factors influenced decision
### Intelligence
- Density-based scoring (not just place count)
- Adaptive thresholds
- Nuanced recommendations
---
## ๐ŸŽ“ Rule of Thumb
**Quick Mental Calculation:**
- 5+ places over 80+ km โ†’ Likely HIGH density
- 2-3 nearby places โ†’ Likely LOW density
- 8+ hours with lots of travel โ†’ Likely HIGH density
**When to Recommend Tour:**
- Density score โ‰ฅ35
- OR total distance >100km
- OR daily time >8 hours
- OR 4+ travelers with complex itinerary
---
## ๐Ÿ”ฎ Future Enhancements
- Real-time traffic data
- Weather-based adjustments
- Seasonal crowd factors
- User feedback loop
- ML pattern recognition
---
**Status**: โœ… Deployed and Active
**Version**: 2.0 (Enhanced)
**Date**: February 7, 2024