pranavkv commited on
Commit
baabed0
Β·
verified Β·
1 Parent(s): 4763db2

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +140 -30
app.py CHANGED
@@ -234,59 +234,159 @@ class UltimateTopcoderMCPEngine:
234
  return None
235
 
236
  def convert_topcoder_challenge(self, tc_data: Dict) -> Challenge:
237
- """Enhanced data conversion from Topcoder MCP response"""
238
  try:
239
- challenge_id = str(tc_data.get('id', 'unknown'))
240
- title = tc_data.get('name', 'Topcoder Challenge')
241
- description = tc_data.get('description', 'Challenge description not available')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
 
 
 
 
 
 
 
 
 
 
 
 
243
  technologies = []
 
 
 
244
  skills = tc_data.get('skills', [])
245
- for skill in skills:
246
- if isinstance(skill, dict) and 'name' in skill:
247
- technologies.append(skill['name'])
248
-
249
- if 'technologies' in tc_data:
250
- tech_list = tc_data['technologies']
251
- if isinstance(tech_list, list):
252
- for tech in tech_list:
253
- if isinstance(tech, dict) and 'name' in tech:
254
- technologies.append(tech['name'])
255
- elif isinstance(tech, str):
256
- technologies.append(tech)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
257
 
 
 
 
 
 
 
258
  total_prize = 0
 
 
259
  prize_sets = tc_data.get('prizeSets', [])
260
- for prize_set in prize_sets:
261
- if prize_set.get('type') == 'placement':
262
- prizes = prize_set.get('prizes', [])
263
- for prize in prizes:
264
- if prize.get('type') == 'USD':
265
- total_prize += prize.get('value', 0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
 
267
  prize = f"${total_prize:,}" if total_prize > 0 else "Merit-based"
 
268
 
269
- challenge_type = tc_data.get('type', 'Unknown')
 
270
  difficulty_mapping = {
271
  'First2Finish': 'Beginner',
272
- 'Code': 'Intermediate',
273
  'Assembly Competition': 'Advanced',
274
  'UI Prototype Competition': 'Intermediate',
275
  'Copilot Posting': 'Beginner',
276
  'Bug Hunt': 'Beginner',
277
- 'Test Suites': 'Intermediate'
 
278
  }
279
  difficulty = difficulty_mapping.get(challenge_type, 'Intermediate')
 
280
 
281
- time_estimate = "Variable duration"
282
- registrants = tc_data.get('numOfRegistrants', 0)
283
- status = tc_data.get('status', '')
 
284
  if status == 'Completed':
285
  time_estimate = "Recently completed"
286
  elif status in ['Active', 'Draft']:
287
  time_estimate = "Active challenge"
 
 
 
288
 
289
- return Challenge(
 
290
  id=challenge_id,
291
  title=title,
292
  description=description[:300] + "..." if len(description) > 300 else description,
@@ -296,9 +396,19 @@ class UltimateTopcoderMCPEngine:
296
  time_estimate=time_estimate,
297
  registrants=registrants
298
  )
 
 
 
 
 
 
 
 
299
 
300
  except Exception as e:
301
- print(f"❌ Error converting challenge: {e}")
 
 
302
  return Challenge(
303
  id=str(tc_data.get('id', 'unknown')),
304
  title=str(tc_data.get('name', 'Challenge')),
 
234
  return None
235
 
236
  def convert_topcoder_challenge(self, tc_data: Dict) -> Challenge:
237
+ """FIXED: Debug what's actually in the MCP challenge data"""
238
  try:
239
+ print(f"\nπŸ” === CONVERTING CHALLENGE DATA ===")
240
+ print(f"πŸ“Š Raw challenge keys: {list(tc_data.keys())}")
241
+
242
+ # Show first few fields for debugging
243
+ for key, value in list(tc_data.items())[:10]: # Show first 10 fields
244
+ if isinstance(value, str):
245
+ print(f" {key}: '{value[:100]}{'...' if len(str(value)) > 100 else ''}'")
246
+ elif isinstance(value, (int, float, bool)):
247
+ print(f" {key}: {value}")
248
+ elif isinstance(value, list):
249
+ print(f" {key}: list with {len(value)} items")
250
+ if len(value) > 0 and isinstance(value[0], dict):
251
+ print(f" First item keys: {list(value[0].keys())}")
252
+ elif isinstance(value, dict):
253
+ print(f" {key}: dict with keys {list(value.keys())}")
254
+ else:
255
+ print(f" {key}: {type(value)}")
256
 
257
+ # Extract basic fields with debugging
258
+ challenge_id = str(tc_data.get('id', tc_data.get('challengeId', 'unknown')))
259
+ print(f"πŸ†” Extracted ID: {challenge_id}")
260
+
261
+ title = tc_data.get('name', tc_data.get('title', tc_data.get('challengeName', 'Topcoder Challenge')))
262
+ print(f"πŸ“ Extracted title: {title}")
263
+
264
+ description = tc_data.get('description', tc_data.get('overview', tc_data.get('summary', 'Challenge description not available')))
265
+ print(f"πŸ“„ Extracted description: {description[:100]}...")
266
+
267
+ # Extract technologies/skills with detailed debugging
268
  technologies = []
269
+ print(f"πŸ”§ Looking for technologies...")
270
+
271
+ # Check skills field
272
  skills = tc_data.get('skills', [])
273
+ print(f" Skills field: {skills}")
274
+ if skills:
275
+ for skill in skills:
276
+ if isinstance(skill, dict):
277
+ skill_name = skill.get('name', skill.get('skillName', ''))
278
+ if skill_name:
279
+ technologies.append(skill_name)
280
+ print(f" Added skill: {skill_name}")
281
+ elif isinstance(skill, str):
282
+ technologies.append(skill)
283
+ print(f" Added skill: {skill}")
284
+
285
+ # Check technologies field
286
+ tech_field = tc_data.get('technologies', [])
287
+ print(f" Technologies field: {tech_field}")
288
+ if tech_field:
289
+ for tech in tech_field:
290
+ if isinstance(tech, dict):
291
+ tech_name = tech.get('name', tech.get('technologyName', ''))
292
+ if tech_name:
293
+ technologies.append(tech_name)
294
+ print(f" Added tech: {tech_name}")
295
+ elif isinstance(tech, str):
296
+ technologies.append(tech)
297
+ print(f" Added tech: {tech}")
298
+
299
+ # Check tags field
300
+ tags = tc_data.get('tags', [])
301
+ print(f" Tags field: {tags}")
302
+ if tags:
303
+ for tag in tags[:3]: # Limit to 3 tags
304
+ if isinstance(tag, str):
305
+ technologies.append(tag)
306
+ print(f" Added tag: {tag}")
307
+
308
+ # If no technologies found, try other fields
309
+ if not technologies:
310
+ print(f" No technologies found, checking other fields...")
311
+ track = tc_data.get('track', tc_data.get('trackName', ''))
312
+ if track:
313
+ technologies.append(track)
314
+ print(f" Added track: {track}")
315
+
316
+ challenge_type = tc_data.get('type', tc_data.get('challengeType', ''))
317
+ if challenge_type:
318
+ technologies.append(challenge_type)
319
+ print(f" Added type: {challenge_type}")
320
 
321
+ # Remove duplicates
322
+ technologies = list(set(technologies))
323
+ print(f"πŸ› οΈ Final technologies: {technologies}")
324
+
325
+ # Extract prize information with debugging
326
+ print(f"πŸ’° Looking for prize information...")
327
  total_prize = 0
328
+
329
+ # Check prizeSets
330
  prize_sets = tc_data.get('prizeSets', [])
331
+ print(f" Prize sets: {prize_sets}")
332
+ if prize_sets:
333
+ for prize_set in prize_sets:
334
+ if isinstance(prize_set, dict) and prize_set.get('type') == 'placement':
335
+ prizes = prize_set.get('prizes', [])
336
+ for prize in prizes:
337
+ if isinstance(prize, dict) and prize.get('type') == 'USD':
338
+ prize_value = prize.get('value', 0)
339
+ total_prize += prize_value
340
+ print(f" Added prize: ${prize_value}")
341
+
342
+ # Check overview field
343
+ if total_prize == 0:
344
+ overview = tc_data.get('overview', {})
345
+ if isinstance(overview, dict):
346
+ overview_prize = overview.get('totalPrizes', 0)
347
+ if overview_prize:
348
+ total_prize = overview_prize
349
+ print(f" Found overview prize: ${total_prize}")
350
+
351
+ # Check direct prize field
352
+ if total_prize == 0:
353
+ direct_prize = tc_data.get('prize', tc_data.get('totalPrize', 0))
354
+ if direct_prize:
355
+ total_prize = direct_prize
356
+ print(f" Found direct prize: ${total_prize}")
357
 
358
  prize = f"${total_prize:,}" if total_prize > 0 else "Merit-based"
359
+ print(f"πŸ’° Final prize: {prize}")
360
 
361
+ # Extract other fields
362
+ challenge_type = tc_data.get('type', tc_data.get('challengeType', 'Challenge'))
363
  difficulty_mapping = {
364
  'First2Finish': 'Beginner',
365
+ 'Code': 'Intermediate',
366
  'Assembly Competition': 'Advanced',
367
  'UI Prototype Competition': 'Intermediate',
368
  'Copilot Posting': 'Beginner',
369
  'Bug Hunt': 'Beginner',
370
+ 'Test Suites': 'Intermediate',
371
+ 'Challenge': 'Intermediate'
372
  }
373
  difficulty = difficulty_mapping.get(challenge_type, 'Intermediate')
374
+ print(f"πŸ“Š Difficulty: {difficulty} (from type: {challenge_type})")
375
 
376
+ registrants = tc_data.get('numOfRegistrants', tc_data.get('registrants', 0))
377
+ print(f"πŸ‘₯ Registrants: {registrants}")
378
+
379
+ status = tc_data.get('status', 'Unknown')
380
  if status == 'Completed':
381
  time_estimate = "Recently completed"
382
  elif status in ['Active', 'Draft']:
383
  time_estimate = "Active challenge"
384
+ else:
385
+ time_estimate = "Variable duration"
386
+ print(f"⏰ Time estimate: {time_estimate} (from status: {status})")
387
 
388
+ # Create challenge object
389
+ challenge = Challenge(
390
  id=challenge_id,
391
  title=title,
392
  description=description[:300] + "..." if len(description) > 300 else description,
 
396
  time_estimate=time_estimate,
397
  registrants=registrants
398
  )
399
+
400
+ print(f"βœ… Created challenge: {challenge.title}")
401
+ print(f" Technologies: {challenge.technologies}")
402
+ print(f" Prize: {challenge.prize}")
403
+ print(f" Registrants: {challenge.registrants}")
404
+ print(f"πŸ” === CHALLENGE CONVERSION COMPLETE ===\n")
405
+
406
+ return challenge
407
 
408
  except Exception as e:
409
+ print(f"❌ Error converting challenge data: {e}")
410
+ print(f"Raw data keys: {list(tc_data.keys()) if isinstance(tc_data, dict) else 'Not a dict'}")
411
+ # Return a basic challenge object as fallback
412
  return Challenge(
413
  id=str(tc_data.get('id', 'unknown')),
414
  title=str(tc_data.get('name', 'Challenge')),