From 6fdc3b1e73ca868913e6475415e8b932bd8bc89d Mon Sep 17 00:00:00 2001 From: gowtham1729 Date: Mon, 18 Dec 2023 10:17:59 +0900 Subject: [PATCH] fix: avg sentiment calculation --- applications/data_analyzer/analyzer.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/applications/data_analyzer/analyzer.py b/applications/data_analyzer/analyzer.py index 81bfd63..8fa2fe3 100644 --- a/applications/data_analyzer/analyzer.py +++ b/applications/data_analyzer/analyzer.py @@ -258,7 +258,17 @@ def update_daily_analysis(self, news: News, date: str): """ UPDATE news_analysis SET - average_sentiment = (SELECT AVG(sentiment) FROM news_news WHERE sentiment!=0), + average_sentiment = + ( + SELECT + AVG(sentiment) + FROM + news_news + WHERE + sentiment!=0 AND + symbol = %s AND + DATE(publish_time) = %s + ), total_news = total_news + 1, positive_news = positive_news + %s, negative_news = negative_news + %s, @@ -267,6 +277,8 @@ def update_daily_analysis(self, news: News, date: str): WHERE symbol = %s AND date = %s """, ( + news.symbol, + date, 1 if news.sentiment > 0 else 0, 1 if news.sentiment < 0 else 0, 1 if news.sentiment == 0 else 0,