You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
|
# 适配器工厂类
|
|
|
|
|
|
from qihuo_analyzer.data.api_adapters.base_adapter import BaseDataAdapter
|
|
|
|
|
|
from qihuo_analyzer.data.api_adapters.tqsdk_adapter import TqSdkAdapter
|
|
|
|
|
|
from qihuo_analyzer.data.api_adapters.rqdata_adapter import RqDataAdapter
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DataAdapterFactory:
|
|
|
|
|
|
"""数据适配器工厂类
|
|
|
|
|
|
|
|
|
|
|
|
根据配置创建相应的数据适配器实例。
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def create_adapter(adapter_type: str = None) -> BaseDataAdapter:
|
|
|
|
|
|
"""创建数据适配器
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
adapter_type: 适配器类型,可选值:'tqsdk', 'rqdata'。如果为None,则从环境变量获取。
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
BaseDataAdapter: 数据适配器实例
|
|
|
|
|
|
"""
|
|
|
|
|
|
# 如果没有指定适配器类型,从环境变量获取
|
|
|
|
|
|
if adapter_type is None:
|
|
|
|
|
|
adapter_type = os.getenv('DATA_ADAPTER_TYPE', 'tqsdk').lower()
|
|
|
|
|
|
|
|
|
|
|
|
# 根据类型创建适配器
|
|
|
|
|
|
if adapter_type == 'tqsdk':
|
|
|
|
|
|
print("创建TQSDK数据适配器")
|
|
|
|
|
|
return TqSdkAdapter()
|
|
|
|
|
|
elif adapter_type == 'rqdata':
|
|
|
|
|
|
print("创建RQData数据适配器")
|
|
|
|
|
|
return RqDataAdapter()
|
|
|
|
|
|
else:
|
|
|
|
|
|
# 默认使用TQSDK适配器
|
|
|
|
|
|
print(f"未知的适配器类型:{adapter_type},使用默认的TQSDK适配器")
|
|
|
|
|
|
return TqSdkAdapter()
|