Upload app.py
Browse files233 unmodified lines2342352362372372382392402412392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722452462472482492502512522532542552562732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313322602612622632642653333343353363373383393403413423433443453463473483493503513523533543553563573583593602693613623633642723653663673683692773703713723733743752812822833763773783793803813823833843853863872893883893903913923 unmodified lines396397398399400401402403404405406407408301409410411412413414233 unmodified lines return None
def convert_topcoder_challenge(self, tc_data: Dict) -> Challenge:
"""Enhanced data conversion from Topcoder MCP response"""
"""FIXED: Debug what's actually in the MCP challenge data"""
try:
challenge_id = str(tc_data.get('id', 'unknown'))
title = tc_data.get('name', 'Topcoder Challenge')
description = tc_data.get('description', 'Challenge description not available')
print(f"\nπ === CONVERTING CHALLENGE DATA ===")
print(f"π Raw challenge keys: {list(tc_data.keys())}")
# Show first few fields for debugging
for key, value in list(tc_data.items())[:10]: # Show first 10 fields
if isinstance(value, str):
print(f" {key}: '{value[:100]}{'...' if len(str(value)) > 100 else ''}'")
elif isinstance(value, (int, float, bool)):
print(f" {key}: {value}")
elif isinstance(value, list):
print(f" {key}: list with {len(value)} items")
if len(value) > 0 and isinstance(value[0], dict):
print(f" First item keys: {list(value[0].keys())}")
elif isinstance(value, dict):
print(f" {key}: dict with keys {list(value.keys())}")
else:
print(f" {key}: {type(value)}")
# Extract basic fields with debugging
challenge_id = str(tc_data.get('id', tc_data.get('challengeId', 'unknown')))
print(f"π Extracted ID: {challenge_id}")
title = tc_data.get('name', tc_data.get('title', tc_data.get('challengeName', 'Topcoder Challenge')))
print(f"π Extracted title: {title}")
description = tc_data.get('description', tc_data.get('overview', tc_data.get('summary', 'Challenge description not available')))
print(f"π Extracted description: {description[:100]}...")
# Extract technologies/skills with detailed debugging
technologies = []
print(f"π§ Looking for technologies...")
# Check skills field
skills = tc_data.get('skills', [])
for skill in skills:
if isinstance(skill, dict) and 'name' in skill:
technologies.append(skill['name'])
if 'technologies' in tc_data:
tech_list = tc_data['technologies']
if isinstance(tech_list, list):
for tech in tech_list:
if isinstance(tech, dict) and 'name' in tech:
technologies.append(tech['name'])
elif isinstance(tech, str):
technologies.append(tech)
print(f" Skills field: {skills}")
if skills:
for skill in skills:
if isinstance(skill, dict):
skill_name = skill.get('name', skill.get('skillName', ''))
if skill_name:
technologies.append(skill_name)
print(f" Added skill: {skill_name}")
elif isinstance(skill, str):
technologies.append(skill)
print(f" Added skill: {skill}")
# Check technologies field
tech_field = tc_data.get('technologies', [])
print(f" Technologies field: {tech_field}")
if tech_field:
for tech in tech_field:
if isinstance(tech, dict):
tech_name = tech.get('name', tech.get('technologyName', ''))
if tech_name:
technologies.append(tech_name)
print(f" Added tech: {tech_name}")
elif isinstance(tech, str):
technologies.append(tech)
print(f" Added tech: {tech}")
# Check tags field
tags = tc_data.get('tags', [])
print(f" Tags field: {tags}")
if tags:
for tag in tags[:3]: # Limit to 3 tags
if isinstance(tag, str):
technologies.append(tag)
print(f" Added tag: {tag}")
# If no technologies found, try other fields
if not technologies:
print(f" No technologies found, checking other fields...")
track = tc_data.get('track', tc_data.get('trackName', ''))
if track:
technologies.append(track)
print(f" Added track: {track}")
challenge_type = tc_data.get('type', tc_data.get('challengeType', ''))
if challenge_type:
technologies.append(challenge_type)
print(f" Added type: {challenge_type}")
# Remove duplicates
technologies = list(set(technologies))
print(f"π οΈ Final technologies: {technologies}")
# Extract prize information with debugging
print(f"π° Looking for prize information...")
total_prize = 0
# Check prizeSets
prize_sets = tc_data.get('prizeSets', [])
print(f" Prize sets: {prize_sets}")
if prize_sets:
for prize_set in prize_sets:
if prize_set.get('type') == 'placement':
prizes = prize_set.get('prizes', [])
for prize in prizes:
if prize.get('type') == 'USD':
total_prize += prize.get('value', 0)
for prize_set in prize_sets:
if isinstance(prize_set, dict) and prize_set.get('type') == 'placement':
prizes = prize_set.get('prizes', [])
for prize in prizes:
if isinstance(prize, dict) and prize.get('type') == 'USD':
prize_value = prize.get('value', 0)
total_prize += prize_value
print(f" Added prize: ${prize_value}")
# Check overview field
if total_prize == 0:
overview = tc_data.get('overview', {})
if isinstance(overview, dict):
overview_prize = overview.get('totalPrizes', 0)
if overview_prize:
total_prize = overview_prize
print(f" Found overview prize: ${total_prize}")
# Check direct prize field
if total_prize == 0:
direct_prize = tc_data.get('prize', tc_data.get('totalPrize', 0))
if direct_prize:
total_prize = direct_prize
print(f" Found direct prize: ${total_prize}")
prize = f"${total_prize:,}" if total_prize > 0 else "Merit-based"
print(f"π° Final prize: {prize}")
challenge_type = tc_data.get('type', 'Unknown')
# Extract other fields
challenge_type = tc_data.get('type', tc_data.get('challengeType', 'Challenge'))
difficulty_mapping = {
'First2Finish': 'Beginner',
'Code': 'Intermediate',
'Code': 'Intermediate',
'Assembly Competition': 'Advanced',
'UI Prototype Competition': 'Intermediate',
'Copilot Posting': 'Beginner',
'Bug Hunt': 'Beginner',
'Test Suites': 'Intermediate'
'Test Suites': 'Intermediate',
'Challenge': 'Intermediate'
}
difficulty = difficulty_mapping.get(challenge_type, 'Intermediate')
print(f"π Difficulty: {difficulty} (from type: {challenge_type})")
time_estimate = "Variable duration"
registrants = tc_data.get('numOfRegistrants', 0)
status = tc_data.get('status', '')
registrants = tc_data.get('numOfRegistrants', tc_data.get('registrants', 0))
print(f"π₯ Registrants: {registrants}")
status = tc_data.get('status', 'Unknown')
if status == 'Completed':
time_estimate = "Recently completed"
elif status in ['Active', 'Draft']:
time_estimate = "Active challenge"
else:
time_estimate = "Variable duration"
print(f"β° Time estimate: {time_estimate} (from status: {status})")
return Challenge(
# Create challenge object
challenge = Challenge(
id=challenge_id,
title=title,
description=description[:300] + "..." if len(description) > 300 else description,3 unmodified lines time_estimate=time_estimate,
registrants=registrants
)
print(f"β
Created challenge: {challenge.title}")
print(f" Technologies: {challenge.technologies}")
print(f" Prize: {challenge.prize}")
print(f" Registrants: {challenge.registrants}")
print(f"π === CHALLENGE CONVERSION COMPLETE ===\n")
return challenge
except Exception as e:
print(f"β Error converting challenge: {e}")
print(f"β Error converting challenge data: {e}")
print(f"Raw data keys: {list(tc_data.keys()) if isinstance(tc_data, dict) else 'Not a dict'}")
# Return a basic challenge object as fallback
return Challenge(
id=str(tc_data.get('id', 'unknown')),
title=str(tc_data.get('name', 'Challenge')),app.py+140-30