pranavkv commited on
Commit
4386ef2
·
verified ·
1 Parent(s): eb9e3c2

Upload app.py

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