Skip to content

Commit d7cf157

Browse files
committed
Clean code from Ratios Summary
1 parent 25edbe4 commit d7cf157

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed

src/ui/layout.py

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -104,55 +104,59 @@ def render_overview(financial_data):
104104

105105
with ratios_summary:
106106
st.markdown("#### Price and Market Data")
107+
properties_text = [
108+
"Previous Close",
109+
"Open",
110+
"Day High",
111+
"Day Low",
112+
"Volume",
113+
"Market Cap",
114+
"Beta",
115+
"PE Ratio",
116+
"EPS",
117+
"Forward Dividend & Yield",
118+
]
119+
values_text = [
120+
f"**{quotes['previousClose']:,}**",
121+
f"**{quotes['open']:,}**",
122+
f"**{quotes['dayHigh']:,}**",
123+
f"**{quotes['dayLow']:,}**",
124+
f"**{quotes['volume']:,}**",
125+
f"**{quotes['marketCap']:,}**",
126+
f"**{quotes['beta']:.3}**",
127+
f"**{quotes['trailingPE']:.4}**",
128+
f"**{quotes['trailingEps']:.3}**",
129+
(
130+
f"**{quotes['dividendRate']:.2} ({quotes['dividendYield'] * 100:.2}%)**"
131+
if "dividendRate" in quotes
132+
else "0"
133+
),
134+
]
107135
properties, values = st.columns(2)
108136
with properties:
109-
st.write("Previous Close")
110-
st.write("Open")
111-
st.write("Day High")
112-
st.write("Day Low")
113-
st.write("Volume")
114-
st.write("Market Cap")
115-
st.write("Beta")
116-
st.write("PE Ratio")
117-
st.write("EPS")
118-
st.write("Forward Dividend & Yield")
137+
for content in properties_text:
138+
st.write(content)
119139

120140
with values:
121-
st.write(f" **{quotes['previousClose']:,}**")
122-
st.write(f" **{quotes['open']:,}**")
123-
st.write(f" **{quotes['dayHigh']:,}**")
124-
st.write(f" **{quotes['dayLow']:,}**")
125-
st.write(f" **{quotes['volume']:,}**")
126-
st.write(f" **{quotes['marketCap']:,}**")
127-
st.write(f" **{quotes['beta']:.3}**")
128-
st.write(f" **{quotes['trailingPE']:.4}**")
129-
st.write(f" **{quotes['trailingEps']:.3}**")
130-
dividend_rate = (
131-
quotes["dividendRate"] if "dividendRate" in quotes.keys() else "0"
132-
)
133-
dividend_yield = (
134-
quotes["dividendYield"] * 100
135-
if "dividendRate" in quotes.keys()
136-
else "0"
137-
)
138-
st.write(f" **{dividend_rate:.2} ({dividend_yield:.2}%)**")
141+
for content in values_text:
142+
st.write(content)
139143

140144
with st.container():
141145
st.markdown("#### Company Profile")
142146
st.write(quotes["longBusinessSummary"])
143147

144-
sector_name = quotes["sector"]
145148
sector_key = quotes["sectorKey"].lower()
146-
sector_url = f"https://finance.yahoo.com/sectors/{sector_key}"
147-
sector_content = apply_tag_style(sector_url, sector_name)
149+
sector_content = apply_tag_style(
150+
f"https://finance.yahoo.com/sectors/{sector_key}", quotes["sector"]
151+
)
148152

149-
industry_name = quotes["industry"]
150153
industry_key = quotes["industryKey"].lower()
151-
industry_url = f"https://finance.yahoo.com/sectors/{sector_key}/{industry_key}"
152-
industry_content = apply_tag_style(industry_url, industry_name)
154+
industry_content = apply_tag_style(
155+
f"https://finance.yahoo.com/sectors/{sector_key}/{industry_key}",
156+
quotes["industry"],
157+
)
153158

154-
company_website = quotes["website"]
155-
website_content = apply_tag_style(company_website, "Website")
159+
website_content = apply_tag_style(quotes["website"], "Website")
156160

157161
st.markdown(
158162
f"""

0 commit comments

Comments
 (0)