Upload app.py
Browse files577 unmodified lines5785795805815825835845855865877 unmodified lines5955965975985996006016026036046056066076086096106116126136146156166176186196206216226236 unmodified lines630631632633634635636577 unmodified linessort_by: str = None, sort_order: str = None,limit: int = 50) -> Dict[str, Any]:start_time = datetime.now()print(f"π― Analyzing profile: {user_profile.skills} | Level: {user_profile.experience_level}")# FIXED: More aggressive real data fetchingreal_challenges = await self.fetch_real_challenges(user_profile=user_profile,query=query,7 unmodified linessort_order=sort_order,)if real_challenges:challenges = real_challengesdata_source = "π₯ REAL Topcoder MCP Server (4,596+ challenges)"print(f"π Using {len(challenges)} REAL Topcoder challenges!")else:challenges = self.mock_challengesdata_source = "β¨ Enhanced Intelligence Engine (Premium Dataset)"print(f"β‘ Using {len(challenges)} premium challenges with advanced algorithms")scored_challenges = []for challenge in challenges:score, factors = self.calculate_advanced_compatibility_score(challenge, user_profile, query)challenge.compatibility_score = scorechallenge.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 0print(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")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"}}577 unmodified lines5785795805815825835845855865875885895905915925937 unmodified lines6016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456 unmodified lines652653654655656657658577 unmodified linessort_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"\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 debuggingprint(f"\nπ Step 1: Attempting to fetch REAL challenges...")real_challenges = await self.fetch_real_challenges(user_profile=user_profile,query=query,7 unmodified linessort_order=sort_order,)print(f"π Step 2: fetch_real_challenges returned {len(real_challenges)} challenges")# Determine data source and challenges to useif real_challenges and len(real_challenges) > 0:challenges = real_challengesdata_source = f"π₯ REAL Topcoder MCP Server ({len(challenges)} live challenges)"print(f"β Step 3: Using {len(challenges)} REAL MCP challenges!")# Show sample challenge detailsif challenges:sample = challenges[0]print(f"π Sample real challenge: {sample.title} | {sample.prize} | {sample.technologies}")else:challenges = self.mock_challengesdata_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 challengesprint(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 = scorechallenge.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 0print(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": f"{len(challenges)} challenges analyzed"}}
app.py+34-12