|
4 | 4 | from rich import box |
5 | 5 | from datetime import datetime |
6 | 6 |
|
| 7 | +import typer |
| 8 | + |
7 | 9 | console = Console() |
8 | 10 |
|
9 | 11 | def format_timestamp(timestamp): |
@@ -84,25 +86,71 @@ def create_profile_header(data): |
84 | 86 | title="[bold cyan]LeetCode Profile[/bold cyan]" |
85 | 87 | ) |
86 | 88 |
|
87 | | -def display_problem_stats(data): |
| 89 | +def display_user_stats(data): |
88 | 90 | console.clear() |
89 | 91 | console.print("\n") |
90 | 92 |
|
91 | | - # Display profile header |
92 | | - console.print(create_profile_header(data)) |
93 | | - console.print("\n") |
| 93 | + if not data.get('userProfile'): |
| 94 | + console.print(Panel("Could not fetch user profile", border_style="red")) |
| 95 | + return |
| 96 | + |
| 97 | + user = data['userProfile']['matchedUser'] |
| 98 | + profile = user['profile'] |
| 99 | + |
| 100 | + # Display basic profile info |
| 101 | + profile_table = Table.grid(padding=(0, 2)) |
| 102 | + profile_table.add_column(justify="left") |
94 | 103 |
|
95 | | - # Display recent submissions |
96 | | - recent_submissions = data.get('matchedUser', {}).get('recentSubmissionList', []) |
97 | | - if recent_submissions: |
98 | | - recent_activity = create_recent_activity(recent_submissions) |
99 | | - if recent_activity: |
100 | | - console.print(recent_activity) |
101 | | - else: |
102 | | - console.print(Panel("No recent activity", border_style="cyan")) |
| 104 | + profile_info = [ |
| 105 | + f"[bold cyan]{user['username']}[/bold cyan]", |
| 106 | + f"[dim]Ranking:[/dim] {profile['ranking']}", |
| 107 | + f"[dim]Company:[/dim] {profile['company'] or 'Not specified'}", |
| 108 | + f"[dim]Location:[/dim] {profile['countryName'] or 'Not specified'}" |
| 109 | + ] |
103 | 110 |
|
| 111 | + if profile['skillTags']: |
| 112 | + skills = ", ".join(profile['skillTags']) |
| 113 | + profile_info.append(f"[dim]Skills:[/dim] {skills}") |
| 114 | + |
| 115 | + profile_table.add_row("\n".join(profile_info)) |
| 116 | + console.print(Panel(profile_table, title="[bold cyan]Profile Info[/bold cyan]", border_style="cyan")) |
104 | 117 | console.print("\n") |
105 | 118 |
|
| 119 | + # Display contest info if available |
| 120 | + if data.get('contestInfo') and data['contestInfo'].get('userContestRanking'): |
| 121 | + contest = data['contestInfo']['userContestRanking'] |
| 122 | + contest_table = Table.grid(padding=(0, 2)) |
| 123 | + contest_table.add_column(justify="left") |
| 124 | + contest_table.add_row( |
| 125 | + f"Rating: [yellow]{contest['rating']}[/yellow]\n" |
| 126 | + f"Global Rank: {contest['globalRanking']}/{contest['totalParticipants']}\n" |
| 127 | + f"Top: {contest['topPercentage']}%\n" |
| 128 | + f"Contests: {contest['attendedContestsCount']}" |
| 129 | + ) |
| 130 | + console.print(Panel(contest_table, title="[bold yellow]Contest Stats[/bold yellow]", border_style="yellow")) |
| 131 | + console.print("\n") |
| 132 | + |
| 133 | + # Display progress |
| 134 | + if data.get('progress'): |
| 135 | + progress = data['progress'] |
| 136 | + console.print(create_profile_header(progress)) |
| 137 | + console.print("\n") |
| 138 | + |
| 139 | + # Display language stats |
| 140 | + if data.get('languageStats'): |
| 141 | + lang_stats = data['languageStats']['matchedUser']['languageProblemCount'] |
| 142 | + lang_table = Table(title="Languages", box=box.ROUNDED, border_style="cyan") |
| 143 | + lang_table.add_column("Language", style="cyan") |
| 144 | + lang_table.add_column("Problems Solved", justify="right") |
| 145 | + |
| 146 | + for lang in sorted(lang_stats, key=lambda x: x['problemsSolved'], reverse=True)[:5]: |
| 147 | + lang_table.add_row( |
| 148 | + lang['languageName'], |
| 149 | + str(lang['problemsSolved']) |
| 150 | + ) |
| 151 | + console.print(lang_table) |
| 152 | + console.print("\n") |
| 153 | + |
106 | 154 | def display_problem_list(data): |
107 | 155 | console.clear() |
108 | 156 | console.print("\n") |
|
0 commit comments