231 lines
5.2 KiB
Markdown
231 lines
5.2 KiB
Markdown
# 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
|