Upload app.py
Browse files577 unmodified lines5785795805815825825835845835845855865875885895905915925937 unmodified lines6016026035986046056066076086006016096106116126136146156166176046056186196206216226236246256266276286296306316326336346356366186196206376386396406416426436446456 unmodified lines652653654633655656657658577 unmodified lines sort_by: str = None, sort_order: str = None,
limit: int = 50
) -> Dict[str, Any]:
"""FIXED: Debug the actual recommendation flow"""
start_time = datetime.now()
print(f"π― Analyzing profile: {user_profile.skills} | Level: {user_profile.experience_level}")
# FIXED: More aggressive real data fetching
print(f"\nπ― === STARTING RECOMMENDATION REQUEST ===")
print(f"π― User skills: {user_profile.skills}")
print(f"π― Query: '{query}'")
print(f"π― Status filter: {status}")
print(f"π― Limit: {limit}")
# FIXED: Try to get real challenges with detailed debugging
print(f"\nπ Step 1: Attempting to fetch REAL challenges...")
real_challenges = await self.fetch_real_challenges(
user_profile=user_profile,
query=query,7 unmodified lines sort_order=sort_order,
)
if real_challenges:
print(f"π Step 2: fetch_real_challenges returned {len(real_challenges)} challenges")
# Determine data source and challenges to use
if real_challenges and len(real_challenges) > 0:
challenges = real_challenges
data_source = "π₯ REAL Topcoder MCP Server (4,596+ challenges)"
print(f"π Using {len(challenges)} REAL Topcoder challenges!")
data_source = f"π₯ REAL Topcoder MCP Server ({len(challenges)} live challenges)"
print(f"β
Step 3: Using {len(challenges)} REAL MCP challenges!")
# Show sample challenge details
if challenges:
sample = challenges[0]
print(f"π Sample real challenge: {sample.title} | {sample.prize} | {sample.technologies}")
else:
challenges = self.mock_challenges
data_source = "β¨ Enhanced Intelligence Engine (Premium Dataset)"
print(f"β‘ Using {len(challenges)} premium challenges with advanced algorithms")
data_source = "β‘ Enhanced Intelligence Engine (Premium Dataset)"
print(f"β οΈ Step 3: No real challenges returned, using {len(challenges)} fallback challenges")
print(f"π Debug: Why no real challenges? Check fetch_real_challenges output above")
# Score and rank challenges
print(f"\nπ§ Step 4: Scoring {len(challenges)} challenges...")
scored_challenges = []
for challenge in challenges:
score, factors = self.calculate_advanced_compatibility_score(challenge, user_profile, query)
challenge.compatibility_score = score
challenge.rationale = f"Match: {score:.0f}%. " + ". ".join(factors[:2]) + "."
scored_challenges.append(challenge)
scored_challenges.sort(key=lambda x: x.compatibility_score, reverse=True)
recommendations = scored_challenges[:5]
processing_time = (datetime.now() - start_time).total_seconds()
query_techs = self.extract_technologies_from_query(query)
avg_score = sum(c.compatibility_score for c in challenges) / len(challenges) if challenges else 0
print(f"β
Generated {len(recommendations)} recommendations in {processing_time:.3f}s:")
for i, rec in enumerate(recommendations, 1):
print(f" {i}. {rec.title} - {rec.compatibility_score:.0f}% compatibility")
print(f"β
Step 5: Generated {len(recommendations)} recommendations in {processing_time:.3f}s")
print(f"π Top recommendation: {recommendations[0].title} ({recommendations[0].compatibility_score:.0f}%)")
print(f"π Data source being reported: {data_source}")
print(f"π― === RECOMMENDATION REQUEST COMPLETE ===\n")
return {
"recommendations": [asdict(rec) for rec in recommendations],
"insights": {6 unmodified lines "session_active": bool(self.session_id),
"mcp_connected": self.is_connected,
"algorithm_version": "Advanced Multi-Factor v2.0",
"topcoder_total": "4,596+ live challenges" if real_challenges else "Premium dataset"
"topcoder_total": f"{len(challenges)} challenges analyzed"
}
}
app.py+34-12