20 KiB
20 KiB
Analyze-Trip Enhancement - Flow Diagram
π Processing Flow
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β INPUT: Trip Request β
β { destination, days: [{ date, places: [...] }], travelers } β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STEP 1: Analyze Trip Metrics β
β β
β For each day: β
β For each place: β
β β Calculate distance from previous place (Haversine) β
β β Estimate travel time (distance Γ· 40 km/h) β
β β Parse visit duration ("2 hours" β 120 min) β
β β
β Calculate daily totals: β
β β Total distance (sum of all distances) β
β β Total travel time (sum of all travel times) β
β β Total visit time (sum of all visit durations) β
β β Total time (travel + visit) β
β β
β Calculate density score: β
β density = (distance_km Γ 5 + time_hours Γ 10) Γ· places β
β β
β Determine density level: β
β <20: low, 20-35: moderate, 35-50: high, β₯50: very_high β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STEP 2: Calculate Overall Metrics β
β β
β β Total days β
β β Total places (across all days) β
β β Total distance (sum of all daily distances) β
β β Total time (sum of all daily times) β
β β Average density score (mean of daily scores) β
β β Maximum density score (highest daily score) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STEP 3: Identify Decision Factors β
β β
β Analyze and record factors: β
β β
β β Density Level (PRIMARY FACTOR) β
β - Very High (β₯50): Strong positive impact β
β - High (35-50): Positive impact β
β - Moderate (20-35): Neutral impact β
β - Low (<20): Negative impact β
β β
β β Total Distance β
β - >100km: Positive impact β
β - 50-100km: Neutral impact β
β β
β β Time Commitment β
β - >8h/day: Positive impact β
β β
β β Group Size β
β - β₯4 travelers: Positive impact β
β - 1 traveler: Neutral impact β
β β
β β Place Count β
β - β₯5 places/day: Positive impact β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STEP 4: Match Daily Tours β
β β
β Query database for active daily tours in region β
β β
β For each tour: β
β β Extract place types from trip β
β β Compare with tour's related_place_types β
β β Calculate overlap score β
β β
β Select best match (highest score β₯0.3) β
β β
β If match found: β
β β Generate tour-specific reasoning β
β β Boost confidence based on density score β
β β Return recommendation with tour slug β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
Match Found?
β
βββββββββββ΄ββββββββββ
β β
YES NO
β β
β β
βββββββββββββββββββββββββ ββββββββββββββββββββ
β Return with Tour β β Check Fallback β
β Recommendation β β (4+ travelers) β
β + Debug Info β β β
βββββββββββββββββββββββββ ββββββββββββββββββββ
β
βββββββββββ΄ββββββββββ
β β
YES NO
β β
β β
ββββββββββββββββββββ ββββββββββββββββββ
β Suggest Private β β Check Minimum β
β Guide β β Criteria β
β + Debug Info β β β
ββββββββββββββββββββ ββββββββββββββββββ
β
βββββββββ΄ββββββββ
β β
PASS FAIL
β β
β β
βββββββββββββββ ββββββββββββββββ
β Call AI for β β Return No β
β Analysis β β Recommend β
β β β + Debug Info β
βββββββββββββββ ββββββββββββββββ
β
βββββββββββββββββββ
β AI analyzes β
β with density β
β metrics β
βββββββββββββββββββ
β
βββββββββββββββββββ
β Return AI β
β Recommendation β
β + Debug Info β
βββββββββββββββββββ
π Density Score Calculation Detail
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β DENSITY SCORE CALCULATION β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Input:
- totalDistanceKm: 85.0
- totalTimeMinutes: 518
- placeCount: 5
Step 1: Convert time to hours
totalTimeHours = 518 Γ· 60 = 8.63
Step 2: Apply formula
density = (distance Γ 5 + time Γ 10) Γ· places
density = (85.0 Γ 5 + 8.63 Γ 10) Γ· 5
density = (425 + 86.3) Γ· 5
density = 511.3 Γ· 5
density = 102.26
Step 3: Determine level
102.26 β₯ 50 β VERY HIGH
Step 4: Calculate confidence
confidence = 0.85 + (102.26 - 50) Γ· 100
confidence = 0.85 + 0.52
confidence = 1.37 β capped at 1.0
confidence = 1.0
Result:
β Density Score: 102.26
β Density Level: VERY HIGH
β Recommendation: HIGHLY RECOMMEND
β Confidence: 1.0 (100%)
π― Decision Tree
Start Analysis
β
β
Calculate Density Score
β
β
βββββββββββ΄ββββββββββ
β β
Score β₯ 50 Score < 50
β β
β β
βββββββββββββββββ ββββββββ΄βββββββ
β VERY HIGH β β β
β Confidence: β β Score β₯ 35β
β 0.85-1.0 β β β
β β β β
β Highly β βββββββ βββββββββββ
β Recommend β βHIGH β βScoreβ₯20 β
β Tour β β0.70-β β β
βββββββββββββββββ β0.85 β β β
β β ββββββ ββββββββ
βRec β βMOD β β LOW β
βTour β β0.50β β<0.50 β
βββββββ β- β β β
β0.70β βDon't β
β β βRec β
βOpt β ββββββββ
βTourβ
ββββββ
Legend:
β VERY HIGH (β₯50): π₯ Highly Recommend (0.85-1.0)
β HIGH (35-50): β Recommend (0.70-0.85)
β MODERATE (20-35): β οΈ Optional (0.50-0.70)
β LOW (<20): β Don't Recommend (<0.50)
π Debug Info Structure
debug_info
βββ dailyMetrics[]
β βββ dayNumber
β βββ date
β βββ totalPlaces
β βββ totalDistanceKm
β βββ totalTravelTimeMinutes
β βββ totalVisitTimeMinutes
β βββ totalTimeMinutes
β βββ densityScore
β βββ densityLevel
β βββ places[]
β βββ name
β βββ type
β βββ lat, lng
β βββ distanceFromPreviousKm
β βββ travelTimeFromPreviousMinutes
β βββ visitDurationMinutes
β
βββ overallMetrics
β βββ totalDays
β βββ totalPlaces
β βββ totalDistanceKm
β βββ totalTimeHours
β βββ averageDensityScore
β βββ maxDensityScore
β
βββ decisionFactors[]
β βββ factor (name)
β βββ value (numeric or string)
β βββ impact (positive/negative/neutral)
β βββ reasoning (explanation)
β
βββ recommendation_reasoning (summary)
π Confidence Calculation Flow
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CONFIDENCE CALCULATION ALGORITHM β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Input: maxDensityScore
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β IF maxDensityScore β₯ 50 β
β confidence = 0.85 + (maxDensityScore - 50) / 100 β
β range: [0.85, 1.0] β
β recommendation: HIGHLY RECOMMEND β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ELSE IF maxDensityScore β₯ 35 β
β confidence = 0.70 + (maxDensityScore - 35) / 100 β
β range: [0.70, 0.85) β
β recommendation: RECOMMEND β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ELSE IF maxDensityScore β₯ 20 β
β confidence = 0.50 + (maxDensityScore - 20) / 100 β
β range: [0.50, 0.70) β
β recommendation: OPTIONAL β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ELSE (maxDensityScore < 20) β
β confidence = maxDensityScore / 40 β
β range: [0.0, 0.50) β
β recommendation: DON'T RECOMMEND β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β IF confidence < 0.6 β
β recommend = false β
β (Override any previous recommendation) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Examples:
Score 102.26 β confidence = 0.85 + 52.26/100 = 1.37 β capped at 1.0
Score 42.8 β confidence = 0.70 + 7.8/100 = 0.778
Score 28.5 β confidence = 0.50 + 8.5/100 = 0.585
Score 15.2 β confidence = 15.2/40 = 0.38 β recommend = false
π¨ Visual Density Scale
DENSITY SCORE VISUALIZATION
0 ββββββββββ 20 ββββββββββ 35 ββββββββββ 50 ββββββββββ 100+
β β β β β
β LOW β MODERATE β HIGH β VERY HIGH β
β β β β β
β β
Self β β οΈ Optional β β Recommendβ π₯ Highly β
β Plan β Tour β Tour β Recommend β
β β β β β
β Confidence β Confidence β Confidence β Confidence β
β 0.0-0.48 β 0.50-0.70 β 0.70-0.85 β 0.85-1.0 β
β β β β β
β Examples: β Examples: β Examples: β Examples: β
β β’ 2 nearby β β’ 4 places β β’ 5 places β β’ 4 places β
β places β 45km β 85km β 90km β
β β’ 15km β β’ 6 hours β β’ 8.5 hours β β’ 9+ hours β
β β’ 4 hours β β β β
ββββββββββββββ΄ββββββββββββββ΄ββββββββββββββ΄βββββββββββββββ
Status: β Deployed and Active Version: 2.0 (Enhanced) Date: February 7, 2024