Visualize company sentiment (#422)

Updates the tab and widget "Stimmung"
This commit is contained in:
KM-R
2023-11-22 22:32:38 +01:00
committed by GitHub
parent 65c41bb20c
commit 4e83c83374
9 changed files with 777 additions and 53 deletions

View File

@ -4,6 +4,7 @@ import pandas as pd
from sqlalchemy.orm import Session
from aki_prj23_transparenzregister.ui import data_elements
from aki_prj23_transparenzregister.utils.enum_types import SentimentLabel
def test_import() -> None:
@ -86,3 +87,27 @@ def test_get_finance_data(full_db: Session) -> None:
}
)
pd.testing.assert_frame_equal(finance_df, test_data)
def test_get_news_of_one_company0(news_db: Session) -> None:
"""Tests what happens if no sentiment can be found."""
selected_company_id = 100
assert data_elements.get_news_of_one_company(selected_company_id, news_db).empty
def test_get_news_of_one_company1(news_db: Session) -> None:
"""Tests if the sentiments can be collected for a company specified."""
selected_company_id = 2
sentiment_df = data_elements.get_news_of_one_company(selected_company_id, news_db)
assert sentiment_df is not None
assert sentiment_df.to_dict(orient="records") == [
{
"overall_sentiment_certainty": 0.95,
"overall_sentiment_label": SentimentLabel.POSITIVE,
"source_domain": "example-news.com",
"source_url": "http://example-news.com/ai-revolution",
"times_named": 2,
"timestamp": pd.Timestamp("2023-11-01 15:30:00"),
"title": "AI Revolution in Tech",
},
]