From b90ac8432e2ed7083db01670716bdf328fee47ff Mon Sep 17 00:00:00 2001 From: zzlgreat Date: Thu, 8 Jan 2026 18:55:49 +0800 Subject: [PATCH] =?UTF-8?q?community=E5=A2=9E=E5=8A=A0=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index 90d44843..bbdfd501 100755 --- a/app.py +++ b/app.py @@ -11149,26 +11149,34 @@ def get_events_effectiveness_stats(): stock_stats = [] total_stocks = 0 if event_ids: - # 查询所有关联股票 - related_stocks = db.session.query(EventStock).filter( - EventStock.event_id.in_(event_ids) + # 查询所有关联股票(使用 RelatedStock 模型) + related_stocks = db.session.query(RelatedStock).filter( + RelatedStock.event_id.in_(event_ids) ).all() - # 统计股票数量(去重) + # 构建事件 ID 到事件的映射,用于获取涨跌幅 + event_map = {e.id: e for e in events_query} + + # 统计股票数量(去重),并关联事件涨跌幅 unique_stocks = {} for rs in related_stocks: stock_key = rs.stock_code + # 获取关联事件的最大涨幅作为该股票的涨幅参考 + event = event_map.get(rs.event_id) + event_max_chg = event.related_max_chg if event else 0 + if stock_key not in unique_stocks: unique_stocks[stock_key] = { 'stockCode': rs.stock_code, 'stockName': rs.stock_name, - 'maxChg': rs.chg_pct or 0, + 'maxChg': event_max_chg or 0, 'eventId': rs.event_id, + 'correlation': rs.correlation or 0, } else: # 保留最大涨幅的记录 - if (rs.chg_pct or 0) > unique_stocks[stock_key]['maxChg']: - unique_stocks[stock_key]['maxChg'] = rs.chg_pct or 0 + if (event_max_chg or 0) > unique_stocks[stock_key]['maxChg']: + unique_stocks[stock_key]['maxChg'] = event_max_chg or 0 unique_stocks[stock_key]['eventId'] = rs.event_id total_stocks = len(unique_stocks)