refactor: 移除交易时间检查逻辑并优化数据获取流程
- 删除 SpiderManager 和 WaveformWidget 中的 is_trading_time 方法及相关检查 - 在 BackendWorker 中添加截图获取步骤 - 更新波形图显示逻辑,移除非交易时间相关提示
This commit is contained in:
@@ -89,37 +89,10 @@ class WaveformWidget(QWidget):
|
||||
logger.error(f"时间转换错误: {time_str}, 错误: {e}")
|
||||
return total_width / 2 # 默认返回中间位置
|
||||
|
||||
def is_trading_time(self, time_str: str) -> bool:
|
||||
"""判断是否为交易时间"""
|
||||
try:
|
||||
current_time = datetime.strptime(time_str, "%H:%M").time()
|
||||
|
||||
# 上午交易时间: 9:30-11:30
|
||||
morning_start = time(9, 30)
|
||||
morning_end = time(11, 30)
|
||||
|
||||
# 下午交易时间: 13:00-15:00
|
||||
afternoon_start = time(13, 0)
|
||||
afternoon_end = time(15, 0)
|
||||
|
||||
# 判断是否在交易时间内
|
||||
is_trading = ((morning_start <= current_time <= morning_end) or
|
||||
(afternoon_start <= current_time <= afternoon_end))
|
||||
|
||||
logger.debug(f"时间 {time_str} 是否为交易时间: {is_trading}")
|
||||
return is_trading
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"时间判断错误: {time_str}, 错误: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def add_data_point(self, time_str: str, value: float):
|
||||
"""添加数据点"""
|
||||
# 检查是否为交易时间
|
||||
if not self.is_trading_time(time_str):
|
||||
logger.info(f"非交易时间 {time_str},跳过数据点添加")
|
||||
return
|
||||
|
||||
# 如果是第一个数据点,设置基准值
|
||||
if not self.data_points:
|
||||
self.base_value = value
|
||||
@@ -154,12 +127,6 @@ class WaveformWidget(QWidget):
|
||||
if not self.data_points:
|
||||
self._draw_no_data_message(painter, width, height)
|
||||
return
|
||||
|
||||
# 检查最后一个数据点的时间是否为交易时间
|
||||
last_time = self.data_points[-1][0] if self.data_points else ""
|
||||
if last_time and not self.is_trading_time(last_time):
|
||||
self._draw_non_trading_message(painter, width, height)
|
||||
return
|
||||
|
||||
# 绘制网格和坐标轴
|
||||
self._draw_grid(painter, width, height)
|
||||
@@ -264,24 +231,12 @@ class WaveformWidget(QWidget):
|
||||
painter.setFont(font)
|
||||
|
||||
# 绘制提示信息
|
||||
message = "等待交易时间数据..."
|
||||
message = "等待数据..."
|
||||
text_rect = painter.fontMetrics().boundingRect(message)
|
||||
x = (width - text_rect.width()) // 2
|
||||
y = height // 2
|
||||
|
||||
painter.drawText(x, y, message)
|
||||
|
||||
# 绘制交易时间说明
|
||||
font.setPointSize(10)
|
||||
font.setBold(False)
|
||||
painter.setFont(font)
|
||||
|
||||
info = "交易时间: 9:30-11:30, 13:00-15:00"
|
||||
info_rect = painter.fontMetrics().boundingRect(info)
|
||||
x_info = (width - info_rect.width()) // 2
|
||||
y_info = y + 30
|
||||
|
||||
painter.drawText(x_info, y_info, info)
|
||||
|
||||
def _draw_non_trading_message(self, painter: QPainter, width: int, height: int):
|
||||
"""绘制非交易时间提示信息或截图"""
|
||||
|
||||
Reference in New Issue
Block a user