forked from ZhuLinsen/daily_stock_analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyzer_service.py
More file actions
125 lines (99 loc) · 3.23 KB
/
analyzer_service.py
File metadata and controls
125 lines (99 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# -*- coding: utf-8 -*-
"""
===================================
A股自选股智能分析系统 - 分析服务层
===================================
职责:
1. 封装核心分析逻辑,支持多调用方(CLI、WebUI、Bot)
2. 提供清晰的API接口,不依赖于命令行参数
3. 支持依赖注入,便于测试和扩展
4. 统一管理分析流程和配置
"""
from typing import List, Optional
from src.analyzer import AnalysisResult
from src.config import get_config, Config
from src.notification import NotificationService
from src.enums import ReportType
from src.core.pipeline import StockAnalysisPipeline
from src.core.market_review import run_market_review
def analyze_stock(
stock_code: str,
config: Config = None,
full_report: bool = False,
notifier: Optional[NotificationService] = None
) -> Optional[AnalysisResult]:
"""
分析单只股票
Args:
stock_code: 股票代码
config: 配置对象(可选,默认使用单例)
full_report: 是否生成完整报告
notifier: 通知服务(可选)
Returns:
分析结果对象
"""
if config is None:
config = get_config()
# 创建分析流水线
pipeline = StockAnalysisPipeline(config=config)
# 使用通知服务(如果提供)
if notifier:
pipeline.notifier = notifier
# 根据full_report参数设置报告类型
report_type = ReportType.FULL if full_report else ReportType.SIMPLE
# 运行单只股票分析
result = pipeline.process_single_stock(
code=stock_code,
skip_analysis=False,
single_stock_notify=notifier is not None,
report_type=report_type
)
return result
def analyze_stocks(
stock_codes: List[str],
config: Config = None,
full_report: bool = False,
notifier: Optional[NotificationService] = None
) -> List[AnalysisResult]:
"""
分析多只股票
Args:
stock_codes: 股票代码列表
config: 配置对象(可选,默认使用单例)
full_report: 是否生成完整报告
notifier: 通知服务(可选)
Returns:
分析结果列表
"""
if config is None:
config = get_config()
results = []
for stock_code in stock_codes:
result = analyze_stock(stock_code, config, full_report, notifier)
if result:
results.append(result)
return results
def perform_market_review(
config: Config = None,
notifier: Optional[NotificationService] = None
) -> Optional[str]:
"""
执行大盘复盘
Args:
config: 配置对象(可选,默认使用单例)
notifier: 通知服务(可选)
Returns:
复盘报告内容
"""
if config is None:
config = get_config()
# 创建分析流水线以获取analyzer和search_service
pipeline = StockAnalysisPipeline(config=config)
# 使用提供的通知服务或创建新的
review_notifier = notifier or pipeline.notifier
# 调用大盘复盘函数
return run_market_review(
notifier=review_notifier,
analyzer=pipeline.analyzer,
search_service=pipeline.search_service
)