diff --git a/openbb_terminal/stocks/fundamental_analysis/eclect_us_model.py b/openbb_terminal/stocks/fundamental_analysis/eclect_us_model.py index 836ca6bce41..27a9eec4f7e 100644 --- a/openbb_terminal/stocks/fundamental_analysis/eclect_us_model.py +++ b/openbb_terminal/stocks/fundamental_analysis/eclect_us_model.py @@ -2,9 +2,9 @@ __docformat__ = "numpy" import logging -from collections import OrderedDict import requests +import pandas as pd from openbb_terminal.decorators import log_start_end @@ -15,7 +15,7 @@ logger = logging.getLogger(__name__) @log_start_end(log=logger) -def get_filings_analysis(symbol: str) -> str: +def get_filings_analysis(symbol: str) -> pd.DataFrame: """Save time reading SEC filings with the help of machine learning. [Source: https://eclect.us] Parameters @@ -32,27 +32,30 @@ def get_filings_analysis(symbol: str) -> str: response = requests.get(f"https://api.eclect.us/symbol/{symbol.lower()}?page=1") if response.status_code != 200: - filings_analysis = "" - else: - response_dict = response.json() + return pd.DataFrame() - rf_highlights = "[bold]\n\tRISK FACTORS:[/bold]\n" - rf_highlights_list = [ - sentence["sentence"] for sentence in response_dict[0]["rf_highlights"] - ] - rf_highlights_list = list(OrderedDict.fromkeys(rf_highlights_list)) - rf_highlights_txt = "\n\n".join(rf_highlights_list) + response_dict = response.json() - daa_highlights = "[bold]\n\tDISCUSSION AND ANALYSIS:[/bold]\n" - daa_highlights_list = [ - sentence["sentence"] for sentence in response_dict[0]["daa_highlights"] - ] - daa_highlights_list = list(OrderedDict.fromkeys(daa_highlights_list)) - daa_highlights += "\n\n".join(daa_highlights_list) + def resultGroupMapper(g): + def resultMapper(a): + return { + "Good": a["good_or_bad"] == "good", + "Sentence": a["sentence"], + "Group": g, + } - if rf_highlights_txt: - filings_analysis = rf_highlights + rf_highlights_txt + "\n" + daa_highlights - else: - filings_analysis = daa_highlights + return resultMapper - return filings_analysis + risk = pd.DataFrame( + map(resultGroupMapper("Risk factors"), response_dict[0]["rf_highlights"]), + columns=["Group", "Good", "Sentence"], + ) + analysis = pd.DataFrame( + map( + resultGroupMapper("Discussion and Analysis"), + response_dict[0]["daa_highlights"], + ), + columns=["Group", "Good", "Sentence"], + ) + + return pd.concat([risk, analysis], ignore_index=True) diff --git a/openbb_terminal/stocks/fundamental_analysis/eclect_us_view.py b/openbb_terminal/stocks/fundamental_analysis/eclect_us_view.py index 5259c62736c..4fbe1eac63c 100644 --- a/openbb_terminal/stocks/fundamental_analysis/eclect_us_view.py +++ b/openbb_terminal/stocks/fundamental_analysis/eclect_us_view.py @@ -2,18 +2,18 @@ __docformat__ = "numpy" import logging +import os from openbb_terminal.decorators import log_start_end from openbb_terminal.rich_config import console from openbb_terminal.stocks.fundamental_analysis import eclect_us_model +from openbb_terminal.helper_funcs import print_rich_table, export_data logger = logging.getLogger(__name__) @log_start_end(log=logger) -def display_analysis( - symbol: str, -) -> None: +def display_analysis(symbol: str, export: str = "") -> None: """Display analysis of SEC filings based on NLP model. [Source: https://eclect.us] Parameters @@ -24,8 +24,11 @@ def display_analysis( analysis = eclect_us_model.get_filings_analysis(symbol) - if analysis: - console.print(analysis) + if not analysis.empty: + print_rich_table(analysis, title="SEC sillings analysis", show_index=True) + export_data( + export, os.path.dirname(os.path.abspath(__file__)), "analysis", analysis + ) else: console.print("Filings not found from eclect.us") console.print("") diff --git a/openbb_terminal/stocks/fundamental_analysis/fa_controller.py b/openbb_terminal/stocks/fundamental_analysis/fa_controller.py index a672647004c..3b4e87682bf 100644 --- a/openbb_terminal/stocks/fundamental_analysis/fa_controller.py +++ b/openbb_terminal/stocks/fundamental_analysis/fa_controller.py @@ -178,7 +178,7 @@ class FundamentalAnalysisController(StockBaseController): parser, other_args, export_allowed=EXPORT_ONLY_RAW_DATA_ALLOWED ) if ns_parser: - eclect_us_view.display_analysis(self.ticker) + eclect_us_view.display_analysis(symbol=self.ticker, export=ns_parser.export) @log_start_end(log=logger) def call_mgmt(self, other_args: List[str]): @@ -227,7 +227,7 @@ class FundamentalAnalysisController(StockBaseController): parser, other_args, export_allowed=EXPORT_ONLY_RAW_DATA_ALLOWED ) if ns_parser: - finviz_view.display_screen_data(self.ticker) + finviz_view.display_screen_data(symbol=self.ticker, export=ns_parser.export) @log_start_end(log=logger) def call_score(self, other_args: List[str]): diff --git a/tests/openbb_terminal/stocks/fundamental_analysis/csv/test_eclect_us_model/test_get_filings_analysis.csv b/tests/openbb_terminal/stocks/fundamental_analysis/csv/test_eclect_us_model/test_get_filings_analysis.csv new file mode 100644 index 00000000000..2f1dab6beea --- /dev/null +++ b/tests/openbb_terminal/stocks/fundamental_analysis/csv/test_eclect_us_model/test_get_filings_analysis.csv @@ -0,0 +1,13 @@ +,Group,Good,Sentence +0,Discussion and Analysis,False,"The TPD sets forth a comprehensive set of regulatory requirements for tobacco products, including: • health warnings covering 65% of the front and back panels of cigarette packs, with an option for member states to further standardize tobacco packaging, including the introduction of plain packaging; • a ban on characterizing flavors in some tobacco products, with a transition period for menthol that expired in May 2020; • security features and tracking and tracing measures that became effective in May 2019; and • a framework for the regulation of novel tobacco products and e-cigarettes, including requirements for health warnings and information leaflets, a prohibition on product packaging text related to reduced risk, and the introduction of notification requirements or authorization procedures in advance of commercialization." +1,Discussion and Analysis,False,"68 Table of ContentsIllicit Trade: Illicit tobacco trade creates a cheap and unregulated supply of tobacco products, undermines efforts to reduce smoking prevalence, especially among youth, damages legitimate businesses and intellectual property rights, stimulates organized crime, increases corruption and reduces government tax revenue." +2,Discussion and Analysis,False,"We submitted to the FDA a Modified Risk Tobacco Product Application (“ MRTPA”) for our Platform 1 product in December 2016, and a Premarket Tobacco Product Application (“ PMTA”) for our Platform 1 product in March 2017." +3,Discussion and Analysis,False,"For the nine months year-to-date, the estimated total market in the Middle East & Africa increased, mainly driven by: • Egypt, up by 14.3%, primarily reflecting a favorable comparison due to pandemic-related supply chain shortages for competitors'products in 2020, as well as the favorable impact of adult smoker in-switching to cigarettes (mainly in the low-tax tier) from other combustible tobacco products; • South Africa, up by 26.9%, mainly reflecting a favorable comparison versus the second and third quarters of 2020, in which the total market was impacted by the pandemic-related ban on all tobacco sales from March 27 th through August 17 th, partly offset by a higher estimated prevalence of illicit trade stemming from the ban; and • Turkey, up by 6.6%, primarily reflecting the same factors as for the quarter, partly offset by a higher estimated prevalence of illicit trade; partly offset by • International Duty Free, down by 17.2%, primarily reflecting the impact of government travel restrictions and reduced passenger traffic since the start of the pandemic in March 2020." +4,Discussion and Analysis,False,"Americas-Total Market, PMI Shipment Volume and Market Share Commentaries In the third quarter, the estimated total market in Americas decreased, notably due to: • Argentina, down by 2.1%, primarily reflecting the impact of price increases; 89 Table of Contents • Canada, down by 12.7%, notably reflecting the impact of price increases and out-switching from cigarettes to e-vapor products; partly offset by • Colombia, up by 13.4%, primarily reflecting the impact on adult smoker average daily consumption of the easing of pandemic-related measures." +5,Discussion and Analysis,True,"During the third quarter of 2021, our Board of Directors approved a 4.2% increase in the quarterly dividend to $1.25 per common share." +6,Discussion and Analysis,False,(1) Cost/Other variance includes charges in 2021 of $43 million for asset impairment and exit costs. +7,Discussion and Analysis,False,"We contributed $45 million in 2020, $40 million in 2021, and expect to contribute $35 million annually from 2022 through 2029, as specified in the amended pledge agreement." +8,Discussion and Analysis,True,"In the third quarter, our total shipment volume increased by 2.0% to 31.1 billion units, notably driven by: • Russia, up by 0.7%." +9,Discussion and Analysis,False,"Excluding favorable currency movements of $0.8 billion, net cash provided by operating activities increased by $0.5 billion, due primarily to higher net earnings, partially offset by higher working capital requirements of $0.2 billion and higher pension plan contributions." +10,Discussion and Analysis,False,"This increase was due to $1.9 billion of cash used in 2021 for our acquisitions, net of acquired cash, partially offset by favorable movements of $0.4 billion in cash collateral exchanged with financial institutions to secure derivatives designated as net investment hedges of Euro assets principally related to changes in exchange rates between the Euro and the U. S. dollar." +11,Discussion and Analysis,False,The net proceeds received are included in cash provided by operating activities in the condensed consolidated statements of cash flows. diff --git a/tests/openbb_terminal/stocks/fundamental_analysis/test_eclect_us_model.py b/tests/openbb_terminal/stocks/fundamental_analysis/test_eclect_us_model.py index 473b3699f6d..d1bca733551 100644 --- a/tests/openbb_terminal/stocks/fundamental_analysis/test_eclect_us_model.py +++ b/tests/openbb_terminal/stocks/fundamental_analysis/test_eclect_us_model.py @@ -21,9 +21,9 @@ def vcr_config(): @pytest.mark.vcr def test_get_filings_analysis(recorder): - result_txt = eclect_us_model.get_filings_analysis(symbol="PM") + result = eclect_us_model.get_filings_analysis(symbol="PM") - recorder.capture(result_txt) + recorder.capture(result) @pytest.mark.vcr(record_mode="none") @@ -36,4 +36,4 @@ def test_get_filings_analysis_invalid(mocker): ) result = eclect_us_model.get_filings_analysis(symbol="PM") - assert result == "" + assert result.empty diff --git a/tests/openbb_terminal/stocks/fundamental_analysis/test_eclect_us_view.py b/tests/openbb_terminal/stocks/fundamental_analysis/test_eclect_us_view.py index 8f50a11c9b2..75a0095a6a2 100644 --- a/tests/openbb_terminal/stocks/fundamental_analysis/test_eclect_us_view.py +++ b/tests/openbb_terminal/stocks/fundamental_analysis/test_eclect_us_view.py @@ -2,6 +2,7 @@ # IMPORTATION THIRDPARTY import pytest +import pandas as pd # IMPORTATION INTERNAL from openbb_terminal.stocks.fundamental_analysis import eclect_us_view @@ -19,7 +20,6 @@ def vcr_config(): @pytest.mark.vcr -@pytest.mark.record_stdout def test_display_analysis(): eclect_us_view.display_analysis(symbol="AAPL") @@ -29,6 +29,6 @@ def test_display_analysis(): def test_display_analysis_invalid(mocker): mocker.patch( target="openbb_terminal.stocks.fundamental_analysis.eclect_us_view.eclect_us_model.get_filings_analysis", - return_value="", + return_value=pd.DataFrame(), ) eclect_us_view.display_analysis(symbol="AAPL") diff --git a/tests/openbb_terminal/stocks/fundamental_analysis/test_fa_controller.py b/tests/openbb_terminal/stocks/fundamental_analysis/test_fa_controller.py index 9d946c77b97..2e531fe5af3 100644 --- a/tests/openbb_terminal/stocks/fundamental_analysis/test_fa_controller.py +++ b/tests/openbb_terminal/stocks/fundamental_analysis/test_fa_controller.py @@ -225,8 +225,8 @@ def test_call_func_expect_queue(expected_queue, queue, func): ( "call_analysis", "eclect_us_view.display_analysis", - [], - {"TSLA"}, + ["--export=csv"], + dict(symbol="TSLA", export="csv"), ), ( "call_mgmt", @@ -237,8 +237,8 @@ def test_call_func_expect_queue(expected_queue, queue, func): ( "call_data", "finviz_view.display_screen_data", - [], - {"TSLA"}, + ["--export=csv"], + dict(symbol="TSLA", export="csv"), ), ( "call_score",