hotfix/ /stocks/fa/pt show all price targets on hover (#5305)

* `/stocks/fa/pt` show all price targets on hover

* Update helper_funcs.py
This commit is contained in:
teh_coderer
2023-08-09 21:28:29 -07:00
committed by GitHub
parent 581fd94276
commit 6cf09392be
2 changed files with 18 additions and 3 deletions

View File

@@ -278,6 +278,7 @@ def print_rich_table(
print_to_console: bool = False,
limit: Optional[int] = 1000,
source: Optional[str] = None,
columns_keep_types: Optional[List[str]] = None,
):
"""Prepare a table from df in rich.
@@ -313,6 +314,8 @@ def print_rich_table(
console.
source: Optional[str]
Source of the table. If provided, it will be displayed in the header of the table.
columns_keep_types: Optional[List[str]]
Columns to keep their types, i.e. not convert to numeric
"""
if export:
return
@@ -329,6 +332,8 @@ def print_rich_table(
# convert non-str that are not timestamp or int into str
# eg) praw.models.reddit.subreddit.Subreddit
for col in df.columns:
if columns_keep_types is not None and col in columns_keep_types:
continue
try:
if not any(
isinstance(df[col].iloc[x], pd.Timestamp)

View File

@@ -172,9 +172,17 @@ def display_price_target_from_analysts(
name="Price Target",
mode="markers",
customdata=df_analyst_plot.apply(
lambda row: f"{row['Company']} ({row['Rating']})", axis=1
).values,
hovertemplate="%{customdata}<br><br>Price Target: %{y:.2f}",
lambda row: "<br>".join(
[
f"<b>${x['Price Target']}</b> - <b>{x['Company']} ({x['Rating']})</b>"
for _, x in df_analyst_plot[df_analyst_plot.index == row.name]
.sort_values(by="Price Target", ascending=False)
.iterrows()
]
),
axis=1,
),
hovertemplate="<br>%{customdata}",
marker=dict(
color=colors,
line=dict(width=1, color="DarkSlateGrey"),
@@ -183,6 +191,8 @@ def display_price_target_from_analysts(
line=dict(color=theme.get_colors()[1]),
)
fig.update_layout(hovermode="x unified")
export_data(
export,
os.path.dirname(os.path.abspath(__file__)),