Upload app.py
Browse files233 unmodified lines2342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912923 unmodified lines296297298299300301302303304233 unmodified linesreturn Nonedef convert_topcoder_challenge(self, tc_data: Dict) -> Challenge:"""Enhanced data conversion from Topcoder MCP response"""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')technologies = []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)total_prize = 0prize_sets = tc_data.get('prizeSets', [])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)prize = f"${total_prize:,}" if total_prize > 0 else "Merit-based"challenge_type = tc_data.get('type', 'Unknown')difficulty_mapping = {'First2Finish': 'Beginner','Code': 'Intermediate','Assembly Competition': 'Advanced','UI Prototype Competition': 'Intermediate','Copilot Posting': 'Beginner','Bug Hunt': 'Beginner','Test Suites': 'Intermediate'}difficulty = difficulty_mapping.get(challenge_type, 'Intermediate')time_estimate = "Variable duration"registrants = tc_data.get('numOfRegistrants', 0)status = tc_data.get('status', '')if status == 'Completed':time_estimate = "Recently completed"elif status in ['Active', 'Draft']:time_estimate = "Active challenge"return Challenge(id=challenge_id,title=title,description=description[:300] + "..." if len(description) > 300 else description,3 unmodified linestime_estimate=time_estimate,registrants=registrants)except Exception as e:print(f"β Error converting challenge: {e}")return Challenge(id=str(tc_data.get('id', 'unknown')),title=str(tc_data.get('name', 'Challenge')),233 unmodified lines2342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923 unmodified lines396397398399400401402403404405406407408409410411412413414233 unmodified linesreturn Nonedef convert_topcoder_challenge(self, tc_data: Dict) -> Challenge:"""FIXED: Debug what's actually in the MCP challenge data"""try:print(f"\nπ === CONVERTING CHALLENGE DATA ===")print(f"π Raw challenge keys: {list(tc_data.keys())}")# Show first few fields for debuggingfor key, value in list(tc_data.items())[:10]: # Show first 10 fieldsif 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 debuggingchallenge_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 debuggingtechnologies = []print(f"π§ Looking for technologies...")# Check skills fieldskills = tc_data.get('skills', [])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 fieldtech_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 fieldtags = tc_data.get('tags', [])print(f" Tags field: {tags}")if tags:for tag in tags[:3]: # Limit to 3 tagsif isinstance(tag, str):technologies.append(tag)print(f" Added tag: {tag}")# If no technologies found, try other fieldsif 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 duplicatestechnologies = list(set(technologies))print(f"π οΈ Final technologies: {technologies}")# Extract prize information with debuggingprint(f"π° Looking for prize information...")total_prize = 0# Check prizeSetsprize_sets = tc_data.get('prizeSets', [])print(f" Prize sets: {prize_sets}")if prize_sets: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_valueprint(f" Added prize: ${prize_value}")# Check overview fieldif total_prize == 0:overview = tc_data.get('overview', {})if isinstance(overview, dict):overview_prize = overview.get('totalPrizes', 0)if overview_prize:total_prize = overview_prizeprint(f" Found overview prize: ${total_prize}")# Check direct prize fieldif total_prize == 0:direct_prize = tc_data.get('prize', tc_data.get('totalPrize', 0))if direct_prize:total_prize = direct_prizeprint(f" Found direct prize: ${total_prize}")prize = f"${total_prize:,}" if total_prize > 0 else "Merit-based"print(f"π° Final prize: {prize}")# Extract other fieldschallenge_type = tc_data.get('type', tc_data.get('challengeType', 'Challenge'))difficulty_mapping = {'First2Finish': 'Beginner','Code': 'Intermediate','Assembly Competition': 'Advanced','UI Prototype Competition': 'Intermediate','Copilot Posting': 'Beginner','Bug Hunt': 'Beginner','Test Suites': 'Intermediate','Challenge': 'Intermediate'}difficulty = difficulty_mapping.get(challenge_type, 'Intermediate')print(f"π Difficulty: {difficulty} (from type: {challenge_type})")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})")# Create challenge objectchallenge = Challenge(id=challenge_id,title=title,description=description[:300] + "..." if len(description) > 300 else description,3 unmodified linestime_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 challengeexcept Exception as 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 fallbackreturn Challenge(id=str(tc_data.get('id', 'unknown')),title=str(tc_data.get('name', 'Challenge')),
app.py+140-30