Upload app.py
Browse files
app.py
CHANGED
|
@@ -265,78 +265,80 @@ class UltimateTopcoderMCPEngine:
|
|
| 265 |
|
| 266 |
return None
|
| 267 |
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
|
|
|
|
|
|
| 299 |
for prize in prizes:
|
| 300 |
if prize.get('type') == 'USD':
|
| 301 |
total_prize += prize.get('value', 0)
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
|
| 341 |
async def fetch_real_challenges(self, limit: int = 30) -> List[Challenge]:
|
| 342 |
"""Fetch real challenges from Topcoder MCP with enhanced error handling"""
|
|
|
|
| 265 |
|
| 266 |
return None
|
| 267 |
|
| 268 |
+
|
| 269 |
+
def convert_topcoder_challenge(self, tc_data: Dict) -> Challenge:
|
| 270 |
+
"""Convert real Topcoder challenge data with enhanced parsing"""
|
| 271 |
+
|
| 272 |
+
# Extract real fields from Topcoder data structure
|
| 273 |
+
challenge_id = str(tc_data.get('id', 'unknown'))
|
| 274 |
+
title = tc_data.get('name', 'Topcoder Challenge')
|
| 275 |
+
description = tc_data.get('description', 'Challenge description not available')
|
| 276 |
+
|
| 277 |
+
# Extract technologies from skills array
|
| 278 |
+
technologies = []
|
| 279 |
+
skills = tc_data.get('skills', [])
|
| 280 |
+
for skill in skills:
|
| 281 |
+
if isinstance(skill, dict) and 'name' in skill:
|
| 282 |
+
technologies.append(skill['name'])
|
| 283 |
+
|
| 284 |
+
# Also check for direct technologies field
|
| 285 |
+
if 'technologies' in tc_data:
|
| 286 |
+
tech_list = tc_data['technologies']
|
| 287 |
+
if isinstance(tech_list, list):
|
| 288 |
+
for tech in tech_list:
|
| 289 |
+
if isinstance(tech, dict) and 'name' in tech:
|
| 290 |
+
technologies.append(tech['name'])
|
| 291 |
+
elif isinstance(tech, str):
|
| 292 |
+
technologies.append(tech)
|
| 293 |
+
|
| 294 |
+
# Calculate total prize from prizeSets
|
| 295 |
+
total_prize = 0
|
| 296 |
+
prize_sets = tc_data.get('prizeSets', [])
|
| 297 |
+
for prize_set in prize_sets:
|
| 298 |
+
if prize_set.get('type') == 'placement':
|
| 299 |
+
prizes = prize_set.get('prizes', [])
|
| 300 |
+
if prizes: # FIXED: Proper indentation here
|
| 301 |
for prize in prizes:
|
| 302 |
if prize.get('type') == 'USD':
|
| 303 |
total_prize += prize.get('value', 0)
|
| 304 |
+
|
| 305 |
+
prize = f"${total_prize:,}" if total_prize > 0 else "Merit-based"
|
| 306 |
+
|
| 307 |
+
# Map challenge type to difficulty
|
| 308 |
+
challenge_type = tc_data.get('type', 'Unknown')
|
| 309 |
+
|
| 310 |
+
difficulty_mapping = {
|
| 311 |
+
'First2Finish': 'Beginner',
|
| 312 |
+
'Code': 'Intermediate',
|
| 313 |
+
'Assembly Competition': 'Advanced',
|
| 314 |
+
'UI Prototype Competition': 'Intermediate',
|
| 315 |
+
'Copilot Posting': 'Beginner',
|
| 316 |
+
'Bug Hunt': 'Beginner',
|
| 317 |
+
'Test Suites': 'Intermediate'
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
difficulty = difficulty_mapping.get(challenge_type, 'Intermediate')
|
| 321 |
+
|
| 322 |
+
# Time estimate and registrants
|
| 323 |
+
time_estimate = "Variable duration"
|
| 324 |
+
registrants = tc_data.get('numOfRegistrants', 0)
|
| 325 |
+
|
| 326 |
+
status = tc_data.get('status', '')
|
| 327 |
+
if status == 'Completed':
|
| 328 |
+
time_estimate = "Recently completed"
|
| 329 |
+
elif status in ['Active', 'Draft']:
|
| 330 |
+
time_estimate = "Active challenge"
|
| 331 |
+
|
| 332 |
+
return Challenge(
|
| 333 |
+
id=challenge_id,
|
| 334 |
+
title=title,
|
| 335 |
+
description=description[:300] + "..." if len(description) > 300 else description,
|
| 336 |
+
technologies=technologies,
|
| 337 |
+
difficulty=difficulty,
|
| 338 |
+
prize=prize,
|
| 339 |
+
time_estimate=time_estimate,
|
| 340 |
+
registrants=registrants
|
| 341 |
+
)
|
| 342 |
|
| 343 |
async def fetch_real_challenges(self, limit: int = 30) -> List[Challenge]:
|
| 344 |
"""Fetch real challenges from Topcoder MCP with enhanced error handling"""
|