11from rich .console import Console
2- from rich .table import Table
32from rich .panel import Panel
43from rich .markdown import Markdown
54from rich .layout import Layout
65from rich .box import ROUNDED
7- from rich .style import Style
8- from rich .text import Text
9- from rich .align import Align
106from bs4 import BeautifulSoup , Tag
117import json
128from dataclasses import dataclass
139from typing import List , Dict , Optional
1410
15- import typer
16-
1711console = Console ()
1812
1913@dataclass
@@ -47,9 +41,13 @@ def __init__(self, problem_data: dict):
4741 except Exception :
4842 pass
4943
50- self .total_accepted : int = problem_data .get ('totalAccepted' , 0 )
51- self .total_submissions : int = problem_data .get ('totalSubmissions' , 0 )
52- self .acceptance_rate : float = problem_data .get ('acRate' , 0 )
44+ # Parse stats from JSON string
45+ self .stats = {}
46+ try :
47+ stats_str = problem_data .get ('stats' , '{}' )
48+ self .stats = json .loads (stats_str )
49+ except Exception :
50+ self .stats = {}
5351
5452 self ._parse_content ()
5553 self .console_width = console .width
@@ -85,36 +83,6 @@ def _parse_content(self):
8583 else :
8684 current_section .append (text )
8785
88- @property
89- def available_languages (self ) -> List [str ]:
90- """Get list of available programming languages"""
91- return [snippet ['lang' ] for snippet in self .code_snippets ]
92-
93- @property
94- def formatted_function_signature (self ) -> str :
95- """Get the formatted function signature"""
96- if not self .function_metadata :
97- return "[red]Error loading function signature[/]"
98-
99- param_str = ', ' .join (
100- f"{ p ['name' ]} : { p ['type' ]} "
101- for p in self .function_metadata .params
102- )
103-
104- return (
105- "[bold blue]Function Signature:[/]\n "
106- f"[bold cyan]def[/] [yellow]{ self .function_metadata .name } [/](\n "
107- f" [green]{ param_str } [/]\n "
108- f") -> [green]{ self .function_metadata .return_type } [/]"
109- )
110-
111- def get_code_snippet (self , language : str ) -> Optional [str ]:
112- """Get code snippet for specific language"""
113- for snippet in self .code_snippets :
114- if snippet ['lang' ].lower () == language .lower ():
115- return snippet ['code' ]
116- return None
117-
11886 def format_test_case (self , input_str : str , expected_str : str , case_num : int ) -> str :
11987 return (
12088 f"[bold blue]Ex { case_num } :[/] "
@@ -220,15 +188,15 @@ def _format_test_cases(self):
220188
221189 def _format_stats (self ) -> str :
222190 """Format problem statistics"""
223- acceptance_rate = f" { self .acceptance_rate :.1f } %" if self . acceptance_rate else " N/A"
224- total_accepted = f" { self .total_accepted :, } " if self . total_accepted else " N/A"
225- total_submissions = f" { self .total_submissions :, } " if self . total_submissions else " N/A"
191+ accepted = self .stats . get ( 'totalAccepted' , ' N/A' )
192+ submissions = self .stats . get ( 'totalSubmission' , ' N/A' )
193+ ac_rate = self .stats . get ( 'acRate' , ' N/A' )
226194
227195 return (
228196 "[bold blue]Problem Stats[/]\n \n "
229- f"[cyan]Acceptance Rate:[/] { acceptance_rate } \n "
230- f"[cyan]Total Accepted:[/] { total_accepted } \n "
231- f"[cyan]Total Submissions:[/] { total_submissions } "
197+ f"[cyan]Acceptance Rate:[/] { ac_rate } \n "
198+ f"[cyan]Total Accepted:[/] { accepted } \n "
199+ f"[cyan]Total Submissions:[/] { submissions } "
232200 )
233201
234202 def display (self ):
@@ -281,4 +249,39 @@ def display(self):
281249 padding = (1 , 2 )
282250 ))
283251
284- console .print (layout )
252+ console .print (layout )
253+
254+ def display_only_description (self ):
255+ """Display only the problem description"""
256+ console .clear ()
257+ console .print ()
258+
259+ console .print (
260+ Panel (
261+ Markdown (self ._format_description (self .content )),
262+ box = ROUNDED ,
263+ title = str (self ._create_header ()),
264+ border_style = "blue" ,
265+ padding = (1 , 2 )
266+ )
267+ )
268+
269+ def display_only_test_cases (self ):
270+ """Display only the test cases"""
271+ console .clear ()
272+ console .print ()
273+
274+ console .print (
275+ Panel (
276+ self ._format_test_cases (),
277+ box = ROUNDED ,
278+ title = "[bold blue]Examples" ,
279+ border_style = "blue" ,
280+ padding = (1 , 2 )
281+ )
282+ )
283+
284+ def display_full (self ):
285+ """Display the full problem details"""
286+ self .display_only_description ()
287+ self .display_only_test_cases ()
0 commit comments