From 1eb0e0ca2922b96cbe132f80786cd8e98c87eae1 Mon Sep 17 00:00:00 2001
From: log
Date: Sat, 11 Jul 2026 08:13:25 +0800
Subject: [PATCH] docs: document incremental data workflow

---
 a_stock_manager.py |  102 +++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 82 insertions(+), 20 deletions(-)

diff --git a/a_stock_manager.py b/a_stock_manager.py
index ae2e11e..b6ac6e5 100644
--- a/a_stock_manager.py
+++ b/a_stock_manager.py
@@ -183,23 +183,23 @@
     """打印信息消息"""
     print(f"{Color.OKCYAN}ℹ {text}{Color.ENDC}")
 
-def run_script(script_name, description="", return_result=False):
+def run_script(script_name, description="", return_result=False, args=None):
     """运行脚本"""
     if description:
         print_info(f"正在执行: {description}")
     script_path = scripts_dir / script_name
+    command = [sys.executable, str(script_path)]
+    if args:
+        command.extend(args)
+
     try:
         result = subprocess.run(
-            [sys.executable, str(script_path)],
+            command,
             cwd=project_root,
-            capture_output=True,
+            capture_output=False,
             text=True
         )
-        if result.stdout:
-            print(result.stdout)
-        if result.stderr:
-            print_error(result.stderr)
-        
+
         if return_result:
             result_file = project_root / 'logs' / 'script_result.json'
             if result_file.exists():
@@ -213,6 +213,32 @@
     except Exception as e:
         print_error(f"执行失败: {e}")
         return False
+
+
+def prompt_stock_count_args():
+    """选择数据更新股票数量,并返回传给数据更新脚本的参数。"""
+    print(f"\n{Color.BOLD}【股票数量】{Color.ENDC}")
+    print("1. 快速更新 500 只股票 ⭐推荐")
+    print("2. 全量更新全部A股(较慢)")
+    print("3. 自定义数量")
+    print("0. 返回")
+
+    choice = input("\n请选择股票数量 (0-3): ").strip()
+    if choice == '1':
+        return ["--n-stocks", "500"], "500只股票"
+    if choice == '2':
+        return ["--n-stocks", "all"], "全量A股"
+    if choice == '3':
+        value = input("请输入股票数量: ").strip()
+        if not value.isdigit() or int(value) <= 0:
+            print_error("股票数量必须是正整数")
+            return None, None
+        return ["--n-stocks", value], f"{value}只股票"
+    if choice == '0':
+        return None, None
+
+    print_error("无效的选择")
+    return None, None
 
 def run_enhanced_factor_system(data_file=None):
     """运行增强因子系统"""
@@ -317,40 +343,76 @@
     
     print(f"\n{Color.BOLD}【功能说明】{Color.ENDC}")
     print("  数据更新用于获取最新的股票市场数据")
-    print("  • 支持多种数据源:AKShare、BaoStock")
+    print("  • 支持多种数据源:AKShare、BaoStock、腾讯行情")
     print("  • 自动计算技术因子指标")
     print("  • 自动运行增强因子系统")
-    print("  • 支持增量更新")
+    print("  • 默认增量更新,全量重建需显式选择")
+    print("  • 重置数据会先移动到备份目录,不直接永久删除")
     
     print("\n选择数据更新方式:")
-    print("1. 使用真实数据源(AKShare/BaoStock)⭐推荐")
-    print("2. 使用本地模拟数据(仅测试用)")
-    print("3. 从AKShare在线获取(需要网络)")
-    print("4. 仅重新计算因子(不更新数据)⭐新增")
+    print("1. 增量更新全部A股 ⭐推荐")
+    print("2. 全量重建全部A股(耗时较长)")
+    print("3. 快速增量更新500只(连通性测试)")
+    print("4. 仅重新计算因子(不更新数据)")
+    print("5. 仅补充北交所历史数据")
+    print("6. 安全重置本地数据(自动备份)")
+    print("7. 使用本地模拟数据(仅测试用)")
     print("0. 返回")
     
-    choice = input("\n请选择 (0-4): ").strip()
+    choice = input("\n请选择 (0-7): ").strip()
     
     if choice == '1':
-        result = fetch_real_data()
+        result = run_script(
+            'update_stock_data.py',
+            "增量更新全部A股",
+        )
         if result:
             print_info("数据更新完成,正在运行增强因子系统...")
             run_enhanced_factor_system()
         return result
     elif choice == '2':
-        result = run_script('data_update_v3.py', "使用本地模拟数据")
+        result = run_script(
+            'update_stock_data.py',
+            "全量重建全部A股",
+            args=['--full', '--n-stocks', 'all', '--days', '730'],
+        )
         if result:
-            print_info("数据更新完成,正在运行增强因子系统...")
+            print_info("全量重建完成,正在运行增强因子系统...")
             run_enhanced_factor_system()
         return result
     elif choice == '3':
-        result = run_script('data_update_v2.py', "从AKShare在线获取数据")
+        result = run_script(
+            'update_stock_data.py',
+            "快速增量更新500只",
+            args=['--n-stocks', '500', '--force'],
+        )
         if result:
-            print_info("数据更新完成,正在运行增强因子系统...")
+            print_info("快速增量更新完成,正在运行增强因子系统...")
             run_enhanced_factor_system()
         return result
     elif choice == '4':
         return run_enhanced_factor_system()
+    elif choice == '5':
+        result = run_script(
+            'data_update_v2.py',
+            "补充北交所历史数据并合并现有数据",
+            args=['--bse-only', '--n-stocks', 'all'],
+        )
+        if result:
+            print_info("北交所数据补充完成,正在运行增强因子系统...")
+            run_enhanced_factor_system()
+        return result
+    elif choice == '6':
+        return run_script(
+            'reset_stock_data.py',
+            "安全重置本地行情、因子和选股数据",
+        )
+    elif choice == '7':
+        result = run_script('data_update_v3.py', "使用本地模拟数据")
+        if result:
+            print_info("模拟数据生成完成,正在运行增强因子系统...")
+            run_enhanced_factor_system()
+        return result
 
 def fetch_real_data():
     """获取真实数据"""

--
Gitblit v1.8.0