Skip to content

Commit 03c417e

Browse files
fix: result handling
1 parent e61a2be commit 03c417e

File tree

6 files changed

+196
-194
lines changed

6 files changed

+196
-194
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"python.analysis.autoImportCompletions": true,
3-
"python.analysis.typeCheckingMode": "basic"
3+
"python.analysis.typeCheckingMode": "basic",
44
}

src/commands/submit.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,10 @@ def submit(
6161
return
6262

6363
with create_submission_progress() as progress:
64-
submit_task = progress.add_task("Submitting...", total=1)
65-
progress.update(submit_task, advance=0.5)
64+
progress.add_task("Submitting...", total=1)
6665
result = solution_manager.submit_solution(problem, code, lang)
67-
progress.update(submit_task, advance=0.5)
6866

69-
display_submission_results(result)
67+
display_submission_results(result, is_test=False)
7068

7169
except Exception as e:
7270
display_exception_error(e)

src/commands/test.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,12 @@ def test(
3636

3737
display_language_detection_message(lang)
3838

39-
typer.echo(typer.style("🧪 Testing solution with LeetCode test cases...", fg=typer.colors.YELLOW))
40-
4139
try:
4240
with create_submission_progress() as progress:
43-
test_task = progress.add_task("Testing...", total=1)
44-
progress.update(test_task, advance=0.5)
41+
progress.add_task("Testing...", total=1)
4542
result = solution_manager.test_solution(problem, code, lang)
46-
progress.update(test_task, advance=0.5)
4743

48-
display_submission_results(result)
44+
display_submission_results(result, is_test=True)
4945

5046
except Exception as e:
5147
display_exception_error(e)

src/lib/submission_ui.py

Lines changed: 187 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from typing import Any, Dict
12
from rich.console import Console
23
from rich.panel import Panel
3-
from rich.progress import Progress, BarColumn, TextColumn
4+
from rich.progress import Progress, SpinnerColumn, TextColumn
45
from rich import box
56
from rich.columns import Columns
67
import typer
@@ -58,122 +59,220 @@ def display_submission_canceled():
5859
def create_submission_progress():
5960
"""Create and return a submission progress context"""
6061
return Progress(
61-
TextColumn("[bold yellow]Submitting solution...", justify="right"),
62-
BarColumn(bar_width=40, style="yellow"),
62+
SpinnerColumn(),
63+
TextColumn("[progress.description]{task.description}"),
6364
transient=True,
6465
)
6566

66-
def display_submission_results(result):
67+
def display_submission_results(result: Dict[str, Any], is_test: bool = False):
6768
"""Display submission results with a cleaner layout"""
68-
if result["success"]:
69-
status = result['status']
70-
71-
if status == "Accepted":
72-
status_style = "bold green"
73-
border_style = "green"
74-
emoji = "✅"
75-
elif status in ["Runtime Error", "Time Limit Exceeded"]:
76-
status_style = "bold yellow"
77-
border_style = "yellow"
78-
emoji = "⚠️"
79-
else:
80-
status_style = "bold red"
81-
border_style = "red"
82-
emoji = "❌"
83-
84-
runtime = result.get('runtime', 'N/A')
85-
memory = result.get('memory', 'N/A')
86-
87-
memory_warning = result.get('memory_warning')
88-
if memory_warning:
89-
memory = f"{memory} [bold yellow](!)[/]"
90-
91-
passed = result.get('passed_testcases', 0)
92-
total = result.get('total_testcases', 0)
93-
test_case_str = f"{passed}/{total} ({passed/total*100:.1f}%)" if total > 0 else "N/A"
94-
95-
content = [
96-
f"[cyan]⏱️ Runtime:[/] {runtime}",
97-
f"[cyan]💾 Memory:[/] {memory}"
98-
]
99-
100-
if result.get('elapsed_time'):
101-
content.append(f"[cyan]⏲️ Elapsed Time:[/] {result.get('elapsed_time')} ms")
102-
103-
content.append(f"[cyan]🧪 Test Cases:[/] {test_case_str}")
104-
105-
title = f"{emoji} Submission Result: [{status_style}]{status}[/]"
106-
console.print(Panel(
107-
"\n".join(content),
108-
title=title,
109-
border_style=border_style,
110-
box=box.ROUNDED
111-
))
69+
status_code = result.get('status_code')
70+
status = result.get('status', result.get('status_msg', 'Unknown'))
71+
run_success = result.get('run_success', result.get('success', False))
72+
73+
if status == "Accepted" and run_success:
74+
status_style = "bold green"
75+
border_style = "green"
76+
emoji = "✅"
77+
elif status in ["Runtime Error", "Time Limit Exceeded"] or status_code in [14, 15]:
78+
status_style = "bold yellow"
79+
border_style = "yellow"
80+
emoji = "⚠️"
81+
elif status == "Compile Error" or status_code == 20:
82+
status_style = "bold red"
83+
border_style = "red"
84+
emoji = "❌"
85+
else:
86+
status_style = "bold red"
87+
border_style = "red"
88+
emoji = "❌"
89+
90+
runtime = result.get('status_runtime', result.get('runtime', 'N/A'))
91+
memory = result.get('status_memory', result.get('memory', 'N/A'))
92+
93+
if isinstance(memory, int):
94+
memory = f"{memory / 1000000:.1f} MB"
95+
96+
memory_warning = None
97+
if isinstance(result.get('memory'), int):
98+
memory_value = result.get('memory', 0)
99+
if memory_value > 200000000:
100+
memory_warning = f"Your solution is using a large amount of memory ({memory_value/1000000:.1f} MB). Consider optimizing to reduce memory usage."
101+
102+
if memory_warning:
103+
memory = f"{memory} [bold yellow](!)[/]"
104+
105+
passed = result.get('total_correct', 0)
106+
total = result.get('total_testcases', 0)
107+
108+
test_case_str = "N/A"
109+
if total and total > 0:
110+
percentage = (passed / total) * 100
111+
test_case_str = f"{passed}/{total} ({percentage:.1f}%)"
112+
113+
content_parts = []
114+
content_parts.append(f"[cyan]⏱️ Runtime:[/] {runtime}")
115+
content_parts.append(f"[cyan]💾 Memory:[/] {memory}")
116+
117+
if result.get('elapsed_time'):
118+
content_parts.append(f"[cyan]⏲️ Elapsed Time:[/] {result.get('elapsed_time')} ms")
112119

113-
if memory_warning:
120+
content_parts.append(f"[cyan]🧪 Test Cases:[/] {test_case_str}")
121+
content_string = "\n".join(content_parts)
122+
123+
title = f"{emoji} {'Test' if is_test else 'Submission'} Result: [{status_style}]{status}[/]"
124+
console.print(Panel(
125+
content_string,
126+
title=title,
127+
border_style=border_style,
128+
box=box.ROUNDED,
129+
padding=(0, 10)
130+
))
131+
132+
# Display specific error messages
133+
if status == "Compile Error" or status_code == 20:
134+
error_msg = result.get('compile_error', result.get('error', 'No details available'))
135+
full_error = result.get('full_compile_error', result.get('full_error', ''))
136+
137+
if error_msg:
138+
console.print(Panel(
139+
error_msg,
140+
title="Compilation Error",
141+
border_style="red",
142+
box=box.ROUNDED,
143+
padding=(0, 1)
144+
))
145+
146+
if full_error:
114147
console.print(Panel(
115-
memory_warning,
116-
title="⚠️ Memory Usage Warning",
148+
full_error,
149+
title="Full Compilation Error",
150+
border_style="red",
151+
box=box.ROUNDED,
152+
padding=(0, 1)
153+
))
154+
155+
elif status == "Runtime Error" or status_code == 15:
156+
error_msg = result.get('runtime_error', result.get('error', 'No details available'))
157+
full_error = result.get('full_runtime_error', result.get('full_error', ''))
158+
159+
if error_msg:
160+
console.print(Panel(
161+
error_msg,
162+
title="Runtime Error",
117163
border_style="yellow",
118-
box=box.ROUNDED
164+
box=box.ROUNDED,
165+
padding=(0, 1)
119166
))
120167

121-
if result.get('stdout'):
168+
if full_error:
122169
console.print(Panel(
123-
result.get('stdout'),
124-
title="📝 Standard Output",
125-
border_style="blue",
126-
box=box.ROUNDED
170+
full_error,
171+
title="Full Error Trace",
172+
border_style="yellow",
173+
box=box.ROUNDED,
174+
padding=(0, 1)
127175
))
128176

129-
if result.get('output') and result.get('expected'):
130-
is_wrong_answer = status == "Wrong Answer"
177+
# Display memory warning if present
178+
if memory_warning:
179+
console.print(Panel(
180+
memory_warning,
181+
title="⚠️ Memory Usage Warning",
182+
border_style="yellow",
183+
box=box.ROUNDED,
184+
padding=(0, 1)
185+
))
186+
187+
stdout_lines = []
188+
if result.get('std_output_list'):
189+
current_test_case = []
190+
for line in result.get('std_output_list', []):
191+
if line and line.strip():
192+
current_test_case.append(line.rstrip())
193+
elif current_test_case:
194+
stdout_lines.extend(current_test_case)
195+
current_test_case = []
196+
197+
if current_test_case:
198+
stdout_lines.extend(current_test_case)
199+
200+
if stdout_lines:
201+
console.print(Panel(
202+
"\n".join(stdout_lines),
203+
title="📝 Standard Output",
204+
border_style="blue",
205+
box=box.ROUNDED,
206+
padding=(0, 1)
207+
))
208+
elif result.get('stdout') and result.get('stdout', '').strip():
209+
console.print(Panel(
210+
result.get('stdout', '').strip(),
211+
title="📝 Standard Output",
212+
border_style="blue",
213+
box=box.ROUNDED,
214+
padding=(0, 1)
215+
))
216+
217+
if result.get('code_answer') and result.get('expected_code_answer'):
218+
output_lines = [line for line in result.get('code_answer', []) if line and line.strip()]
219+
expected_lines = [line for line in result.get('expected_code_answer', []) if line and line.strip()]
220+
221+
if output_lines or expected_lines:
222+
output = "\n".join(output_lines)
223+
expected = "\n".join(expected_lines)
224+
225+
is_wrong_answer = status == "Wrong Answer" or (not run_success and not (status in ["Compile Error", "Runtime Error", "Time Limit Exceeded"]))
131226

132227
output_panel = Panel(
133-
result.get('output', ''),
228+
output,
134229
title="Your Output",
135-
border_style="red" if is_wrong_answer else "blue"
230+
border_style="red" if is_wrong_answer else "blue",
231+
padding=(0, 1)
136232
)
137233
expected_panel = Panel(
138-
result.get('expected', ''),
234+
expected,
139235
title="Expected Output",
140-
border_style="green"
236+
border_style="green",
237+
padding=(0, 1)
141238
)
142239
console.print(Columns([output_panel, expected_panel]))
240+
elif result.get('output') or result.get('expected'):
241+
output = (result.get('output', '') or '').strip()
242+
expected = (result.get('expected', '') or '').strip()
143243

144-
if status != "Accepted" and result.get('error'):
145-
error_msg = result.get('error', 'No details available')
146-
console.print(Panel(error_msg, title="Error Details", border_style="red"))
147-
148-
if result.get('full_error'):
149-
console.print(Panel(
150-
result.get('full_error', ''),
151-
title="Full Error Trace",
152-
border_style="red",
153-
box=box.ROUNDED
154-
))
155-
else:
156-
error_panel = Panel(
157-
f"{result.get('error', 'Unknown error')}",
158-
title="❌ Submission Failed",
159-
border_style="red"
244+
is_wrong_answer = status == "Wrong Answer" or (not run_success and not (status in ["Compile Error", "Runtime Error", "Time Limit Exceeded"]))
245+
246+
output_panel = Panel(
247+
output,
248+
title="Your Output",
249+
border_style="red" if is_wrong_answer else "blue",
250+
padding=(0, 1)
160251
)
161-
console.print(error_panel)
252+
expected_panel = Panel(
253+
expected,
254+
title="Expected Output",
255+
border_style="green",
256+
padding=(0, 1)
257+
)
258+
console.print(Columns([output_panel, expected_panel]))
162259

163-
if result.get('stdout'):
164-
console.print(Panel(
165-
result.get('stdout'),
166-
title="📝 Standard Output",
167-
border_style="blue",
168-
box=box.ROUNDED
169-
))
260+
if not run_success and status not in ["Compile Error", "Runtime Error"] and result.get('error'):
261+
error_msg = result.get('error', 'No details available')
262+
console.print(Panel(
263+
error_msg,
264+
title="Error Details",
265+
border_style="red",
266+
padding=(0, 1)
267+
))
170268

171269
if result.get('full_error'):
172270
console.print(Panel(
173271
result.get('full_error', ''),
174272
title="Full Error Trace",
175273
border_style="red",
176-
box=box.ROUNDED
274+
box=box.ROUNDED,
275+
padding=(0, 1)
177276
))
178277

179278
def display_exception_error(e):

src/server/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
15: "Runtime Error",
77
16: "Memory Limit Exceeded",
88
20: "Compile Error",
9-
30: "Wrong Answer"
9+
11: "Wrong Answer"
1010
}
1111
LANGUAGE_MAP = {
1212
'.py': 'python3',

0 commit comments

Comments
 (0)