mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 20:42:26 +00:00
Improved verbosity of dd rating failure, and add color to the chart (#2204)
* Added verbosity to rating failure * Made rating failure verbose and added color * Fixed tests
This commit is contained in:
@@ -8,6 +8,7 @@ import pandas as pd
|
||||
|
||||
from openbb_terminal import config_terminal as cfg
|
||||
from openbb_terminal.decorators import log_start_end
|
||||
from openbb_terminal.rich_config import console
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -30,6 +31,7 @@ def get_rating(ticker: str) -> pd.DataFrame:
|
||||
try:
|
||||
df = fa.rating(ticker, cfg.API_KEY_FINANCIALMODELINGPREP)
|
||||
except ValueError as e:
|
||||
console.print(f"[red]{e}[/red]\n")
|
||||
logger.exception(str(e))
|
||||
df = pd.DataFrame()
|
||||
else:
|
||||
|
||||
@@ -11,6 +11,14 @@ from openbb_terminal.stocks.due_diligence import fmp_model
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def add_color(value: str) -> str:
|
||||
if "buy" in value.lower():
|
||||
value = f"[green]{value}[/green]"
|
||||
elif "sell" in value.lower():
|
||||
value = f"[red]{value}[/red]"
|
||||
return value
|
||||
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def rating(ticker: str, num: int, export: str):
|
||||
"""Display ratings for a given ticker. [Source: Financial Modeling Prep]
|
||||
@@ -27,9 +35,9 @@ def rating(ticker: str, num: int, export: str):
|
||||
df = fmp_model.get_rating(ticker)
|
||||
|
||||
# TODO: This could be displayed in a nice rating plot over time
|
||||
# TODO: Add coloring to table
|
||||
|
||||
if not df.empty:
|
||||
df = df.astype(str).applymap(lambda x: add_color(x))
|
||||
l_recoms = [col for col in df.columns if "Recommendation" in col]
|
||||
l_recoms_show = [
|
||||
recom.replace("rating", "")
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
ratingRecommendation ratingDetailsDCFRecommendation ratingDetailsROERecommendation ratingDetailsROARecommendation ratingDetailsDERecommendation ratingDetailsPERecommendation ratingDetailsPBRecommendation
|
||||
date
|
||||
2021-11-16 Strong Buy Strong Buy Neutral Neutral Buy Strong Buy Strong Buy
|
||||
2021-11-15 Strong Buy Strong Buy Neutral Neutral Buy Strong Buy Strong Buy
|
||||
2021-11-12 Strong Buy Strong Buy Neutral Neutral Buy Strong Buy Strong Buy
|
||||
2021-11-11 Strong Buy Strong Buy Neutral Neutral Buy Strong Buy Strong Buy
|
||||
2021-11-10 Strong Buy Strong Buy Neutral Neutral Buy Strong Buy Strong Buy
|
||||
|
||||
ratingRecommendation ratingDetailsDCFRecommendation ratingDetailsROERecommendation ratingDetailsROARecommendation ratingDetailsDERecommendation ratingDetailsPERecommendation ratingDetailsPBRecommendation
|
||||
date
|
||||
2021-11-16 [green]Strong Buy[/green] [green]Strong Buy[/green] Neutral Neutral [green]Buy[/green] [green]Strong Buy[/green] [green]Strong Buy[/green]
|
||||
2021-11-15 [green]Strong Buy[/green] [green]Strong Buy[/green] Neutral Neutral [green]Buy[/green] [green]Strong Buy[/green] [green]Strong Buy[/green]
|
||||
2021-11-12 [green]Strong Buy[/green] [green]Strong Buy[/green] Neutral Neutral [green]Buy[/green] [green]Strong Buy[/green] [green]Strong Buy[/green]
|
||||
2021-11-11 [green]Strong Buy[/green] [green]Strong Buy[/green] Neutral Neutral [green]Buy[/green] [green]Strong Buy[/green] [green]Strong Buy[/green]
|
||||
2021-11-10 [green]Strong Buy[/green] [green]Strong Buy[/green] Neutral Neutral [green]Buy[/green] [green]Strong Buy[/green] [green]Strong Buy[/green]
|
||||
|
||||
Reference in New Issue
Block a user