Skip to content

Commit 8ced115

Browse files
feat: user profile
1 parent a42aa32 commit 8ced115

File tree

2 files changed

+90
-39
lines changed

2 files changed

+90
-39
lines changed

solution.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/lib/ui.py

Lines changed: 90 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,104 @@
11
from rich.console import Console
22
from rich.table import Table
3+
from rich.panel import Panel
4+
from rich import box
5+
from datetime import datetime
36

47
console = Console()
58

6-
def create_problems_table(data):
7-
table = Table(title="LeetCode Problems Count")
8-
table.add_column("Difficulty", style="cyan")
9-
table.add_column("Count", justify="right", style="green")
9+
def format_timestamp(timestamp):
10+
dt = datetime.fromtimestamp(timestamp)
11+
return dt.strftime("%Y-%m-%d %H:%M")
1012

11-
for item in data['allQuestionsCount']:
12-
table.add_row(item['difficulty'], str(item['count']))
13-
return table
13+
def create_recent_activity(recent_submissions):
14+
if not recent_submissions:
15+
return None
1416

15-
def create_user_stats_table(data):
16-
if not data.get('matchedUser'):
17-
return None
17+
table = Table(
18+
title="Recent Submissions",
19+
box=box.ROUNDED,
20+
border_style="cyan",
21+
pad_edge=False,
22+
show_edge=True
23+
)
1824

19-
table = Table(title="Your Statistics")
20-
table.add_column("Difficulty", style="cyan")
21-
table.add_column("Solved", justify="right", style="green")
22-
table.add_column("Beats", justify="right", style="yellow")
25+
table.add_column("Time", style="dim", width=16)
26+
table.add_column("Problem", style="cyan")
27+
table.add_column("Status", justify="center", width=8)
2328

24-
user_data = data['matchedUser']
25-
solved = user_data['submitStatsGlobal']['acSubmissionNum']
26-
beats = user_data['problemsSolvedBeatsStats']
29+
for sub in recent_submissions[:5]: # Show last 5 submissions
30+
status_icon = "[green]✓" if sub['statusDisplay'] == "Accepted" else "[red]✗"
31+
table.add_row(
32+
format_timestamp(sub['timestamp']),
33+
sub['title'],
34+
status_icon
35+
)
2736

28-
difficulties = ['Easy', 'Medium', 'Hard']
29-
for diff in difficulties:
30-
solved_count = next((item['count'] for item in solved if item['difficulty'] == diff), 0)
31-
beats_percent = next((f"{item['percentage']:.1f}%" for item in beats if item['difficulty'] == diff), "N/A")
32-
table.add_row(diff, str(solved_count), beats_percent)
37+
return table
3338

34-
return table
39+
def create_profile_header(data):
40+
username = data.get('matchedUser', {}).get('username', 'Leetcoder')
41+
user_data = data.get('matchedUser', {})
42+
solved = user_data.get('submitStatsGlobal', {}).get('acSubmissionNum', [])
43+
44+
table = Table.grid(padding=(0, 2))
45+
table.add_column(justify="left", width=130)
46+
table.add_column(justify="left", width=45)
47+
48+
# Calculate stats
49+
total_solved = next((item['count'] for item in solved if item['difficulty'] == 'All'), 0)
50+
total_problems = next((item['count'] for item in data['allQuestionsCount'] if item['difficulty'] == 'All'), 0)
51+
solve_percentage = (total_solved / total_problems) * 100 if total_problems > 0 else 0
52+
53+
# Left column - compact formatting
54+
profile_text = (
55+
f"[bold cyan]{username}[/bold cyan]\n"
56+
f"Solved: [cyan]{total_solved}[/cyan]/[cyan]{total_problems}[/cyan]\n"
57+
f"[dim]({solve_percentage:.1f}%)[/dim]"
58+
)
59+
60+
# Right column - clean difficulty stats
61+
difficulties = ['Easy', 'Medium', 'Hard']
62+
colors = ['green', 'yellow', 'red']
63+
stats_text = []
64+
65+
for diff, color in zip(difficulties, colors):
66+
solved_count = next((item['count'] for item in solved if item['difficulty'] == diff), 0)
67+
total_count = next((item['count'] for item in data['allQuestionsCount'] if item['difficulty'] == diff), 0)
68+
percentage = (solved_count / total_count) * 100 if total_count > 0 else 0
69+
70+
dots = "●" * int(percentage/10) + "○" * (10 - int(percentage/10))
71+
stats_text.append(
72+
f"[{color}]{diff:<6} {solved_count:>3}/{total_count:<4} {dots} {percentage:>5.1f}%[/{color}]"
73+
)
74+
75+
table.add_row(
76+
profile_text,
77+
"\n".join(stats_text)
78+
)
79+
80+
return Panel(
81+
table,
82+
border_style="cyan",
83+
padding=(1, 2),
84+
title="[bold cyan]LeetCode Profile[/bold cyan]"
85+
)
3586

3687
def display_problem_stats(data):
37-
problems_table = create_problems_table(data)
38-
console.print(problems_table)
88+
console.clear()
89+
console.print("\n")
90+
91+
# Display profile header
92+
console.print(create_profile_header(data))
93+
console.print("\n")
94+
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"))
39103

40-
user_stats = create_user_stats_table(data)
41-
if user_stats:
42-
console.print("\n")
43-
console.print(user_stats)
104+
console.print("\n")

0 commit comments

Comments
 (0)