Fix gov & economy failed test (#1585)

* fix more GST to OpenBB Terminal

* Fix gov & economy fail tests

* Small changes

* Patching valuation & performance command

* Change GTFF to OBBFF

Co-authored-by: DidierRLopes <dro.lopes@campus.fct.unl.pt>
Co-authored-by: Theodore Aptekarev <aptekarev@gmail.com>
This commit is contained in:
minhhoang1023
2022-03-29 21:27:02 +07:00
committed by GitHub
parent 4a61dc491d
commit e89cf9c5b2
10 changed files with 108 additions and 89 deletions

View File

@@ -11,6 +11,7 @@ from typing import List, Dict, Any
import pandas as pd
from prompt_toolkit.completion import NestedCompleter
from openbb_terminal.decorators import check_api_key
from openbb_terminal import feature_flags as obbff
from openbb_terminal.decorators import log_start_end
from openbb_terminal.economy import (
@@ -603,6 +604,7 @@ Performance & Valuations
self.update_runtime_choices()
@check_api_key(["API_FRED_KEY"])
def call_fred(self, other_args: List[str]):
"""Process fred command"""
parser = argparse.ArgumentParser(
@@ -669,10 +671,12 @@ Performance & Valuations
if ns_parser.query:
query = " ".join(ns_parser.query)
df_search = fred_model.get_series_notes(query)
fred_view.notes(series_term=query, num=ns_parser.limit)
self.fred_query = df_search["id"].head(ns_parser.limit)
self.update_runtime_choices()
if not df_search.empty:
fred_view.notes(series_term=query, num=ns_parser.limit)
self.fred_query = df_search["id"].head(ns_parser.limit)
self.update_runtime_choices()
if ns_parser.parameter:
series_dict = {}

View File

@@ -8,6 +8,7 @@ import pandas as pd
import requests
from finvizfinance.group import performance, spectrum, valuation
from openbb_terminal.rich_config import console
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import get_user_agent
@@ -30,9 +31,15 @@ def get_valuation_performance_data(group: str, data_type: str) -> pd.DataFrame:
pd.DataFrame
dataframe with valuation/performance data
"""
if data_type == "valuation":
return valuation.Valuation().screener_view(group=group)
return performance.Performance().screener_view(group=group)
try:
if data_type == "valuation":
return valuation.Valuation().screener_view(group=group)
elif data_type == "performance":
return performance.Performance().screener_view(group=group)
except IndexError:
console.print("Data not found.\n")
return pd.DataFrame()
@log_start_end(log=logger)

View File

@@ -58,6 +58,10 @@ def display_performance(
Export data to csv,json,xlsx or png,jpg,pdf,svg file
"""
df_group = finviz_model.get_valuation_performance_data(s_group, "performance")
if df_group.empty:
return
df_group = df_group.rename(
columns={
"Perf Week": "Week",
@@ -115,6 +119,10 @@ def display_valuation(
Export data to csv,json,xlsx or png,jpg,pdf,svg file
"""
df_group = finviz_model.get_valuation_performance_data(s_group, "valuation")
if df_group.empty:
return
df_group["Market Cap"] = df_group["Market Cap"].apply(
lambda x: float(x.strip("B")) if x.endswith("B") else float(x.strip("M")) / 1000
)

View File

@@ -908,7 +908,7 @@ def display_lobbying(ticker: str, num: int = 10):
"$" + str(int(float(row["Amount"]))) if row["Amount"] is not None else "N/A"
)
console.print(f"{row['Date']}: {row['Client']} {amount}")
if row["Amount"] is not None:
if (row["Amount"] is not None) and (row["Specific_Issue"] is not None):
console.print(
"\t" + row["Specific_Issue"].replace("\n", " ").replace("\r", "")
)

View File

@@ -1,26 +1,26 @@
# PRESETS
* [How to add presets](#how-to-add-presets)
* [template](#template)
* [sexy_year](#sexy_year)
* [buffett_like](#buffett_like)
* [cheap_bottom_dividend](#cheap_bottom_dividend)
* [cheap_dividend](#cheap_dividend)
* [cheap_oversold](#cheap_oversold)
* [cdeath_cross](#death_cross)
* [golden_cross](#golden_cross)
* [heavy_inst_ins](#heavy_inst_ins)
* [modified_dreman](#modified_dreman)
* [modified_neff](#modified_neff)
* [rosenwald](#rosenwald)
* [rosenwald_gtfo](#rosenwald_gtfo)
* [undervalue](#undervalue)
- [How to add presets](#how-to-add-presets)
- [template](#template)
- [sexy_year](#sexy_year)
- [buffett_like](#buffett_like)
- [cheap_bottom_dividend](#cheap_bottom_dividend)
- [cheap_dividend](#cheap_dividend)
- [cheap_oversold](#cheap_oversold)
- [cdeath_cross](#death_cross)
- [golden_cross](#golden_cross)
- [heavy_inst_ins](#heavy_inst_ins)
- [modified_dreman](#modified_dreman)
- [modified_neff](#modified_neff)
- [rosenwald](#rosenwald)
- [rosenwald_gtfo](#rosenwald_gtfo)
- [undervalue](#undervalue)
---
## How to add presets
1. Go to the folder GamestonkTerminal/gamestonk_terminal/screener/presets.
1. Go to the folder GamestonkTerminal/openbb_terminal/screener/presets.
2. There should be a `README.md` file and multiple `.ini` files. One of these `.ini` files should be named `template.ini`.
@@ -44,140 +44,140 @@
<img width="807" alt="5" src="https://user-images.githubusercontent.com/25267873/123713239-db765e00-d86b-11eb-8b58-127205d75894.png">
8. Start the terminal, and go to the `> scr` menu. In there, you can play with it on the terminal as shown:
8. Start the terminal, and go to the `> scr` menu. In there, you can play with it on the terminal as shown:
* **view**: Allows to see the screeners available. I.e. all `.ini` files in presets folder.
<img width="1201" alt="6" src="https://user-images.githubusercontent.com/25267873/123713231-d9ac9a80-d86b-11eb-920a-0959481de143.png">
- **view**: Allows to see the screeners available. I.e. all `.ini` files in presets folder.
<img width="1201" alt="6" src="https://user-images.githubusercontent.com/25267873/123713231-d9ac9a80-d86b-11eb-920a-0959481de143.png">
* **view <selected_preset>**: Allows to see the specific parameters set for the preset selected.
<img width="443" alt="Captura de ecrã 2021-06-28, às 23 58 35" src="https://user-images.githubusercontent.com/25267873/123713683-d82fa200-d86c-11eb-92ee-bf5ae14d5f12.png">
- **view <selected_preset>**: Allows to see the specific parameters set for the preset selected.
<img width="443" alt="Captura de ecrã 2021-06-28, às 23 58 35" src="https://user-images.githubusercontent.com/25267873/123713683-d82fa200-d86c-11eb-92ee-bf5ae14d5f12.png">
* **set <selected_preset>**: Allows to set this preset as main filter. See that the help menu will display a different
`PRESET: my_own_filter`
<img width="857" alt="7" src="https://user-images.githubusercontent.com/25267873/123713226-d9140400-d86b-11eb-9a61-bce07b6f580d.png">
- **set <selected_preset>**: Allows to set this preset as main filter. See that the help menu will display a different
`PRESET: my_own_filter`
<img width="857" alt="7" src="https://user-images.githubusercontent.com/25267873/123713226-d9140400-d86b-11eb-9a61-bce07b6f580d.png">
* **historical, overview, valuation, financial, ownership, performance, technical** commands will now be performed on
tickers that are filtered with the selected preset. Note: Since it is likely that there will be a big range of
tickers, we cap it to 10 randomly. So, it is normal if for the same filter the user sees 10 different tickers.
If the user wants to see more than 10 tickers, it can select a different limit using `-l` flag.
- **historical, overview, valuation, financial, ownership, performance, technical** commands will now be performed on
tickers that are filtered with the selected preset. Note: Since it is likely that there will be a big range of
tickers, we cap it to 10 randomly. So, it is normal if for the same filter the user sees 10 different tickers.
If the user wants to see more than 10 tickers, it can select a different limit using `-l` flag.
<img width="1049" alt="8" src="https://user-images.githubusercontent.com/25267873/123713223-d6191380-d86b-11eb-9e50-ac3a32d7922d.png">
9. Share with other Apes. You can do so by either creating yourself a Pull Request with this change, or asking a dev
(e.g. @Sexy_Year) on our discord server to add it for you.
(e.g. @Sexy_Year) on our discord server to add it for you.
---
## template
* **Author of preset:** GamestonkTerminal
* **Contact:** <https://github.com/DidierRLopes/GamestonkTerminal#contacts>
* **Description:** Template with all available filters and their options menu. More information can be found in
- **Author of preset:** GamestonkTerminal
- **Contact:** <https://github.com/DidierRLopes/GamestonkTerminal#contacts>
- **Description:** Template with all available filters and their options menu. More information can be found in
<https://finviz.com/help/screener.ashx> and <https://finviz.com/help/technical-analysis/charts-patterns.ashx>
---
## sexy_year
* **Author of preset:** Sexy Year
* **Contact:** Add contact of author, if (s)he whishes to be contacted. This can be an hyperlink, an e-mail, wtv
* **Description:** This is just a sample. The user that adds the preset can add a description for what type of stocks
- **Author of preset:** Sexy Year
- **Contact:** Add contact of author, if (s)he whishes to be contacted. This can be an hyperlink, an e-mail, wtv
- **Description:** This is just a sample. The user that adds the preset can add a description for what type of stocks
these filters are aimed for
---
## buffett_like
* **Author of preset:** Traceabl3
* **Contact:** via smoke signals
* **Description:** Buffet like value screener (Value invsting for long term growth)
- **Author of preset:** Traceabl3
- **Contact:** via smoke signals
- **Description:** Buffet like value screener (Value invsting for long term growth)
---
## cheap_bottom_dividend
* **Author of preset:** Traceabl3
* **Contact:** swing the bullroarer
* **ABOUT:** High Yield Dividend stonks that are at-or-near their lowest price. Inverse Head and shoulders pattern recognized.
- **Author of preset:** Traceabl3
- **Contact:** swing the bullroarer
- **ABOUT:** High Yield Dividend stonks that are at-or-near their lowest price. Inverse Head and shoulders pattern recognized.
---
## cheap_dividend
* **Author of preset:** Traceabl3
* **Contact:** illuminated bat symbol in the sky
* **Description:** cheap dividend stocks
- **Author of preset:** Traceabl3
- **Contact:** illuminated bat symbol in the sky
- **Description:** cheap dividend stocks
---
## cheap_oversold
* **Author of preset:** Traceabl3
* **Contact:** hit me on my skytel pager
* **Description:** Cheap stonks that are oversold: under 10% above the low, and oversold on the RSI.
- **Author of preset:** Traceabl3
- **Contact:** hit me on my skytel pager
- **Description:** Cheap stonks that are oversold: under 10% above the low, and oversold on the RSI.
---
## death_cross
* **Author of preset:** Traceabl3
* **Contact:** take the red pill
* **Description:** Death cross : when the 50sma crosses below the 200 sma
* **More information:** <https://www.investopedia.com/terms/d/deathcross.asp>
- **Author of preset:** Traceabl3
- **Contact:** take the red pill
- **Description:** Death cross : when the 50sma crosses below the 200 sma
- **More information:** <https://www.investopedia.com/terms/d/deathcross.asp>
---
## golden_cross
* **Author of preset:** Traceabl3
* **Contact:** flip the pigeons
* **Description:** Golden Cross when the 50 day moves above the 200 day from below.
- **Author of preset:** Traceabl3
- **Contact:** flip the pigeons
- **Description:** Golden Cross when the 50 day moves above the 200 day from below.
---
## heavy_inst_ins
* **Author of preset:** Traceabl3
* **Contact:** blow into the conch shell
* **Description:** Heavily owned by institutions and insiders (>30% each)
- **Author of preset:** Traceabl3
- **Contact:** blow into the conch shell
- **Description:** Heavily owned by institutions and insiders (>30% each)
---
## modified_dreman
* **Author of preset:** Traceabl3
* **Contact:** Drum Telegraphy
* **Description:** Modified Version of the Dreman Screener.
- **Author of preset:** Traceabl3
- **Contact:** Drum Telegraphy
- **Description:** Modified Version of the Dreman Screener.
---
## modified_neff
* **Author of preset:** Traceabl3
* **Contact:** bang the drums
* **Description:** Neff Screener with modifications // operational margin <50%
* **More information:** <https://marketxls.com/template/neff-screen/>
- **Author of preset:** Traceabl3
- **Contact:** bang the drums
- **Description:** Neff Screener with modifications // operational margin <50%
- **More information:** <https://marketxls.com/template/neff-screen/>
---
## rosenwald
* **Author of preset:** Traceabl3
* **Contact:** three shots in the air.
* **Description:** the classic rosenwald screen based on some dude I work with best guess.
- **Author of preset:** Traceabl3
- **Contact:** three shots in the air.
- **Description:** the classic rosenwald screen based on some dude I work with best guess.
---
## rosenwald_gtfo
* **Author of preset:** Traceabl3
* **Contact:** wave the white flag
* **Description:** Too many indicators indicating an impending downturn.
- **Author of preset:** Traceabl3
- **Contact:** wave the white flag
- **Description:** Too many indicators indicating an impending downturn.
---
## undervalue
* **Author of preset:** Traceabl3
* **Contact:** message on tor browser.
* **Description:** Potential Undervalued stocks
- **Author of preset:** Traceabl3
- **Contact:** message on tor browser.
- **Description:** Potential Undervalued stocks

View File

@@ -19,7 +19,7 @@ def test_display_sentiment_analysis(color, mocker):
target="openbb_terminal.common.behavioural_analysis.finbrain_view.export_data"
)
# MOCK GTFF
# MOCK OBBFF
mocker.patch.object(target=helper_funcs.obbff, attribute="USE_ION", new=True)
mocker.patch.object(
target=finbrain_view.rich_config, attribute="USE_COLOR", new=color
@@ -44,7 +44,7 @@ def test_display_sentiment_analysis_empty_df(mocker):
target="openbb_terminal.common.behavioural_analysis.finbrain_view.export_data"
)
# MOCK GTFF
# MOCK OBBFF
mocker.patch.object(target=helper_funcs.obbff, attribute="USE_ION", new=True)
# MOCK GET_SENTIMENT

View File

@@ -39,7 +39,7 @@ def test_map_sp500_view(mocker):
],
)
def test_display_performance(mocker, tab):
# MOCK GTFF
# MOCK OBBFF
mocker.patch.object(target=helper_funcs.obbff, attribute="USE_TABULATE_DF", new=tab)
mocker.patch.object(target=helper_funcs.obbff, attribute="USE_ION", new=True)
@@ -65,7 +65,7 @@ def test_display_performance(mocker, tab):
],
)
def test_display_valuation(mocker, tab):
# MOCK GTFF
# MOCK OBBFF
mocker.patch.object(target=helper_funcs.obbff, attribute="USE_TABULATE_DF", new=tab)
mocker.patch.object(target=helper_funcs.obbff, attribute="USE_ION", new=True)
@@ -116,7 +116,7 @@ def test_display_spectrum(mocker):
],
)
def test_display_future(mocker, tab):
# MOCK GTFF
# MOCK OBBFF
mocker.patch.object(target=helper_funcs.obbff, attribute="USE_TABULATE_DF", new=tab)
mocker.patch.object(target=helper_funcs.obbff, attribute="USE_ION", new=True)

View File

@@ -26,7 +26,7 @@ from openbb_terminal import helper_funcs
)
@pytest.mark.record_stdout
def test_call_func(func, mocker, tab):
# MOCK GTFF
# MOCK OBBFF
mocker.patch.object(target=helper_funcs.obbff, attribute="USE_TABULATE_DF", new=tab)
# MOCK EXPORT_DATA

View File

@@ -64,7 +64,7 @@ def test_print_insider_filter_no_table(mocker):
[True, False],
)
def test_print_insider_data(color, mocker):
# MOCK GTFF
# MOCK OBBFF
mocker.patch.object(
target=openinsider_view.rich_config, attribute="USE_COLOR", new=color
)

View File

@@ -509,7 +509,7 @@ def test_call_func_no_parser(func, mocker):
def test_controller_init_summary_profile(countries, industries, mocker, sectors):
path_controller = "openbb_terminal.stocks.sector_industry_analysis.sia_controller"
# MOCK GTFF
# MOCK OBBFF
mocker.patch(
target=f"{path_controller}.obbff.USE_PROMPT_TOOLKIT",
new=True,
@@ -568,7 +568,7 @@ def test_controller_init_market_cap(market_cap, mocker):
def test_update_runtime_choices(mocker):
path_controller = "openbb_terminal.stocks.sector_industry_analysis.sia_controller"
# MOCK GTFF
# MOCK OBBFF
mocker.patch(
target=f"{path_controller}.obbff.USE_PROMPT_TOOLKIT",
new=True,