Upload app.py
Browse files
app.py
CHANGED
|
@@ -35,7 +35,7 @@ class UserProfile:
|
|
| 35 |
|
| 36 |
class UltimateTopcoderMCPEngine:
|
| 37 |
"""ULTIMATE MCP Engine - Real Data + Advanced Intelligence"""
|
| 38 |
-
|
| 39 |
def __init__(self):
|
| 40 |
print("π Initializing ULTIMATE Topcoder Intelligence Engine...")
|
| 41 |
self.base_url = "https://api.topcoder-dev.com/v6/mcp"
|
|
@@ -43,9 +43,8 @@ class UltimateTopcoderMCPEngine:
|
|
| 43 |
self.is_connected = False
|
| 44 |
self.mock_challenges = self._create_enhanced_fallback_challenges()
|
| 45 |
print(f"β
Loaded fallback system with {len(self.mock_challenges)} premium challenges")
|
| 46 |
-
|
| 47 |
def _create_enhanced_fallback_challenges(self) -> List[Challenge]:
|
| 48 |
-
"""Enhanced fallback challenges with real-world data structure"""
|
| 49 |
return [
|
| 50 |
Challenge(
|
| 51 |
id="30174840",
|
|
@@ -108,9 +107,8 @@ class UltimateTopcoderMCPEngine:
|
|
| 108 |
registrants=24
|
| 109 |
)
|
| 110 |
]
|
| 111 |
-
|
| 112 |
def parse_sse_response(self, sse_text: str) -> Dict[str, Any]:
|
| 113 |
-
"""Parse Server-Sent Events response"""
|
| 114 |
lines = sse_text.strip().split('\n')
|
| 115 |
for line in lines:
|
| 116 |
line = line.strip()
|
|
@@ -121,13 +119,11 @@ class UltimateTopcoderMCPEngine:
|
|
| 121 |
except json.JSONDecodeError:
|
| 122 |
pass
|
| 123 |
return None
|
| 124 |
-
|
| 125 |
async def initialize_connection(self) -> bool:
|
| 126 |
-
"""Initialize MCP connection with enhanced error handling"""
|
| 127 |
-
|
| 128 |
if self.is_connected:
|
| 129 |
return True
|
| 130 |
-
|
| 131 |
headers = {
|
| 132 |
"Accept": "application/json, text/event-stream, */*",
|
| 133 |
"Accept-Language": "en-US,en;q=0.9",
|
|
@@ -137,7 +133,7 @@ class UltimateTopcoderMCPEngine:
|
|
| 137 |
"Referer": "https://modelcontextprotocol.io/",
|
| 138 |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
| 139 |
}
|
| 140 |
-
|
| 141 |
init_request = {
|
| 142 |
"jsonrpc": "2.0",
|
| 143 |
"id": 0,
|
|
@@ -155,7 +151,7 @@ class UltimateTopcoderMCPEngine:
|
|
| 155 |
}
|
| 156 |
}
|
| 157 |
}
|
| 158 |
-
|
| 159 |
try:
|
| 160 |
async with httpx.AsyncClient(timeout=10.0) as client:
|
| 161 |
response = await client.post(
|
|
@@ -163,7 +159,7 @@ class UltimateTopcoderMCPEngine:
|
|
| 163 |
json=init_request,
|
| 164 |
headers=headers
|
| 165 |
)
|
| 166 |
-
|
| 167 |
if response.status_code == 200:
|
| 168 |
response_headers = dict(response.headers)
|
| 169 |
if 'mcp-session-id' in response_headers:
|
|
@@ -171,25 +167,23 @@ class UltimateTopcoderMCPEngine:
|
|
| 171 |
self.is_connected = True
|
| 172 |
print(f"β
Real MCP connection established: {self.session_id[:8]}...")
|
| 173 |
return True
|
| 174 |
-
|
| 175 |
except Exception as e:
|
| 176 |
print(f"β οΈ MCP connection failed, using enhanced fallback: {e}")
|
| 177 |
-
|
| 178 |
return False
|
| 179 |
-
|
| 180 |
async def call_tool(self, tool_name: str, arguments: Dict[str, Any]) -> Optional[Dict]:
|
| 181 |
-
"""Call MCP tool with real session"""
|
| 182 |
-
|
| 183 |
if not self.session_id:
|
| 184 |
return None
|
| 185 |
-
|
| 186 |
headers = {
|
| 187 |
"Accept": "application/json, text/event-stream, */*",
|
| 188 |
"Content-Type": "application/json",
|
| 189 |
"Origin": "https://modelcontextprotocol.io",
|
| 190 |
"mcp-session-id": self.session_id
|
| 191 |
}
|
| 192 |
-
|
| 193 |
tool_request = {
|
| 194 |
"jsonrpc": "2.0",
|
| 195 |
"id": int(datetime.now().timestamp()),
|
|
@@ -199,7 +193,7 @@ class UltimateTopcoderMCPEngine:
|
|
| 199 |
"arguments": arguments
|
| 200 |
}
|
| 201 |
}
|
| 202 |
-
|
| 203 |
try:
|
| 204 |
async with httpx.AsyncClient(timeout=30.0) as client:
|
| 205 |
response = await client.post(
|
|
@@ -207,7 +201,7 @@ class UltimateTopcoderMCPEngine:
|
|
| 207 |
json=tool_request,
|
| 208 |
headers=headers
|
| 209 |
)
|
| 210 |
-
|
| 211 |
if response.status_code == 200:
|
| 212 |
if "text/event-stream" in response.headers.get("content-type", ""):
|
| 213 |
sse_data = self.parse_sse_response(response.text)
|
|
@@ -217,28 +211,23 @@ class UltimateTopcoderMCPEngine:
|
|
| 217 |
json_data = response.json()
|
| 218 |
if "result" in json_data:
|
| 219 |
return json_data["result"]
|
| 220 |
-
|
| 221 |
except Exception:
|
| 222 |
pass
|
| 223 |
-
|
| 224 |
return None
|
| 225 |
-
|
| 226 |
def convert_topcoder_challenge(self, tc_data: Dict) -> Challenge:
|
| 227 |
-
"""Convert real Topcoder challenge data with enhanced parsing"""
|
| 228 |
-
|
| 229 |
-
# Extract real fields from Topcoder data structure
|
| 230 |
challenge_id = str(tc_data.get('id', 'unknown'))
|
| 231 |
title = tc_data.get('name', 'Topcoder Challenge')
|
| 232 |
description = tc_data.get('description', 'Challenge description not available')
|
| 233 |
-
|
| 234 |
-
# Extract technologies from skills array
|
| 235 |
technologies = []
|
| 236 |
skills = tc_data.get('skills', [])
|
| 237 |
for skill in skills:
|
| 238 |
if isinstance(skill, dict) and 'name' in skill:
|
| 239 |
technologies.append(skill['name'])
|
| 240 |
-
|
| 241 |
-
# Also check for direct technologies field
|
| 242 |
if 'technologies' in tc_data:
|
| 243 |
tech_list = tc_data['technologies']
|
| 244 |
if isinstance(tech_list, list):
|
|
@@ -247,8 +236,7 @@ class UltimateTopcoderMCPEngine:
|
|
| 247 |
technologies.append(tech['name'])
|
| 248 |
elif isinstance(tech, str):
|
| 249 |
technologies.append(tech)
|
| 250 |
-
|
| 251 |
-
# Calculate total prize from prizeSets
|
| 252 |
total_prize = 0
|
| 253 |
prize_sets = tc_data.get('prizeSets', [])
|
| 254 |
for prize_set in prize_sets:
|
|
@@ -257,12 +245,10 @@ class UltimateTopcoderMCPEngine:
|
|
| 257 |
for prize in prizes:
|
| 258 |
if prize.get('type') == 'USD':
|
| 259 |
total_prize += prize.get('value', 0)
|
| 260 |
-
|
| 261 |
prize = f"${total_prize:,}" if total_prize > 0 else "Merit-based"
|
| 262 |
-
|
| 263 |
-
# Map challenge type to difficulty
|
| 264 |
challenge_type = tc_data.get('type', 'Unknown')
|
| 265 |
-
|
| 266 |
difficulty_mapping = {
|
| 267 |
'First2Finish': 'Beginner',
|
| 268 |
'Code': 'Intermediate',
|
|
@@ -272,19 +258,16 @@ class UltimateTopcoderMCPEngine:
|
|
| 272 |
'Bug Hunt': 'Beginner',
|
| 273 |
'Test Suites': 'Intermediate'
|
| 274 |
}
|
| 275 |
-
|
| 276 |
difficulty = difficulty_mapping.get(challenge_type, 'Intermediate')
|
| 277 |
-
|
| 278 |
-
# Time estimate and registrants
|
| 279 |
time_estimate = "Variable duration"
|
| 280 |
registrants = tc_data.get('numOfRegistrants', 0)
|
| 281 |
-
|
| 282 |
status = tc_data.get('status', '')
|
| 283 |
if status == 'Completed':
|
| 284 |
time_estimate = "Recently completed"
|
| 285 |
elif status in ['Active', 'Draft']:
|
| 286 |
time_estimate = "Active challenge"
|
| 287 |
-
|
| 288 |
return Challenge(
|
| 289 |
id=challenge_id,
|
| 290 |
title=title,
|
|
@@ -295,29 +278,72 @@ class UltimateTopcoderMCPEngine:
|
|
| 295 |
time_estimate=time_estimate,
|
| 296 |
registrants=registrants
|
| 297 |
)
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
if not await self.initialize_connection():
|
| 303 |
return []
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
if not result:
|
| 308 |
return []
|
| 309 |
-
|
| 310 |
-
# Extract challenge data using the fixed parsing method
|
| 311 |
challenge_data_list = []
|
| 312 |
-
|
| 313 |
-
# Method 1: Use structuredContent (real data)
|
| 314 |
if "structuredContent" in result:
|
| 315 |
structured = result["structuredContent"]
|
| 316 |
if isinstance(structured, dict) and "data" in structured:
|
| 317 |
challenge_data_list = structured["data"]
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
# Method 2: Fallback to content parsing
|
| 321 |
elif "content" in result and len(result["content"]) > 0:
|
| 322 |
content_item = result["content"][0]
|
| 323 |
if isinstance(content_item, dict) and content_item.get("type") == "text":
|
|
@@ -326,11 +352,9 @@ class UltimateTopcoderMCPEngine:
|
|
| 326 |
parsed_data = json.loads(text_content)
|
| 327 |
if "data" in parsed_data:
|
| 328 |
challenge_data_list = parsed_data["data"]
|
| 329 |
-
print(f"β
Retrieved {len(challenge_data_list)} challenges from content")
|
| 330 |
except json.JSONDecodeError:
|
| 331 |
pass
|
| 332 |
-
|
| 333 |
-
# Convert to Challenge objects
|
| 334 |
challenges = []
|
| 335 |
for item in challenge_data_list:
|
| 336 |
if isinstance(item, dict):
|
|
@@ -340,50 +364,22 @@ class UltimateTopcoderMCPEngine:
|
|
| 340 |
except Exception as e:
|
| 341 |
print(f"Error converting challenge: {e}")
|
| 342 |
continue
|
| 343 |
-
|
| 344 |
return challenges
|
| 345 |
-
|
| 346 |
-
def extract_technologies_from_query(self, query: str) -> List[str]:
|
| 347 |
-
"""Enhanced technology extraction with expanded keywords"""
|
| 348 |
-
tech_keywords = {
|
| 349 |
-
'python', 'java', 'javascript', 'react', 'node', 'angular', 'vue',
|
| 350 |
-
'aws', 'docker', 'kubernetes', 'api', 'rest', 'graphql', 'sql',
|
| 351 |
-
'mongodb', 'postgresql', 'machine learning', 'ai', 'blockchain',
|
| 352 |
-
'ios', 'android', 'flutter', 'swift', 'kotlin', 'c++', 'c#',
|
| 353 |
-
'ruby', 'php', 'go', 'rust', 'typescript', 'html', 'css',
|
| 354 |
-
'nft', 'non-fungible tokens', 'ethereum', 'smart contracts', 'solidity',
|
| 355 |
-
'figma', 'ui/ux', 'design', 'testing', 'jest', 'hardhat', 'web3',
|
| 356 |
-
'fastapi', 'django', 'flask', 'redis', 'tensorflow', 'd3.js', 'chart.js'
|
| 357 |
-
}
|
| 358 |
-
|
| 359 |
-
query_lower = query.lower()
|
| 360 |
-
found_techs = [tech for tech in tech_keywords if tech in query_lower]
|
| 361 |
-
return found_techs
|
| 362 |
-
|
| 363 |
def calculate_advanced_compatibility_score(self, challenge: Challenge, user_profile: UserProfile, query: str) -> tuple:
|
| 364 |
-
"""ENHANCED compatibility scoring algorithm with detailed analysis"""
|
| 365 |
-
|
| 366 |
score = 0.0
|
| 367 |
factors = []
|
| 368 |
-
|
| 369 |
-
# Convert to lowercase for matching
|
| 370 |
user_skills_lower = [skill.lower().strip() for skill in user_profile.skills]
|
| 371 |
challenge_techs_lower = [tech.lower() for tech in challenge.technologies]
|
| 372 |
-
|
| 373 |
-
# 1. Advanced Skill Matching (40% weight)
|
| 374 |
skill_matches = len(set(user_skills_lower) & set(challenge_techs_lower))
|
| 375 |
-
|
| 376 |
if len(challenge.technologies) > 0:
|
| 377 |
-
# Exact match score
|
| 378 |
exact_match_score = (skill_matches / len(challenge.technologies)) * 30
|
| 379 |
-
# Coverage bonus for multiple matches
|
| 380 |
coverage_bonus = min(skill_matches * 10, 10)
|
| 381 |
skill_score = exact_match_score + coverage_bonus
|
| 382 |
else:
|
| 383 |
-
skill_score = 30
|
| 384 |
-
|
| 385 |
score += skill_score
|
| 386 |
-
|
| 387 |
if skill_matches > 0:
|
| 388 |
matched_skills = [t for t in challenge.technologies if t.lower() in user_skills_lower]
|
| 389 |
factors.append(f"Strong match: uses your {', '.join(matched_skills[:2])} expertise")
|
|
@@ -391,12 +387,9 @@ class UltimateTopcoderMCPEngine:
|
|
| 391 |
factors.append(f"Growth opportunity: learn {', '.join(challenge.technologies[:2])}")
|
| 392 |
else:
|
| 393 |
factors.append("Versatile challenge suitable for multiple skill levels")
|
| 394 |
-
|
| 395 |
-
# 2. Experience Level Compatibility (30% weight)
|
| 396 |
level_mapping = {'beginner': 1, 'intermediate': 2, 'advanced': 3}
|
| 397 |
user_level_num = level_mapping.get(user_profile.experience_level.lower(), 2)
|
| 398 |
challenge_level_num = level_mapping.get(challenge.difficulty.lower(), 2)
|
| 399 |
-
|
| 400 |
level_diff = abs(user_level_num - challenge_level_num)
|
| 401 |
if level_diff == 0:
|
| 402 |
level_score = 30
|
|
@@ -407,10 +400,7 @@ class UltimateTopcoderMCPEngine:
|
|
| 407 |
else:
|
| 408 |
level_score = 5
|
| 409 |
factors.append("Stretch challenge with significant learning curve")
|
| 410 |
-
|
| 411 |
score += level_score
|
| 412 |
-
|
| 413 |
-
# 3. Query/Interest Relevance (20% weight)
|
| 414 |
query_techs = self.extract_technologies_from_query(query)
|
| 415 |
if query_techs:
|
| 416 |
query_matches = len(set([tech.lower() for tech in query_techs]) & set(challenge_techs_lower))
|
|
@@ -418,57 +408,41 @@ class UltimateTopcoderMCPEngine:
|
|
| 418 |
query_score = min(query_matches / len(query_techs), 1.0) * 20
|
| 419 |
else:
|
| 420 |
query_score = 10
|
| 421 |
-
|
| 422 |
if query_matches > 0:
|
| 423 |
factors.append(f"Directly matches your interest in {', '.join(query_techs[:2])}")
|
| 424 |
else:
|
| 425 |
query_score = 10
|
| 426 |
-
|
| 427 |
score += query_score
|
| 428 |
-
|
| 429 |
-
# 4. Market Attractiveness (10% weight)
|
| 430 |
try:
|
| 431 |
-
# Extract numeric value from prize string
|
| 432 |
prize_numeric = 0
|
| 433 |
if challenge.prize.startswith('$'):
|
| 434 |
prize_str = challenge.prize[1:].replace(',', '')
|
| 435 |
prize_numeric = int(prize_str) if prize_str.isdigit() else 0
|
| 436 |
-
|
| 437 |
-
prize_score = min(prize_numeric / 1000 * 2, 8) # Max 8 points
|
| 438 |
competition_bonus = 2 if 20 <= challenge.registrants <= 50 else 0
|
| 439 |
market_score = prize_score + competition_bonus
|
| 440 |
except:
|
| 441 |
-
market_score = 5
|
| 442 |
-
|
| 443 |
score += market_score
|
| 444 |
-
|
| 445 |
return min(score, 100.0), factors
|
| 446 |
-
|
| 447 |
def get_user_insights(self, user_profile: UserProfile) -> Dict:
|
| 448 |
-
"""Generate comprehensive user insights with market intelligence"""
|
| 449 |
skills = user_profile.skills
|
| 450 |
level = user_profile.experience_level
|
| 451 |
time_available = user_profile.time_available
|
| 452 |
-
|
| 453 |
-
# Analyze skill categories
|
| 454 |
frontend_skills = ['react', 'javascript', 'css', 'html', 'vue', 'angular', 'typescript']
|
| 455 |
backend_skills = ['python', 'java', 'node', 'fastapi', 'django', 'flask', 'php', 'ruby']
|
| 456 |
data_skills = ['sql', 'postgresql', 'mongodb', 'redis', 'elasticsearch', 'tensorflow']
|
| 457 |
devops_skills = ['docker', 'kubernetes', 'aws', 'azure', 'terraform', 'jenkins']
|
| 458 |
design_skills = ['figma', 'ui/ux', 'design', 'prototyping', 'accessibility']
|
| 459 |
blockchain_skills = ['solidity', 'web3', 'ethereum', 'blockchain', 'smart contracts', 'nft']
|
| 460 |
-
|
| 461 |
user_skills_lower = [skill.lower() for skill in skills]
|
| 462 |
-
|
| 463 |
-
# Calculate strengths
|
| 464 |
frontend_count = sum(1 for skill in user_skills_lower if any(fs in skill for fs in frontend_skills))
|
| 465 |
backend_count = sum(1 for skill in user_skills_lower if any(bs in skill for bs in backend_skills))
|
| 466 |
data_count = sum(1 for skill in user_skills_lower if any(ds in skill for ds in data_skills))
|
| 467 |
devops_count = sum(1 for skill in user_skills_lower if any(ds in skill for ds in devops_skills))
|
| 468 |
design_count = sum(1 for skill in user_skills_lower if any(ds in skill for ds in design_skills))
|
| 469 |
blockchain_count = sum(1 for skill in user_skills_lower if any(bs in skill for bs in blockchain_skills))
|
| 470 |
-
|
| 471 |
-
# Determine profile type with enhanced categories
|
| 472 |
if blockchain_count >= 2:
|
| 473 |
profile_type = "Blockchain Developer"
|
| 474 |
elif frontend_count >= 2 and backend_count >= 1:
|
|
@@ -485,8 +459,6 @@ class UltimateTopcoderMCPEngine:
|
|
| 485 |
profile_type = "DevOps Engineer"
|
| 486 |
else:
|
| 487 |
profile_type = "Versatile Developer"
|
| 488 |
-
|
| 489 |
-
# Generate comprehensive insights
|
| 490 |
insights = {
|
| 491 |
'profile_type': profile_type,
|
| 492 |
'strengths': f"Strong {profile_type.lower()} with expertise in {', '.join(skills[:3]) if skills else 'multiple technologies'}",
|
|
@@ -496,13 +468,10 @@ class UltimateTopcoderMCPEngine:
|
|
| 496 |
'time_optimization': f"With {time_available}, you can complete 1-2 medium challenges or 1 large project",
|
| 497 |
'success_probability': self._calculate_success_probability(level, len(skills))
|
| 498 |
}
|
| 499 |
-
|
| 500 |
return insights
|
| 501 |
-
|
| 502 |
def _suggest_growth_areas(self, user_skills: List[str], frontend: int, backend: int, data: int, devops: int, blockchain: int) -> str:
|
| 503 |
-
"""Enhanced growth area suggestions"""
|
| 504 |
suggestions = []
|
| 505 |
-
|
| 506 |
if blockchain < 1 and (frontend >= 1 or backend >= 1):
|
| 507 |
suggestions.append("blockchain and Web3 technologies")
|
| 508 |
if devops < 1:
|
|
@@ -513,14 +482,11 @@ class UltimateTopcoderMCPEngine:
|
|
| 513 |
suggestions.append("TypeScript for enhanced development")
|
| 514 |
if backend >= 1 and "api" not in str(user_skills):
|
| 515 |
suggestions.append("API design and microservices")
|
| 516 |
-
|
| 517 |
if not suggestions:
|
| 518 |
suggestions = ["AI/ML integration", "system design", "performance optimization"]
|
| 519 |
-
|
| 520 |
return "Consider exploring " + ", ".join(suggestions[:3])
|
| 521 |
-
|
| 522 |
def _get_market_trends(self, skills: List[str]) -> str:
|
| 523 |
-
"""Enhanced market trends with current data"""
|
| 524 |
hot_skills = {
|
| 525 |
'react': 'React dominates frontend with 75% job market share',
|
| 526 |
'python': 'Python leads in AI/ML and backend development growth',
|
|
@@ -531,21 +497,17 @@ class UltimateTopcoderMCPEngine:
|
|
| 531 |
'ai': 'AI integration skills in highest demand for 2024',
|
| 532 |
'kubernetes': 'Container orchestration critical for enterprise roles'
|
| 533 |
}
|
| 534 |
-
|
| 535 |
for skill in skills:
|
| 536 |
skill_lower = skill.lower()
|
| 537 |
for hot_skill, trend in hot_skills.items():
|
| 538 |
if hot_skill in skill_lower:
|
| 539 |
return trend
|
| 540 |
-
|
| 541 |
return "Full-stack and cloud skills show strongest market demand"
|
| 542 |
-
|
| 543 |
def _calculate_success_probability(self, level: str, skill_count: int) -> str:
|
| 544 |
-
"""Enhanced success probability calculation"""
|
| 545 |
base_score = {'beginner': 60, 'intermediate': 75, 'advanced': 85}.get(level.lower(), 70)
|
| 546 |
skill_bonus = min(skill_count * 3, 15)
|
| 547 |
total = base_score + skill_bonus
|
| 548 |
-
|
| 549 |
if total >= 90:
|
| 550 |
return f"{total}% - Outstanding success potential"
|
| 551 |
elif total >= 80:
|
|
@@ -554,51 +516,53 @@ class UltimateTopcoderMCPEngine:
|
|
| 554 |
return f"{total}% - Good probability of success"
|
| 555 |
else:
|
| 556 |
return f"{total}% - Consider skill development first"
|
| 557 |
-
|
| 558 |
-
async def get_personalized_recommendations(
|
| 559 |
-
|
| 560 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 561 |
start_time = datetime.now()
|
| 562 |
print(f"π Analyzing profile: {user_profile.skills} | Level: {user_profile.experience_level}")
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 567 |
if real_challenges:
|
| 568 |
challenges = real_challenges
|
| 569 |
data_source = "π₯ REAL Topcoder MCP Server (4,596+ challenges)"
|
| 570 |
print(f"π Using {len(challenges)} REAL Topcoder challenges!")
|
| 571 |
else:
|
| 572 |
-
# Fallback to enhanced mock data
|
| 573 |
challenges = self.mock_challenges
|
| 574 |
data_source = "β¨ Enhanced Intelligence Engine (Premium Dataset)"
|
| 575 |
print(f"β‘ Using {len(challenges)} premium challenges with advanced algorithms")
|
| 576 |
-
|
| 577 |
-
# Apply ADVANCED scoring algorithm
|
| 578 |
scored_challenges = []
|
| 579 |
for challenge in challenges:
|
| 580 |
score, factors = self.calculate_advanced_compatibility_score(challenge, user_profile, query)
|
| 581 |
challenge.compatibility_score = score
|
| 582 |
challenge.rationale = f"Match: {score:.0f}%. " + ". ".join(factors[:2]) + "."
|
| 583 |
scored_challenges.append(challenge)
|
| 584 |
-
|
| 585 |
-
# Sort by advanced compatibility score
|
| 586 |
scored_challenges.sort(key=lambda x: x.compatibility_score, reverse=True)
|
| 587 |
-
|
| 588 |
-
# Return top recommendations
|
| 589 |
recommendations = scored_challenges[:5]
|
| 590 |
-
|
| 591 |
-
# Processing time
|
| 592 |
processing_time = (datetime.now() - start_time).total_seconds()
|
| 593 |
-
|
| 594 |
-
# Generate comprehensive insights
|
| 595 |
query_techs = self.extract_technologies_from_query(query)
|
| 596 |
avg_score = sum(c.compatibility_score for c in challenges) / len(challenges) if challenges else 0
|
| 597 |
-
|
| 598 |
print(f"β
Generated {len(recommendations)} recommendations in {processing_time:.3f}s:")
|
| 599 |
for i, rec in enumerate(recommendations, 1):
|
| 600 |
print(f" {i}. {rec.title} - {rec.compatibility_score:.0f}% compatibility")
|
| 601 |
-
|
| 602 |
return {
|
| 603 |
"recommendations": [asdict(rec) for rec in recommendations],
|
| 604 |
"insights": {
|
|
@@ -994,46 +958,47 @@ def format_insights_panel(insights: Dict) -> str:
|
|
| 994 |
</div>
|
| 995 |
"""
|
| 996 |
|
| 997 |
-
async def get_ultimate_recommendations_async(
|
| 998 |
-
|
| 999 |
-
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
|
| 1003 |
-
print(f" Level: {experience_level}")
|
| 1004 |
-
print(f" Time: {time_available}")
|
| 1005 |
-
print(f" Interests: {interests}")
|
| 1006 |
-
|
| 1007 |
-
# Enhanced input validation
|
| 1008 |
-
if not skills_input.strip():
|
| 1009 |
-
error_msg = """
|
| 1010 |
-
<div style='background:linear-gradient(135deg,#ff7675,#fd79a8);color:white;padding:25px;border-radius:12px;text-align:center;box-shadow:0 8px 25px rgba(255,118,117,0.3);'>
|
| 1011 |
-
<div style='font-size:3em;margin-bottom:15px;'>β οΈ</div>
|
| 1012 |
-
<div style='font-size:1.3em;font-weight:600;margin-bottom:10px;'>Please enter your skills</div>
|
| 1013 |
-
<div style='opacity:0.9;font-size:1em;'>Example: Python, JavaScript, React, AWS, Docker</div>
|
| 1014 |
-
</div>
|
| 1015 |
-
"""
|
| 1016 |
-
return error_msg, ""
|
| 1017 |
-
|
| 1018 |
-
try:
|
| 1019 |
-
# Parse and clean skills
|
| 1020 |
skills = [skill.strip() for skill in skills_input.split(',') if skill.strip()]
|
| 1021 |
-
|
| 1022 |
-
# Create comprehensive user profile
|
| 1023 |
user_profile = UserProfile(
|
| 1024 |
skills=skills,
|
| 1025 |
experience_level=experience_level,
|
| 1026 |
time_available=time_available,
|
| 1027 |
interests=[interests] if interests else []
|
| 1028 |
)
|
| 1029 |
-
|
| 1030 |
-
|
| 1031 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1032 |
insights = intelligence_engine.get_user_insights(user_profile)
|
| 1033 |
-
|
| 1034 |
recommendations = recommendations_data["recommendations"]
|
| 1035 |
insights_data = recommendations_data["insights"]
|
| 1036 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1037 |
# Format results with enhanced styling
|
| 1038 |
if recommendations:
|
| 1039 |
# Success header with data source info
|
|
@@ -1082,10 +1047,16 @@ async def get_ultimate_recommendations_async(skills_input: str, experience_level
|
|
| 1082 |
print(f"β Error processing ULTIMATE request: {str(e)}")
|
| 1083 |
return error_msg, ""
|
| 1084 |
|
| 1085 |
-
def get_ultimate_recommendations_sync(
|
| 1086 |
-
|
| 1087 |
-
|
| 1088 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1089 |
def run_ultimate_performance_test():
|
| 1090 |
"""ULTIMATE comprehensive system performance test"""
|
| 1091 |
results = []
|
|
@@ -1234,69 +1205,101 @@ def create_ultimate_interface():
|
|
| 1234 |
with gr.TabItem("π― ULTIMATE Recommendations", elem_id="ultimate-recommendations"):
|
| 1235 |
gr.Markdown("### π AI-Powered Challenge Discovery with Real MCP Data")
|
| 1236 |
|
|
|
|
|
|
|
| 1237 |
with gr.Row():
|
| 1238 |
with gr.Column(scale=1):
|
| 1239 |
-
gr.Markdown("**π€ Tell the AI about yourself:**")
|
| 1240 |
-
|
| 1241 |
skills_input = gr.Textbox(
|
| 1242 |
label="π οΈ Your Skills & Technologies",
|
| 1243 |
placeholder="Python, React, JavaScript, AWS, Docker, Blockchain, UI/UX...",
|
| 1244 |
-
info="Enter your skills separated by commas - the more specific, the better!",
|
| 1245 |
lines=3,
|
| 1246 |
-
value="Python, JavaScript, React"
|
| 1247 |
)
|
| 1248 |
-
|
| 1249 |
experience_level = gr.Dropdown(
|
| 1250 |
choices=["Beginner", "Intermediate", "Advanced"],
|
| 1251 |
label="π Experience Level",
|
| 1252 |
-
value="Intermediate"
|
| 1253 |
-
info="Your overall development and competitive coding experience"
|
| 1254 |
)
|
| 1255 |
-
|
| 1256 |
time_available = gr.Dropdown(
|
| 1257 |
choices=["2-4 hours", "4-8 hours", "8+ hours"],
|
| 1258 |
label="β° Time Available",
|
| 1259 |
-
value="4-8 hours"
|
| 1260 |
-
info="How much time can you dedicate to a challenge?"
|
| 1261 |
)
|
| 1262 |
-
|
| 1263 |
interests = gr.Textbox(
|
| 1264 |
label="π― Current Interests & Goals",
|
| 1265 |
placeholder="web development, blockchain, AI/ML, cloud computing, mobile apps...",
|
| 1266 |
-
info="What type of projects and technologies excite you most?",
|
| 1267 |
lines=3,
|
| 1268 |
-
value="web development, cloud computing"
|
| 1269 |
)
|
| 1270 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1271 |
ultimate_recommend_btn = gr.Button(
|
| 1272 |
"π Get My ULTIMATE Recommendations",
|
| 1273 |
variant="primary",
|
| 1274 |
size="lg",
|
| 1275 |
elem_classes="ultimate-btn"
|
| 1276 |
)
|
| 1277 |
-
|
| 1278 |
-
|
| 1279 |
-
|
| 1280 |
-
- **Be specific**: Include frameworks, libraries, and tools you know
|
| 1281 |
-
- **Mention experience**: Add years of experience with key technologies
|
| 1282 |
-
- **State goals**: Career objectives help fine-tune recommendations
|
| 1283 |
-
- **Real data**: You'll get actual Topcoder challenges with real prizes!
|
| 1284 |
-
""")
|
| 1285 |
-
|
| 1286 |
with gr.Column(scale=2):
|
| 1287 |
-
ultimate_insights_output = gr.HTML(
|
| 1288 |
-
|
| 1289 |
-
|
| 1290 |
-
|
| 1291 |
-
ultimate_recommendations_output = gr.HTML(
|
| 1292 |
-
label="π Your ULTIMATE Recommendations",
|
| 1293 |
-
visible=True
|
| 1294 |
-
)
|
| 1295 |
-
|
| 1296 |
-
# Connect the ULTIMATE recommendation system
|
| 1297 |
ultimate_recommend_btn.click(
|
| 1298 |
get_ultimate_recommendations_sync,
|
| 1299 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1300 |
outputs=[ultimate_recommendations_output, ultimate_insights_output]
|
| 1301 |
)
|
| 1302 |
|
|
|
|
| 35 |
|
| 36 |
class UltimateTopcoderMCPEngine:
|
| 37 |
"""ULTIMATE MCP Engine - Real Data + Advanced Intelligence"""
|
| 38 |
+
|
| 39 |
def __init__(self):
|
| 40 |
print("π Initializing ULTIMATE Topcoder Intelligence Engine...")
|
| 41 |
self.base_url = "https://api.topcoder-dev.com/v6/mcp"
|
|
|
|
| 43 |
self.is_connected = False
|
| 44 |
self.mock_challenges = self._create_enhanced_fallback_challenges()
|
| 45 |
print(f"β
Loaded fallback system with {len(self.mock_challenges)} premium challenges")
|
| 46 |
+
|
| 47 |
def _create_enhanced_fallback_challenges(self) -> List[Challenge]:
|
|
|
|
| 48 |
return [
|
| 49 |
Challenge(
|
| 50 |
id="30174840",
|
|
|
|
| 107 |
registrants=24
|
| 108 |
)
|
| 109 |
]
|
| 110 |
+
|
| 111 |
def parse_sse_response(self, sse_text: str) -> Dict[str, Any]:
|
|
|
|
| 112 |
lines = sse_text.strip().split('\n')
|
| 113 |
for line in lines:
|
| 114 |
line = line.strip()
|
|
|
|
| 119 |
except json.JSONDecodeError:
|
| 120 |
pass
|
| 121 |
return None
|
| 122 |
+
|
| 123 |
async def initialize_connection(self) -> bool:
|
|
|
|
|
|
|
| 124 |
if self.is_connected:
|
| 125 |
return True
|
| 126 |
+
|
| 127 |
headers = {
|
| 128 |
"Accept": "application/json, text/event-stream, */*",
|
| 129 |
"Accept-Language": "en-US,en;q=0.9",
|
|
|
|
| 133 |
"Referer": "https://modelcontextprotocol.io/",
|
| 134 |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
|
| 135 |
}
|
| 136 |
+
|
| 137 |
init_request = {
|
| 138 |
"jsonrpc": "2.0",
|
| 139 |
"id": 0,
|
|
|
|
| 151 |
}
|
| 152 |
}
|
| 153 |
}
|
| 154 |
+
|
| 155 |
try:
|
| 156 |
async with httpx.AsyncClient(timeout=10.0) as client:
|
| 157 |
response = await client.post(
|
|
|
|
| 159 |
json=init_request,
|
| 160 |
headers=headers
|
| 161 |
)
|
| 162 |
+
|
| 163 |
if response.status_code == 200:
|
| 164 |
response_headers = dict(response.headers)
|
| 165 |
if 'mcp-session-id' in response_headers:
|
|
|
|
| 167 |
self.is_connected = True
|
| 168 |
print(f"β
Real MCP connection established: {self.session_id[:8]}...")
|
| 169 |
return True
|
| 170 |
+
|
| 171 |
except Exception as e:
|
| 172 |
print(f"β οΈ MCP connection failed, using enhanced fallback: {e}")
|
| 173 |
+
|
| 174 |
return False
|
| 175 |
+
|
| 176 |
async def call_tool(self, tool_name: str, arguments: Dict[str, Any]) -> Optional[Dict]:
|
|
|
|
|
|
|
| 177 |
if not self.session_id:
|
| 178 |
return None
|
| 179 |
+
|
| 180 |
headers = {
|
| 181 |
"Accept": "application/json, text/event-stream, */*",
|
| 182 |
"Content-Type": "application/json",
|
| 183 |
"Origin": "https://modelcontextprotocol.io",
|
| 184 |
"mcp-session-id": self.session_id
|
| 185 |
}
|
| 186 |
+
|
| 187 |
tool_request = {
|
| 188 |
"jsonrpc": "2.0",
|
| 189 |
"id": int(datetime.now().timestamp()),
|
|
|
|
| 193 |
"arguments": arguments
|
| 194 |
}
|
| 195 |
}
|
| 196 |
+
|
| 197 |
try:
|
| 198 |
async with httpx.AsyncClient(timeout=30.0) as client:
|
| 199 |
response = await client.post(
|
|
|
|
| 201 |
json=tool_request,
|
| 202 |
headers=headers
|
| 203 |
)
|
| 204 |
+
|
| 205 |
if response.status_code == 200:
|
| 206 |
if "text/event-stream" in response.headers.get("content-type", ""):
|
| 207 |
sse_data = self.parse_sse_response(response.text)
|
|
|
|
| 211 |
json_data = response.json()
|
| 212 |
if "result" in json_data:
|
| 213 |
return json_data["result"]
|
| 214 |
+
|
| 215 |
except Exception:
|
| 216 |
pass
|
| 217 |
+
|
| 218 |
return None
|
| 219 |
+
|
| 220 |
def convert_topcoder_challenge(self, tc_data: Dict) -> Challenge:
|
|
|
|
|
|
|
|
|
|
| 221 |
challenge_id = str(tc_data.get('id', 'unknown'))
|
| 222 |
title = tc_data.get('name', 'Topcoder Challenge')
|
| 223 |
description = tc_data.get('description', 'Challenge description not available')
|
| 224 |
+
|
|
|
|
| 225 |
technologies = []
|
| 226 |
skills = tc_data.get('skills', [])
|
| 227 |
for skill in skills:
|
| 228 |
if isinstance(skill, dict) and 'name' in skill:
|
| 229 |
technologies.append(skill['name'])
|
| 230 |
+
|
|
|
|
| 231 |
if 'technologies' in tc_data:
|
| 232 |
tech_list = tc_data['technologies']
|
| 233 |
if isinstance(tech_list, list):
|
|
|
|
| 236 |
technologies.append(tech['name'])
|
| 237 |
elif isinstance(tech, str):
|
| 238 |
technologies.append(tech)
|
| 239 |
+
|
|
|
|
| 240 |
total_prize = 0
|
| 241 |
prize_sets = tc_data.get('prizeSets', [])
|
| 242 |
for prize_set in prize_sets:
|
|
|
|
| 245 |
for prize in prizes:
|
| 246 |
if prize.get('type') == 'USD':
|
| 247 |
total_prize += prize.get('value', 0)
|
| 248 |
+
|
| 249 |
prize = f"${total_prize:,}" if total_prize > 0 else "Merit-based"
|
| 250 |
+
|
|
|
|
| 251 |
challenge_type = tc_data.get('type', 'Unknown')
|
|
|
|
| 252 |
difficulty_mapping = {
|
| 253 |
'First2Finish': 'Beginner',
|
| 254 |
'Code': 'Intermediate',
|
|
|
|
| 258 |
'Bug Hunt': 'Beginner',
|
| 259 |
'Test Suites': 'Intermediate'
|
| 260 |
}
|
|
|
|
| 261 |
difficulty = difficulty_mapping.get(challenge_type, 'Intermediate')
|
| 262 |
+
|
|
|
|
| 263 |
time_estimate = "Variable duration"
|
| 264 |
registrants = tc_data.get('numOfRegistrants', 0)
|
|
|
|
| 265 |
status = tc_data.get('status', '')
|
| 266 |
if status == 'Completed':
|
| 267 |
time_estimate = "Recently completed"
|
| 268 |
elif status in ['Active', 'Draft']:
|
| 269 |
time_estimate = "Active challenge"
|
| 270 |
+
|
| 271 |
return Challenge(
|
| 272 |
id=challenge_id,
|
| 273 |
title=title,
|
|
|
|
| 278 |
time_estimate=time_estimate,
|
| 279 |
registrants=registrants
|
| 280 |
)
|
| 281 |
+
|
| 282 |
+
def extract_technologies_from_query(self, query: str) -> List[str]:
|
| 283 |
+
tech_keywords = {
|
| 284 |
+
'python', 'java', 'javascript', 'react', 'node', 'angular', 'vue',
|
| 285 |
+
'aws', 'docker', 'kubernetes', 'api', 'rest', 'graphql', 'sql',
|
| 286 |
+
'mongodb', 'postgresql', 'machine learning', 'ai', 'blockchain',
|
| 287 |
+
'ios', 'android', 'flutter', 'swift', 'kotlin', 'c++', 'c#',
|
| 288 |
+
'ruby', 'php', 'go', 'rust', 'typescript', 'html', 'css',
|
| 289 |
+
'nft', 'non-fungible tokens', 'ethereum', 'smart contracts', 'solidity',
|
| 290 |
+
'figma', 'ui/ux', 'design', 'testing', 'jest', 'hardhat', 'web3',
|
| 291 |
+
'fastapi', 'django', 'flask', 'redis', 'tensorflow', 'd3.js', 'chart.js'
|
| 292 |
+
}
|
| 293 |
+
query_lower = query.lower()
|
| 294 |
+
found_techs = [tech for tech in tech_keywords if tech in query_lower]
|
| 295 |
+
return found_techs
|
| 296 |
+
|
| 297 |
+
async def fetch_real_challenges(
|
| 298 |
+
self,
|
| 299 |
+
user_profile: UserProfile,
|
| 300 |
+
query: str,
|
| 301 |
+
limit: int = 30,
|
| 302 |
+
status: str = None,
|
| 303 |
+
prize_min: int = None,
|
| 304 |
+
prize_max: int = None,
|
| 305 |
+
challenge_type: str = None,
|
| 306 |
+
track: str = None,
|
| 307 |
+
sort_by: str = None,
|
| 308 |
+
sort_order: str = None,
|
| 309 |
+
) -> List[Challenge]:
|
| 310 |
if not await self.initialize_connection():
|
| 311 |
return []
|
| 312 |
+
|
| 313 |
+
skill_keywords = self.extract_technologies_from_query(
|
| 314 |
+
query + " " + " ".join(user_profile.skills + user_profile.interests)
|
| 315 |
+
)
|
| 316 |
+
|
| 317 |
+
mcp_query = {
|
| 318 |
+
"perPage": limit,
|
| 319 |
+
}
|
| 320 |
+
mcp_query["status"] = status if status else "Active"
|
| 321 |
+
if prize_min is not None:
|
| 322 |
+
mcp_query["totalPrizesFrom"] = prize_min
|
| 323 |
+
if prize_max is not None:
|
| 324 |
+
mcp_query["totalPrizesTo"] = prize_max
|
| 325 |
+
if challenge_type:
|
| 326 |
+
mcp_query["type"] = challenge_type
|
| 327 |
+
if track:
|
| 328 |
+
mcp_query["track"] = track
|
| 329 |
+
if skill_keywords:
|
| 330 |
+
mcp_query["tags"] = skill_keywords
|
| 331 |
+
if query.strip():
|
| 332 |
+
mcp_query["search"] = query.strip()
|
| 333 |
+
mcp_query["sortBy"] = sort_by if sort_by else "overview.totalPrizes"
|
| 334 |
+
mcp_query["sortOrder"] = sort_order if sort_order else "desc"
|
| 335 |
+
|
| 336 |
+
result = await self.call_tool("query-tc-challenges", mcp_query)
|
| 337 |
if not result:
|
| 338 |
return []
|
| 339 |
+
|
|
|
|
| 340 |
challenge_data_list = []
|
|
|
|
|
|
|
| 341 |
if "structuredContent" in result:
|
| 342 |
structured = result["structuredContent"]
|
| 343 |
if isinstance(structured, dict) and "data" in structured:
|
| 344 |
challenge_data_list = structured["data"]
|
| 345 |
+
elif "data" in result:
|
| 346 |
+
challenge_data_list = result["data"]
|
|
|
|
| 347 |
elif "content" in result and len(result["content"]) > 0:
|
| 348 |
content_item = result["content"][0]
|
| 349 |
if isinstance(content_item, dict) and content_item.get("type") == "text":
|
|
|
|
| 352 |
parsed_data = json.loads(text_content)
|
| 353 |
if "data" in parsed_data:
|
| 354 |
challenge_data_list = parsed_data["data"]
|
|
|
|
| 355 |
except json.JSONDecodeError:
|
| 356 |
pass
|
| 357 |
+
|
|
|
|
| 358 |
challenges = []
|
| 359 |
for item in challenge_data_list:
|
| 360 |
if isinstance(item, dict):
|
|
|
|
| 364 |
except Exception as e:
|
| 365 |
print(f"Error converting challenge: {e}")
|
| 366 |
continue
|
| 367 |
+
|
| 368 |
return challenges
|
| 369 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
def calculate_advanced_compatibility_score(self, challenge: Challenge, user_profile: UserProfile, query: str) -> tuple:
|
|
|
|
|
|
|
| 371 |
score = 0.0
|
| 372 |
factors = []
|
|
|
|
|
|
|
| 373 |
user_skills_lower = [skill.lower().strip() for skill in user_profile.skills]
|
| 374 |
challenge_techs_lower = [tech.lower() for tech in challenge.technologies]
|
|
|
|
|
|
|
| 375 |
skill_matches = len(set(user_skills_lower) & set(challenge_techs_lower))
|
|
|
|
| 376 |
if len(challenge.technologies) > 0:
|
|
|
|
| 377 |
exact_match_score = (skill_matches / len(challenge.technologies)) * 30
|
|
|
|
| 378 |
coverage_bonus = min(skill_matches * 10, 10)
|
| 379 |
skill_score = exact_match_score + coverage_bonus
|
| 380 |
else:
|
| 381 |
+
skill_score = 30
|
|
|
|
| 382 |
score += skill_score
|
|
|
|
| 383 |
if skill_matches > 0:
|
| 384 |
matched_skills = [t for t in challenge.technologies if t.lower() in user_skills_lower]
|
| 385 |
factors.append(f"Strong match: uses your {', '.join(matched_skills[:2])} expertise")
|
|
|
|
| 387 |
factors.append(f"Growth opportunity: learn {', '.join(challenge.technologies[:2])}")
|
| 388 |
else:
|
| 389 |
factors.append("Versatile challenge suitable for multiple skill levels")
|
|
|
|
|
|
|
| 390 |
level_mapping = {'beginner': 1, 'intermediate': 2, 'advanced': 3}
|
| 391 |
user_level_num = level_mapping.get(user_profile.experience_level.lower(), 2)
|
| 392 |
challenge_level_num = level_mapping.get(challenge.difficulty.lower(), 2)
|
|
|
|
| 393 |
level_diff = abs(user_level_num - challenge_level_num)
|
| 394 |
if level_diff == 0:
|
| 395 |
level_score = 30
|
|
|
|
| 400 |
else:
|
| 401 |
level_score = 5
|
| 402 |
factors.append("Stretch challenge with significant learning curve")
|
|
|
|
| 403 |
score += level_score
|
|
|
|
|
|
|
| 404 |
query_techs = self.extract_technologies_from_query(query)
|
| 405 |
if query_techs:
|
| 406 |
query_matches = len(set([tech.lower() for tech in query_techs]) & set(challenge_techs_lower))
|
|
|
|
| 408 |
query_score = min(query_matches / len(query_techs), 1.0) * 20
|
| 409 |
else:
|
| 410 |
query_score = 10
|
|
|
|
| 411 |
if query_matches > 0:
|
| 412 |
factors.append(f"Directly matches your interest in {', '.join(query_techs[:2])}")
|
| 413 |
else:
|
| 414 |
query_score = 10
|
|
|
|
| 415 |
score += query_score
|
|
|
|
|
|
|
| 416 |
try:
|
|
|
|
| 417 |
prize_numeric = 0
|
| 418 |
if challenge.prize.startswith('$'):
|
| 419 |
prize_str = challenge.prize[1:].replace(',', '')
|
| 420 |
prize_numeric = int(prize_str) if prize_str.isdigit() else 0
|
| 421 |
+
prize_score = min(prize_numeric / 1000 * 2, 8)
|
|
|
|
| 422 |
competition_bonus = 2 if 20 <= challenge.registrants <= 50 else 0
|
| 423 |
market_score = prize_score + competition_bonus
|
| 424 |
except:
|
| 425 |
+
market_score = 5
|
|
|
|
| 426 |
score += market_score
|
|
|
|
| 427 |
return min(score, 100.0), factors
|
| 428 |
+
|
| 429 |
def get_user_insights(self, user_profile: UserProfile) -> Dict:
|
|
|
|
| 430 |
skills = user_profile.skills
|
| 431 |
level = user_profile.experience_level
|
| 432 |
time_available = user_profile.time_available
|
|
|
|
|
|
|
| 433 |
frontend_skills = ['react', 'javascript', 'css', 'html', 'vue', 'angular', 'typescript']
|
| 434 |
backend_skills = ['python', 'java', 'node', 'fastapi', 'django', 'flask', 'php', 'ruby']
|
| 435 |
data_skills = ['sql', 'postgresql', 'mongodb', 'redis', 'elasticsearch', 'tensorflow']
|
| 436 |
devops_skills = ['docker', 'kubernetes', 'aws', 'azure', 'terraform', 'jenkins']
|
| 437 |
design_skills = ['figma', 'ui/ux', 'design', 'prototyping', 'accessibility']
|
| 438 |
blockchain_skills = ['solidity', 'web3', 'ethereum', 'blockchain', 'smart contracts', 'nft']
|
|
|
|
| 439 |
user_skills_lower = [skill.lower() for skill in skills]
|
|
|
|
|
|
|
| 440 |
frontend_count = sum(1 for skill in user_skills_lower if any(fs in skill for fs in frontend_skills))
|
| 441 |
backend_count = sum(1 for skill in user_skills_lower if any(bs in skill for bs in backend_skills))
|
| 442 |
data_count = sum(1 for skill in user_skills_lower if any(ds in skill for ds in data_skills))
|
| 443 |
devops_count = sum(1 for skill in user_skills_lower if any(ds in skill for ds in devops_skills))
|
| 444 |
design_count = sum(1 for skill in user_skills_lower if any(ds in skill for ds in design_skills))
|
| 445 |
blockchain_count = sum(1 for skill in user_skills_lower if any(bs in skill for bs in blockchain_skills))
|
|
|
|
|
|
|
| 446 |
if blockchain_count >= 2:
|
| 447 |
profile_type = "Blockchain Developer"
|
| 448 |
elif frontend_count >= 2 and backend_count >= 1:
|
|
|
|
| 459 |
profile_type = "DevOps Engineer"
|
| 460 |
else:
|
| 461 |
profile_type = "Versatile Developer"
|
|
|
|
|
|
|
| 462 |
insights = {
|
| 463 |
'profile_type': profile_type,
|
| 464 |
'strengths': f"Strong {profile_type.lower()} with expertise in {', '.join(skills[:3]) if skills else 'multiple technologies'}",
|
|
|
|
| 468 |
'time_optimization': f"With {time_available}, you can complete 1-2 medium challenges or 1 large project",
|
| 469 |
'success_probability': self._calculate_success_probability(level, len(skills))
|
| 470 |
}
|
|
|
|
| 471 |
return insights
|
| 472 |
+
|
| 473 |
def _suggest_growth_areas(self, user_skills: List[str], frontend: int, backend: int, data: int, devops: int, blockchain: int) -> str:
|
|
|
|
| 474 |
suggestions = []
|
|
|
|
| 475 |
if blockchain < 1 and (frontend >= 1 or backend >= 1):
|
| 476 |
suggestions.append("blockchain and Web3 technologies")
|
| 477 |
if devops < 1:
|
|
|
|
| 482 |
suggestions.append("TypeScript for enhanced development")
|
| 483 |
if backend >= 1 and "api" not in str(user_skills):
|
| 484 |
suggestions.append("API design and microservices")
|
|
|
|
| 485 |
if not suggestions:
|
| 486 |
suggestions = ["AI/ML integration", "system design", "performance optimization"]
|
|
|
|
| 487 |
return "Consider exploring " + ", ".join(suggestions[:3])
|
| 488 |
+
|
| 489 |
def _get_market_trends(self, skills: List[str]) -> str:
|
|
|
|
| 490 |
hot_skills = {
|
| 491 |
'react': 'React dominates frontend with 75% job market share',
|
| 492 |
'python': 'Python leads in AI/ML and backend development growth',
|
|
|
|
| 497 |
'ai': 'AI integration skills in highest demand for 2024',
|
| 498 |
'kubernetes': 'Container orchestration critical for enterprise roles'
|
| 499 |
}
|
|
|
|
| 500 |
for skill in skills:
|
| 501 |
skill_lower = skill.lower()
|
| 502 |
for hot_skill, trend in hot_skills.items():
|
| 503 |
if hot_skill in skill_lower:
|
| 504 |
return trend
|
|
|
|
| 505 |
return "Full-stack and cloud skills show strongest market demand"
|
| 506 |
+
|
| 507 |
def _calculate_success_probability(self, level: str, skill_count: int) -> str:
|
|
|
|
| 508 |
base_score = {'beginner': 60, 'intermediate': 75, 'advanced': 85}.get(level.lower(), 70)
|
| 509 |
skill_bonus = min(skill_count * 3, 15)
|
| 510 |
total = base_score + skill_bonus
|
|
|
|
| 511 |
if total >= 90:
|
| 512 |
return f"{total}% - Outstanding success potential"
|
| 513 |
elif total >= 80:
|
|
|
|
| 516 |
return f"{total}% - Good probability of success"
|
| 517 |
else:
|
| 518 |
return f"{total}% - Consider skill development first"
|
| 519 |
+
|
| 520 |
+
async def get_personalized_recommendations(
|
| 521 |
+
self, user_profile: UserProfile, query: str = "",
|
| 522 |
+
status: str = None, prize_min: int = None, prize_max: int = None,
|
| 523 |
+
challenge_type: str = None, track: str = None,
|
| 524 |
+
sort_by: str = None, sort_order: str = None,
|
| 525 |
+
limit: int = 50
|
| 526 |
+
) -> Dict[str, Any]:
|
| 527 |
start_time = datetime.now()
|
| 528 |
print(f"π Analyzing profile: {user_profile.skills} | Level: {user_profile.experience_level}")
|
| 529 |
+
|
| 530 |
+
real_challenges = await self.fetch_real_challenges(
|
| 531 |
+
user_profile=user_profile,
|
| 532 |
+
query=query,
|
| 533 |
+
limit=limit,
|
| 534 |
+
status=status,
|
| 535 |
+
prize_min=prize_min,
|
| 536 |
+
prize_max=prize_max,
|
| 537 |
+
challenge_type=challenge_type,
|
| 538 |
+
track=track,
|
| 539 |
+
sort_by=sort_by,
|
| 540 |
+
sort_order=sort_order,
|
| 541 |
+
)
|
| 542 |
+
|
| 543 |
if real_challenges:
|
| 544 |
challenges = real_challenges
|
| 545 |
data_source = "π₯ REAL Topcoder MCP Server (4,596+ challenges)"
|
| 546 |
print(f"π Using {len(challenges)} REAL Topcoder challenges!")
|
| 547 |
else:
|
|
|
|
| 548 |
challenges = self.mock_challenges
|
| 549 |
data_source = "β¨ Enhanced Intelligence Engine (Premium Dataset)"
|
| 550 |
print(f"β‘ Using {len(challenges)} premium challenges with advanced algorithms")
|
| 551 |
+
|
|
|
|
| 552 |
scored_challenges = []
|
| 553 |
for challenge in challenges:
|
| 554 |
score, factors = self.calculate_advanced_compatibility_score(challenge, user_profile, query)
|
| 555 |
challenge.compatibility_score = score
|
| 556 |
challenge.rationale = f"Match: {score:.0f}%. " + ". ".join(factors[:2]) + "."
|
| 557 |
scored_challenges.append(challenge)
|
|
|
|
|
|
|
| 558 |
scored_challenges.sort(key=lambda x: x.compatibility_score, reverse=True)
|
|
|
|
|
|
|
| 559 |
recommendations = scored_challenges[:5]
|
|
|
|
|
|
|
| 560 |
processing_time = (datetime.now() - start_time).total_seconds()
|
|
|
|
|
|
|
| 561 |
query_techs = self.extract_technologies_from_query(query)
|
| 562 |
avg_score = sum(c.compatibility_score for c in challenges) / len(challenges) if challenges else 0
|
|
|
|
| 563 |
print(f"β
Generated {len(recommendations)} recommendations in {processing_time:.3f}s:")
|
| 564 |
for i, rec in enumerate(recommendations, 1):
|
| 565 |
print(f" {i}. {rec.title} - {rec.compatibility_score:.0f}% compatibility")
|
|
|
|
| 566 |
return {
|
| 567 |
"recommendations": [asdict(rec) for rec in recommendations],
|
| 568 |
"insights": {
|
|
|
|
| 958 |
</div>
|
| 959 |
"""
|
| 960 |
|
| 961 |
+
async def get_ultimate_recommendations_async(
|
| 962 |
+
skills_input: str, experience_level: str, time_available: str, interests: str,
|
| 963 |
+
status: str, prize_min: int, prize_max: int, challenge_type: str, track: str,
|
| 964 |
+
sort_by: str, sort_order: str
|
| 965 |
+
) -> Tuple[str, str]:
|
| 966 |
+
# ...input validation, parsing...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 967 |
skills = [skill.strip() for skill in skills_input.split(',') if skill.strip()]
|
|
|
|
|
|
|
| 968 |
user_profile = UserProfile(
|
| 969 |
skills=skills,
|
| 970 |
experience_level=experience_level,
|
| 971 |
time_available=time_available,
|
| 972 |
interests=[interests] if interests else []
|
| 973 |
)
|
| 974 |
+
# Pass all new filter params to get_personalized_recommendations
|
| 975 |
+
recommendations_data = await intelligence_engine.get_personalized_recommendations(
|
| 976 |
+
user_profile,
|
| 977 |
+
interests,
|
| 978 |
+
status=status,
|
| 979 |
+
prize_min=prize_min,
|
| 980 |
+
prize_max=prize_max,
|
| 981 |
+
challenge_type=challenge_type,
|
| 982 |
+
track=track,
|
| 983 |
+
sort_by=sort_by,
|
| 984 |
+
sort_order=sort_order,
|
| 985 |
+
limit=50
|
| 986 |
+
)
|
| 987 |
insights = intelligence_engine.get_user_insights(user_profile)
|
|
|
|
| 988 |
recommendations = recommendations_data["recommendations"]
|
| 989 |
insights_data = recommendations_data["insights"]
|
| 990 |
+
real_challenges = await intelligence_engine.fetch_real_challenges(
|
| 991 |
+
user_profile=user_profile,
|
| 992 |
+
query=interests,
|
| 993 |
+
limit=50,
|
| 994 |
+
status=status,
|
| 995 |
+
prize_min=prize_min,
|
| 996 |
+
prize_max=prize_max,
|
| 997 |
+
challenge_type=challenge_type,
|
| 998 |
+
track=track,
|
| 999 |
+
sort_by=sort_by,
|
| 1000 |
+
sort_order=sort_order,
|
| 1001 |
+
)
|
| 1002 |
# Format results with enhanced styling
|
| 1003 |
if recommendations:
|
| 1004 |
# Success header with data source info
|
|
|
|
| 1047 |
print(f"β Error processing ULTIMATE request: {str(e)}")
|
| 1048 |
return error_msg, ""
|
| 1049 |
|
| 1050 |
+
def get_ultimate_recommendations_sync(
|
| 1051 |
+
skills_input: str, experience_level: str, time_available: str, interests: str,
|
| 1052 |
+
status: str, prize_min: int, prize_max: int, challenge_type: str, track: str,
|
| 1053 |
+
sort_by: str, sort_order: str
|
| 1054 |
+
) -> Tuple[str, str]:
|
| 1055 |
+
return asyncio.run(get_ultimate_recommendations_async(
|
| 1056 |
+
skills_input, experience_level, time_available, interests,
|
| 1057 |
+
status, prize_min, prize_max, challenge_type, track,
|
| 1058 |
+
sort_by, sort_order
|
| 1059 |
+
))
|
| 1060 |
def run_ultimate_performance_test():
|
| 1061 |
"""ULTIMATE comprehensive system performance test"""
|
| 1062 |
results = []
|
|
|
|
| 1205 |
with gr.TabItem("π― ULTIMATE Recommendations", elem_id="ultimate-recommendations"):
|
| 1206 |
gr.Markdown("### π AI-Powered Challenge Discovery with Real MCP Data")
|
| 1207 |
|
| 1208 |
+
# ... Inside create_ultimate_interface() ...
|
| 1209 |
+
|
| 1210 |
with gr.Row():
|
| 1211 |
with gr.Column(scale=1):
|
| 1212 |
+
gr.Markdown("**π€ Tell the AI about yourself and filter challenges:**")
|
| 1213 |
+
|
| 1214 |
skills_input = gr.Textbox(
|
| 1215 |
label="π οΈ Your Skills & Technologies",
|
| 1216 |
placeholder="Python, React, JavaScript, AWS, Docker, Blockchain, UI/UX...",
|
|
|
|
| 1217 |
lines=3,
|
| 1218 |
+
value="Python, JavaScript, React"
|
| 1219 |
)
|
|
|
|
| 1220 |
experience_level = gr.Dropdown(
|
| 1221 |
choices=["Beginner", "Intermediate", "Advanced"],
|
| 1222 |
label="π Experience Level",
|
| 1223 |
+
value="Intermediate"
|
|
|
|
| 1224 |
)
|
|
|
|
| 1225 |
time_available = gr.Dropdown(
|
| 1226 |
choices=["2-4 hours", "4-8 hours", "8+ hours"],
|
| 1227 |
label="β° Time Available",
|
| 1228 |
+
value="4-8 hours"
|
|
|
|
| 1229 |
)
|
|
|
|
| 1230 |
interests = gr.Textbox(
|
| 1231 |
label="π― Current Interests & Goals",
|
| 1232 |
placeholder="web development, blockchain, AI/ML, cloud computing, mobile apps...",
|
|
|
|
| 1233 |
lines=3,
|
| 1234 |
+
value="web development, cloud computing"
|
| 1235 |
)
|
| 1236 |
+
|
| 1237 |
+
# --- NEW FILTERS BELOW ---
|
| 1238 |
+
status_dropdown = gr.Dropdown(
|
| 1239 |
+
choices=["Active", "Completed", "Draft", "Cancelled"],
|
| 1240 |
+
label="Challenge Status",
|
| 1241 |
+
value="Active"
|
| 1242 |
+
)
|
| 1243 |
+
prize_min = gr.Number(
|
| 1244 |
+
label="Minimum Prize ($)",
|
| 1245 |
+
value=0
|
| 1246 |
+
)
|
| 1247 |
+
prize_max = gr.Number(
|
| 1248 |
+
label="Maximum Prize ($)",
|
| 1249 |
+
value=10000
|
| 1250 |
+
)
|
| 1251 |
+
type_dropdown = gr.Dropdown(
|
| 1252 |
+
choices=["", "Code", "First2Finish", "UI Prototype Competition", "Bug Hunt", "Test Suites"],
|
| 1253 |
+
label="Challenge Type",
|
| 1254 |
+
value=""
|
| 1255 |
+
)
|
| 1256 |
+
track_dropdown = gr.Dropdown(
|
| 1257 |
+
choices=["", "DEVELOPMENT", "DESIGN", "DATA_SCIENCE", "QA"],
|
| 1258 |
+
label="Track",
|
| 1259 |
+
value=""
|
| 1260 |
+
)
|
| 1261 |
+
sort_by_dropdown = gr.Dropdown(
|
| 1262 |
+
choices=[
|
| 1263 |
+
"overview.totalPrizes", "numOfRegistrants", "endDate", "startDate"
|
| 1264 |
+
],
|
| 1265 |
+
label="Sort By",
|
| 1266 |
+
value="overview.totalPrizes"
|
| 1267 |
+
)
|
| 1268 |
+
sort_order_dropdown = gr.Dropdown(
|
| 1269 |
+
choices=["desc", "asc"],
|
| 1270 |
+
label="Sort Order",
|
| 1271 |
+
value="desc"
|
| 1272 |
+
)
|
| 1273 |
+
|
| 1274 |
ultimate_recommend_btn = gr.Button(
|
| 1275 |
"π Get My ULTIMATE Recommendations",
|
| 1276 |
variant="primary",
|
| 1277 |
size="lg",
|
| 1278 |
elem_classes="ultimate-btn"
|
| 1279 |
)
|
| 1280 |
+
|
| 1281 |
+
# ...Tips markdown...
|
| 1282 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1283 |
with gr.Column(scale=2):
|
| 1284 |
+
ultimate_insights_output = gr.HTML(label="π§ Your Intelligence Profile", visible=True)
|
| 1285 |
+
ultimate_recommendations_output = gr.HTML(label="π Your ULTIMATE Recommendations", visible=True)
|
| 1286 |
+
|
| 1287 |
+
# --- Connect the ULTIMATE recommendation system with new inputs ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1288 |
ultimate_recommend_btn.click(
|
| 1289 |
get_ultimate_recommendations_sync,
|
| 1290 |
+
inputs=[
|
| 1291 |
+
skills_input,
|
| 1292 |
+
experience_level,
|
| 1293 |
+
time_available,
|
| 1294 |
+
interests,
|
| 1295 |
+
status_dropdown,
|
| 1296 |
+
prize_min,
|
| 1297 |
+
prize_max,
|
| 1298 |
+
type_dropdown,
|
| 1299 |
+
track_dropdown,
|
| 1300 |
+
sort_by_dropdown,
|
| 1301 |
+
sort_order_dropdown
|
| 1302 |
+
],
|
| 1303 |
outputs=[ultimate_recommendations_output, ultimate_insights_output]
|
| 1304 |
)
|
| 1305 |
|