@@ -454,31 +454,89 @@ def _renderMarket(result, console) -> None:
454454 console .print (Panel (mt , title = "[bold]Market Data[/bold]" , border_style = "blue" ))
455455
456456
457- def _renderFinancial (result , console ) -> None :
458- """Financial Trends — 수익성·DuPont·효율성 종합 테이블."""
459- if not result .financial or not result .financial .periods :
457+ def _renderSummaryPanel (
458+ console ,
459+ periods ,
460+ summary ,
461+ * ,
462+ gateKey : str ,
463+ tableTitle : str ,
464+ panelTitle : str ,
465+ labels : dict ,
466+ percentKeys : set | None = None ,
467+ ratioKeys : set | None = None ,
468+ ) -> None :
469+ """라벨 표 하나를 기간 열 표로 그려 패널에 담는다. 자료가 없으면 아무 것도 안 그린다.
470+
471+ `gateKey` 가 비면 섹션 전체를 건너뛴다. 대표 항목이 없으면 나머지가 있어도 읽을 수 없는
472+ 표가 되기 때문이고, 이 규칙은 섹션마다 대표 항목이 달라 인자로 받는다.
473+
474+ 값 표기는 세 가지다. 백분율, 배수, 큰 금액. 어느 것인지는 지표가 정하지 그리는 쪽이
475+ 정하지 않는다.
476+ """
477+ if not summary or not summary .get (gateKey ):
460478 return
461479 from rich .panel import Panel
462480 from rich .table import Table
463481
464- fa = result .financial
465- periods = fa .periods
482+ table = Table (show_header = True , box = None , padding = (0 , 2 ), title = tableTitle )
483+ table .add_column ("지표" , style = "dim" )
484+ for period in periods :
485+ table .add_column (period , justify = "right" )
486+ for key , label in labels .items ():
487+ values = summary .get (key )
488+ if not values :
489+ continue
490+ if percentKeys and key in percentKeys :
491+ table .add_row (label , * [_fmtNum (v , "%" , precision = 1 ) for v in values ])
492+ elif ratioKeys and key in ratioKeys :
493+ table .add_row (label , * [_fmtNum (v , "배" , precision = 2 ) for v in values ])
494+ else :
495+ table .add_row (label , * [_fmtBig (v ) for v in values ])
496+ console .print (Panel (table , title = f"[bold]{ panelTitle } [/bold]" , border_style = "cyan" ))
497+
498+
499+ def _addTrendRows (table , trends : dict , rows : tuple , * , unit : str = "%" , precision : int = 1 , big : bool = False ) -> None :
500+ """값이 있는 지표만 골라 표에 행으로 붙인다.
501+
502+ 없는 지표는 빈 행을 만들지 않고 건너뛴다. 자료가 없는 것과 값이 0 인 것이 표에서
503+ 같아 보이면 안 되기 때문이다.
504+ """
505+ for key , label in rows :
506+ values = trends .get (key )
507+ if not values :
508+ continue
509+ if big :
510+ table .add_row (label , * [_fmtBig (v ) for v in values ])
511+ else :
512+ table .add_row (label , * [_fmtNum (v , unit , precision = precision ) for v in values ])
513+
514+
515+ def _renderTrendPanel (console , periods , fa ) -> None :
516+ """수익성부터 규모까지 다섯 구간을 한 표에 순서대로 쌓아 패널로 낸다.
517+
518+ 다섯을 따로 그리지 않는 이유가 있다. 같은 기간 열을 공유하고 빈 줄로만 구분하는
519+ 한 덩어리라, 따로 그리면 열 너비가 구간마다 달라져 눈으로 세로 비교가 안 된다.
520+ """
521+ from rich .panel import Panel
522+ from rich .table import Table
466523
467524 # ── 1) 수익성 추이 ──
468525 ft = Table (show_header = True , box = None , padding = (0 , 2 ), title = "수익성 추이" )
469526 ft .add_column ("지표" , style = "dim" )
470527 for p in periods :
471528 ft .add_column (p , justify = "right" )
472- if fa .marginTrends .get ("grossMargin" ):
473- ft .add_row ("매출총이익률" , * [_fmtNum (v , "%" ) for v in fa .marginTrends ["grossMargin" ]])
474- if fa .marginTrends .get ("operatingMargin" ):
475- ft .add_row ("영업이익률" , * [_fmtNum (v , "%" ) for v in fa .marginTrends ["operatingMargin" ]])
476- if fa .marginTrends .get ("netMargin" ):
477- ft .add_row ("순이익률" , * [_fmtNum (v , "%" ) for v in fa .marginTrends ["netMargin" ]])
478- if fa .marginTrends .get ("costOfSalesRatio" ):
479- ft .add_row ("원가율" , * [_fmtNum (v , "%" ) for v in fa .marginTrends ["costOfSalesRatio" ]])
480- if fa .marginTrends .get ("sgaRatio" ):
481- ft .add_row ("판관비율" , * [_fmtNum (v , "%" ) for v in fa .marginTrends ["sgaRatio" ]])
529+ _addTrendRows (
530+ ft ,
531+ fa .marginTrends ,
532+ (
533+ ("grossMargin" , "매출총이익률" ),
534+ ("operatingMargin" , "영업이익률" ),
535+ ("netMargin" , "순이익률" ),
536+ ("costOfSalesRatio" , "원가율" ),
537+ ("sgaRatio" , "판관비율" ),
538+ ),
539+ )
482540
483541 # ── 2) DuPont 분해 ──
484542 if fa .dupont and fa .dupont .roe :
@@ -504,14 +562,18 @@ def _renderFinancial(result, console) -> None:
504562 # ── 3) 효율성 추이 ──
505563 if fa .marginTrends .get ("dso" ) or fa .marginTrends .get ("ccc" ):
506564 ft .add_row ("" ) # separator
507- if fa .marginTrends .get ("dso" ):
508- ft .add_row ("매출채권회전일" , * [_fmtNum (v , "일" , precision = 0 ) for v in fa .marginTrends ["dso" ]])
509- if fa .marginTrends .get ("dio" ):
510- ft .add_row ("재고자산회전일" , * [_fmtNum (v , "일" , precision = 0 ) for v in fa .marginTrends ["dio" ]])
511- if fa .marginTrends .get ("dpo" ):
512- ft .add_row ("매입채무회전일" , * [_fmtNum (v , "일" , precision = 0 ) for v in fa .marginTrends ["dpo" ]])
513- if fa .marginTrends .get ("ccc" ):
514- ft .add_row ("[bold]CCC[/bold]" , * [_fmtNum (v , "일" , precision = 0 ) for v in fa .marginTrends ["ccc" ]])
565+ _addTrendRows (
566+ ft ,
567+ fa .marginTrends ,
568+ (
569+ ("dso" , "매출채권회전일" ),
570+ ("dio" , "재고자산회전일" ),
571+ ("dpo" , "매입채무회전일" ),
572+ ("ccc" , "[bold]CCC[/bold]" ),
573+ ),
574+ unit = "일" ,
575+ precision = 0 ,
576+ )
515577
516578 # ── 4) 성장률 ──
517579 if fa .marginTrends .get ("salesGrowth" ):
@@ -524,20 +586,34 @@ def _renderFinancial(result, console) -> None:
524586 if fa .marginTrends .get ("sales" ):
525587 ft .add_row ("" )
526588 ft .add_row ("매출" , * [_fmtBig (v ) for v in fa .marginTrends ["sales" ]])
527- if fa .marginTrends .get ("operatingProfit" ):
528- ft .add_row ("영업이익" , * [_fmtBig (v ) for v in fa .marginTrends ["operatingProfit" ]])
529- if fa .marginTrends .get ("netProfit" ):
530- ft .add_row ("순이익" , * [_fmtBig (v ) for v in fa .marginTrends ["netProfit" ]])
589+ _addTrendRows (ft , fa .marginTrends , (("operatingProfit" , "영업이익" ), ("netProfit" , "순이익" )), big = True )
531590
532591 console .print (Panel (ft , title = "[bold]Financial Analysis[/bold]" , border_style = "cyan" ))
533592
534- # ── 6) BS 요약 ──
535- if fa .bsSummary and fa .bsSummary .get ("totalAssets" ):
536- bt = Table (show_header = True , box = None , padding = (0 , 2 ), title = "재무상태표 요약" )
537- bt .add_column ("지표" , style = "dim" )
538- for p in periods :
539- bt .add_column (p , justify = "right" )
540- bsLabels = {
593+
594+ def _renderFinancial (result , console ) -> None :
595+ """Financial Trends — 수익성·DuPont·효율성 종합 테이블."""
596+ if not result .financial or not result .financial .periods :
597+ return
598+ from rich .panel import Panel
599+ from rich .table import Table
600+
601+ fa = result .financial
602+ periods = fa .periods
603+
604+ _renderTrendPanel (console , periods , fa )
605+
606+ # ── 6~8) BS·CF·3표 연결 요약 ──
607+ # 세 섹션이 "표 만들고, 라벨 표 돌며 행 추가하고, 패널로 출력" 하는 같은 모양이었다.
608+ # 라벨과 단위 규칙만 다르므로 그것만 자료로 넘긴다.
609+ _renderSummaryPanel (
610+ console ,
611+ periods ,
612+ fa .bsSummary ,
613+ gateKey = "totalAssets" ,
614+ tableTitle = "재무상태표 요약" ,
615+ panelTitle = "Balance Sheet Summary" ,
616+ labels = {
541617 "totalAssets" : "자산총계" ,
542618 "currentAssets" : "유동자산" ,
543619 "nonCurrentAssets" : "비유동자산" ,
@@ -547,54 +623,36 @@ def _renderFinancial(result, console) -> None:
547623 "retainedEarnings" : "이익잉여금" ,
548624 "debtRatio" : "부채비율" ,
549625 "currentRatio" : "유동비율" ,
550- }
551- for key , label in bsLabels .items ():
552- vals = fa .bsSummary .get (key )
553- if not vals :
554- continue
555- if key in ("debtRatio" , "currentRatio" ):
556- bt .add_row (label , * [_fmtNum (v , "%" , precision = 1 ) for v in vals ])
557- else :
558- bt .add_row (label , * [_fmtBig (v ) for v in vals ])
559- console .print (Panel (bt , title = "[bold]Balance Sheet Summary[/bold]" , border_style = "cyan" ))
560-
561- # ── 7) CF 요약 ──
562- if fa .cfSummary and fa .cfSummary .get ("operatingCf" ):
563- ct = Table (show_header = True , box = None , padding = (0 , 2 ), title = "현금흐름표 요약" )
564- ct .add_column ("지표" , style = "dim" )
565- for p in periods :
566- ct .add_column (p , justify = "right" )
567- cfLabels = {
626+ },
627+ percentKeys = {"debtRatio" , "currentRatio" },
628+ )
629+ _renderSummaryPanel (
630+ console ,
631+ periods ,
632+ fa .cfSummary ,
633+ gateKey = "operatingCf" ,
634+ tableTitle = "현금흐름표 요약" ,
635+ panelTitle = "Cash Flow Summary" ,
636+ labels = {
568637 "operatingCf" : "영업CF" ,
569638 "investingCf" : "투자CF" ,
570639 "financingCf" : "재무CF" ,
571640 "capex" : "CAPEX" ,
572641 "fcf" : "FCF" ,
573- }
574- for key , label in cfLabels .items ():
575- vals = fa .cfSummary .get (key )
576- if not vals :
577- continue
578- ct .add_row (label , * [_fmtBig (v ) for v in vals ])
579- console .print (Panel (ct , title = "[bold]Cash Flow Summary[/bold]" , border_style = "cyan" ))
580-
581- # ── 8) 3표 연결 지표 ──
582- if fa .crossStatementMetrics and fa .crossStatementMetrics .get ("ocfToNetIncome" ):
583- xt = Table (show_header = True , box = None , padding = (0 , 2 ), title = "3표 연결 지표" )
584- xt .add_column ("지표" , style = "dim" )
585- for p in periods :
586- xt .add_column (p , justify = "right" )
587- xLabels = {
642+ },
643+ )
644+ _renderSummaryPanel (
645+ console ,
646+ periods ,
647+ fa .crossStatementMetrics ,
648+ gateKey = "ocfToNetIncome" ,
649+ tableTitle = "3표 연결 지표" ,
650+ panelTitle = "Cross-Statement Metrics" ,
651+ labels = {
588652 "ocfToNetIncome" : "OCF/NI" ,
589653 "capexToDepreciation" : "CAPEX/감가상각" ,
590654 "retainedEarningsGrowth" : "이익잉여금 증가율" ,
591- }
592- for key , label in xLabels .items ():
593- vals = fa .crossStatementMetrics .get (key )
594- if not vals :
595- continue
596- if key == "retainedEarningsGrowth" :
597- xt .add_row (label , * [_fmtNum (v , "%" , precision = 1 ) for v in vals ])
598- else :
599- xt .add_row (label , * [_fmtNum (v , "배" , precision = 2 ) for v in vals ])
600- console .print (Panel (xt , title = "[bold]Cross-Statement Metrics[/bold]" , border_style = "cyan" ))
655+ },
656+ percentKeys = {"retainedEarningsGrowth" },
657+ ratioKeys = {"ocfToNetIncome" , "capexToDepreciation" },
658+ )
0 commit comments