fix: 统一退市/ST股票过滤逻辑

- sync_kline.py: get_all_stock_codes SQL 添加 ST 过滤
- full_signal_scan.py: get_all_stock_codes SQL 添加 ST 过滤
- routes/analysis.py: total_stocks/triggered_stocks/信号分布/推荐分布
  统计查询统一添加退市/ST过滤,确保分母与过滤后扫描范围一致
This commit is contained in:
freedakgmail
2026-07-22 07:49:35 +08:00
parent 2697345670
commit 037d9cd26c
3 changed files with 9 additions and 2 deletions
+1
View File
@@ -62,6 +62,7 @@ def get_all_stock_codes(conn):
SELECT code, name FROM stock_realtime_price SELECT code, name FROM stock_realtime_price
WHERE volume > 0 AND price > 0 WHERE volume > 0 AND price > 0
AND name NOT LIKE '%%退%%' AND name NOT LIKE '%%退%%'
AND name NOT LIKE '%%ST%%'
AND name NOT LIKE 'PT%%' AND name NOT LIKE 'PT%%'
ORDER BY code ORDER BY code
""") """)
+7 -2
View File
@@ -717,7 +717,8 @@ def get_scan_results():
) )
total_scanned = cur.fetchone()[0] total_scanned = cur.fetchone()[0]
cur.execute("SELECT count(*) FROM stock_realtime_price") cur.execute("""SELECT count(*) FROM stock_realtime_price
WHERE name NOT LIKE '%%退%%' AND name NOT LIKE '%%ST%%' AND name NOT LIKE 'PT%%'""")
total_stocks = cur.fetchone()[0] total_stocks = cur.fetchone()[0]
where_clauses = ["scan_date = %s"] where_clauses = ["scan_date = %s"]
@@ -893,6 +894,7 @@ def get_scan_results():
count(*) as cnt count(*) as cnt
FROM stock_signal_scan, jsonb_array_elements(signal_status) s FROM stock_signal_scan, jsonb_array_elements(signal_status) s
WHERE scan_date = %s AND (s.value->>'triggered')::boolean = true WHERE scan_date = %s AND (s.value->>'triggered')::boolean = true
AND name NOT LIKE '%%退%%' AND name NOT LIKE '%%ST%%'
GROUP BY s.value->>'name', s.value->>'type' GROUP BY s.value->>'name', s.value->>'type'
ORDER BY cnt DESC ORDER BY cnt DESC
""", (scan_date,)) """, (scan_date,))
@@ -904,6 +906,7 @@ def get_scan_results():
cur.execute(""" cur.execute("""
SELECT count(*) FROM stock_signal_scan SELECT count(*) FROM stock_signal_scan
WHERE scan_date = %s AND triggered_count > 0 WHERE scan_date = %s AND triggered_count > 0
AND name NOT LIKE '%%退%%' AND name NOT LIKE '%%ST%%'
""", (scan_date,)) """, (scan_date,))
triggered_stocks = cur.fetchone()[0] triggered_stocks = cur.fetchone()[0]
@@ -919,6 +922,7 @@ def get_scan_results():
cur.execute(""" cur.execute("""
SELECT code, signal_status, indicators, triggered_count SELECT code, signal_status, indicators, triggered_count
FROM stock_signal_scan WHERE scan_date = %s FROM stock_signal_scan WHERE scan_date = %s
AND name NOT LIKE '%%退%%' AND name NOT LIKE '%%ST%%'
""", (scan_date,)) """, (scan_date,))
recommend_counts = {} recommend_counts = {}
for r in cur.fetchall(): for r in cur.fetchall():
@@ -1141,7 +1145,8 @@ def get_scan_status():
) )
scanned = cur.fetchone()[0] scanned = cur.fetchone()[0]
cur.execute("SELECT count(*) FROM stock_realtime_price") cur.execute("""SELECT count(*) FROM stock_realtime_price
WHERE name NOT LIKE '%%退%%' AND name NOT LIKE '%%ST%%' AND name NOT LIKE 'PT%%'""")
total = cur.fetchone()[0] total = cur.fetchone()[0]
cur.execute( cur.execute(
+1
View File
@@ -60,6 +60,7 @@ def get_all_stock_codes(conn):
SELECT code, name FROM stock_realtime_price SELECT code, name FROM stock_realtime_price
WHERE volume > 0 AND price > 0 WHERE volume > 0 AND price > 0
AND name NOT LIKE '%%退%%' AND name NOT LIKE '%%退%%'
AND name NOT LIKE '%%ST%%'
AND name NOT LIKE 'PT%%' AND name NOT LIKE 'PT%%'
ORDER BY code ORDER BY code
""") """)